1 // SPDX-License-Identifier: GPL-2.0-only
3 * adis16400.c support Analog Devices ADIS16400/5
4 * 3d 2g Linear Accelerometers,
6 * 3d Magnetometers via SPI
8 * Copyright (c) 2009 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
9 * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org>
10 * Copyright (c) 2011 Analog Devices Inc.
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/delay.h>
16 #include <linux/mutex.h>
17 #include <linux/device.h>
18 #include <linux/kernel.h>
19 #include <linux/spi/spi.h>
20 #include <linux/slab.h>
21 #include <linux/sysfs.h>
22 #include <linux/list.h>
23 #include <linux/module.h>
24 #include <linux/debugfs.h>
25 #include <linux/bitops.h>
27 #include <linux/iio/iio.h>
28 #include <linux/iio/sysfs.h>
29 #include <linux/iio/buffer.h>
30 #include <linux/iio/trigger_consumer.h>
31 #include <linux/iio/imu/adis.h>
33 #define ADIS16400_STARTUP_DELAY 290 /* ms */
34 #define ADIS16400_MTEST_DELAY 90 /* ms */
36 #define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */
37 #define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */
38 #define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */
39 #define ADIS16400_YGYRO_OUT 0x06 /* Y-axis gyroscope output */
40 #define ADIS16400_ZGYRO_OUT 0x08 /* Z-axis gyroscope output */
41 #define ADIS16400_XACCL_OUT 0x0A /* X-axis accelerometer output */
42 #define ADIS16400_YACCL_OUT 0x0C /* Y-axis accelerometer output */
43 #define ADIS16400_ZACCL_OUT 0x0E /* Z-axis accelerometer output */
44 #define ADIS16400_XMAGN_OUT 0x10 /* X-axis magnetometer measurement */
45 #define ADIS16400_YMAGN_OUT 0x12 /* Y-axis magnetometer measurement */
46 #define ADIS16400_ZMAGN_OUT 0x14 /* Z-axis magnetometer measurement */
47 #define ADIS16400_TEMP_OUT 0x16 /* Temperature output */
48 #define ADIS16400_AUX_ADC 0x18 /* Auxiliary ADC measurement */
50 #define ADIS16350_XTEMP_OUT 0x10 /* X-axis gyroscope temperature measurement */
51 #define ADIS16350_YTEMP_OUT 0x12 /* Y-axis gyroscope temperature measurement */
52 #define ADIS16350_ZTEMP_OUT 0x14 /* Z-axis gyroscope temperature measurement */
54 #define ADIS16300_PITCH_OUT 0x12 /* X axis inclinometer output measurement */
55 #define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */
56 #define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */
58 #define ADIS16448_BARO_OUT 0x16 /* Barometric pressure output */
59 #define ADIS16448_TEMP_OUT 0x18 /* Temperature output */
61 /* Calibration parameters */
62 #define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */
63 #define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */
64 #define ADIS16400_ZGYRO_OFF 0x1E /* Z-axis gyroscope bias offset factor */
65 #define ADIS16400_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */
66 #define ADIS16400_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */
67 #define ADIS16400_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */
68 #define ADIS16400_XMAGN_HIF 0x26 /* X-axis magnetometer, hard-iron factor */
69 #define ADIS16400_YMAGN_HIF 0x28 /* Y-axis magnetometer, hard-iron factor */
70 #define ADIS16400_ZMAGN_HIF 0x2A /* Z-axis magnetometer, hard-iron factor */
71 #define ADIS16400_XMAGN_SIF 0x2C /* X-axis magnetometer, soft-iron factor */
72 #define ADIS16400_YMAGN_SIF 0x2E /* Y-axis magnetometer, soft-iron factor */
73 #define ADIS16400_ZMAGN_SIF 0x30 /* Z-axis magnetometer, soft-iron factor */
75 #define ADIS16400_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */
76 #define ADIS16400_MSC_CTRL 0x34 /* Miscellaneous control */
77 #define ADIS16400_SMPL_PRD 0x36 /* Internal sample period (rate) control */
78 #define ADIS16400_SENS_AVG 0x38 /* Dynamic range and digital filter control */
79 #define ADIS16400_SLP_CNT 0x3A /* Sleep mode control */
80 #define ADIS16400_DIAG_STAT 0x3C /* System status */
83 #define ADIS16400_GLOB_CMD 0x3E /* System command */
84 #define ADIS16400_ALM_MAG1 0x40 /* Alarm 1 amplitude threshold */
85 #define ADIS16400_ALM_MAG2 0x42 /* Alarm 2 amplitude threshold */
86 #define ADIS16400_ALM_SMPL1 0x44 /* Alarm 1 sample size */
87 #define ADIS16400_ALM_SMPL2 0x46 /* Alarm 2 sample size */
88 #define ADIS16400_ALM_CTRL 0x48 /* Alarm control */
89 #define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */
91 #define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */
92 #define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */
93 #define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */
94 #define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */
96 #define ADIS16400_ERROR_ACTIVE (1<<14)
97 #define ADIS16400_NEW_DATA (1<<14)
100 #define ADIS16400_MSC_CTRL_MEM_TEST (1<<11)
101 #define ADIS16400_MSC_CTRL_INT_SELF_TEST (1<<10)
102 #define ADIS16400_MSC_CTRL_NEG_SELF_TEST (1<<9)
103 #define ADIS16400_MSC_CTRL_POS_SELF_TEST (1<<8)
104 #define ADIS16400_MSC_CTRL_GYRO_BIAS (1<<7)
105 #define ADIS16400_MSC_CTRL_ACCL_ALIGN (1<<6)
106 #define ADIS16400_MSC_CTRL_DATA_RDY_EN (1<<2)
107 #define ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1)
108 #define ADIS16400_MSC_CTRL_DATA_RDY_DIO2 (1<<0)
111 #define ADIS16400_SMPL_PRD_TIME_BASE (1<<7)
112 #define ADIS16400_SMPL_PRD_DIV_MASK 0x7F
115 #define ADIS16400_DIAG_STAT_ZACCL_FAIL 15
116 #define ADIS16400_DIAG_STAT_YACCL_FAIL 14
117 #define ADIS16400_DIAG_STAT_XACCL_FAIL 13
118 #define ADIS16400_DIAG_STAT_XGYRO_FAIL 12
119 #define ADIS16400_DIAG_STAT_YGYRO_FAIL 11
120 #define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10
121 #define ADIS16400_DIAG_STAT_ALARM2 9
122 #define ADIS16400_DIAG_STAT_ALARM1 8
123 #define ADIS16400_DIAG_STAT_FLASH_CHK 6
124 #define ADIS16400_DIAG_STAT_SELF_TEST 5
125 #define ADIS16400_DIAG_STAT_OVERFLOW 4
126 #define ADIS16400_DIAG_STAT_SPI_FAIL 3
127 #define ADIS16400_DIAG_STAT_FLASH_UPT 2
128 #define ADIS16400_DIAG_STAT_POWER_HIGH 1
129 #define ADIS16400_DIAG_STAT_POWER_LOW 0
132 #define ADIS16400_GLOB_CMD_SW_RESET (1<<7)
133 #define ADIS16400_GLOB_CMD_P_AUTO_NULL (1<<4)
134 #define ADIS16400_GLOB_CMD_FLASH_UPD (1<<3)
135 #define ADIS16400_GLOB_CMD_DAC_LATCH (1<<2)
136 #define ADIS16400_GLOB_CMD_FAC_CALIB (1<<1)
137 #define ADIS16400_GLOB_CMD_AUTO_NULL (1<<0)
140 #define ADIS16400_SLP_CNT_POWER_OFF (1<<8)
142 #define ADIS16334_RATE_DIV_SHIFT 8
143 #define ADIS16334_RATE_INT_CLK BIT(0)
145 #define ADIS16400_SPI_SLOW (u32)(300 * 1000)
146 #define ADIS16400_SPI_BURST (u32)(1000 * 1000)
147 #define ADIS16400_SPI_FAST (u32)(2000 * 1000)
149 #define ADIS16400_HAS_PROD_ID BIT(0)
150 #define ADIS16400_NO_BURST BIT(1)
151 #define ADIS16400_HAS_SLOW_MODE BIT(2)
152 #define ADIS16400_HAS_SERIAL_NUMBER BIT(3)
153 #define ADIS16400_BURST_DIAG_STAT BIT(4)
155 struct adis16400_state
;
157 struct adis16400_chip_info
{
158 const struct iio_chan_spec
*channels
;
159 const struct adis_data adis_data
;
160 const int num_channels
;
162 unsigned int gyro_scale_micro
;
163 unsigned int accel_scale_micro
;
166 /* set_freq() & get_freq() need to avoid using ADIS lib's state lock */
167 int (*set_freq
)(struct adis16400_state
*st
, unsigned int freq
);
168 int (*get_freq
)(struct adis16400_state
*st
);
172 * struct adis16400_state - device instance specific data
173 * @variant: chip variant info
174 * @filt_int: integer part of requested filter frequency
176 * @avail_scan_mask: NULL terminated array of bitmaps of channels
177 * that must be enabled together
179 struct adis16400_state
{
180 struct adis16400_chip_info
*variant
;
184 unsigned long avail_scan_mask
[2];
187 /* At the moment triggers are only used for ring buffer
188 * filling. This may change!
192 ADIS16400_SCAN_SUPPLY
,
193 ADIS16400_SCAN_GYRO_X
,
194 ADIS16400_SCAN_GYRO_Y
,
195 ADIS16400_SCAN_GYRO_Z
,
196 ADIS16400_SCAN_ACC_X
,
197 ADIS16400_SCAN_ACC_Y
,
198 ADIS16400_SCAN_ACC_Z
,
199 ADIS16400_SCAN_MAGN_X
,
200 ADIS16400_SCAN_MAGN_Y
,
201 ADIS16400_SCAN_MAGN_Z
,
203 ADIS16350_SCAN_TEMP_X
,
204 ADIS16350_SCAN_TEMP_Y
,
205 ADIS16350_SCAN_TEMP_Z
,
206 ADIS16300_SCAN_INCLI_X
,
207 ADIS16300_SCAN_INCLI_Y
,
209 ADIS16400_SCAN_TIMESTAMP
,
212 #ifdef CONFIG_DEBUG_FS
214 static ssize_t
adis16400_show_serial_number(struct file
*file
,
215 char __user
*userbuf
, size_t count
, loff_t
*ppos
)
217 struct adis16400_state
*st
= file
->private_data
;
218 u16 lot1
, lot2
, serial_number
;
223 ret
= adis_read_reg_16(&st
->adis
, ADIS16334_LOT_ID1
, &lot1
);
227 ret
= adis_read_reg_16(&st
->adis
, ADIS16334_LOT_ID2
, &lot2
);
231 ret
= adis_read_reg_16(&st
->adis
, ADIS16334_SERIAL_NUMBER
,
236 len
= snprintf(buf
, sizeof(buf
), "%.4x-%.4x-%.4x\n", lot1
, lot2
,
239 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
242 static const struct file_operations adis16400_serial_number_fops
= {
244 .read
= adis16400_show_serial_number
,
245 .llseek
= default_llseek
,
246 .owner
= THIS_MODULE
,
249 static int adis16400_show_product_id(void *arg
, u64
*val
)
251 struct adis16400_state
*st
= arg
;
255 ret
= adis_read_reg_16(&st
->adis
, ADIS16400_PRODUCT_ID
, &prod_id
);
263 DEFINE_DEBUGFS_ATTRIBUTE(adis16400_product_id_fops
,
264 adis16400_show_product_id
, NULL
, "%lld\n");
266 static int adis16400_show_flash_count(void *arg
, u64
*val
)
268 struct adis16400_state
*st
= arg
;
269 uint16_t flash_count
;
272 ret
= adis_read_reg_16(&st
->adis
, ADIS16400_FLASH_CNT
, &flash_count
);
280 DEFINE_DEBUGFS_ATTRIBUTE(adis16400_flash_count_fops
,
281 adis16400_show_flash_count
, NULL
, "%lld\n");
283 static int adis16400_debugfs_init(struct iio_dev
*indio_dev
)
285 struct adis16400_state
*st
= iio_priv(indio_dev
);
286 struct dentry
*d
= iio_get_debugfs_dentry(indio_dev
);
288 if (st
->variant
->flags
& ADIS16400_HAS_SERIAL_NUMBER
)
289 debugfs_create_file_unsafe("serial_number", 0400,
290 d
, st
, &adis16400_serial_number_fops
);
291 if (st
->variant
->flags
& ADIS16400_HAS_PROD_ID
)
292 debugfs_create_file_unsafe("product_id", 0400,
293 d
, st
, &adis16400_product_id_fops
);
294 debugfs_create_file_unsafe("flash_count", 0400,
295 d
, st
, &adis16400_flash_count_fops
);
302 static int adis16400_debugfs_init(struct iio_dev
*indio_dev
)
309 enum adis16400_chip_variant
{
322 static int adis16334_get_freq(struct adis16400_state
*st
)
327 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, &t
);
331 t
>>= ADIS16334_RATE_DIV_SHIFT
;
336 static int adis16334_set_freq(struct adis16400_state
*st
, unsigned int freq
)
341 t
= ilog2(819200 / freq
);
348 t
<<= ADIS16334_RATE_DIV_SHIFT
;
349 t
|= ADIS16334_RATE_INT_CLK
;
351 return __adis_write_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, t
);
354 static int adis16400_get_freq(struct adis16400_state
*st
)
359 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, &t
);
363 sps
= (t
& ADIS16400_SMPL_PRD_TIME_BASE
) ? 52851 : 1638404;
364 sps
/= (t
& ADIS16400_SMPL_PRD_DIV_MASK
) + 1;
369 static int adis16400_set_freq(struct adis16400_state
*st
, unsigned int freq
)
376 val
|= ADIS16400_SMPL_PRD_TIME_BASE
;
386 if (t
>= 0x0A || (val
& ADIS16400_SMPL_PRD_TIME_BASE
))
387 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_SLOW
;
389 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_FAST
;
391 return __adis_write_reg_8(&st
->adis
, ADIS16400_SMPL_PRD
, val
);
394 static const unsigned int adis16400_3db_divisors
[] = {
395 [0] = 2, /* Special case */
402 [7] = 200, /* Not a valid setting */
405 static int __adis16400_set_filter(struct iio_dev
*indio_dev
, int sps
, int val
)
407 struct adis16400_state
*st
= iio_priv(indio_dev
);
411 for (i
= ARRAY_SIZE(adis16400_3db_divisors
) - 1; i
>= 1; i
--) {
412 if (sps
/ adis16400_3db_divisors
[i
] >= val
)
416 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SENS_AVG
, &val16
);
420 ret
= __adis_write_reg_16(&st
->adis
, ADIS16400_SENS_AVG
,
421 (val16
& ~0x07) | i
);
425 /* Power down the device */
426 static int adis16400_stop_device(struct iio_dev
*indio_dev
)
428 struct adis16400_state
*st
= iio_priv(indio_dev
);
431 ret
= adis_write_reg_16(&st
->adis
, ADIS16400_SLP_CNT
,
432 ADIS16400_SLP_CNT_POWER_OFF
);
434 dev_err(&indio_dev
->dev
,
435 "problem with turning device off: SLP_CNT");
440 static int adis16400_initial_setup(struct iio_dev
*indio_dev
)
442 struct adis16400_state
*st
= iio_priv(indio_dev
);
443 uint16_t prod_id
, smp_prd
;
444 unsigned int device_id
;
447 /* use low spi speed for init if the device has a slow mode */
448 if (st
->variant
->flags
& ADIS16400_HAS_SLOW_MODE
)
449 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_SLOW
;
451 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_FAST
;
452 st
->adis
.spi
->mode
= SPI_MODE_3
;
453 spi_setup(st
->adis
.spi
);
455 ret
= adis_initial_startup(&st
->adis
);
459 if (st
->variant
->flags
& ADIS16400_HAS_PROD_ID
) {
460 ret
= adis_read_reg_16(&st
->adis
,
461 ADIS16400_PRODUCT_ID
, &prod_id
);
465 ret
= sscanf(indio_dev
->name
, "adis%u\n", &device_id
);
471 if (prod_id
!= device_id
)
472 dev_warn(&indio_dev
->dev
, "Device ID(%u) and product ID(%u) do not match.",
475 dev_info(&indio_dev
->dev
, "%s: prod_id 0x%04x at CS%d (irq %d)\n",
476 indio_dev
->name
, prod_id
,
477 st
->adis
.spi
->chip_select
, st
->adis
.spi
->irq
);
479 /* use high spi speed if possible */
480 if (st
->variant
->flags
& ADIS16400_HAS_SLOW_MODE
) {
481 ret
= adis_read_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, &smp_prd
);
485 if ((smp_prd
& ADIS16400_SMPL_PRD_DIV_MASK
) < 0x0A) {
486 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_FAST
;
487 spi_setup(st
->adis
.spi
);
495 static const uint8_t adis16400_addresses
[] = {
496 [ADIS16400_SCAN_GYRO_X
] = ADIS16400_XGYRO_OFF
,
497 [ADIS16400_SCAN_GYRO_Y
] = ADIS16400_YGYRO_OFF
,
498 [ADIS16400_SCAN_GYRO_Z
] = ADIS16400_ZGYRO_OFF
,
499 [ADIS16400_SCAN_ACC_X
] = ADIS16400_XACCL_OFF
,
500 [ADIS16400_SCAN_ACC_Y
] = ADIS16400_YACCL_OFF
,
501 [ADIS16400_SCAN_ACC_Z
] = ADIS16400_ZACCL_OFF
,
504 static int adis16400_write_raw(struct iio_dev
*indio_dev
,
505 struct iio_chan_spec
const *chan
, int val
, int val2
, long info
)
507 struct adis16400_state
*st
= iio_priv(indio_dev
);
508 struct mutex
*slock
= &st
->adis
.state_lock
;
512 case IIO_CHAN_INFO_CALIBBIAS
:
513 ret
= adis_write_reg_16(&st
->adis
,
514 adis16400_addresses
[chan
->scan_index
], val
);
516 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY
:
518 * Need to cache values so we can update if the frequency
523 /* Work out update to current value */
524 sps
= st
->variant
->get_freq(st
);
530 ret
= __adis16400_set_filter(indio_dev
, sps
,
531 val
* 1000 + val2
/ 1000);
534 case IIO_CHAN_INFO_SAMP_FREQ
:
535 sps
= val
* 1000 + val2
/ 1000;
541 ret
= st
->variant
->set_freq(st
, sps
);
549 static int adis16400_read_raw(struct iio_dev
*indio_dev
,
550 struct iio_chan_spec
const *chan
, int *val
, int *val2
, long info
)
552 struct adis16400_state
*st
= iio_priv(indio_dev
);
553 struct mutex
*slock
= &st
->adis
.state_lock
;
558 case IIO_CHAN_INFO_RAW
:
559 return adis_single_conversion(indio_dev
, chan
, 0, val
);
560 case IIO_CHAN_INFO_SCALE
:
561 switch (chan
->type
) {
564 *val2
= st
->variant
->gyro_scale_micro
;
565 return IIO_VAL_INT_PLUS_MICRO
;
568 if (chan
->channel
== 0) {
570 *val2
= 418000; /* 2.418 mV */
573 *val2
= 805800; /* 805.8 uV */
575 return IIO_VAL_INT_PLUS_MICRO
;
578 *val2
= st
->variant
->accel_scale_micro
;
579 return IIO_VAL_INT_PLUS_MICRO
;
582 *val2
= 500; /* 0.5 mgauss */
583 return IIO_VAL_INT_PLUS_MICRO
;
585 *val
= st
->variant
->temp_scale_nano
/ 1000000;
586 *val2
= (st
->variant
->temp_scale_nano
% 1000000);
587 return IIO_VAL_INT_PLUS_MICRO
;
589 /* 20 uBar = 0.002kPascal */
592 return IIO_VAL_INT_PLUS_MICRO
;
596 case IIO_CHAN_INFO_CALIBBIAS
:
597 ret
= adis_read_reg_16(&st
->adis
,
598 adis16400_addresses
[chan
->scan_index
], &val16
);
601 val16
= sign_extend32(val16
, 11);
604 case IIO_CHAN_INFO_OFFSET
:
605 /* currently only temperature */
606 *val
= st
->variant
->temp_offset
;
608 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY
:
610 /* Need both the number of taps and the sampling frequency */
611 ret
= __adis_read_reg_16(&st
->adis
,
618 ret
= st
->variant
->get_freq(st
);
622 ret
/= adis16400_3db_divisors
[val16
& 0x07];
624 *val2
= (ret
% 1000) * 1000;
625 return IIO_VAL_INT_PLUS_MICRO
;
626 case IIO_CHAN_INFO_SAMP_FREQ
:
628 ret
= st
->variant
->get_freq(st
);
633 *val2
= (ret
% 1000) * 1000;
634 return IIO_VAL_INT_PLUS_MICRO
;
640 #if IS_ENABLED(CONFIG_IIO_BUFFER)
641 static irqreturn_t
adis16400_trigger_handler(int irq
, void *p
)
643 struct iio_poll_func
*pf
= p
;
644 struct iio_dev
*indio_dev
= pf
->indio_dev
;
645 struct adis16400_state
*st
= iio_priv(indio_dev
);
646 struct adis
*adis
= &st
->adis
;
647 u32 old_speed_hz
= st
->adis
.spi
->max_speed_hz
;
654 if (!(st
->variant
->flags
& ADIS16400_NO_BURST
) &&
655 st
->adis
.spi
->max_speed_hz
> ADIS16400_SPI_BURST
) {
656 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_BURST
;
657 spi_setup(st
->adis
.spi
);
660 ret
= spi_sync(adis
->spi
, &adis
->msg
);
662 dev_err(&adis
->spi
->dev
, "Failed to read data: %d\n", ret
);
664 if (!(st
->variant
->flags
& ADIS16400_NO_BURST
)) {
665 st
->adis
.spi
->max_speed_hz
= old_speed_hz
;
666 spi_setup(st
->adis
.spi
);
669 if (st
->variant
->flags
& ADIS16400_BURST_DIAG_STAT
)
670 buffer
= adis
->buffer
+ sizeof(u16
);
672 buffer
= adis
->buffer
;
674 iio_push_to_buffers_with_timestamp(indio_dev
, buffer
,
677 iio_trigger_notify_done(indio_dev
->trig
);
682 #define adis16400_trigger_handler NULL
683 #endif /* IS_ENABLED(CONFIG_IIO_BUFFER) */
685 #define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si, chn) { \
686 .type = IIO_VOLTAGE, \
689 .extend_name = name, \
690 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
691 BIT(IIO_CHAN_INFO_SCALE), \
692 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
694 .scan_index = (si), \
697 .realbits = (bits), \
700 .endianness = IIO_BE, \
704 #define ADIS16400_SUPPLY_CHAN(addr, bits) \
705 ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY, 0)
707 #define ADIS16400_AUX_ADC_CHAN(addr, bits) \
708 ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC, 1)
710 #define ADIS16400_GYRO_CHAN(mod, addr, bits) { \
711 .type = IIO_ANGL_VEL, \
713 .channel2 = IIO_MOD_ ## mod, \
714 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
715 BIT(IIO_CHAN_INFO_CALIBBIAS), \
716 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
717 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
718 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
720 .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \
723 .realbits = (bits), \
726 .endianness = IIO_BE, \
730 #define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \
733 .channel2 = IIO_MOD_ ## mod, \
734 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
735 BIT(IIO_CHAN_INFO_CALIBBIAS), \
736 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
737 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
738 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
740 .scan_index = ADIS16400_SCAN_ACC_ ## mod, \
743 .realbits = (bits), \
746 .endianness = IIO_BE, \
750 #define ADIS16400_MAGN_CHAN(mod, addr, bits) { \
753 .channel2 = IIO_MOD_ ## mod, \
754 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
755 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
756 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
757 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
759 .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \
762 .realbits = (bits), \
765 .endianness = IIO_BE, \
769 #define ADIS16400_MOD_TEMP_NAME_X "x"
770 #define ADIS16400_MOD_TEMP_NAME_Y "y"
771 #define ADIS16400_MOD_TEMP_NAME_Z "z"
773 #define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \
777 .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \
778 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
779 BIT(IIO_CHAN_INFO_OFFSET) | \
780 BIT(IIO_CHAN_INFO_SCALE), \
781 .info_mask_shared_by_type = \
782 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
783 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
785 .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \
788 .realbits = (bits), \
791 .endianness = IIO_BE, \
795 #define ADIS16400_TEMP_CHAN(addr, bits) { \
799 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
800 BIT(IIO_CHAN_INFO_OFFSET) | \
801 BIT(IIO_CHAN_INFO_SCALE), \
802 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
804 .scan_index = ADIS16350_SCAN_TEMP_X, \
807 .realbits = (bits), \
810 .endianness = IIO_BE, \
814 #define ADIS16400_INCLI_CHAN(mod, addr, bits) { \
817 .channel2 = IIO_MOD_ ## mod, \
818 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
819 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
820 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
822 .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \
825 .realbits = (bits), \
828 .endianness = IIO_BE, \
832 static const struct iio_chan_spec adis16400_channels
[] = {
833 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT
, 14),
834 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
835 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 14),
836 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 14),
837 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
838 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
839 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
840 ADIS16400_MAGN_CHAN(X
, ADIS16400_XMAGN_OUT
, 14),
841 ADIS16400_MAGN_CHAN(Y
, ADIS16400_YMAGN_OUT
, 14),
842 ADIS16400_MAGN_CHAN(Z
, ADIS16400_ZMAGN_OUT
, 14),
843 ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT
, 12),
844 ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC
, 12),
845 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
848 static const struct iio_chan_spec adis16445_channels
[] = {
849 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 16),
850 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 16),
851 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 16),
852 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 16),
853 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 16),
854 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 16),
855 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT
, 12),
856 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
859 static const struct iio_chan_spec adis16448_channels
[] = {
860 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 16),
861 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 16),
862 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 16),
863 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 16),
864 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 16),
865 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 16),
866 ADIS16400_MAGN_CHAN(X
, ADIS16400_XMAGN_OUT
, 16),
867 ADIS16400_MAGN_CHAN(Y
, ADIS16400_YMAGN_OUT
, 16),
868 ADIS16400_MAGN_CHAN(Z
, ADIS16400_ZMAGN_OUT
, 16),
870 .type
= IIO_PRESSURE
,
871 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
),
872 .info_mask_shared_by_type
= BIT(IIO_CHAN_INFO_SCALE
),
873 .info_mask_shared_by_all
= BIT(IIO_CHAN_INFO_SAMP_FREQ
),
874 .address
= ADIS16448_BARO_OUT
,
875 .scan_index
= ADIS16400_SCAN_BARO
,
880 .endianness
= IIO_BE
,
883 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT
, 12),
884 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
887 static const struct iio_chan_spec adis16350_channels
[] = {
888 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT
, 12),
889 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
890 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 14),
891 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 14),
892 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
893 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
894 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
895 ADIS16400_MAGN_CHAN(X
, ADIS16400_XMAGN_OUT
, 14),
896 ADIS16400_MAGN_CHAN(Y
, ADIS16400_YMAGN_OUT
, 14),
897 ADIS16400_MAGN_CHAN(Z
, ADIS16400_ZMAGN_OUT
, 14),
898 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC
, 12),
899 ADIS16400_MOD_TEMP_CHAN(X
, ADIS16350_XTEMP_OUT
, 12),
900 ADIS16400_MOD_TEMP_CHAN(Y
, ADIS16350_YTEMP_OUT
, 12),
901 ADIS16400_MOD_TEMP_CHAN(Z
, ADIS16350_ZTEMP_OUT
, 12),
902 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
905 static const struct iio_chan_spec adis16300_channels
[] = {
906 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT
, 12),
907 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
908 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
909 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
910 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
911 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT
, 12),
912 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC
, 12),
913 ADIS16400_INCLI_CHAN(X
, ADIS16300_PITCH_OUT
, 13),
914 ADIS16400_INCLI_CHAN(Y
, ADIS16300_ROLL_OUT
, 13),
915 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
918 static const struct iio_chan_spec adis16334_channels
[] = {
919 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
920 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 14),
921 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 14),
922 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
923 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
924 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
925 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT
, 12),
926 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
929 static const char * const adis16400_status_error_msgs
[] = {
930 [ADIS16400_DIAG_STAT_ZACCL_FAIL
] = "Z-axis accelerometer self-test failure",
931 [ADIS16400_DIAG_STAT_YACCL_FAIL
] = "Y-axis accelerometer self-test failure",
932 [ADIS16400_DIAG_STAT_XACCL_FAIL
] = "X-axis accelerometer self-test failure",
933 [ADIS16400_DIAG_STAT_XGYRO_FAIL
] = "X-axis gyroscope self-test failure",
934 [ADIS16400_DIAG_STAT_YGYRO_FAIL
] = "Y-axis gyroscope self-test failure",
935 [ADIS16400_DIAG_STAT_ZGYRO_FAIL
] = "Z-axis gyroscope self-test failure",
936 [ADIS16400_DIAG_STAT_ALARM2
] = "Alarm 2 active",
937 [ADIS16400_DIAG_STAT_ALARM1
] = "Alarm 1 active",
938 [ADIS16400_DIAG_STAT_FLASH_CHK
] = "Flash checksum error",
939 [ADIS16400_DIAG_STAT_SELF_TEST
] = "Self test error",
940 [ADIS16400_DIAG_STAT_OVERFLOW
] = "Sensor overrange",
941 [ADIS16400_DIAG_STAT_SPI_FAIL
] = "SPI failure",
942 [ADIS16400_DIAG_STAT_FLASH_UPT
] = "Flash update failed",
943 [ADIS16400_DIAG_STAT_POWER_HIGH
] = "Power supply above 5.25V",
944 [ADIS16400_DIAG_STAT_POWER_LOW
] = "Power supply below 4.75V",
947 #define ADIS16400_DATA(_timeouts, _burst_len) \
949 .msc_ctrl_reg = ADIS16400_MSC_CTRL, \
950 .glob_cmd_reg = ADIS16400_GLOB_CMD, \
951 .diag_stat_reg = ADIS16400_DIAG_STAT, \
954 .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, \
955 .self_test_reg = ADIS16400_MSC_CTRL, \
956 .status_error_msgs = adis16400_status_error_msgs, \
957 .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | \
958 BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | \
959 BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | \
960 BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | \
961 BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | \
962 BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | \
963 BIT(ADIS16400_DIAG_STAT_ALARM2) | \
964 BIT(ADIS16400_DIAG_STAT_ALARM1) | \
965 BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | \
966 BIT(ADIS16400_DIAG_STAT_SELF_TEST) | \
967 BIT(ADIS16400_DIAG_STAT_OVERFLOW) | \
968 BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | \
969 BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | \
970 BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | \
971 BIT(ADIS16400_DIAG_STAT_POWER_LOW), \
972 .timeouts = (_timeouts), \
973 .burst_reg_cmd = ADIS16400_GLOB_CMD, \
974 .burst_len = (_burst_len) \
977 static const struct adis_timeout adis16300_timeouts
= {
978 .reset_ms
= ADIS16400_STARTUP_DELAY
,
979 .sw_reset_ms
= ADIS16400_STARTUP_DELAY
,
980 .self_test_ms
= ADIS16400_STARTUP_DELAY
,
983 static const struct adis_timeout adis16334_timeouts
= {
989 static const struct adis_timeout adis16362_timeouts
= {
995 static const struct adis_timeout adis16400_timeouts
= {
1001 static const struct adis_timeout adis16445_timeouts
= {
1007 static const struct adis_timeout adis16448_timeouts
= {
1013 static struct adis16400_chip_info adis16400_chips
[] = {
1015 .channels
= adis16300_channels
,
1016 .num_channels
= ARRAY_SIZE(adis16300_channels
),
1017 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1018 ADIS16400_HAS_SERIAL_NUMBER
,
1019 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1020 .accel_scale_micro
= 5884,
1021 .temp_scale_nano
= 140000000, /* 0.14 C */
1022 .temp_offset
= 25000000 / 140000, /* 25 C = 0x00 */
1023 .set_freq
= adis16400_set_freq
,
1024 .get_freq
= adis16400_get_freq
,
1025 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 18),
1028 .channels
= adis16334_channels
,
1029 .num_channels
= ARRAY_SIZE(adis16334_channels
),
1030 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_NO_BURST
|
1031 ADIS16400_HAS_SERIAL_NUMBER
,
1032 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1033 .accel_scale_micro
= IIO_G_TO_M_S_2(1000), /* 1 mg */
1034 .temp_scale_nano
= 67850000, /* 0.06785 C */
1035 .temp_offset
= 25000000 / 67850, /* 25 C = 0x00 */
1036 .set_freq
= adis16334_set_freq
,
1037 .get_freq
= adis16334_get_freq
,
1038 .adis_data
= ADIS16400_DATA(&adis16334_timeouts
, 0),
1041 .channels
= adis16350_channels
,
1042 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1043 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */
1044 .accel_scale_micro
= IIO_G_TO_M_S_2(2522), /* 0.002522 g */
1045 .temp_scale_nano
= 145300000, /* 0.1453 C */
1046 .temp_offset
= 25000000 / 145300, /* 25 C = 0x00 */
1047 .flags
= ADIS16400_NO_BURST
| ADIS16400_HAS_SLOW_MODE
,
1048 .set_freq
= adis16400_set_freq
,
1049 .get_freq
= adis16400_get_freq
,
1050 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 0),
1053 .channels
= adis16350_channels
,
1054 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1055 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1056 ADIS16400_HAS_SERIAL_NUMBER
,
1057 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1058 .accel_scale_micro
= IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1059 .temp_scale_nano
= 136000000, /* 0.136 C */
1060 .temp_offset
= 25000000 / 136000, /* 25 C = 0x00 */
1061 .set_freq
= adis16400_set_freq
,
1062 .get_freq
= adis16400_get_freq
,
1063 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 28),
1066 .channels
= adis16350_channels
,
1067 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1068 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1069 ADIS16400_HAS_SERIAL_NUMBER
,
1070 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1071 .accel_scale_micro
= IIO_G_TO_M_S_2(333), /* 0.333 mg */
1072 .temp_scale_nano
= 136000000, /* 0.136 C */
1073 .temp_offset
= 25000000 / 136000, /* 25 C = 0x00 */
1074 .set_freq
= adis16400_set_freq
,
1075 .get_freq
= adis16400_get_freq
,
1076 .adis_data
= ADIS16400_DATA(&adis16362_timeouts
, 28),
1079 .channels
= adis16350_channels
,
1080 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1081 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1082 ADIS16400_HAS_SERIAL_NUMBER
,
1083 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1084 .accel_scale_micro
= IIO_G_TO_M_S_2(1000), /* 1 mg */
1085 .temp_scale_nano
= 136000000, /* 0.136 C */
1086 .temp_offset
= 25000000 / 136000, /* 25 C = 0x00 */
1087 .set_freq
= adis16400_set_freq
,
1088 .get_freq
= adis16400_get_freq
,
1089 .adis_data
= ADIS16400_DATA(&adis16362_timeouts
, 28),
1092 .channels
= adis16350_channels
,
1093 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1094 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1095 ADIS16400_HAS_SERIAL_NUMBER
,
1096 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(2000), /* 0.2 deg/s */
1097 .accel_scale_micro
= IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1098 .temp_scale_nano
= 136000000, /* 0.136 C */
1099 .temp_offset
= 25000000 / 136000, /* 25 C = 0x00 */
1100 .set_freq
= adis16400_set_freq
,
1101 .get_freq
= adis16400_get_freq
,
1102 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 28),
1105 .channels
= adis16400_channels
,
1106 .num_channels
= ARRAY_SIZE(adis16400_channels
),
1107 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
,
1108 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1109 .accel_scale_micro
= IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1110 .temp_scale_nano
= 140000000, /* 0.14 C */
1111 .temp_offset
= 25000000 / 140000, /* 25 C = 0x00 */
1112 .set_freq
= adis16400_set_freq
,
1113 .get_freq
= adis16400_get_freq
,
1114 .adis_data
= ADIS16400_DATA(&adis16400_timeouts
, 24),
1117 .channels
= adis16445_channels
,
1118 .num_channels
= ARRAY_SIZE(adis16445_channels
),
1119 .flags
= ADIS16400_HAS_PROD_ID
|
1120 ADIS16400_HAS_SERIAL_NUMBER
|
1121 ADIS16400_BURST_DIAG_STAT
,
1122 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
1123 .accel_scale_micro
= IIO_G_TO_M_S_2(250), /* 1/4000 g */
1124 .temp_scale_nano
= 73860000, /* 0.07386 C */
1125 .temp_offset
= 31000000 / 73860, /* 31 C = 0x00 */
1126 .set_freq
= adis16334_set_freq
,
1127 .get_freq
= adis16334_get_freq
,
1128 .adis_data
= ADIS16400_DATA(&adis16445_timeouts
, 16),
1131 .channels
= adis16448_channels
,
1132 .num_channels
= ARRAY_SIZE(adis16448_channels
),
1133 .flags
= ADIS16400_HAS_PROD_ID
|
1134 ADIS16400_HAS_SERIAL_NUMBER
|
1135 ADIS16400_BURST_DIAG_STAT
,
1136 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(40000), /* 0.04 deg/s */
1137 .accel_scale_micro
= IIO_G_TO_M_S_2(833), /* 1/1200 g */
1138 .temp_scale_nano
= 73860000, /* 0.07386 C */
1139 .temp_offset
= 31000000 / 73860, /* 31 C = 0x00 */
1140 .set_freq
= adis16334_set_freq
,
1141 .get_freq
= adis16334_get_freq
,
1142 .adis_data
= ADIS16400_DATA(&adis16448_timeouts
, 24),
1146 static const struct iio_info adis16400_info
= {
1147 .read_raw
= &adis16400_read_raw
,
1148 .write_raw
= &adis16400_write_raw
,
1149 .update_scan_mode
= adis_update_scan_mode
,
1150 .debugfs_reg_access
= adis_debugfs_reg_access
,
1153 static void adis16400_setup_chan_mask(struct adis16400_state
*st
)
1155 const struct adis16400_chip_info
*chip_info
= st
->variant
;
1158 for (i
= 0; i
< chip_info
->num_channels
; i
++) {
1159 const struct iio_chan_spec
*ch
= &chip_info
->channels
[i
];
1161 if (ch
->scan_index
>= 0 &&
1162 ch
->scan_index
!= ADIS16400_SCAN_TIMESTAMP
)
1163 st
->avail_scan_mask
[0] |= BIT(ch
->scan_index
);
1167 static void adis16400_stop(void *data
)
1169 adis16400_stop_device(data
);
1172 static int adis16400_probe(struct spi_device
*spi
)
1174 struct adis16400_state
*st
;
1175 struct iio_dev
*indio_dev
;
1177 const struct adis_data
*adis16400_data
;
1179 indio_dev
= devm_iio_device_alloc(&spi
->dev
, sizeof(*st
));
1180 if (indio_dev
== NULL
)
1183 st
= iio_priv(indio_dev
);
1184 /* this is only used for removal purposes */
1185 spi_set_drvdata(spi
, indio_dev
);
1187 /* setup the industrialio driver allocated elements */
1188 st
->variant
= &adis16400_chips
[spi_get_device_id(spi
)->driver_data
];
1189 indio_dev
->name
= spi_get_device_id(spi
)->name
;
1190 indio_dev
->channels
= st
->variant
->channels
;
1191 indio_dev
->num_channels
= st
->variant
->num_channels
;
1192 indio_dev
->info
= &adis16400_info
;
1193 indio_dev
->modes
= INDIO_DIRECT_MODE
;
1195 if (!(st
->variant
->flags
& ADIS16400_NO_BURST
)) {
1196 adis16400_setup_chan_mask(st
);
1197 indio_dev
->available_scan_masks
= st
->avail_scan_mask
;
1200 adis16400_data
= &st
->variant
->adis_data
;
1202 ret
= adis_init(&st
->adis
, indio_dev
, spi
, adis16400_data
);
1206 ret
= devm_adis_setup_buffer_and_trigger(&st
->adis
, indio_dev
, adis16400_trigger_handler
);
1210 /* Get the device into a sane initial state */
1211 ret
= adis16400_initial_setup(indio_dev
);
1215 ret
= devm_add_action_or_reset(&spi
->dev
, adis16400_stop
, indio_dev
);
1219 ret
= devm_iio_device_register(&spi
->dev
, indio_dev
);
1223 adis16400_debugfs_init(indio_dev
);
1227 static const struct spi_device_id adis16400_id
[] = {
1228 {"adis16300", ADIS16300
},
1229 {"adis16305", ADIS16300
},
1230 {"adis16334", ADIS16334
},
1231 {"adis16350", ADIS16350
},
1232 {"adis16354", ADIS16350
},
1233 {"adis16355", ADIS16350
},
1234 {"adis16360", ADIS16360
},
1235 {"adis16362", ADIS16362
},
1236 {"adis16364", ADIS16364
},
1237 {"adis16365", ADIS16360
},
1238 {"adis16367", ADIS16367
},
1239 {"adis16400", ADIS16400
},
1240 {"adis16405", ADIS16400
},
1241 {"adis16445", ADIS16445
},
1242 {"adis16448", ADIS16448
},
1245 MODULE_DEVICE_TABLE(spi
, adis16400_id
);
1247 static struct spi_driver adis16400_driver
= {
1249 .name
= "adis16400",
1251 .id_table
= adis16400_id
,
1252 .probe
= adis16400_probe
,
1254 module_spi_driver(adis16400_driver
);
1256 MODULE_AUTHOR("Manuel Stahl <manuel.stahl@iis.fraunhofer.de>");
1257 MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver");
1258 MODULE_LICENSE("GPL v2");