Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * adis16400.c support Analog Devices ADIS16400/5 |
| 3 | * 3d 2g Linear Accelerometers, |
| 4 | * 3d Gyroscopes, |
| 5 | * 3d Magnetometers via SPI |
| 6 | * |
| 7 | * Copyright (c) 2009 Manuel Stahl <manuel.stahl@iis.fraunhofer.de> |
Jonathan Cameron | 0f8c962 | 2012-09-02 21:34:59 +0100 | [diff] [blame] | 8 | * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org> |
Michael Hennerich | 6a6ec62 | 2011-03-21 16:44:40 +0100 | [diff] [blame] | 9 | * Copyright (c) 2011 Analog Devices Inc. |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/irq.h> |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/mutex.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/spi/spi.h> |
Mike Frysinger | 1cb6c1f | 2010-05-23 03:10:35 -0400 | [diff] [blame] | 24 | #include <linux/slab.h> |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 25 | #include <linux/sysfs.h> |
| 26 | #include <linux/list.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 28 | #include <linux/debugfs.h> |
Rasmus Villemoes | 19e353f | 2015-01-23 00:34:02 +0100 | [diff] [blame] | 29 | #include <linux/bitops.h> |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 30 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 31 | #include <linux/iio/iio.h> |
| 32 | #include <linux/iio/sysfs.h> |
| 33 | #include <linux/iio/buffer.h> |
Alexandru Ardelean | 74878d4 | 2019-03-22 22:44:38 +0200 | [diff] [blame] | 34 | #include <linux/iio/trigger_consumer.h> |
Alexandru Ardelean | 3cb5161 | 2019-03-22 22:44:42 +0200 | [diff] [blame] | 35 | #include <linux/iio/imu/adis.h> |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 36 | |
Alexandru Ardelean | 3cb5161 | 2019-03-22 22:44:42 +0200 | [diff] [blame] | 37 | #define ADIS16400_STARTUP_DELAY 290 /* ms */ |
| 38 | #define ADIS16400_MTEST_DELAY 90 /* ms */ |
| 39 | |
| 40 | #define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */ |
| 41 | #define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */ |
| 42 | #define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */ |
| 43 | #define ADIS16400_YGYRO_OUT 0x06 /* Y-axis gyroscope output */ |
| 44 | #define ADIS16400_ZGYRO_OUT 0x08 /* Z-axis gyroscope output */ |
| 45 | #define ADIS16400_XACCL_OUT 0x0A /* X-axis accelerometer output */ |
| 46 | #define ADIS16400_YACCL_OUT 0x0C /* Y-axis accelerometer output */ |
| 47 | #define ADIS16400_ZACCL_OUT 0x0E /* Z-axis accelerometer output */ |
| 48 | #define ADIS16400_XMAGN_OUT 0x10 /* X-axis magnetometer measurement */ |
| 49 | #define ADIS16400_YMAGN_OUT 0x12 /* Y-axis magnetometer measurement */ |
| 50 | #define ADIS16400_ZMAGN_OUT 0x14 /* Z-axis magnetometer measurement */ |
| 51 | #define ADIS16400_TEMP_OUT 0x16 /* Temperature output */ |
| 52 | #define ADIS16400_AUX_ADC 0x18 /* Auxiliary ADC measurement */ |
| 53 | |
| 54 | #define ADIS16350_XTEMP_OUT 0x10 /* X-axis gyroscope temperature measurement */ |
| 55 | #define ADIS16350_YTEMP_OUT 0x12 /* Y-axis gyroscope temperature measurement */ |
| 56 | #define ADIS16350_ZTEMP_OUT 0x14 /* Z-axis gyroscope temperature measurement */ |
| 57 | |
| 58 | #define ADIS16300_PITCH_OUT 0x12 /* X axis inclinometer output measurement */ |
| 59 | #define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */ |
| 60 | #define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */ |
| 61 | |
| 62 | #define ADIS16448_BARO_OUT 0x16 /* Barometric pressure output */ |
| 63 | #define ADIS16448_TEMP_OUT 0x18 /* Temperature output */ |
| 64 | |
| 65 | /* Calibration parameters */ |
| 66 | #define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */ |
| 67 | #define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */ |
| 68 | #define ADIS16400_ZGYRO_OFF 0x1E /* Z-axis gyroscope bias offset factor */ |
| 69 | #define ADIS16400_XACCL_OFF 0x20 /* X-axis acceleration bias offset factor */ |
| 70 | #define ADIS16400_YACCL_OFF 0x22 /* Y-axis acceleration bias offset factor */ |
| 71 | #define ADIS16400_ZACCL_OFF 0x24 /* Z-axis acceleration bias offset factor */ |
| 72 | #define ADIS16400_XMAGN_HIF 0x26 /* X-axis magnetometer, hard-iron factor */ |
| 73 | #define ADIS16400_YMAGN_HIF 0x28 /* Y-axis magnetometer, hard-iron factor */ |
| 74 | #define ADIS16400_ZMAGN_HIF 0x2A /* Z-axis magnetometer, hard-iron factor */ |
| 75 | #define ADIS16400_XMAGN_SIF 0x2C /* X-axis magnetometer, soft-iron factor */ |
| 76 | #define ADIS16400_YMAGN_SIF 0x2E /* Y-axis magnetometer, soft-iron factor */ |
| 77 | #define ADIS16400_ZMAGN_SIF 0x30 /* Z-axis magnetometer, soft-iron factor */ |
| 78 | |
| 79 | #define ADIS16400_GPIO_CTRL 0x32 /* Auxiliary digital input/output control */ |
| 80 | #define ADIS16400_MSC_CTRL 0x34 /* Miscellaneous control */ |
| 81 | #define ADIS16400_SMPL_PRD 0x36 /* Internal sample period (rate) control */ |
| 82 | #define ADIS16400_SENS_AVG 0x38 /* Dynamic range and digital filter control */ |
| 83 | #define ADIS16400_SLP_CNT 0x3A /* Sleep mode control */ |
| 84 | #define ADIS16400_DIAG_STAT 0x3C /* System status */ |
| 85 | |
| 86 | /* Alarm functions */ |
| 87 | #define ADIS16400_GLOB_CMD 0x3E /* System command */ |
| 88 | #define ADIS16400_ALM_MAG1 0x40 /* Alarm 1 amplitude threshold */ |
| 89 | #define ADIS16400_ALM_MAG2 0x42 /* Alarm 2 amplitude threshold */ |
| 90 | #define ADIS16400_ALM_SMPL1 0x44 /* Alarm 1 sample size */ |
| 91 | #define ADIS16400_ALM_SMPL2 0x46 /* Alarm 2 sample size */ |
| 92 | #define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ |
| 93 | #define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ |
| 94 | |
| 95 | #define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */ |
| 96 | #define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */ |
| 97 | #define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ |
| 98 | #define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */ |
| 99 | |
| 100 | #define ADIS16400_ERROR_ACTIVE (1<<14) |
| 101 | #define ADIS16400_NEW_DATA (1<<14) |
| 102 | |
| 103 | /* MSC_CTRL */ |
| 104 | #define ADIS16400_MSC_CTRL_MEM_TEST (1<<11) |
| 105 | #define ADIS16400_MSC_CTRL_INT_SELF_TEST (1<<10) |
| 106 | #define ADIS16400_MSC_CTRL_NEG_SELF_TEST (1<<9) |
| 107 | #define ADIS16400_MSC_CTRL_POS_SELF_TEST (1<<8) |
| 108 | #define ADIS16400_MSC_CTRL_GYRO_BIAS (1<<7) |
| 109 | #define ADIS16400_MSC_CTRL_ACCL_ALIGN (1<<6) |
| 110 | #define ADIS16400_MSC_CTRL_DATA_RDY_EN (1<<2) |
| 111 | #define ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1) |
| 112 | #define ADIS16400_MSC_CTRL_DATA_RDY_DIO2 (1<<0) |
| 113 | |
| 114 | /* SMPL_PRD */ |
| 115 | #define ADIS16400_SMPL_PRD_TIME_BASE (1<<7) |
| 116 | #define ADIS16400_SMPL_PRD_DIV_MASK 0x7F |
| 117 | |
| 118 | /* DIAG_STAT */ |
| 119 | #define ADIS16400_DIAG_STAT_ZACCL_FAIL 15 |
| 120 | #define ADIS16400_DIAG_STAT_YACCL_FAIL 14 |
| 121 | #define ADIS16400_DIAG_STAT_XACCL_FAIL 13 |
| 122 | #define ADIS16400_DIAG_STAT_XGYRO_FAIL 12 |
| 123 | #define ADIS16400_DIAG_STAT_YGYRO_FAIL 11 |
| 124 | #define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10 |
| 125 | #define ADIS16400_DIAG_STAT_ALARM2 9 |
| 126 | #define ADIS16400_DIAG_STAT_ALARM1 8 |
| 127 | #define ADIS16400_DIAG_STAT_FLASH_CHK 6 |
| 128 | #define ADIS16400_DIAG_STAT_SELF_TEST 5 |
| 129 | #define ADIS16400_DIAG_STAT_OVERFLOW 4 |
| 130 | #define ADIS16400_DIAG_STAT_SPI_FAIL 3 |
| 131 | #define ADIS16400_DIAG_STAT_FLASH_UPT 2 |
| 132 | #define ADIS16400_DIAG_STAT_POWER_HIGH 1 |
| 133 | #define ADIS16400_DIAG_STAT_POWER_LOW 0 |
| 134 | |
| 135 | /* GLOB_CMD */ |
| 136 | #define ADIS16400_GLOB_CMD_SW_RESET (1<<7) |
| 137 | #define ADIS16400_GLOB_CMD_P_AUTO_NULL (1<<4) |
| 138 | #define ADIS16400_GLOB_CMD_FLASH_UPD (1<<3) |
| 139 | #define ADIS16400_GLOB_CMD_DAC_LATCH (1<<2) |
| 140 | #define ADIS16400_GLOB_CMD_FAC_CALIB (1<<1) |
| 141 | #define ADIS16400_GLOB_CMD_AUTO_NULL (1<<0) |
| 142 | |
| 143 | /* SLP_CNT */ |
| 144 | #define ADIS16400_SLP_CNT_POWER_OFF (1<<8) |
| 145 | |
| 146 | #define ADIS16334_RATE_DIV_SHIFT 8 |
| 147 | #define ADIS16334_RATE_INT_CLK BIT(0) |
| 148 | |
| 149 | #define ADIS16400_SPI_SLOW (u32)(300 * 1000) |
| 150 | #define ADIS16400_SPI_BURST (u32)(1000 * 1000) |
| 151 | #define ADIS16400_SPI_FAST (u32)(2000 * 1000) |
| 152 | |
| 153 | #define ADIS16400_HAS_PROD_ID BIT(0) |
| 154 | #define ADIS16400_NO_BURST BIT(1) |
| 155 | #define ADIS16400_HAS_SLOW_MODE BIT(2) |
| 156 | #define ADIS16400_HAS_SERIAL_NUMBER BIT(3) |
| 157 | #define ADIS16400_BURST_DIAG_STAT BIT(4) |
| 158 | |
| 159 | struct adis16400_state; |
| 160 | |
| 161 | struct adis16400_chip_info { |
| 162 | const struct iio_chan_spec *channels; |
| 163 | const int num_channels; |
| 164 | const long flags; |
| 165 | unsigned int gyro_scale_micro; |
| 166 | unsigned int accel_scale_micro; |
| 167 | int temp_scale_nano; |
| 168 | int temp_offset; |
| 169 | int (*set_freq)(struct adis16400_state *st, unsigned int freq); |
| 170 | int (*get_freq)(struct adis16400_state *st); |
| 171 | }; |
| 172 | |
| 173 | /** |
| 174 | * struct adis16400_state - device instance specific data |
| 175 | * @variant: chip variant info |
| 176 | * @filt_int: integer part of requested filter frequency |
| 177 | * @adis: adis device |
| 178 | **/ |
| 179 | struct adis16400_state { |
| 180 | struct adis16400_chip_info *variant; |
| 181 | int filt_int; |
| 182 | |
| 183 | struct adis adis; |
| 184 | unsigned long avail_scan_mask[2]; |
| 185 | }; |
| 186 | |
| 187 | /* At the moment triggers are only used for ring buffer |
| 188 | * filling. This may change! |
| 189 | */ |
| 190 | |
| 191 | enum { |
| 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, |
| 202 | ADIS16400_SCAN_BARO, |
| 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, |
| 208 | ADIS16400_SCAN_ADC, |
| 209 | ADIS16400_SCAN_TIMESTAMP, |
| 210 | }; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 211 | |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 212 | #ifdef CONFIG_DEBUG_FS |
| 213 | |
| 214 | static ssize_t adis16400_show_serial_number(struct file *file, |
| 215 | char __user *userbuf, size_t count, loff_t *ppos) |
| 216 | { |
| 217 | struct adis16400_state *st = file->private_data; |
| 218 | u16 lot1, lot2, serial_number; |
| 219 | char buf[16]; |
| 220 | size_t len; |
| 221 | int ret; |
| 222 | |
| 223 | ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1); |
| 224 | if (ret < 0) |
| 225 | return ret; |
| 226 | |
| 227 | ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2); |
| 228 | if (ret < 0) |
| 229 | return ret; |
| 230 | |
| 231 | ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER, |
| 232 | &serial_number); |
| 233 | if (ret < 0) |
| 234 | return ret; |
| 235 | |
| 236 | len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2, |
| 237 | serial_number); |
| 238 | |
| 239 | return simple_read_from_buffer(userbuf, count, ppos, buf, len); |
| 240 | } |
| 241 | |
| 242 | static const struct file_operations adis16400_serial_number_fops = { |
| 243 | .open = simple_open, |
| 244 | .read = adis16400_show_serial_number, |
| 245 | .llseek = default_llseek, |
| 246 | .owner = THIS_MODULE, |
| 247 | }; |
| 248 | |
| 249 | static int adis16400_show_product_id(void *arg, u64 *val) |
| 250 | { |
| 251 | struct adis16400_state *st = arg; |
| 252 | uint16_t prod_id; |
| 253 | int ret; |
| 254 | |
| 255 | ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id); |
| 256 | if (ret < 0) |
| 257 | return ret; |
| 258 | |
| 259 | *val = prod_id; |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops, |
| 264 | adis16400_show_product_id, NULL, "%lld\n"); |
| 265 | |
| 266 | static int adis16400_show_flash_count(void *arg, u64 *val) |
| 267 | { |
| 268 | struct adis16400_state *st = arg; |
| 269 | uint16_t flash_count; |
| 270 | int ret; |
| 271 | |
| 272 | ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count); |
| 273 | if (ret < 0) |
| 274 | return ret; |
| 275 | |
| 276 | *val = flash_count; |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops, |
| 281 | adis16400_show_flash_count, NULL, "%lld\n"); |
| 282 | |
| 283 | static int adis16400_debugfs_init(struct iio_dev *indio_dev) |
| 284 | { |
| 285 | struct adis16400_state *st = iio_priv(indio_dev); |
| 286 | |
| 287 | if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER) |
| 288 | debugfs_create_file("serial_number", 0400, |
| 289 | indio_dev->debugfs_dentry, st, |
| 290 | &adis16400_serial_number_fops); |
| 291 | if (st->variant->flags & ADIS16400_HAS_PROD_ID) |
| 292 | debugfs_create_file("product_id", 0400, |
| 293 | indio_dev->debugfs_dentry, st, |
| 294 | &adis16400_product_id_fops); |
| 295 | debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry, |
| 296 | st, &adis16400_flash_count_fops); |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | #else |
| 302 | |
| 303 | static int adis16400_debugfs_init(struct iio_dev *indio_dev) |
| 304 | { |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | #endif |
| 309 | |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 310 | enum adis16400_chip_variant { |
Jonathan Cameron | 8e886e6 | 2011-05-18 14:41:30 +0100 | [diff] [blame] | 311 | ADIS16300, |
Jonathan Cameron | 85da505 | 2011-09-30 10:05:45 +0100 | [diff] [blame] | 312 | ADIS16334, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 313 | ADIS16350, |
| 314 | ADIS16360, |
| 315 | ADIS16362, |
| 316 | ADIS16364, |
Lars-Peter Clausen | dc8615c | 2015-08-05 15:38:19 +0200 | [diff] [blame] | 317 | ADIS16367, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 318 | ADIS16400, |
Lars-Peter Clausen | 72d9c98 | 2015-08-05 15:38:20 +0200 | [diff] [blame] | 319 | ADIS16445, |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 320 | ADIS16448, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 321 | }; |
| 322 | |
Alexandru Ardelean | 5075e07 | 2019-03-22 22:44:39 +0200 | [diff] [blame] | 323 | static struct adis_burst adis16400_burst = { |
| 324 | .en = true, |
| 325 | .reg_cmd = ADIS16400_GLOB_CMD, |
| 326 | }; |
| 327 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 328 | static int adis16334_get_freq(struct adis16400_state *st) |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 329 | { |
| 330 | int ret; |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 331 | uint16_t t; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 332 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 333 | ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 334 | if (ret < 0) |
| 335 | return ret; |
| 336 | |
| 337 | t >>= ADIS16334_RATE_DIV_SHIFT; |
| 338 | |
Lars-Peter Clausen | b24150e | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 339 | return 819200 >> t; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 342 | static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 343 | { |
| 344 | unsigned int t; |
| 345 | |
Lars-Peter Clausen | b24150e | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 346 | if (freq < 819200) |
| 347 | t = ilog2(819200 / freq); |
Lars-Peter Clausen | 06220b8 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 348 | else |
| 349 | t = 0; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 350 | |
| 351 | if (t > 0x31) |
| 352 | t = 0x31; |
| 353 | |
| 354 | t <<= ADIS16334_RATE_DIV_SHIFT; |
| 355 | t |= ADIS16334_RATE_INT_CLK; |
| 356 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 357 | return adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t); |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 360 | static int adis16400_get_freq(struct adis16400_state *st) |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 361 | { |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 362 | int sps, ret; |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 363 | uint16_t t; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 364 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 365 | ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t); |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 366 | if (ret < 0) |
| 367 | return ret; |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 368 | |
Lars-Peter Clausen | b24150e | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 369 | sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 52851 : 1638404; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 370 | sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; |
| 371 | |
| 372 | return sps; |
| 373 | } |
| 374 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 375 | static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 376 | { |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 377 | unsigned int t; |
Lars-Peter Clausen | 7ba8a04 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 378 | uint8_t val = 0; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 379 | |
Lars-Peter Clausen | b24150e | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 380 | t = 1638404 / freq; |
Lars-Peter Clausen | 7ba8a04 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 381 | if (t >= 128) { |
| 382 | val |= ADIS16400_SMPL_PRD_TIME_BASE; |
| 383 | t = 52851 / freq; |
| 384 | if (t >= 128) |
| 385 | t = 127; |
| 386 | } else if (t != 0) { |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 387 | t--; |
Lars-Peter Clausen | 7ba8a04 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 388 | } |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 389 | |
Lars-Peter Clausen | 7ba8a04 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 390 | val |= t; |
| 391 | |
| 392 | if (t >= 0x0A || (val & ADIS16400_SMPL_PRD_TIME_BASE)) |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 393 | st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 394 | else |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 395 | st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 396 | |
Lars-Peter Clausen | 7ba8a04 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 397 | return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val); |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Reno Farnesi | aab498b | 2017-07-01 17:54:08 -0400 | [diff] [blame] | 400 | static const unsigned int adis16400_3db_divisors[] = { |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 401 | [0] = 2, /* Special case */ |
Lars-Peter Clausen | bdb20bd | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 402 | [1] = 6, |
| 403 | [2] = 12, |
| 404 | [3] = 25, |
| 405 | [4] = 50, |
| 406 | [5] = 100, |
| 407 | [6] = 200, |
| 408 | [7] = 200, /* Not a valid setting */ |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) |
| 412 | { |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 413 | struct adis16400_state *st = iio_priv(indio_dev); |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 414 | uint16_t val16; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 415 | int i, ret; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 416 | |
Lars-Peter Clausen | bdb20bd | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 417 | for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) { |
| 418 | if (sps / adis16400_3db_divisors[i] >= val) |
| 419 | break; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 420 | } |
Lars-Peter Clausen | bdb20bd | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 421 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 422 | ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16); |
Lars-Peter Clausen | bdb20bd | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 423 | if (ret < 0) |
| 424 | return ret; |
| 425 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 426 | ret = adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG, |
Lars-Peter Clausen | bdb20bd | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 427 | (val16 & ~0x07) | i); |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 428 | return ret; |
| 429 | } |
| 430 | |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 431 | /* Power down the device */ |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 432 | static int adis16400_stop_device(struct iio_dev *indio_dev) |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 433 | { |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 434 | struct adis16400_state *st = iio_priv(indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 435 | int ret; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 436 | |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 437 | ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT, |
| 438 | ADIS16400_SLP_CNT_POWER_OFF); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 439 | if (ret) |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 440 | dev_err(&indio_dev->dev, |
| 441 | "problem with turning device off: SLP_CNT"); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 442 | |
| 443 | return ret; |
| 444 | } |
| 445 | |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 446 | static int adis16400_initial_setup(struct iio_dev *indio_dev) |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 447 | { |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 448 | struct adis16400_state *st = iio_priv(indio_dev); |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 449 | uint16_t prod_id, smp_prd; |
| 450 | unsigned int device_id; |
| 451 | int ret; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 452 | |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 453 | /* use low spi speed for init if the device has a slow mode */ |
| 454 | if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 455 | st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW; |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 456 | else |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 457 | st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; |
| 458 | st->adis.spi->mode = SPI_MODE_3; |
| 459 | spi_setup(st->adis.spi); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 460 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 461 | ret = adis_initial_startup(&st->adis); |
| 462 | if (ret) |
| 463 | return ret; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 464 | |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 465 | if (st->variant->flags & ADIS16400_HAS_PROD_ID) { |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 466 | ret = adis_read_reg_16(&st->adis, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 467 | ADIS16400_PRODUCT_ID, &prod_id); |
| 468 | if (ret) |
| 469 | goto err_ret; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 470 | |
Ioana Ciornei | 72a868b | 2015-11-01 14:58:45 +0200 | [diff] [blame] | 471 | ret = sscanf(indio_dev->name, "adis%u\n", &device_id); |
| 472 | if (ret != 1) { |
| 473 | ret = -EINVAL; |
| 474 | goto err_ret; |
| 475 | } |
Lars-Peter Clausen | fc8850c | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 476 | |
| 477 | if (prod_id != device_id) |
| 478 | dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.", |
| 479 | device_id, prod_id); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 480 | |
Michael Hennerich | 69d80ba | 2011-09-02 17:25:34 +0100 | [diff] [blame] | 481 | dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n", |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 482 | indio_dev->name, prod_id, |
| 483 | st->adis.spi->chip_select, st->adis.spi->irq); |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 484 | } |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 485 | /* use high spi speed if possible */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 486 | if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) { |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 487 | ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd); |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 488 | if (ret) |
| 489 | goto err_ret; |
| 490 | |
| 491 | if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 492 | st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST; |
| 493 | spi_setup(st->adis.spi); |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 494 | } |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 497 | err_ret: |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 498 | return ret; |
| 499 | } |
| 500 | |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 501 | static const uint8_t adis16400_addresses[] = { |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 502 | [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF, |
| 503 | [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF, |
| 504 | [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF, |
| 505 | [ADIS16400_SCAN_ACC_X] = ADIS16400_XACCL_OFF, |
| 506 | [ADIS16400_SCAN_ACC_Y] = ADIS16400_YACCL_OFF, |
| 507 | [ADIS16400_SCAN_ACC_Z] = ADIS16400_ZACCL_OFF, |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 508 | }; |
| 509 | |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 510 | static int adis16400_write_raw(struct iio_dev *indio_dev, |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 511 | struct iio_chan_spec const *chan, int val, int val2, long info) |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 512 | { |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 513 | struct adis16400_state *st = iio_priv(indio_dev); |
| 514 | int ret, sps; |
Jonathan Cameron | 521de51 | 2011-09-02 17:25:33 +0100 | [diff] [blame] | 515 | |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 516 | switch (info) { |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 517 | case IIO_CHAN_INFO_CALIBBIAS: |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 518 | mutex_lock(&indio_dev->mlock); |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 519 | ret = adis_write_reg_16(&st->adis, |
| 520 | adis16400_addresses[chan->scan_index], val); |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 521 | mutex_unlock(&indio_dev->mlock); |
| 522 | return ret; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 523 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 524 | /* |
| 525 | * Need to cache values so we can update if the frequency |
| 526 | * changes. |
| 527 | */ |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 528 | mutex_lock(&indio_dev->mlock); |
| 529 | st->filt_int = val; |
| 530 | /* Work out update to current value */ |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 531 | sps = st->variant->get_freq(st); |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 532 | if (sps < 0) { |
| 533 | mutex_unlock(&indio_dev->mlock); |
| 534 | return sps; |
| 535 | } |
| 536 | |
Lars-Peter Clausen | b24150e | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 537 | ret = adis16400_set_filter(indio_dev, sps, |
| 538 | val * 1000 + val2 / 1000); |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 539 | mutex_unlock(&indio_dev->mlock); |
| 540 | return ret; |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 541 | case IIO_CHAN_INFO_SAMP_FREQ: |
| 542 | sps = val * 1000 + val2 / 1000; |
| 543 | |
| 544 | if (sps <= 0) |
| 545 | return -EINVAL; |
| 546 | |
| 547 | mutex_lock(&indio_dev->mlock); |
| 548 | ret = st->variant->set_freq(st, sps); |
| 549 | mutex_unlock(&indio_dev->mlock); |
| 550 | return ret; |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 551 | default: |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | static int adis16400_read_raw(struct iio_dev *indio_dev, |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 557 | struct iio_chan_spec const *chan, int *val, int *val2, long info) |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 558 | { |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 559 | struct adis16400_state *st = iio_priv(indio_dev); |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 560 | int16_t val16; |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 561 | int ret; |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 562 | |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 563 | switch (info) { |
Jonathan Cameron | a5d016d | 2012-04-15 17:41:21 +0100 | [diff] [blame] | 564 | case IIO_CHAN_INFO_RAW: |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 565 | return adis_single_conversion(indio_dev, chan, 0, val); |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 566 | case IIO_CHAN_INFO_SCALE: |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 567 | switch (chan->type) { |
Jonathan Cameron | 41ea040 | 2011-10-05 15:27:59 +0100 | [diff] [blame] | 568 | case IIO_ANGL_VEL: |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 569 | *val = 0; |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 570 | *val2 = st->variant->gyro_scale_micro; |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 571 | return IIO_VAL_INT_PLUS_MICRO; |
Jonathan Cameron | 6835cb6 | 2011-09-27 09:56:41 +0100 | [diff] [blame] | 572 | case IIO_VOLTAGE: |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 573 | *val = 0; |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 574 | if (chan->channel == 0) { |
| 575 | *val = 2; |
| 576 | *val2 = 418000; /* 2.418 mV */ |
| 577 | } else { |
| 578 | *val = 0; |
| 579 | *val2 = 805800; /* 805.8 uV */ |
| 580 | } |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 581 | return IIO_VAL_INT_PLUS_MICRO; |
| 582 | case IIO_ACCEL: |
| 583 | *val = 0; |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 584 | *val2 = st->variant->accel_scale_micro; |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 585 | return IIO_VAL_INT_PLUS_MICRO; |
| 586 | case IIO_MAGN: |
| 587 | *val = 0; |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 588 | *val2 = 500; /* 0.5 mgauss */ |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 589 | return IIO_VAL_INT_PLUS_MICRO; |
| 590 | case IIO_TEMP: |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 591 | *val = st->variant->temp_scale_nano / 1000000; |
| 592 | *val2 = (st->variant->temp_scale_nano % 1000000); |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 593 | return IIO_VAL_INT_PLUS_MICRO; |
Lars-Peter Clausen | 69ca2d7 | 2015-05-15 17:18:34 +0200 | [diff] [blame] | 594 | case IIO_PRESSURE: |
| 595 | /* 20 uBar = 0.002kPascal */ |
| 596 | *val = 0; |
| 597 | *val2 = 2000; |
| 598 | return IIO_VAL_INT_PLUS_MICRO; |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 599 | default: |
| 600 | return -EINVAL; |
| 601 | } |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 602 | case IIO_CHAN_INFO_CALIBBIAS: |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 603 | mutex_lock(&indio_dev->mlock); |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 604 | ret = adis_read_reg_16(&st->adis, |
| 605 | adis16400_addresses[chan->scan_index], &val16); |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 606 | mutex_unlock(&indio_dev->mlock); |
| 607 | if (ret) |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 608 | return ret; |
Rasmus Villemoes | 19e353f | 2015-01-23 00:34:02 +0100 | [diff] [blame] | 609 | val16 = sign_extend32(val16, 11); |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 610 | *val = val16; |
| 611 | return IIO_VAL_INT; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 612 | case IIO_CHAN_INFO_OFFSET: |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 613 | /* currently only temperature */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 614 | *val = st->variant->temp_offset; |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 615 | return IIO_VAL_INT; |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 616 | case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: |
| 617 | mutex_lock(&indio_dev->mlock); |
| 618 | /* Need both the number of taps and the sampling frequency */ |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 619 | ret = adis_read_reg_16(&st->adis, |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 620 | ADIS16400_SENS_AVG, |
| 621 | &val16); |
| 622 | if (ret < 0) { |
| 623 | mutex_unlock(&indio_dev->mlock); |
| 624 | return ret; |
| 625 | } |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 626 | ret = st->variant->get_freq(st); |
Lars-Peter Clausen | b24150e | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 627 | if (ret >= 0) { |
| 628 | ret /= adis16400_3db_divisors[val16 & 0x07]; |
| 629 | *val = ret / 1000; |
| 630 | *val2 = (ret % 1000) * 1000; |
| 631 | } |
Jonathan Cameron | 98c9373 | 2011-11-27 11:39:13 +0000 | [diff] [blame] | 632 | mutex_unlock(&indio_dev->mlock); |
| 633 | if (ret < 0) |
| 634 | return ret; |
| 635 | return IIO_VAL_INT_PLUS_MICRO; |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 636 | case IIO_CHAN_INFO_SAMP_FREQ: |
| 637 | ret = st->variant->get_freq(st); |
| 638 | if (ret < 0) |
| 639 | return ret; |
| 640 | *val = ret / 1000; |
| 641 | *val2 = (ret % 1000) * 1000; |
| 642 | return IIO_VAL_INT_PLUS_MICRO; |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 643 | default: |
| 644 | return -EINVAL; |
| 645 | } |
| 646 | } |
| 647 | |
Alexandru Ardelean | 74878d4 | 2019-03-22 22:44:38 +0200 | [diff] [blame] | 648 | #if IS_ENABLED(CONFIG_IIO_BUFFER) |
| 649 | static irqreturn_t adis16400_trigger_handler(int irq, void *p) |
| 650 | { |
| 651 | struct iio_poll_func *pf = p; |
| 652 | struct iio_dev *indio_dev = pf->indio_dev; |
| 653 | struct adis16400_state *st = iio_priv(indio_dev); |
| 654 | struct adis *adis = &st->adis; |
| 655 | u32 old_speed_hz = st->adis.spi->max_speed_hz; |
| 656 | void *buffer; |
| 657 | int ret; |
| 658 | |
| 659 | if (!adis->buffer) |
| 660 | return -ENOMEM; |
| 661 | |
| 662 | if (!(st->variant->flags & ADIS16400_NO_BURST) && |
| 663 | st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) { |
| 664 | st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST; |
| 665 | spi_setup(st->adis.spi); |
| 666 | } |
| 667 | |
| 668 | ret = spi_sync(adis->spi, &adis->msg); |
| 669 | if (ret) |
| 670 | dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); |
| 671 | |
| 672 | if (!(st->variant->flags & ADIS16400_NO_BURST)) { |
| 673 | st->adis.spi->max_speed_hz = old_speed_hz; |
| 674 | spi_setup(st->adis.spi); |
| 675 | } |
| 676 | |
| 677 | if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) |
| 678 | buffer = adis->buffer + sizeof(u16); |
| 679 | else |
| 680 | buffer = adis->buffer; |
| 681 | |
| 682 | iio_push_to_buffers_with_timestamp(indio_dev, buffer, |
| 683 | pf->timestamp); |
| 684 | |
| 685 | iio_trigger_notify_done(indio_dev->trig); |
| 686 | |
| 687 | return IRQ_HANDLED; |
| 688 | } |
| 689 | #else |
| 690 | #define adis16400_trigger_handler NULL |
| 691 | #endif /* IS_ENABLED(CONFIG_IIO_BUFFER) */ |
| 692 | |
Paul Cercueil | 7323d59 | 2015-05-15 17:18:35 +0200 | [diff] [blame] | 693 | #define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si, chn) { \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 694 | .type = IIO_VOLTAGE, \ |
| 695 | .indexed = 1, \ |
Paul Cercueil | 7323d59 | 2015-05-15 17:18:35 +0200 | [diff] [blame] | 696 | .channel = chn, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 697 | .extend_name = name, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 698 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ |
| 699 | BIT(IIO_CHAN_INFO_SCALE), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 700 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 701 | .address = (addr), \ |
| 702 | .scan_index = (si), \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 703 | .scan_type = { \ |
| 704 | .sign = 'u', \ |
| 705 | .realbits = (bits), \ |
| 706 | .storagebits = 16, \ |
| 707 | .shift = 0, \ |
| 708 | .endianness = IIO_BE, \ |
| 709 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | #define ADIS16400_SUPPLY_CHAN(addr, bits) \ |
Paul Cercueil | 7323d59 | 2015-05-15 17:18:35 +0200 | [diff] [blame] | 713 | ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY, 0) |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 714 | |
| 715 | #define ADIS16400_AUX_ADC_CHAN(addr, bits) \ |
Paul Cercueil | 7323d59 | 2015-05-15 17:18:35 +0200 | [diff] [blame] | 716 | ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC, 1) |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 717 | |
| 718 | #define ADIS16400_GYRO_CHAN(mod, addr, bits) { \ |
| 719 | .type = IIO_ANGL_VEL, \ |
| 720 | .modified = 1, \ |
| 721 | .channel2 = IIO_MOD_ ## mod, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 722 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ |
| 723 | BIT(IIO_CHAN_INFO_CALIBBIAS), \ |
| 724 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ |
| 725 | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 726 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 727 | .address = addr, \ |
| 728 | .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 729 | .scan_type = { \ |
| 730 | .sign = 's', \ |
| 731 | .realbits = (bits), \ |
| 732 | .storagebits = 16, \ |
| 733 | .shift = 0, \ |
| 734 | .endianness = IIO_BE, \ |
| 735 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | #define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \ |
| 739 | .type = IIO_ACCEL, \ |
| 740 | .modified = 1, \ |
| 741 | .channel2 = IIO_MOD_ ## mod, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 742 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ |
| 743 | BIT(IIO_CHAN_INFO_CALIBBIAS), \ |
| 744 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ |
| 745 | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 746 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 747 | .address = (addr), \ |
| 748 | .scan_index = ADIS16400_SCAN_ACC_ ## mod, \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 749 | .scan_type = { \ |
| 750 | .sign = 's', \ |
| 751 | .realbits = (bits), \ |
| 752 | .storagebits = 16, \ |
| 753 | .shift = 0, \ |
| 754 | .endianness = IIO_BE, \ |
| 755 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | #define ADIS16400_MAGN_CHAN(mod, addr, bits) { \ |
| 759 | .type = IIO_MAGN, \ |
| 760 | .modified = 1, \ |
| 761 | .channel2 = IIO_MOD_ ## mod, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 762 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 763 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ |
| 764 | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 765 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 766 | .address = (addr), \ |
| 767 | .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 768 | .scan_type = { \ |
| 769 | .sign = 's', \ |
| 770 | .realbits = (bits), \ |
| 771 | .storagebits = 16, \ |
| 772 | .shift = 0, \ |
| 773 | .endianness = IIO_BE, \ |
| 774 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | #define ADIS16400_MOD_TEMP_NAME_X "x" |
| 778 | #define ADIS16400_MOD_TEMP_NAME_Y "y" |
| 779 | #define ADIS16400_MOD_TEMP_NAME_Z "z" |
| 780 | |
| 781 | #define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \ |
| 782 | .type = IIO_TEMP, \ |
| 783 | .indexed = 1, \ |
| 784 | .channel = 0, \ |
| 785 | .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 786 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ |
| 787 | BIT(IIO_CHAN_INFO_OFFSET) | \ |
| 788 | BIT(IIO_CHAN_INFO_SCALE), \ |
| 789 | .info_mask_shared_by_type = \ |
| 790 | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 791 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 792 | .address = (addr), \ |
| 793 | .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 794 | .scan_type = { \ |
| 795 | .sign = 's', \ |
| 796 | .realbits = (bits), \ |
| 797 | .storagebits = 16, \ |
| 798 | .shift = 0, \ |
| 799 | .endianness = IIO_BE, \ |
| 800 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | #define ADIS16400_TEMP_CHAN(addr, bits) { \ |
| 804 | .type = IIO_TEMP, \ |
| 805 | .indexed = 1, \ |
| 806 | .channel = 0, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 807 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ |
| 808 | BIT(IIO_CHAN_INFO_OFFSET) | \ |
| 809 | BIT(IIO_CHAN_INFO_SCALE), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 810 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 811 | .address = (addr), \ |
| 812 | .scan_index = ADIS16350_SCAN_TEMP_X, \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 813 | .scan_type = { \ |
| 814 | .sign = 's', \ |
| 815 | .realbits = (bits), \ |
| 816 | .storagebits = 16, \ |
| 817 | .shift = 0, \ |
| 818 | .endianness = IIO_BE, \ |
| 819 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | #define ADIS16400_INCLI_CHAN(mod, addr, bits) { \ |
| 823 | .type = IIO_INCLI, \ |
| 824 | .modified = 1, \ |
| 825 | .channel2 = IIO_MOD_ ## mod, \ |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 826 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ |
| 827 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 828 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 829 | .address = (addr), \ |
| 830 | .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \ |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 831 | .scan_type = { \ |
| 832 | .sign = 's', \ |
| 833 | .realbits = (bits), \ |
| 834 | .storagebits = 16, \ |
| 835 | .shift = 0, \ |
| 836 | .endianness = IIO_BE, \ |
| 837 | }, \ |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 840 | static const struct iio_chan_spec adis16400_channels[] = { |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 841 | ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 14), |
| 842 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), |
| 843 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), |
| 844 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), |
| 845 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), |
| 846 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), |
| 847 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), |
| 848 | ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), |
| 849 | ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), |
| 850 | ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), |
| 851 | ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12), |
| 852 | ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12), |
Marcus Folkesson | c76782d | 2014-01-24 11:24:00 +0000 | [diff] [blame] | 853 | IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), |
Jonathan Cameron | e785484 | 2011-05-18 14:41:27 +0100 | [diff] [blame] | 854 | }; |
| 855 | |
Lars-Peter Clausen | 72d9c98 | 2015-08-05 15:38:20 +0200 | [diff] [blame] | 856 | static const struct iio_chan_spec adis16445_channels[] = { |
| 857 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16), |
| 858 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16), |
| 859 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 16), |
| 860 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 16), |
| 861 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 16), |
| 862 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 16), |
| 863 | ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12), |
| 864 | IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), |
| 865 | }; |
| 866 | |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 867 | static const struct iio_chan_spec adis16448_channels[] = { |
| 868 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16), |
| 869 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16), |
| 870 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 16), |
| 871 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 16), |
| 872 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 16), |
| 873 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 16), |
| 874 | ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 16), |
| 875 | ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 16), |
| 876 | ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 16), |
| 877 | { |
| 878 | .type = IIO_PRESSURE, |
Jonathan Cameron | 19a7c88 | 2013-02-27 19:31:17 +0000 | [diff] [blame] | 879 | .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), |
| 880 | .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), |
Jonathan Cameron | a07a97d | 2014-06-22 20:59:00 +0100 | [diff] [blame] | 881 | .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 882 | .address = ADIS16448_BARO_OUT, |
| 883 | .scan_index = ADIS16400_SCAN_BARO, |
Jonathan Cameron | 3425c0f | 2013-12-11 18:45:00 +0000 | [diff] [blame] | 884 | .scan_type = { |
| 885 | .sign = 's', |
| 886 | .realbits = 16, |
| 887 | .storagebits = 16, |
| 888 | .endianness = IIO_BE, |
| 889 | }, |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 890 | }, |
| 891 | ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12), |
Marcus Folkesson | c76782d | 2014-01-24 11:24:00 +0000 | [diff] [blame] | 892 | IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 893 | }; |
| 894 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 895 | static const struct iio_chan_spec adis16350_channels[] = { |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 896 | ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), |
| 897 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), |
| 898 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), |
| 899 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), |
| 900 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), |
| 901 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), |
| 902 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), |
| 903 | ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14), |
| 904 | ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14), |
| 905 | ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14), |
| 906 | ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), |
| 907 | ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12), |
| 908 | ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12), |
| 909 | ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12), |
Marcus Folkesson | c76782d | 2014-01-24 11:24:00 +0000 | [diff] [blame] | 910 | IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 911 | }; |
| 912 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 913 | static const struct iio_chan_spec adis16300_channels[] = { |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 914 | ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12), |
| 915 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), |
| 916 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), |
| 917 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), |
| 918 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), |
| 919 | ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), |
| 920 | ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12), |
| 921 | ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13), |
| 922 | ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13), |
Marcus Folkesson | c76782d | 2014-01-24 11:24:00 +0000 | [diff] [blame] | 923 | IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), |
Jonathan Cameron | 8e886e6 | 2011-05-18 14:41:30 +0100 | [diff] [blame] | 924 | }; |
| 925 | |
Jonathan Cameron | 85da505 | 2011-09-30 10:05:45 +0100 | [diff] [blame] | 926 | static const struct iio_chan_spec adis16334_channels[] = { |
Lars-Peter Clausen | 599acfb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 927 | ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14), |
| 928 | ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14), |
| 929 | ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14), |
| 930 | ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14), |
| 931 | ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14), |
| 932 | ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14), |
| 933 | ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12), |
Marcus Folkesson | c76782d | 2014-01-24 11:24:00 +0000 | [diff] [blame] | 934 | IIO_CHAN_SOFT_TIMESTAMP(ADIS16400_SCAN_TIMESTAMP), |
Jonathan Cameron | 88b42f3 | 2011-08-12 18:04:37 +0100 | [diff] [blame] | 935 | }; |
| 936 | |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 937 | static struct adis16400_chip_info adis16400_chips[] = { |
Jonathan Cameron | 8e886e6 | 2011-05-18 14:41:30 +0100 | [diff] [blame] | 938 | [ADIS16300] = { |
| 939 | .channels = adis16300_channels, |
| 940 | .num_channels = ARRAY_SIZE(adis16300_channels), |
Lars-Peter Clausen | bd95a89 | 2015-08-05 15:38:16 +0200 | [diff] [blame] | 941 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
| 942 | ADIS16400_HAS_SERIAL_NUMBER, |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 943 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
Jonathan Cameron | 8e886e6 | 2011-05-18 14:41:30 +0100 | [diff] [blame] | 944 | .accel_scale_micro = 5884, |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 945 | .temp_scale_nano = 140000000, /* 0.14 C */ |
| 946 | .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 947 | .set_freq = adis16400_set_freq, |
| 948 | .get_freq = adis16400_get_freq, |
Jonathan Cameron | 8e886e6 | 2011-05-18 14:41:30 +0100 | [diff] [blame] | 949 | }, |
Jonathan Cameron | 85da505 | 2011-09-30 10:05:45 +0100 | [diff] [blame] | 950 | [ADIS16334] = { |
| 951 | .channels = adis16334_channels, |
| 952 | .num_channels = ARRAY_SIZE(adis16334_channels), |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 953 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_NO_BURST | |
| 954 | ADIS16400_HAS_SERIAL_NUMBER, |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 955 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
| 956 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 957 | .temp_scale_nano = 67850000, /* 0.06785 C */ |
| 958 | .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 959 | .set_freq = adis16334_set_freq, |
| 960 | .get_freq = adis16334_get_freq, |
Jonathan Cameron | 88b42f3 | 2011-08-12 18:04:37 +0100 | [diff] [blame] | 961 | }, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 962 | [ADIS16350] = { |
| 963 | .channels = adis16350_channels, |
| 964 | .num_channels = ARRAY_SIZE(adis16350_channels), |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 965 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */ |
| 966 | .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 967 | .temp_scale_nano = 145300000, /* 0.1453 C */ |
| 968 | .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 969 | .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE, |
| 970 | .set_freq = adis16400_set_freq, |
| 971 | .get_freq = adis16400_get_freq, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 972 | }, |
| 973 | [ADIS16360] = { |
| 974 | .channels = adis16350_channels, |
| 975 | .num_channels = ARRAY_SIZE(adis16350_channels), |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 976 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
| 977 | ADIS16400_HAS_SERIAL_NUMBER, |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 978 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
| 979 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 980 | .temp_scale_nano = 136000000, /* 0.136 C */ |
| 981 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 982 | .set_freq = adis16400_set_freq, |
| 983 | .get_freq = adis16400_get_freq, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 984 | }, |
| 985 | [ADIS16362] = { |
| 986 | .channels = adis16350_channels, |
| 987 | .num_channels = ARRAY_SIZE(adis16350_channels), |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 988 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
| 989 | ADIS16400_HAS_SERIAL_NUMBER, |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 990 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
| 991 | .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 992 | .temp_scale_nano = 136000000, /* 0.136 C */ |
| 993 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 994 | .set_freq = adis16400_set_freq, |
| 995 | .get_freq = adis16400_get_freq, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 996 | }, |
| 997 | [ADIS16364] = { |
| 998 | .channels = adis16350_channels, |
| 999 | .num_channels = ARRAY_SIZE(adis16350_channels), |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1000 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
| 1001 | ADIS16400_HAS_SERIAL_NUMBER, |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 1002 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
| 1003 | .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 1004 | .temp_scale_nano = 136000000, /* 0.136 C */ |
| 1005 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 1006 | .set_freq = adis16400_set_freq, |
| 1007 | .get_freq = adis16400_get_freq, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1008 | }, |
Lars-Peter Clausen | dc8615c | 2015-08-05 15:38:19 +0200 | [diff] [blame] | 1009 | [ADIS16367] = { |
| 1010 | .channels = adis16350_channels, |
| 1011 | .num_channels = ARRAY_SIZE(adis16350_channels), |
| 1012 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE | |
| 1013 | ADIS16400_HAS_SERIAL_NUMBER, |
| 1014 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(2000), /* 0.2 deg/s */ |
| 1015 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ |
| 1016 | .temp_scale_nano = 136000000, /* 0.136 C */ |
| 1017 | .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */ |
| 1018 | .set_freq = adis16400_set_freq, |
| 1019 | .get_freq = adis16400_get_freq, |
| 1020 | }, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1021 | [ADIS16400] = { |
| 1022 | .channels = adis16400_channels, |
| 1023 | .num_channels = ARRAY_SIZE(adis16400_channels), |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 1024 | .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE, |
Lars-Peter Clausen | 1cf8c97 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 1025 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */ |
| 1026 | .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */ |
Lars-Peter Clausen | 760ebc0 | 2012-10-15 10:35:00 +0100 | [diff] [blame] | 1027 | .temp_scale_nano = 140000000, /* 0.14 C */ |
| 1028 | .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */ |
Lars-Peter Clausen | ea2ccb3 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 1029 | .set_freq = adis16400_set_freq, |
| 1030 | .get_freq = adis16400_get_freq, |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1031 | }, |
Lars-Peter Clausen | 72d9c98 | 2015-08-05 15:38:20 +0200 | [diff] [blame] | 1032 | [ADIS16445] = { |
| 1033 | .channels = adis16445_channels, |
| 1034 | .num_channels = ARRAY_SIZE(adis16445_channels), |
| 1035 | .flags = ADIS16400_HAS_PROD_ID | |
| 1036 | ADIS16400_HAS_SERIAL_NUMBER | |
| 1037 | ADIS16400_BURST_DIAG_STAT, |
| 1038 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */ |
| 1039 | .accel_scale_micro = IIO_G_TO_M_S_2(250), /* 1/4000 g */ |
| 1040 | .temp_scale_nano = 73860000, /* 0.07386 C */ |
| 1041 | .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */ |
| 1042 | .set_freq = adis16334_set_freq, |
| 1043 | .get_freq = adis16334_get_freq, |
| 1044 | }, |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1045 | [ADIS16448] = { |
| 1046 | .channels = adis16448_channels, |
| 1047 | .num_channels = ARRAY_SIZE(adis16448_channels), |
| 1048 | .flags = ADIS16400_HAS_PROD_ID | |
Lars-Peter Clausen | d046ba2 | 2015-05-15 17:18:38 +0200 | [diff] [blame] | 1049 | ADIS16400_HAS_SERIAL_NUMBER | |
| 1050 | ADIS16400_BURST_DIAG_STAT, |
Lars-Peter Clausen | 8166537 | 2015-08-05 15:38:13 +0200 | [diff] [blame] | 1051 | .gyro_scale_micro = IIO_DEGREE_TO_RAD(40000), /* 0.04 deg/s */ |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1052 | .accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */ |
| 1053 | .temp_scale_nano = 73860000, /* 0.07386 C */ |
| 1054 | .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */ |
| 1055 | .set_freq = adis16334_set_freq, |
| 1056 | .get_freq = adis16334_get_freq, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1057 | } |
| 1058 | }; |
| 1059 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1060 | static const struct iio_info adis16400_info = { |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1061 | .read_raw = &adis16400_read_raw, |
| 1062 | .write_raw = &adis16400_write_raw, |
Alexandru Ardelean | 0e92e2d | 2019-03-22 22:44:40 +0200 | [diff] [blame] | 1063 | .update_scan_mode = adis_update_scan_mode, |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1064 | .debugfs_reg_access = adis_debugfs_reg_access, |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1065 | }; |
| 1066 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1067 | static const char * const adis16400_status_error_msgs[] = { |
| 1068 | [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure", |
| 1069 | [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure", |
| 1070 | [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure", |
| 1071 | [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure", |
| 1072 | [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure", |
| 1073 | [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure", |
| 1074 | [ADIS16400_DIAG_STAT_ALARM2] = "Alarm 2 active", |
| 1075 | [ADIS16400_DIAG_STAT_ALARM1] = "Alarm 1 active", |
| 1076 | [ADIS16400_DIAG_STAT_FLASH_CHK] = "Flash checksum error", |
| 1077 | [ADIS16400_DIAG_STAT_SELF_TEST] = "Self test error", |
| 1078 | [ADIS16400_DIAG_STAT_OVERFLOW] = "Sensor overrange", |
| 1079 | [ADIS16400_DIAG_STAT_SPI_FAIL] = "SPI failure", |
| 1080 | [ADIS16400_DIAG_STAT_FLASH_UPT] = "Flash update failed", |
| 1081 | [ADIS16400_DIAG_STAT_POWER_HIGH] = "Power supply above 5.25V", |
| 1082 | [ADIS16400_DIAG_STAT_POWER_LOW] = "Power supply below 4.75V", |
| 1083 | }; |
| 1084 | |
| 1085 | static const struct adis_data adis16400_data = { |
| 1086 | .msc_ctrl_reg = ADIS16400_MSC_CTRL, |
| 1087 | .glob_cmd_reg = ADIS16400_GLOB_CMD, |
| 1088 | .diag_stat_reg = ADIS16400_DIAG_STAT, |
| 1089 | |
| 1090 | .read_delay = 50, |
| 1091 | .write_delay = 50, |
| 1092 | |
| 1093 | .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST, |
| 1094 | .startup_delay = ADIS16400_STARTUP_DELAY, |
| 1095 | |
| 1096 | .status_error_msgs = adis16400_status_error_msgs, |
| 1097 | .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) | |
| 1098 | BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) | |
| 1099 | BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) | |
| 1100 | BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) | |
| 1101 | BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) | |
| 1102 | BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) | |
| 1103 | BIT(ADIS16400_DIAG_STAT_ALARM2) | |
| 1104 | BIT(ADIS16400_DIAG_STAT_ALARM1) | |
| 1105 | BIT(ADIS16400_DIAG_STAT_FLASH_CHK) | |
| 1106 | BIT(ADIS16400_DIAG_STAT_SELF_TEST) | |
| 1107 | BIT(ADIS16400_DIAG_STAT_OVERFLOW) | |
| 1108 | BIT(ADIS16400_DIAG_STAT_SPI_FAIL) | |
| 1109 | BIT(ADIS16400_DIAG_STAT_FLASH_UPT) | |
| 1110 | BIT(ADIS16400_DIAG_STAT_POWER_HIGH) | |
| 1111 | BIT(ADIS16400_DIAG_STAT_POWER_LOW), |
| 1112 | }; |
| 1113 | |
Paul Cercueil | c2a8b62 | 2015-05-15 17:18:36 +0200 | [diff] [blame] | 1114 | static void adis16400_setup_chan_mask(struct adis16400_state *st) |
| 1115 | { |
| 1116 | const struct adis16400_chip_info *chip_info = st->variant; |
Reno Farnesi | aab498b | 2017-07-01 17:54:08 -0400 | [diff] [blame] | 1117 | unsigned int i; |
Paul Cercueil | c2a8b62 | 2015-05-15 17:18:36 +0200 | [diff] [blame] | 1118 | |
| 1119 | for (i = 0; i < chip_info->num_channels; i++) { |
| 1120 | const struct iio_chan_spec *ch = &chip_info->channels[i]; |
| 1121 | |
| 1122 | if (ch->scan_index >= 0 && |
| 1123 | ch->scan_index != ADIS16400_SCAN_TIMESTAMP) |
| 1124 | st->avail_scan_mask[0] |= BIT(ch->scan_index); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Bill Pemberton | 4ae1c61 | 2012-11-19 13:21:57 -0500 | [diff] [blame] | 1128 | static int adis16400_probe(struct spi_device *spi) |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1129 | { |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1130 | struct adis16400_state *st; |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1131 | struct iio_dev *indio_dev; |
| 1132 | int ret; |
| 1133 | |
Sachin Kamat | 5b778b9 | 2013-07-30 09:44:00 +0100 | [diff] [blame] | 1134 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1135 | if (indio_dev == NULL) |
| 1136 | return -ENOMEM; |
| 1137 | |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1138 | st = iio_priv(indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1139 | /* this is only used for removal purposes */ |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1140 | spi_set_drvdata(spi, indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1141 | |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1142 | /* setup the industrialio driver allocated elements */ |
| 1143 | st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; |
| 1144 | indio_dev->dev.parent = &spi->dev; |
| 1145 | indio_dev->name = spi_get_device_id(spi)->name; |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1146 | indio_dev->channels = st->variant->channels; |
| 1147 | indio_dev->num_channels = st->variant->num_channels; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1148 | indio_dev->info = &adis16400_info; |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1149 | indio_dev->modes = INDIO_DIRECT_MODE; |
| 1150 | |
Paul Cercueil | c2a8b62 | 2015-05-15 17:18:36 +0200 | [diff] [blame] | 1151 | if (!(st->variant->flags & ADIS16400_NO_BURST)) { |
| 1152 | adis16400_setup_chan_mask(st); |
| 1153 | indio_dev->available_scan_masks = st->avail_scan_mask; |
Alexandru Ardelean | 5075e07 | 2019-03-22 22:44:39 +0200 | [diff] [blame] | 1154 | st->adis.burst = &adis16400_burst; |
| 1155 | if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) |
| 1156 | st->adis.burst->extra_len = sizeof(u16); |
Paul Cercueil | c2a8b62 | 2015-05-15 17:18:36 +0200 | [diff] [blame] | 1157 | } |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1158 | |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1159 | ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data); |
| 1160 | if (ret) |
Sachin Kamat | 5b778b9 | 2013-07-30 09:44:00 +0100 | [diff] [blame] | 1161 | return ret; |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1162 | |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1163 | ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, |
| 1164 | adis16400_trigger_handler); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1165 | if (ret) |
Sachin Kamat | 5b778b9 | 2013-07-30 09:44:00 +0100 | [diff] [blame] | 1166 | return ret; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1167 | |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1168 | /* Get the device into a sane initial state */ |
Jonathan Cameron | 38d15f0 | 2011-05-18 14:42:23 +0100 | [diff] [blame] | 1169 | ret = adis16400_initial_setup(indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1170 | if (ret) |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1171 | goto error_cleanup_buffer; |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 1172 | ret = iio_device_register(indio_dev); |
| 1173 | if (ret) |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1174 | goto error_cleanup_buffer; |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 1175 | |
Lars-Peter Clausen | 1db18bb | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1176 | adis16400_debugfs_init(indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1177 | return 0; |
| 1178 | |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1179 | error_cleanup_buffer: |
| 1180 | adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1181 | return ret; |
| 1182 | } |
| 1183 | |
Bill Pemberton | 447d4f2 | 2012-11-19 13:26:37 -0500 | [diff] [blame] | 1184 | static int adis16400_remove(struct spi_device *spi) |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1185 | { |
Lars-Peter Clausen | f4c6d64 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1186 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1187 | struct adis16400_state *st = iio_priv(indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1188 | |
Jonathan Cameron | d2fffd6 | 2011-10-14 14:46:58 +0100 | [diff] [blame] | 1189 | iio_device_unregister(indio_dev); |
Lars-Peter Clausen | 0b4ac3d | 2012-09-22 09:56:00 +0100 | [diff] [blame] | 1190 | adis16400_stop_device(indio_dev); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1191 | |
Lars-Peter Clausen | 5eda355 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1192 | adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); |
Lars-Peter Clausen | cd888a17 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1193 | |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1194 | return 0; |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1195 | } |
| 1196 | |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1197 | static const struct spi_device_id adis16400_id[] = { |
Jonathan Cameron | 8e886e6 | 2011-05-18 14:41:30 +0100 | [diff] [blame] | 1198 | {"adis16300", ADIS16300}, |
Lars-Peter Clausen | 3c38676 | 2015-08-05 15:38:17 +0200 | [diff] [blame] | 1199 | {"adis16305", ADIS16300}, |
Jonathan Cameron | 85da505 | 2011-09-30 10:05:45 +0100 | [diff] [blame] | 1200 | {"adis16334", ADIS16334}, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1201 | {"adis16350", ADIS16350}, |
| 1202 | {"adis16354", ADIS16350}, |
| 1203 | {"adis16355", ADIS16350}, |
| 1204 | {"adis16360", ADIS16360}, |
| 1205 | {"adis16362", ADIS16362}, |
| 1206 | {"adis16364", ADIS16364}, |
Lars-Peter Clausen | a7462e6 | 2012-10-30 10:26:00 +0000 | [diff] [blame] | 1207 | {"adis16365", ADIS16360}, |
Lars-Peter Clausen | dc8615c | 2015-08-05 15:38:19 +0200 | [diff] [blame] | 1208 | {"adis16367", ADIS16367}, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1209 | {"adis16400", ADIS16400}, |
| 1210 | {"adis16405", ADIS16400}, |
Lars-Peter Clausen | 72d9c98 | 2015-08-05 15:38:20 +0200 | [diff] [blame] | 1211 | {"adis16445", ADIS16445}, |
Lars-Peter Clausen | 76ada52 | 2013-01-16 12:48:00 +0000 | [diff] [blame] | 1212 | {"adis16448", ADIS16448}, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1213 | {} |
| 1214 | }; |
Lars-Peter Clausen | 55e4390 | 2011-11-16 08:53:31 +0100 | [diff] [blame] | 1215 | MODULE_DEVICE_TABLE(spi, adis16400_id); |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1216 | |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1217 | static struct spi_driver adis16400_driver = { |
| 1218 | .driver = { |
| 1219 | .name = "adis16400", |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1220 | }, |
Jonathan Cameron | 2a29a90 | 2011-05-18 14:41:28 +0100 | [diff] [blame] | 1221 | .id_table = adis16400_id, |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1222 | .probe = adis16400_probe, |
Bill Pemberton | e543acf | 2012-11-19 13:21:38 -0500 | [diff] [blame] | 1223 | .remove = adis16400_remove, |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1224 | }; |
Lars-Peter Clausen | ae6ae6f | 2011-11-16 10:13:39 +0100 | [diff] [blame] | 1225 | module_spi_driver(adis16400_driver); |
Barry Song | a9d26f0 | 2010-05-04 14:43:15 +0100 | [diff] [blame] | 1226 | |
| 1227 | MODULE_AUTHOR("Manuel Stahl <manuel.stahl@iis.fraunhofer.de>"); |
| 1228 | MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver"); |
| 1229 | MODULE_LICENSE("GPL v2"); |