Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt...
[pandora-kernel.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  * @indio_dev:          industrial I/O device structure
108  * @trig:               data ready trigger registered with iio
109  * @tx:                 transmit buffer
110  * @rx:                 receive buffer
111  * @buf_lock:           mutex to protect tx and rx
112  **/
113 struct adis16209_state {
114         struct spi_device               *us;
115         struct iio_dev                  *indio_dev;
116         struct iio_trigger              *trig;
117         u8                              *tx;
118         u8                              *rx;
119         struct mutex                    buf_lock;
120 };
121
122 int adis16209_set_irq(struct iio_dev *indio_dev, bool enable);
123
124 #define ADIS16209_SCAN_SUPPLY   0
125 #define ADIS16209_SCAN_ACC_X    1
126 #define ADIS16209_SCAN_ACC_Y    2
127 #define ADIS16209_SCAN_AUX_ADC  3
128 #define ADIS16209_SCAN_TEMP     4
129 #define ADIS16209_SCAN_INCLI_X  5
130 #define ADIS16209_SCAN_INCLI_Y  6
131 #define ADIS16209_SCAN_ROT      7
132
133 #ifdef CONFIG_IIO_RING_BUFFER
134
135 void adis16209_remove_trigger(struct iio_dev *indio_dev);
136 int adis16209_probe_trigger(struct iio_dev *indio_dev);
137
138 ssize_t adis16209_read_data_from_ring(struct device *dev,
139                                       struct device_attribute *attr,
140                                       char *buf);
141
142 int adis16209_configure_ring(struct iio_dev *indio_dev);
143 void adis16209_unconfigure_ring(struct iio_dev *indio_dev);
144
145 #else /* CONFIG_IIO_RING_BUFFER */
146
147 static inline void adis16209_remove_trigger(struct iio_dev *indio_dev)
148 {
149 }
150
151 static inline int adis16209_probe_trigger(struct iio_dev *indio_dev)
152 {
153         return 0;
154 }
155
156 static inline ssize_t
157 adis16209_read_data_from_ring(struct device *dev,
158                               struct device_attribute *attr,
159                               char *buf)
160 {
161         return 0;
162 }
163
164 static int adis16209_configure_ring(struct iio_dev *indio_dev)
165 {
166         return 0;
167 }
168
169 static inline void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
170 {
171 }
172
173 #endif /* CONFIG_IIO_RING_BUFFER */
174 #endif /* SPI_ADIS16209_H_ */