Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[pandora-kernel.git] / drivers / staging / iio / gyro / adis16251.h
1 #ifndef SPI_ADIS16251_H_
2 #define SPI_ADIS16251_H_
3
4 #define ADIS16251_STARTUP_DELAY 220 /* ms */
5
6 #define ADIS16251_READ_REG(a)    a
7 #define ADIS16251_WRITE_REG(a) ((a) | 0x80)
8
9 #define ADIS16251_ENDURANCE  0x00 /* Flash memory write count */
10 #define ADIS16251_SUPPLY_OUT 0x02 /* Power supply measurement */
11 #define ADIS16251_GYRO_OUT   0x04 /* X-axis gyroscope output */
12 #define ADIS16251_AUX_ADC    0x0A /* analog input channel measurement */
13 #define ADIS16251_TEMP_OUT   0x0C /* internal temperature measurement */
14 #define ADIS16251_ANGL_OUT   0x0E /* angle displacement */
15 #define ADIS16251_GYRO_OFF   0x14 /* Calibration, offset/bias adjustment */
16 #define ADIS16251_GYRO_SCALE 0x16 /* Calibration, scale adjustment */
17 #define ADIS16251_ALM_MAG1   0x20 /* Alarm 1 magnitude/polarity setting */
18 #define ADIS16251_ALM_MAG2   0x22 /* Alarm 2 magnitude/polarity setting */
19 #define ADIS16251_ALM_SMPL1  0x24 /* Alarm 1 dynamic rate of change setting */
20 #define ADIS16251_ALM_SMPL2  0x26 /* Alarm 2 dynamic rate of change setting */
21 #define ADIS16251_ALM_CTRL   0x28 /* Alarm control */
22 #define ADIS16251_AUX_DAC    0x30 /* Auxiliary DAC data */
23 #define ADIS16251_GPIO_CTRL  0x32 /* Control, digital I/O line */
24 #define ADIS16251_MSC_CTRL   0x34 /* Control, data ready, self-test settings */
25 #define ADIS16251_SMPL_PRD   0x36 /* Control, internal sample rate */
26 #define ADIS16251_SENS_AVG   0x38 /* Control, dynamic range, filtering */
27 #define ADIS16251_SLP_CNT    0x3A /* Control, sleep mode initiation */
28 #define ADIS16251_DIAG_STAT  0x3C /* Diagnostic, error flags */
29 #define ADIS16251_GLOB_CMD   0x3E /* Control, global commands */
30
31 #define ADIS16251_ERROR_ACTIVE                  (1<<14)
32 #define ADIS16251_NEW_DATA                      (1<<14)
33
34 /* MSC_CTRL */
35 #define ADIS16251_MSC_CTRL_INT_SELF_TEST        (1<<10) /* Internal self-test enable */
36 #define ADIS16251_MSC_CTRL_NEG_SELF_TEST        (1<<9)
37 #define ADIS16251_MSC_CTRL_POS_SELF_TEST        (1<<8)
38 #define ADIS16251_MSC_CTRL_DATA_RDY_EN          (1<<2)
39 #define ADIS16251_MSC_CTRL_DATA_RDY_POL_HIGH    (1<<1)
40 #define ADIS16251_MSC_CTRL_DATA_RDY_DIO2        (1<<0)
41
42 /* SMPL_PRD */
43 #define ADIS16251_SMPL_PRD_TIME_BASE    (1<<7) /* Time base (tB): 0 = 1.953 ms, 1 = 60.54 ms */
44 #define ADIS16251_SMPL_PRD_DIV_MASK     0x7F
45
46 /* SLP_CNT */
47 #define ADIS16251_SLP_CNT_POWER_OFF     0x80
48
49 /* DIAG_STAT */
50 #define ADIS16251_DIAG_STAT_ALARM2      (1<<9)
51 #define ADIS16251_DIAG_STAT_ALARM1      (1<<8)
52 #define ADIS16251_DIAG_STAT_SELF_TEST   (1<<5)
53 #define ADIS16251_DIAG_STAT_OVERFLOW    (1<<4)
54 #define ADIS16251_DIAG_STAT_SPI_FAIL    (1<<3)
55 #define ADIS16251_DIAG_STAT_FLASH_UPT   (1<<2)
56 #define ADIS16251_DIAG_STAT_POWER_HIGH  (1<<1)
57 #define ADIS16251_DIAG_STAT_POWER_LOW   (1<<0)
58
59 #define ADIS16251_DIAG_STAT_ERR_MASK (ADIS16251_DIAG_STAT_ALARM2 | \
60                                       ADIS16251_DIAG_STAT_ALARM1 | \
61                                       ADIS16251_DIAG_STAT_SELF_TEST | \
62                                       ADIS16251_DIAG_STAT_OVERFLOW | \
63                                       ADIS16251_DIAG_STAT_SPI_FAIL | \
64                                       ADIS16251_DIAG_STAT_FLASH_UPT | \
65                                       ADIS16251_DIAG_STAT_POWER_HIGH | \
66                                       ADIS16251_DIAG_STAT_POWER_LOW)
67
68 /* GLOB_CMD */
69 #define ADIS16251_GLOB_CMD_SW_RESET     (1<<7)
70 #define ADIS16251_GLOB_CMD_FLASH_UPD    (1<<3)
71 #define ADIS16251_GLOB_CMD_DAC_LATCH    (1<<2)
72 #define ADIS16251_GLOB_CMD_FAC_CALIB    (1<<1)
73 #define ADIS16251_GLOB_CMD_AUTO_NULL    (1<<0)
74
75 #define ADIS16251_MAX_TX 24
76 #define ADIS16251_MAX_RX 24
77
78 #define ADIS16251_SPI_SLOW      (u32)(300 * 1000)
79 #define ADIS16251_SPI_BURST     (u32)(1000 * 1000)
80 #define ADIS16251_SPI_FAST      (u32)(2000 * 1000)
81
82 /**
83  * struct adis16251_state - device instance specific data
84  * @us:                 actual spi_device
85  * @work_trigger_to_ring: bh for triggered event handling
86  * @inter:              used to check if new interrupt has been triggered
87  * @last_timestamp:     passing timestamp from th to bh of interrupt handler
88  * @indio_dev:          industrial I/O device structure
89  * @trig:               data ready trigger registered with iio
90  * @tx:                 transmit buffer
91  * @rx:                 recieve buffer
92  * @buf_lock:           mutex to protect tx and rx
93  **/
94 struct adis16251_state {
95         struct spi_device               *us;
96         struct work_struct              work_trigger_to_ring;
97         s64                             last_timestamp;
98         struct iio_dev                  *indio_dev;
99         struct iio_trigger              *trig;
100         u8                              *tx;
101         u8                              *rx;
102         struct mutex                    buf_lock;
103 };
104
105 int adis16251_spi_write_reg_8(struct device *dev,
106                               u8 reg_address,
107                               u8 val);
108
109 int adis16251_spi_read_burst(struct device *dev, u8 *rx);
110
111 int adis16251_spi_read_sequence(struct device *dev,
112                                       u8 *tx, u8 *rx, int num);
113
114 int adis16251_set_irq(struct device *dev, bool enable);
115
116 int adis16251_reset(struct device *dev);
117
118 int adis16251_stop_device(struct device *dev);
119
120 int adis16251_check_status(struct device *dev);
121
122 #if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
123 /* At the moment triggers are only used for ring buffer
124  * filling. This may change!
125  */
126
127 enum adis16251_scan {
128         ADIS16251_SCAN_SUPPLY,
129         ADIS16251_SCAN_GYRO,
130         ADIS16251_SCAN_TEMP,
131         ADIS16251_SCAN_ADC_0,
132 };
133
134 void adis16251_remove_trigger(struct iio_dev *indio_dev);
135 int adis16251_probe_trigger(struct iio_dev *indio_dev);
136
137 ssize_t adis16251_read_data_from_ring(struct device *dev,
138                                       struct device_attribute *attr,
139                                       char *buf);
140
141
142 int adis16251_configure_ring(struct iio_dev *indio_dev);
143 void adis16251_unconfigure_ring(struct iio_dev *indio_dev);
144
145 int adis16251_initialize_ring(struct iio_ring_buffer *ring);
146 void adis16251_uninitialize_ring(struct iio_ring_buffer *ring);
147 #else /* CONFIG_IIO_RING_BUFFER */
148
149 static inline void adis16251_remove_trigger(struct iio_dev *indio_dev)
150 {
151 }
152
153 static inline int adis16251_probe_trigger(struct iio_dev *indio_dev)
154 {
155         return 0;
156 }
157
158 static inline ssize_t
159 adis16251_read_data_from_ring(struct device *dev,
160                               struct device_attribute *attr,
161                               char *buf)
162 {
163         return 0;
164 }
165
166 static int adis16251_configure_ring(struct iio_dev *indio_dev)
167 {
168         return 0;
169 }
170
171 static inline void adis16251_unconfigure_ring(struct iio_dev *indio_dev)
172 {
173 }
174
175 static inline int adis16251_initialize_ring(struct iio_ring_buffer *ring)
176 {
177         return 0;
178 }
179
180 static inline void adis16251_uninitialize_ring(struct iio_ring_buffer *ring)
181 {
182 }
183
184 #endif /* CONFIG_IIO_RING_BUFFER */
185 #endif /* SPI_ADIS16251_H_ */