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/irq.h>
14 #include <linux/device.h>
15 #include <linux/kernel.h>
16 #include <linux/spi/spi.h>
17 #include <linux/module.h>
18 #include <linux/debugfs.h>
19 #include <linux/bitops.h>
21 #include <linux/iio/iio.h>
22 #include <linux/iio/buffer.h>
23 #include <linux/iio/trigger_consumer.h>
24 #include <linux/iio/imu/adis.h>
26 #define ADIS16400_STARTUP_DELAY 290 /* ms */
27 #define ADIS16400_MTEST_DELAY 90 /* ms */
29 #define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */
30 #define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */
31 #define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */
32 #define ADIS16400_YGYRO_OUT 0x06 /* Y-axis gyroscope output */
33 #define ADIS16400_ZGYRO_OUT 0x08 /* Z-axis gyroscope output */
34 #define ADIS16400_XACCL_OUT 0x0A /* X-axis accelerometer output */
35 #define ADIS16400_YACCL_OUT 0x0C /* Y-axis accelerometer output */
36 #define ADIS16400_ZACCL_OUT 0x0E /* Z-axis accelerometer output */
37 #define ADIS16400_XMAGN_OUT 0x10 /* X-axis magnetometer measurement */
38 #define ADIS16400_YMAGN_OUT 0x12 /* Y-axis magnetometer measurement */
39 #define ADIS16400_ZMAGN_OUT 0x14 /* Z-axis magnetometer measurement */
40 #define ADIS16400_TEMP_OUT 0x16 /* Temperature output */
41 #define ADIS16400_AUX_ADC 0x18 /* Auxiliary ADC measurement */
43 #define ADIS16350_XTEMP_OUT 0x10 /* X-axis gyroscope temperature measurement */
44 #define ADIS16350_YTEMP_OUT 0x12 /* Y-axis gyroscope temperature measurement */
45 #define ADIS16350_ZTEMP_OUT 0x14 /* Z-axis gyroscope temperature measurement */
47 #define ADIS16300_PITCH_OUT 0x12 /* X axis inclinometer output measurement */
48 #define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */
49 #define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */
51 #define ADIS16448_BARO_OUT 0x16 /* Barometric pressure output */
52 #define ADIS16448_TEMP_OUT 0x18 /* Temperature output */
54 /* Calibration parameters */
55 #define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */
56 #define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */
57 #define ADIS16400_ZGYRO_OFF 0x1E /* Z-axis gyroscope bias offset factor */
58 #define ADIS16400_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */
59 #define ADIS16400_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */
60 #define ADIS16400_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */
61 #define ADIS16400_XMAGN_HIF 0x26 /* X-axis magnetometer, hard-iron factor */
62 #define ADIS16400_YMAGN_HIF 0x28 /* Y-axis magnetometer, hard-iron factor */
63 #define ADIS16400_ZMAGN_HIF 0x2A /* Z-axis magnetometer, hard-iron factor */
64 #define ADIS16400_XMAGN_SIF 0x2C /* X-axis magnetometer, soft-iron factor */
65 #define ADIS16400_YMAGN_SIF 0x2E /* Y-axis magnetometer, soft-iron factor */
66 #define ADIS16400_ZMAGN_SIF 0x30 /* Z-axis magnetometer, soft-iron factor */
68 #define ADIS16400_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */
69 #define ADIS16400_MSC_CTRL 0x34 /* Miscellaneous control */
70 #define ADIS16400_SMPL_PRD 0x36 /* Internal sample period (rate) control */
71 #define ADIS16400_SENS_AVG 0x38 /* Dynamic range and digital filter control */
72 #define ADIS16400_SLP_CNT 0x3A /* Sleep mode control */
73 #define ADIS16400_DIAG_STAT 0x3C /* System status */
76 #define ADIS16400_GLOB_CMD 0x3E /* System command */
77 #define ADIS16400_ALM_MAG1 0x40 /* Alarm 1 amplitude threshold */
78 #define ADIS16400_ALM_MAG2 0x42 /* Alarm 2 amplitude threshold */
79 #define ADIS16400_ALM_SMPL1 0x44 /* Alarm 1 sample size */
80 #define ADIS16400_ALM_SMPL2 0x46 /* Alarm 2 sample size */
81 #define ADIS16400_ALM_CTRL 0x48 /* Alarm control */
82 #define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */
84 #define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */
85 #define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */
86 #define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */
87 #define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */
89 #define ADIS16400_ERROR_ACTIVE (1<<14)
90 #define ADIS16400_NEW_DATA (1<<14)
93 #define ADIS16400_MSC_CTRL_MEM_TEST (1<<11)
94 #define ADIS16400_MSC_CTRL_INT_SELF_TEST (1<<10)
95 #define ADIS16400_MSC_CTRL_NEG_SELF_TEST (1<<9)
96 #define ADIS16400_MSC_CTRL_POS_SELF_TEST (1<<8)
97 #define ADIS16400_MSC_CTRL_GYRO_BIAS (1<<7)
98 #define ADIS16400_MSC_CTRL_ACCL_ALIGN (1<<6)
99 #define ADIS16400_MSC_CTRL_DATA_RDY_EN (1<<2)
100 #define ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1)
101 #define ADIS16400_MSC_CTRL_DATA_RDY_DIO2 (1<<0)
104 #define ADIS16400_SMPL_PRD_TIME_BASE (1<<7)
105 #define ADIS16400_SMPL_PRD_DIV_MASK 0x7F
108 #define ADIS16400_DIAG_STAT_ZACCL_FAIL 15
109 #define ADIS16400_DIAG_STAT_YACCL_FAIL 14
110 #define ADIS16400_DIAG_STAT_XACCL_FAIL 13
111 #define ADIS16400_DIAG_STAT_XGYRO_FAIL 12
112 #define ADIS16400_DIAG_STAT_YGYRO_FAIL 11
113 #define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10
114 #define ADIS16400_DIAG_STAT_ALARM2 9
115 #define ADIS16400_DIAG_STAT_ALARM1 8
116 #define ADIS16400_DIAG_STAT_FLASH_CHK 6
117 #define ADIS16400_DIAG_STAT_SELF_TEST 5
118 #define ADIS16400_DIAG_STAT_OVERFLOW 4
119 #define ADIS16400_DIAG_STAT_SPI_FAIL 3
120 #define ADIS16400_DIAG_STAT_FLASH_UPT 2
121 #define ADIS16400_DIAG_STAT_POWER_HIGH 1
122 #define ADIS16400_DIAG_STAT_POWER_LOW 0
125 #define ADIS16400_GLOB_CMD_SW_RESET (1<<7)
126 #define ADIS16400_GLOB_CMD_P_AUTO_NULL (1<<4)
127 #define ADIS16400_GLOB_CMD_FLASH_UPD (1<<3)
128 #define ADIS16400_GLOB_CMD_DAC_LATCH (1<<2)
129 #define ADIS16400_GLOB_CMD_FAC_CALIB (1<<1)
130 #define ADIS16400_GLOB_CMD_AUTO_NULL (1<<0)
133 #define ADIS16400_SLP_CNT_POWER_OFF (1<<8)
135 #define ADIS16334_RATE_DIV_SHIFT 8
136 #define ADIS16334_RATE_INT_CLK BIT(0)
138 #define ADIS16400_SPI_SLOW (u32)(300 * 1000)
139 #define ADIS16400_SPI_BURST (u32)(1000 * 1000)
140 #define ADIS16400_SPI_FAST (u32)(2000 * 1000)
142 #define ADIS16400_HAS_PROD_ID BIT(0)
143 #define ADIS16400_NO_BURST BIT(1)
144 #define ADIS16400_HAS_SLOW_MODE BIT(2)
145 #define ADIS16400_HAS_SERIAL_NUMBER BIT(3)
146 #define ADIS16400_BURST_DIAG_STAT BIT(4)
148 struct adis16400_state
;
150 struct adis16400_chip_info
{
151 const struct iio_chan_spec
*channels
;
152 const struct adis_data adis_data
;
153 const int num_channels
;
155 unsigned int gyro_scale_micro
;
156 unsigned int accel_scale_micro
;
159 /* set_freq() & get_freq() need to avoid using ADIS lib's state lock */
160 int (*set_freq
)(struct adis16400_state
*st
, unsigned int freq
);
161 int (*get_freq
)(struct adis16400_state
*st
);
165 * struct adis16400_state - device instance specific data
166 * @variant: chip variant info
167 * @filt_int: integer part of requested filter frequency
169 * @avail_scan_mask: NULL terminated array of bitmaps of channels
170 * that must be enabled together
172 struct adis16400_state
{
173 struct adis16400_chip_info
*variant
;
177 unsigned long avail_scan_mask
[2];
180 /* At the moment triggers are only used for ring buffer
181 * filling. This may change!
185 ADIS16400_SCAN_SUPPLY
,
186 ADIS16400_SCAN_GYRO_X
,
187 ADIS16400_SCAN_GYRO_Y
,
188 ADIS16400_SCAN_GYRO_Z
,
189 ADIS16400_SCAN_ACC_X
,
190 ADIS16400_SCAN_ACC_Y
,
191 ADIS16400_SCAN_ACC_Z
,
192 ADIS16400_SCAN_MAGN_X
,
193 ADIS16400_SCAN_MAGN_Y
,
194 ADIS16400_SCAN_MAGN_Z
,
196 ADIS16350_SCAN_TEMP_X
,
197 ADIS16350_SCAN_TEMP_Y
,
198 ADIS16350_SCAN_TEMP_Z
,
199 ADIS16300_SCAN_INCLI_X
,
200 ADIS16300_SCAN_INCLI_Y
,
202 ADIS16400_SCAN_TIMESTAMP
,
205 static ssize_t
adis16400_show_serial_number(struct file
*file
,
206 char __user
*userbuf
, size_t count
, loff_t
*ppos
)
208 struct adis16400_state
*st
= file
->private_data
;
209 u16 lot1
, lot2
, serial_number
;
214 ret
= adis_read_reg_16(&st
->adis
, ADIS16334_LOT_ID1
, &lot1
);
218 ret
= adis_read_reg_16(&st
->adis
, ADIS16334_LOT_ID2
, &lot2
);
222 ret
= adis_read_reg_16(&st
->adis
, ADIS16334_SERIAL_NUMBER
,
227 len
= snprintf(buf
, sizeof(buf
), "%.4x-%.4x-%.4x\n", lot1
, lot2
,
230 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, len
);
233 static const struct file_operations adis16400_serial_number_fops
= {
235 .read
= adis16400_show_serial_number
,
236 .llseek
= default_llseek
,
237 .owner
= THIS_MODULE
,
240 static int adis16400_show_product_id(void *arg
, u64
*val
)
242 struct adis16400_state
*st
= arg
;
246 ret
= adis_read_reg_16(&st
->adis
, ADIS16400_PRODUCT_ID
, &prod_id
);
254 DEFINE_DEBUGFS_ATTRIBUTE(adis16400_product_id_fops
,
255 adis16400_show_product_id
, NULL
, "%lld\n");
257 static int adis16400_show_flash_count(void *arg
, u64
*val
)
259 struct adis16400_state
*st
= arg
;
260 uint16_t flash_count
;
263 ret
= adis_read_reg_16(&st
->adis
, ADIS16400_FLASH_CNT
, &flash_count
);
271 DEFINE_DEBUGFS_ATTRIBUTE(adis16400_flash_count_fops
,
272 adis16400_show_flash_count
, NULL
, "%lld\n");
274 static void adis16400_debugfs_init(struct iio_dev
*indio_dev
)
276 struct adis16400_state
*st
= iio_priv(indio_dev
);
277 struct dentry
*d
= iio_get_debugfs_dentry(indio_dev
);
279 if (!IS_ENABLED(CONFIG_DEBUG_FS
))
282 if (st
->variant
->flags
& ADIS16400_HAS_SERIAL_NUMBER
)
283 debugfs_create_file_unsafe("serial_number", 0400,
284 d
, st
, &adis16400_serial_number_fops
);
285 if (st
->variant
->flags
& ADIS16400_HAS_PROD_ID
)
286 debugfs_create_file_unsafe("product_id", 0400,
287 d
, st
, &adis16400_product_id_fops
);
288 debugfs_create_file_unsafe("flash_count", 0400,
289 d
, st
, &adis16400_flash_count_fops
);
292 enum adis16400_chip_variant
{
305 static int adis16334_get_freq(struct adis16400_state
*st
)
310 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, &t
);
314 t
>>= ADIS16334_RATE_DIV_SHIFT
;
319 static int adis16334_set_freq(struct adis16400_state
*st
, unsigned int freq
)
324 t
= ilog2(819200 / freq
);
331 t
<<= ADIS16334_RATE_DIV_SHIFT
;
332 t
|= ADIS16334_RATE_INT_CLK
;
334 return __adis_write_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, t
);
337 static int adis16400_get_freq(struct adis16400_state
*st
)
342 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, &t
);
346 sps
= (t
& ADIS16400_SMPL_PRD_TIME_BASE
) ? 52851 : 1638404;
347 sps
/= (t
& ADIS16400_SMPL_PRD_DIV_MASK
) + 1;
352 static int adis16400_set_freq(struct adis16400_state
*st
, unsigned int freq
)
359 val
|= ADIS16400_SMPL_PRD_TIME_BASE
;
369 if (t
>= 0x0A || (val
& ADIS16400_SMPL_PRD_TIME_BASE
))
370 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_SLOW
;
372 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_FAST
;
374 return __adis_write_reg_8(&st
->adis
, ADIS16400_SMPL_PRD
, val
);
377 static const unsigned int adis16400_3db_divisors
[] = {
378 [0] = 2, /* Special case */
385 [7] = 200, /* Not a valid setting */
388 static int __adis16400_set_filter(struct iio_dev
*indio_dev
, int sps
, int val
)
390 struct adis16400_state
*st
= iio_priv(indio_dev
);
394 for (i
= ARRAY_SIZE(adis16400_3db_divisors
) - 1; i
>= 1; i
--) {
395 if (sps
/ adis16400_3db_divisors
[i
] >= val
)
399 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SENS_AVG
, &val16
);
403 ret
= __adis_write_reg_16(&st
->adis
, ADIS16400_SENS_AVG
,
404 (val16
& ~0x07) | i
);
408 /* Power down the device */
409 static int adis16400_stop_device(struct iio_dev
*indio_dev
)
411 struct adis16400_state
*st
= iio_priv(indio_dev
);
414 ret
= adis_write_reg_16(&st
->adis
, ADIS16400_SLP_CNT
,
415 ADIS16400_SLP_CNT_POWER_OFF
);
417 dev_err(&indio_dev
->dev
,
418 "problem with turning device off: SLP_CNT");
423 static int adis16400_initial_setup(struct iio_dev
*indio_dev
)
425 struct adis16400_state
*st
= iio_priv(indio_dev
);
426 uint16_t prod_id
, smp_prd
;
427 unsigned int device_id
;
430 /* use low spi speed for init if the device has a slow mode */
431 if (st
->variant
->flags
& ADIS16400_HAS_SLOW_MODE
)
432 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_SLOW
;
434 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_FAST
;
435 st
->adis
.spi
->mode
= SPI_MODE_3
;
436 spi_setup(st
->adis
.spi
);
438 ret
= __adis_initial_startup(&st
->adis
);
442 if (st
->variant
->flags
& ADIS16400_HAS_PROD_ID
) {
443 ret
= adis_read_reg_16(&st
->adis
,
444 ADIS16400_PRODUCT_ID
, &prod_id
);
448 if (sscanf(indio_dev
->name
, "adis%u\n", &device_id
) != 1) {
453 if (prod_id
!= device_id
)
454 dev_warn(&indio_dev
->dev
, "Device ID(%u) and product ID(%u) do not match.",
457 dev_info(&indio_dev
->dev
, "%s: prod_id 0x%04x at CS%d (irq %d)\n",
458 indio_dev
->name
, prod_id
,
459 spi_get_chipselect(st
->adis
.spi
, 0), st
->adis
.spi
->irq
);
461 /* use high spi speed if possible */
462 if (st
->variant
->flags
& ADIS16400_HAS_SLOW_MODE
) {
463 ret
= adis_read_reg_16(&st
->adis
, ADIS16400_SMPL_PRD
, &smp_prd
);
467 if ((smp_prd
& ADIS16400_SMPL_PRD_DIV_MASK
) < 0x0A) {
468 st
->adis
.spi
->max_speed_hz
= ADIS16400_SPI_FAST
;
469 spi_setup(st
->adis
.spi
);
477 static const uint8_t adis16400_addresses
[] = {
478 [ADIS16400_SCAN_GYRO_X
] = ADIS16400_XGYRO_OFF
,
479 [ADIS16400_SCAN_GYRO_Y
] = ADIS16400_YGYRO_OFF
,
480 [ADIS16400_SCAN_GYRO_Z
] = ADIS16400_ZGYRO_OFF
,
481 [ADIS16400_SCAN_ACC_X
] = ADIS16400_XACCL_OFF
,
482 [ADIS16400_SCAN_ACC_Y
] = ADIS16400_YACCL_OFF
,
483 [ADIS16400_SCAN_ACC_Z
] = ADIS16400_ZACCL_OFF
,
486 static int adis16400_write_raw(struct iio_dev
*indio_dev
,
487 struct iio_chan_spec
const *chan
, int val
, int val2
, long info
)
489 struct adis16400_state
*st
= iio_priv(indio_dev
);
493 case IIO_CHAN_INFO_CALIBBIAS
:
494 return adis_write_reg_16(&st
->adis
,
495 adis16400_addresses
[chan
->scan_index
],
497 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY
:
499 * Need to cache values so we can update if the frequency
502 adis_dev_auto_scoped_lock(&st
->adis
) {
504 /* Work out update to current value */
505 sps
= st
->variant
->get_freq(st
);
509 return __adis16400_set_filter(indio_dev
, sps
,
510 val
* 1000 + val2
/ 1000);
513 case IIO_CHAN_INFO_SAMP_FREQ
:
514 sps
= val
* 1000 + val2
/ 1000;
519 adis_dev_auto_scoped_lock(&st
->adis
)
520 return st
->variant
->set_freq(st
, sps
);
527 static int adis16400_read_raw(struct iio_dev
*indio_dev
,
528 struct iio_chan_spec
const *chan
, int *val
, int *val2
, long info
)
530 struct adis16400_state
*st
= iio_priv(indio_dev
);
535 case IIO_CHAN_INFO_RAW
:
536 return adis_single_conversion(indio_dev
, chan
, 0, val
);
537 case IIO_CHAN_INFO_SCALE
:
538 switch (chan
->type
) {
541 *val2
= st
->variant
->gyro_scale_micro
;
542 return IIO_VAL_INT_PLUS_MICRO
;
545 if (chan
->channel
== 0) {
547 *val2
= 418000; /* 2.418 mV */
550 *val2
= 805800; /* 805.8 uV */
552 return IIO_VAL_INT_PLUS_MICRO
;
555 *val2
= st
->variant
->accel_scale_micro
;
556 return IIO_VAL_INT_PLUS_MICRO
;
559 *val2
= 500; /* 0.5 mgauss */
560 return IIO_VAL_INT_PLUS_MICRO
;
562 *val
= st
->variant
->temp_scale_nano
/ 1000000;
563 *val2
= (st
->variant
->temp_scale_nano
% 1000000);
564 return IIO_VAL_INT_PLUS_MICRO
;
566 /* 20 uBar = 0.002kPascal */
569 return IIO_VAL_INT_PLUS_MICRO
;
573 case IIO_CHAN_INFO_CALIBBIAS
:
574 ret
= adis_read_reg_16(&st
->adis
,
575 adis16400_addresses
[chan
->scan_index
], &val16
);
578 val16
= sign_extend32(val16
, 11);
581 case IIO_CHAN_INFO_OFFSET
:
582 /* currently only temperature */
583 *val
= st
->variant
->temp_offset
;
585 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY
:
586 adis_dev_auto_scoped_lock(&st
->adis
) {
588 * Need both the number of taps and the sampling
591 ret
= __adis_read_reg_16(&st
->adis
, ADIS16400_SENS_AVG
,
596 ret
= st
->variant
->get_freq(st
);
600 ret
/= adis16400_3db_divisors
[val16
& 0x07];
602 *val2
= (ret
% 1000) * 1000;
603 return IIO_VAL_INT_PLUS_MICRO
;
604 case IIO_CHAN_INFO_SAMP_FREQ
:
605 adis_dev_auto_scoped_lock(&st
->adis
) {
606 ret
= st
->variant
->get_freq(st
);
611 *val2
= (ret
% 1000) * 1000;
612 return IIO_VAL_INT_PLUS_MICRO
;
618 #if IS_ENABLED(CONFIG_IIO_BUFFER)
619 static irqreturn_t
adis16400_trigger_handler(int irq
, void *p
)
621 struct iio_poll_func
*pf
= p
;
622 struct iio_dev
*indio_dev
= pf
->indio_dev
;
623 struct adis16400_state
*st
= iio_priv(indio_dev
);
624 struct adis
*adis
= &st
->adis
;
628 ret
= spi_sync(adis
->spi
, &adis
->msg
);
630 dev_err(&adis
->spi
->dev
, "Failed to read data: %d\n", ret
);
632 if (st
->variant
->flags
& ADIS16400_BURST_DIAG_STAT
) {
633 buffer
= adis
->buffer
+ sizeof(u16
);
635 * The size here is always larger than, or equal to the true
636 * size of the channel data. This may result in a larger copy
637 * than necessary, but as the target buffer will be
638 * buffer->scan_bytes this will be safe.
640 iio_push_to_buffers_with_ts_unaligned(indio_dev
, buffer
,
641 indio_dev
->scan_bytes
- sizeof(pf
->timestamp
),
644 iio_push_to_buffers_with_timestamp(indio_dev
,
650 iio_trigger_notify_done(indio_dev
->trig
);
655 #define adis16400_trigger_handler NULL
656 #endif /* IS_ENABLED(CONFIG_IIO_BUFFER) */
658 #define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si, chn) { \
659 .type = IIO_VOLTAGE, \
662 .extend_name = name, \
663 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
664 BIT(IIO_CHAN_INFO_SCALE), \
665 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
667 .scan_index = (si), \
670 .realbits = (bits), \
673 .endianness = IIO_BE, \
677 #define ADIS16400_SUPPLY_CHAN(addr, bits) \
678 ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY, 0)
680 #define ADIS16400_AUX_ADC_CHAN(addr, bits) \
681 ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC, 1)
683 #define ADIS16400_GYRO_CHAN(mod, addr, bits) { \
684 .type = IIO_ANGL_VEL, \
686 .channel2 = IIO_MOD_ ## mod, \
687 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
688 BIT(IIO_CHAN_INFO_CALIBBIAS), \
689 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
690 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
691 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
693 .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \
696 .realbits = (bits), \
699 .endianness = IIO_BE, \
703 #define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \
706 .channel2 = IIO_MOD_ ## mod, \
707 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
708 BIT(IIO_CHAN_INFO_CALIBBIAS), \
709 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
710 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
711 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
713 .scan_index = ADIS16400_SCAN_ACC_ ## mod, \
716 .realbits = (bits), \
719 .endianness = IIO_BE, \
723 #define ADIS16400_MAGN_CHAN(mod, addr, bits) { \
726 .channel2 = IIO_MOD_ ## mod, \
727 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
728 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
729 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
730 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
732 .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \
735 .realbits = (bits), \
738 .endianness = IIO_BE, \
742 #define ADIS16400_MOD_TEMP_NAME_X "x"
743 #define ADIS16400_MOD_TEMP_NAME_Y "y"
744 #define ADIS16400_MOD_TEMP_NAME_Z "z"
746 #define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \
750 .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \
751 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
752 BIT(IIO_CHAN_INFO_OFFSET) | \
753 BIT(IIO_CHAN_INFO_SCALE), \
754 .info_mask_shared_by_type = \
755 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
756 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
758 .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \
761 .realbits = (bits), \
764 .endianness = IIO_BE, \
768 #define ADIS16400_TEMP_CHAN(addr, bits) { \
772 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
773 BIT(IIO_CHAN_INFO_OFFSET) | \
774 BIT(IIO_CHAN_INFO_SCALE), \
775 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
777 .scan_index = ADIS16350_SCAN_TEMP_X, \
780 .realbits = (bits), \
783 .endianness = IIO_BE, \
787 #define ADIS16400_INCLI_CHAN(mod, addr, bits) { \
790 .channel2 = IIO_MOD_ ## mod, \
791 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
792 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
793 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
795 .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \
798 .realbits = (bits), \
801 .endianness = IIO_BE, \
805 static const struct iio_chan_spec adis16400_channels
[] = {
806 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT
, 14),
807 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
808 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 14),
809 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 14),
810 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
811 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
812 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
813 ADIS16400_MAGN_CHAN(X
, ADIS16400_XMAGN_OUT
, 14),
814 ADIS16400_MAGN_CHAN(Y
, ADIS16400_YMAGN_OUT
, 14),
815 ADIS16400_MAGN_CHAN(Z
, ADIS16400_ZMAGN_OUT
, 14),
816 ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT
, 12),
817 ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC
, 12),
818 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
821 static const struct iio_chan_spec adis16445_channels
[] = {
822 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 16),
823 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 16),
824 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 16),
825 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 16),
826 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 16),
827 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 16),
828 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT
, 12),
829 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
832 static const struct iio_chan_spec adis16448_channels
[] = {
833 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 16),
834 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 16),
835 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 16),
836 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 16),
837 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 16),
838 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 16),
839 ADIS16400_MAGN_CHAN(X
, ADIS16400_XMAGN_OUT
, 16),
840 ADIS16400_MAGN_CHAN(Y
, ADIS16400_YMAGN_OUT
, 16),
841 ADIS16400_MAGN_CHAN(Z
, ADIS16400_ZMAGN_OUT
, 16),
843 .type
= IIO_PRESSURE
,
844 .info_mask_separate
= BIT(IIO_CHAN_INFO_RAW
),
845 .info_mask_shared_by_type
= BIT(IIO_CHAN_INFO_SCALE
),
846 .info_mask_shared_by_all
= BIT(IIO_CHAN_INFO_SAMP_FREQ
),
847 .address
= ADIS16448_BARO_OUT
,
848 .scan_index
= ADIS16400_SCAN_BARO
,
853 .endianness
= IIO_BE
,
856 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT
, 12),
857 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
860 static const struct iio_chan_spec adis16350_channels
[] = {
861 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT
, 12),
862 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
863 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 14),
864 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 14),
865 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
866 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
867 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
868 ADIS16400_MAGN_CHAN(X
, ADIS16400_XMAGN_OUT
, 14),
869 ADIS16400_MAGN_CHAN(Y
, ADIS16400_YMAGN_OUT
, 14),
870 ADIS16400_MAGN_CHAN(Z
, ADIS16400_ZMAGN_OUT
, 14),
871 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC
, 12),
872 ADIS16400_MOD_TEMP_CHAN(X
, ADIS16350_XTEMP_OUT
, 12),
873 ADIS16400_MOD_TEMP_CHAN(Y
, ADIS16350_YTEMP_OUT
, 12),
874 ADIS16400_MOD_TEMP_CHAN(Z
, ADIS16350_ZTEMP_OUT
, 12),
875 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
878 static const struct iio_chan_spec adis16300_channels
[] = {
879 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT
, 12),
880 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
881 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
882 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
883 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
884 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT
, 12),
885 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC
, 12),
886 ADIS16400_INCLI_CHAN(X
, ADIS16300_PITCH_OUT
, 13),
887 ADIS16400_INCLI_CHAN(Y
, ADIS16300_ROLL_OUT
, 13),
888 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
891 static const struct iio_chan_spec adis16334_channels
[] = {
892 ADIS16400_GYRO_CHAN(X
, ADIS16400_XGYRO_OUT
, 14),
893 ADIS16400_GYRO_CHAN(Y
, ADIS16400_YGYRO_OUT
, 14),
894 ADIS16400_GYRO_CHAN(Z
, ADIS16400_ZGYRO_OUT
, 14),
895 ADIS16400_ACCEL_CHAN(X
, ADIS16400_XACCL_OUT
, 14),
896 ADIS16400_ACCEL_CHAN(Y
, ADIS16400_YACCL_OUT
, 14),
897 ADIS16400_ACCEL_CHAN(Z
, ADIS16400_ZACCL_OUT
, 14),
898 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT
, 12),
899 IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP
),
902 static const char * const adis16400_status_error_msgs
[] = {
903 [ADIS16400_DIAG_STAT_ZACCL_FAIL
] = "Z-axis accelerometer self-test failure",
904 [ADIS16400_DIAG_STAT_YACCL_FAIL
] = "Y-axis accelerometer self-test failure",
905 [ADIS16400_DIAG_STAT_XACCL_FAIL
] = "X-axis accelerometer self-test failure",
906 [ADIS16400_DIAG_STAT_XGYRO_FAIL
] = "X-axis gyroscope self-test failure",
907 [ADIS16400_DIAG_STAT_YGYRO_FAIL
] = "Y-axis gyroscope self-test failure",
908 [ADIS16400_DIAG_STAT_ZGYRO_FAIL
] = "Z-axis gyroscope self-test failure",
909 [ADIS16400_DIAG_STAT_ALARM2
] = "Alarm 2 active",
910 [ADIS16400_DIAG_STAT_ALARM1
] = "Alarm 1 active",
911 [ADIS16400_DIAG_STAT_FLASH_CHK
] = "Flash checksum error",
912 [ADIS16400_DIAG_STAT_SELF_TEST
] = "Self test error",
913 [ADIS16400_DIAG_STAT_OVERFLOW
] = "Sensor overrange",
914 [ADIS16400_DIAG_STAT_SPI_FAIL
] = "SPI failure",
915 [ADIS16400_DIAG_STAT_FLASH_UPT
] = "Flash update failed",
916 [ADIS16400_DIAG_STAT_POWER_HIGH
] = "Power supply above 5.25V",
917 [ADIS16400_DIAG_STAT_POWER_LOW
] = "Power supply below 4.75V",
920 #define ADIS16400_DATA(_timeouts, _burst_len) \
922 .msc_ctrl_reg = ADIS16400_MSC_CTRL, \
923 .glob_cmd_reg = ADIS16400_GLOB_CMD, \
924 .diag_stat_reg = ADIS16400_DIAG_STAT, \
927 .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, \
928 .self_test_reg = ADIS16400_MSC_CTRL, \
929 .status_error_msgs = adis16400_status_error_msgs, \
930 .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | \
931 BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | \
932 BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | \
933 BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | \
934 BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | \
935 BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | \
936 BIT(ADIS16400_DIAG_STAT_ALARM2) | \
937 BIT(ADIS16400_DIAG_STAT_ALARM1) | \
938 BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | \
939 BIT(ADIS16400_DIAG_STAT_SELF_TEST) | \
940 BIT(ADIS16400_DIAG_STAT_OVERFLOW) | \
941 BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | \
942 BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | \
943 BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | \
944 BIT(ADIS16400_DIAG_STAT_POWER_LOW), \
945 .timeouts = (_timeouts), \
946 .burst_reg_cmd = ADIS16400_GLOB_CMD, \
947 .burst_len = (_burst_len), \
948 .burst_max_speed_hz = ADIS16400_SPI_BURST \
951 static const struct adis_timeout adis16300_timeouts
= {
952 .reset_ms
= ADIS16400_STARTUP_DELAY
,
953 .sw_reset_ms
= ADIS16400_STARTUP_DELAY
,
954 .self_test_ms
= ADIS16400_STARTUP_DELAY
,
957 static const struct adis_timeout adis16334_timeouts
= {
963 static const struct adis_timeout adis16362_timeouts
= {
969 static const struct adis_timeout adis16400_timeouts
= {
975 static const struct adis_timeout adis16445_timeouts
= {
981 static const struct adis_timeout adis16448_timeouts
= {
987 static struct adis16400_chip_info adis16400_chips
[] = {
989 .channels
= adis16300_channels
,
990 .num_channels
= ARRAY_SIZE(adis16300_channels
),
991 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
992 ADIS16400_HAS_SERIAL_NUMBER
,
993 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
994 .accel_scale_micro
= 5884,
995 .temp_scale_nano
= 140000000, /* 0.14 C */
996 .temp_offset
= 25000000 / 140000, /* 25 C = 0x00 */
997 .set_freq
= adis16400_set_freq
,
998 .get_freq
= adis16400_get_freq
,
999 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 18),
1002 .channels
= adis16334_channels
,
1003 .num_channels
= ARRAY_SIZE(adis16334_channels
),
1004 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_NO_BURST
|
1005 ADIS16400_HAS_SERIAL_NUMBER
,
1006 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1007 .accel_scale_micro
= IIO_G_TO_M_S_2(1000), /* 1 mg */
1008 .temp_scale_nano
= 67850000, /* 0.06785 C */
1009 .temp_offset
= 25000000 / 67850, /* 25 C = 0x00 */
1010 .set_freq
= adis16334_set_freq
,
1011 .get_freq
= adis16334_get_freq
,
1012 .adis_data
= ADIS16400_DATA(&adis16334_timeouts
, 0),
1015 .channels
= adis16350_channels
,
1016 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1017 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */
1018 .accel_scale_micro
= IIO_G_TO_M_S_2(2522), /* 0.002522 g */
1019 .temp_scale_nano
= 145300000, /* 0.1453 C */
1020 .temp_offset
= 25000000 / 145300, /* 25 C = 0x00 */
1021 .flags
= ADIS16400_NO_BURST
| ADIS16400_HAS_SLOW_MODE
,
1022 .set_freq
= adis16400_set_freq
,
1023 .get_freq
= adis16400_get_freq
,
1024 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 0),
1027 .channels
= adis16350_channels
,
1028 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1029 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1030 ADIS16400_HAS_SERIAL_NUMBER
,
1031 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1032 .accel_scale_micro
= IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1033 .temp_scale_nano
= 136000000, /* 0.136 C */
1034 .temp_offset
= 25000000 / 136000, /* 25 C = 0x00 */
1035 .set_freq
= adis16400_set_freq
,
1036 .get_freq
= adis16400_get_freq
,
1037 .adis_data
= ADIS16400_DATA(&adis16300_timeouts
, 28),
1040 .channels
= adis16350_channels
,
1041 .num_channels
= ARRAY_SIZE(adis16350_channels
),
1042 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
|
1043 ADIS16400_HAS_SERIAL_NUMBER
,
1044 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1045 .accel_scale_micro
= IIO_G_TO_M_S_2(333), /* 0.333 mg */
1046 .temp_scale_nano
= 136000000, /* 0.136 C */
1047 .temp_offset
= 25000000 / 136000, /* 25 C = 0x00 */
1048 .set_freq
= adis16400_set_freq
,
1049 .get_freq
= adis16400_get_freq
,
1050 .adis_data
= ADIS16400_DATA(&adis16362_timeouts
, 28),
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(1000), /* 1 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(&adis16362_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(2000), /* 0.2 deg/s */
1071 .accel_scale_micro
= IIO_G_TO_M_S_2(3333), /* 3.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(&adis16300_timeouts
, 28),
1079 .channels
= adis16400_channels
,
1080 .num_channels
= ARRAY_SIZE(adis16400_channels
),
1081 .flags
= ADIS16400_HAS_PROD_ID
| ADIS16400_HAS_SLOW_MODE
,
1082 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1083 .accel_scale_micro
= IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1084 .temp_scale_nano
= 140000000, /* 0.14 C */
1085 .temp_offset
= 25000000 / 140000, /* 25 C = 0x00 */
1086 .set_freq
= adis16400_set_freq
,
1087 .get_freq
= adis16400_get_freq
,
1088 .adis_data
= ADIS16400_DATA(&adis16400_timeouts
, 24),
1091 .channels
= adis16445_channels
,
1092 .num_channels
= ARRAY_SIZE(adis16445_channels
),
1093 .flags
= ADIS16400_HAS_PROD_ID
|
1094 ADIS16400_HAS_SERIAL_NUMBER
|
1095 ADIS16400_BURST_DIAG_STAT
,
1096 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
1097 .accel_scale_micro
= IIO_G_TO_M_S_2(250), /* 1/4000 g */
1098 .temp_scale_nano
= 73860000, /* 0.07386 C */
1099 .temp_offset
= 31000000 / 73860, /* 31 C = 0x00 */
1100 .set_freq
= adis16334_set_freq
,
1101 .get_freq
= adis16334_get_freq
,
1102 .adis_data
= ADIS16400_DATA(&adis16445_timeouts
, 16),
1105 .channels
= adis16448_channels
,
1106 .num_channels
= ARRAY_SIZE(adis16448_channels
),
1107 .flags
= ADIS16400_HAS_PROD_ID
|
1108 ADIS16400_HAS_SERIAL_NUMBER
|
1109 ADIS16400_BURST_DIAG_STAT
,
1110 .gyro_scale_micro
= IIO_DEGREE_TO_RAD(40000), /* 0.04 deg/s */
1111 .accel_scale_micro
= IIO_G_TO_M_S_2(833), /* 1/1200 g */
1112 .temp_scale_nano
= 73860000, /* 0.07386 C */
1113 .temp_offset
= 31000000 / 73860, /* 31 C = 0x00 */
1114 .set_freq
= adis16334_set_freq
,
1115 .get_freq
= adis16334_get_freq
,
1116 .adis_data
= ADIS16400_DATA(&adis16448_timeouts
, 24),
1120 static const struct iio_info adis16400_info
= {
1121 .read_raw
= &adis16400_read_raw
,
1122 .write_raw
= &adis16400_write_raw
,
1123 .update_scan_mode
= adis_update_scan_mode
,
1124 .debugfs_reg_access
= adis_debugfs_reg_access
,
1127 static void adis16400_setup_chan_mask(struct adis16400_state
*st
)
1129 const struct adis16400_chip_info
*chip_info
= st
->variant
;
1132 for (i
= 0; i
< chip_info
->num_channels
; i
++) {
1133 const struct iio_chan_spec
*ch
= &chip_info
->channels
[i
];
1135 if (ch
->scan_index
>= 0 &&
1136 ch
->scan_index
!= ADIS16400_SCAN_TIMESTAMP
)
1137 st
->avail_scan_mask
[0] |= BIT(ch
->scan_index
);
1141 static void adis16400_stop(void *data
)
1143 adis16400_stop_device(data
);
1146 static int adis16400_probe(struct spi_device
*spi
)
1148 struct adis16400_state
*st
;
1149 struct iio_dev
*indio_dev
;
1151 const struct adis_data
*adis16400_data
;
1153 indio_dev
= devm_iio_device_alloc(&spi
->dev
, sizeof(*st
));
1154 if (indio_dev
== NULL
)
1157 st
= iio_priv(indio_dev
);
1159 /* setup the industrialio driver allocated elements */
1160 st
->variant
= &adis16400_chips
[spi_get_device_id(spi
)->driver_data
];
1161 indio_dev
->name
= spi_get_device_id(spi
)->name
;
1162 indio_dev
->channels
= st
->variant
->channels
;
1163 indio_dev
->num_channels
= st
->variant
->num_channels
;
1164 indio_dev
->info
= &adis16400_info
;
1165 indio_dev
->modes
= INDIO_DIRECT_MODE
;
1167 if (!(st
->variant
->flags
& ADIS16400_NO_BURST
)) {
1168 adis16400_setup_chan_mask(st
);
1169 indio_dev
->available_scan_masks
= st
->avail_scan_mask
;
1172 adis16400_data
= &st
->variant
->adis_data
;
1174 ret
= adis_init(&st
->adis
, indio_dev
, spi
, adis16400_data
);
1178 ret
= devm_adis_setup_buffer_and_trigger(&st
->adis
, indio_dev
, adis16400_trigger_handler
);
1182 /* Get the device into a sane initial state */
1183 ret
= adis16400_initial_setup(indio_dev
);
1187 ret
= devm_add_action_or_reset(&spi
->dev
, adis16400_stop
, indio_dev
);
1191 ret
= devm_iio_device_register(&spi
->dev
, indio_dev
);
1195 adis16400_debugfs_init(indio_dev
);
1199 static const struct spi_device_id adis16400_id
[] = {
1200 {"adis16300", ADIS16300
},
1201 {"adis16305", ADIS16300
},
1202 {"adis16334", ADIS16334
},
1203 {"adis16350", ADIS16350
},
1204 {"adis16354", ADIS16350
},
1205 {"adis16355", ADIS16350
},
1206 {"adis16360", ADIS16360
},
1207 {"adis16362", ADIS16362
},
1208 {"adis16364", ADIS16364
},
1209 {"adis16365", ADIS16360
},
1210 {"adis16367", ADIS16367
},
1211 {"adis16400", ADIS16400
},
1212 {"adis16405", ADIS16400
},
1213 {"adis16445", ADIS16445
},
1214 {"adis16448", ADIS16448
},
1217 MODULE_DEVICE_TABLE(spi
, adis16400_id
);
1219 static struct spi_driver adis16400_driver
= {
1221 .name
= "adis16400",
1223 .id_table
= adis16400_id
,
1224 .probe
= adis16400_probe
,
1226 module_spi_driver(adis16400_driver
);
1228 MODULE_AUTHOR("Manuel Stahl <manuel.stahl@iis.fraunhofer.de>");
1229 MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver");
1230 MODULE_LICENSE("GPL v2");
1231 MODULE_IMPORT_NS("IIO_ADISLIB");