11 #include <linux/device.h>
12 #include <linux/kernel.h>
14 #include <linux/slab.h>
16 #include <linux/list.h>
17 #include <linux/module.h>
25 #define DRIVER_NAME "adis16209"
33 static int adis16209_spi_write_reg_8(
struct iio_dev *indio_dev,
44 ret = spi_write(st->
us, st->tx, 2);
57 static int adis16209_spi_write_reg_16(
struct iio_dev *indio_dev,
81 st->tx[1] = value & 0xFF;
83 st->tx[3] = (value >> 8) & 0xFF;
85 spi_message_init(&
msg);
86 spi_message_add_tail(&xfers[0], &
msg);
87 spi_message_add_tail(&xfers[1], &
msg);
101 static int adis16209_spi_read_reg_16(
struct iio_dev *indio_dev,
102 u8 lower_reg_address,
127 spi_message_init(&
msg);
128 spi_message_add_tail(&xfers[0], &
msg);
129 spi_message_add_tail(&xfers[1], &
msg);
133 "problem when reading 16 bit register 0x%02X",
137 *val = (st->
rx[0] << 8) | st->
rx[1];
144 static int adis16209_reset(
struct iio_dev *indio_dev)
147 ret = adis16209_spi_write_reg_8(indio_dev,
151 dev_err(&indio_dev->
dev,
"problem resetting device");
178 static int adis16209_check_status(
struct iio_dev *indio_dev)
183 ret = adis16209_spi_read_reg_16(indio_dev,
186 dev_err(&indio_dev->
dev,
"Reading status failed\n");
192 dev_err(&indio_dev->
dev,
"Self test failure\n");
196 dev_err(&indio_dev->
dev,
"Flash update failed\n");
198 dev_err(&indio_dev->
dev,
"Power supply above 3.625V\n");
200 dev_err(&indio_dev->
dev,
"Power supply below 3.15V\n");
206 static int adis16209_self_test(
struct iio_dev *indio_dev)
209 ret = adis16209_spi_write_reg_16(indio_dev,
213 dev_err(&indio_dev->
dev,
"problem starting self test");
217 adis16209_check_status(indio_dev);
223 static int adis16209_initial_setup(
struct iio_dev *indio_dev)
230 dev_err(&indio_dev->
dev,
"disable irq failed");
235 ret = adis16209_self_test(indio_dev);
237 dev_err(&indio_dev->
dev,
"self test failure");
242 ret = adis16209_check_status(indio_dev);
244 adis16209_reset(indio_dev);
245 dev_err(&indio_dev->
dev,
"device not playing ball -> reset");
247 ret = adis16209_check_status(indio_dev);
269 static const u8 adis16209_addresses[8][2] = {
280 static int adis16209_write_raw(
struct iio_dev *indio_dev,
291 switch (chan->
type) {
299 val16 = val & ((1 <<
bits) - 1);
300 addr = adis16209_addresses[chan->
address][1];
301 return adis16209_spi_write_reg_16(indio_dev, addr, val16);
306 static int adis16209_read_raw(
struct iio_dev *indio_dev,
319 addr = adis16209_addresses[chan->
address][0];
320 ret = adis16209_spi_read_reg_16(indio_dev, addr, &val16);
327 ret = adis16209_check_status(indio_dev);
333 val16 = val16 & ((1 << chan->
scan_type.realbits) - 1);
335 val16 = (
s16)(val16 <<
342 switch (chan->
type) {
368 *val = 25000 / -470 - 0x4FE;
371 switch (chan->
type) {
379 addr = adis16209_addresses[chan->
address][1];
380 ret = adis16209_spi_read_reg_16(indio_dev, addr, &val16);
385 val16 &= (1 <<
bits) - 1;
386 val16 = (
s16)(val16 << (16 - bits)) >> (16 - bits);
399 .extend_name =
"supply",
507 static const struct iio_info adis16209_info = {
508 .read_raw = &adis16209_read_raw,
509 .write_raw = &adis16209_write_raw,
521 if (indio_dev ==
NULL) {
525 st = iio_priv(indio_dev);
527 spi_set_drvdata(spi, indio_dev);
531 indio_dev->
name = spi->
dev.driver->name;
532 indio_dev->
dev.parent = &spi->
dev;
533 indio_dev->
info = &adis16209_info;
534 indio_dev->
channels = adis16209_channels;
547 goto error_unreg_ring_funcs;
553 goto error_uninitialize_ring;
557 ret = adis16209_initial_setup(indio_dev);
559 goto error_remove_trigger;
562 goto error_remove_trigger;
566 error_remove_trigger:
568 error_uninitialize_ring:
570 error_unreg_ring_funcs:
580 struct iio_dev *indio_dev = spi_get_drvdata(spi);
596 .probe = adis16209_probe,