iio: imu: adis16480: Add support for ADIS1649x family of devices
Subsystems (3)
v2 cover iio: imu: adis16480: Add support for ADIS1649x family of devices
This series has as main goal to add support for ADIS1649x family of devices as part of the already existing adis16480, but on the way it also deals with some outstanding items:
* Make drdy pin configurable
* Add OF device ID table
* Deal with the temperature max scale in a generic way
* Add missing docs
Changes in v2:
Patch 1:
- use DIO1 pin as default data ready signal instead of DIO2.
Patch 2:
- nothing changed.
Patch 3, 4:
- give the scale directly in the adis16480_chip_info struct.
Patch 5:
- document the use of DIO1 pin as default data ready signal.
Stefan Popa (5):
iio: imu: adis16480: Add support for configurable drdy indicator
iio: imu: adis16480: Add OF device ID table
iio: imu: adis16480: Treat temperature scale in a generic way
iio: imu: adis16480: Add support for ADIS1649x family of devices
iio: imu: adis16480: Add docs for ADIS16480 IMU
.../devicetree/bindings/iio/imu/adi,adis16480.txt | 49 +++++ MAINTAINERS | 1 + drivers/iio/imu/adis16480.c | 197 ++++++++++++++++++++- 3 files changed, 242 insertions(+), 5 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
Signature · 1 line
2.7.4
PATCH v2 1/5 iio: imu: adis16480: Add support for configurable drdy indicator
The FNCTIO_CTRL register provides configuration control for each I/O pin (DIO1, DIO2, DIO3 and DIO4).
This patch adds the option to configure each DIOx pin as data ready indicator with positive or negative polarity by reading the 'interrupts' and 'interrupt-names' properties from the devicetree. The 'interrupt-names' property is optional, if it is not specified, then the DIO1 pin is used as default data ready signal.
Although the factory default assigns DIO2 as data ready signal, in the versions previous this patch, DIO1 pin was used. We should leave this configuration as is, since some devices might be expecting the interrupt on the wrong physical pin.
--- drivers/iio/imu/adis16480.c | 97 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-)
drivers/iio/imu/adis16480.c +95 -2
@@ -9,6 +9,8 @@* */ +#include <linux/bitfield.h> +#include <linux/of_irq.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/mutex.h>
@@ -107,6 +109,14 @@#define ADIS16480_FIR_COEF_C (x) ADIS16480_FIR_COEF(0x09, (x))#define ADIS16480_FIR_COEF_D (x) ADIS16480_FIR_COEF(0x0B, (x)) +/* ADIS16480_REG_FNCTIO_CTRL */ +#define ADIS16480_DRDY_SEL_MSK GENMASK(1, 0) +#define ADIS16480_DRDY_SEL (x) FIELD_PREP(ADIS16480_DRDY_SEL_MSK, x) +#define ADIS16480_DRDY_POL_MSK BIT(2) +#define ADIS16480_DRDY_POL (x) FIELD_PREP(ADIS16480_DRDY_POL_MSK, x) +#define ADIS16480_DRDY_EN_MSK BIT(3) +#define ADIS16480_DRDY_EN (x) FIELD_PREP(ADIS16480_DRDY_EN_MSK, x) +struct adis16480_chip_info {unsigned int num_channels;const struct iio_chan_spec *channels;
@@ -116,12 +126,26 @@ struct adis16480_chip_info {unsigned int accel_max_scale; }; +enum adis16480_int_pin { +ADIS16480_PIN_DIO1 , +ADIS16480_PIN_DIO2 , +ADIS16480_PIN_DIO3 , +ADIS16480_PIN_DIO4 +}; +struct adis16480 {const struct adis16480_chip_info *chip_info;struct adis adis; }; +static const char *const adis16480_int_pin_names[4 ] = { + [ADIS16480_PIN_DIO1 ] ="DIO1" , + [ADIS16480_PIN_DIO2 ] ="DIO2" , + [ADIS16480_PIN_DIO3 ] ="DIO3" , + [ADIS16480_PIN_DIO4 ] ="DIO4" , +}; +#ifdef CONFIG_DEBUG_FS static ssize_t adis16480_show_firmware_revision(struct file *file,
@@ -741,8 +765,17 @@ static int adis16480_stop_device(struct iio_dev *indio_dev)static int adis16480_enable_irq (struct adis *adis,bool enable) { -return adis_write_reg_16 (adis,ADIS16480_REG_FNCTIO_CTRL , - enable ?BIT (3 ) :0 ); +uint16_t val; +int ret; + + ret =adis_read_reg_16 (adis,ADIS16480_REG_FNCTIO_CTRL , &val); +if (ret <0 ) +return ret; + + val &= ~ADIS16480_DRDY_EN_MSK ; + val |=ADIS16480_DRDY_EN (enable); + +return adis_write_reg_16 (adis,ADIS16480_REG_FNCTIO_CTRL , val); }static int adis16480_initial_setup (struct iio_dev *indio_dev)
@@ -826,6 +859,62 @@ static const struct adis_data adis16480_data = { .enable_irq = adis16480_enable_irq, }; +static int adis16480_config_irq_pin (struct device_node *of_node, +struct adis16480 *st) +{ +struct irq_data *desc; +enum adis16480_int_pin pin; +unsigned int irq_type; +uint16_t val; +int i, irq =0 ; + + desc =irq_get_irq_data (st->adis.spi->irq); +if (!desc) { +dev_err (&st->adis.spi->dev,"Could not find IRQ %d\n" , irq); +return -EINVAL ; + } + +/* Disable data ready since the default after reset is on */ + val =ADIS16480_DRDY_EN (0 ); + +/* +* Get the interrupt from the devicetre by reading the interrupt-names +* property. If it is not specified, use DIO1 pin as default. +* According to the datasheet, the factory default assigns DIO2 as data +* ready signal. However, in the previous versions of the driver, DIO1 +* pin was used. So, we should leave it as is since some devices might +* be expecting the interrupt on the wrong physical pin. +*/ + pin =ADIS16480_PIN_DIO1 ; +for (i =0 ; i <ARRAY_SIZE (adis16480_int_pin_names); i++) { + irq =of_irq_get_byname (of_node, adis16480_int_pin_names[i]); +if (irq >0 ) { + pin = i; +break ; + } + } + + val |=ADIS16480_DRDY_SEL (pin); + +/* +* Get the interrupt line behaviour. The data ready polarity can be +* configured as positive or negative, corresponding to +* IRQF_TRIGGER_RISING or IRQF_TRIGGER_FALLING respectively. +*/ + irq_type =irqd_get_trigger_type (desc); +if (irq_type ==IRQF_TRIGGER_RISING ) {/* Default */ + val |=ADIS16480_DRDY_POL (1 ); + }else if (irq_type ==IRQF_TRIGGER_FALLING ) { + val |=ADIS16480_DRDY_POL (0 ); + }else { +dev_err (&st->adis.spi->dev, +"Invalid interrupt type 0x%x specified\n" , irq_type); +return -EINVAL ; + } +/* Write the data ready configuration to the FNCTIO_CTRL register */ +return adis_write_reg_16 (&st->adis,ADIS16480_REG_FNCTIO_CTRL , val); +} +static int adis16480_probe (struct spi_device *spi) {const struct spi_device_id *id =spi_get_device_id (spi);
@@ -853,6 +942,10 @@ static int adis16480_probe(struct spi_device *spi)if (ret)return ret; + ret =adis16480_config_irq_pin (spi->dev.of_node, st); +if (ret) +return ret; + ret =adis_setup_buffer_and_trigger (&st->adis, indio_dev,NULL );if (ret)return ret;
Signature · 1 line
2.7.4
PATCH v2 2/5 iio: imu: adis16480: Add OF device ID table
In reply to Stefan PopaThe driver does not have a struct of_device_id table, but supported devices are registered via Device Trees. This patch adds OF device ID table.
--- drivers/iio/imu/adis16480.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/iio/imu/adis16480.c +10 -0
@@ -991,9 +991,19 @@ static const struct spi_device_id adis16480_ids[] = { };MODULE_DEVICE_TABLE (spi, adis16480_ids); +static const struct of_device_id adis16480_of_match[] = { + { .compatible ="adi,adis16375" }, + { .compatible ="adi,adis16480" }, + { .compatible ="adi,adis16485" }, + { .compatible ="adi,adis16488" }, + { }, +}; +MODULE_DEVICE_TABLE (of, adis16480_of_match); +static struct spi_driver adis16480_driver = { .driver = { .name ="adis16480" , + .of_match_table = adis16480_of_match, }, .id_table = adis16480_ids, .probe = adis16480_probe,
Signature · 1 line
2.7.4
PATCH v2 3/5 iio: imu: adis16480: Treat temperature scale in a generic way
In reply to Stefan PopaAll supported devices provide internal temperature measurement from -40 C to +85 C, with +25 C representing value 0x00.
This patch treats the temperature scale in a generic way, similar to the accelerometer and gyroscope scales. So far, there are no temperature max scale differences between the supported devices. However, devices that will make use of this feature will be added in the future.
--- drivers/iio/imu/adis16480.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/iio/imu/adis16480.c +15 -3
@@ -124,6 +124,7 @@ struct adis16480_chip_info {unsigned int gyro_max_scale;unsigned int accel_max_val;unsigned int accel_max_scale; +unsigned int temp_scale; };enum adis16480_int_pin {
@@ -530,6 +531,7 @@ static int adis16480_read_raw(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, int *val, int *val2, long info) { struct adis16480 *st = iio_priv(indio_dev); +unsigned int temp;switch (info) {case IIO_CHAN_INFO_RAW :
@@ -549,8 +551,13 @@ static int adis16480_read_raw(struct iio_dev *indio_dev, *val2 =100 ;/* 0.0001 gauss */ return IIO_VAL_INT_PLUS_MICRO ;case IIO_TEMP : - *val =5 ; - *val2 =650000 ;/* 5.65 milli degree Celsius */ +/* +* +85 degrees Celsius = temp_max_scale +* +25 degrees Celsius = 0 +* LSB, 25 degrees Celsius = 60 / temp_max_scale +*/ + *val = st->chip_info->temp_scale /1000 ; + *val2 = (st->chip_info->temp_scale %1000 ) *1000 ;return IIO_VAL_INT_PLUS_MICRO ;case IIO_PRESSURE : *val =0 ;
@@ -561,7 +568,8 @@ static int adis16480_read_raw(struct iio_dev *indio_dev, }case IIO_CHAN_INFO_OFFSET :/* Only the temperature channel has a offset */ - *val =4425 ;/* 25 degree Celsius = 0x0000 */ + temp =25 *1000000LL ;/* 25 degree Celsius = 0x0000 */ + *val =DIV_ROUND_CLOSEST_ULL (temp, st->chip_info->temp_scale);return IIO_VAL_INT ;case IIO_CHAN_INFO_CALIBBIAS :return adis16480_get_calibbias (indio_dev, chan, val);
@@ -717,6 +725,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .gyro_max_scale = 300, .accel_max_val = IIO_M_S_2_TO_G(21973), .accel_max_scale = 18, + .temp_scale = 5650, /* 5.65 milli degree Celsius */ }, [ADIS16480] = { .channels = adis16480_channels,
@@ -725,6 +734,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .gyro_max_scale = 450, .accel_max_val = IIO_M_S_2_TO_G(12500), .accel_max_scale = 10, + .temp_scale = 5650, /* 5.65 milli degree Celsius */ }, [ADIS16485] = { .channels = adis16485_channels,
@@ -733,6 +743,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .gyro_max_scale = 450, .accel_max_val = IIO_M_S_2_TO_G(20000), .accel_max_scale = 5, + .temp_scale = 5650, /* 5.65 milli degree Celsius */ }, [ADIS16488] = { .channels = adis16480_channels,
@@ -741,6 +752,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .gyro_max_scale = 450, .accel_max_val = IIO_M_S_2_TO_G(22500), .accel_max_scale = 18, + .temp_scale = 5650, /* 5.65 milli degree Celsius */ }, };
Signature · 1 line
2.7.4
PATCH v2 4/5 iio: imu: adis16480: Add support for ADIS1649x family of devices
In reply to Stefan PopaThe ADIS16495 and ADIS16497 are inertial systems that include a triaxis gyroscope and a triaxis accelerometer. The serial peripheral interface (SPI) provide a simple interface for data collection and configuration control. The devices are similar to ADIS16475, ADIS16480, ADIS16485 and ADIS16488, the main differences are related to range and scale factors.
The temperature data scale is 0.00565 C/LSB for ADIS16475 and ADIS1648x devices, while for ADIS1649x 0.0125 C/LSB.
Another difference is that ADIS1649x devices support different gyroscope measurement ranges which are dependent on the dash number (-1, -2, -3), see Table 24 in the ADIS16495 datasheet. However, the ADIS16497 gyroscopes have the same scale as ADIS16495.
Furthermore, ADIS16495 devices support the acceleration maximum range of 8g, while ADIS16497 devices go up to 40g.
Datasheets:
--- drivers/iio/imu/adis16480.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+)
drivers/iio/imu/adis16480.c +72 -0
@@ -710,6 +710,12 @@ enum adis16480_variant {ADIS16480 ,ADIS16485 ,ADIS16488 , +ADIS16495_1 , +ADIS16495_2 , +ADIS16495_3 , +ADIS16497_1 , +ADIS16497_2 , + ADIS16497_3, }; static const struct adis16480_chip_info adis16480_chip_info[] = {
@@ -754,6 +760,60 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .accel_max_scale = 18, .temp_scale = 5650, /* 5.65 milli degree Celsius */ }, + [ADIS16495_1] = { + .channels = adis16485_channels, + .num_channels = ARRAY_SIZE(adis16485_channels), + .gyro_max_val = IIO_RAD_TO_DEGREE(20000), + .gyro_max_scale = 125, + .accel_max_val = IIO_M_S_2_TO_G(32000), + .accel_max_scale = 8, + .temp_scale = 12500, /* 12.5 milli degree Celsius */ + }, + [ADIS16495_2] = { + .channels = adis16485_channels, + .num_channels = ARRAY_SIZE(adis16485_channels), + .gyro_max_val = IIO_RAD_TO_DEGREE(18000), + .gyro_max_scale = 450, + .accel_max_val = IIO_M_S_2_TO_G(32000), + .accel_max_scale = 8, + .temp_scale = 12500, /* 12.5 milli degree Celsius */ + }, + [ADIS16495_3] = { + .channels = adis16485_channels, + .num_channels = ARRAY_SIZE(adis16485_channels), + .gyro_max_val = IIO_RAD_TO_DEGREE(20000), + .gyro_max_scale = 2000, + .accel_max_val = IIO_M_S_2_TO_G(32000), + .accel_max_scale = 8, + .temp_scale = 12500, /* 12.5 milli degree Celsius */ + }, + [ADIS16497_1] = { + .channels = adis16485_channels, + .num_channels = ARRAY_SIZE(adis16485_channels), + .gyro_max_val = IIO_RAD_TO_DEGREE(20000), + .gyro_max_scale = 125, + .accel_max_val = IIO_M_S_2_TO_G(32000), + .accel_max_scale = 40, + .temp_scale = 12500, /* 12.5 milli degree Celsius */ + }, + [ADIS16497_2] = { + .channels = adis16485_channels, + .num_channels = ARRAY_SIZE(adis16485_channels), + .gyro_max_val = IIO_RAD_TO_DEGREE(18000), + .gyro_max_scale = 450, + .accel_max_val = IIO_M_S_2_TO_G(32000), + .accel_max_scale = 40, + .temp_scale = 12500, /* 12.5 milli degree Celsius */ + }, + [ADIS16497_3] = { + .channels = adis16485_channels, + .num_channels = ARRAY_SIZE(adis16485_channels), + .gyro_max_val = IIO_RAD_TO_DEGREE(20000), + .gyro_max_scale = 2000, + .accel_max_val = IIO_M_S_2_TO_G(32000), + .accel_max_scale = 40, + .temp_scale = 12500, /* 12.5 milli degree Celsius */ + }, };static const struct iio_info adis16480_info = {
@@ -999,6 +1059,12 @@ static const struct spi_device_id adis16480_ids[] = { { "adis16480", ADIS16480 }, { "adis16485", ADIS16485 }, { "adis16488", ADIS16488 }, + { "adis16495-1", ADIS16495_1 }, + { "adis16495-2", ADIS16495_2 }, + { "adis16495-3", ADIS16495_3 }, + { "adis16497-1", ADIS16497_1 }, + { "adis16497-2", ADIS16497_2 }, + { "adis16497-3", ADIS16497_3 }, { } };MODULE_DEVICE_TABLE (spi, adis16480_ids);
@@ -1008,6 +1074,12 @@ static const struct of_device_id adis16480_of_match[] = { { .compatible = "adi,adis16480" }, { .compatible = "adi,adis16485" }, { .compatible = "adi,adis16488" }, + { .compatible = "adi,adis16495-1" }, + { .compatible = "adi,adis16495-2" }, + { .compatible = "adi,adis16495-3" }, + { .compatible = "adi,adis16497-1" }, + { .compatible = "adi,adis16497-2" }, + { .compatible = "adi,adis16497-3" }, { }, };MODULE_DEVICE_TABLE (of, adis16480_of_match);
Signature · 1 line
2.7.4
PATCH v2 5/5 iio: imu: adis16480: Add docs for ADIS16480 IMU
In reply to Stefan PopaDocument support for ADIS16480 Inertial Measurement Unit.
--- .../devicetree/bindings/iio/imu/adi,adis16480.txt | 49 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt
Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt new file +49 -0
@@ -0,0 +1,49 @@ + +Analog Devices ADIS16480 and similar IMUs + +Required properties for the ADIS16480: + +- compatible: Must be one of + * "adi,adis16375" + * "adi,adis16480" + * "adi,adis16485" + * "adi,adis16488" + * "adi,adis16495-1" + * "adi,adis16495-2" + * "adi,adis16495-3" + * "adi,adis16497-1" + * "adi,adis16497-2" + * "adi,adis16497-3" +- reg: SPI chip select number for the device +- spi-max-frequency: Max SPI frequency to use + see: Documentation/devicetree/bindings/spi/spi-bus.txt +- spi-cpha: See Documentation/devicetree/bindings/spi/spi-bus.txt +- spi-cpol: See Documentation/devicetree/bindings/spi/spi-bus.txt +- interrupts: interrupt mapping for IRQ, accepted values are: + * IRQF_TRIGGER_RISING + * IRQF_TRIGGER_FALLING + +Optional properties: + +- interrupt-names: Data ready line selection. Valid values are: + * DIO1 + * DIO2 + * DIO3 + * DIO4 + If this field is left empty, DIO1 is assigned as default data ready + signal. +- reset-gpios: must be the device tree identifier of the RESET pin. As the line + is active low, it should be marked GPIO_ACTIVE_LOW. + +Example: + + imu@0 { + compatible = "adi,adis16495-1"; + reg = <0>; + spi-max-frequency = <3200000>; + spi-cpol; + spi-cpha; + interrupts = <25 IRQF_TRIGGER_FALLING>; + interrupt-parent = <&gpio>; + interrupt-names = "DIO2"; + };
MAINTAINERS +1 -0
@@ -942,6 +942,7 @@ F: drivers/dma/dma-axi-dmac.c ANALOG DEVICES INC IIO DRIVERS M: Lars-Peter Clausen <[email protected]> M: Michael Hennerich <[email protected]> +M: Stefan Popa <[email protected]> W: http://wiki.analog.com/ W: http://ez.analog.com/community/linux-device-drivers S: Supported
Signature · 1 line
2.7.4
Re: [PATCH v2 5/5] iio: imu: adis16480: Add docs for ADIS16480 IMU
Quoted 9 lines · Stefan Popa
Document support for ADIS16480 Inertial Measurement Unit.
Signed-off-by Stefan Popa <[email protected]>--- .../devicetree/bindings/iio/imu/adi,adis16480.txt | 49 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt