Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: iio: new adis16204 driver

IIO driver for Programmable High-g Digital Impact Sensor and Recorder.

Signed-off-by: Barry Song <barry.song@analog.com>
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Barry Song and committed by
Greg Kroah-Hartman
bb6f19ea f11ba4f5

+1125
+9
drivers/staging/iio/accel/Kconfig
··· 21 21 Say yes here to build support for Analog Devices adis16203 Programmable 22 22 360 Degrees Inclinometer. 23 23 24 + config ADIS16204 25 + tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder" 26 + depends on SPI 27 + select IIO_TRIGGER if IIO_RING_BUFFER 28 + select IIO_SW_RING if IIO_RING_BUFFER 29 + help 30 + Say yes here to build support for Analog Devices adis16204 Programmable 31 + High-g Digital Impact Sensor and Recorder. 32 + 24 33 config ADIS16209 25 34 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" 26 35 depends on SPI
+4
drivers/staging/iio/accel/Makefile
··· 10 10 adis16203-$(CONFIG_IIO_RING_BUFFER) += adis16203_ring.o adis16203_trigger.o 11 11 obj-$(CONFIG_ADIS16203) += adis16203.o 12 12 13 + adis16204-y := adis16204_core.o 14 + adis16204-$(CONFIG_IIO_RING_BUFFER) += adis16204_ring.o adis16204_trigger.o 15 + obj-$(CONFIG_ADIS16204) += adis16204.o 16 + 13 17 adis16209-y := adis16209_core.o 14 18 adis16209-$(CONFIG_IIO_RING_BUFFER) += adis16209_ring.o adis16209_trigger.o 15 19 obj-$(CONFIG_ADIS16209) += adis16209.o
+20
drivers/staging/iio/accel/accel.h
··· 65 65 #define IIO_DEV_ATTR_ACCEL_Z(_show, _addr) \ 66 66 IIO_DEVICE_ATTR(accel_z_raw, S_IRUGO, _show, NULL, _addr) 67 67 68 + #define IIO_DEV_ATTR_ACCEL_XY(_show, _addr) \ 69 + IIO_DEVICE_ATTR(accel_xy, S_IRUGO, _show, NULL, _addr) 70 + 71 + #define IIO_DEV_ATTR_ACCEL_PEAK(_show, _addr) \ 72 + IIO_DEVICE_ATTR(accel_peak, S_IRUGO, _show, NULL, _addr) 73 + 74 + #define IIO_DEV_ATTR_ACCEL_XPEAK(_show, _addr) \ 75 + IIO_DEVICE_ATTR(accel_xpeak, S_IRUGO, _show, NULL, _addr) 76 + 77 + #define IIO_DEV_ATTR_ACCEL_YPEAK(_show, _addr) \ 78 + IIO_DEVICE_ATTR(accel_ypeak, S_IRUGO, _show, NULL, _addr) 79 + 80 + #define IIO_DEV_ATTR_ACCEL_ZPEAK(_show, _addr) \ 81 + IIO_DEVICE_ATTR(accel_zpeak, S_IRUGO, _show, NULL, _addr) 82 + 83 + #define IIO_DEV_ATTR_ACCEL_XYPEAK(_show, _addr) \ 84 + IIO_DEVICE_ATTR(accel_xypeak, S_IRUGO, _show, NULL, _addr) 85 + 86 + #define IIO_DEV_ATTR_ACCEL_XYZPEAK(_show, _addr) \ 87 + IIO_DEVICE_ATTR(accel_xyzpeak, S_IRUGO, _show, NULL, _addr)
+151
drivers/staging/iio/accel/adis16204.h
··· 1 + #ifndef SPI_ADIS16204_H_ 2 + #define SPI_ADIS16204_H_ 3 + 4 + #define ADIS16204_STARTUP_DELAY 220 /* ms */ 5 + 6 + #define ADIS16204_READ_REG(a) a 7 + #define ADIS16204_WRITE_REG(a) ((a) | 0x80) 8 + 9 + #define ADIS16204_FLASH_CNT 0x00 /* Flash memory write count */ 10 + #define ADIS16204_SUPPLY_OUT 0x02 /* Output, power supply */ 11 + #define ADIS16204_XACCL_OUT 0x04 /* Output, x-axis accelerometer */ 12 + #define ADIS16204_YACCL_OUT 0x06 /* Output, y-axis accelerometer */ 13 + #define ADIS16204_AUX_ADC 0x08 /* Output, auxiliary ADC input */ 14 + #define ADIS16204_TEMP_OUT 0x0A /* Output, temperature */ 15 + #define ADIS16204_X_PEAK_OUT 0x0C /* Twos complement */ 16 + #define ADIS16204_Y_PEAK_OUT 0x0E /* Twos complement */ 17 + #define ADIS16204_XACCL_NULL 0x10 /* Calibration, x-axis acceleration offset null */ 18 + #define ADIS16204_YACCL_NULL 0x12 /* Calibration, y-axis acceleration offset null */ 19 + #define ADIS16204_XACCL_SCALE 0x14 /* X-axis scale factor calibration register */ 20 + #define ADIS16204_YACCL_SCALE 0x16 /* Y-axis scale factor calibration register */ 21 + #define ADIS16204_XY_RSS_OUT 0x18 /* XY combined acceleration (RSS) */ 22 + #define ADIS16204_XY_PEAK_OUT 0x1A /* Peak, XY combined output (RSS) */ 23 + #define ADIS16204_CAP_BUF_1 0x1C /* Capture buffer output register 1 */ 24 + #define ADIS16204_CAP_BUF_2 0x1E /* Capture buffer output register 2 */ 25 + #define ADIS16204_ALM_MAG1 0x20 /* Alarm 1 amplitude threshold */ 26 + #define ADIS16204_ALM_MAG2 0x22 /* Alarm 2 amplitude threshold */ 27 + #define ADIS16204_ALM_CTRL 0x28 /* Alarm control */ 28 + #define ADIS16204_CAPT_PNTR 0x2A /* Capture register address pointer */ 29 + #define ADIS16204_AUX_DAC 0x30 /* Auxiliary DAC data */ 30 + #define ADIS16204_GPIO_CTRL 0x32 /* General-purpose digital input/output control */ 31 + #define ADIS16204_MSC_CTRL 0x34 /* Miscellaneous control */ 32 + #define ADIS16204_SMPL_PRD 0x36 /* Internal sample period (rate) control */ 33 + #define ADIS16204_AVG_CNT 0x38 /* Operation, filter configuration */ 34 + #define ADIS16204_SLP_CNT 0x3A /* Operation, sleep mode control */ 35 + #define ADIS16204_DIAG_STAT 0x3C /* Diagnostics, system status register */ 36 + #define ADIS16204_GLOB_CMD 0x3E /* Operation, system command register */ 37 + 38 + #define ADIS16204_OUTPUTS 5 39 + 40 + /* MSC_CTRL */ 41 + #define ADIS16204_MSC_CTRL_PWRUP_SELF_TEST (1 << 10) /* Self-test at power-on: 1 = disabled, 0 = enabled */ 42 + #define ADIS16204_MSC_CTRL_SELF_TEST_EN (1 << 8) /* Self-test enable */ 43 + #define ADIS16204_MSC_CTRL_DATA_RDY_EN (1 << 2) /* Data-ready enable: 1 = enabled, 0 = disabled */ 44 + #define ADIS16204_MSC_CTRL_ACTIVE_HIGH (1 << 1) /* Data-ready polarity: 1 = active high, 0 = active low */ 45 + #define ADIS16204_MSC_CTRL_DATA_RDY_DIO2 (1 << 0) /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ 46 + 47 + /* DIAG_STAT */ 48 + #define ADIS16204_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ 49 + #define ADIS16204_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ 50 + #define ADIS16204_DIAG_STAT_SELFTEST_FAIL (1<<5) /* Self-test diagnostic error flag: 1 = error condition, 51 + 0 = normal operation */ 52 + #define ADIS16204_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */ 53 + #define ADIS16204_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */ 54 + #define ADIS16204_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */ 55 + #define ADIS16204_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 2.975 V */ 56 + 57 + /* GLOB_CMD */ 58 + #define ADIS16204_GLOB_CMD_SW_RESET (1<<7) 59 + #define ADIS16204_GLOB_CMD_CLEAR_STAT (1<<4) 60 + #define ADIS16204_GLOB_CMD_FACTORY_CAL (1<<1) 61 + 62 + #define ADIS16204_MAX_TX 24 63 + #define ADIS16204_MAX_RX 24 64 + 65 + #define ADIS16204_ERROR_ACTIVE (1<<14) 66 + 67 + /** 68 + * struct adis16204_state - device instance specific data 69 + * @us: actual spi_device 70 + * @work_trigger_to_ring: bh for triggered event handling 71 + * @inter: used to check if new interrupt has been triggered 72 + * @last_timestamp: passing timestamp from th to bh of interrupt handler 73 + * @indio_dev: industrial I/O device structure 74 + * @trig: data ready trigger registered with iio 75 + * @tx: transmit buffer 76 + * @rx: recieve buffer 77 + * @buf_lock: mutex to protect tx and rx 78 + **/ 79 + struct adis16204_state { 80 + struct spi_device *us; 81 + struct work_struct work_trigger_to_ring; 82 + s64 last_timestamp; 83 + struct iio_dev *indio_dev; 84 + struct iio_trigger *trig; 85 + u8 *tx; 86 + u8 *rx; 87 + struct mutex buf_lock; 88 + }; 89 + 90 + int adis16204_set_irq(struct device *dev, bool enable); 91 + 92 + #ifdef CONFIG_IIO_RING_BUFFER 93 + enum adis16204_scan { 94 + ADIS16204_SCAN_SUPPLY, 95 + ADIS16204_SCAN_ACC_X, 96 + ADIS16204_SCAN_ACC_Y, 97 + ADIS16204_SCAN_AUX_ADC, 98 + ADIS16204_SCAN_TEMP, 99 + }; 100 + 101 + void adis16204_remove_trigger(struct iio_dev *indio_dev); 102 + int adis16204_probe_trigger(struct iio_dev *indio_dev); 103 + 104 + ssize_t adis16204_read_data_from_ring(struct device *dev, 105 + struct device_attribute *attr, 106 + char *buf); 107 + 108 + int adis16204_configure_ring(struct iio_dev *indio_dev); 109 + void adis16204_unconfigure_ring(struct iio_dev *indio_dev); 110 + 111 + int adis16204_initialize_ring(struct iio_ring_buffer *ring); 112 + void adis16204_uninitialize_ring(struct iio_ring_buffer *ring); 113 + #else /* CONFIG_IIO_RING_BUFFER */ 114 + 115 + static inline void adis16204_remove_trigger(struct iio_dev *indio_dev) 116 + { 117 + } 118 + 119 + static inline int adis16204_probe_trigger(struct iio_dev *indio_dev) 120 + { 121 + return 0; 122 + } 123 + 124 + static inline ssize_t 125 + adis16204_read_data_from_ring(struct device *dev, 126 + struct device_attribute *attr, 127 + char *buf) 128 + { 129 + return 0; 130 + } 131 + 132 + static int adis16204_configure_ring(struct iio_dev *indio_dev) 133 + { 134 + return 0; 135 + } 136 + 137 + static inline void adis16204_unconfigure_ring(struct iio_dev *indio_dev) 138 + { 139 + } 140 + 141 + static inline int adis16204_initialize_ring(struct iio_ring_buffer *ring) 142 + { 143 + return 0; 144 + } 145 + 146 + static inline void adis16204_uninitialize_ring(struct iio_ring_buffer *ring) 147 + { 148 + } 149 + 150 + #endif /* CONFIG_IIO_RING_BUFFER */ 151 + #endif /* SPI_ADIS16204_H_ */
+613
drivers/staging/iio/accel/adis16204_core.c
··· 1 + /* 2 + * ADIS16204 Programmable High-g Digital Impact Sensor and Recorder 3 + * 4 + * Copyright 2010 Analog Devices Inc. 5 + * 6 + * Licensed under the GPL-2 or later. 7 + */ 8 + 9 + #include <linux/interrupt.h> 10 + #include <linux/irq.h> 11 + #include <linux/gpio.h> 12 + #include <linux/delay.h> 13 + #include <linux/mutex.h> 14 + #include <linux/device.h> 15 + #include <linux/kernel.h> 16 + #include <linux/spi/spi.h> 17 + #include <linux/slab.h> 18 + #include <linux/sysfs.h> 19 + #include <linux/list.h> 20 + 21 + #include "../iio.h" 22 + #include "../sysfs.h" 23 + #include "accel.h" 24 + #include "../gyro/gyro.h" 25 + #include "../adc/adc.h" 26 + 27 + #include "adis16204.h" 28 + 29 + #define DRIVER_NAME "adis16204" 30 + 31 + static int adis16204_check_status(struct device *dev); 32 + 33 + /** 34 + * adis16204_spi_write_reg_8() - write single byte to a register 35 + * @dev: device associated with child of actual device (iio_dev or iio_trig) 36 + * @reg_address: the address of the register to be written 37 + * @val: the value to write 38 + **/ 39 + static int adis16204_spi_write_reg_8(struct device *dev, 40 + u8 reg_address, 41 + u8 val) 42 + { 43 + int ret; 44 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 45 + struct adis16204_state *st = iio_dev_get_devdata(indio_dev); 46 + 47 + mutex_lock(&st->buf_lock); 48 + st->tx[0] = ADIS16204_WRITE_REG(reg_address); 49 + st->tx[1] = val; 50 + 51 + ret = spi_write(st->us, st->tx, 2); 52 + mutex_unlock(&st->buf_lock); 53 + 54 + return ret; 55 + } 56 + 57 + /** 58 + * adis16204_spi_write_reg_16() - write 2 bytes to a pair of registers 59 + * @dev: device associated with child of actual device (iio_dev or iio_trig) 60 + * @reg_address: the address of the lower of the two registers. Second register 61 + * is assumed to have address one greater. 62 + * @val: value to be written 63 + **/ 64 + static int adis16204_spi_write_reg_16(struct device *dev, 65 + u8 lower_reg_address, 66 + u16 value) 67 + { 68 + int ret; 69 + struct spi_message msg; 70 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 71 + struct adis16204_state *st = iio_dev_get_devdata(indio_dev); 72 + struct spi_transfer xfers[] = { 73 + { 74 + .tx_buf = st->tx, 75 + .bits_per_word = 8, 76 + .len = 2, 77 + .cs_change = 1, 78 + }, { 79 + .tx_buf = st->tx + 2, 80 + .bits_per_word = 8, 81 + .len = 2, 82 + .cs_change = 1, 83 + }, 84 + }; 85 + 86 + mutex_lock(&st->buf_lock); 87 + st->tx[0] = ADIS16204_WRITE_REG(lower_reg_address); 88 + st->tx[1] = value & 0xFF; 89 + st->tx[2] = ADIS16204_WRITE_REG(lower_reg_address + 1); 90 + st->tx[3] = (value >> 8) & 0xFF; 91 + 92 + spi_message_init(&msg); 93 + spi_message_add_tail(&xfers[0], &msg); 94 + spi_message_add_tail(&xfers[1], &msg); 95 + ret = spi_sync(st->us, &msg); 96 + mutex_unlock(&st->buf_lock); 97 + 98 + return ret; 99 + } 100 + 101 + /** 102 + * adis16204_spi_read_reg_16() - read 2 bytes from a 16-bit register 103 + * @dev: device associated with child of actual device (iio_dev or iio_trig) 104 + * @reg_address: the address of the lower of the two registers. Second register 105 + * is assumed to have address one greater. 106 + * @val: somewhere to pass back the value read 107 + **/ 108 + static int adis16204_spi_read_reg_16(struct device *dev, 109 + u8 lower_reg_address, 110 + u16 *val) 111 + { 112 + struct spi_message msg; 113 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 114 + struct adis16204_state *st = iio_dev_get_devdata(indio_dev); 115 + int ret; 116 + struct spi_transfer xfers[] = { 117 + { 118 + .tx_buf = st->tx, 119 + .bits_per_word = 8, 120 + .len = 2, 121 + .cs_change = 1, 122 + .delay_usecs = 20, 123 + }, { 124 + .rx_buf = st->rx, 125 + .bits_per_word = 8, 126 + .len = 2, 127 + .cs_change = 1, 128 + .delay_usecs = 20, 129 + }, 130 + }; 131 + 132 + mutex_lock(&st->buf_lock); 133 + st->tx[0] = ADIS16204_READ_REG(lower_reg_address); 134 + st->tx[1] = 0; 135 + 136 + spi_message_init(&msg); 137 + spi_message_add_tail(&xfers[0], &msg); 138 + spi_message_add_tail(&xfers[1], &msg); 139 + ret = spi_sync(st->us, &msg); 140 + if (ret) { 141 + dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X", 142 + lower_reg_address); 143 + goto error_ret; 144 + } 145 + *val = (st->rx[0] << 8) | st->rx[1]; 146 + 147 + error_ret: 148 + mutex_unlock(&st->buf_lock); 149 + return ret; 150 + } 151 + 152 + static ssize_t adis16204_read_12bit_unsigned(struct device *dev, 153 + struct device_attribute *attr, 154 + char *buf) 155 + { 156 + int ret; 157 + u16 val = 0; 158 + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 159 + 160 + ret = adis16204_spi_read_reg_16(dev, this_attr->address, &val); 161 + if (ret) 162 + return ret; 163 + 164 + if (val & ADIS16204_ERROR_ACTIVE) 165 + adis16204_check_status(dev); 166 + 167 + return sprintf(buf, "%u\n", val & 0x0FFF); 168 + } 169 + 170 + static ssize_t adis16204_read_temp(struct device *dev, 171 + struct device_attribute *attr, 172 + char *buf) 173 + { 174 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 175 + ssize_t ret; 176 + u16 val; 177 + 178 + /* Take the iio_dev status lock */ 179 + mutex_lock(&indio_dev->mlock); 180 + 181 + ret = adis16204_spi_read_reg_16(dev, ADIS16204_TEMP_OUT, (u16 *)&val); 182 + if (ret) 183 + goto error_ret; 184 + 185 + if (val & ADIS16204_ERROR_ACTIVE) 186 + adis16204_check_status(dev); 187 + 188 + val &= 0xFFF; 189 + ret = sprintf(buf, "%d\n", val); 190 + 191 + error_ret: 192 + mutex_unlock(&indio_dev->mlock); 193 + return ret; 194 + } 195 + 196 + static ssize_t adis16204_read_12bit_signed(struct device *dev, 197 + struct device_attribute *attr, 198 + char *buf) 199 + { 200 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 201 + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 202 + s16 val = 0; 203 + ssize_t ret; 204 + 205 + mutex_lock(&indio_dev->mlock); 206 + 207 + ret = adis16204_spi_read_reg_16(dev, this_attr->address, (u16 *)&val); 208 + if (!ret) { 209 + if (val & ADIS16204_ERROR_ACTIVE) 210 + adis16204_check_status(dev); 211 + 212 + val = ((s16)(val << 4) >> 4); 213 + ret = sprintf(buf, "%d\n", val); 214 + } 215 + 216 + mutex_unlock(&indio_dev->mlock); 217 + 218 + return ret; 219 + } 220 + 221 + static ssize_t adis16204_read_14bit_signed(struct device *dev, 222 + struct device_attribute *attr, 223 + char *buf) 224 + { 225 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 226 + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 227 + s16 val = 0; 228 + ssize_t ret; 229 + 230 + mutex_lock(&indio_dev->mlock); 231 + 232 + ret = adis16204_spi_read_reg_16(dev, this_attr->address, (u16 *)&val); 233 + if (!ret) { 234 + if (val & ADIS16204_ERROR_ACTIVE) 235 + adis16204_check_status(dev); 236 + 237 + val = ((s16)(val << 2) >> 2); 238 + ret = sprintf(buf, "%d\n", val); 239 + } 240 + 241 + mutex_unlock(&indio_dev->mlock); 242 + 243 + return ret; 244 + } 245 + 246 + static ssize_t adis16204_write_16bit(struct device *dev, 247 + struct device_attribute *attr, 248 + const char *buf, 249 + size_t len) 250 + { 251 + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 252 + int ret; 253 + long val; 254 + 255 + ret = strict_strtol(buf, 10, &val); 256 + if (ret) 257 + goto error_ret; 258 + ret = adis16204_spi_write_reg_16(dev, this_attr->address, val); 259 + 260 + error_ret: 261 + return ret ? ret : len; 262 + } 263 + 264 + static int adis16204_reset(struct device *dev) 265 + { 266 + int ret; 267 + ret = adis16204_spi_write_reg_8(dev, 268 + ADIS16204_GLOB_CMD, 269 + ADIS16204_GLOB_CMD_SW_RESET); 270 + if (ret) 271 + dev_err(dev, "problem resetting device"); 272 + 273 + return ret; 274 + } 275 + 276 + static ssize_t adis16204_write_reset(struct device *dev, 277 + struct device_attribute *attr, 278 + const char *buf, size_t len) 279 + { 280 + if (len < 1) 281 + return -EINVAL; 282 + switch (buf[0]) { 283 + case '1': 284 + case 'y': 285 + case 'Y': 286 + return adis16204_reset(dev); 287 + } 288 + return -EINVAL; 289 + } 290 + 291 + int adis16204_set_irq(struct device *dev, bool enable) 292 + { 293 + int ret = 0; 294 + u16 msc; 295 + 296 + ret = adis16204_spi_read_reg_16(dev, ADIS16204_MSC_CTRL, &msc); 297 + if (ret) 298 + goto error_ret; 299 + 300 + msc |= ADIS16204_MSC_CTRL_ACTIVE_HIGH; 301 + msc &= ~ADIS16204_MSC_CTRL_DATA_RDY_DIO2; 302 + if (enable) 303 + msc |= ADIS16204_MSC_CTRL_DATA_RDY_EN; 304 + else 305 + msc &= ~ADIS16204_MSC_CTRL_DATA_RDY_EN; 306 + 307 + ret = adis16204_spi_write_reg_16(dev, ADIS16204_MSC_CTRL, msc); 308 + 309 + error_ret: 310 + return ret; 311 + } 312 + 313 + static int adis16204_check_status(struct device *dev) 314 + { 315 + u16 status; 316 + int ret; 317 + 318 + ret = adis16204_spi_read_reg_16(dev, ADIS16204_DIAG_STAT, &status); 319 + if (ret < 0) { 320 + dev_err(dev, "Reading status failed\n"); 321 + goto error_ret; 322 + } 323 + ret = status & 0x1F; 324 + 325 + if (status & ADIS16204_DIAG_STAT_SELFTEST_FAIL) 326 + dev_err(dev, "Self test failure\n"); 327 + if (status & ADIS16204_DIAG_STAT_SPI_FAIL) 328 + dev_err(dev, "SPI failure\n"); 329 + if (status & ADIS16204_DIAG_STAT_FLASH_UPT) 330 + dev_err(dev, "Flash update failed\n"); 331 + if (status & ADIS16204_DIAG_STAT_POWER_HIGH) 332 + dev_err(dev, "Power supply above 3.625V\n"); 333 + if (status & ADIS16204_DIAG_STAT_POWER_LOW) 334 + dev_err(dev, "Power supply below 2.975V\n"); 335 + 336 + error_ret: 337 + return ret; 338 + } 339 + 340 + static int adis16204_self_test(struct device *dev) 341 + { 342 + int ret; 343 + ret = adis16204_spi_write_reg_16(dev, 344 + ADIS16204_MSC_CTRL, 345 + ADIS16204_MSC_CTRL_SELF_TEST_EN); 346 + if (ret) { 347 + dev_err(dev, "problem starting self test"); 348 + goto err_ret; 349 + } 350 + 351 + adis16204_check_status(dev); 352 + 353 + err_ret: 354 + return ret; 355 + } 356 + 357 + static int adis16204_initial_setup(struct adis16204_state *st) 358 + { 359 + int ret; 360 + struct device *dev = &st->indio_dev->dev; 361 + 362 + /* Disable IRQ */ 363 + ret = adis16204_set_irq(dev, false); 364 + if (ret) { 365 + dev_err(dev, "disable irq failed"); 366 + goto err_ret; 367 + } 368 + 369 + /* Do self test */ 370 + ret = adis16204_self_test(dev); 371 + if (ret) { 372 + dev_err(dev, "self test failure"); 373 + goto err_ret; 374 + } 375 + 376 + /* Read status register to check the result */ 377 + ret = adis16204_check_status(dev); 378 + if (ret) { 379 + adis16204_reset(dev); 380 + dev_err(dev, "device not playing ball -> reset"); 381 + msleep(ADIS16204_STARTUP_DELAY); 382 + ret = adis16204_check_status(dev); 383 + if (ret) { 384 + dev_err(dev, "giving up"); 385 + goto err_ret; 386 + } 387 + } 388 + 389 + printk(KERN_INFO DRIVER_NAME ": at CS%d (irq %d)\n", 390 + st->us->chip_select, st->us->irq); 391 + 392 + err_ret: 393 + return ret; 394 + } 395 + 396 + static IIO_DEV_ATTR_IN_NAMED_RAW(0, supply, adis16204_read_12bit_unsigned, 397 + ADIS16204_SUPPLY_OUT); 398 + static IIO_CONST_ATTR(in0_supply_scale, "0.00122"); 399 + static IIO_DEV_ATTR_IN_RAW(1, adis16204_read_12bit_unsigned, 400 + ADIS16204_AUX_ADC); 401 + static IIO_CONST_ATTR(in1_scale, "0.00061"); 402 + 403 + static IIO_DEV_ATTR_ACCEL_X(adis16204_read_14bit_signed, 404 + ADIS16204_XACCL_OUT); 405 + static IIO_DEV_ATTR_ACCEL_Y(adis16204_read_14bit_signed, 406 + ADIS16204_YACCL_OUT); 407 + static IIO_DEV_ATTR_ACCEL_XY(adis16204_read_14bit_signed, 408 + ADIS16204_XY_RSS_OUT); 409 + static IIO_DEV_ATTR_ACCEL_XPEAK(adis16204_read_14bit_signed, 410 + ADIS16204_X_PEAK_OUT); 411 + static IIO_DEV_ATTR_ACCEL_YPEAK(adis16204_read_14bit_signed, 412 + ADIS16204_Y_PEAK_OUT); 413 + static IIO_DEV_ATTR_ACCEL_XYPEAK(adis16204_read_14bit_signed, 414 + ADIS16204_XY_PEAK_OUT); 415 + static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO, 416 + adis16204_read_12bit_signed, 417 + adis16204_write_16bit, 418 + ADIS16204_XACCL_NULL); 419 + static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO, 420 + adis16204_read_12bit_signed, 421 + adis16204_write_16bit, 422 + ADIS16204_YACCL_NULL); 423 + static IIO_CONST_ATTR(accel_x_scale, "0.017125"); 424 + static IIO_CONST_ATTR(accel_y_scale, "0.008407"); 425 + static IIO_CONST_ATTR(accel_xy_scale, "0.017125"); 426 + 427 + static IIO_DEV_ATTR_TEMP_RAW(adis16204_read_temp); 428 + static IIO_CONST_ATTR(temp_offset, "25"); 429 + static IIO_CONST_ATTR(temp_scale, "-0.47"); 430 + 431 + static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16204_write_reset, 0); 432 + 433 + static IIO_CONST_ATTR(name, "adis16204"); 434 + 435 + static struct attribute *adis16204_event_attributes[] = { 436 + NULL 437 + }; 438 + 439 + static struct attribute_group adis16204_event_attribute_group = { 440 + .attrs = adis16204_event_attributes, 441 + }; 442 + 443 + static struct attribute *adis16204_attributes[] = { 444 + &iio_dev_attr_in0_supply_raw.dev_attr.attr, 445 + &iio_const_attr_in0_supply_scale.dev_attr.attr, 446 + &iio_dev_attr_temp_raw.dev_attr.attr, 447 + &iio_const_attr_temp_offset.dev_attr.attr, 448 + &iio_const_attr_temp_scale.dev_attr.attr, 449 + &iio_dev_attr_reset.dev_attr.attr, 450 + &iio_const_attr_name.dev_attr.attr, 451 + &iio_dev_attr_in1_raw.dev_attr.attr, 452 + &iio_const_attr_in1_scale.dev_attr.attr, 453 + &iio_dev_attr_accel_x_raw.dev_attr.attr, 454 + &iio_dev_attr_accel_y_raw.dev_attr.attr, 455 + &iio_dev_attr_accel_xy.dev_attr.attr, 456 + &iio_dev_attr_accel_xpeak.dev_attr.attr, 457 + &iio_dev_attr_accel_ypeak.dev_attr.attr, 458 + &iio_dev_attr_accel_xypeak.dev_attr.attr, 459 + &iio_dev_attr_accel_x_offset.dev_attr.attr, 460 + &iio_dev_attr_accel_y_offset.dev_attr.attr, 461 + &iio_const_attr_accel_x_scale.dev_attr.attr, 462 + &iio_const_attr_accel_y_scale.dev_attr.attr, 463 + &iio_const_attr_accel_xy_scale.dev_attr.attr, 464 + NULL 465 + }; 466 + 467 + static const struct attribute_group adis16204_attribute_group = { 468 + .attrs = adis16204_attributes, 469 + }; 470 + 471 + static int __devinit adis16204_probe(struct spi_device *spi) 472 + { 473 + int ret, regdone = 0; 474 + struct adis16204_state *st = kzalloc(sizeof *st, GFP_KERNEL); 475 + if (!st) { 476 + ret = -ENOMEM; 477 + goto error_ret; 478 + } 479 + /* this is only used for removal purposes */ 480 + spi_set_drvdata(spi, st); 481 + 482 + /* Allocate the comms buffers */ 483 + st->rx = kzalloc(sizeof(*st->rx)*ADIS16204_MAX_RX, GFP_KERNEL); 484 + if (st->rx == NULL) { 485 + ret = -ENOMEM; 486 + goto error_free_st; 487 + } 488 + st->tx = kzalloc(sizeof(*st->tx)*ADIS16204_MAX_TX, GFP_KERNEL); 489 + if (st->tx == NULL) { 490 + ret = -ENOMEM; 491 + goto error_free_rx; 492 + } 493 + st->us = spi; 494 + mutex_init(&st->buf_lock); 495 + /* setup the industrialio driver allocated elements */ 496 + st->indio_dev = iio_allocate_device(); 497 + if (st->indio_dev == NULL) { 498 + ret = -ENOMEM; 499 + goto error_free_tx; 500 + } 501 + 502 + st->indio_dev->dev.parent = &spi->dev; 503 + st->indio_dev->num_interrupt_lines = 1; 504 + st->indio_dev->event_attrs = &adis16204_event_attribute_group; 505 + st->indio_dev->attrs = &adis16204_attribute_group; 506 + st->indio_dev->dev_data = (void *)(st); 507 + st->indio_dev->driver_module = THIS_MODULE; 508 + st->indio_dev->modes = INDIO_DIRECT_MODE; 509 + 510 + ret = adis16204_configure_ring(st->indio_dev); 511 + if (ret) 512 + goto error_free_dev; 513 + 514 + ret = iio_device_register(st->indio_dev); 515 + if (ret) 516 + goto error_unreg_ring_funcs; 517 + regdone = 1; 518 + 519 + ret = adis16204_initialize_ring(st->indio_dev->ring); 520 + if (ret) { 521 + printk(KERN_ERR "failed to initialize the ring\n"); 522 + goto error_unreg_ring_funcs; 523 + } 524 + 525 + if (spi->irq) { 526 + ret = iio_register_interrupt_line(spi->irq, 527 + st->indio_dev, 528 + 0, 529 + IRQF_TRIGGER_RISING, 530 + "adis16204"); 531 + if (ret) 532 + goto error_uninitialize_ring; 533 + 534 + ret = adis16204_probe_trigger(st->indio_dev); 535 + if (ret) 536 + goto error_unregister_line; 537 + } 538 + 539 + /* Get the device into a sane initial state */ 540 + ret = adis16204_initial_setup(st); 541 + if (ret) 542 + goto error_remove_trigger; 543 + return 0; 544 + 545 + error_remove_trigger: 546 + adis16204_remove_trigger(st->indio_dev); 547 + error_unregister_line: 548 + if (spi->irq) 549 + iio_unregister_interrupt_line(st->indio_dev, 0); 550 + error_uninitialize_ring: 551 + adis16204_uninitialize_ring(st->indio_dev->ring); 552 + error_unreg_ring_funcs: 553 + adis16204_unconfigure_ring(st->indio_dev); 554 + error_free_dev: 555 + if (regdone) 556 + iio_device_unregister(st->indio_dev); 557 + else 558 + iio_free_device(st->indio_dev); 559 + error_free_tx: 560 + kfree(st->tx); 561 + error_free_rx: 562 + kfree(st->rx); 563 + error_free_st: 564 + kfree(st); 565 + error_ret: 566 + return ret; 567 + } 568 + 569 + static int adis16204_remove(struct spi_device *spi) 570 + { 571 + struct adis16204_state *st = spi_get_drvdata(spi); 572 + struct iio_dev *indio_dev = st->indio_dev; 573 + 574 + flush_scheduled_work(); 575 + 576 + adis16204_remove_trigger(indio_dev); 577 + if (spi->irq) 578 + iio_unregister_interrupt_line(indio_dev, 0); 579 + 580 + adis16204_uninitialize_ring(indio_dev->ring); 581 + iio_device_unregister(indio_dev); 582 + adis16204_unconfigure_ring(indio_dev); 583 + kfree(st->tx); 584 + kfree(st->rx); 585 + kfree(st); 586 + 587 + return 0; 588 + } 589 + 590 + static struct spi_driver adis16204_driver = { 591 + .driver = { 592 + .name = "adis16204", 593 + .owner = THIS_MODULE, 594 + }, 595 + .probe = adis16204_probe, 596 + .remove = __devexit_p(adis16204_remove), 597 + }; 598 + 599 + static __init int adis16204_init(void) 600 + { 601 + return spi_register_driver(&adis16204_driver); 602 + } 603 + module_init(adis16204_init); 604 + 605 + static __exit void adis16204_exit(void) 606 + { 607 + spi_unregister_driver(&adis16204_driver); 608 + } 609 + module_exit(adis16204_exit); 610 + 611 + MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 612 + MODULE_DESCRIPTION("Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder"); 613 + MODULE_LICENSE("GPL v2");
+206
drivers/staging/iio/accel/adis16204_ring.c
··· 1 + #include <linux/interrupt.h> 2 + #include <linux/irq.h> 3 + #include <linux/gpio.h> 4 + #include <linux/workqueue.h> 5 + #include <linux/mutex.h> 6 + #include <linux/device.h> 7 + #include <linux/kernel.h> 8 + #include <linux/spi/spi.h> 9 + #include <linux/slab.h> 10 + #include <linux/sysfs.h> 11 + #include <linux/list.h> 12 + 13 + #include "../iio.h" 14 + #include "../sysfs.h" 15 + #include "../ring_sw.h" 16 + #include "accel.h" 17 + #include "../trigger.h" 18 + #include "adis16204.h" 19 + 20 + static IIO_SCAN_EL_C(in_supply, ADIS16204_SCAN_SUPPLY, ADIS16204_SUPPLY_OUT, NULL); 21 + static IIO_CONST_ATTR_SCAN_EL_TYPE(in_supply, u, 12, 16); 22 + static IIO_SCAN_EL_C(accel_x, ADIS16204_SCAN_ACC_X, ADIS16204_XACCL_OUT, NULL); 23 + static IIO_SCAN_EL_C(accel_y, ADIS16204_SCAN_ACC_Y, ADIS16204_YACCL_OUT, NULL); 24 + static IIO_CONST_ATTR_SCAN_EL_TYPE(accel, s, 14, 16); 25 + static IIO_SCAN_EL_C(in0, ADIS16204_SCAN_AUX_ADC, ADIS16204_AUX_ADC, NULL); 26 + static IIO_CONST_ATTR_SCAN_EL_TYPE(in0, u, 12, 16); 27 + static IIO_SCAN_EL_C(temp, ADIS16204_SCAN_TEMP, ADIS16204_TEMP_OUT, NULL); 28 + static IIO_CONST_ATTR_SCAN_EL_TYPE(temp, u, 12, 16); 29 + static IIO_SCAN_EL_TIMESTAMP(5); 30 + static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64); 31 + 32 + static struct attribute *adis16204_scan_el_attrs[] = { 33 + &iio_scan_el_in_supply.dev_attr.attr, 34 + &iio_const_attr_in_supply_index.dev_attr.attr, 35 + &iio_const_attr_in_supply_type.dev_attr.attr, 36 + &iio_scan_el_accel_x.dev_attr.attr, 37 + &iio_const_attr_accel_x_index.dev_attr.attr, 38 + &iio_scan_el_accel_y.dev_attr.attr, 39 + &iio_const_attr_accel_y_index.dev_attr.attr, 40 + &iio_const_attr_accel_type.dev_attr.attr, 41 + &iio_scan_el_in0.dev_attr.attr, 42 + &iio_const_attr_in0_index.dev_attr.attr, 43 + &iio_const_attr_in0_type.dev_attr.attr, 44 + &iio_scan_el_temp.dev_attr.attr, 45 + &iio_const_attr_temp_index.dev_attr.attr, 46 + &iio_const_attr_temp_type.dev_attr.attr, 47 + &iio_scan_el_timestamp.dev_attr.attr, 48 + &iio_const_attr_timestamp_index.dev_attr.attr, 49 + &iio_const_attr_timestamp_type.dev_attr.attr, 50 + NULL, 51 + }; 52 + 53 + static struct attribute_group adis16204_scan_el_group = { 54 + .attrs = adis16204_scan_el_attrs, 55 + .name = "scan_elements", 56 + }; 57 + 58 + /** 59 + * adis16204_poll_func_th() top half interrupt handler called by trigger 60 + * @private_data: iio_dev 61 + **/ 62 + static void adis16204_poll_func_th(struct iio_dev *indio_dev, s64 timestamp) 63 + { 64 + struct adis16204_state *st = iio_dev_get_devdata(indio_dev); 65 + st->last_timestamp = timestamp; 66 + schedule_work(&st->work_trigger_to_ring); 67 + } 68 + 69 + /** 70 + * adis16204_read_ring_data() read data registers which will be placed into ring 71 + * @dev: device associated with child of actual device (iio_dev or iio_trig) 72 + * @rx: somewhere to pass back the value read 73 + **/ 74 + static int adis16204_read_ring_data(struct device *dev, u8 *rx) 75 + { 76 + struct spi_message msg; 77 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 78 + struct adis16204_state *st = iio_dev_get_devdata(indio_dev); 79 + struct spi_transfer xfers[ADIS16204_OUTPUTS + 1]; 80 + int ret; 81 + int i; 82 + 83 + mutex_lock(&st->buf_lock); 84 + 85 + spi_message_init(&msg); 86 + 87 + memset(xfers, 0, sizeof(xfers)); 88 + for (i = 0; i <= ADIS16204_OUTPUTS; i++) { 89 + xfers[i].bits_per_word = 8; 90 + xfers[i].cs_change = 1; 91 + xfers[i].len = 2; 92 + xfers[i].delay_usecs = 20; 93 + xfers[i].tx_buf = st->tx + 2 * i; 94 + st->tx[2 * i] = ADIS16204_READ_REG(ADIS16204_SUPPLY_OUT + 2 * i); 95 + st->tx[2 * i + 1] = 0; 96 + if (i >= 1) 97 + xfers[i].rx_buf = rx + 2 * (i - 1); 98 + spi_message_add_tail(&xfers[i], &msg); 99 + } 100 + 101 + ret = spi_sync(st->us, &msg); 102 + if (ret) 103 + dev_err(&st->us->dev, "problem when burst reading"); 104 + 105 + mutex_unlock(&st->buf_lock); 106 + 107 + return ret; 108 + } 109 + 110 + /* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device 111 + * specific to be rolled into the core. 112 + */ 113 + static void adis16204_trigger_bh_to_ring(struct work_struct *work_s) 114 + { 115 + struct adis16204_state *st 116 + = container_of(work_s, struct adis16204_state, 117 + work_trigger_to_ring); 118 + struct iio_ring_buffer *ring = st->indio_dev->ring; 119 + 120 + int i = 0; 121 + s16 *data; 122 + size_t datasize = ring->access.get_bytes_per_datum(ring); 123 + 124 + data = kmalloc(datasize, GFP_KERNEL); 125 + if (data == NULL) { 126 + dev_err(&st->us->dev, "memory alloc failed in ring bh"); 127 + return; 128 + } 129 + 130 + if (ring->scan_count) 131 + if (adis16204_read_ring_data(&st->indio_dev->dev, st->rx) >= 0) 132 + for (; i < ring->scan_count; i++) 133 + data[i] = be16_to_cpup( 134 + (__be16 *)&(st->rx[i*2])); 135 + 136 + /* Guaranteed to be aligned with 8 byte boundary */ 137 + if (ring->scan_timestamp) 138 + *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp; 139 + 140 + ring->access.store_to(ring, 141 + (u8 *)data, 142 + st->last_timestamp); 143 + 144 + iio_trigger_notify_done(st->indio_dev->trig); 145 + kfree(data); 146 + 147 + return; 148 + } 149 + 150 + void adis16204_unconfigure_ring(struct iio_dev *indio_dev) 151 + { 152 + kfree(indio_dev->pollfunc); 153 + iio_sw_rb_free(indio_dev->ring); 154 + } 155 + 156 + int adis16204_configure_ring(struct iio_dev *indio_dev) 157 + { 158 + int ret = 0; 159 + struct adis16204_state *st = indio_dev->dev_data; 160 + struct iio_ring_buffer *ring; 161 + INIT_WORK(&st->work_trigger_to_ring, adis16204_trigger_bh_to_ring); 162 + 163 + ring = iio_sw_rb_allocate(indio_dev); 164 + if (!ring) { 165 + ret = -ENOMEM; 166 + return ret; 167 + } 168 + indio_dev->ring = ring; 169 + /* Effectively select the ring buffer implementation */ 170 + iio_ring_sw_register_funcs(&ring->access); 171 + ring->bpe = 2; 172 + ring->scan_el_attrs = &adis16204_scan_el_group; 173 + ring->scan_timestamp = true; 174 + ring->preenable = &iio_sw_ring_preenable; 175 + ring->postenable = &iio_triggered_ring_postenable; 176 + ring->predisable = &iio_triggered_ring_predisable; 177 + ring->owner = THIS_MODULE; 178 + 179 + /* Set default scan mode */ 180 + iio_scan_mask_set(ring, iio_scan_el_in_supply.number); 181 + iio_scan_mask_set(ring, iio_scan_el_accel_x.number); 182 + iio_scan_mask_set(ring, iio_scan_el_accel_y.number); 183 + iio_scan_mask_set(ring, iio_scan_el_temp.number); 184 + iio_scan_mask_set(ring, iio_scan_el_in0.number); 185 + 186 + ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16204_poll_func_th); 187 + if (ret) 188 + goto error_iio_sw_rb_free; 189 + 190 + indio_dev->modes |= INDIO_RING_TRIGGERED; 191 + return 0; 192 + 193 + error_iio_sw_rb_free: 194 + iio_sw_rb_free(indio_dev->ring); 195 + return ret; 196 + } 197 + 198 + int adis16204_initialize_ring(struct iio_ring_buffer *ring) 199 + { 200 + return iio_ring_buffer_register(ring, 0); 201 + } 202 + 203 + void adis16204_uninitialize_ring(struct iio_ring_buffer *ring) 204 + { 205 + iio_ring_buffer_unregister(ring); 206 + }
+122
drivers/staging/iio/accel/adis16204_trigger.c
··· 1 + #include <linux/interrupt.h> 2 + #include <linux/irq.h> 3 + #include <linux/mutex.h> 4 + #include <linux/device.h> 5 + #include <linux/kernel.h> 6 + #include <linux/sysfs.h> 7 + #include <linux/list.h> 8 + #include <linux/spi/spi.h> 9 + 10 + #include "../iio.h" 11 + #include "../sysfs.h" 12 + #include "../trigger.h" 13 + #include "adis16204.h" 14 + 15 + /** 16 + * adis16204_data_rdy_trig_poll() the event handler for the data rdy trig 17 + **/ 18 + static int adis16204_data_rdy_trig_poll(struct iio_dev *dev_info, 19 + int index, 20 + s64 timestamp, 21 + int no_test) 22 + { 23 + struct adis16204_state *st = iio_dev_get_devdata(dev_info); 24 + struct iio_trigger *trig = st->trig; 25 + 26 + iio_trigger_poll(trig, timestamp); 27 + 28 + return IRQ_HANDLED; 29 + } 30 + 31 + IIO_EVENT_SH(data_rdy_trig, &adis16204_data_rdy_trig_poll); 32 + 33 + static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); 34 + 35 + static struct attribute *adis16204_trigger_attrs[] = { 36 + &dev_attr_name.attr, 37 + NULL, 38 + }; 39 + 40 + static const struct attribute_group adis16204_trigger_attr_group = { 41 + .attrs = adis16204_trigger_attrs, 42 + }; 43 + 44 + /** 45 + * adis16204_data_rdy_trigger_set_state() set datardy interrupt state 46 + **/ 47 + static int adis16204_data_rdy_trigger_set_state(struct iio_trigger *trig, 48 + bool state) 49 + { 50 + struct adis16204_state *st = trig->private_data; 51 + struct iio_dev *indio_dev = st->indio_dev; 52 + int ret = 0; 53 + 54 + dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); 55 + ret = adis16204_set_irq(&st->indio_dev->dev, state); 56 + if (state == false) { 57 + iio_remove_event_from_list(&iio_event_data_rdy_trig, 58 + &indio_dev->interrupts[0] 59 + ->ev_list); 60 + flush_scheduled_work(); 61 + } else { 62 + iio_add_event_to_list(&iio_event_data_rdy_trig, 63 + &indio_dev->interrupts[0]->ev_list); 64 + } 65 + return ret; 66 + } 67 + 68 + /** 69 + * adis16204_trig_try_reen() try renabling irq for data rdy trigger 70 + * @trig: the datardy trigger 71 + **/ 72 + static int adis16204_trig_try_reen(struct iio_trigger *trig) 73 + { 74 + struct adis16204_state *st = trig->private_data; 75 + enable_irq(st->us->irq); 76 + return 0; 77 + } 78 + 79 + int adis16204_probe_trigger(struct iio_dev *indio_dev) 80 + { 81 + int ret; 82 + struct adis16204_state *st = indio_dev->dev_data; 83 + 84 + st->trig = iio_allocate_trigger(); 85 + st->trig->name = kasprintf(GFP_KERNEL, 86 + "adis16204-dev%d", 87 + indio_dev->id); 88 + if (!st->trig->name) { 89 + ret = -ENOMEM; 90 + goto error_free_trig; 91 + } 92 + st->trig->dev.parent = &st->us->dev; 93 + st->trig->owner = THIS_MODULE; 94 + st->trig->private_data = st; 95 + st->trig->set_trigger_state = &adis16204_data_rdy_trigger_set_state; 96 + st->trig->try_reenable = &adis16204_trig_try_reen; 97 + st->trig->control_attrs = &adis16204_trigger_attr_group; 98 + ret = iio_trigger_register(st->trig); 99 + 100 + /* select default trigger */ 101 + indio_dev->trig = st->trig; 102 + if (ret) 103 + goto error_free_trig_name; 104 + 105 + return 0; 106 + 107 + error_free_trig_name: 108 + kfree(st->trig->name); 109 + error_free_trig: 110 + iio_free_trigger(st->trig); 111 + 112 + return ret; 113 + } 114 + 115 + void adis16204_remove_trigger(struct iio_dev *indio_dev) 116 + { 117 + struct adis16204_state *state = indio_dev->dev_data; 118 + 119 + iio_trigger_unregister(state->trig); 120 + kfree(state->trig->name); 121 + iio_free_trigger(state->trig); 122 + }