Commit | Line | Data |
---|---|---|
a9d26f00 BS |
1 | /* |
2 | * adis16400.c support Analog Devices ADIS16400/5 | |
3 | * 3d 2g Linear Accelerometers, | |
4 | * 3d Gyroscopes, | |
5 | * 3d Magnetometers via SPI | |
6 | * | |
7 | * Copyright (c) 2009 Manuel Stahl <manuel.stahl@iis.fraunhofer.de> | |
0f8c9620 | 8 | * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org> |
6a6ec623 | 9 | * Copyright (c) 2011 Analog Devices Inc. |
a9d26f00 BS |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License version 2 as | |
13 | * published by the Free Software Foundation. | |
14 | * | |
15 | */ | |
16 | ||
17 | #include <linux/interrupt.h> | |
18 | #include <linux/irq.h> | |
a9d26f00 BS |
19 | #include <linux/delay.h> |
20 | #include <linux/mutex.h> | |
21 | #include <linux/device.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/spi/spi.h> | |
1cb6c1f5 | 24 | #include <linux/slab.h> |
a9d26f00 BS |
25 | #include <linux/sysfs.h> |
26 | #include <linux/list.h> | |
99c97852 | 27 | #include <linux/module.h> |
1db18bb4 | 28 | #include <linux/debugfs.h> |
a9d26f00 | 29 | |
06458e27 JC |
30 | #include <linux/iio/iio.h> |
31 | #include <linux/iio/sysfs.h> | |
32 | #include <linux/iio/buffer.h> | |
cd888a17 | 33 | |
a9d26f00 BS |
34 | #include "adis16400.h" |
35 | ||
1db18bb4 LPC |
36 | #ifdef CONFIG_DEBUG_FS |
37 | ||
38 | static ssize_t adis16400_show_serial_number(struct file *file, | |
39 | char __user *userbuf, size_t count, loff_t *ppos) | |
40 | { | |
41 | struct adis16400_state *st = file->private_data; | |
42 | u16 lot1, lot2, serial_number; | |
43 | char buf[16]; | |
44 | size_t len; | |
45 | int ret; | |
46 | ||
47 | ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1); | |
48 | if (ret < 0) | |
49 | return ret; | |
50 | ||
51 | ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2); | |
52 | if (ret < 0) | |
53 | return ret; | |
54 | ||
55 | ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER, | |
56 | &serial_number); | |
57 | if (ret < 0) | |
58 | return ret; | |
59 | ||
60 | len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2, | |
61 | serial_number); | |
62 | ||
63 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); | |
64 | } | |
65 | ||
66 | static const struct file_operations adis16400_serial_number_fops = { | |
67 | .open = simple_open, | |
68 | .read = adis16400_show_serial_number, | |
69 | .llseek = default_llseek, | |
70 | .owner = THIS_MODULE, | |
71 | }; | |
72 | ||
73 | static int adis16400_show_product_id(void *arg, u64 *val) | |
74 | { | |
75 | struct adis16400_state *st = arg; | |
76 | uint16_t prod_id; | |
77 | int ret; | |
78 | ||
79 | ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id); | |
80 | if (ret < 0) | |
81 | return ret; | |
82 | ||
83 | *val = prod_id; | |
84 | ||
85 | return 0; | |
86 | } | |
87 | DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops, | |
88 | adis16400_show_product_id, NULL, "%lld\n"); | |
89 | ||
90 | static int adis16400_show_flash_count(void *arg, u64 *val) | |
91 | { | |
92 | struct adis16400_state *st = arg; | |
93 | uint16_t flash_count; | |
94 | int ret; | |
95 | ||
96 | ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count); | |
97 | if (ret < 0) | |
98 | return ret; | |
99 | ||
100 | *val = flash_count; | |
101 | ||
102 | return 0; | |
103 | } | |
104 | DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops, | |
105 | adis16400_show_flash_count, NULL, "%lld\n"); | |
106 | ||
107 | static int adis16400_debugfs_init(struct iio_dev *indio_dev) | |
108 | { | |
109 | struct adis16400_state *st = iio_priv(indio_dev); | |
110 | ||
111 | if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER) | |
112 | debugfs_create_file("serial_number", 0400, | |
113 | indio_dev->debugfs_dentry, st, | |
114 | &adis16400_serial_number_fops); | |
115 | if (st->variant->flags & ADIS16400_HAS_PROD_ID) | |
116 | debugfs_create_file("product_id", 0400, | |
117 | indio_dev->debugfs_dentry, st, | |
118 | &adis16400_product_id_fops); | |
119 | debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, | |
120 | st, &adis16400_flash_count_fops); | |
121 | ||
122 | return 0; | |
123 | } | |
124 | ||
125 | #else | |
126 | ||
127 | static int adis16400_debugfs_init(struct iio_dev *indio_dev) | |
128 | { | |
129 | return 0; | |
130 | } | |
131 | ||
132 | #endif | |
133 | ||
2a29a90b | 134 | enum adis16400_chip_variant { |
8e886e65 | 135 | ADIS16300, |
85da5059 | 136 | ADIS16334, |
2a29a90b JC |
137 | ADIS16350, |
138 | ADIS16360, | |
139 | ADIS16362, | |
140 | ADIS16364, | |
2a29a90b | 141 | ADIS16400, |
76ada52f | 142 | ADIS16448, |
2a29a90b JC |
143 | }; |
144 | ||
cd888a17 | 145 | static int adis16334_get_freq(struct adis16400_state *st) |
98c9373d | 146 | { |
ea2ccb3e | 147 | int ret; |
f4c6d64b | 148 | uint16_t t; |
ea2ccb3e | 149 | |
cd888a17 | 150 | ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); |
ea2ccb3e LPC |
151 | if (ret < 0) |
152 | return ret; | |
153 | ||
154 | t >>= ADIS16334_RATE_DIV_SHIFT; | |
155 | ||
b24150e3 | 156 | return 819200 >> t; |
ea2ccb3e LPC |
157 | } |
158 | ||
cd888a17 | 159 | static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) |
ea2ccb3e LPC |
160 | { |
161 | unsigned int t; | |
162 | ||
b24150e3 LPC |
163 | if (freq < 819200) |
164 | t = ilog2(819200 / freq); | |
06220b89 LPC |
165 | else |
166 | t = 0; | |
ea2ccb3e LPC |
167 | |
168 | if (t > 0x31) | |
169 | t = 0x31; | |
170 | ||
171 | t <<= ADIS16334_RATE_DIV_SHIFT; | |
172 | t |= ADIS16334_RATE_INT_CLK; | |
173 | ||
cd888a17 | 174 | return adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t); |
ea2ccb3e LPC |
175 | } |
176 | ||
cd888a17 | 177 | static int adis16400_get_freq(struct adis16400_state *st) |
ea2ccb3e | 178 | { |
98c9373d | 179 | int sps, ret; |
f4c6d64b | 180 | uint16_t t; |
98c9373d | 181 | |
cd888a17 | 182 | ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); |
98c9373d JC |
183 | if (ret < 0) |
184 | return ret; | |
f4c6d64b | 185 | |
b24150e3 | 186 | sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 52851 : 1638404; |
98c9373d JC |
187 | sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; |
188 | ||
189 | return sps; | |
190 | } | |
191 | ||
cd888a17 | 192 | static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) |
ea2ccb3e | 193 | { |
ea2ccb3e | 194 | unsigned int t; |
7ba8a04d | 195 | uint8_t val = 0; |
ea2ccb3e | 196 | |
b24150e3 | 197 | t = 1638404 / freq; |
7ba8a04d LPC |
198 | if (t >= 128) { |
199 | val |= ADIS16400_SMPL_PRD_TIME_BASE; | |
200 | t = 52851 / freq; | |
201 | if (t >= 128) | |
202 | t = 127; | |
203 | } else if (t != 0) { | |
ea2ccb3e | 204 | t--; |
7ba8a04d | 205 | } |
f4c6d64b | 206 | |
7ba8a04d LPC |
207 | val |= t; |
208 | ||
209 | if (t >= 0x0A || (val & ADIS16400_SMPL_PRD_TIME_BASE)) | |
cd888a17 | 210 | st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; |
ea2ccb3e | 211 | else |
cd888a17 | 212 | st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; |
ea2ccb3e | 213 | |
7ba8a04d | 214 | return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val); |
ea2ccb3e LPC |
215 | } |
216 | ||
a9d26f00 BS |
217 | static ssize_t adis16400_read_frequency(struct device *dev, |
218 | struct device_attribute *attr, | |
219 | char *buf) | |
220 | { | |
dedb1e77 | 221 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
ea2ccb3e | 222 | struct adis16400_state *st = iio_priv(indio_dev); |
f4c6d64b | 223 | int ret; |
ea2ccb3e | 224 | |
cd888a17 | 225 | ret = st->variant->get_freq(st); |
98c9373d | 226 | if (ret < 0) |
a9d26f00 | 227 | return ret; |
f4c6d64b | 228 | |
b24150e3 | 229 | return sprintf(buf, "%d.%.3d\n", ret / 1000, ret % 1000); |
a9d26f00 BS |
230 | } |
231 | ||
98c9373d JC |
232 | static const unsigned adis16400_3db_divisors[] = { |
233 | [0] = 2, /* Special case */ | |
bdb20bdb LPC |
234 | [1] = 6, |
235 | [2] = 12, | |
236 | [3] = 25, | |
237 | [4] = 50, | |
238 | [5] = 100, | |
239 | [6] = 200, | |
240 | [7] = 200, /* Not a valid setting */ | |
98c9373d JC |
241 | }; |
242 | ||
243 | static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) | |
244 | { | |
cd888a17 | 245 | struct adis16400_state *st = iio_priv(indio_dev); |
f4c6d64b | 246 | uint16_t val16; |
98c9373d | 247 | int i, ret; |
bdb20bdb LPC |
248 | |
249 | for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { | |
250 | if (sps / adis16400_3db_divisors[i] >= val) | |
98c9373d | 251 | break; |
bdb20bdb LPC |
252 | } |
253 | ||
cd888a17 | 254 | ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); |
bdb20bdb LPC |
255 | if (ret < 0) |
256 | return ret; | |
98c9373d | 257 | |
cd888a17 | 258 | ret = adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG, |
bdb20bdb | 259 | (val16 & ~0x07) | i); |
98c9373d JC |
260 | return ret; |
261 | } | |
262 | ||
a9d26f00 | 263 | static ssize_t adis16400_write_frequency(struct device *dev, |
f4c6d64b | 264 | struct device_attribute *attr, const char *buf, size_t len) |
a9d26f00 | 265 | { |
dedb1e77 | 266 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
38d15f06 | 267 | struct adis16400_state *st = iio_priv(indio_dev); |
b24150e3 | 268 | int i, f, val; |
a9d26f00 | 269 | int ret; |
a9d26f00 | 270 | |
b24150e3 | 271 | ret = iio_str_to_fixpoint(buf, 100, &i, &f); |
a9d26f00 BS |
272 | if (ret) |
273 | return ret; | |
f4c6d64b | 274 | |
b24150e3 LPC |
275 | val = i * 1000 + f; |
276 | ||
277 | if (val <= 0) | |
50d4b306 | 278 | return -EINVAL; |
a9d26f00 BS |
279 | |
280 | mutex_lock(&indio_dev->mlock); | |
cd888a17 | 281 | st->variant->set_freq(st, val); |
a9d26f00 BS |
282 | mutex_unlock(&indio_dev->mlock); |
283 | ||
284 | return ret ? ret : len; | |
285 | } | |
286 | ||
a9d26f00 | 287 | /* Power down the device */ |
e7854845 | 288 | static int adis16400_stop_device(struct iio_dev *indio_dev) |
a9d26f00 | 289 | { |
cd888a17 | 290 | struct adis16400_state *st = iio_priv(indio_dev); |
a9d26f00 | 291 | int ret; |
a9d26f00 | 292 | |
f4c6d64b LPC |
293 | ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, |
294 | ADIS16400_SLP_CNT_POWER_OFF); | |
a9d26f00 | 295 | if (ret) |
e7854845 JC |
296 | dev_err(&indio_dev->dev, |
297 | "problem with turning device off: SLP_CNT"); | |
a9d26f00 BS |
298 | |
299 | return ret; | |
300 | } | |
301 | ||
38d15f06 | 302 | static int adis16400_initial_setup(struct iio_dev *indio_dev) |
a9d26f00 | 303 | { |
38d15f06 | 304 | struct adis16400_state *st = iio_priv(indio_dev); |
f4c6d64b LPC |
305 | uint16_t prod_id, smp_prd; |
306 | unsigned int device_id; | |
307 | int ret; | |
a9d26f00 | 308 | |
ea2ccb3e LPC |
309 | /* use low spi speed for init if the device has a slow mode */ |
310 | if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) | |
cd888a17 | 311 | st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; |
ea2ccb3e | 312 | else |
cd888a17 LPC |
313 | st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; |
314 | st->adis.spi->mode = SPI_MODE_3; | |
315 | spi_setup(st->adis.spi); | |
a9d26f00 | 316 | |
cd888a17 LPC |
317 | ret = adis_initial_startup(&st->adis); |
318 | if (ret) | |
319 | return ret; | |
a9d26f00 | 320 | |
2a29a90b | 321 | if (st->variant->flags & ADIS16400_HAS_PROD_ID) { |
cd888a17 | 322 | ret = adis_read_reg_16(&st->adis, |
2a29a90b JC |
323 | ADIS16400_PRODUCT_ID, &prod_id); |
324 | if (ret) | |
325 | goto err_ret; | |
a9d26f00 | 326 | |
fc8850c0 LPC |
327 | sscanf(indio_dev->name, "adis%u\n", &device_id); |
328 | ||
329 | if (prod_id != device_id) | |
330 | dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", | |
331 | device_id, prod_id); | |
a9d26f00 | 332 | |
69d80bae | 333 | dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", |
f4c6d64b LPC |
334 | indio_dev->name, prod_id, |
335 | st->adis.spi->chip_select, st->adis.spi->irq); | |
2a29a90b | 336 | } |
a9d26f00 | 337 | /* use high spi speed if possible */ |
ea2ccb3e | 338 | if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { |
cd888a17 | 339 | ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd); |
ea2ccb3e LPC |
340 | if (ret) |
341 | goto err_ret; | |
342 | ||
343 | if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { | |
cd888a17 LPC |
344 | st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; |
345 | spi_setup(st->adis.spi); | |
ea2ccb3e | 346 | } |
a9d26f00 BS |
347 | } |
348 | ||
a9d26f00 | 349 | err_ret: |
a9d26f00 BS |
350 | return ret; |
351 | } | |
352 | ||
a9d26f00 | 353 | static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, |
521de518 JC |
354 | adis16400_read_frequency, |
355 | adis16400_write_frequency); | |
a9d26f00 | 356 | |
f4c6d64b | 357 | static const uint8_t adis16400_addresses[] = { |
cd888a17 LPC |
358 | [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, |
359 | [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, | |
360 | [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF, | |
361 | [ADIS16400_SCAN_ACC_X] = ADIS16400_XACCL_OFF, | |
362 | [ADIS16400_SCAN_ACC_Y] = ADIS16400_YACCL_OFF, | |
363 | [ADIS16400_SCAN_ACC_Z] = ADIS16400_ZACCL_OFF, | |
e7854845 JC |
364 | }; |
365 | ||
366 | static int adis16400_write_raw(struct iio_dev *indio_dev, | |
f4c6d64b | 367 | struct iio_chan_spec const *chan, int val, int val2, long info) |
e7854845 | 368 | { |
98c9373d JC |
369 | struct adis16400_state *st = iio_priv(indio_dev); |
370 | int ret, sps; | |
521de518 | 371 | |
f4c6d64b | 372 | switch (info) { |
c8a9f805 | 373 | case IIO_CHAN_INFO_CALIBBIAS: |
e7854845 | 374 | mutex_lock(&indio_dev->mlock); |
cd888a17 LPC |
375 | ret = adis_write_reg_16(&st->adis, |
376 | adis16400_addresses[chan->scan_index], val); | |
e7854845 JC |
377 | mutex_unlock(&indio_dev->mlock); |
378 | return ret; | |
98c9373d | 379 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: |
f4c6d64b LPC |
380 | /* |
381 | * Need to cache values so we can update if the frequency | |
382 | * changes. | |
383 | */ | |
98c9373d JC |
384 | mutex_lock(&indio_dev->mlock); |
385 | st->filt_int = val; | |
386 | /* Work out update to current value */ | |
cd888a17 | 387 | sps = st->variant->get_freq(st); |
98c9373d JC |
388 | if (sps < 0) { |
389 | mutex_unlock(&indio_dev->mlock); | |
390 | return sps; | |
391 | } | |
392 | ||
b24150e3 LPC |
393 | ret = adis16400_set_filter(indio_dev, sps, |
394 | val * 1000 + val2 / 1000); | |
98c9373d JC |
395 | mutex_unlock(&indio_dev->mlock); |
396 | return ret; | |
e7854845 JC |
397 | default: |
398 | return -EINVAL; | |
399 | } | |
400 | } | |
401 | ||
402 | static int adis16400_read_raw(struct iio_dev *indio_dev, | |
f4c6d64b | 403 | struct iio_chan_spec const *chan, int *val, int *val2, long info) |
e7854845 | 404 | { |
38d15f06 | 405 | struct adis16400_state *st = iio_priv(indio_dev); |
f4c6d64b | 406 | int16_t val16; |
cd888a17 | 407 | int ret; |
e7854845 | 408 | |
f4c6d64b | 409 | switch (info) { |
a5d016d4 | 410 | case IIO_CHAN_INFO_RAW: |
cd888a17 | 411 | return adis_single_conversion(indio_dev, chan, 0, val); |
c8a9f805 | 412 | case IIO_CHAN_INFO_SCALE: |
e7854845 | 413 | switch (chan->type) { |
41ea040c | 414 | case IIO_ANGL_VEL: |
e7854845 | 415 | *val = 0; |
2a29a90b | 416 | *val2 = st->variant->gyro_scale_micro; |
e7854845 | 417 | return IIO_VAL_INT_PLUS_MICRO; |
6835cb6b | 418 | case IIO_VOLTAGE: |
e7854845 | 419 | *val = 0; |
1cf8c97f LPC |
420 | if (chan->channel == 0) { |
421 | *val = 2; | |
422 | *val2 = 418000; /* 2.418 mV */ | |
423 | } else { | |
424 | *val = 0; | |
425 | *val2 = 805800; /* 805.8 uV */ | |
426 | } | |
e7854845 JC |
427 | return IIO_VAL_INT_PLUS_MICRO; |
428 | case IIO_ACCEL: | |
429 | *val = 0; | |
2a29a90b | 430 | *val2 = st->variant->accel_scale_micro; |
e7854845 JC |
431 | return IIO_VAL_INT_PLUS_MICRO; |
432 | case IIO_MAGN: | |
433 | *val = 0; | |
1cf8c97f | 434 | *val2 = 500; /* 0.5 mgauss */ |
e7854845 JC |
435 | return IIO_VAL_INT_PLUS_MICRO; |
436 | case IIO_TEMP: | |
760ebc0d LPC |
437 | *val = st->variant->temp_scale_nano / 1000000; |
438 | *val2 = (st->variant->temp_scale_nano % 1000000); | |
e7854845 JC |
439 | return IIO_VAL_INT_PLUS_MICRO; |
440 | default: | |
441 | return -EINVAL; | |
442 | } | |
c8a9f805 | 443 | case IIO_CHAN_INFO_CALIBBIAS: |
e7854845 | 444 | mutex_lock(&indio_dev->mlock); |
cd888a17 LPC |
445 | ret = adis_read_reg_16(&st->adis, |
446 | adis16400_addresses[chan->scan_index], &val16); | |
2a29a90b JC |
447 | mutex_unlock(&indio_dev->mlock); |
448 | if (ret) | |
e7854845 | 449 | return ret; |
e7854845 JC |
450 | val16 = ((val16 & 0xFFF) << 4) >> 4; |
451 | *val = val16; | |
452 | return IIO_VAL_INT; | |
c8a9f805 | 453 | case IIO_CHAN_INFO_OFFSET: |
e7854845 | 454 | /* currently only temperature */ |
760ebc0d | 455 | *val = st->variant->temp_offset; |
1cf8c97f | 456 | return IIO_VAL_INT; |
98c9373d JC |
457 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: |
458 | mutex_lock(&indio_dev->mlock); | |
459 | /* Need both the number of taps and the sampling frequency */ | |
cd888a17 | 460 | ret = adis_read_reg_16(&st->adis, |
98c9373d JC |
461 | ADIS16400_SENS_AVG, |
462 | &val16); | |
463 | if (ret < 0) { | |
464 | mutex_unlock(&indio_dev->mlock); | |
465 | return ret; | |
466 | } | |
cd888a17 | 467 | ret = st->variant->get_freq(st); |
b24150e3 LPC |
468 | if (ret >= 0) { |
469 | ret /= adis16400_3db_divisors[val16 & 0x07]; | |
470 | *val = ret / 1000; | |
471 | *val2 = (ret % 1000) * 1000; | |
472 | } | |
98c9373d JC |
473 | mutex_unlock(&indio_dev->mlock); |
474 | if (ret < 0) | |
475 | return ret; | |
476 | return IIO_VAL_INT_PLUS_MICRO; | |
e7854845 JC |
477 | default: |
478 | return -EINVAL; | |
479 | } | |
480 | } | |
481 | ||
599acfbb LPC |
482 | #define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \ |
483 | .type = IIO_VOLTAGE, \ | |
484 | .indexed = 1, \ | |
485 | .channel = 0, \ | |
486 | .extend_name = name, \ | |
487 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
488 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ | |
489 | .address = (addr), \ | |
490 | .scan_index = (si), \ | |
5eda3550 LPC |
491 | .scan_type = { \ |
492 | .sign = 'u', \ | |
493 | .realbits = (bits), \ | |
494 | .storagebits = 16, \ | |
495 | .shift = 0, \ | |
496 | .endianness = IIO_BE, \ | |
497 | }, \ | |
599acfbb LPC |
498 | } |
499 | ||
500 | #define ADIS16400_SUPPLY_CHAN(addr, bits) \ | |
501 | ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY) | |
502 | ||
503 | #define ADIS16400_AUX_ADC_CHAN(addr, bits) \ | |
504 | ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC) | |
505 | ||
506 | #define ADIS16400_GYRO_CHAN(mod, addr, bits) { \ | |
507 | .type = IIO_ANGL_VEL, \ | |
508 | .modified = 1, \ | |
509 | .channel2 = IIO_MOD_ ## mod, \ | |
510 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
511 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ | |
512 | IIO_CHAN_INFO_SCALE_SHARED_BIT | \ | |
513 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ | |
514 | .address = addr, \ | |
515 | .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ | |
5eda3550 LPC |
516 | .scan_type = { \ |
517 | .sign = 's', \ | |
518 | .realbits = (bits), \ | |
519 | .storagebits = 16, \ | |
520 | .shift = 0, \ | |
521 | .endianness = IIO_BE, \ | |
522 | }, \ | |
599acfbb LPC |
523 | } |
524 | ||
525 | #define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \ | |
526 | .type = IIO_ACCEL, \ | |
527 | .modified = 1, \ | |
528 | .channel2 = IIO_MOD_ ## mod, \ | |
529 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
530 | IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \ | |
531 | IIO_CHAN_INFO_SCALE_SHARED_BIT | \ | |
532 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ | |
533 | .address = (addr), \ | |
534 | .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ | |
5eda3550 LPC |
535 | .scan_type = { \ |
536 | .sign = 's', \ | |
537 | .realbits = (bits), \ | |
538 | .storagebits = 16, \ | |
539 | .shift = 0, \ | |
540 | .endianness = IIO_BE, \ | |
541 | }, \ | |
599acfbb LPC |
542 | } |
543 | ||
544 | #define ADIS16400_MAGN_CHAN(mod, addr, bits) { \ | |
545 | .type = IIO_MAGN, \ | |
546 | .modified = 1, \ | |
547 | .channel2 = IIO_MOD_ ## mod, \ | |
548 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
549 | IIO_CHAN_INFO_SCALE_SHARED_BIT | \ | |
550 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ | |
551 | .address = (addr), \ | |
552 | .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ | |
5eda3550 LPC |
553 | .scan_type = { \ |
554 | .sign = 's', \ | |
555 | .realbits = (bits), \ | |
556 | .storagebits = 16, \ | |
557 | .shift = 0, \ | |
558 | .endianness = IIO_BE, \ | |
559 | }, \ | |
599acfbb LPC |
560 | } |
561 | ||
562 | #define ADIS16400_MOD_TEMP_NAME_X "x" | |
563 | #define ADIS16400_MOD_TEMP_NAME_Y "y" | |
564 | #define ADIS16400_MOD_TEMP_NAME_Z "z" | |
565 | ||
566 | #define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \ | |
567 | .type = IIO_TEMP, \ | |
568 | .indexed = 1, \ | |
569 | .channel = 0, \ | |
570 | .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \ | |
571 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
572 | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ | |
573 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ | |
574 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \ | |
575 | .address = (addr), \ | |
576 | .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ | |
5eda3550 LPC |
577 | .scan_type = { \ |
578 | .sign = 's', \ | |
579 | .realbits = (bits), \ | |
580 | .storagebits = 16, \ | |
581 | .shift = 0, \ | |
582 | .endianness = IIO_BE, \ | |
583 | }, \ | |
599acfbb LPC |
584 | } |
585 | ||
586 | #define ADIS16400_TEMP_CHAN(addr, bits) { \ | |
587 | .type = IIO_TEMP, \ | |
588 | .indexed = 1, \ | |
589 | .channel = 0, \ | |
590 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
591 | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \ | |
592 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ | |
593 | .address = (addr), \ | |
594 | .scan_index = ADIS16350_SCAN_TEMP_X, \ | |
5eda3550 LPC |
595 | .scan_type = { \ |
596 | .sign = 's', \ | |
597 | .realbits = (bits), \ | |
598 | .storagebits = 16, \ | |
599 | .shift = 0, \ | |
600 | .endianness = IIO_BE, \ | |
601 | }, \ | |
599acfbb LPC |
602 | } |
603 | ||
604 | #define ADIS16400_INCLI_CHAN(mod, addr, bits) { \ | |
605 | .type = IIO_INCLI, \ | |
606 | .modified = 1, \ | |
607 | .channel2 = IIO_MOD_ ## mod, \ | |
608 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ | |
609 | IIO_CHAN_INFO_SCALE_SHARED_BIT, \ | |
610 | .address = (addr), \ | |
611 | .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ | |
5eda3550 LPC |
612 | .scan_type = { \ |
613 | .sign = 's', \ | |
614 | .realbits = (bits), \ | |
615 | .storagebits = 16, \ | |
616 | .shift = 0, \ | |
617 | .endianness = IIO_BE, \ | |
618 | }, \ | |
599acfbb LPC |
619 | } |
620 | ||
f4e4b955 | 621 | static const struct iio_chan_spec adis16400_channels[] = { |
599acfbb LPC |
622 | ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 14), |
623 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), | |
624 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), | |
625 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), | |
626 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), | |
627 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), | |
628 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), | |
629 | ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), | |
630 | ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), | |
631 | ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), | |
632 | ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12), | |
633 | ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12), | |
e7854845 JC |
634 | IIO_CHAN_SOFT_TIMESTAMP(12) |
635 | }; | |
636 | ||
76ada52f LPC |
637 | static const struct iio_chan_spec adis16448_channels[] = { |
638 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16), | |
639 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16), | |
640 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 16), | |
641 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 16), | |
642 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 16), | |
643 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 16), | |
644 | ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 16), | |
645 | ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 16), | |
646 | ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 16), | |
647 | { | |
648 | .type = IIO_PRESSURE, | |
649 | .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | | |
650 | IIO_CHAN_INFO_SCALE_SHARED_BIT, | |
651 | .address = ADIS16448_BARO_OUT, | |
652 | .scan_index = ADIS16400_SCAN_BARO, | |
653 | .scan_type = IIO_ST('s', 16, 16, 0), | |
654 | }, | |
655 | ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12), | |
656 | IIO_CHAN_SOFT_TIMESTAMP(11) | |
657 | }; | |
658 | ||
f4e4b955 | 659 | static const struct iio_chan_spec adis16350_channels[] = { |
599acfbb LPC |
660 | ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), |
661 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), | |
662 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), | |
663 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), | |
664 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), | |
665 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), | |
666 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), | |
667 | ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), | |
668 | ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), | |
669 | ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), | |
670 | ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), | |
671 | ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12), | |
672 | ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12), | |
673 | ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12), | |
2a29a90b JC |
674 | IIO_CHAN_SOFT_TIMESTAMP(11) |
675 | }; | |
676 | ||
f4e4b955 | 677 | static const struct iio_chan_spec adis16300_channels[] = { |
599acfbb LPC |
678 | ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), |
679 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), | |
680 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), | |
681 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), | |
682 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), | |
683 | ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), | |
684 | ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), | |
685 | ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13), | |
686 | ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13), | |
8e886e65 JC |
687 | IIO_CHAN_SOFT_TIMESTAMP(14) |
688 | }; | |
689 | ||
85da5059 | 690 | static const struct iio_chan_spec adis16334_channels[] = { |
599acfbb LPC |
691 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), |
692 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), | |
693 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), | |
694 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), | |
695 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), | |
696 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), | |
697 | ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), | |
698 | IIO_CHAN_SOFT_TIMESTAMP(8) | |
88b42f3a JC |
699 | }; |
700 | ||
a9d26f00 | 701 | static struct attribute *adis16400_attributes[] = { |
a9d26f00 | 702 | &iio_dev_attr_sampling_frequency.dev_attr.attr, |
a9d26f00 BS |
703 | NULL |
704 | }; | |
705 | ||
706 | static const struct attribute_group adis16400_attribute_group = { | |
707 | .attrs = adis16400_attributes, | |
708 | }; | |
709 | ||
2a29a90b | 710 | static struct adis16400_chip_info adis16400_chips[] = { |
8e886e65 JC |
711 | [ADIS16300] = { |
712 | .channels = adis16300_channels, | |
713 | .num_channels = ARRAY_SIZE(adis16300_channels), | |
ea2ccb3e | 714 | .flags = ADIS16400_HAS_SLOW_MODE, |
1cf8c97f | 715 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
8e886e65 | 716 | .accel_scale_micro = 5884, |
760ebc0d LPC |
717 | .temp_scale_nano = 140000000, /* 0.14 C */ |
718 | .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
719 | .set_freq = adis16400_set_freq, |
720 | .get_freq = adis16400_get_freq, | |
8e886e65 | 721 | }, |
85da5059 JC |
722 | [ADIS16334] = { |
723 | .channels = adis16334_channels, | |
724 | .num_channels = ARRAY_SIZE(adis16334_channels), | |
1db18bb4 LPC |
725 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_NO_BURST | |
726 | ADIS16400_HAS_SERIAL_NUMBER, | |
1cf8c97f LPC |
727 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
728 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ | |
760ebc0d LPC |
729 | .temp_scale_nano = 67850000, /* 0.06785 C */ |
730 | .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
731 | .set_freq = adis16334_set_freq, |
732 | .get_freq = adis16334_get_freq, | |
88b42f3a | 733 | }, |
2a29a90b JC |
734 | [ADIS16350] = { |
735 | .channels = adis16350_channels, | |
736 | .num_channels = ARRAY_SIZE(adis16350_channels), | |
1cf8c97f LPC |
737 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */ |
738 | .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */ | |
760ebc0d LPC |
739 | .temp_scale_nano = 145300000, /* 0.1453 C */ |
740 | .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
741 | .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE, |
742 | .set_freq = adis16400_set_freq, | |
743 | .get_freq = adis16400_get_freq, | |
2a29a90b JC |
744 | }, |
745 | [ADIS16360] = { | |
746 | .channels = adis16350_channels, | |
747 | .num_channels = ARRAY_SIZE(adis16350_channels), | |
1db18bb4 LPC |
748 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
749 | ADIS16400_HAS_SERIAL_NUMBER, | |
1cf8c97f LPC |
750 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
751 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ | |
760ebc0d LPC |
752 | .temp_scale_nano = 136000000, /* 0.136 C */ |
753 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
754 | .set_freq = adis16400_set_freq, |
755 | .get_freq = adis16400_get_freq, | |
2a29a90b JC |
756 | }, |
757 | [ADIS16362] = { | |
758 | .channels = adis16350_channels, | |
759 | .num_channels = ARRAY_SIZE(adis16350_channels), | |
1db18bb4 LPC |
760 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
761 | ADIS16400_HAS_SERIAL_NUMBER, | |
1cf8c97f LPC |
762 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
763 | .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ | |
760ebc0d LPC |
764 | .temp_scale_nano = 136000000, /* 0.136 C */ |
765 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
766 | .set_freq = adis16400_set_freq, |
767 | .get_freq = adis16400_get_freq, | |
2a29a90b JC |
768 | }, |
769 | [ADIS16364] = { | |
770 | .channels = adis16350_channels, | |
771 | .num_channels = ARRAY_SIZE(adis16350_channels), | |
1db18bb4 LPC |
772 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
773 | ADIS16400_HAS_SERIAL_NUMBER, | |
1cf8c97f LPC |
774 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
775 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ | |
760ebc0d LPC |
776 | .temp_scale_nano = 136000000, /* 0.136 C */ |
777 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
778 | .set_freq = adis16400_set_freq, |
779 | .get_freq = adis16400_get_freq, | |
2a29a90b | 780 | }, |
2a29a90b JC |
781 | [ADIS16400] = { |
782 | .channels = adis16400_channels, | |
783 | .num_channels = ARRAY_SIZE(adis16400_channels), | |
ea2ccb3e | 784 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, |
1cf8c97f LPC |
785 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
786 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ | |
760ebc0d LPC |
787 | .temp_scale_nano = 140000000, /* 0.14 C */ |
788 | .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ | |
ea2ccb3e LPC |
789 | .set_freq = adis16400_set_freq, |
790 | .get_freq = adis16400_get_freq, | |
76ada52f LPC |
791 | }, |
792 | [ADIS16448] = { | |
793 | .channels = adis16448_channels, | |
794 | .num_channels = ARRAY_SIZE(adis16448_channels), | |
795 | .flags = ADIS16400_HAS_PROD_ID | | |
796 | ADIS16400_HAS_SERIAL_NUMBER, | |
797 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */ | |
798 | .accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */ | |
799 | .temp_scale_nano = 73860000, /* 0.07386 C */ | |
800 | .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */ | |
801 | .set_freq = adis16334_set_freq, | |
802 | .get_freq = adis16334_get_freq, | |
2a29a90b JC |
803 | } |
804 | }; | |
805 | ||
6fe8135f JC |
806 | static const struct iio_info adis16400_info = { |
807 | .driver_module = THIS_MODULE, | |
808 | .read_raw = &adis16400_read_raw, | |
809 | .write_raw = &adis16400_write_raw, | |
810 | .attrs = &adis16400_attribute_group, | |
5eda3550 | 811 | .update_scan_mode = adis16400_update_scan_mode, |
1db18bb4 | 812 | .debugfs_reg_access = adis_debugfs_reg_access, |
5eda3550 LPC |
813 | }; |
814 | ||
815 | static const unsigned long adis16400_burst_scan_mask[] = { | |
816 | ~0UL, | |
817 | 0, | |
6fe8135f | 818 | }; |
2a29a90b | 819 | |
cd888a17 LPC |
820 | static const char * const adis16400_status_error_msgs[] = { |
821 | [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure", | |
822 | [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure", | |
823 | [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure", | |
824 | [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure", | |
825 | [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure", | |
826 | [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure", | |
827 | [ADIS16400_DIAG_STAT_ALARM2] = "Alarm 2 active", | |
828 | [ADIS16400_DIAG_STAT_ALARM1] = "Alarm 1 active", | |
829 | [ADIS16400_DIAG_STAT_FLASH_CHK] = "Flash checksum error", | |
830 | [ADIS16400_DIAG_STAT_SELF_TEST] = "Self test error", | |
831 | [ADIS16400_DIAG_STAT_OVERFLOW] = "Sensor overrange", | |
832 | [ADIS16400_DIAG_STAT_SPI_FAIL] = "SPI failure", | |
833 | [ADIS16400_DIAG_STAT_FLASH_UPT] = "Flash update failed", | |
834 | [ADIS16400_DIAG_STAT_POWER_HIGH] = "Power supply above 5.25V", | |
835 | [ADIS16400_DIAG_STAT_POWER_LOW] = "Power supply below 4.75V", | |
836 | }; | |
837 | ||
838 | static const struct adis_data adis16400_data = { | |
839 | .msc_ctrl_reg = ADIS16400_MSC_CTRL, | |
840 | .glob_cmd_reg = ADIS16400_GLOB_CMD, | |
841 | .diag_stat_reg = ADIS16400_DIAG_STAT, | |
842 | ||
843 | .read_delay = 50, | |
844 | .write_delay = 50, | |
845 | ||
846 | .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, | |
847 | .startup_delay = ADIS16400_STARTUP_DELAY, | |
848 | ||
849 | .status_error_msgs = adis16400_status_error_msgs, | |
850 | .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | | |
851 | BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | | |
852 | BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | | |
853 | BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | | |
854 | BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | | |
855 | BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | | |
856 | BIT(ADIS16400_DIAG_STAT_ALARM2) | | |
857 | BIT(ADIS16400_DIAG_STAT_ALARM1) | | |
858 | BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | | |
859 | BIT(ADIS16400_DIAG_STAT_SELF_TEST) | | |
860 | BIT(ADIS16400_DIAG_STAT_OVERFLOW) | | |
861 | BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | | |
862 | BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | | |
863 | BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | | |
864 | BIT(ADIS16400_DIAG_STAT_POWER_LOW), | |
865 | }; | |
866 | ||
4ae1c61f | 867 | static int adis16400_probe(struct spi_device *spi) |
a9d26f00 | 868 | { |
38d15f06 | 869 | struct adis16400_state *st; |
f4c6d64b LPC |
870 | struct iio_dev *indio_dev; |
871 | int ret; | |
872 | ||
873 | indio_dev = iio_device_alloc(sizeof(*st)); | |
874 | if (indio_dev == NULL) | |
875 | return -ENOMEM; | |
876 | ||
38d15f06 | 877 | st = iio_priv(indio_dev); |
a9d26f00 | 878 | /* this is only used for removal purposes */ |
38d15f06 | 879 | spi_set_drvdata(spi, indio_dev); |
a9d26f00 | 880 | |
a9d26f00 | 881 | /* setup the industrialio driver allocated elements */ |
2a29a90b | 882 | st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; |
38d15f06 JC |
883 | indio_dev->dev.parent = &spi->dev; |
884 | indio_dev->name = spi_get_device_id(spi)->name; | |
38d15f06 JC |
885 | indio_dev->channels = st->variant->channels; |
886 | indio_dev->num_channels = st->variant->num_channels; | |
6fe8135f | 887 | indio_dev->info = &adis16400_info; |
38d15f06 JC |
888 | indio_dev->modes = INDIO_DIRECT_MODE; |
889 | ||
5eda3550 LPC |
890 | if (!(st->variant->flags & ADIS16400_NO_BURST)) |
891 | indio_dev->available_scan_masks = adis16400_burst_scan_mask; | |
892 | ||
cd888a17 LPC |
893 | ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); |
894 | if (ret) | |
895 | goto error_free_dev; | |
896 | ||
5eda3550 LPC |
897 | ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, |
898 | adis16400_trigger_handler); | |
a9d26f00 BS |
899 | if (ret) |
900 | goto error_free_dev; | |
901 | ||
a9d26f00 | 902 | /* Get the device into a sane initial state */ |
38d15f06 | 903 | ret = adis16400_initial_setup(indio_dev); |
a9d26f00 | 904 | if (ret) |
5eda3550 | 905 | goto error_cleanup_buffer; |
26d25ae3 JC |
906 | ret = iio_device_register(indio_dev); |
907 | if (ret) | |
5eda3550 | 908 | goto error_cleanup_buffer; |
26d25ae3 | 909 | |
1db18bb4 | 910 | adis16400_debugfs_init(indio_dev); |
a9d26f00 BS |
911 | return 0; |
912 | ||
5eda3550 LPC |
913 | error_cleanup_buffer: |
914 | adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); | |
a9d26f00 | 915 | error_free_dev: |
7cbb7537 | 916 | iio_device_free(indio_dev); |
a9d26f00 BS |
917 | return ret; |
918 | } | |
919 | ||
447d4f29 | 920 | static int adis16400_remove(struct spi_device *spi) |
a9d26f00 | 921 | { |
f4c6d64b | 922 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
cd888a17 | 923 | struct adis16400_state *st = iio_priv(indio_dev); |
a9d26f00 | 924 | |
d2fffd6c | 925 | iio_device_unregister(indio_dev); |
0b4ac3dc | 926 | adis16400_stop_device(indio_dev); |
a9d26f00 | 927 | |
5eda3550 | 928 | adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); |
cd888a17 | 929 | |
7cbb7537 | 930 | iio_device_free(indio_dev); |
2a29a90b | 931 | |
a9d26f00 | 932 | return 0; |
a9d26f00 BS |
933 | } |
934 | ||
2a29a90b | 935 | static const struct spi_device_id adis16400_id[] = { |
8e886e65 | 936 | {"adis16300", ADIS16300}, |
85da5059 | 937 | {"adis16334", ADIS16334}, |
2a29a90b JC |
938 | {"adis16350", ADIS16350}, |
939 | {"adis16354", ADIS16350}, | |
940 | {"adis16355", ADIS16350}, | |
941 | {"adis16360", ADIS16360}, | |
942 | {"adis16362", ADIS16362}, | |
943 | {"adis16364", ADIS16364}, | |
a7462e64 | 944 | {"adis16365", ADIS16360}, |
2a29a90b JC |
945 | {"adis16400", ADIS16400}, |
946 | {"adis16405", ADIS16400}, | |
76ada52f | 947 | {"adis16448", ADIS16448}, |
2a29a90b JC |
948 | {} |
949 | }; | |
55e4390c | 950 | MODULE_DEVICE_TABLE(spi, adis16400_id); |
2a29a90b | 951 | |
a9d26f00 BS |
952 | static struct spi_driver adis16400_driver = { |
953 | .driver = { | |
954 | .name = "adis16400", | |
955 | .owner = THIS_MODULE, | |
956 | }, | |
2a29a90b | 957 | .id_table = adis16400_id, |
a9d26f00 | 958 | .probe = adis16400_probe, |
e543acf0 | 959 | .remove = adis16400_remove, |
a9d26f00 | 960 | }; |
ae6ae6fe | 961 | module_spi_driver(adis16400_driver); |
a9d26f00 BS |
962 | |
963 | MODULE_AUTHOR("Manuel Stahl <manuel.stahl@iis.fraunhofer.de>"); | |
964 | MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver"); | |
965 | MODULE_LICENSE("GPL v2"); |