Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[sfrench/cifs-2.6.git] / drivers / staging / iio / accel / adis16209.h
1 #ifndef SPI_ADIS16209_H_
2 #define SPI_ADIS16209_H_
3
4 #define ADIS16209_STARTUP_DELAY 220 /* ms */
5
6 #define ADIS16209_READ_REG(a)    a
7 #define ADIS16209_WRITE_REG(a) ((a) | 0x80)
8
9 /* Flash memory write count */
10 #define ADIS16209_FLASH_CNT      0x00
11 /* Output, power supply */
12 #define ADIS16209_SUPPLY_OUT     0x02
13 /* Output, x-axis accelerometer */
14 #define ADIS16209_XACCL_OUT      0x04
15 /* Output, y-axis accelerometer */
16 #define ADIS16209_YACCL_OUT      0x06
17 /* Output, auxiliary ADC input */
18 #define ADIS16209_AUX_ADC        0x08
19 /* Output, temperature */
20 #define ADIS16209_TEMP_OUT       0x0A
21 /* Output, x-axis inclination */
22 #define ADIS16209_XINCL_OUT      0x0C
23 /* Output, y-axis inclination */
24 #define ADIS16209_YINCL_OUT      0x0E
25 /* Output, +/-180 vertical rotational position */
26 #define ADIS16209_ROT_OUT        0x10
27 /* Calibration, x-axis acceleration offset null */
28 #define ADIS16209_XACCL_NULL     0x12
29 /* Calibration, y-axis acceleration offset null */
30 #define ADIS16209_YACCL_NULL     0x14
31 /* Calibration, x-axis inclination offset null */
32 #define ADIS16209_XINCL_NULL     0x16
33 /* Calibration, y-axis inclination offset null */
34 #define ADIS16209_YINCL_NULL     0x18
35 /* Calibration, vertical rotation offset null */
36 #define ADIS16209_ROT_NULL       0x1A
37 /* Alarm 1 amplitude threshold */
38 #define ADIS16209_ALM_MAG1       0x20
39 /* Alarm 2 amplitude threshold */
40 #define ADIS16209_ALM_MAG2       0x22
41 /* Alarm 1, sample period */
42 #define ADIS16209_ALM_SMPL1      0x24
43 /* Alarm 2, sample period */
44 #define ADIS16209_ALM_SMPL2      0x26
45 /* Alarm control */
46 #define ADIS16209_ALM_CTRL       0x28
47 /* Auxiliary DAC data */
48 #define ADIS16209_AUX_DAC        0x30
49 /* General-purpose digital input/output control */
50 #define ADIS16209_GPIO_CTRL      0x32
51 /* Miscellaneous control */
52 #define ADIS16209_MSC_CTRL       0x34
53 /* Internal sample period (rate) control */
54 #define ADIS16209_SMPL_PRD       0x36
55 /* Operation, filter configuration */
56 #define ADIS16209_AVG_CNT        0x38
57 /* Operation, sleep mode control */
58 #define ADIS16209_SLP_CNT        0x3A
59 /* Diagnostics, system status register */
60 #define ADIS16209_DIAG_STAT      0x3C
61 /* Operation, system command register */
62 #define ADIS16209_GLOB_CMD       0x3E
63
64 #define ADIS16209_OUTPUTS        8
65
66 /* MSC_CTRL */
67 /* Self-test at power-on: 1 = disabled, 0 = enabled */
68 #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST      (1 << 10)
69 /* Self-test enable */
70 #define ADIS16209_MSC_CTRL_SELF_TEST_EN         (1 << 8)
71 /* Data-ready enable: 1 = enabled, 0 = disabled */
72 #define ADIS16209_MSC_CTRL_DATA_RDY_EN          (1 << 2)
73 /* Data-ready polarity: 1 = active high, 0 = active low */
74 #define ADIS16209_MSC_CTRL_ACTIVE_HIGH          (1 << 1)
75 /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
76 #define ADIS16209_MSC_CTRL_DATA_RDY_DIO2        (1 << 0)
77
78 /* DIAG_STAT */
79 /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
80 #define ADIS16209_DIAG_STAT_ALARM2        (1<<9)
81 /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
82 #define ADIS16209_DIAG_STAT_ALARM1        (1<<8)
83 /* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */
84 #define ADIS16209_DIAG_STAT_SELFTEST_FAIL (1<<5)
85 /* SPI communications failure */
86 #define ADIS16209_DIAG_STAT_SPI_FAIL      (1<<3)
87 /* Flash update failure */
88 #define ADIS16209_DIAG_STAT_FLASH_UPT     (1<<2)
89 /* Power supply above 3.625 V */
90 #define ADIS16209_DIAG_STAT_POWER_HIGH    (1<<1)
91 /* Power supply below 3.15 V */
92 #define ADIS16209_DIAG_STAT_POWER_LOW     (1<<0)
93
94 /* GLOB_CMD */
95 #define ADIS16209_GLOB_CMD_SW_RESET     (1<<7)
96 #define ADIS16209_GLOB_CMD_CLEAR_STAT   (1<<4)
97 #define ADIS16209_GLOB_CMD_FACTORY_CAL  (1<<1)
98
99 #define ADIS16209_MAX_TX 24
100 #define ADIS16209_MAX_RX 24
101
102 #define ADIS16209_ERROR_ACTIVE          (1<<14)
103
104 /**
105  * struct adis16209_state - device instance specific data
106  * @us:                 actual spi_device
107  * @work_trigger_to_ring: bh for triggered event handling
108  * @work_cont_thresh: CLEAN
109  * @inter:              used to check if new interrupt has been triggered
110  * @last_timestamp:     passing timestamp from th to bh of interrupt handler
111  * @indio_dev:          industrial I/O device structure
112  * @trig:               data ready trigger registered with iio
113  * @tx:                 transmit buffer
114  * @rx:                 recieve buffer
115  * @buf_lock:           mutex to protect tx and rx
116  **/
117 struct adis16209_state {
118         struct spi_device               *us;
119         struct work_struct              work_trigger_to_ring;
120         struct iio_work_cont            work_cont_thresh;
121         s64                             last_timestamp;
122         struct iio_dev                  *indio_dev;
123         struct iio_trigger              *trig;
124         u8                              *tx;
125         u8                              *rx;
126         struct mutex                    buf_lock;
127 };
128
129 int adis16209_set_irq(struct device *dev, bool enable);
130
131 #ifdef CONFIG_IIO_RING_BUFFER
132 enum adis16209_scan {
133         ADIS16209_SCAN_SUPPLY,
134         ADIS16209_SCAN_ACC_X,
135         ADIS16209_SCAN_ACC_Y,
136         ADIS16209_SCAN_AUX_ADC,
137         ADIS16209_SCAN_TEMP,
138         ADIS16209_SCAN_INCLI_X,
139         ADIS16209_SCAN_INCLI_Y,
140         ADIS16209_SCAN_ROT,
141 };
142
143 void adis16209_remove_trigger(struct iio_dev *indio_dev);
144 int adis16209_probe_trigger(struct iio_dev *indio_dev);
145
146 ssize_t adis16209_read_data_from_ring(struct device *dev,
147                                       struct device_attribute *attr,
148                                       char *buf);
149
150 int adis16209_configure_ring(struct iio_dev *indio_dev);
151 void adis16209_unconfigure_ring(struct iio_dev *indio_dev);
152
153 int adis16209_initialize_ring(struct iio_ring_buffer *ring);
154 void adis16209_uninitialize_ring(struct iio_ring_buffer *ring);
155 #else /* CONFIG_IIO_RING_BUFFER */
156
157 static inline void adis16209_remove_trigger(struct iio_dev *indio_dev)
158 {
159 }
160
161 static inline int adis16209_probe_trigger(struct iio_dev *indio_dev)
162 {
163         return 0;
164 }
165
166 static inline ssize_t
167 adis16209_read_data_from_ring(struct device *dev,
168                               struct device_attribute *attr,
169                               char *buf)
170 {
171         return 0;
172 }
173
174 static int adis16209_configure_ring(struct iio_dev *indio_dev)
175 {
176         return 0;
177 }
178
179 static inline void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
180 {
181 }
182
183 static inline int adis16209_initialize_ring(struct iio_ring_buffer *ring)
184 {
185         return 0;
186 }
187
188 static inline void adis16209_uninitialize_ring(struct iio_ring_buffer *ring)
189 {
190 }
191
192 #endif /* CONFIG_IIO_RING_BUFFER */
193 #endif /* SPI_ADIS16209_H_ */