This source file includes following definitions.
- adis_write_reg_8
- adis_write_reg_16
- adis_write_reg_32
- adis_read_reg_16
- adis_read_reg_32
- adis_setup_buffer_and_trigger
- adis_cleanup_buffer_and_trigger
- adis_probe_trigger
- adis_remove_trigger
1
2
3
4
5
6
7
8
9 #ifndef __IIO_ADIS_H__
10 #define __IIO_ADIS_H__
11
12 #include <linux/spi/spi.h>
13 #include <linux/interrupt.h>
14 #include <linux/iio/types.h>
15
16 #define ADIS_WRITE_REG(reg) ((0x80 | (reg)))
17 #define ADIS_READ_REG(reg) ((reg) & 0x7f)
18
19 #define ADIS_PAGE_SIZE 0x80
20 #define ADIS_REG_PAGE_ID 0x00
21
22 struct adis;
23 struct adis_burst;
24
25
26
27
28
29
30
31
32
33
34
35
36 struct adis_data {
37 unsigned int read_delay;
38 unsigned int write_delay;
39 unsigned int cs_change_delay;
40
41 unsigned int glob_cmd_reg;
42 unsigned int msc_ctrl_reg;
43 unsigned int diag_stat_reg;
44
45 unsigned int self_test_mask;
46 bool self_test_no_autoclear;
47 unsigned int startup_delay;
48
49 const char * const *status_error_msgs;
50 unsigned int status_error_mask;
51
52 int (*enable_irq)(struct adis *adis, bool enable);
53
54 bool has_paging;
55 };
56
57 struct adis {
58 struct spi_device *spi;
59 struct iio_trigger *trig;
60
61 const struct adis_data *data;
62 struct adis_burst *burst;
63
64 struct mutex txrx_lock;
65 struct spi_message msg;
66 struct spi_transfer *xfer;
67 unsigned int current_page;
68 void *buffer;
69
70 uint8_t tx[10] ____cacheline_aligned;
71 uint8_t rx[4];
72 };
73
74 int adis_init(struct adis *adis, struct iio_dev *indio_dev,
75 struct spi_device *spi, const struct adis_data *data);
76 int adis_reset(struct adis *adis);
77
78 int adis_write_reg(struct adis *adis, unsigned int reg,
79 unsigned int val, unsigned int size);
80 int adis_read_reg(struct adis *adis, unsigned int reg,
81 unsigned int *val, unsigned int size);
82
83
84
85
86
87
88
89 static inline int adis_write_reg_8(struct adis *adis, unsigned int reg,
90 uint8_t val)
91 {
92 return adis_write_reg(adis, reg, val, 1);
93 }
94
95
96
97
98
99
100
101 static inline int adis_write_reg_16(struct adis *adis, unsigned int reg,
102 uint16_t val)
103 {
104 return adis_write_reg(adis, reg, val, 2);
105 }
106
107
108
109
110
111
112
113 static inline int adis_write_reg_32(struct adis *adis, unsigned int reg,
114 uint32_t val)
115 {
116 return adis_write_reg(adis, reg, val, 4);
117 }
118
119
120
121
122
123
124
125 static inline int adis_read_reg_16(struct adis *adis, unsigned int reg,
126 uint16_t *val)
127 {
128 unsigned int tmp;
129 int ret;
130
131 ret = adis_read_reg(adis, reg, &tmp, 2);
132 *val = tmp;
133
134 return ret;
135 }
136
137
138
139
140
141
142
143 static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,
144 uint32_t *val)
145 {
146 unsigned int tmp;
147 int ret;
148
149 ret = adis_read_reg(adis, reg, &tmp, 4);
150 *val = tmp;
151
152 return ret;
153 }
154
155 int adis_enable_irq(struct adis *adis, bool enable);
156 int adis_check_status(struct adis *adis);
157
158 int adis_initial_startup(struct adis *adis);
159
160 int adis_single_conversion(struct iio_dev *indio_dev,
161 const struct iio_chan_spec *chan, unsigned int error_mask,
162 int *val);
163
164 #define ADIS_VOLTAGE_CHAN(addr, si, chan, name, info_all, bits) { \
165 .type = IIO_VOLTAGE, \
166 .indexed = 1, \
167 .channel = (chan), \
168 .extend_name = name, \
169 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
170 BIT(IIO_CHAN_INFO_SCALE), \
171 .info_mask_shared_by_all = info_all, \
172 .address = (addr), \
173 .scan_index = (si), \
174 .scan_type = { \
175 .sign = 'u', \
176 .realbits = (bits), \
177 .storagebits = 16, \
178 .endianness = IIO_BE, \
179 }, \
180 }
181
182 #define ADIS_SUPPLY_CHAN(addr, si, info_all, bits) \
183 ADIS_VOLTAGE_CHAN(addr, si, 0, "supply", info_all, bits)
184
185 #define ADIS_AUX_ADC_CHAN(addr, si, info_all, bits) \
186 ADIS_VOLTAGE_CHAN(addr, si, 1, NULL, info_all, bits)
187
188 #define ADIS_TEMP_CHAN(addr, si, info_all, bits) { \
189 .type = IIO_TEMP, \
190 .indexed = 1, \
191 .channel = 0, \
192 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
193 BIT(IIO_CHAN_INFO_SCALE) | \
194 BIT(IIO_CHAN_INFO_OFFSET), \
195 .info_mask_shared_by_all = info_all, \
196 .address = (addr), \
197 .scan_index = (si), \
198 .scan_type = { \
199 .sign = 'u', \
200 .realbits = (bits), \
201 .storagebits = 16, \
202 .endianness = IIO_BE, \
203 }, \
204 }
205
206 #define ADIS_MOD_CHAN(_type, mod, addr, si, info_sep, info_all, bits) { \
207 .type = (_type), \
208 .modified = 1, \
209 .channel2 = IIO_MOD_ ## mod, \
210 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
211 info_sep, \
212 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
213 .info_mask_shared_by_all = info_all, \
214 .address = (addr), \
215 .scan_index = (si), \
216 .scan_type = { \
217 .sign = 's', \
218 .realbits = (bits), \
219 .storagebits = 16, \
220 .endianness = IIO_BE, \
221 }, \
222 }
223
224 #define ADIS_ACCEL_CHAN(mod, addr, si, info_sep, info_all, bits) \
225 ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info_sep, info_all, bits)
226
227 #define ADIS_GYRO_CHAN(mod, addr, si, info_sep, info_all, bits) \
228 ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info_sep, info_all, bits)
229
230 #define ADIS_INCLI_CHAN(mod, addr, si, info_sep, info_all, bits) \
231 ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info_sep, info_all, bits)
232
233 #define ADIS_ROT_CHAN(mod, addr, si, info_sep, info_all, bits) \
234 ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info_sep, info_all, bits)
235
236 #ifdef CONFIG_IIO_ADIS_LIB_BUFFER
237
238
239
240
241
242
243
244 struct adis_burst {
245 bool en;
246 unsigned int reg_cmd;
247 unsigned int extra_len;
248 };
249
250 int adis_setup_buffer_and_trigger(struct adis *adis,
251 struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *));
252 void adis_cleanup_buffer_and_trigger(struct adis *adis,
253 struct iio_dev *indio_dev);
254
255 int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev);
256 void adis_remove_trigger(struct adis *adis);
257
258 int adis_update_scan_mode(struct iio_dev *indio_dev,
259 const unsigned long *scan_mask);
260
261 #else
262
263 static inline int adis_setup_buffer_and_trigger(struct adis *adis,
264 struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *))
265 {
266 return 0;
267 }
268
269 static inline void adis_cleanup_buffer_and_trigger(struct adis *adis,
270 struct iio_dev *indio_dev)
271 {
272 }
273
274 static inline int adis_probe_trigger(struct adis *adis,
275 struct iio_dev *indio_dev)
276 {
277 return 0;
278 }
279
280 static inline void adis_remove_trigger(struct adis *adis)
281 {
282 }
283
284 #define adis_update_scan_mode NULL
285
286 #endif
287
288 #ifdef CONFIG_DEBUG_FS
289
290 int adis_debugfs_reg_access(struct iio_dev *indio_dev,
291 unsigned int reg, unsigned int writeval, unsigned int *readval);
292
293 #else
294
295 #define adis_debugfs_reg_access NULL
296
297 #endif
298
299 #endif