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 "adis16260"
29 static int adis16260_check_status(
struct iio_dev *indio_dev);
37 static int adis16260_spi_write_reg_8(
struct iio_dev *indio_dev,
48 ret = spi_write(st->
us, st->tx, 2);
61 static int adis16260_spi_write_reg_16(
struct iio_dev *indio_dev,
85 st->tx[1] = value & 0xFF;
87 st->tx[3] = (value >> 8) & 0xFF;
89 spi_message_init(&
msg);
90 spi_message_add_tail(&xfers[0], &
msg);
91 spi_message_add_tail(&xfers[1], &
msg);
105 static int adis16260_spi_read_reg_16(
struct iio_dev *indio_dev,
106 u8 lower_reg_address,
131 spi_message_init(&
msg);
132 spi_message_add_tail(&xfers[0], &
msg);
133 spi_message_add_tail(&xfers[1], &
msg);
137 "problem when reading 16 bit register 0x%02X",
141 *val = (st->
rx[0] << 8) | st->
rx[1];
152 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
155 return sprintf(buf,
"%s\n",
"0.129 ~ 256");
157 return sprintf(buf,
"%s\n",
"256 2048");
164 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
169 ret = adis16260_spi_read_reg_16(indio_dev,
180 len =
sprintf(buf,
"%d SPS\n", sps);
189 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
217 ret = adis16260_spi_write_reg_8(indio_dev,
223 return ret ? ret : len;
226 static int adis16260_reset(
struct iio_dev *indio_dev)
229 ret = adis16260_spi_write_reg_8(indio_dev,
233 dev_err(&indio_dev->
dev,
"problem resetting device");
261 static int adis16260_stop_device(
struct iio_dev *indio_dev)
268 dev_err(&indio_dev->
dev,
"problem with turning device off: SLP_CNT");
273 static int adis16260_self_test(
struct iio_dev *indio_dev)
276 ret = adis16260_spi_write_reg_16(indio_dev,
280 dev_err(&indio_dev->
dev,
"problem starting self test");
284 adis16260_check_status(indio_dev);
290 static int adis16260_check_status(
struct iio_dev *indio_dev)
296 ret = adis16260_spi_read_reg_16(indio_dev,
301 dev_err(dev,
"Reading status failed\n");
306 dev_err(dev,
"Flash checksum error\n");
308 dev_err(dev,
"Self test error\n");
310 dev_err(dev,
"Sensor overrange\n");
314 dev_err(dev,
"Flash update failed\n");
316 dev_err(dev,
"Power supply above 5.25V\n");
318 dev_err(dev,
"Power supply below 4.75V\n");
324 static int adis16260_initial_setup(
struct iio_dev *indio_dev)
332 dev_err(dev,
"disable irq failed");
337 ret = adis16260_self_test(indio_dev);
339 dev_err(dev,
"self test failure");
344 ret = adis16260_check_status(indio_dev);
346 adis16260_reset(indio_dev);
347 dev_err(dev,
"device not playing ball -> reset");
349 ret = adis16260_check_status(indio_dev);
361 adis16260_read_frequency,
362 adis16260_write_frequency);
365 S_IRUGO, adis16260_read_frequency_available,
NULL, 0);
374 #define ADIS16260_GYRO_CHANNEL_SET(axis, mod) \
375 struct iio_chan_spec adis16260_channels_##axis[] = { \
377 .type = IIO_ANGL_VEL, \
380 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
381 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
382 IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
383 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
385 .scan_index = ADIS16260_SCAN_GYRO, \
395 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
397 .scan_index = ADIS16260_SCAN_ANGL, \
407 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
408 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
409 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
411 .scan_index = ADIS16260_SCAN_TEMP, \
418 .type = IIO_VOLTAGE, \
421 .extend_name = "supply", \
422 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
423 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
424 .address = in_supply, \
425 .scan_index = ADIS16260_SCAN_SUPPLY, \
432 .type = IIO_VOLTAGE, \
435 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
436 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
438 .scan_index = ADIS16260_SCAN_AUX_ADC, \
445 IIO_CHAN_SOFT_TIMESTAMP(5), \
452 static const u8 adis16260_addresses[5][3] = {
461 static int adis16260_read_raw(
struct iio_dev *indio_dev,
475 addr = adis16260_addresses[chan->
address][0];
476 ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16);
483 ret = adis16260_check_status(indio_dev);
489 val16 = val16 & ((1 << chan->
scan_type.realbits) - 1);
491 val16 = (
s16)(val16 <<
498 switch (chan->
type) {
527 *val = 250000 / 1453;
530 switch (chan->
type) {
538 addr = adis16260_addresses[chan->
address][1];
539 ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16);
544 val16 &= (1 <<
bits) - 1;
545 val16 = (
s16)(val16 << (16 - bits)) >> (16 - bits);
550 switch (chan->
type) {
558 addr = adis16260_addresses[chan->
address][2];
559 ret = adis16260_spi_read_reg_16(indio_dev, addr, &val16);
564 *val = (1 <<
bits) - 1;
571 static int adis16260_write_raw(
struct iio_dev *indio_dev,
582 val16 = val & ((1 <<
bits) - 1);
583 addr = adis16260_addresses[chan->
address][1];
584 return adis16260_spi_write_reg_16(indio_dev, addr, val16);
586 val16 = val & ((1 <<
bits) - 1);
587 addr = adis16260_addresses[chan->
address][2];
588 return adis16260_spi_write_reg_16(indio_dev, addr, val16);
593 static struct attribute *adis16260_attributes[] = {
594 &iio_dev_attr_sampling_frequency.dev_attr.attr,
595 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
600 .attrs = adis16260_attributes,
603 static const struct iio_info adis16260_info = {
604 .attrs = &adis16260_attribute_group,
605 .read_raw = &adis16260_read_raw,
606 .write_raw = &adis16260_write_raw,
619 if (indio_dev ==
NULL) {
623 st = iio_priv(indio_dev);
627 spi_set_drvdata(spi, indio_dev);
633 indio_dev->
dev.parent = &spi->
dev;
634 indio_dev->
info = &adis16260_info;
640 indio_dev->
channels = adis16260_channels_x;
643 indio_dev->
channels = adis16260_channels_y;
646 indio_dev->
channels = adis16260_channels_z;
652 indio_dev->
channels = adis16260_channels_x;
665 goto error_unreg_ring_funcs;
683 goto error_uninitialize_ring;
687 ret = adis16260_initial_setup(indio_dev);
689 goto error_remove_trigger;
692 goto error_remove_trigger;
696 error_remove_trigger:
698 error_uninitialize_ring:
700 error_unreg_ring_funcs:
710 struct iio_dev *indio_dev = spi_get_drvdata(spi);
713 adis16260_stop_device(indio_dev);
741 .probe = adis16260_probe,
743 .id_table = adis16260_id,