Thomas Gleixner | 80503b2 | 2019-05-24 12:04:09 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 2 | /* |
Reto Schneider | 58401bd | 2016-11-20 22:11:24 +0100 | [diff] [blame] | 3 | * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 4 | * |
| 5 | * Copyright 2010 Analog Devices Inc. |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 8 | #include <linux/device.h> |
| 9 | #include <linux/kernel.h> |
Shreeya Patel | 5824d09 | 2018-03-02 18:49:23 +0530 | [diff] [blame] | 10 | #include <linux/module.h> |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 11 | #include <linux/spi/spi.h> |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 12 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 13 | #include <linux/iio/iio.h> |
Lars-Peter Clausen | ec04cb0 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 14 | #include <linux/iio/imu/adis.h> |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 15 | |
Shreeya Patel | c97712c | 2018-03-02 18:53:41 +0530 | [diff] [blame] | 16 | #define ADIS16209_STARTUP_DELAY_MS 220 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 17 | #define ADIS16209_FLASH_CNT_REG 0x00 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 18 | |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 19 | /* Data Output Register Definitions */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 20 | #define ADIS16209_SUPPLY_OUT_REG 0x02 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 21 | #define ADIS16209_XACCL_OUT_REG 0x04 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 22 | #define ADIS16209_YACCL_OUT_REG 0x06 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 23 | /* Output, auxiliary ADC input */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 24 | #define ADIS16209_AUX_ADC_REG 0x08 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 25 | /* Output, temperature */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 26 | #define ADIS16209_TEMP_OUT_REG 0x0A |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 27 | /* Output, +/- 90 degrees X-axis inclination */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 28 | #define ADIS16209_XINCL_OUT_REG 0x0C |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 29 | #define ADIS16209_YINCL_OUT_REG 0x0E |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 30 | /* Output, +/-180 vertical rotational position */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 31 | #define ADIS16209_ROT_OUT_REG 0x10 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 32 | |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 33 | /* |
| 34 | * Calibration Register Definitions. |
| 35 | * Acceleration, inclination or rotation offset null. |
| 36 | */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 37 | #define ADIS16209_XACCL_NULL_REG 0x12 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 38 | #define ADIS16209_YACCL_NULL_REG 0x14 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 39 | #define ADIS16209_XINCL_NULL_REG 0x16 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 40 | #define ADIS16209_YINCL_NULL_REG 0x18 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 41 | #define ADIS16209_ROT_NULL_REG 0x1A |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 42 | |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 43 | /* Alarm Register Definitions */ |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 44 | #define ADIS16209_ALM_MAG1_REG 0x20 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 45 | #define ADIS16209_ALM_MAG2_REG 0x22 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 46 | #define ADIS16209_ALM_SMPL1_REG 0x24 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 47 | #define ADIS16209_ALM_SMPL2_REG 0x26 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 48 | #define ADIS16209_ALM_CTRL_REG 0x28 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 49 | |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 50 | #define ADIS16209_AUX_DAC_REG 0x30 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 51 | #define ADIS16209_GPIO_CTRL_REG 0x32 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 52 | #define ADIS16209_SMPL_PRD_REG 0x36 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 53 | #define ADIS16209_AVG_CNT_REG 0x38 |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 54 | #define ADIS16209_SLP_CNT_REG 0x3A |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 55 | |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 56 | #define ADIS16209_MSC_CTRL_REG 0x34 |
| 57 | #define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST BIT(10) |
| 58 | #define ADIS16209_MSC_CTRL_SELF_TEST_EN BIT(8) |
| 59 | #define ADIS16209_MSC_CTRL_DATA_RDY_EN BIT(2) |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 60 | /* Data-ready polarity: 1 = active high, 0 = active low */ |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 61 | #define ADIS16209_MSC_CTRL_ACTIVE_HIGH BIT(1) |
| 62 | #define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0) |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 63 | |
Shreeya Patel | 1026bb3 | 2018-03-04 18:11:17 +0530 | [diff] [blame] | 64 | #define ADIS16209_STAT_REG 0x3C |
| 65 | #define ADIS16209_STAT_ALARM2 BIT(9) |
| 66 | #define ADIS16209_STAT_ALARM1 BIT(8) |
Shreeya Patel | 55cdd2e | 2018-03-29 14:42:02 +0530 | [diff] [blame] | 67 | #define ADIS16209_STAT_SELFTEST_FAIL_BIT 5 |
| 68 | #define ADIS16209_STAT_SPI_FAIL_BIT 3 |
| 69 | #define ADIS16209_STAT_FLASH_UPT_FAIL_BIT 2 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 70 | /* Power supply above 3.625 V */ |
Shreeya Patel | 55cdd2e | 2018-03-29 14:42:02 +0530 | [diff] [blame] | 71 | #define ADIS16209_STAT_POWER_HIGH_BIT 1 |
Alexandru Ardelean | 10dd571 | 2019-06-25 15:48:40 +0300 | [diff] [blame] | 72 | /* Power supply below 2.975 V */ |
Shreeya Patel | 55cdd2e | 2018-03-29 14:42:02 +0530 | [diff] [blame] | 73 | #define ADIS16209_STAT_POWER_LOW_BIT 0 |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 74 | |
Shreeya Patel | 1026bb3 | 2018-03-04 18:11:17 +0530 | [diff] [blame] | 75 | #define ADIS16209_CMD_REG 0x3E |
| 76 | #define ADIS16209_CMD_SW_RESET BIT(7) |
| 77 | #define ADIS16209_CMD_CLEAR_STAT BIT(4) |
| 78 | #define ADIS16209_CMD_FACTORY_CAL BIT(1) |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 79 | |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 80 | #define ADIS16209_ERROR_ACTIVE BIT(14) |
Narcisa Ana Maria Vasile | 21a123b | 2017-03-04 15:47:08 +0200 | [diff] [blame] | 81 | |
Narcisa Ana Maria Vasile | a3b2ce9 | 2017-03-05 18:26:41 +0200 | [diff] [blame] | 82 | enum adis16209_scan { |
| 83 | ADIS16209_SCAN_SUPPLY, |
| 84 | ADIS16209_SCAN_ACC_X, |
| 85 | ADIS16209_SCAN_ACC_Y, |
| 86 | ADIS16209_SCAN_AUX_ADC, |
| 87 | ADIS16209_SCAN_TEMP, |
| 88 | ADIS16209_SCAN_INCLI_X, |
| 89 | ADIS16209_SCAN_INCLI_Y, |
| 90 | ADIS16209_SCAN_ROT, |
| 91 | }; |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 92 | |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 93 | static const u8 adis16209_addresses[8][1] = { |
| 94 | [ADIS16209_SCAN_SUPPLY] = { }, |
| 95 | [ADIS16209_SCAN_AUX_ADC] = { }, |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 96 | [ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL_REG }, |
| 97 | [ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL_REG }, |
| 98 | [ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL_REG }, |
| 99 | [ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL_REG }, |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 100 | [ADIS16209_SCAN_ROT] = { }, |
| 101 | [ADIS16209_SCAN_TEMP] = { }, |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 102 | }; |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 103 | |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 104 | static int adis16209_write_raw(struct iio_dev *indio_dev, |
| 105 | struct iio_chan_spec const *chan, |
| 106 | int val, |
| 107 | int val2, |
| 108 | long mask) |
| 109 | { |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 110 | struct adis *st = iio_priv(indio_dev); |
Shreeya Patel | abb0708 | 2018-03-29 14:51:19 +0530 | [diff] [blame] | 111 | int m; |
Murilo Opsfelder Araujo | d7b7951 | 2014-07-08 01:22:00 +0100 | [diff] [blame] | 112 | |
Shreeya Patel | abb0708 | 2018-03-29 14:51:19 +0530 | [diff] [blame] | 113 | if (mask != IIO_CHAN_INFO_CALIBBIAS) |
| 114 | return -EINVAL; |
| 115 | |
| 116 | switch (chan->type) { |
| 117 | case IIO_ACCEL: |
| 118 | case IIO_INCLI: |
| 119 | m = GENMASK(13, 0); |
| 120 | break; |
| 121 | default: |
| 122 | return -EINVAL; |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 123 | } |
Shreeya Patel | abb0708 | 2018-03-29 14:51:19 +0530 | [diff] [blame] | 124 | |
| 125 | return adis_write_reg_16(st, adis16209_addresses[chan->scan_index][0], |
| 126 | val & m); |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 127 | } |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 128 | |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 129 | static int adis16209_read_raw(struct iio_dev *indio_dev, |
| 130 | struct iio_chan_spec const *chan, |
| 131 | int *val, int *val2, |
| 132 | long mask) |
| 133 | { |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 134 | struct adis *st = iio_priv(indio_dev); |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 135 | int ret; |
| 136 | int bits; |
| 137 | u8 addr; |
| 138 | s16 val16; |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 139 | |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 140 | switch (mask) { |
Jonathan Cameron | 31313fc | 2012-04-15 17:41:17 +0100 | [diff] [blame] | 141 | case IIO_CHAN_INFO_RAW: |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 142 | return adis_single_conversion(indio_dev, chan, |
| 143 | ADIS16209_ERROR_ACTIVE, val); |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 144 | case IIO_CHAN_INFO_SCALE: |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 145 | switch (chan->type) { |
Jonathan Cameron | 6835cb6 | 2011-09-27 09:56:41 +0100 | [diff] [blame] | 146 | case IIO_VOLTAGE: |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 147 | *val = 0; |
Shreeya Patel | 0df8bae | 2018-03-04 18:13:12 +0530 | [diff] [blame] | 148 | switch (chan->channel) { |
| 149 | case 0: |
Lars-Peter Clausen | d5304b7 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 150 | *val2 = 305180; /* 0.30518 mV */ |
Shreeya Patel | 0df8bae | 2018-03-04 18:13:12 +0530 | [diff] [blame] | 151 | break; |
| 152 | case 1: |
Lars-Peter Clausen | d5304b7 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 153 | *val2 = 610500; /* 0.6105 mV */ |
Shreeya Patel | 0df8bae | 2018-03-04 18:13:12 +0530 | [diff] [blame] | 154 | break; |
| 155 | default: |
| 156 | return -EINVAL; |
| 157 | } |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 158 | return IIO_VAL_INT_PLUS_MICRO; |
| 159 | case IIO_TEMP: |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 160 | *val = -470; |
Lars-Peter Clausen | d5304b7 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 161 | *val2 = 0; |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 162 | return IIO_VAL_INT_PLUS_MICRO; |
| 163 | case IIO_ACCEL: |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 164 | /* |
| 165 | * IIO base unit for sensitivity of accelerometer |
| 166 | * is milli g. |
| 167 | * 1 LSB represents 0.244 mg. |
| 168 | */ |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 169 | *val = 0; |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 170 | *val2 = IIO_G_TO_M_S_2(244140); |
Lars-Peter Clausen | d5304b7 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 171 | return IIO_VAL_INT_PLUS_NANO; |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 172 | case IIO_INCLI: |
Lars-Peter Clausen | d5304b7 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 173 | case IIO_ROT: |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 174 | /* |
| 175 | * IIO base units for rotation are degrees. |
| 176 | * 1 LSB represents 0.025 milli degrees. |
| 177 | */ |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 178 | *val = 0; |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 179 | *val2 = 25000; |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 180 | return IIO_VAL_INT_PLUS_MICRO; |
| 181 | default: |
| 182 | return -EINVAL; |
| 183 | } |
| 184 | break; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 185 | case IIO_CHAN_INFO_OFFSET: |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 186 | /* |
| 187 | * The raw ADC value is 0x4FE when the temperature |
Shreeya Patel | 524c762 | 2018-03-29 14:52:51 +0530 | [diff] [blame] | 188 | * is 45 degrees and the scale factor per milli |
Shreeya Patel | f3cfe18 | 2018-03-04 18:06:22 +0530 | [diff] [blame] | 189 | * degree celcius is -470. |
| 190 | */ |
| 191 | *val = 25000 / -470 - 0x4FE; |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 192 | return IIO_VAL_INT; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 193 | case IIO_CHAN_INFO_CALIBBIAS: |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 194 | switch (chan->type) { |
| 195 | case IIO_ACCEL: |
| 196 | bits = 14; |
| 197 | break; |
| 198 | default: |
| 199 | return -EINVAL; |
Peter Senna Tschudin | 73327b4 | 2012-09-28 10:57:00 +0100 | [diff] [blame] | 200 | } |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 201 | addr = adis16209_addresses[chan->scan_index][0]; |
| 202 | ret = adis_read_reg_16(st, addr, &val16); |
Mark Stenglein | baecc57 | 2017-03-23 02:18:12 -0400 | [diff] [blame] | 203 | if (ret) |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 204 | return ret; |
Shreeya Patel | 9dd6ec1 | 2018-03-04 18:15:06 +0530 | [diff] [blame] | 205 | |
| 206 | *val = sign_extend32(val16, bits - 1); |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 207 | return IIO_VAL_INT; |
| 208 | } |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 212 | static const struct iio_chan_spec adis16209_channels[] = { |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 213 | ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT_REG, ADIS16209_SCAN_SUPPLY, |
| 214 | 0, 14), |
| 215 | ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT_REG, ADIS16209_SCAN_TEMP, 0, 12), |
| 216 | ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT_REG, ADIS16209_SCAN_ACC_X, |
Haneen Mohammed | 9963bce | 2015-03-25 10:51:55 +0300 | [diff] [blame] | 217 | BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 218 | ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT_REG, ADIS16209_SCAN_ACC_Y, |
Haneen Mohammed | 9963bce | 2015-03-25 10:51:55 +0300 | [diff] [blame] | 219 | BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 220 | ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC_REG, ADIS16209_SCAN_AUX_ADC, 0, 12), |
| 221 | ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT_REG, ADIS16209_SCAN_INCLI_X, |
Haneen Mohammed | 9963bce | 2015-03-25 10:51:55 +0300 | [diff] [blame] | 222 | 0, 0, 14), |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 223 | ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT_REG, ADIS16209_SCAN_INCLI_Y, |
Haneen Mohammed | 9963bce | 2015-03-25 10:51:55 +0300 | [diff] [blame] | 224 | 0, 0, 14), |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 225 | ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT_REG, ADIS16209_SCAN_ROT, 0, 0, 14), |
Jonathan Cameron | a34c26dc | 2011-05-18 14:41:49 +0100 | [diff] [blame] | 226 | IIO_CHAN_SOFT_TIMESTAMP(8) |
| 227 | }; |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 228 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 229 | static const struct iio_info adis16209_info = { |
simran singhal | ebfb115 | 2017-03-11 19:56:41 +0530 | [diff] [blame] | 230 | .read_raw = adis16209_read_raw, |
| 231 | .write_raw = adis16209_write_raw, |
Lars-Peter Clausen | aacff89 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 232 | .update_scan_mode = adis_update_scan_mode, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 233 | }; |
| 234 | |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 235 | static const char * const adis16209_status_error_msgs[] = { |
Shreeya Patel | 1026bb3 | 2018-03-04 18:11:17 +0530 | [diff] [blame] | 236 | [ADIS16209_STAT_SELFTEST_FAIL_BIT] = "Self test failure", |
| 237 | [ADIS16209_STAT_SPI_FAIL_BIT] = "SPI failure", |
| 238 | [ADIS16209_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed", |
| 239 | [ADIS16209_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", |
Alexandru Ardelean | 10dd571 | 2019-06-25 15:48:40 +0300 | [diff] [blame] | 240 | [ADIS16209_STAT_POWER_LOW_BIT] = "Power supply below 2.975V", |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
Nuno Sá | 380b107 | 2020-01-07 13:17:04 +0200 | [diff] [blame] | 243 | static const struct adis_timeout adis16209_timeouts = { |
| 244 | .reset_ms = ADIS16209_STARTUP_DELAY_MS, |
| 245 | .self_test_ms = ADIS16209_STARTUP_DELAY_MS, |
| 246 | .sw_reset_ms = ADIS16209_STARTUP_DELAY_MS, |
| 247 | }; |
| 248 | |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 249 | static const struct adis_data adis16209_data = { |
| 250 | .read_delay = 30, |
Shreeya Patel | 200905f | 2018-03-02 18:55:56 +0530 | [diff] [blame] | 251 | .msc_ctrl_reg = ADIS16209_MSC_CTRL_REG, |
Shreeya Patel | 1026bb3 | 2018-03-04 18:11:17 +0530 | [diff] [blame] | 252 | .glob_cmd_reg = ADIS16209_CMD_REG, |
| 253 | .diag_stat_reg = ADIS16209_STAT_REG, |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 254 | |
| 255 | .self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN, |
Nuno Sá | fdcf6bb | 2020-02-10 15:26:02 +0200 | [diff] [blame] | 256 | .self_test_reg = ADIS16209_MSC_CTRL_REG, |
Lars-Peter Clausen | 5d116ed | 2016-04-15 16:59:41 +0200 | [diff] [blame] | 257 | .self_test_no_autoclear = true, |
Nuno Sá | 380b107 | 2020-01-07 13:17:04 +0200 | [diff] [blame] | 258 | .timeouts = &adis16209_timeouts, |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 259 | |
| 260 | .status_error_msgs = adis16209_status_error_msgs, |
Shreeya Patel | 1026bb3 | 2018-03-04 18:11:17 +0530 | [diff] [blame] | 261 | .status_error_mask = BIT(ADIS16209_STAT_SELFTEST_FAIL_BIT) | |
| 262 | BIT(ADIS16209_STAT_SPI_FAIL_BIT) | |
| 263 | BIT(ADIS16209_STAT_FLASH_UPT_FAIL_BIT) | |
| 264 | BIT(ADIS16209_STAT_POWER_HIGH_BIT) | |
| 265 | BIT(ADIS16209_STAT_POWER_LOW_BIT), |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 266 | }; |
| 267 | |
Bill Pemberton | 4ae1c61 | 2012-11-19 13:21:57 -0500 | [diff] [blame] | 268 | static int adis16209_probe(struct spi_device *spi) |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 269 | { |
Jonathan Cameron | 35212df | 2011-06-27 13:07:13 +0100 | [diff] [blame] | 270 | struct iio_dev *indio_dev; |
Shreeya Patel | 0a9d5dc | 2018-03-29 14:43:23 +0530 | [diff] [blame] | 271 | struct adis *st; |
| 272 | int ret; |
Jonathan Cameron | 35212df | 2011-06-27 13:07:13 +0100 | [diff] [blame] | 273 | |
Sachin Kamat | 864bf5c | 2013-08-24 19:48:00 +0100 | [diff] [blame] | 274 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
| 275 | if (!indio_dev) |
| 276 | return -ENOMEM; |
Shreeya Patel | ec41877 | 2018-03-29 14:44:42 +0530 | [diff] [blame] | 277 | |
Jonathan Cameron | 35212df | 2011-06-27 13:07:13 +0100 | [diff] [blame] | 278 | st = iio_priv(indio_dev); |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 279 | |
Jonathan Cameron | 35212df | 2011-06-27 13:07:13 +0100 | [diff] [blame] | 280 | indio_dev->name = spi->dev.driver->name; |
Jonathan Cameron | 35212df | 2011-06-27 13:07:13 +0100 | [diff] [blame] | 281 | indio_dev->info = &adis16209_info; |
| 282 | indio_dev->channels = adis16209_channels; |
| 283 | indio_dev->num_channels = ARRAY_SIZE(adis16209_channels); |
| 284 | indio_dev->modes = INDIO_DIRECT_MODE; |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 285 | |
Lars-Peter Clausen | 511fb29 | 2012-11-13 13:28:00 +0000 | [diff] [blame] | 286 | ret = adis_init(st, indio_dev, spi, &adis16209_data); |
| 287 | if (ret) |
Sachin Kamat | 864bf5c | 2013-08-24 19:48:00 +0100 | [diff] [blame] | 288 | return ret; |
Shreeya Patel | ec41877 | 2018-03-29 14:44:42 +0530 | [diff] [blame] | 289 | |
Nuno Sá | 17ff204 | 2020-09-15 14:02:50 +0200 | [diff] [blame] | 290 | ret = devm_adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 291 | if (ret) |
Sachin Kamat | 864bf5c | 2013-08-24 19:48:00 +0100 | [diff] [blame] | 292 | return ret; |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 293 | |
Ramona Bolboaca | 09f8360 | 2022-11-22 10:27:51 +0200 | [diff] [blame] | 294 | ret = __adis_initial_startup(st); |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 295 | if (ret) |
Nuno Sá | 17ff204 | 2020-09-15 14:02:50 +0200 | [diff] [blame] | 296 | return ret; |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 297 | |
Nuno Sá | 17ff204 | 2020-09-15 14:02:50 +0200 | [diff] [blame] | 298 | return devm_iio_device_register(&spi->dev, indio_dev); |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static struct spi_driver adis16209_driver = { |
| 302 | .driver = { |
| 303 | .name = "adis16209", |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 304 | }, |
| 305 | .probe = adis16209_probe, |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 306 | }; |
Lars-Peter Clausen | ae6ae6f | 2011-11-16 10:13:39 +0100 | [diff] [blame] | 307 | module_spi_driver(adis16209_driver); |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 308 | |
| 309 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); |
Reto Schneider | 58401bd | 2016-11-20 22:11:24 +0100 | [diff] [blame] | 310 | MODULE_DESCRIPTION("Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer"); |
Barry Song | 671ece1 | 2010-05-07 15:38:59 +0100 | [diff] [blame] | 311 | MODULE_LICENSE("GPL v2"); |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 312 | MODULE_ALIAS("spi:adis16209"); |
Jonathan Cameron | 6c9304d | 2022-01-30 20:56:53 +0000 | [diff] [blame] | 313 | MODULE_IMPORT_NS(IIO_ADISLIB); |