staging:iio: Add common ADIS library
Subsystems (5)
PATCH 1/11 staging:iio: Add common ADIS library
A lot of the devices from the ADIS family use the same methods for accessing registers, sampling data and trigger handling. They also have similar register layout for the control registers.
This patch adds a common library for these devices. The library implements functions for reading and writing registers as buffer and trigger management. It also provides a set functions for accessing the control registers and for running the devices internal self-test. Having this common library code will allow us to remove a lot of duplicated code.
--- drivers/staging/iio/imu/Kconfig | 13 ++ drivers/staging/iio/imu/Makefile | 5 + drivers/staging/iio/imu/adis.c | 338 +++++++++++++++++++++++++++++++++ drivers/staging/iio/imu/adis.h | 178 +++++++++++++++++ drivers/staging/iio/imu/adis_buffer.c | 200 +++++++++++++++++++ drivers/staging/iio/imu/adis_trigger.c | 90 +++++++++ 6 files changed, 824 insertions(+) create mode 100644 drivers/staging/iio/imu/adis.c create mode 100644 drivers/staging/iio/imu/adis.h create mode 100644 drivers/staging/iio/imu/adis_buffer.c create mode 100644 drivers/staging/iio/imu/adis_trigger.c
drivers/staging/iio/imu/Kconfig +13 -0
@@ -15,3 +15,16 @@ config ADIS16400 (adis16400 series also have magnetometers). endmenu + +config IIO_ADIS_LIB + tristate + help + A set of IO helper functions for the Analog Devices ADIS* device family. + +config IIO_ADIS_LIB_BUFFER + bool + select IIO_TRIGGER + select IIO_SW_RING + help + A set of buffer helper functions for the Analog Devices ADIS* device + family.
drivers/staging/iio/imu/Makefile +5 -0
@@ -5,3 +5,8 @@ adis16400-y := adis16400_core.o adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o adis16400_trigger.o obj-$(CONFIG_ADIS16400) += adis16400.o + +adis_lib-y += adis.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o +obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o
drivers/staging/iio/imu/adis.c new file +338 -0
338 lines not on this page · raw message
drivers/staging/iio/imu/adis.h new file +178 -0
178 lines not on this page · raw message
drivers/staging/iio/imu/adis_buffer.c new file +200 -0
200 lines not on this page · raw message
drivers/staging/iio/imu/adis_trigger.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 2/11 staging:iio:adis16201: Use adis library
Use the new adis library for the adis16201 driver. This allows us to completely scrap the adis16201 buffer and trigger code and more than half of the core driver code.
--- drivers/staging/iio/accel/Kconfig | 4 +- drivers/staging/iio/accel/Makefile | 1 - drivers/staging/iio/accel/adis16201.h | 89 +---- drivers/staging/iio/accel/adis16201_core.c | 465 ++++---------------------- drivers/staging/iio/accel/adis16201_ring.c | 136 -------- drivers/staging/iio/accel/adis16201_trigger.c | 71 ---- 6 files changed, 69 insertions(+), 697 deletions(-) delete mode 100644 drivers/staging/iio/accel/adis16201_ring.c delete mode 100644 drivers/staging/iio/accel/adis16201_trigger.c
drivers/staging/iio/accel/Kconfig +2 -2
@@ -6,8 +6,8 @@ menu "Accelerometers" config ADIS16201 tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16201 dual-axis digital inclinometer and accelerometer.
drivers/staging/iio/accel/Makefile +0 -1
@@ -3,7 +3,6 @@ # adis16201-y := adis16201_core.o -adis16201-$(CONFIG_IIO_BUFFER) += adis16201_ring.o adis16201_trigger.o obj-$(CONFIG_ADIS16201) += adis16201.o adis16203-y := adis16203_core.o
drivers/staging/iio/accel/adis16201.h +7 -82
119 lines not on this page · raw message
drivers/staging/iio/accel/adis16201_core.c +60 -405
546 lines not on this page · raw message
drivers/staging/iio/accel/adis16201_ring.c deleted +0 -136
136 lines not on this page · raw message
drivers/staging/iio/accel/adis16201_trigger.c deleted +0 -71
71 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 3/11 staging:iio:adis16203: Use adis library
In reply to Lars-Peter ClausenUse the new adis library for the adis16203 driver. This allows us to completely scrap the adis16203 buffer and trigger code and more than half of the core driver code.
--- drivers/staging/iio/accel/Kconfig | 4 +- drivers/staging/iio/accel/Makefile | 1 - drivers/staging/iio/accel/adis16203.h | 80 +---- drivers/staging/iio/accel/adis16203_core.c | 425 ++++---------------------- drivers/staging/iio/accel/adis16203_ring.c | 136 --------- drivers/staging/iio/accel/adis16203_trigger.c | 73 ----- 6 files changed, 66 insertions(+), 653 deletions(-) delete mode 100644 drivers/staging/iio/accel/adis16203_ring.c delete mode 100644 drivers/staging/iio/accel/adis16203_trigger.c
drivers/staging/iio/accel/Kconfig +2 -2
@@ -15,8 +15,8 @@ config ADIS16201 config ADIS16203 tristate "Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16203 Programmable 360 Degrees Inclinometer.
drivers/staging/iio/accel/Makefile +0 -1
@@ -6,7 +6,6 @@ adis16201-y := adis16201_core.o obj-$(CONFIG_ADIS16201) += adis16201.o adis16203-y := adis16203_core.o -adis16203-$(CONFIG_IIO_BUFFER) += adis16203_ring.o adis16203_trigger.o obj-$(CONFIG_ADIS16203) += adis16203.o adis16204-y := adis16204_core.o
drivers/staging/iio/accel/adis16203.h +7 -73
110 lines not on this page · raw message
drivers/staging/iio/accel/adis16203_core.c +57 -368
512 lines not on this page · raw message
drivers/staging/iio/accel/adis16203_ring.c deleted +0 -136
136 lines not on this page · raw message
drivers/staging/iio/accel/adis16203_trigger.c deleted +0 -73
73 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 4/11 staging:iio:adis16204: Use adis library
In reply to Lars-Peter ClausenUse the new adis library for the adis16204 driver. This allows us to completely scrap the adis16204 buffer and trigger code and more than half of the core driver code.
--- drivers/staging/iio/accel/Kconfig | 4 +- drivers/staging/iio/accel/Makefile | 1 - drivers/staging/iio/accel/adis16204.h | 79 +---- drivers/staging/iio/accel/adis16204_core.c | 451 ++++---------------------- drivers/staging/iio/accel/adis16204_ring.c | 134 -------- drivers/staging/iio/accel/adis16204_trigger.c | 73 ----- 6 files changed, 70 insertions(+), 672 deletions(-) delete mode 100644 drivers/staging/iio/accel/adis16204_ring.c delete mode 100644 drivers/staging/iio/accel/adis16204_trigger.c
drivers/staging/iio/accel/Kconfig +2 -2
@@ -24,8 +24,8 @@ config ADIS16203 config ADIS16204 tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16204 Programmable High-g Digital Impact Sensor and Recorder.
drivers/staging/iio/accel/Makefile +0 -1
@@ -9,7 +9,6 @@ adis16203-y := adis16203_core.o obj-$(CONFIG_ADIS16203) += adis16203.o adis16204-y := adis16204_core.o -adis16204-$(CONFIG_IIO_BUFFER) += adis16204_ring.o adis16204_trigger.o obj-$(CONFIG_ADIS16204) += adis16204.o adis16209-y := adis16209_core.o
drivers/staging/iio/accel/adis16204.h +7 -72
111 lines not on this page · raw message
drivers/staging/iio/accel/adis16204_core.c +61 -390
542 lines not on this page · raw message
drivers/staging/iio/accel/adis16204_ring.c deleted +0 -134
134 lines not on this page · raw message
drivers/staging/iio/accel/adis16204_trigger.c deleted +0 -73
73 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 5/11 staging:iio:adis16209: Use adis library
In reply to Lars-Peter ClausenUse the new adis library for the adis16209 driver. This allows us to completely scrap the adis16209 buffer and trigger code and more than half of the core driver code.
--- drivers/staging/iio/accel/Kconfig | 4 +- drivers/staging/iio/accel/Makefile | 1 - drivers/staging/iio/accel/adis16209.h | 77 +--- drivers/staging/iio/accel/adis16209_core.c | 485 ++++---------------------- drivers/staging/iio/accel/adis16209_ring.c | 134 ------- drivers/staging/iio/accel/adis16209_trigger.c | 72 ---- 6 files changed, 74 insertions(+), 699 deletions(-) delete mode 100644 drivers/staging/iio/accel/adis16209_ring.c delete mode 100644 drivers/staging/iio/accel/adis16209_trigger.c
drivers/staging/iio/accel/Kconfig +2 -2
@@ -33,8 +33,8 @@ config ADIS16204 config ADIS16209 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16209 dual-axis digital inclinometer and accelerometer.
drivers/staging/iio/accel/Makefile +0 -1
@@ -12,7 +12,6 @@ adis16204-y := adis16204_core.o obj-$(CONFIG_ADIS16204) += adis16204.o adis16209-y := adis16209_core.o -adis16209-$(CONFIG_IIO_BUFFER) += adis16209_ring.o adis16209_trigger.o obj-$(CONFIG_ADIS16209) += adis16209.o adis16220-y := adis16220_core.o
drivers/staging/iio/accel/adis16209.h +5 -72
111 lines not on this page · raw message
drivers/staging/iio/accel/adis16209_core.c +67 -418
566 lines not on this page · raw message
drivers/staging/iio/accel/adis16209_ring.c deleted +0 -134
134 lines not on this page · raw message
drivers/staging/iio/accel/adis16209_trigger.c deleted +0 -72
72 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 6/11 staging:iio:adis16220: Use adis library
In reply to Lars-Peter ClausenUse the new adis library for the adis16220 driver. The adis16220 driver is a bit special and so we can only make use of the generic register access and control functions for now.
--- drivers/staging/iio/accel/adis16220.h | 20 +-- drivers/staging/iio/accel/adis16220_core.c | 280 ++++++----------------------- 2 files changed, 60 insertions(+), 240 deletions(-)
drivers/staging/iio/accel/adis16220.h +10 -10
@@ -1,10 +1,9 @@#ifndef SPI_ADIS16220_H_ #define SPI_ADIS16220_H_ -#define ADIS16220_STARTUP_DELAY 220/* ms */ +#include "../imu/adis.h" -#define ADIS16220_READ_REG (a) a -#define ADIS16220_WRITE_REG (a) ((a) | 0x80) +#define ADIS16220_STARTUP_DELAY 220/* ms */ /* Flash memory write count */ #define ADIS16220_FLASH_CNT 0x00
@@ -102,15 +101,15 @@#define ADIS16220_DIAG_STAT_FLASH_CHK (1<<6)#define ADIS16220_DIAG_STAT_SELF_TEST (1<<5)/* Capture period violation/interruption */ -#define ADIS16220_DIAG_STAT_VIOLATION (1<<4) +#define ADIS16220_DIAG_STAT_VIOLATION_BIT 4/* SPI communications failure */ -#define ADIS16220_DIAG_STAT_SPI_FAIL (1<<3) +#define ADIS16220_DIAG_STAT_SPI_FAIL_BIT 3/* Flash update failure */ -#define ADIS16220_DIAG_STAT_FLASH_UPT (1<<2) +#define ADIS16220_DIAG_STAT_FLASH_UPT_BIT 2/* Power supply above 3.625 V */ -#define ADIS16220_DIAG_STAT_POWER_HIGH (1<<1) +#define ADIS16220_DIAG_STAT_POWER_HIGH_BIT 1/* Power supply below 3.15 V */ -#define ADIS16220_DIAG_STAT_POWER_LOW (1<<0) +#define ADIS16220_DIAG_STAT_POWER_LOW_BIT 0/* GLOB_CMD */ #define ADIS16220_GLOB_CMD_SW_RESET (1<<7)
@@ -125,13 +124,14 @@/** * struct adis16220_state - device instance specific data -* @us: actual spi_device +* @adis: adis device * @tx: transmit buffer * @rx: receive buffer * @buf_lock: mutex to protect tx and rx **/ struct adis16220_state { -struct spi_device *us; +struct adis adis; +struct mutex buf_lock;u8 tx[ADIS16220_MAX_TX ]____cacheline_aligned ;u8 rx[ADIS16220_MAX_RX ];
drivers/staging/iio/accel/adis16220_core.c +50 -230
387 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 7/11 staging:iio:adis16240: Use adis library
In reply to Lars-Peter ClausenUse the new adis library for the adis16240 driver. This allows us to completely scrap the adis16240 buffer and trigger code and more than half of the core driver code.
--- drivers/staging/iio/accel/Kconfig | 5 +- drivers/staging/iio/accel/Makefile | 1 - drivers/staging/iio/accel/adis16240.h | 85 +---- drivers/staging/iio/accel/adis16240_core.c | 472 ++++---------------------- drivers/staging/iio/accel/adis16240_ring.c | 132 ------- drivers/staging/iio/accel/adis16240_trigger.c | 73 ---- 6 files changed, 77 insertions(+), 691 deletions(-) delete mode 100644 drivers/staging/iio/accel/adis16240_ring.c delete mode 100644 drivers/staging/iio/accel/adis16240_trigger.c
drivers/staging/iio/accel/Kconfig +3 -2
@@ -42,6 +42,7 @@ config ADIS16209 config ADIS16220 tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor" depends on SPI + select IIO_ADIS_LIB help Say yes here to build support for Analog Devices adis16220 programmable digital vibration sensor.
@@ -49,8 +50,8 @@ config ADIS16220 config ADIS16240 tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" depends on SPI - select IIO_TRIGGER if IIO_BUFFER - select IIO_SW_RING if IIO_BUFFER + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help Say yes here to build support for Analog Devices adis16240 programmable impact Sensor and recorder.
drivers/staging/iio/accel/Makefile +0 -1
@@ -18,7 +18,6 @@ adis16220-y := adis16220_core.o obj-$(CONFIG_ADIS16220) += adis16220.o adis16240-y := adis16240_core.o -adis16240-$(CONFIG_IIO_BUFFER) += adis16240_ring.o adis16240_trigger.o obj-$(CONFIG_ADIS16240) += adis16240.o obj-$(CONFIG_KXSD9) += kxsd9.o
drivers/staging/iio/accel/adis16240.h +9 -76
120 lines not on this page · raw message
drivers/staging/iio/accel/adis16240_core.c +65 -407
589 lines not on this page · raw message
drivers/staging/iio/accel/adis16240_ring.c deleted +0 -132
132 lines not on this page · raw message
drivers/staging/iio/accel/adis16240_trigger.c deleted +0 -73
73 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 8/11 staging:iio:adis16260: Use adis library
In reply to Lars-Peter ClausenUse the new adis library for the adis16260 driver. This allows us to completely scrap the adis16260 buffer and trigger code and about half of the core driver code.
--- drivers/staging/iio/gyro/Makefile | 1 - drivers/staging/iio/gyro/adis16260.h | 84 +---- drivers/staging/iio/gyro/adis16260_core.c | 483 +++++---------------------- drivers/staging/iio/gyro/adis16260_ring.c | 136 -------- drivers/staging/iio/gyro/adis16260_trigger.c | 75 ----- 5 files changed, 94 insertions(+), 685 deletions(-) delete mode 100644 drivers/staging/iio/gyro/adis16260_ring.c delete mode 100644 drivers/staging/iio/gyro/adis16260_trigger.c
drivers/staging/iio/gyro/Makefile +0 -1
@@ -12,7 +12,6 @@ adis16130-y := adis16130_core.o obj-$(CONFIG_ADIS16130) += adis16130.o adis16260-y := adis16260_core.o -adis16260-$(CONFIG_IIO_BUFFER) += adis16260_ring.o adis16260_trigger.o obj-$(CONFIG_ADIS16260) += adis16260.o adis16251-y := adis16251_core.o
drivers/staging/iio/gyro/adis16260.h +13 -71
128 lines not on this page · raw message
drivers/staging/iio/gyro/adis16260_core.c +81 -402
624 lines not on this page · raw message
drivers/staging/iio/gyro/adis16260_ring.c deleted +0 -136
136 lines not on this page · raw message
drivers/staging/iio/gyro/adis16260_trigger.c deleted +0 -75
75 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 9/11 staging:iio:adis_lib: Use triggered buffer setup helper function
In reply to Lars-Peter ClausenUse the triggered buffer helper functions to setup and tear down the buffer for the adis library instead of doing this manually. This also means that we switch away from the deprecated sw_ring buffer and use the kfifo buffer now instead.
--- drivers/staging/iio/imu/Kconfig | 3 +- drivers/staging/iio/imu/adis_buffer.c | 78 +++++------------------------------ 2 files changed, 11 insertions(+), 70 deletions(-)
drivers/staging/iio/imu/Kconfig +1 -2
@@ -23,8 +23,7 @@ config IIO_ADIS_LIB config IIO_ADIS_LIB_BUFFER bool - select IIO_TRIGGER - select IIO_SW_RING + select IIO_TRIGGERED_BUFFER help A set of buffer helper functions for the Analog Devices ADIS* device family.
drivers/staging/iio/imu/adis_buffer.c +10 -68
111 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 10/11 staging:iio:adis: Preallocate transfer message
In reply to Lars-Peter ClausenCurrently the driver reads out all sample registers of the device and throws away those which it does not need. Furthermore the SPI message is constructed each time the trigger handler is run, although it will be the same each time. This patch preallocates and pre-constructs the SPI message in the "update_scan_mode" callback. Only those register which are actually selected for sampling are included in the message. The patch also gets rid of the conversion of the sample data from big endian to the native endianness and instead marks the channel as big endian in its scan type. This allows to directly push the SPI transfer buffer to the IIO buffer without the need to post-process it.
--- drivers/staging/iio/accel/adis16201_core.c | 1 + drivers/staging/iio/accel/adis16203_core.c | 1 + drivers/staging/iio/accel/adis16204_core.c | 1 + drivers/staging/iio/accel/adis16209_core.c | 1 + drivers/staging/iio/accel/adis16240_core.c | 1 + drivers/staging/iio/gyro/adis16260_core.c | 1 + drivers/staging/iio/imu/adis.h | 8 ++ drivers/staging/iio/imu/adis_buffer.c | 114 +++++++++++++++++------------ 8 files changed, 80 insertions(+), 48 deletions(-)
drivers/staging/iio/accel/adis16201_core.c +1 -0
@@ -148,6 +148,7 @@ static const struct iio_chan_spec adis16201_channels[] = {static const struct iio_info adis16201_info = { .read_raw = &adis16201_read_raw, .write_raw = &adis16201_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module =THIS_MODULE , };
drivers/staging/iio/accel/adis16203_core.c +1 -0
@@ -112,6 +112,7 @@ static const struct iio_chan_spec adis16203_channels[] = {static const struct iio_info adis16203_info = { .read_raw = &adis16203_read_raw, .write_raw = &adis16203_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module =THIS_MODULE , };
drivers/staging/iio/accel/adis16204_core.c +1 -0
@@ -153,6 +153,7 @@ static const struct iio_chan_spec adis16204_channels[] = {static const struct iio_info adis16204_info = { .read_raw = &adis16204_read_raw, .write_raw = &adis16204_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module =THIS_MODULE , };
drivers/staging/iio/accel/adis16209_core.c +1 -0
@@ -146,6 +146,7 @@ static const struct iio_chan_spec adis16209_channels[] = {static const struct iio_info adis16209_info = { .read_raw = &adis16209_read_raw, .write_raw = &adis16209_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module =THIS_MODULE , };
drivers/staging/iio/accel/adis16240_core.c +1 -0
@@ -202,6 +202,7 @@ static const struct iio_info adis16240_info = { .attrs = &adis16240_attribute_group, .read_raw = &adis16240_read_raw, .write_raw = &adis16240_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, };
drivers/staging/iio/gyro/adis16260_core.c +1 -0
@@ -267,6 +267,7 @@ static const struct iio_info adis16260_info = { .attrs = &adis16260_attribute_group, .read_raw = &adis16260_read_raw, .write_raw = &adis16260_write_raw, + .update_scan_mode = adis_update_scan_mode, .driver_module = THIS_MODULE, };
drivers/staging/iio/imu/adis.h +8 -0
@@ -87,6 +87,7 @@ int adis_single_conversion(struct iio_dev *indio_dev, .sign = 'u', \ .realbits = (bits), \ .storagebits = 16, \ + .endianness = IIO_BE, \ }, \ }
@@ -109,6 +110,7 @@ int adis_single_conversion(struct iio_dev *indio_dev, .sign = 'u', \ .realbits = (bits), \ .storagebits = 16, \ + .endianness = IIO_BE, \ }, \ }
@@ -125,6 +127,7 @@ int adis_single_conversion(struct iio_dev *indio_dev, .sign = 's', \ .realbits = (bits), \ .storagebits = 16, \ + .endianness = IIO_BE, \ }, \ }
@@ -150,6 +153,9 @@ void adis_cleanup_buffer_and_trigger(struct adis *adis,int adis_probe_trigger (struct adis *adis,struct iio_dev *indio_dev);void adis_remove_trigger (struct adis *adis); +int adis_update_scan_mode (struct iio_dev *indio_dev, +const unsigned long *scan_mask); +#else /* CONFIG_IIO_BUFFER */ static inline int adis_setup_buffer_and_trigger(struct adis *adis,
@@ -173,6 +179,8 @@ static inline void adis_remove_trigger(struct adis *adis) { } +#define adis_update_scan_mode NULL +#endif /* CONFIG_IIO_BUFFER */ #endif
drivers/staging/iio/imu/adis_buffer.c +66 -48
148 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 11/11 staging:iio: Move adis library out of staging
In reply to Lars-Peter ClausenNow that the adis library no longer depends on the sw_ring buffer implementation we can move it out of staging.
While we are at it also sort the entries in the iio Kconfig and Makefile to be in alphabetical order.
---
drivers/iio/Kconfig | 7 ++++---
drivers/iio/Makefile | 7 ++++---
drivers/iio/imu/Kconfig | 11 +++++++++++
drivers/iio/imu/Makefile | 8 ++++++++
drivers/{staging => }/iio/imu/adis.c | 3 +--
drivers/{staging => }/iio/imu/adis_buffer.c | 3 +--
drivers/{staging => }/iio/imu/adis_trigger.c | 3 +--
drivers/staging/iio/accel/adis16201_core.c | 2 +-
drivers/staging/iio/accel/adis16203_core.c | 2 +-
drivers/staging/iio/accel/adis16204_core.c | 2 +-
drivers/staging/iio/accel/adis16209_core.c | 2 +-
drivers/staging/iio/accel/adis16220.h | 2 +-
drivers/staging/iio/accel/adis16240_core.c | 2 +-
drivers/staging/iio/gyro/adis16260.h | 2 +-
drivers/staging/iio/imu/Kconfig | 12 ------------
drivers/staging/iio/imu/Makefile | 5 -----
{drivers/staging => include/linux}/iio/imu/adis.h | 0
17 files changed, 37 insertions(+), 36 deletions(-)
create mode 100644 drivers/iio/imu/Kconfig
create mode 100644 drivers/iio/imu/Makefile
rename drivers/{staging => }/iio/imu/adis.c (99%)
rename drivers/{staging => }/iio/imu/adis_buffer.c (99%)
rename drivers/{staging => }/iio/imu/adis_trigger.c (98%)
rename {drivers/staging => include/linux}/iio/imu/adis.h (100%)drivers/iio/Kconfig +4 -3
@@ -63,11 +63,12 @@ config IIO_CONSUMERS_PER_TRIGGER source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/amplifiers/Kconfig" -source "drivers/iio/light/Kconfig" -source "drivers/iio/frequency/Kconfig" -source "drivers/iio/dac/Kconfig" source "drivers/iio/common/Kconfig" +source "drivers/iio/dac/Kconfig" +source "drivers/iio/frequency/Kconfig" source "drivers/iio/gyro/Kconfig" +source "drivers/iio/imu/Kconfig" +source "drivers/iio/light/Kconfig" source "drivers/iio/magnetometer/Kconfig" endif # IIO
drivers/iio/Makefile +4 -3
@@ -14,9 +14,10 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o obj-y += accel/ obj-y += adc/ obj-y += amplifiers/ -obj-y += light/ -obj-y += frequency/ -obj-y += dac/ obj-y += common/ +obj-y += dac/ obj-y += gyro/ +obj-y += frequency/ +obj-y += imu/ +obj-y += light/ obj-y += magnetometer/
drivers/iio/imu/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +config IIO_ADIS_LIB + tristate + help + A set of IO helper functions for the Analog Devices ADIS* device family. + +config IIO_ADIS_LIB_BUFFER + bool + select IIO_TRIGGERED_BUFFER + help + A set of buffer helper functions for the Analog Devices ADIS* device + family.
drivers/iio/imu/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Makefile for Inertial Measurement Units +# + +adis_lib-y += adis.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o +obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o
drivers/iio/imu/adis.c renamed from drivers/staging/iio/imu/adis.c +1 -2
@@ -20,8 +20,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> - -#include "adis.h" +#include <linux/iio/imu/adis.h> #define ADIS_MSC_CTRL_DATA_RDY_EN BIT(2)#define ADIS_MSC_CTRL_DATA_RDY_POL_HIGH BIT(1)
drivers/iio/imu/adis_buffer.c renamed from drivers/staging/iio/imu/adis_buffer.c +1 -2
@@ -18,8 +18,7 @@#include <linux/iio/buffer.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> - -#include "adis.h" +#include <linux/iio/imu/adis.h> int adis_update_scan_mode (struct iio_dev *indio_dev,const unsigned long *scan_mask)
drivers/iio/imu/adis_trigger.c renamed from drivers/staging/iio/imu/adis_trigger.c +1 -2
@@ -14,8 +14,7 @@#include <linux/iio/iio.h> #include <linux/iio/trigger.h> - -#include "adis.h" +#include <linux/iio/imu/adis.h> static int adis_data_rdy_trigger_set_state (struct iio_trigger *trig,bool state)
drivers/staging/iio/accel/adis16201_core.c +1 -1
@@ -18,9 +18,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16201.h" -#include "../imu/adis.h" static const u8 adis16201_addresses[] = { [ADIS16201_SCAN_ACC_X ] =ADIS16201_XACCL_OFFS ,
drivers/staging/iio/accel/adis16203_core.c +1 -1
@@ -18,9 +18,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16203.h" -#include "../imu/adis.h" #define DRIVER_NAME "adis16203"
drivers/staging/iio/accel/adis16204_core.c +1 -1
@@ -21,9 +21,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16204.h" -#include "../imu/adis.h" /* Unique to this driver currently */
drivers/staging/iio/accel/adis16209_core.c +1 -1
@@ -19,9 +19,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16209.h" -#include "../imu/adis.h" static const u8 adis16209_addresses[8 ][1 ] = { [ADIS16209_SCAN_SUPPLY ] = { },
drivers/staging/iio/accel/adis16220.h +1 -1
@@ -1,7 +1,7 @@#ifndef SPI_ADIS16220_H_ #define SPI_ADIS16220_H_ -#include "../imu/adis.h" +#include <linux/iio/imu/adis.h> #define ADIS16220_STARTUP_DELAY 220/* ms */
drivers/staging/iio/accel/adis16240_core.c +1 -1
@@ -22,9 +22,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16240.h" -#include "../imu/adis.h" static ssize_t adis16240_spi_read_signed(struct device *dev, struct device_attribute *attr,
drivers/staging/iio/gyro/adis16260.h +1 -1
@@ -2,7 +2,7 @@#define SPI_ADIS16260_H_ #include "adis16260_platform_data.h" -#include "../imu/adis.h" +#include <linux/iio/imu/adis.h> #define ADIS16260_STARTUP_DELAY 220/* ms */
drivers/staging/iio/imu/Kconfig +0 -12
@@ -15,15 +15,3 @@ config ADIS16400 (adis16400 series also have magnetometers). endmenu - -config IIO_ADIS_LIB - tristate - help - A set of IO helper functions for the Analog Devices ADIS* device family. - -config IIO_ADIS_LIB_BUFFER - bool - select IIO_TRIGGERED_BUFFER - help - A set of buffer helper functions for the Analog Devices ADIS* device - family.
drivers/staging/iio/imu/Makefile +0 -5
@@ -5,8 +5,3 @@ adis16400-y := adis16400_core.o adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o adis16400_trigger.o obj-$(CONFIG_ADIS16400) += adis16400.o - -adis_lib-y += adis.o -adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o -adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o -obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o
include/linux/iio/imu/adis.h renamed from drivers/staging/iio/imu/adis.h +0 -0
Signature · 1 line
1.8.0
Jonathan Cameron
maintainerRe: [PATCH 11/11] staging:iio: Move adis library out of staging
Quoted 5 lines · Lars-Peter Clausen
Now that the adis library no longer depends on the
sw_ringbuffer implementation we can move it out of staging.While we are at it also sort the entries in the iio
KconfigandMakefileto be in alphabetical order.
hmm.. slight moan here. Would have prefered a separate precursor patch to fix the ordering in kconfig and make file...
Quoted 2 lines
Signed-off-by Lars-Peter Clausen <[email protected]>
Merged with the rest into iio.git to greg branch.
Thanks,
Jonathan
Quoted 285 lines
--- drivers/iio/Kconfig | 7 ++++--- drivers/iio/Makefile | 7 ++++--- drivers/iio/imu/Kconfig | 11 +++++++++++ drivers/iio/imu/Makefile | 8 ++++++++ drivers/{staging => }/iio/imu/adis.c | 3 +-- drivers/{staging => }/iio/imu/adis_buffer.c | 3 +-- drivers/{staging => }/iio/imu/adis_trigger.c | 3 +-- drivers/staging/iio/accel/adis16201_core.c | 2 +- drivers/staging/iio/accel/adis16203_core.c | 2 +- drivers/staging/iio/accel/adis16204_core.c | 2 +- drivers/staging/iio/accel/adis16209_core.c | 2 +- drivers/staging/iio/accel/adis16220.h | 2 +- drivers/staging/iio/accel/adis16240_core.c | 2 +- drivers/staging/iio/gyro/adis16260.h | 2 +- drivers/staging/iio/imu/Kconfig | 12 ------------ drivers/staging/iio/imu/Makefile | 5 ----- {drivers/staging => include/linux}/iio/imu/adis.h | 0 17 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 drivers/iio/imu/Kconfig create mode 100644 drivers/iio/imu/Makefile rename drivers/{staging => }/iio/imu/adis.c (99%) rename drivers/{staging => }/iio/imu/adis_buffer.c (99%) rename drivers/{staging => }/iio/imu/adis_trigger.c (98%) rename {drivers/staging => include/linux}/iio/imu/adis.h (100%)drivers/iio/Kconfig +4
-3@@ -63,11 +63,12 @@ config IIO_CONSUMERS_PER_TRIGGER source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/amplifiers/Kconfig" -source "drivers/iio/light/Kconfig" -source "drivers/iio/frequency/Kconfig" -source "drivers/iio/dac/Kconfig" source "drivers/iio/common/Kconfig" +source "drivers/iio/dac/Kconfig" +source "drivers/iio/frequency/Kconfig" source "drivers/iio/gyro/Kconfig" +source "drivers/iio/imu/Kconfig" +source "drivers/iio/light/Kconfig" source "drivers/iio/magnetometer/Kconfig" endif # IIOdrivers/iio/Makefile +4
-3@@ -14,9 +14,10 @@ obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o obj-y += accel/ obj-y += adc/ obj-y += amplifiers/ -obj-y += light/ -obj-y += frequency/ -obj-y += dac/ obj-y += common/ +obj-y += dac/ obj-y += gyro/ +obj-y += frequency/ +obj-y += imu/ +obj-y += light/ obj-y += magnetometer/drivers/iio/imu/Kconfig new file +11
-0@@ -0,0 +1,11 @@ +config IIO_ADIS_LIB + tristate + help + A set of IO helper functions for the Analog Devices ADIS* device family. + +config IIO_ADIS_LIB_BUFFER + bool + select IIO_TRIGGERED_BUFFER + help + A set of buffer helper functions for the Analog Devices ADIS* device + family.drivers/iio/imu/Makefile new file +8
-0@@ -0,0 +1,8 @@ +# +# Makefile for Inertial Measurement Units +# + +adis_lib-y += adis.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o +obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.odrivers/iio/imu/adis.c renamed from drivers/staging/iio/imu/adis.c +1
-2@@ -20,8 +20,7 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> - -#include "adis.h" +#include <linux/iio/imu/adis.h> #define ADIS_MSC_CTRL_DATA_RDY_EN BIT(2)#define ADIS_MSC_CTRL_DATA_RDY_POL_HIGH BIT(1)drivers/iio/imu/adis_buffer.c renamed from drivers/staging/iio/imu/adis_buffer.c +1
-2@@ -18,8 +18,7 @@#include <linux/iio/buffer.h> #include <linux/iio/trigger_consumer.h> #include <linux/iio/triggered_buffer.h> - -#include "adis.h" +#include <linux/iio/imu/adis.h> int adis_update_scan_mode (struct iio_dev *indio_dev,const unsigned long *scan_mask)drivers/iio/imu/adis_trigger.c renamed from drivers/staging/iio/imu/adis_trigger.c +1
-2@@ -14,8 +14,7 @@#include <linux/iio/iio.h> #include <linux/iio/trigger.h> - -#include "adis.h" +#include <linux/iio/imu/adis.h> static int adis_data_rdy_trigger_set_state (struct iio_trigger *trig,bool state)drivers/staging/iio/accel/adis16201_core.c +1
-1@@ -18,9 +18,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16201.h" -#include "../imu/adis.h" static const u8 adis16201_addresses[] = { [ADIS16201_SCAN_ACC_X ] =ADIS16201_XACCL_OFFS ,drivers/staging/iio/accel/adis16203_core.c +1
-1@@ -18,9 +18,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16203.h" -#include "../imu/adis.h" #define DRIVER_NAME "adis16203"drivers/staging/iio/accel/adis16204_core.c +1
-1@@ -21,9 +21,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16204.h" -#include "../imu/adis.h" /* Unique to this driver currently */ drivers/staging/iio/accel/adis16209_core.c +1
-1@@ -19,9 +19,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16209.h" -#include "../imu/adis.h" static const u8 adis16209_addresses[8 ][1 ] = { [ADIS16209_SCAN_SUPPLY ] = { },drivers/staging/iio/accel/adis16220.h +1
-1@@ -1,7 +1,7 @@#ifndef SPI_ADIS16220_H_ #define SPI_ADIS16220_H_ -#include "../imu/adis.h" +#include <linux/iio/imu/adis.h> #define ADIS16220_STARTUP_DELAY 220/* ms */ drivers/staging/iio/accel/adis16240_core.c +1
-1@@ -22,9 +22,9 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/imu/adis.h> #include "adis16240.h" -#include "../imu/adis.h" static ssize_t adis16240_spi_read_signed(struct device *dev, struct device_attribute *attr,drivers/staging/iio/gyro/adis16260.h +1
-1@@ -2,7 +2,7 @@#define SPI_ADIS16260_H_ #include "adis16260_platform_data.h" -#include "../imu/adis.h" +#include <linux/iio/imu/adis.h> #define ADIS16260_STARTUP_DELAY 220/* ms */ drivers/staging/iio/imu/Kconfig +0
-12@@ -15,15 +15,3 @@ config ADIS16400 (adis16400 series also have magnetometers). endmenu - -config IIO_ADIS_LIB - tristate - help - A set of IO helper functions for the Analog Devices ADIS* device family. - -config IIO_ADIS_LIB_BUFFER - bool - select IIO_TRIGGERED_BUFFER - help - A set of buffer helper functions for the Analog Devices ADIS* device - family.drivers/staging/iio/imu/Makefile +0
-5@@ -5,8 +5,3 @@ adis16400-y := adis16400_core.o adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o adis16400_trigger.o obj-$(CONFIG_ADIS16400) += adis16400.o - -adis_lib-y += adis.o -adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o -adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o -obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.oinclude/linux/iio/imu/adis.h renamed from drivers/staging/iio/imu/adis.h +0
-0
Jonathan Cameron
maintainerQuoted 9 lines · Lars-Peter Clausen
A lot of the devices from the ADIS family use the same methods for accessing registers, sampling data and trigger handling. They also have similar register layout for the control registers.
This patch adds a common library for these devices. The library implements functions for reading and writing registers as buffer and trigger management. It also provides a set functions for accessing the control registers and for running the devices internal self-test. Having this common library code will allow us to remove a lot of duplicated code.
Excellent work. This series is exactly what I like to see. Nicely broken up with one step per patch. I kept reading this and thinking 'why is he still using that?' only to notice the drivers you are working with are using the old methods / buffer, and that you change over to the more recent method with the cleanup patches at the end. (exactly as it should be done even if I am usually too lazy to do it myself sometimes ;)
So far all I've found is an 'a' where it should be an 'an'. I think I'll just ignore that ;)
Quoted 880 lines
Signed-off-by Lars-Peter Clausen <[email protected]>--- drivers/staging/iio/imu/Kconfig | 13 ++ drivers/staging/iio/imu/Makefile | 5 + drivers/staging/iio/imu/adis.c | 338 +++++++++++++++++++++++++++++++++ drivers/staging/iio/imu/adis.h | 178 +++++++++++++++++ drivers/staging/iio/imu/adis_buffer.c | 200 +++++++++++++++++++ drivers/staging/iio/imu/adis_trigger.c | 90 +++++++++ 6 files changed, 824 insertions(+) create mode 100644 drivers/staging/iio/imu/adis.c create mode 100644 drivers/staging/iio/imu/adis.h create mode 100644 drivers/staging/iio/imu/adis_buffer.c create mode 100644 drivers/staging/iio/imu/adis_trigger.cdrivers/staging/iio/imu/Kconfig +13
-0@@ -15,3 +15,16 @@ config ADIS16400 (adis16400 series also have magnetometers). endmenu + +config IIO_ADIS_LIB + tristate + help + A set of IO helper functions for the Analog Devices ADIS* device family. + +config IIO_ADIS_LIB_BUFFER + bool + select IIO_TRIGGER + select IIO_SW_RING + help + A set of buffer helper functions for the Analog Devices ADIS* device + family.drivers/staging/iio/imu/Makefile +5
-0@@ -5,3 +5,8 @@ adis16400-y := adis16400_core.o adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o adis16400_trigger.o obj-$(CONFIG_ADIS16400) += adis16400.o + +adis_lib-y += adis.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o +adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o +obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.odrivers/staging/iio/imu/adis.c new file +338
-0@@ -0,0 +1,338 @@ +/* +* Common library for ADIS16XXX devices +* +* Copyright 2012 Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/delay.h> +#include <linux/mutex.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/spi/spi.h> +#include <linux/slab.h> +#include <linux/sysfs.h> +#include <linux/module.h> +#include <asm/unaligned.h> + +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/buffer.h> + +#include "adis.h" + +#define ADIS_MSC_CTRL_DATA_RDY_EN BIT(2) +#define ADIS_MSC_CTRL_DATA_RDY_POL_HIGH BIT(1) +#define ADIS_MSC_CTRL_DATA_RDY_DIO2 BIT(0) +#define ADIS_GLOB_CMD_SW_RESET BIT(7) + +/** +* adis_write_reg_8() - Write single byte to a register +* @adis: The adis device +* @reg: The address of the register to be written +* @val: The value to write +*/ +int adis_write_reg_8 (struct adis *adis,unsigned int reg,uint8_t val) +{ +int ret; + +mutex_lock (&adis->txrx_lock); + adis->tx[0 ] =ADIS_WRITE_REG (reg); + adis->tx[1 ] = val; + + ret =spi_write (adis->spi, adis->tx,2 ); +mutex_unlock (&adis->txrx_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (adis_write_reg_8); + +/** +* adis_write_reg_16() - Write 2 bytes to a pair of registers +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @val: Value to be written +*/ +int adis_write_reg_16 (struct adis *adis,unsigned int reg,uint16_t value) +{ +int ret; +struct spi_message msg; +struct spi_transfer xfers[] = { + { + .tx_buf = adis->tx, + .bits_per_word =8 , + .len =2 , + .cs_change =1 , + .delay_usecs = adis->data->write_delay, + }, { + .tx_buf = adis->tx +2 , + .bits_per_word =8 , + .len =2 , + .delay_usecs = adis->data->write_delay, + }, + }; + +mutex_lock (&adis->txrx_lock); + adis->tx[0 ] =ADIS_WRITE_REG (reg); + adis->tx[1 ] = value &0xff ; + adis->tx[2 ] =ADIS_WRITE_REG (reg +1 ); + adis->tx[3 ] = (value >>8 ) &0xff ; + +spi_message_init (&msg); +spi_message_add_tail (&xfers[0 ], &msg); +spi_message_add_tail (&xfers[1 ], &msg); + ret =spi_sync (adis->spi, &msg); +mutex_unlock (&adis->txrx_lock); + +return ret; +} +EXPORT_SYMBOL_GPL (adis_write_reg_16); + +/** +* adis_read_reg_16() - read 2 bytes from a 16-bit register +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @val: The value read back from the device +*/ +int adis_read_reg_16 (struct adis *adis,unsigned int reg,uint16_t *val) +{ +struct spi_message msg; +int ret; +struct spi_transfer xfers[] = { + { + .tx_buf = adis->tx, + .bits_per_word =8 , + .len =2 , + .cs_change =1 , + .delay_usecs = adis->data->read_delay, + }, { + .rx_buf = adis->rx, + .bits_per_word =8 , + .len =2 , + .delay_usecs = adis->data->read_delay, + }, + }; + +mutex_lock (&adis->txrx_lock); + adis->tx[0 ] =ADIS_READ_REG (reg); + adis->tx[1 ] =0 ; + +spi_message_init (&msg); +spi_message_add_tail (&xfers[0 ], &msg); +spi_message_add_tail (&xfers[1 ], &msg); + ret =spi_sync (adis->spi, &msg); +if (ret) { +dev_err (&adis->spi->dev,"Failed to read 16 bit register 0x%02X: %d\n" , + reg, ret); + goto error_ret; + } + *val =get_unaligned_be16 (adis->rx); + +error_ret: +mutex_unlock (&adis->txrx_lock); +return ret; +} +EXPORT_SYMBOL_GPL (adis_read_reg_16); + +/** +* adis_enable_irq() - Enable or disable data ready IRQ +* @adis: The adis device +* @enable: Whether to enable the IRQ +* +* Returns 0 on success, negative error code otherwise +*/ +int adis_enable_irq (struct adis *adis,bool enable) +{ +int ret =0 ; +uint16_t msc; + + ret =adis_read_reg_16 (adis, adis->data->msc_ctrl_reg, &msc); +if (ret) + goto error_ret; + + msc |=ADIS_MSC_CTRL_DATA_RDY_POL_HIGH ; + msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2 ; +if (enable) + msc |=ADIS_MSC_CTRL_DATA_RDY_EN ; +else + msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN ; + + ret =adis_write_reg_16 (adis, adis->data->msc_ctrl_reg, msc); + +error_ret: +return ret; +} +EXPORT_SYMBOL (adis_enable_irq); + +/** +* adis_check_status() - Check the device for error conditions +* @adis: The adis device +* +* Returns 0 on success, a negative error code otherwise +*/ +int adis_check_status (struct adis *adis) +{ +uint16_t status; +int ret; +int i; + + ret =adis_read_reg_16 (adis, adis->data->diag_stat_reg, &status); +if (ret <0 ) +return ret; + + status &= adis->data->status_error_mask; + +if (status ==0 ) +return 0 ; + +for (i =0 ; i <16 ; ++i) { +if (status &BIT (i)) { +dev_err (&adis->spi->dev,"%s.\n" , + adis->data->status_error_msgs[i]); + } + } + +return -EIO ; +} +EXPORT_SYMBOL_GPL (adis_check_status); + +/** +* adis_reset() - Reset the device +* @adis: The adis device +* +* Returns 0 on success, a negative error code otherwise +*/ +int adis_reset (struct adis *adis) +{ +int ret; + + ret =adis_write_reg_8 (adis, adis->data->glob_cmd_reg, +ADIS_GLOB_CMD_SW_RESET ); +if (ret) +dev_err (&adis->spi->dev,"Failed to reset device: %d\n" , ret); + +return ret; +} +EXPORT_SYMBOL_GPL (adis_reset); + +static int adis_self_test (struct adis *adis) +{ +int ret; + + ret =adis_write_reg_16 (adis, adis->data->msc_ctrl_reg, + adis->data->self_test_mask); +if (ret) { +dev_err (&adis->spi->dev,"Failed to initiate self test: %d\n" , + ret); +return ret; + } + +msleep (adis->data->startup_delay); + +return adis_check_status (adis); +} + +/** +* adis_inital_startup() - Performs device self-test +* @adis: The adis device +* +* Returns 0 if the device is operational, a negative error code otherwise. +* +* This function should be called early on in the device initialization sequence +* to ensure that the device is in a sane and known state and that it is usable. +*/ +int adis_initial_startup (struct adis *adis) +{ +int ret; + + ret =adis_self_test (adis); +if (ret) { +dev_err (&adis->spi->dev,"Self-test failed, trying reset.\n" ); +adis_reset (adis); +msleep (adis->data->startup_delay); + ret =adis_self_test (adis); +if (ret) { +dev_err (&adis->spi->dev,"Second self-test failed, giving up.\n" ); +return ret; + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (adis_initial_startup); + +/** +* adis_single_conversion() - Performs a single sample conversion +* @indio_dev: The IIO device +* @chan: The IIO channel +* @error_mask: Mask for the error bit +* @val: Result of the conversion +* +* Returns IIO_VAL_INT on success, a negative error code otherwise. +* +* The function performs a single conversion on a given channel and post +* processes the value accordingly to the channel spec. If a error_mask is given +* the function will check if the mask is set in the returned raw value. If it +* is set the function will perform a self-check. If the device does not report +* a error bit in the channels raw value set error_mask to 0. +*/ +int adis_single_conversion (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int error_mask,int *val) +{ +struct adis *adis =iio_device_get_drvdata (indio_dev); +uint16_t val16; +int ret; + +mutex_lock (&indio_dev->mlock); + + ret =adis_read_reg_16 (adis, chan->address, &val16); +if (ret) + goto err_unlock; + +if (val16 & error_mask) { + ret =adis_check_status (adis); +if (ret) + goto err_unlock; + } + +if (chan->scan_type.sign =='s' ) + *val =sign_extend32 (val16, chan->scan_type.realbits -1 ); +else + *val = val16 & ((1 << chan->scan_type.realbits) -1 ); + + ret =IIO_VAL_INT ; +err_unlock: +mutex_unlock (&indio_dev->mlock); +return ret; +} +EXPORT_SYMBOL_GPL (adis_single_conversion); + +/** +* adis_init() - Initialize adis device structure +* @adis: The adis device +* @indio_dev: The iio device +* @spi: The spi device +* @data: Chip specific data +* +* Returns 0 on success, a negative error code otherwise. +* +* This function must be called, before any other adis helper function may be +* called. +*/ +int adis_init (struct adis *adis,struct iio_dev *indio_dev, +struct spi_device *spi,const struct adis_data *data) +{ +mutex_init (&adis->txrx_lock); + adis->spi = spi; + adis->data = data; +iio_device_set_drvdata (indio_dev, adis); + +return adis_enable_irq (adis, false); +} +EXPORT_SYMBOL_GPL (adis_init); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Lars-Peter Clausen <[email protected]>" ); +MODULE_DESCRIPTION ("Common library code for ADIS16XXX devices" );drivers/staging/iio/imu/adis.h new file +178
-0@@ -0,0 +1,178 @@ +/* +* Common library for ADIS16XXX devices +* +* Copyright 2012 Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Licensed under the GPL-2 or later. +*/ + +#ifndef __IIO_ADIS_H__ +#define __IIO_ADIS_H__ + +#include <linux/spi/spi.h> +#include <linux/interrupt.h> +#include <linux/iio/types.h> + +#define ADIS_WRITE_REG (reg) (0x80 | (reg)) +#define ADIS_READ_REG (reg) (reg) + +/** +* struct adis_data - ADIS chip variant specific data +* @read_delay: SPI delay for read operations in us +* @write_delay: SPI delay for write operations in us +* @glob_cmd_reg: Register address of the GLOB_CMD register +* @msc_ctrl_reg: Register address of the MSC_CTRL register +* @diag_stat_reg: Register address of the DIAG_STAT register +* @status_error_msgs: Array of error messgaes +* @status_error_mask: +*/ +struct adis_data { +unsigned int read_delay; +unsigned int write_delay; + +unsigned int glob_cmd_reg; +unsigned int msc_ctrl_reg; +unsigned int diag_stat_reg; + +unsigned int self_test_mask; +unsigned int startup_delay; + +const char *const *status_error_msgs; +unsigned int status_error_mask; +}; + +struct adis { +struct spi_device *spi; +struct iio_trigger *trig; + +const struct adis_data *data; + +struct mutex txrx_lock; +struct spi_message msg; +struct spi_transfer *xfer; +void *buffer; + +uint8_t tx[8 ]____cacheline_aligned ; +uint8_t rx[4 ]; +}; + +int adis_init (struct adis *adis,struct iio_dev *indio_dev, +struct spi_device *spi,const struct adis_data *data); +int adis_reset (struct adis *adis); + +int adis_write_reg_8 (struct adis *adis,unsigned int reg,uint8_t val); +int adis_write_reg_16 (struct adis *adis,unsigned int reg,uint16_t val); +int adis_read_reg_16 (struct adis *adis,unsigned int reg,uint16_t *val); + +int adis_enable_irq (struct adis *adis,bool enable); +int adis_check_status (struct adis *adis); + +int adis_initial_startup (struct adis *adis); + +int adis_single_conversion (struct iio_dev *indio_dev, +const struct iio_chan_spec *chan,unsigned int error_mask, +int *val); + +#define ADIS_VOLTAGE_CHAN (addr, si, chan, name, bits) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = (chan), \ + .extend_name = name, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ + .address = (addr), \ + .scan_index = (si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (bits), \ + .storagebits = 16, \ + }, \ +} + +#define ADIS_SUPPLY_CHAN (addr, si, bits) \ + ADIS_VOLTAGE_CHAN(addr, si, 0, "supply", bits) + +#define ADIS_AUX_ADC_CHAN (addr, si, bits) \ + ADIS_VOLTAGE_CHAN(addr, si, 1, NULL, bits) + +#define ADIS_TEMP_CHAN (addr, si, bits) { \ + .type = IIO_TEMP, \ + .indexed = 1, \ + .channel = 0, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \ + IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, \ + .address = (addr), \ + .scan_index = (si), \ + .scan_type = { \ + .sign = 'u', \ + .realbits = (bits), \ + .storagebits = 16, \ + }, \ +} + +#define ADIS_MOD_CHAN (_type, mod, addr, si, info, bits) { \ + .type = (_type), \ + .modified = 1, \ + .channel2 = IIO_MOD_ ## mod, \ + .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ + IIO_CHAN_INFO_SCALE_SHARED_BIT | \ + info, \ + .address = (addr), \ + .scan_index = (si), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (bits), \ + .storagebits = 16, \ + }, \ +} + +#define ADIS_ACCEL_CHAN (mod, addr, si, info, bits) \ + ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info, bits) + +#define ADIS_GYRO_CHAN (mod, addr, si, info, bits) \ + ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info, bits) + +#define ADIS_INCLI_CHAN (mod, addr, si, info, bits) \ + ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info, bits) + +#define ADIS_ROT_CHAN (mod, addr, si, info, bits) \ + ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info, bits) + +#ifdef CONFIG_IIO_ADIS_LIB_BUFFER + +int adis_setup_buffer_and_trigger (struct adis *adis, +struct iio_dev *indio_dev,irqreturn_t (*trigger_handler)(int ,void *)); +void adis_cleanup_buffer_and_trigger (struct adis *adis, +struct iio_dev *indio_dev); + +int adis_probe_trigger (struct adis *adis,struct iio_dev *indio_dev); +void adis_remove_trigger (struct adis *adis); + +#else /* CONFIG_IIO_BUFFER */ + +static inline int adis_setup_buffer_and_trigger (struct adis *adis, +struct iio_dev *indio_dev,irqreturn_t (*trigger_handler)(int ,void *)) +{ +return 0 ; +} + +static inline void adis_cleanup_buffer_and_trigger (struct adis *adis, +struct iio_dev *indio_dev) +{ +} + +static inline int adis_probe_trigger (struct adis *adis, +struct iio_dev *indio_dev) +{ +return 0 ; +} + +static inline void adis_remove_trigger (struct adis *adis) +{ +} + +#endif /* CONFIG_IIO_BUFFER */ + +#endif drivers/staging/iio/imu/adis_buffer.c new file +200
-0@@ -0,0 +1,200 @@ +#include <linux/export.h> +#include <linux/interrupt.h> +#include <linux/mutex.h> +#include <linux/kernel.h> +#include <linux/spi/spi.h> +#include <linux/slab.h> + +#include <linux/iio/iio.h> +#include <linux/iio/buffer.h> +#include "../ring_sw.h" +#include <linux/iio/trigger_consumer.h> + +#include "adis.h" + +#define ADIS_MAX_OUTPUTS 12 + +static int adis_read_buffer_data (struct adis *adis,struct iio_dev *indio_dev) +{ +int n_outputs = indio_dev->num_channels; +struct spi_transfer xfers[ADIS_MAX_OUTPUTS +1 ]; +struct spi_message msg; +int ret; +int i; + +mutex_lock (&adis->txrx_lock); + +spi_message_init (&msg); + +memset (xfers,0 ,sizeof (xfers)); +for (i =0 ; i <= n_outputs; i++) { + xfers[i].bits_per_word =8 ; + xfers[i].cs_change =1 ; + xfers[i].len =2 ; + xfers[i].delay_usecs = adis->data->read_delay; +if (i < n_outputs) { + xfers[i].tx_buf = adis->tx +2 * i; + adis->tx[2 * i] = indio_dev->channels[i].address; + adis->tx[2 * i +1 ] =0 ; + } +if (i >=1 ) + xfers[i].rx_buf = adis->rx +2 * (i -1 ); +spi_message_add_tail (&xfers[i], &msg); + } + + ret =spi_sync (adis->spi, &msg); +if (ret) +dev_err (&adis->spi->dev,"Failed to read data: %d" , ret); + +mutex_unlock (&adis->txrx_lock); + +return ret; +} + +static irqreturn_t adis_trigger_handler (int irq,void *p) +{ +struct iio_poll_func *pf = p; +struct iio_dev *indio_dev = pf->indio_dev; +struct adis *adis =iio_device_get_drvdata (indio_dev); +u16 *data; +int i =0 ; + + data =kmalloc (indio_dev->scan_bytes,GFP_KERNEL ); +if (data ==NULL ) { +dev_err (&adis->spi->dev,"Failed to allocate memory." ); +return -ENOMEM ; + } + +if (!bitmap_empty (indio_dev->active_scan_mask, indio_dev->masklength) + &&adis_read_buffer_data (adis, indio_dev) >=0 ) +for (; i <bitmap_weight (indio_dev->active_scan_mask, + indio_dev->masklength); i++) + data[i] =be16_to_cpup ((__be16 *)&(adis->rx[i*2 ])); + +/* Guaranteed to be aligned with 8 byte boundary */ +if (indio_dev->scan_timestamp) + *((s64 *)(PTR_ALIGN (data,sizeof (s64)))) = pf->timestamp; + +iio_push_to_buffers (indio_dev, (u8 *)data); + +iio_trigger_notify_done (indio_dev->trig); +kfree (data); + +return IRQ_HANDLED ; +} + +static const struct iio_buffer_setup_ops adis_buffer_setup_ops = { + .preenable = &iio_sw_buffer_preenable, + .postenable = &iio_triggered_buffer_postenable, + .predisable = &iio_triggered_buffer_predisable, +}; + +static int adis_buffer_setup (struct iio_dev *indio_dev, +irqreturn_t (*trigger_handler)(int ,void *)) +{ +int ret =0 ; +struct iio_buffer *buffer; + +if (!trigger_handler) + trigger_handler = &adis_trigger_handler; + + buffer =iio_sw_rb_allocate (indio_dev); +if (!buffer) { + ret = -ENOMEM ; +return ret; + } + + indio_dev->buffer = buffer; + indio_dev->setup_ops = &adis_buffer_setup_ops; + + indio_dev->pollfunc =iio_alloc_pollfunc (&iio_pollfunc_store_time, + trigger_handler, +IRQF_ONESHOT , + indio_dev, +"%s_consumer%d" , + indio_dev->name, + indio_dev->id); +if (indio_dev->pollfunc ==NULL ) { + ret = -ENOMEM ; + goto error_iio_sw_rb_free; + } + + indio_dev->modes |=INDIO_BUFFER_TRIGGERED ; +return 0 ; + +error_iio_sw_rb_free: +iio_sw_rb_free (indio_dev->buffer); +return ret; +} + +static void adis_buffer_cleanup (struct iio_dev *indio_dev) +{ +iio_dealloc_pollfunc (indio_dev->pollfunc); +iio_sw_rb_free (indio_dev->buffer); +} + +/** +* adis_setup_buffer_and_trigger() - Sets up buffer and trigger for the adis device +* @adis: The adis device. +* @indio_dev: The IIO device. +* @trigger_handler: Optional trigger handler, may be NULL. +* +* Returns 0 on success, a negative error code otherwise. +* +* This function sets up the buffer and trigger for a adis devices. If +* 'trigger_handler' is NULL the default trigger handler will be used. The +* default trigger handler will simply read the registers assigned to the +* currently active channels. +* +* adis_cleanup_buffer_and_trigger() should be called to free the resources +* allocated by this function. +*/ +int adis_setup_buffer_and_trigger (struct adis *adis,struct iio_dev *indio_dev, +irqreturn_t (*trigger_handler)(int ,void *)) +{ +int ret; + + ret =adis_buffer_setup (indio_dev, trigger_handler); +if (ret) +return ret; + + ret =iio_buffer_register (indio_dev, + indio_dev->channels, + indio_dev->num_channels); +if (ret) { +dev_err (&adis->spi->dev,"Failed to initialize buffer %d\n" , + ret); + goto error_unreg_buffer_funcs; + } + +if (adis->spi->irq) { + ret =adis_probe_trigger (adis, indio_dev); +if (ret) + goto error_uninitialize_buffer; + } +return 0 ; + +error_uninitialize_buffer: +iio_buffer_unregister (indio_dev); +error_unreg_buffer_funcs: +adis_buffer_cleanup (indio_dev); +return ret; +} +EXPORT_SYMBOL_GPL (adis_setup_buffer_and_trigger); + +/** +* adis_cleanup_buffer_and_trigger() - Free buffer and trigger resources +* @adis: The adis device. +* @indio_dev: The IIO device. +* +* Frees resources allocated by adis_setup_buffer_and_trigger() +*/ +void adis_cleanup_buffer_and_trigger (struct adis *adis, +struct iio_dev *indio_dev) +{ +if (adis->spi->irq) +adis_remove_trigger (adis); +iio_buffer_unregister (indio_dev); +adis_buffer_cleanup (indio_dev); +} +EXPORT_SYMBOL_GPL (adis_cleanup_buffer_and_trigger);drivers/staging/iio/imu/adis_trigger.c new file +90
-0@@ -0,0 +1,90 @@ +/* +* Common library for ADIS16XXX devices +* +* Copyright 2012 Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/spi/spi.h> +#include <linux/export.h> + +#include <linux/iio/iio.h> +#include <linux/iio/trigger.h> + +#include "adis.h" + +static int adis_data_rdy_trigger_set_state (struct iio_trigger *trig, +bool state) +{ +struct adis *adis = trig->private_data; + +return adis_enable_irq (adis, state); +} + +static const struct iio_trigger_ops adis_trigger_ops = { + .owner =THIS_MODULE , + .set_trigger_state = &adis_data_rdy_trigger_set_state, +}; + +/** +* adis_probe_trigger() - Sets up trigger for a adis device +* @adis: The adis device +* @indio_dev: The IIO device +* +* Returns 0 on success or a negative error code +* +* adis_remove_trigger() should be used to free the trigger. +*/ +int adis_probe_trigger (struct adis *adis,struct iio_dev *indio_dev) +{ +int ret; + + adis->trig =iio_trigger_alloc ("%s-dev%d" , indio_dev->name, + indio_dev->id); +if (adis->trig ==NULL ) +return -ENOMEM ; + + ret =request_irq (adis->spi->irq, + &iio_trigger_generic_data_rdy_poll, +IRQF_TRIGGER_RISING , + indio_dev->name, + adis->trig); +if (ret) + goto error_free_trig; + + adis->trig->dev.parent = &adis->spi->dev; + adis->trig->ops = &adis_trigger_ops; + adis->trig->private_data = adis; + ret =iio_trigger_register (adis->trig); + + indio_dev->trig = adis->trig; +if (ret) + goto error_free_irq; + +return 0 ; + +error_free_irq: +free_irq (adis->spi->irq, adis->trig); +error_free_trig: +iio_trigger_free (adis->trig); +return ret; +} +EXPORT_SYMBOL_GPL (adis_probe_trigger); + +/** +* adis_remove_trigger() - Remove trigger for a adis devices +* @adis: The adis device +* +* Removes the trigger previously registered with adis_probe_trigger(). +*/ +void adis_remove_trigger (struct adis *adis) +{ +iio_trigger_unregister (adis->trig); +free_irq (adis->spi->irq, adis->trig); +iio_trigger_free (adis->trig); +} +EXPORT_SYMBOL_GPL (adis_remove_trigger);