Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh...
[pandora-kernel.git] / drivers / staging / iio / imu / adis16300.h
1 #ifndef SPI_ADIS16300_H_
2 #define SPI_ADIS16300_H_
3
4 #define ADIS16300_STARTUP_DELAY 220 /* ms */
5
6 #define ADIS16300_READ_REG(a)    a
7 #define ADIS16300_WRITE_REG(a) ((a) | 0x80)
8
9 #define ADIS16300_FLASH_CNT  0x00 /* Flash memory write count */
10 #define ADIS16300_SUPPLY_OUT 0x02 /* Power supply measurement */
11 #define ADIS16300_XGYRO_OUT 0x04 /* X-axis gyroscope output */
12 #define ADIS16300_XACCL_OUT 0x0A /* X-axis accelerometer output */
13 #define ADIS16300_YACCL_OUT 0x0C /* Y-axis accelerometer output */
14 #define ADIS16300_ZACCL_OUT 0x0E /* Z-axis accelerometer output */
15 #define ADIS16300_TEMP_OUT  0x10 /* Temperature output */
16 #define ADIS16300_XINCLI_OUT 0x12 /* X-axis inclinometer output measurement */
17 #define ADIS16300_YINCLI_OUT 0x14 /* Y-axis inclinometer output measurement */
18 #define ADIS16300_AUX_ADC   0x16 /* Auxiliary ADC measurement */
19
20 /* Calibration parameters */
21 #define ADIS16300_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */
22 #define ADIS16300_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */
23 #define ADIS16300_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */
24 #define ADIS16300_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */
25
26 #define ADIS16300_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */
27 #define ADIS16300_MSC_CTRL  0x34 /* Miscellaneous control */
28 #define ADIS16300_SMPL_PRD  0x36 /* Internal sample period (rate) control */
29 #define ADIS16300_SENS_AVG  0x38 /* Dynamic range and digital filter control */
30 #define ADIS16300_SLP_CNT   0x3A /* Sleep mode control */
31 #define ADIS16300_DIAG_STAT 0x3C /* System status */
32
33 /* Alarm functions */
34 #define ADIS16300_GLOB_CMD  0x3E /* System command */
35 #define ADIS16300_ALM_MAG1  0x26 /* Alarm 1 amplitude threshold */
36 #define ADIS16300_ALM_MAG2  0x28 /* Alarm 2 amplitude threshold */
37 #define ADIS16300_ALM_SMPL1 0x2A /* Alarm 1 sample size */
38 #define ADIS16300_ALM_SMPL2 0x2C /* Alarm 2 sample size */
39 #define ADIS16300_ALM_CTRL  0x2E /* Alarm control */
40 #define ADIS16300_AUX_DAC   0x30 /* Auxiliary DAC data */
41
42 #define ADIS16300_ERROR_ACTIVE                  (1<<14)
43 #define ADIS16300_NEW_DATA                      (1<<15)
44
45 /* MSC_CTRL */
46 #define ADIS16300_MSC_CTRL_MEM_TEST             (1<<11)
47 #define ADIS16300_MSC_CTRL_INT_SELF_TEST        (1<<10)
48 #define ADIS16300_MSC_CTRL_NEG_SELF_TEST        (1<<9)
49 #define ADIS16300_MSC_CTRL_POS_SELF_TEST        (1<<8)
50 #define ADIS16300_MSC_CTRL_GYRO_BIAS            (1<<7)
51 #define ADIS16300_MSC_CTRL_ACCL_ALIGN           (1<<6)
52 #define ADIS16300_MSC_CTRL_DATA_RDY_EN          (1<<2)
53 #define ADIS16300_MSC_CTRL_DATA_RDY_POL_HIGH    (1<<1)
54 #define ADIS16300_MSC_CTRL_DATA_RDY_DIO2        (1<<0)
55
56 /* SMPL_PRD */
57 #define ADIS16300_SMPL_PRD_TIME_BASE    (1<<7)
58 #define ADIS16300_SMPL_PRD_DIV_MASK     0x7F
59
60 /* DIAG_STAT */
61 #define ADIS16300_DIAG_STAT_ZACCL_FAIL  (1<<15)
62 #define ADIS16300_DIAG_STAT_YACCL_FAIL  (1<<14)
63 #define ADIS16300_DIAG_STAT_XACCL_FAIL  (1<<13)
64 #define ADIS16300_DIAG_STAT_XGYRO_FAIL  (1<<10)
65 #define ADIS16300_DIAG_STAT_ALARM2      (1<<9)
66 #define ADIS16300_DIAG_STAT_ALARM1      (1<<8)
67 #define ADIS16300_DIAG_STAT_FLASH_CHK   (1<<6)
68 #define ADIS16300_DIAG_STAT_SELF_TEST   (1<<5)
69 #define ADIS16300_DIAG_STAT_OVERFLOW    (1<<4)
70 #define ADIS16300_DIAG_STAT_SPI_FAIL    (1<<3)
71 #define ADIS16300_DIAG_STAT_FLASH_UPT   (1<<2)
72 #define ADIS16300_DIAG_STAT_POWER_HIGH  (1<<1)
73 #define ADIS16300_DIAG_STAT_POWER_LOW   (1<<0)
74
75 /* GLOB_CMD */
76 #define ADIS16300_GLOB_CMD_SW_RESET     (1<<7)
77 #define ADIS16300_GLOB_CMD_P_AUTO_NULL  (1<<4)
78 #define ADIS16300_GLOB_CMD_FLASH_UPD    (1<<3)
79 #define ADIS16300_GLOB_CMD_DAC_LATCH    (1<<2)
80 #define ADIS16300_GLOB_CMD_FAC_CALIB    (1<<1)
81 #define ADIS16300_GLOB_CMD_AUTO_NULL    (1<<0)
82
83 /* SLP_CNT */
84 #define ADIS16300_SLP_CNT_POWER_OFF     (1<<8)
85
86 #define ADIS16300_MAX_TX 18
87 #define ADIS16300_MAX_RX 18
88
89 #define ADIS16300_SPI_SLOW      (u32)(300 * 1000)
90 #define ADIS16300_SPI_BURST     (u32)(1000 * 1000)
91 #define ADIS16300_SPI_FAST      (u32)(2000 * 1000)
92
93 /**
94  * struct adis16300_state - device instance specific data
95  * @us:                 actual spi_device
96  * @work_trigger_to_ring: bh for triggered event handling
97  * @work_cont_thresh: CLEAN
98  * @inter:              used to check if new interrupt has been triggered
99  * @last_timestamp:     passing timestamp from th to bh of interrupt handler
100  * @indio_dev:          industrial I/O device structure
101  * @trig:               data ready trigger registered with iio
102  * @tx:                 transmit buffer
103  * @rx:                 recieve buffer
104  * @buf_lock:           mutex to protect tx and rx
105  **/
106 struct adis16300_state {
107         struct spi_device               *us;
108         struct work_struct              work_trigger_to_ring;
109         struct iio_work_cont            work_cont_thresh;
110         s64                             last_timestamp;
111         struct iio_dev                  *indio_dev;
112         struct iio_trigger              *trig;
113         u8                              *tx;
114         u8                              *rx;
115         struct mutex                    buf_lock;
116 };
117
118 int adis16300_spi_read_burst(struct device *dev, u8 *rx);
119
120 int adis16300_set_irq(struct device *dev, bool enable);
121
122 int adis16300_reset(struct device *dev);
123
124 int adis16300_check_status(struct device *dev);
125
126 #ifdef CONFIG_IIO_RING_BUFFER
127 /* At the moment triggers are only used for ring buffer
128  * filling. This may change!
129  */
130
131 enum adis16300_scan {
132         ADIS16300_SCAN_SUPPLY,
133         ADIS16300_SCAN_GYRO_X,
134         ADIS16300_SCAN_ACC_X,
135         ADIS16300_SCAN_ACC_Y,
136         ADIS16300_SCAN_ACC_Z,
137         ADIS16300_SCAN_TEMP,
138         ADIS16300_SCAN_ADC_0,
139         ADIS16300_SCAN_INCLI_X,
140         ADIS16300_SCAN_INCLI_Y,
141 };
142
143 void adis16300_remove_trigger(struct iio_dev *indio_dev);
144 int adis16300_probe_trigger(struct iio_dev *indio_dev);
145
146 ssize_t adis16300_read_data_from_ring(struct device *dev,
147                                       struct device_attribute *attr,
148                                       char *buf);
149
150
151 int adis16300_configure_ring(struct iio_dev *indio_dev);
152 void adis16300_unconfigure_ring(struct iio_dev *indio_dev);
153
154 int adis16300_initialize_ring(struct iio_ring_buffer *ring);
155 void adis16300_uninitialize_ring(struct iio_ring_buffer *ring);
156 #else /* CONFIG_IIO_RING_BUFFER */
157
158 static inline void adis16300_remove_trigger(struct iio_dev *indio_dev)
159 {
160 }
161
162 static inline int adis16300_probe_trigger(struct iio_dev *indio_dev)
163 {
164         return 0;
165 }
166
167 static inline ssize_t
168 adis16300_read_data_from_ring(struct device *dev,
169                               struct device_attribute *attr,
170                               char *buf)
171 {
172         return 0;
173 }
174
175 static int adis16300_configure_ring(struct iio_dev *indio_dev)
176 {
177         return 0;
178 }
179
180 static inline void adis16300_unconfigure_ring(struct iio_dev *indio_dev)
181 {
182 }
183
184 static inline int adis16300_initialize_ring(struct iio_ring_buffer *ring)
185 {
186         return 0;
187 }
188
189 static inline void adis16300_uninitialize_ring(struct iio_ring_buffer *ring)
190 {
191 }
192
193 #endif /* CONFIG_IIO_RING_BUFFER */
194 #endif /* SPI_ADIS16300_H_ */