13 #include <linux/device.h>
14 #include <linux/kernel.h>
16 #include <linux/slab.h>
18 #include <linux/list.h>
19 #include <linux/module.h>
27 #define DRIVER_NAME "adis16204"
35 static int adis16204_spi_write_reg_8(
struct iio_dev *indio_dev,
46 ret = spi_write(st->
us, st->tx, 2);
59 static int adis16204_spi_write_reg_16(
struct iio_dev *indio_dev,
82 st->tx[1] = value & 0xFF;
84 st->tx[3] = (value >> 8) & 0xFF;
86 spi_message_init(&
msg);
87 spi_message_add_tail(&xfers[0], &
msg);
88 spi_message_add_tail(&xfers[1], &
msg);
102 static int adis16204_spi_read_reg_16(
struct iio_dev *indio_dev,
103 u8 lower_reg_address,
128 spi_message_init(&
msg);
129 spi_message_add_tail(&xfers[0], &
msg);
130 spi_message_add_tail(&xfers[1], &
msg);
133 dev_err(&st->
us->dev,
"problem when reading 16 bit register 0x%02X",
137 *val = (st->
rx[0] << 8) | st->
rx[1];
144 static int adis16204_check_status(
struct iio_dev *indio_dev)
149 ret = adis16204_spi_read_reg_16(indio_dev,
152 dev_err(&indio_dev->
dev,
"Reading status failed\n");
158 dev_err(&indio_dev->
dev,
"Self test failure\n");
162 dev_err(&indio_dev->
dev,
"Flash update failed\n");
164 dev_err(&indio_dev->
dev,
"Power supply above 3.625V\n");
166 dev_err(&indio_dev->
dev,
"Power supply below 2.975V\n");
172 static int adis16204_reset(
struct iio_dev *indio_dev)
175 ret = adis16204_spi_write_reg_8(indio_dev,
179 dev_err(&indio_dev->
dev,
"problem resetting device");
206 static int adis16204_self_test(
struct iio_dev *indio_dev)
209 ret = adis16204_spi_write_reg_16(indio_dev,
213 dev_err(&indio_dev->
dev,
"problem starting self test");
217 adis16204_check_status(indio_dev);
223 static int adis16204_initial_setup(
struct iio_dev *indio_dev)
230 dev_err(&indio_dev->
dev,
"disable irq failed");
235 ret = adis16204_self_test(indio_dev);
237 dev_err(&indio_dev->
dev,
"self test failure");
242 ret = adis16204_check_status(indio_dev);
244 adis16204_reset(indio_dev);
245 dev_err(&indio_dev->
dev,
"device not playing ball -> reset");
247 ret = adis16204_check_status(indio_dev);
269 static u8 adis16204_addresses[6][3] = {
281 static int adis16204_read_raw(
struct iio_dev *indio_dev,
295 addr = adis16204_addresses[chan->
address][0];
296 ret = adis16204_spi_read_reg_16(indio_dev, addr, &val16);
303 ret = adis16204_check_status(indio_dev);
309 val16 = val16 & ((1 << chan->
scan_type.realbits) - 1);
311 val16 = (
s16)(val16 <<
318 switch (chan->
type) {
350 *val = 25000 / -470 - 1278;
362 addr = adis16204_addresses[chan->
address][addrind];
363 ret = adis16204_spi_read_reg_16(indio_dev, addr, &val16);
368 val16 &= (1 <<
bits) - 1;
369 val16 = (
s16)(val16 << (16 - bits)) >> (16 - bits);
377 static int adis16204_write_raw(
struct iio_dev *indio_dev,
388 switch (chan->
type) {
395 val16 = val & ((1 <<
bits) - 1);
396 addr = adis16204_addresses[chan->
address][1];
397 return adis16204_spi_write_reg_16(indio_dev, addr, val16);
407 .extend_name =
"supply",
492 static const struct iio_info adis16204_info = {
493 .read_raw = &adis16204_read_raw,
494 .write_raw = &adis16204_write_raw,
506 if (indio_dev ==
NULL) {
510 st = iio_priv(indio_dev);
512 spi_set_drvdata(spi, indio_dev);
516 indio_dev->
name = spi->
dev.driver->name;
517 indio_dev->
dev.parent = &spi->
dev;
518 indio_dev->
info = &adis16204_info;
519 indio_dev->
channels = adis16204_channels;
532 goto error_unreg_ring_funcs;
538 goto error_uninitialize_ring;
542 ret = adis16204_initial_setup(indio_dev);
544 goto error_remove_trigger;
547 goto error_remove_trigger;
551 error_remove_trigger:
553 error_uninitialize_ring:
555 error_unreg_ring_funcs:
565 struct iio_dev *indio_dev = spi_get_drvdata(spi);
581 .probe = adis16204_probe,