Support ADIS16475 and similar IMUs
Subsystems (5)
Nuno Sá
maintainerv2 cover Support ADIS16475 and similar IMUs
This series adds support for the adis16475 and similar IMUs. This driver will be the first user of some changes on the adis library. Hence, the first three patches are related to the library:
* Add anaged device functions for registering triggers with the library;
* Updates the way irq_mask is passed to request_irq();
* It adds an update_bits() like API.
A new patch was introduced (iio: adis: Add burst_max_len variable) in order to make burst32 configuration at runtime.
Nuno Sá (6):
iio: imu: adis: Add Managed device functions
iio: imu: adis: Add irq mask variable
iio: adis: Add adis_update_bits() APIs
iio: adis: Add burst_max_len variable
iio: imu: Add support for adis16475
dt-bindings: iio: Add adis16475 documentation
.../bindings/iio/imu/adi,adis16475.yaml | 146 ++ MAINTAINERS | 9 + drivers/iio/imu/Kconfig | 13 + drivers/iio/imu/Makefile | 1 + drivers/iio/imu/adis.c | 26 + drivers/iio/imu/adis16475.c | 1344 +++++++++++++++++ drivers/iio/imu/adis_buffer.c | 47 +- drivers/iio/imu/adis_trigger.c | 65 +- include/linux/iio/imu/adis.h | 81 + 9 files changed, 1725 insertions(+), 7 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml create mode 100644 drivers/iio/imu/adis16475.c
Signature · 1 line
2.25.1
Nuno Sá
maintainerPATCH v2 1/6 iio: imu: adis: Add Managed device functions
This patch adds support for a managed device version of adis_setup_buffer_and_trigger. It works exactly as the original one but it calls all the devm_iio_* functions to setup an iio buffer and trigger. Hence we do not need to care about cleaning those and we do not need to support a remove() callback for every driver using the adis library.
---
Changes in v2:
* Added blank lines for readability.
drivers/iio/imu/adis_buffer.c | 36 +++++++++++++++++++++++++++++ drivers/iio/imu/adis_trigger.c | 41 +++++++++++++++++++++++++++++++--- include/linux/iio/imu/adis.h | 17 ++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_buffer.c +36 -0
@@ -198,6 +198,42 @@ int adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev, }EXPORT_SYMBOL_GPL (adis_setup_buffer_and_trigger); +/** +* devm_adis_setup_buffer_and_trigger() - Sets up buffer and trigger for +* the managed 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 perfoms exactly the same as adis_setup_buffer_and_trigger() +*/ +int +devm_adis_setup_buffer_and_trigger (struct adis *adis,struct iio_dev *indio_dev, +irqreturn_t (*trigger_handler)(int ,void *)) +{ +int ret; + +if (!trigger_handler) + trigger_handler = adis_trigger_handler; + + ret =devm_iio_triggered_buffer_setup (&adis->spi->dev, indio_dev, + &iio_pollfunc_store_time, + trigger_handler,NULL ); +if (ret) +return ret; + +if (adis->spi->irq) { + ret =devm_adis_probe_trigger (adis, indio_dev); +if (ret) +return ret; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (devm_adis_setup_buffer_and_trigger); +/** * adis_cleanup_buffer_and_trigger() - Free buffer and trigger resources * @adis: The adis device.
drivers/iio/imu/adis_trigger.c +38 -3
59 lines not on this page · raw message
include/linux/iio/imu/adis.h +17 -0
@@ -448,11 +448,15 @@ struct adis_burst {unsigned int extra_len; }; +int +devm_adis_setup_buffer_and_trigger (struct adis *adis,struct iio_dev *indio_dev, +irqreturn_t (*trigger_handler)(int ,void *));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 devm_adis_probe_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);
@@ -461,6 +465,13 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,#else /* CONFIG_IIO_BUFFER */ +static inline int +devm_adis_setup_buffer_and_trigger (struct adis *adis,struct iio_dev *indio_dev, +irqreturn_t (*trigger_handler)(int ,void *)) +{ +return 0 ; +} +static inline int adis_setup_buffer_and_trigger (struct adis *adis,struct iio_dev *indio_dev,irqreturn_t (*trigger_handler)(int ,void *)) {
@@ -472,6 +483,12 @@ static inline void adis_cleanup_buffer_and_trigger(struct adis *adis, { } +static inline int devm_adis_probe_trigger (struct adis *adis, +struct iio_dev *indio_dev) +{ +return 0 ; +} +static inline int adis_probe_trigger (struct adis *adis,struct iio_dev *indio_dev) {
Signature · 1 line
2.25.1
Re: [PATCH v2 1/6] iio: imu: adis: Add Managed device functions
drivers/iio/imu/adis_trigger.c static const struct iio_trigger_ops adis_trigger_ops = { · line 30
Quoted 9 lines · Nuno Sá
drivers/iio/imu/adis_trigger.c +1
-0@@ -27,6 +27,13 @@ static const struct iio_trigger_ops adis_trigger_ops = { .set_trigger_state = &adis_data_rdy_trigger_set_state, }; +static inline void adis_trigger_setup (struct adis *adis)
No need for inline. The compiler will figure this out on its own.
Quoted 23 lines
drivers/iio/imu/adis_trigger.c +7
-3+{ + adis->trig->dev.parent = &adis->spi->dev; + adis->trig->ops = &adis_trigger_ops; +iio_trigger_set_drvdata (adis->trig, adis); +} +/** * adis_probe_trigger() - Sets up trigger for a adis device * @adis: The adis device @@ -45,9 +52,7 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)if (adis->trig ==NULL )return -ENOMEM ; - adis->trig->dev.parent = &adis->spi->dev; - adis->trig->ops = &adis_trigger_ops; -iio_trigger_set_drvdata (adis->trig, adis); +adis_trigger_setup (adis); ret = request_irq(adis->spi->irq, &iio_trigger_generic_data_rdy_poll,@@ -73,6 +78,36 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev) }EXPORT_SYMBOL_GPL (adis_probe_trigger);
Nuno Sá
maintainerPATCH v2 2/6 iio: imu: adis: Add irq mask variable
In reply to Nuno SáThere are some ADIS devices that can configure the data ready pin polarity. Hence, we cannot hardcode our IRQ mask as IRQF_TRIGGER_RISING since we might want to have it as IRQF_TRIGGER_FALLING.
---
Changes in v2:
* Add kernel doc-string for irq-mask.
drivers/iio/imu/adis_trigger.c | 26 ++++++++++++++++++++++++-- include/linux/iio/imu/adis.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-)
drivers/iio/imu/adis_trigger.c +24 -2
@@ -34,6 +34,20 @@ static inline void adis_trigger_setup(struct adis *adis)iio_trigger_set_drvdata (adis->trig, adis); } +static inline int __adis_validate_irq_mask (struct adis *adis) +{ +if (!adis->irq_mask) { + adis->irq_mask =IRQF_TRIGGER_RISING ; +return 0 ; + }else if (adis->irq_mask !=IRQF_TRIGGER_RISING && + adis->irq_mask !=IRQF_TRIGGER_FALLING ) { +dev_err (&adis->spi->dev,"Invalid IRQ mask:%08lx\n" , + adis->irq_mask); +return -EINVAL ; + } + +return 0 ; +}/** * adis_probe_trigger() - Sets up trigger for a adis device * @adis: The adis device
@@ -54,9 +68,13 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)adis_trigger_setup (adis); + ret =__adis_validate_irq_mask (adis); +if (ret) +return ret; + ret =request_irq (adis->spi->irq, &iio_trigger_generic_data_rdy_poll, -IRQF_TRIGGER_RISING , + adis->irq_mask, indio_dev->name, adis->trig);if (ret)
@@ -96,9 +114,13 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)adis_trigger_setup (adis); + ret =__adis_validate_irq_mask (adis); +if (ret) +return ret; + ret =devm_request_irq (&adis->spi->dev, adis->spi->irq, &iio_trigger_generic_data_rdy_poll, -IRQF_TRIGGER_RISING , + adis->irq_mask, indio_dev->name, adis->trig);if (ret)
include/linux/iio/imu/adis.h +2 -0
@@ -87,6 +87,7 @@ struct adis_data {* @msg: SPI message object * @xfer: SPI transfer objects to be used for a @msg * @current_page: Some ADIS devices have registers, this selects current page +* @irq_mask: IRQ handling flags as passed to request_irq() * @buffer: Data buffer for information read from the device * @tx: DMA safe TX buffer for SPI transfers * @rx: DMA safe RX buffer for SPI transfers
@@ -113,6 +114,7 @@ struct adis {struct spi_message msg;struct spi_transfer *xfer;unsigned int current_page; +unsigned long irq_mask;void *buffer;uint8_t tx[10 ]____cacheline_aligned ;
Signature · 1 line
2.25.1
Re: [PATCH v2 2/6] iio: imu: adis: Add irq mask variable
Quoted 18 lines · Nuno Sá
There are some ADIS devices that can configure the data ready pin polarity. Hence, we cannot hardcode our IRQ mask as
IRQF_TRIGGER_RISINGsince we might want to have it asIRQF_TRIGGER_FALLING.Signed-off-by Nuno Sá <[email protected]>---
Changes in v2:
* Add kernel doc-string forirq-mask.drivers/iio/imu/adis_trigger.c | 26 ++++++++++++++++++++++++-- include/linux/iio/imu/adis.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-)drivers/iio/imu/adis_trigger.c +0
-0
drivers/iio/imu/adis_trigger.c static inline void adis_trigger_setup(struct adis *adis) · line 37
Quoted 4 lines
drivers/iio/imu/adis_trigger.c +1
-0@@ -34,6 +34,20 @@ static inline void adis_trigger_setup(struct adis *adis)iio_trigger_set_drvdata (adis->trig, adis); } +static inline int __adis_validate_irq_mask (struct adis *adis)
Bit of a nitpick, I'd drop the __ prefix, so far we only used it if there is a locked and an unlocked version of a function and it is unlikely that we'll need an unlocked function here.
I'd also drop the inline the compiler is smart enough to figure this out on its own. I believe the recommendation at the moment for kernel code is to use inline only for functions defined in header files.
drivers/iio/imu/adis_trigger.c static inline void adis_trigger_setup(struct adis *adis) · line 44
Quoted 7 lines
drivers/iio/imu/adis_trigger.c +7
-0+{ +if (!adis->irq_mask) { + adis->irq_mask =IRQF_TRIGGER_RISING ; +return 0 ; + }else if (adis->irq_mask !=IRQF_TRIGGER_RISING && + adis->irq_mask !=IRQF_TRIGGER_FALLING ) { + dev_err(&adis->spi->dev, "Invalid IRQ mask:%08lx\n",
Another nitpick. Space behind the ":".
Quoted 59 lines
drivers/iio/imu/adis_trigger.c +16
-2+ adis->irq_mask); +return -EINVAL ; + } + +return 0 ; +}/** * adis_probe_trigger() - Sets up trigger for a adis device * @adis: The adis device @@ -54,9 +68,13 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)adis_trigger_setup (adis); + ret =__adis_validate_irq_mask (adis); +if (ret) +return ret; + ret =request_irq (adis->spi->irq, &iio_trigger_generic_data_rdy_poll, -IRQF_TRIGGER_RISING , + adis->irq_mask, indio_dev->name, adis->trig);if (ret)@@ -96,9 +114,13 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)adis_trigger_setup (adis); + ret =__adis_validate_irq_mask (adis); +if (ret) +return ret; + ret =devm_request_irq (&adis->spi->dev, adis->spi->irq, &iio_trigger_generic_data_rdy_poll, -IRQF_TRIGGER_RISING , + adis->irq_mask, indio_dev->name, adis->trig);if (ret)include/linux/iio/imu/adis.h +2
-0@@ -87,6 +87,7 @@ struct adis_data {* @msg: SPI message object * @xfer: SPI transfer objects to be used for a @msg * @current_page: Some ADIS devices have registers, this selects current page +* @irq_mask: IRQ handling flags as passed to request_irq() * @buffer: Data buffer for information read from the device * @tx: DMA safe TX buffer for SPI transfers * @rx: DMA safe RX buffer for SPI transfers @@ -113,6 +114,7 @@ struct adis {struct spi_message msg;struct spi_transfer *xfer;unsigned int current_page; +unsigned long irq_mask;void *buffer;uint8_t tx[10 ]____cacheline_aligned ;
Nuno Sá
maintainerPATCH v2 3/6 iio: adis: Add adis_update_bits() APIs
In reply to Nuno SáThis patch adds a regmap_update_bits() like API to the ADIS library. It provides locked and unlocked variant.
---
Changes in v2:
* Add BUILD_BUG_ON() to avoid invalid types.
drivers/iio/imu/adis.c | 26 ++++++++++++++++ include/linux/iio/imu/adis.h | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
drivers/iio/imu/adis.c +26 -0
@@ -223,6 +223,32 @@ int __adis_read_reg(struct adis *adis, unsigned int reg,return ret; }EXPORT_SYMBOL_GPL (__adis_read_reg); +/** +* __adis_update_bits_base() - ADIS Update bits function - Unlocked version +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @mask: Bitmask to change +* @val: Value to be written +* @size: Size of the register to update +* +* Updates the desired bits of @reg in accordance with @mask and @val. +*/ +int __adis_update_bits_base (struct adis *adis,unsigned int reg,const u32 mask, +const u32 val,u8 size) +{ +int ret; +u32 __val; + + ret =__adis_read_reg (adis, reg, &__val, size); +if (ret) +return ret; + + __val &= ~mask; + __val |= val & mask; + +return __adis_write_reg (adis, reg, __val, size); +} +EXPORT_SYMBOL_GPL (__adis_update_bits_base);#ifdef CONFIG_DEBUG_FS
include/linux/iio/imu/adis.h +59 -0
65 lines not on this page · raw message
Signature · 1 line
2.25.1
Jonathan Cameron
maintainerRe: [PATCH v2 3/6] iio: adis: Add adis_update_bits() APIs
Quoted 4 lines · On Mon, 16 Mar 2020 13:53:09 +0100 Nuno Sá <[email protected]> wrote:
This patch adds a
regmap_update_bits()like API to the ADIS library. It provides locked and unlocked variant.Signed-off-by Nuno Sá <[email protected]>
hmm. This feels a bit 'too clever' but hopefully we won't get any subtle bugs due to wrong local variable types etc.
I'll pick this up when the rest of the series is ready.
Jonathan
Quoted 115 lines
---
Changes in v2:
* AddBUILD_BUG_ON()to avoid invalid types.drivers/iio/imu/adis.c | 26 ++++++++++++++++ include/linux/iio/imu/adis.h | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)drivers/iio/imu/adis.c +26
-0@@ -223,6 +223,32 @@ int __adis_read_reg(struct adis *adis, unsigned int reg,return ret; }EXPORT_SYMBOL_GPL (__adis_read_reg); +/** +* __adis_update_bits_base() - ADIS Update bits function - Unlocked version +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @mask: Bitmask to change +* @val: Value to be written +* @size: Size of the register to update +* +* Updates the desired bits of @reg in accordance with @mask and @val. +*/ +int __adis_update_bits_base (struct adis *adis,unsigned int reg,const u32 mask, +const u32 val,u8 size) +{ +int ret; +u32 __val; + + ret =__adis_read_reg (adis, reg, &__val, size); +if (ret) +return ret; + + __val &= ~mask; + __val |= val & mask; + +return __adis_write_reg (adis, reg, __val, size); +} +EXPORT_SYMBOL_GPL (__adis_update_bits_base);#ifdef CONFIG_DEBUG_FS include/linux/iio/imu/adis.h +59
-0@@ -333,6 +333,65 @@ static inline int adis_read_reg_32(struct adis *adis, unsigned int reg,return ret; } +int __adis_update_bits_base (struct adis *adis,unsigned int reg,const u32 mask, +const u32 val,u8 size); +/** +* adis_update_bits_base() - ADIS Update bits function - Locked version +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @mask: Bitmask to change +* @val: Value to be written +* @size: Size of the register to update +* +* Updates the desired bits of @reg in accordance with @mask and @val. +*/ +static inline int adis_update_bits_base (struct adis *adis,unsigned int reg, +const u32 mask,const u32 val,u8 size) +{ +int ret; + +mutex_lock (&adis->state_lock); + ret =__adis_update_bits_base (adis, reg, mask, val, size); +mutex_unlock (&adis->state_lock); +return ret; +} + +/** +* adis_update_bits() - Wrapper macro for adis_update_bits_base - Locked version +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @mask: Bitmask to change +* @val: Value to be written +* +* This macro evaluates the sizeof of @val at compile time and calls +* adis_update_bits_base() accordingly. Be aware that using MACROS/DEFINES for +* @val can lead to undesired behavior if the register to update is 16bit. +*/ +#define adis_update_bits (adis, reg, mask, val) ({ \ + BUILD_BUG_ON(sizeof(val) == 1 || sizeof(val) == 8); \ + __builtin_choose_expr(sizeof(val) == 4, \ + adis_update_bits_base(adis, reg, mask, val, 4), \ + adis_update_bits_base(adis, reg, mask, val, 2)); \ +}) + +/** +* adis_update_bits() - Wrapper macro for adis_update_bits_base +* @adis: The adis device +* @reg: The address of the lower of the two registers +* @mask: Bitmask to change +* @val: Value to be written +* +* This macro evaluates the sizeof of @val at compile time and calls +* adis_update_bits_base() accordingly. Be aware that using MACROS/DEFINES for +* @val can lead to undesired behavior if the register to update is 16bit. +*/ +#define __adis_update_bits (adis, reg, mask, val) ({ \ + BUILD_BUG_ON(sizeof(val) == 1 || sizeof(val) == 8); \ + __builtin_choose_expr(sizeof(val) == 4, \ + __adis_update_bits_base(adis, reg, mask, val, 4), \ + __adis_update_bits_base(adis, reg, mask, val, 2)); \ +}) +int adis_enable_irq (struct adis *adis,bool enable);int __adis_check_status (struct adis *adis);int __adis_initial_startup (struct adis *adis);
Nuno Sá
maintainerPATCH v2 4/6 iio: adis: Add burst_max_len variable
In reply to Nuno SáAdd burst_max_len to adis_burst. This is useful for devices which support different burst modes with different sizes. The buffer to be used in the spi transfer is allocated with this variable making sure that has space for all burst modes. The spi transfer length should hold the "real" burst length depending on the current burst mode configured in the device.
--- drivers/iio/imu/adis_buffer.c | 11 ++++++++--- include/linux/iio/imu/adis.h | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_buffer.c +8 -3
@@ -23,25 +23,30 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev, const unsigned long *scan_mask) {struct adis *adis =iio_device_get_drvdata (indio_dev); -unsigned int burst_length; +unsigned int burst_length, burst_max_length;u8 *tx;/* All but the timestamp channel */ burst_length = (indio_dev->num_channels -1 ) *sizeof (u16); burst_length += adis->burst->extra_len; +if (adis->burst->burst_max_len) + burst_max_length = adis->burst->burst_max_len; +else + burst_max_length = burst_length; + adis->xfer =kcalloc (2 ,sizeof (*adis->xfer),GFP_KERNEL );if (!adis->xfer)return -ENOMEM ; - adis->buffer =kzalloc (burst_length +sizeof (u16),GFP_KERNEL ); + adis->buffer =kzalloc (burst_max_length +sizeof (u16),GFP_KERNEL );if (!adis->buffer) {kfree (adis->xfer); adis->xfer =NULL ;return -ENOMEM ; } - tx = adis->buffer + burst_length; + tx = adis->buffer + burst_max_length; tx[0 ] =ADIS_READ_REG (adis->burst->reg_cmd); tx[1 ] =0 ;
include/linux/iio/imu/adis.h +3 -0
@@ -502,11 +502,14 @@ int adis_single_conversion(struct iio_dev *indio_dev,* @en burst mode enabled * @reg_cmd register command that triggers burst * @extra_len extra length to account in the SPI RX buffer +* @burst_max_len holds the maximum burst size when the device supports +* more than one burst mode with different sizes */ struct adis_burst {bool en;unsigned int reg_cmd;unsigned int extra_len; +const u32 burst_max_len; };int
Signature · 1 line
2.25.1
Nuno Sá
maintainerPATCH v2 5/6 iio: imu: Add support for adis16475
In reply to Nuno SáSupport ADIS16475 and similar IMU devices. These devices are a precision, miniature MEMS inertial measurement unit (IMU) that includes a triaxial gyroscope and a triaxial accelerometer. Each inertial sensor combines with signal conditioning that optimizes dynamic performance.
The driver adds support for the following devices:
* adis16470, adis16475, adis16477, adis16465, adis16467, adis16500, adis16505, adis16507.
---
Changes in v2:
* Remove burst mode config (enabled by default);
* Fix timestamp channel index;
* Do return code checks inline in adis16475_read_raw;
* Increase buffer size to fit aligned timestamp;
* Remove spi_device_id table;
* Rename adis16475_clks to adis16475_sync;
* Rename adis16475_config_ext_clk adis16475_config_sync_mode;
* Fix output-sync mode. There's no need to call clk_get in this mode as
it acts as an output pin;
* Fix scaled-mode configuration. Up scale was not being written on the right register;
* Handle burst32 configuration at runtime. When the decimation or the FIR filter is enabled
the LSB bits are meangninfull. Hence, use burst32 in that case (if the part supports it);
* When there's no burst32 mode and the LSB data is meangninfull, read it manually...
* Do not push data to buffers if crc is invalid.
MAINTAINERS | 8 + drivers/iio/imu/Kconfig | 13 + drivers/iio/imu/Makefile | 1 + drivers/iio/imu/adis16475.c | 1344 +++++++++++++++++++++++++++++++++++ 4 files changed, 1366 insertions(+) create mode 100644 drivers/iio/imu/adis16475.c
MAINTAINERS +8 -0
@@ -1008,6 +1008,14 @@ W: http://ez.analog.com/community/linux-device-drivers F: drivers/iio/imu/adis16460.c F: Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml +ANALOG DEVICES INC ADIS16475 DRIVER +M: Nuno Sa <[email protected]> +L: [email protected] +W: http://ez.analog.com/community/linux-device-drivers +S: Supported +F: drivers/iio/imu/adis16475.c +F: Documentation/ABI/testing/sysfs-bus-iio-imu-adis16475 + ANALOG DEVICES INC ADM1177 DRIVER M: Beniamin Bia <[email protected]> M: Michael Hennerich <[email protected]>
drivers/iio/imu/Kconfig +13 -0
@@ -29,6 +29,19 @@ config ADIS16460 To compile this driver as a module, choose M here: the module will be called adis16460. +config ADIS16475 + tristate "Analog Devices ADIS16475 and similar IMU driver" + depends on SPI + select IIO_ADIS_LIB + select IIO_ADIS_LIB_BUFFER if IIO_BUFFER + help + Say yes here to build support for Analog Devices ADIS16470, ADIS16475, + ADIS16477, ADIS16465, ADIS16467, ADIS16500, ADIS16505, ADIS16507 inertial + sensors. + + To compile this driver as a module, choose M here: the module will be + called adis16475. + config ADIS16480 tristate "Analog Devices ADIS16480 and similar IMU driver" depends on SPI
drivers/iio/imu/Makefile +1 -0
@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADIS16400) += adis16400.o obj-$(CONFIG_ADIS16460) += adis16460.o +obj-$(CONFIG_ADIS16475) += adis16475.o obj-$(CONFIG_ADIS16480) += adis16480.o adis_lib-y += adis.o
drivers/iio/imu/adis16475.c new file +1344 -0
1,344 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 5/6] iio: imu: Add support for adis16475
Quoted 10 lines · Nuno Sá
Support ADIS16475 and similar IMU devices. These devices are a precision, miniature MEMS inertial measurement unit (IMU) that includes a triaxial gyroscope and a triaxial accelerometer. Each inertial sensor combines with signal conditioning that optimizes dynamic performance.
The driver adds support for the following devices:
* adis16470, adis16475, adis16477, adis16465, adis16467, adis16500,adis16505, adis16507.
Looks very good, just a few comments and questions. I like the solution for the 32-bit registers.
drivers/iio/imu/adis16475.c line 272
Quoted 7 lines
drivers/iio/imu/adis16475.c new file +7
-0+static int adis16475_set_freq (struct adis16475 *st,const u32 freq) +{ +u16 dec; +int ret; + +if (freq ==0 || freq > st->clk_freq) +return -EINVAL ;
Maybe round down if freq is larger the maximum rate. I believe we do that same for other drivers.
Quoted 5 lines
drivers/iio/imu/adis16475.c new file +5
-0+ + dec =DIV_ROUND_CLOSEST (st->clk_freq, freq); + +if (dec) + dec--;
drivers/iio/imu/adis16475.c line 287
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+ +if (dec > st->info->max_dec) + dec = st->info->max_dec; + + ret =adis_write_reg_16 (&st->adis,ADIS16475_REG_DEC_RATE , dec); +if (ret) +return ret; + +/* +* If decimation is used, then gyro and accel data will have meaningfull
Typo: "meaningful"
Quoted 5 lines
drivers/iio/imu/adis16475.c new file +5
-0+* bits on the LSB registers. This info is used on the trigger handler. +*/ +if (!dec) +clear_bit (ADIS16475_LSB_DEC_MASK , &st->lsb_flag); +else
drivers/iio/imu/adis16475.c line 302
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+set_bit (ADIS16475_LSB_DEC_MASK , &st->lsb_flag); + +return 0 ; +} + +/* The values are approximated. */ +static const u32 adis16475_3db_freqs[] = { + [0 ] =720 ,/* Filter disabled, full BW (~720Hz) */ + [1 ] =360 , + [2 ] =164 ,
164 is the only one that does not follow the pattern of 720 / (2**n). Not sure if that is on purpose. But either way where did you find the bandwidths for the different filter settings? I had a quick look at the datasheet and could not find anything.
Maybe it also makes sense to consider the clock rate when running in sync mode as the bandwidth will be a function of the sampling rate.
Quoted 21 lines
drivers/iio/imu/adis16475.c new file +21
-0+ [3] = 80, + [4] = 40, + [5] = 20, + [6] = 10, + [7] = 10, /* not a valid setting */ +}; + +static int adis16475_get_filter (struct adis16475 *st,u32 *filter) +{ +u16 filter_sz; +int ret; +const int mask =ADIS16475_FILT_CTRL_MASK ; + + ret =adis_read_reg_16 (&st->adis,ADIS16475_REG_FILT_CTRL , &filter_sz); +if (ret) +return ret; + + *filter = adis16475_3db_freqs[filter_sz & mask]; + +return 0 ; +}
drivers/iio/imu/adis16475.c line 333
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+ +static int adis16475_set_filter (struct adis16475 *st,const u32 filter) +{ +int i; +int ret; + +for (i =ARRAY_SIZE (adis16475_3db_freqs) -1 ; i >=1 ; i--) { +if (adis16475_3db_freqs[i] >= filter) +break ; + }
If the filter frequency is less or equal to 10, this will pick 7 for i. But the comment above says that it is an invalid setting.
drivers/iio/imu/adis16475.c line 936
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +2
-0+static u16 adis16475_validate_crc (const u8 *buffer,const u16 crc, +const bool burst32)
Return type is u16, but the return value is bool. Also validate kind of suggests that it returns true if valid, but right now it returns true if invalid.
drivers/iio/imu/adis16475.c line 939
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+{ +int i; +u16 __crc =0 ;
I find having both __crc and crc a bit confusing, maybe give them names which better describe them. Maybe computed_crc or expected_crc. Or as an alternative I think also just crc -= buffer[i] in the loop and crc != 0 at the end should work.
Quoted 22 lines
drivers/iio/imu/adis16475.c new file +22
-0+/* extra 6 elements for low gyro and accel */ +const u16 sz = burst32 ?ADIS16475_BURST32_MAX_DATA : +ADIS16475_BURST_MAX_DATA ; + +for (i =0 ; i < sz -2 ; i++) + __crc += buffer[i]; + +return (__crc != crc); +} + +static void adis16475_burst32_check (struct adis16475 *st) +{ +int ret; +struct adis *adis = &st->adis; + +if (!st->info->has_burst32) +return ; + +if (st->lsb_flag && !st->burst32) { +const u16 en =ADIS16500_BURST32 (1 ); + + ret = __adis_update_bits(&st->adis, ADIS16475_REG_MSG_CTRL,
drivers/iio/imu/adis16475.c line 971
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+ ADIS16500_BURST32_MASK, en); +if (ret <0 ) +return ; + + st->burst32 = true; +/* +* In 32bit mode we need extra 2 bytes for all gyro +* and accel channels. +*/ + adis->burst->extra_len +=6 *sizeof (u16);
I believe this breaks if you have more than one device instance as adis->burst points to a global struct that is shared between all instances. extra_len should probably be part of the adis struct itself and then make the burst field const.
Quoted 21 lines
drivers/iio/imu/adis16475.c new file +21
-0+ adis->xfer[1 ].len +=6 *sizeof (u16); +dev_dbg (&adis->spi->dev,"Enable burst32 mode, xfer:%d" , + adis->xfer[1 ].len); + + }else if (!st->lsb_flag && st->burst32) { +const u16 en =ADIS16500_BURST32 (0 ); + + ret =__adis_update_bits (&st->adis,ADIS16475_REG_MSG_CTRL , +ADIS16500_BURST32_MASK , en); +if (ret <0 ) +return ; + + st->burst32 = false; +/* Remove the extra bits */ + adis->burst->extra_len -=6 *sizeof (u16); + adis->xfer[1 ].len -=6 *sizeof (u16); +dev_dbg (&adis->spi->dev,"Disable burst32 mode, xfer:%d\n" , + adis->xfer[1 ].len); + } +} +
Sa, Nuno
maintainerRE: [PATCH v2 5/6] iio: imu: Add support for adis16475
Quoted 27 lines
-----Original Message-----
From: Lars-Peter Clausen <[email protected]>
Sent: Montag, 16. März 2020 15:27
To: Sa, Nuno <[email protected]>; [email protected]; [email protected]
Cc: Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Peter Meerwald-Stadler <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Ardelean, Alexandru <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v2 5/6] iio: imu: Add support for adis16475Quoted 10 lines · Nuno Sá
Support ADIS16475 and similar IMU devices. These devices are a precision, miniature MEMS inertial measurement unit (IMU) that includes a triaxial gyroscope and a triaxial accelerometer. Each inertial sensor combines with signal conditioning that optimizes dynamic performance.
The driver adds support for the following devices:
* adis16470, adis16475, adis16477, adis16465, adis16467, adis16500,adis16505, adis16507.Looks very good, just a few comments and questions. I like the solution for the 32-bit registers.
Quoted 10 lines
drivers/iio/imu/adis16475.c line 272
Quoted 7 lines
drivers/iio/imu/adis16475.c new file +7
-0+static int adis16475_set_freq (struct adis16475 *st,const u32 freq) +{ +u16 dec; +int ret; + +if (freq ==0 || freq > st->clk_freq) +return -EINVAL ;Maybe round down if freq is larger the maximum rate. I believe we do that same for other drivers.
Can do that...
Quoted 8 lines
Quoted 8 lines
drivers/iio/imu/adis16475.c new file +8
-0+ + dec =DIV_ROUND_CLOSEST (st->clk_freq, freq); + +if (dec) + dec--; + +if (dec > st->info->max_dec) + dec = st->info->max_dec;
Quoted 8 lines
drivers/iio/imu/adis16475.c line 287
Quoted 7 lines
drivers/iio/imu/adis16475.c new file +7
-0+ + ret =adis_write_reg_16 (&st->adis,ADIS16475_REG_DEC_RATE , dec); +if (ret) +return ret; + +/* +* If decimation is used, then gyro and accel data will have meaningfull Typo: "meaningful"
Ack
Quoted 12 lines
Quoted 12 lines
drivers/iio/imu/adis16475.c new file +12
-0+* bits on the LSB registers. This info is used on the trigger handler. +*/ +if (!dec) +clear_bit (ADIS16475_LSB_DEC_MASK , &st->lsb_flag); +else +set_bit (ADIS16475_LSB_DEC_MASK , &st->lsb_flag); + +return 0 ; +} + +/* The values are approximated. */ +static const u32 adis16475_3db_freqs[] = {
Quoted 9 lines
drivers/iio/imu/adis16475.c line 302
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+ [0] = 720, /* Filter disabled, full BW (~720Hz) */ + [1] = 360, + [2] = 164,164 is the only one that does not follow the pattern of 720 / (2**n). Not sure if that is on purpose. But either way where did you find the bandwidths for the different filter settings? I had a quick look at the datasheet and could not find anything.
So, when I started the driver and looked to other examples I also wondered about this. So, basically I asked (internally) about this table to the Application engineer responsible for this parts and got an excel sheet with this values calculated for a sampling rate of 2khz.
Quoted 3 lines
Maybe it also makes sense to consider the clock rate when running in sync mode as the bandwidth will be a function of the sampling rate.
Hmm, that is true. The sampling rate also contributes to the system bandwidth Need to check if we can calculate this in the kernel though...
Quoted 27 lines
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +4
-0+ [3] = 80, + [4] = 40, + [5] = 20, + [6] = 10,drivers/iio/imu/adis16475.c
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+ [7] = 10, /* not a valid setting */ +}; + +static int adis16475_get_filter (struct adis16475 *st,u32 *filter) +{ +u16 filter_sz; +int ret; +const int mask =ADIS16475_FILT_CTRL_MASK ; + + ret = adis_read_reg_16(&st->adis, ADIS16475_REG_FILT_CTRL,
&filter_sz);Quoted 12 lines
drivers/iio/imu/adis16475.c new file +12
-0+if (ret) +return ret; + + *filter = adis16475_3db_freqs[filter_sz & mask]; + +return 0 ; +} + +static int adis16475_set_filter (struct adis16475 *st,const u32 filter) +{ +int i; +int ret;
Quoted 9 lines
drivers/iio/imu/adis16475.c line 333
Quoted 5 lines
drivers/iio/imu/adis16475.c new file +5
-0+ +for (i =ARRAY_SIZE (adis16475_3db_freqs) -1 ; i >=1 ; i--) { +if (adis16475_3db_freqs[i] >= filter) +break ; + }If the filter frequency is less or equal to 10, this will pick 7 for i. But the comment above says that it is an invalid setting.
Good catch! I believe the part will just automatically convert it to 6. Either way, better play safe.
Quoted 6 lines
drivers/iio/imu/adis16475.c line 936
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +2
-0+static u16 adis16475_validate_crc (const u8 *buffer,const u16 crc, +const bool burst32)Return type is u16, but the return value is bool. Also validate kind of suggests that it returns true if valid, but right now it returns true if invalid.
Quoted 9 lines
drivers/iio/imu/adis16475.c line 939
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+{ +int i; +u16 __crc =0 ;I find having both
__crcand crc a bit confusing, maybe give them names which better describe them. Maybecomputed_crcorexpected_crc. Or as an alternative I think also just crc -= buffer[i] in the loop and crc != 0 at the end should work.
Hmm, I like the alternative...
Quoted 24 lines
Quoted 13 lines
drivers/iio/imu/adis16475.c new file +12
-0+/* extra 6 elements for low gyro and accel */ +const u16 sz = burst32 ?ADIS16475_BURST32_MAX_DATA : +ADIS16475_BURST_MAX_DATA ; + +for (i =0 ; i < sz -2 ; i++) + __crc += buffer[i]; + +return (__crc != crc); +} + +static void adis16475_burst32_check (struct adis16475 *st) +{drivers/iio/imu/adis16475.c
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+int ret; +struct adis *adis = &st->adis; + +if (!st->info->has_burst32) +return ; + +if (st->lsb_flag && !st->burst32) { +const u16 en =ADIS16500_BURST32 (1 ); + + ret = __adis_update_bits(&st->adis,
ADIS16475_REG_MSG_CTRL,
Quoted 16 lines
drivers/iio/imu/adis16475.c line 971
Quoted 10 lines
drivers/iio/imu/adis16475.c new file +10
-0+ ADIS16500_BURST32_MASK, en); +if (ret <0 ) +return ; + + st->burst32 = true; +/* +* In 32bit mode we need extra 2 bytes for all gyro +* and accel channels. +*/ + adis->burst->extra_len +=6 *sizeof (u16);I believe this breaks if you have more than one device instance as
adis->burstpoints to a global struct that is shared between all instances.extra_lenshould probably be part of the adis struct itself and then make the burst field const.
Ups, definitely a problem! This extra_len is actually something that I don't like. I have some local patches to get rid of this variable. So, burst_len is being calculated like this
/* All but the timestamp channel */burst_length = (indio_dev->num_channels - 1) * sizeof(u16); burst_length += adis->burst->extra_len;
This is done in the library which in my opinion is wrong. The library should not assume that a timestamp channel is defined. IMHO, it would be just simpler and direct if users define burst_len directly (replacing extra_len) which is actually constant in a lot of devices...
Either way, we still need a variable in the adis struct which can actually change per "instance"... Maybe I just go with your suggestion and leave the replacement of extra_len for a future patch.
- Nuno Sá
Nuno Sá
maintainerPATCH v2 6/6 dt-bindings: iio: Add adis16475 documentation
In reply to Nuno SáDocument the ADIS16475 device devicetree bindings.
---
Changes in v2:
* Remove burst32 property;
* Rename clk-mode to adi,sync-mode;
* Remove clock-names;
* Add conditionals to state that clocks is only needed depending on adi,sync-mode property
.../bindings/iio/imu/adi,adis16475.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +146 -0
@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/adi,adis16475.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADIS16475 and similar IMUs + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices ADIS16475 and similar IMUs + https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16475.pdf + +properties: + compatible: + enum: + - adi,adis16475-1 + - adi,adis16475-2 + - adi,adis16475-3 + - adi,adis16477-1 + - adi,adis16477-2 + - adi,adis16477-3 + - adi,adis16470 + - adi,adis16465-1 + - adi,adis16465-2 + - adi,adis16465-3 + - adi,adis16467-1 + - adi,adis16467-2 + - adi,adis16467-3 + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + + reg: + maxItems: 1 + + spi-cpha: true + + spi-cpol: true + + spi-max-frequency: + maximum: 2000000 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + reset-gpios: + description: + Must be the device tree identifier of the RESET pin. If specified, + it will be asserted during driver probe. As the line is active low, + it should be marked GPIO_ACTIVE_LOW. + maxItems: 1 + + adi,sync-mode: + description: + Configures the device SYNC pin. The following modes are supported + 0 - output_sync + 1 - direct_sync + 2 - scaled_sync + 3 - pulse_sync + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 3 + + adi,scaled-output-hz: + description: + This property must be present if the clock mode is scaled-sync through + clock-names property. In this mode, the input clock can have a range + of 1Hz to 128HZ which must be scaled to originate an allowable sample + rate. This property specifies that rate. + minimum: 1900 + maximum: 2100 + +required: + - compatible + - reg + - interrupts + - spi-cpha + - spi-cpol + +if: + properties: + compatible: + contains: + enum: + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + +then: + properties: + adi,sync-mode: + minimum: 0 + maximum: 2 + + if: + properties: + adi,sync-mode: + enum: [1, 2] + + then: + dependencies: + adi,sync-mode: [ clocks ] + +else: + if: + properties: + adi,sync-mode: + enum: [1, 2, 3] + + then: + dependencies: + adi,sync-mode: [ clocks ] + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + adis16475: adis16475-3@0 { + compatible = "adi,adis16475-3"; + reg = <0>; + spi-cpha; + spi-cpol; + spi-max-frequency = <2000000>; + interrupts = <4 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + }; + }; +...
MAINTAINERS +1 -0
@@ -1015,6 +1015,7 @@ W: http://ez.analog.com/community/linux-device-drivers S: Supported F: drivers/iio/imu/adis16475.c F: Documentation/ABI/testing/sysfs-bus-iio-imu-adis16475 +F: Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml ANALOG DEVICES INC ADM1177 DRIVER M: Beniamin Bia <[email protected]>
Signature · 1 line
2.25.1
Jonathan Cameron
maintainerRe: [PATCH v2 6/6] dt-bindings: iio: Add adis16475 documentation
Quoted 3 lines · On Mon, 16 Mar 2020 13:53:12 +0100 Nuno Sá <[email protected]> wrote:
Document the ADIS16475 device devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>
Hmm. A bit fiddly so definitely want a review from Rob.
Thanks,
Jonathan
Quoted 144 lines
---
Changes in v2:
* Remove burst32 property;
* Rename clk-mode to adi,sync-mode;
* Remove clock-names;
* Add conditionals to state that clocks is only needed depending on adi,sync-mode property.../bindings/iio/imu/adi,adis16475.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yamlDocumentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +126
-0@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/adi,adis16475.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADIS16475 and similar IMUs + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices ADIS16475 and similar IMUs + https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16475.pdf + +properties: + compatible: + enum: + - adi,adis16475-1 + - adi,adis16475-2 + - adi,adis16475-3 + - adi,adis16477-1 + - adi,adis16477-2 + - adi,adis16477-3 + - adi,adis16470 + - adi,adis16465-1 + - adi,adis16465-2 + - adi,adis16465-3 + - adi,adis16467-1 + - adi,adis16467-2 + - adi,adis16467-3 + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + + reg: + maxItems: 1 + + spi-cpha: true + + spi-cpol: true + + spi-max-frequency: + maximum: 2000000 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + reset-gpios: + description: + Must be the device tree identifier of the RESET pin. If specified, + it will be asserted during driver probe. As the line is active low, + it should be marked GPIO_ACTIVE_LOW. + maxItems: 1 + + adi,sync-mode: + description: + Configures the device SYNC pin. The following modes are supported + 0 - output_sync + 1 - direct_sync + 2 - scaled_sync + 3 - pulse_sync + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 3 + + adi,scaled-output-hz: + description: + This property must be present if the clock mode is scaled-sync through + clock-names property. In this mode, the input clock can have a range + of 1Hz to 128HZ which must be scaled to originate an allowable sample + rate. This property specifies that rate. + minimum: 1900 + maximum: 2100 + +required: + - compatible + - reg + - interrupts + - spi-cpha + - spi-cpol + +if: + properties: + compatible: + contains: + enum: + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + +then: + properties: + adi,sync-mode: + minimum: 0 + maximum: 2 + + if: + properties: + adi,sync-mode: + enum: [1, 2] + + then: + dependencies: + adi,sync-mode: [ clocks ] + +else: + if: + properties: + adi,sync-mode: + enum: [1, 2, 3] + + then: + dependencies:
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml line 136
Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+ adi,sync-mode: [ clocks ] + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + adis16475: adis16475-3@0 {
Generic name for nodes. imu I guess here.
Quoted 22 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+ compatible = "adi,adis16475-3"; + reg = <0>; + spi-cpha; + spi-cpol; + spi-max-frequency = <2000000>; + interrupts = <4 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + }; + }; +...MAINTAINERS +1
-0@@ -1015,6 +1015,7 @@ W: http://ez.analog.com/community/linux-device-drivers S: Supported F: drivers/iio/imu/adis16475.c F: Documentation/ABI/testing/sysfs-bus-iio-imu-adis16475 +F: Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml ANALOG DEVICES INC ADM1177 DRIVER M: Beniamin Bia <[email protected]>
Rob Herring
maintainerRe: [PATCH v2 6/6] dt-bindings: iio: Add adis16475 documentation
In reply to Nuno SáQuoted 128 lines · Nuno Sá
Document the ADIS16475 device devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>---
Changes in v2:
* Remove burst32 property;
* Rename clk-mode to adi,sync-mode;
* Remove clock-names;
* Add conditionals to state that clocks is only needed depending on adi,sync-mode property.../bindings/iio/imu/adi,adis16475.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yamlDocumentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +107
-0@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/adi,adis16475.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADIS16475 and similar IMUs + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices ADIS16475 and similar IMUs + https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16475.pdf + +properties: + compatible: + enum: + - adi,adis16475-1 + - adi,adis16475-2 + - adi,adis16475-3 + - adi,adis16477-1 + - adi,adis16477-2 + - adi,adis16477-3 + - adi,adis16470 + - adi,adis16465-1 + - adi,adis16465-2 + - adi,adis16465-3 + - adi,adis16467-1 + - adi,adis16467-2 + - adi,adis16467-3 + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + + reg: + maxItems: 1 + + spi-cpha: true + + spi-cpol: true + + spi-max-frequency: + maximum: 2000000 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + reset-gpios: + description: + Must be the device tree identifier of the RESET pin. If specified, + it will be asserted during driver probe. As the line is active low, + it should be marked GPIO_ACTIVE_LOW. + maxItems: 1 + + adi,sync-mode: + description: + Configures the device SYNC pin. The following modes are supported + 0 - output_sync + 1 - direct_sync + 2 - scaled_sync + 3 - pulse_sync + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 3 + + adi,scaled-output-hz: + description: + This property must be present if the clock mode is scaled-sync through + clock-names property. In this mode, the input clock can have a range + of 1Hz to 128HZ which must be scaled to originate an allowable sample + rate. This property specifies that rate. + minimum: 1900 + maximum: 2100 + +required: + - compatible + - reg + - interrupts + - spi-cpha + - spi-cpol + +if: + properties: + compatible: + contains: + enum: + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + +then: + properties: + adi,sync-mode: + minimum: 0
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml line 117
Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+ maximum: 2 + + if: + properties: + adi,sync-mode: + enum: [1, 2] + + then: + dependencies: + adi,sync-mode: [ clocks ]
You can remove this if/then if you...
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml line 127
Quoted 11 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+ +else: + if: + properties: + adi,sync-mode: + enum: [1, 2, 3] + + then: + dependencies: + adi,sync-mode: [ clocks ]
...put this if by itself under an 'allOf'. (And then the 1st if should go under the 'allOf' too).
Quoted 34 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +19
-0+ +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + adis16475: adis16475-3@0 { + compatible = "adi,adis16475-3"; + reg = <0>; + spi-cpha; + spi-cpol; + spi-max-frequency = <2000000>; + interrupts = <4 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + }; + }; +...MAINTAINERS +1
-0@@ -1015,6 +1015,7 @@ W: http://ez.analog.com/community/linux-device-drivers S: Supported F: drivers/iio/imu/adis16475.c F: Documentation/ABI/testing/sysfs-bus-iio-imu-adis16475 +F: Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml ANALOG DEVICES INC ADM1177 DRIVER M: Beniamin Bia <[email protected]>Signature · 1 line
2.25.1
Sa, Nuno
maintainerRE: [PATCH v2 6/6] dt-bindings: iio: Add adis16475 documentation
Quoted 170 lines
From: [email protected] <[email protected]> On Behalf Of Rob Herring
Sent: Montag, 30. März 2020 22:33
To: Sa, Nuno <[email protected]>
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>; Mark Rutland <[email protected]>; Ardelean, Alexandru <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v2 6/6] dt-bindings: iio: Add adis16475 documentationQuoted 9 lines · Nuno Sá
Document the ADIS16475 device devicetree bindings.
Signed-off-by Nuno Sá <[email protected]>---
Changes in v2:
* Remove burst32 property;
* Rename clk-mode to adi,sync-mode;
* Remove clock-names;
* Add conditionals to state that clocks is only needed depending onadi,sync-mode property
Quoted 5 lines
.../bindings/iio/imu/adi,adis16475.yaml | 146 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 147 insertions(+) create mode 100644
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yamlReview
Quoted 2 lines
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/iio/imu/adi,adis16475.yamlQuoted 9 lines
new file mode 100644
index 000000000000..9eeb42773eddDocumentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +4
-0@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/adi,adis16475.yaml#Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices ADIS16475 and similar IMUs + +maintainers: + - Nuno Sá <[email protected]> + +description: | + Analog Devices ADIS16475 and similar IMUs + https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16475.pdf
Quoted 93 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +93
-0+ +properties: + compatible: + enum: + - adi,adis16475-1 + - adi,adis16475-2 + - adi,adis16475-3 + - adi,adis16477-1 + - adi,adis16477-2 + - adi,adis16477-3 + - adi,adis16470 + - adi,adis16465-1 + - adi,adis16465-2 + - adi,adis16465-3 + - adi,adis16467-1 + - adi,adis16467-2 + - adi,adis16467-3 + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + + reg: + maxItems: 1 + + spi-cpha: true + + spi-cpol: true + + spi-max-frequency: + maximum: 2000000 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + reset-gpios: + description: + Must be the device tree identifier of the RESET pin. If specified, + it will be asserted during driver probe. As the line is active low, + it should be marked GPIO_ACTIVE_LOW. + maxItems: 1 + + adi,sync-mode: + description: + Configures the device SYNC pin. The following modes are supported + 0 - output_sync + 1 - direct_sync + 2 - scaled_sync + 3 - pulse_sync + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 3 + + adi,scaled-output-hz: + description: + This property must be present if the clock mode is scaled-sync through + clock-names property. In this mode, the input clock can have a range + of 1Hz to 128HZ which must be scaled to originate an allowable sample + rate. This property specifies that rate. + minimum: 1900 + maximum: 2100 + +required: + - compatible + - reg + - interrupts + - spi-cpha + - spi-cpol + +if: + properties: + compatible: + contains: + enum: + - adi,adis16500 + - adi,adis16505-1 + - adi,adis16505-2 + - adi,adis16505-3 + - adi,adis16507-1 + - adi,adis16507-2 + - adi,adis16507-3 + +then: + properties: + adi,sync-mode: + minimum: 0Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml line 117
Quoted 10 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+ maximum: 2 + + if: + properties: + adi,sync-mode: + enum: [1, 2] + + then: + dependencies: + adi,sync-mode: [ clocks ]You can remove this if/then if you...
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml line 127
Quoted 11 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +10
-0+ +else: + if: + properties: + adi,sync-mode: + enum: [1, 2, 3] + + then: + dependencies: + adi,sync-mode: [ clocks ]
Quoted 3 lines
...put this if by itself under an 'allOf'. (And then the 1st if should go under the 'allOf' too).
I see. I was being a bit picky here. If I'm understanding correctly I actually tried that form and when playing with the example and setting compatible to "adis16505" and adi,sync-mode = <3> (for eg), I was getting both messages:
adis16475-3@0: adi,sync-mode:0:0: 3 is greater than the maximum of 2 adis16475-3@0: 'clocks' is a dependency of 'adi,sync-mode'
And in this case, I wanted to just have the first message. Either way, it should be clear that the first message needs to be fixed. I will change to allOf...
- Nuno Sá
Quoted 35 lines
MAINTAINERS W: http://ez.analog.com/community/linux-
Quoted 24 lines
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +19
-0+ +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + adis16475: adis16475-3@0 { + compatible = "adi,adis16475-3"; + reg = <0>; + spi-cpha; + spi-cpol; + spi-max-frequency = <2000000>; + interrupts = <4 IRQ_TYPE_EDGE_RISING>; + interrupt-parent = <&gpio>; + }; + }; +...MAINTAINERS +0
-0@@ -1015,6 +1015,7 @@ W: http://ez.analog.com/community/linux-device-drivers
Quoted 10 lines
MAINTAINERS +1
-1S: Supported F: drivers/iio/imu/adis16475.c F: Documentation/ABI/testing/sysfs-bus-iio-imu-adis16475 +F: Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml ANALOG DEVICES INC ADM1177 DRIVER M: Beniamin Bia <[email protected]> --2.25.1