Support ADIS16475 and similar IMUs
Subsystems (5)
Nuno Sá
maintainerv3 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: Support different burst sizes
iio: imu: Add support for adis16475
dt-bindings: iio: Add adis16475 documentation
.../bindings/iio/imu/adi,adis16475.yaml | 137 ++ MAINTAINERS | 9 + drivers/iio/imu/Kconfig | 13 + drivers/iio/imu/Makefile | 1 + drivers/iio/imu/adis.c | 26 + drivers/iio/imu/adis16400.c | 2 +- drivers/iio/imu/adis16475.c | 1344 +++++++++++++++++ drivers/iio/imu/adis_buffer.c | 58 +- drivers/iio/imu/adis_trigger.c | 65 +- include/linux/iio/imu/adis.h | 87 +- 10 files changed, 1731 insertions(+), 11 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml create mode 100644 drivers/iio/imu/adis16475.c
Signature · 1 line
2.17.1
Nuno Sá
maintainerPATCH v3 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.
Changes in V3:
* Removed unnecessary inline;
* Free buffer resources.
drivers/iio/imu/adis_buffer.c | 45 ++++++++++++++++++++++++++++++++++ drivers/iio/imu/adis_trigger.c | 41 ++++++++++++++++++++++++++++--- include/linux/iio/imu/adis.h | 17 +++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_buffer.c +45 -0
@@ -156,6 +156,14 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)return IRQ_HANDLED ; } +static void adis_buffer_cleanup (void *arg) +{ +struct adis *adis = arg; + +kfree (adis->buffer); +kfree (adis->xfer); +} +/** * adis_setup_buffer_and_trigger() - Sets up buffer and trigger for the adis device * @adis: The adis device.
@@ -198,6 +206,43 @@ 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 devm_add_action_or_reset (&adis->spi->dev, adis_buffer_cleanup, + adis); +} +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.17.1
Jonathan Cameron
maintainerRe: [PATCH v3 1/6] iio: imu: adis: Add Managed device functions
Quoted 8 lines · On Tue, 31 Mar 2020 13:48:06 +0200 Nuno Sá <[email protected]> wrote:
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 aremove()callback for every driver using the adis library.Signed-off-by Nuno Sá <[email protected]>
Random thought inline. Something we could use more in IIO :)
Quoted 40 lines
---
Changes in v2:
* Added blank lines for readability.Changes in V3:
* Removed unnecessary inline;
* Free buffer resources.drivers/iio/imu/adis_buffer.c | 45 ++++++++++++++++++++++++++++++++++ drivers/iio/imu/adis_trigger.c | 41 ++++++++++++++++++++++++++++--- include/linux/iio/imu/adis.h | 17 +++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-)drivers/iio/imu/adis_buffer.c +12
-0@@ -156,6 +156,14 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)return IRQ_HANDLED ; } +static void adis_buffer_cleanup (void *arg) +{ +struct adis *adis = arg; + +kfree (adis->buffer); +kfree (adis->xfer); +} +/** * adis_setup_buffer_and_trigger() - Sets up buffer and trigger for the adis device * @adis: The adis device. @@ -198,6 +206,43 @@ 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
drivers/iio/imu/adis_buffer.c int adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev, · line 222
Quoted 10 lines
drivers/iio/imu/adis_buffer.c +10
-0+* @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 *))
It occurred to me that there must be a lot of irq handling function pointers in the kernel and it would be odd if there wasn't a type for this...
There is :) irq_handler_t
https://elixir.bootlin.com/linux/latest/source/include/linux/interrupt.h#L92
Not sure why I never noticed that before. Hohum.
Jonathan
Quoted 139 lines
drivers/iio/imu/adis_buffer.c +23
-0+{ +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 devm_add_action_or_reset (&adis->spi->dev, adis_buffer_cleanup, + adis); +} +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@@ -27,6 +27,13 @@ static const struct iio_trigger_ops adis_trigger_ops = { .set_trigger_state = &adis_data_rdy_trigger_set_state, }; +static void adis_trigger_setup (struct adis *adis) +{ + 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); +/** +* devm_adis_probe_trigger() - Sets up trigger for a managed adis device +* @adis: The adis device +* @indio_dev: The IIO device +* +* Returns 0 on success or a negative error code +*/ +int devm_adis_probe_trigger (struct adis *adis,struct iio_dev *indio_dev) +{ +int ret; + + adis->trig =devm_iio_trigger_alloc (&adis->spi->dev,"%s-dev%d" , + indio_dev->name, indio_dev->id); +if (!adis->trig) +return -ENOMEM ; + +adis_trigger_setup (adis); + + ret =devm_request_irq (&adis->spi->dev, adis->spi->irq, + &iio_trigger_generic_data_rdy_poll, +IRQF_TRIGGER_RISING , + indio_dev->name, + adis->trig); +if (ret) +return ret; + +return devm_iio_trigger_register (&adis->spi->dev, adis->trig); +} +EXPORT_SYMBOL_GPL (devm_adis_probe_trigger); +/** * adis_remove_trigger() - Remove trigger for a adis devices * @adis: The adis device 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) {
Nuno Sá
maintainerPATCH v3 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.
Changes in v3:
* Removed unnecessary inline;
* Renamed __adis_validate_irq_mask to adis_validate_irq_mask to keep lib consistency;
* Cosmetics in logs.
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 void adis_trigger_setup(struct adis *adis)iio_trigger_set_drvdata (adis->trig, adis); } +static 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.17.1
Re: [PATCH v3 2/6] iio: imu: adis: Add irq mask variable
Quoted 4 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.
...
drivers/iio/imu/adis_trigger.c static void adis_trigger_setup(struct adis *adis) · line 42
Quoted 7 lines
drivers/iio/imu/adis_trigger.c +6
-0+static 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 &&
'else' is redundant.
Quoted 1 line
+
adis->irq_mask!=IRQF_TRIGGER_FALLING) {
But this condition rises questions. Why i can't configure both? Why I can't configure other flags there?
drivers/iio/imu/adis_trigger.c static void adis_trigger_setup(struct adis *adis) · line 50
Quoted 7 lines
drivers/iio/imu/adis_trigger.c +6
-0+dev_err (&adis->spi->dev,"Invalid IRQ mask: %08lx\n" , + adis->irq_mask); +return -EINVAL ; + } +return 0 ; +}
And actually name of the function is not exactly what it does. It validates *or* initializes.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 2/6] iio: imu: adis: Add irq mask variable
Quoted 30 lines
From: [email protected] <[email protected]> On Behalf Of Andy Shevchenko
Sent: Dienstag, 31. März 2020 19:40
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 2/6] iio: imu: adis: Add irq mask variable[External]
Quoted 3 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_RISINGQuoted 1 line
since we might want to have it as
IRQF_TRIGGER_FALLING....
Quoted 5 lines
drivers/iio/imu/adis_trigger.c +5
-0+static int adis_validate_irq_mask (struct adis *adis) +{ +if (!adis->irq_mask) { + adis->irq_mask =IRQF_TRIGGER_RISING ; +return 0 ;
Quoted 8 lines
Quoted 1 line
+ } else if (
adis->irq_mask!=IRQF_TRIGGER_RISING&&'else' is redundant.
Quoted 1 line
+
adis->irq_mask!=IRQF_TRIGGER_FALLING) {But this condition rises questions. Why i can't configure both? Why I can't configure other flags there?
Both you can't because it is just how these type of devices work. Data is ready either on the rising edge or on the falling edge (if supported by the device)...
I agree this could check if only one of the flags are set instead of directly comparing the values (invalidating other flags) but I would prefer to keep this simple for now...
Quoted 11 lines
drivers/iio/imu/adis_trigger.c static void adis_trigger_setup(struct adis *adis) · line 50
Quoted 8 lines
drivers/iio/imu/adis_trigger.c +6
-0+dev_err (&adis->spi->dev,"Invalid IRQ mask: %08lx\n" , + adis->irq_mask); +return -EINVAL ; + } +return 0 ; +}And actually name of the function is not exactly what it does. It validates *or* initializes.
Well, yes. It just sets the mask to the default value to keep backward compatibility with all the other devices that don't support/use this variable...
- Nuno Sá
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 2/6] iio: imu: adis: Add irq mask variable
Quoted 9 lines · Nuno
Quoted 9 lines
From: [email protected] <[email protected]> On Behalf Of Andy Shevchenko
Sent: Dienstag, 31. März 2020 19:40Quoted 3 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_RISINGQuoted 1 line
since we might want to have it as
IRQF_TRIGGER_FALLING.
...
Quoted 26 lines
Quoted 6 lines
Quoted 5 lines
drivers/iio/imu/adis_trigger.c +5
-0+static int adis_validate_irq_mask (struct adis *adis) +{ +if (!adis->irq_mask) { + adis->irq_mask =IRQF_TRIGGER_RISING ; +return 0 ;Quoted 8 lines
Quoted 1 line
+ } else if (
adis->irq_mask!=IRQF_TRIGGER_RISING&&'else' is redundant.
Quoted 1 line
+
adis->irq_mask!=IRQF_TRIGGER_FALLING) {But this condition rises questions. Why i can't configure both? Why I can't configure other flags there?
Both you can't because it is just how these type of devices work. Data is ready either on the rising edge or on the falling edge (if supported by the device)...
I agree this could check if only one of the flags are set instead of directly comparing the values (invalidating other flags) but I would prefer to keep this simple for now...Quoted 6 lines
Quoted 5 lines
drivers/iio/imu/adis_trigger.c +4
-0+dev_err (&adis->spi->dev,"Invalid IRQ mask: %08lx\n" , + adis->irq_mask); +return -EINVAL ; + }
Quoted 8 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}And actually name of the function is not exactly what it does. It validates *or* initializes.
Well, yes. It just sets the mask to the default value to keep backward compatibility with all the other devices that don't support/use this variable...
Perhaps documentation in a comment form should be added. Moreover, I realized that you added to variable and function mask suffix while it's actually flag.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 2/6] iio: imu: adis: Add irq mask variable
Quoted 61 lines
From: Andy Shevchenko <[email protected]>
Sent: Mittwoch, 1. April 2020 12:27
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 2/6] iio: imu: adis: Add irq mask variableQuoted 1 line · Nuno
Quoted 1 line
From: [email protected] <[email protected]>
On
Quoted 8 lines
Quoted 8 lines
Behalf Of Andy Shevchenko
Sent: Dienstag, 31. März 2020 19:40Quoted 3 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_RISINGQuoted 1 line
since we might want to have it as
IRQF_TRIGGER_FALLING....
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/iio/imu/adis_trigger.c +6
-0+static 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 &&Quoted 8 lines
Quoted 6 lines
'else' is redundant.
Quoted 1 line
+
adis->irq_mask!=IRQF_TRIGGER_FALLING) {But this condition rises questions. Why i can't configure both? Why I can't configure other flags there?
Both you can't because it is just how these type of devices work. Data is
ready either
Quoted 2 lines
on the rising edge or on the falling edge (if supported by the device)... I agree this could check if only one of the flags are set instead of directly
comparing the
Quoted 1 line
values (invalidating other flags) but I would prefer to keep this simple for
now...
Quoted 13 lines
Quoted 12 lines
drivers/iio/imu/adis_trigger.c static void adis_trigger_setup(struct adis *adis) · line 50
Quoted 9 lines
drivers/iio/imu/adis_trigger.c +6
-0+dev_err (&adis->spi->dev,"Invalid IRQ mask: %08lx\n" , + adis->irq_mask); +return -EINVAL ; + } +return 0 ; +}And actually name of the function is not exactly what it does. It validates *or* initializes.
Quoted 7 lines
Quoted 1 line
Well, yes. It just sets the mask to the default value to keep backward
compatibility
Quoted 1 line
with all the other devices that don't support/use this variable...
Perhaps documentation in a comment form should be added. Moreover, I realized that you added to variable and function mask suffix while it's actually flag.
Will change the suffix to flag...
- Nuno Sá
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Nuno Sá
maintainerPATCH v3 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.
Changes in V3:
* Nothing changed.
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.17.1
Re: [PATCH v3 3/6] iio: adis: Add adis_update_bits() APIs
drivers/iio/imu/adis.c int __adis_read_reg(struct adis *adis, unsigned int reg, · line 247
Quoted 6 lines · Nuno Sá
This patch adds a
regmap_update_bits()like API to the ADIS library. It provides locked and unlocked variant.drivers/iio/imu/adis.c +2
-0+ __val &= ~mask; + __val |= val & mask;
You can use standard one liner, i.e.
__val = (__val & ~mask) | (val & mask);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 3/6] iio: adis: Add adis_update_bits() APIs
Quoted 19 lines
From: Andy Shevchenko <[email protected]>
Sent: Dienstag, 31. März 2020 19:42
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 3/6] iio: adis: Addadis_update_bits()APIs[External]
Quoted 3 lines · Nuno Sá
This patch adds a
regmap_update_bits()like API to the ADIS library. It provides locked and unlocked variant.
Quoted 6 lines
drivers/iio/imu/adis.c int __adis_read_reg(struct adis *adis, unsigned int reg, · line 247
Quoted 2 lines
drivers/iio/imu/adis.c +2
-0+ __val &= ~mask; + __val |= val & mask;You can use standard one liner, i.e.
__val = (__val & ~mask) | (val & mask);
Sure. Can do that...
- Nuno Sá
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Nuno Sá
maintainerPATCH v3 4/6 iio: adis: Support different burst sizes
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.
Moreover, extra_len in adis_burst is made const and it should contain the smallest extra length necessary for a burst transfer. In struct adis was added a new burst_extra_len that should hold the extra bytes needed depending on the device instance being used.
---
Changes in v2:
* Nothing changed.
Changes in v3:
* Reworked commit message;
* Made extra_len const;
* Added burst_extra_len to struct adis;
* Changed adis16400 accordingly.
drivers/iio/imu/adis16400.c | 2 +- drivers/iio/imu/adis_buffer.c | 13 +++++++++---- include/linux/iio/imu/adis.h | 9 +++++++-- 3 files changed, 17 insertions(+), 7 deletions(-)
drivers/iio/imu/adis16400.c +1 -1
@@ -1194,7 +1194,7 @@ static int adis16400_probe(struct spi_device *spi) indio_dev->available_scan_masks = st->avail_scan_mask; st->adis.burst = &adis16400_burst;if (st->variant->flags &ADIS16400_BURST_DIAG_STAT ) - st->adis.burst->extra_len =sizeof (u16); + st->adis.burst_extra_len =sizeof (u16); } adis16400_data = &st->variant->adis_data;
drivers/iio/imu/adis_buffer.c +9 -4
@@ -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; + burst_length += adis->burst->extra_len + 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 +7 -2
@@ -83,6 +83,8 @@ struct adis_data {* @trig: IIO trigger object data * @data: ADIS chip variant specific data * @burst: ADIS burst transfer information +* @burst_extra_len: Burst extra length. Should only be used by devices that can +* dynamically change their burst mode length. * @state_lock: Lock used by the device to protect state * @msg: SPI message object * @xfer: SPI transfer objects to be used for a @msg
@@ -98,7 +100,7 @@ struct adis {const struct adis_data *data;struct adis_burst *burst; - +unsigned int burst_extra_len;/** * The state_lock is meant to be used during operations that require * a sequence of SPI R/W in order to protect the SPI transfer
@@ -502,11 +504,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 extra_len; +const u32 burst_max_len; };int
Signature · 1 line
2.17.1
Nuno Sá
maintainerPATCH v3 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.
Changes in V3:
* Fix multiple instance devices for different burst sizes;
* Only return error if freq is 0 on `adis16475_set_freq``;
* Fixed typo in comment;
* Do not allow 7 to be set in adis16475_set_filter;
* Change adis16475_validate_crc return type to bool;
* Return 1 if crc is valid instead of 0.
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
@@ -1009,6 +1009,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.17.1
Re: [PATCH v3 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.
...
MAINTAINERS W: http://ez.analog.com/community/linux-device-drivers · line 1018
Quoted 7 lines
MAINTAINERS +7
-0+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
Run parse-maintainers.pl to fix this.
...
Quoted 1 line
+#include <
asm/unaligned.h>
Usually it goes after linux/*
drivers/iio/imu/adis16475.c line 14
Quoted 8 lines
drivers/iio/imu/adis16475.c new file +7
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/kernel.h>
What this is for?
drivers/iio/imu/adis16475.c line 22
Quoted 9 lines
drivers/iio/imu/adis16475.c new file +8
-0+#include <linux/iio/buffer.h> +#include <linux/iio/iio.h> +#include <linux/iio/imu/adis.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/of_device.h>
Do you really need this? Perhaps mod_devicetable.h is what you are looking for.
Quoted 1 line
+#include <
linux/spi/spi.h>
...
drivers/iio/imu/adis16475.c line 191
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +3
-0+#ifdef CONFIG_DEBUG_FS +DEFINE_SIMPLE_ATTRIBUTE (adis16475_serial_number_fops, + adis16475_show_serial_number,NULL ,"0x%.4llx\n" );
DEBUGFS ATTRIBUTE?
drivers/iio/imu/adis16475.c line 226
Quoted 5 lines
drivers/iio/imu/adis16475.c new file +4
-0+DEFINE_SIMPLE_ATTRIBUTE (adis16475_product_id_fops, + adis16475_show_product_id,NULL ,"%llu\n" ); +DEFINE_SIMPLE_ATTRIBUTE (adis16475_flash_count_fops, + adis16475_show_flash_count,NULL ,"%lld\n" );
Ditto.
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +6
-0+#else +static int adis16475_debugfs_init (struct iio_dev *indio_dev) +{ +return 0 ; +} +#endif
...
drivers/iio/imu/adis16475.c line 293
Quoted 8 lines
drivers/iio/imu/adis16475.c new file +8
-0+/* +* If decimation is used, then gyro and accel data will have meaningful +* 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);
assign_bit()
Also to the rest of same
...
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {
Why those margins? size-2 and 1 ?
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }
...
drivers/iio/imu/adis16475.c line 460
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +4
-0+#define ADIS16475_GYRO_CHANNEL (_mod) \ + ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \ + ADIS16475_REG_ ## _mod ## _GYRO_L, ADIS16475_SCAN_GYRO_ ## _mod, 32, \ + 32)
It's not obvious that this is macro inside macro. Can you indent better? Ditto for the rest similar ones.
...
drivers/iio/imu/adis16475.c line 552
Quoted 13 lines
drivers/iio/imu/adis16475.c new file +13
-0+static int adis16475_enable_irq (struct adis *adis,bool enable) +{ +/* +* There is no way to gate the data-ready signal internally inside the +* ADIS16475. We can only control it's polarity... +*/ +if (enable) +enable_irq (adis->spi->irq); +else +disable_irq (adis->spi->irq); + +return 0 ; +}
It's seems this function is bigger than in-place calls for enable or disable IRQ.
...
Quoted 1 line
+ return (crc == 0);
Too many parentheses.
...
drivers/iio/imu/adis16475.c line 962
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+ ret =__adis_update_bits (&st->adis,ADIS16475_REG_MSG_CTRL , +ADIS16500_BURST32_MASK , en); +if (ret <0 )
ret > 0 has any meaning? Maybe drop all these ' < 0' parts from the code (where it's appropriate)?
Quoted 1 line
+ return;
...
Quoted 1 line
+ buffer = (u16 *)adis->buffer;
Why the casting is needed?
Quoted 1 line
+ crc =
get_unaligned_be16(&buffer[offset + 2]);
If your buffer is aligned in the structure, you may simple use be16_to_cpu(). Same for the rest of get_unaligned*() calls.
Or do you have unaligned data there?
Quoted 1 line
+ valid =
adis16475_validate_crc((u8 *)adis->buffer, crc, st->burst32);
Why casting?
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +4
-0+if (!valid) { +dev_err (&adis->spi->dev,"Invalid crc\n" ); + goto check_burst32; + }
...
Quoted 1 line
+ /* keep sparse happy */
Perhaps buffer should be declared as __be16.
Quoted 1 line
+ data[i++] = (
__forceu16)__val;
...
drivers/iio/imu/adis16475.c line 1199
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +5
-0+ desc =irq_get_irq_data (spi->irq); +if (!desc) { +dev_err (&spi->dev,"Could not find IRQ %d\n" , spi->irq); +return -EINVAL ; + }
Is this even possible?
...
drivers/iio/imu/adis16475.c line 1272
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+ { .compatible = "adi,adis16507-3", + .data = &adis16475_chip_info[ADIS16507_3] }, + { },
Comma is not needed.
...
Quoted 1 line
+
st->info=of_device_get_match_data(&spi->dev);
device_get_match_data()
Quoted 2 lines
drivers/iio/imu/adis16475.c new file +2
-0+if (!st->info) +return -EINVAL ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 5/6] iio: imu: Add support for adis16475
Quoted 28 lines
From: Andy Shevchenko <[email protected]>
Sent: Dienstag, 31. März 2020 20:16
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 5/6] iio: imu: Add support for adis16475[External]
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....
Quoted 10 lines
MAINTAINERS W: http://ez.analog.com/community/linux-device-drivers · line 1018
Quoted 7 lines
MAINTAINERS +7
-0+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-adis16475Run parse-maintainers.pl to fix this.
Ups. Leftover from v1. Thanks!
Quoted 4 lines
...
Quoted 1 line
+#include <
asm/unaligned.h>
I thought we wanted alphabetic order...
Quoted 9 lines
Usually it goes after linux/*
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +6
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h>
Quoted 4 lines
Quoted 1 line
+#include <
linux/kernel.h>What this is for?
Yeps. Not really needed...
Quoted 8 lines
Quoted 7 lines
drivers/iio/imu/adis16475.c new file +7
-0+#include <linux/iio/buffer.h> +#include <linux/iio/iio.h> +#include <linux/iio/imu/adis.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/irq.h> +#include <linux/module.h>
Quoted 5 lines
Quoted 1 line
+#include <
linux/of_device.h>Do you really need this? Perhaps
mod_devicetable.his what you are looking for.
Yes. For ` of_device_get_match_data ``. If changed by device_get_match_data, then I guess I can drop it..
Quoted 37 lines
Quoted 1 line
+#include <
linux/spi/spi.h>...
drivers/iio/imu/adis16475.c line 191
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +3
-0+#ifdef CONFIG_DEBUG_FS +DEFINE_SIMPLE_ATTRIBUTE (adis16475_serial_number_fops, + adis16475_show_serial_number,NULL ,"0x%.4llx\n" );DEBUGFS ATTRIBUTE?
drivers/iio/imu/adis16475.c line 226
Quoted 5 lines
drivers/iio/imu/adis16475.c new file +4
-0+DEFINE_SIMPLE_ATTRIBUTE (adis16475_product_id_fops, + adis16475_show_product_id,NULL ,"%llu\n" ); +DEFINE_SIMPLE_ATTRIBUTE (adis16475_flash_count_fops, + adis16475_show_flash_count,NULL ,"%lld\n" );Ditto.
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +6
-0+#else +static int adis16475_debugfs_init (struct iio_dev *indio_dev) +{ +return 0 ; +} +#endif ...
drivers/iio/imu/adis16475.c line 293
Quoted 8 lines
drivers/iio/imu/adis16475.c new file +8
-0+/* +* If decimation is used, then gyro and accel data will have meaningful +* 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);
Quoted 2 lines
assign_bit()
Will do that...
Quoted 8 lines
Also to the rest of same
...
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {Why those margins? size-2 and 1 ?
The -2 is needed since index 7 is not valid. The 1 I honestly don't remember why I did it like this. Using > 0 is the same and more "common"...
Quoted 6 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }...
Quoted 9 lines
drivers/iio/imu/adis16475.c
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+#define ADIS16475_GYRO_CHANNEL (_mod) \ + ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \ + ADIS16475_REG_ ## _mod ## _GYRO_L, ADIS16475_SCAN_GYRO_ ##
_mod, 32, \Quoted 1 line
+ 32)
It's not obvious that this is macro inside macro. Can you indent better? Ditto for the rest similar ones.
Honestly here I don't see any problems with indentation and it goes in conformity with other IMU drivers already in tree. So here, as long as anyone else has a problem with this, I prefer to keep it this way...
Quoted 19 lines
...
drivers/iio/imu/adis16475.c line 552
Quoted 13 lines
drivers/iio/imu/adis16475.c new file +13
-0+static int adis16475_enable_irq (struct adis *adis,bool enable) +{ +/* +* There is no way to gate the data-ready signal internally inside the +* ADIS16475. We can only control it's polarity... +*/ +if (enable) +enable_irq (adis->spi->irq); +else +disable_irq (adis->spi->irq); + +return 0 ; +}It's seems this function is bigger than in-place calls for enable or disable IRQ.
This api is callbacked from the ADIS library...
Quoted 21 lines
...
Quoted 1 line
+ return (crc == 0);
Too many parentheses.
...
drivers/iio/imu/adis16475.c line 962
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+ ret =__adis_update_bits (&st->adis,ADIS16475_REG_MSG_CTRL , +ADIS16500_BURST32_MASK , en); +if (ret <0 )ret > 0 has any meaning? Maybe drop all these ' < 0' parts from the code (where it's appropriate)?
Quoted 1 line
+ return;
...
Quoted 1 line
+ buffer = (u16 *)adis->buffer;
Quoted 7 lines
Why the casting is needed?
Quoted 1 line
+ crc =
get_unaligned_be16(&buffer[offset + 2]);If your buffer is aligned in the structure, you may simple use
be16_to_cpu(). Same for the rest of get_unaligned*() calls.
Or do you have unaligned data there?
This is a nice point. So, honestly I made it like this to keep conformity with other drivers we have in our internal tree (in queue for upstream) and I also wondered about this. The only justification I can find to use unligned calls is to keep this independent from the ADIS lib (not sure if it makes sense) since we get the pointer from the library (allocated there).
Now, if Im not missing nothing obvious we can access the buffer normally since it's being allocated with kmalloc which means we have ARCH_KMALLOC_MINALIGN (which is at least 8 if Im not mistaken). On top of this, the device sends the data as n 16 bits segments. So in theory, I guess we can ditch the overhead of the *unaligned calls if any objections?
Quoted 4 lines
Quoted 1 line
+ valid =
adis16475_validate_crc((u8 *)adis->buffer, crc, st->burst32);Why casting?
Not really needed...
Quoted 11 lines
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +4
-0+if (!valid) { +dev_err (&adis->spi->dev,"Invalid crc\n" ); + goto check_burst32; + }...
Quoted 1 line
+ /* keep sparse happy */
Perhaps buffer should be declared as
__be16.
Will do it if removing the *unaligned calls...
Quoted 5 lines
Quoted 1 line
+ data[i++] = (
__forceu16)__val;...
Quoted 9 lines
drivers/iio/imu/adis16475.c line 1199
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +5
-0+ desc =irq_get_irq_data (spi->irq); +if (!desc) { +dev_err (&spi->dev,"Could not find IRQ %d\n" , spi->irq); +return -EINVAL ; + }Is this even possible?
I guess. If someone does not include it in device tree...
Quoted 8 lines
...
drivers/iio/imu/adis16475.c line 1272
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+ { .compatible = "adi,adis16507-3", + .data = &adis16475_chip_info[ADIS16507_3] }, + { },Comma is not needed.
Will remove it
Quoted 5 lines
...
Quoted 1 line
+
st->info=of_device_get_match_data(&spi->dev);
device_get_match_data()
Will use it...
Quoted 4 lines
drivers/iio/imu/adis16475.c line 1292
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +2
-0+if (!st->info) +return -EINVAL ;
Thanks for the review
- Nuno Sá
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 5/6] iio: imu: Add support for adis16475
Quoted 13 lines · Nuno
Quoted 13 lines
From: Andy Shevchenko <[email protected]>
Sent: Dienstag, 31. März 2020 20:16
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 5/6] iio: imu: Add support for adis16475 On Tue, Mar 31, 2020 at 2:49 PM Nuno Sá <[email protected]> wrote:
...
Quoted 3 lines
Quoted 1 line
Quoted 1 line
+#include <
asm/unaligned.h>I thought we wanted alphabetic order...
Yes, but from more generic header groups to less generic. Inside each group is alphabetical.
asm/ is less generic than linux/.
Quoted 9 lines
Quoted 9 lines
Usually it goes after linux/*
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +6
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h>
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+#include <
linux/kernel.h>What this is for?
Yeps. Not really needed...
I think you needed it for DIV_ROUND_UP or alike macros. It also has container_of...
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/iio/imu/adis16475.c new file +7
-0+#include <linux/iio/buffer.h> +#include <linux/iio/iio.h> +#include <linux/iio/imu/adis.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/irq.h> +#include <linux/module.h>
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
+#include <
linux/of_device.h>Do you really need this? Perhaps
mod_devicetable.his what you are looking for.Yes. For `
of_device_get_match_data``. If changed bydevice_get_match_data, then I guess I can drop it..
Probably change to mod_devicetable.h with property.h.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+#include <
linux/spi/spi.h>
...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {Why those margins? size-2 and 1 ?
The -2 is needed since index 7 is not valid. The 1 I honestly don't remember why I did it like this. Using > 0 is the same and more "common"...
More common is >= 0. That's my question basically. And if 7 is not valid why to keep it in the array at all?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }
...
Quoted 6 lines
Quoted 6 lines
drivers/iio/imu/adis16475.c
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+#define ADIS16475_GYRO_CHANNEL (_mod) \ + ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \ + ADIS16475_REG_ ## _mod ## _GYRO_L, ADIS16475_SCAN_GYRO_ ##
_mod, 32, \Quoted 1 line
+ 32)
Quoted 7 lines
Quoted 3 lines
It's not obvious that this is macro inside macro. Can you indent better? Ditto for the rest similar ones.
Honestly here I don't see any problems with indentation and it goes in conformity with other IMU drivers already in tree. So here, as long as anyone else has a problem with this, I prefer to keep it this way...
I'm not a maintainer, not my call :-)
...
Quoted 15 lines
Quoted 9 lines
Quoted 1 line
+ buffer = (u16 *)adis->buffer;
Why the casting is needed?
Quoted 1 line
+ crc =
get_unaligned_be16(&buffer[offset + 2]);If your buffer is aligned in the structure, you may simple use
be16_to_cpu(). Same for the rest of get_unaligned*() calls.
Or do you have unaligned data there?This is a nice point. So, honestly I made it like this to keep conformity with other drivers we have in our internal tree (in queue for upstream) and I also wondered about this. The only justification I can find to use unligned calls is to keep this independent from the ADIS lib (not sure if it makes sense) since we get the pointer from the library (allocated there).
Quoted 4 lines
Now, if Im not missing nothing obvious we can access the buffer normally since it's being allocated with kmalloc which means we have
ARCH_KMALLOC_MINALIGN(which is at least 8 if Im not mistaken). On top of this, the device sends the data as n 16 bits segments. So in theory, I guess we can ditch the overhead of the *unaligned calls if any objections?
No objections from my side at least.
...
Quoted 10 lines
Quoted 8 lines
drivers/iio/imu/adis16475.c line 1199
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +5
-0+ desc =irq_get_irq_data (spi->irq); +if (!desc) { +dev_err (&spi->dev,"Could not find IRQ %d\n" , spi->irq); +return -EINVAL ; + }Is this even possible?
I guess. If someone does not include it in device tree...
Hmm... and this function will be called anyway?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 5/6] iio: imu: Add support for adis16475
Quoted 32 lines
From: [email protected] <[email protected]> On Behalf Of Andy Shevchenko
Sent: Mittwoch, 1. April 2020 12:23
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 5/6] iio: imu: Add support for adis16475Quoted 7 lines · Nuno
Quoted 7 lines
From: Andy Shevchenko <[email protected]>
Sent: Dienstag, 31. März 2020 20:16
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter ClausenQuoted 2 lines
Quoted 2 lines
Peter Meerwald-Stadler <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>;
Ardelean,
Quoted 4 lines
Quoted 4 lines
Alexandru <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v3 5/6] iio: imu: Add support for adis16475 On Tue, Mar 31, 2020 at 2:49 PM Nuno Sá <[email protected]> wrote:...
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
+#include <
asm/unaligned.h>I thought we wanted alphabetic order...
Yes, but from more generic header groups to less generic. Inside each group is alphabetical.
asm/ is less generic than linux/.
Got it...
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Usually it goes after linux/*
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +6
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h>
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+#include <
linux/kernel.h>What this is for?
Yeps. Not really needed...
I think you needed it for
DIV_ROUND_UPor alike macros. It also hascontainer_of...
Yes, DIV_ROUND_CLOSEST is defined there...
Quoted 30 lines
Quoted 11 lines
Quoted 11 lines
drivers/iio/imu/adis16475.c line 22
Quoted 9 lines
drivers/iio/imu/adis16475.c new file +8
-0+#include <linux/iio/buffer.h> +#include <linux/iio/iio.h> +#include <linux/iio/imu/adis.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/of_device.h> Do you really need this? Perhaps
mod_devicetable.his what you arelooking
Quoted 4 lines
Quoted 2 lines
for.
Yes. For `
of_device_get_match_data``. If changed by
device_get_match_data, then I guessQuoted 1 line
I can drop it..
Probably change to
mod_devicetable.hwithproperty.h.Quoted 1 line
Quoted 1 line
Quoted 1 line
+#include <
linux/spi/spi.h>...
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {Why those margins? size-2 and 1 ?
Quoted 6 lines
Quoted 1 line
The -2 is needed since index 7 is not valid. The 1 I honestly don't remember
why I did it
Quoted 1 line
like this. Using > 0 is the same and more "common"...
More common is >= 0. That's my question basically. And if 7 is not valid why to keep it in the array at all?
Well, I can remove the 7. I honestly took it from another driver and I guess the idea is to make explicit that 7 is not supported. Since this is a 3 bit field and the datasheet does not state this directly.
As for the >=0, I prefer to have either as is or >0 since we don't really need to check the index 0. If 1 fails, then we will use 0 either way...
Quoted 47 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }...
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+#define ADIS16475_GYRO_CHANNEL (_mod) \ + ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \ + ADIS16475_REG_ ## _mod ## _GYRO_L, ADIS16475_SCAN_GYRO_##
Quoted 8 lines
Quoted 6 lines
_mod, 32, \Quoted 1 line
+ 32)
It's not obvious that this is macro inside macro. Can you indent better? Ditto for the rest similar ones.
Honestly here I don't see any problems with indentation and it goes in
conformity with
Quoted 1 line
other IMU drivers already in tree. So here, as long as anyone else has a
problem with this, I prefer
Quoted 1 line
to keep it this way...
I'm not a maintainer, not my call :-)
...
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
+ buffer = (u16 *)adis->buffer;
Why the casting is needed?
Quoted 1 line
+ crc =
get_unaligned_be16(&buffer[offset + 2]);If your buffer is aligned in the structure, you may simple use
be16_to_cpu().Quoted 4 lines
Quoted 2 lines
Same for the rest of get_unaligned*() calls.
Or do you have unaligned data there?This is a nice point. So, honestly I made it like this to keep conformity with
other drivers we have
Quoted 1 line
in our internal tree (in queue for upstream) and I also wondered about this.
The only justification I can
Quoted 1 line
find to use unligned calls is to keep this independent from the ADIS lib (not
sure if it makes sense) since
Quoted 3 lines
we get the pointer from the library (allocated there).
Now, if Im not missing nothing obvious we can access the buffer normally
Quoted 9 lines
since it's being allocated
Quoted 1 line
with kmalloc which means we have
ARCH_KMALLOC_MINALIGN(which isat least 8 if Im not mistaken).
Quoted 1 line
On top of this, the device sends the data as n 16 bits segments. So in theory,
I guess we can ditch the
Quoted 1 line
overhead of the *unaligned calls if any objections?
No objections from my side at least.
I will wait to see if someone else has anything to add and if not, I will change it to normal buffer accesses (probably using restricted types).
Quoted 9 lines
...
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +5
-0+ desc =irq_get_irq_data (spi->irq); +if (!desc) { +dev_err (&spi->dev,"Could not find IRQ %d\n" , spi->irq); +return -EINVAL ; + }
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Is this even possible?
I guess. If someone does not include it in device tree...
Hmm... and this function will be called anyway?
Yes, it is called on probe... And we should fail if no interrupt is given in device tree. It’s a required property.
- Nuno Sá
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 5/6] iio: imu: Add support for adis16475
Quoted 2 lines · Nuno
Quoted 2 lines · Nuno
Quoted 1 line
Quoted 1 line · Nuno Sá
...
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {Why those margins? size-2 and 1 ?
The -2 is needed since index 7 is not valid. The 1 I honestly don't remember
why I did it
Quoted 1 line
like this. Using > 0 is the same and more "common"...
More common is >= 0. That's my question basically. And if 7 is not valid why to keep it in the array at all?
Quoted 6 lines
Well, I can remove the 7. I honestly took it from another driver and I guess the idea is to make explicit that 7 is not supported. Since this is a 3 bit field and the datasheet does not state this directly.
As for the >=0, I prefer to have either as is or >0 since we don't really need to check the index 0. If 1 fails, then we will use 0 either way...
It makes sense to check to get better optimization (and increased readability). Look for this
i = ARRAY_SIZE(...);
while (i--) {
...
}
It's much better to read and understand.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sa, Nuno
maintainerRE: [PATCH v3 5/6] iio: imu: Add support for adis16475
Quoted 46 lines
From: Andy Shevchenko <[email protected]>
Sent: Mittwoch, 1. April 2020 16:06
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 5/6] iio: imu: Add support for adis16475Quoted 1 line · Nuno
Quoted 1 line
On Wed, Apr 1, 2020 at 10:13 AM Sa, Nuno <[email protected]>
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Tue, Mar 31, 2020 at 2:49 PM Nuno Sá <[email protected]>
wrote:
...
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {Why those margins? size-2 and 1 ?
The -2 is needed since index 7 is not valid. The 1 I honestly don't
remember
Quoted 7 lines
Quoted 5 lines
why I did it
Quoted 1 line
like this. Using > 0 is the same and more "common"...
More common is >= 0. That's my question basically. And if 7 is not valid why to keep it in the array at all?
Well, I can remove the 7. I honestly took it from another driver and I guess
the idea
Quoted 1 line
is to make explicit that 7 is not supported. Since this is a 3 bit field and the
datasheet
Quoted 3 lines
does not state this directly.
As for the >=0, I prefer to have either as is or >0 since we don't really need to
check the
Quoted 1 line
index 0. If 1 fails, then we will use 0 either way...
It makes sense to check to get better optimization (and increased readability). Look for this
Quoted 7 lines
i =
ARRAY_SIZE(...);while (i--) {
...
}It's much better to read and understand.
Well, about the readability it's a bit subjective 😊. It depends who is reading the code. Just curious, how would you get better optimization by doing >=0 instead of > 0?
Either way, I don’t have any strong feeling about this so I can do as you suggest.
- Nuno Sá
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c line 333
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 5/6] iio: imu: Add support for adis16475
Quoted 18 lines · Nuno
Quoted 18 lines
From: Andy Shevchenko <[email protected]>
Sent: Mittwoch, 1. April 2020 16:06
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 5/6] iio: imu: Add support for adis16475Quoted 1 line · Nuno
Quoted 1 line
On Wed, Apr 1, 2020 at 10:13 AM Sa, Nuno <[email protected]>
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Tue, Mar 31, 2020 at 2:49 PM Nuno Sá <[email protected]>
wrote:
...
Quoted 19 lines
Quoted 19 lines
Quoted 1 line
Well, I can remove the 7. I honestly took it from another driver and I guess
the idea
Quoted 1 line
is to make explicit that 7 is not supported. Since this is a 3 bit field and the
datasheet
Quoted 3 lines
does not state this directly.
As for the >=0, I prefer to have either as is or >0 since we don't really need to
check the
Quoted 1 line
index 0. If 1 fails, then we will use 0 either way...
It makes sense to check to get better optimization (and increased readability). Look for this
i =
ARRAY_SIZE(...);while (i--) {
...
}
Quoted 5 lines
Quoted 1 line
It's much better to read and understand.
Well, about the readability it's a bit subjective . It depends who is reading the code. Just curious, how would you get better optimization by doing >=0 instead of > 0?
Feel the difference while (i--) vs. while (--i > 0). The latter one is a bit unusual.
Quoted 2 lines
Either way, I don’t have any strong feeling about this so I can do as you suggest.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v3 5/6] iio: imu: Add support for adis16475
In reply to Sa, NunoQuoted 101 lines · Nuno
Quoted 32 lines
From: [email protected] <[email protected]> On Behalf Of Andy Shevchenko
Sent: Mittwoch, 1. April 2020 12:23
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[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 v3 5/6] iio: imu: Add support for adis16475Quoted 7 lines · Nuno
Quoted 7 lines
From: Andy Shevchenko <[email protected]>
Sent: Dienstag, 31. März 2020 20:16
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; devicetree <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter ClausenQuoted 2 lines
Quoted 2 lines
Peter Meerwald-Stadler <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>;
Ardelean,
Quoted 4 lines
Quoted 4 lines
Alexandru <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v3 5/6] iio: imu: Add support for adis16475 On Tue, Mar 31, 2020 at 2:49 PM Nuno Sá <[email protected]> wrote:...
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
+#include <
asm/unaligned.h>I thought we wanted alphabetic order...
Yes, but from more generic header groups to less generic. Inside each group is alphabetical.
asm/ is less generic than linux/.Got it...
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Usually it goes after linux/*
Quoted 6 lines
drivers/iio/imu/adis16475.c new file +6
-0+#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h> Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+#include <
linux/kernel.h>What this is for?
Yeps. Not really needed...
I think you needed it for
DIV_ROUND_UPor alike macros. It also hascontainer_of...Yes,
DIV_ROUND_CLOSESTis defined there...Quoted 30 lines
Quoted 11 lines
Quoted 11 lines
drivers/iio/imu/adis16475.c line 22
Quoted 9 lines
drivers/iio/imu/adis16475.c new file +8
-0+#include <linux/iio/buffer.h> +#include <linux/iio/iio.h> +#include <linux/iio/imu/adis.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/trigger_consumer.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/of_device.h> Do you really need this? Perhaps
mod_devicetable.his what you arelooking
Quoted 4 lines
Quoted 2 lines
for.
Yes. For `
of_device_get_match_data``. If changed by
device_get_match_data, then I guessQuoted 1 line
I can drop it..
Probably change to
mod_devicetable.hwithproperty.h.Quoted 1 line
Quoted 1 line
Quoted 1 line
+#include <
linux/spi/spi.h>...
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+ for (i =
ARRAY_SIZE(adis16475_3db_freqs)- 2; i >= 1; i--) {Why those margins? size-2 and 1 ?
Quoted 6 lines
Quoted 1 line
The -2 is needed since index 7 is not valid. The 1 I honestly don't remember
why I did it
Quoted 1 line
like this. Using > 0 is the same and more "common"...
More common is >= 0. That's my question basically. And if 7 is not valid why to keep it in the array at all?
Quoted 52 lines
Well, I can remove the 7. I honestly took it from another driver and I guess the idea is to make explicit that 7 is not supported. Since this is a 3 bit field and the datasheet does not state this directly.
As for the >=0, I prefer to have either as is or >0 since we don't really need to check the index 0. If 1 fails, then we will use 0 either way...
Quoted 45 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+if (adis16475_3db_freqs[i] >= filter) +break ; + }...
Quoted 3 lines
Quoted 3 lines
drivers/iio/imu/adis16475.c
Quoted 3 lines
drivers/iio/imu/adis16475.c new file +3
-0+#define ADIS16475_GYRO_CHANNEL (_mod) \ + ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \ + ADIS16475_REG_ ## _mod ## _GYRO_L, ADIS16475_SCAN_GYRO_##
Quoted 8 lines
Quoted 6 lines
_mod, 32, \Quoted 1 line
+ 32)
It's not obvious that this is macro inside macro. Can you indent better? Ditto for the rest similar ones.
Honestly here I don't see any problems with indentation and it goes in
conformity with
Quoted 1 line
other IMU drivers already in tree. So here, as long as anyone else has a
problem with this, I prefer
Quoted 1 line
to keep it this way...
I'm not a maintainer, not my call :-)
...
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
+ buffer = (u16 *)adis->buffer;
Why the casting is needed?
Quoted 1 line
+ crc =
get_unaligned_be16(&buffer[offset + 2]);If your buffer is aligned in the structure, you may simple use
be16_to_cpu().Quoted 4 lines
Quoted 2 lines
Same for the rest of get_unaligned*() calls.
Or do you have unaligned data there?This is a nice point. So, honestly I made it like this to keep conformity with
other drivers we have
Quoted 1 line
in our internal tree (in queue for upstream) and I also wondered about this.
The only justification I can
Quoted 1 line
find to use unligned calls is to keep this independent from the ADIS lib (not
sure if it makes sense) since
Quoted 1 line
we get the pointer from the library (allocated there).
It would be very odd to get a buffer from a library dealing with this sort of device that wanted at least 8 byte aligned. I guess we could add a paranoid check in the driver, but I think we can safely assume this is fine without one.
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Now, if Im not missing nothing obvious we can access the buffer normally
since it's being allocated
Quoted 1 line
with kmalloc which means we have
ARCH_KMALLOC_MINALIGN(which isat least 8 if Im not mistaken).
Quoted 1 line
On top of this, the device sends the data as n 16 bits segments. So in theory,
Quoted 9 lines
Quoted 5 lines
I guess we can ditch the
Quoted 1 line
overhead of the *unaligned calls if any objections?
No objections from my side at least.
I will wait to see if someone else has anything to add and if not, I will change it to normal buffer accesses (probably using restricted types).
If it's aligned, definitely prefer that to be explicit in the driver and use the relevant endian types.
We have had a few cases where things are oddly padded so this may be cut and paste from one of those.
Jonathan
Jonathan Cameron
maintainerRe: [PATCH v3 5/6] iio: imu: Add support for adis16475
In reply to Andy Shevchenko...
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
drivers/iio/imu/adis16475.c
Quoted 4 lines
drivers/iio/imu/adis16475.c new file +3
-0+#define ADIS16475_GYRO_CHANNEL (_mod) \ + ADIS16475_MOD_CHAN(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \ + ADIS16475_REG_ ## _mod ## _GYRO_L, ADIS16475_SCAN_GYRO_ ##
_mod, 32, \Quoted 1 line
+ 32)
It's not obvious that this is macro inside macro. Can you indent better? Ditto for the rest similar ones.
Quoted 5 lines
Quoted 3 lines
Honestly here I don't see any problems with indentation and it goes in conformity with other IMU drivers already in tree. So here, as long as anyone else has a problem with this, I prefer to keep it this way...
I'm not a maintainer, not my call :-)
I'm lazy when it comes to things like this. Yes it could be better, but it's still fairly readable so I don't really mind.
That's not to say I don't like beautiful things if you don't mind tidying it up? :)
Jonathan
Nuno Sá
maintainerPATCH v3 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.
Changes in v3:
* Make use of 'allOf' in conditionals.
.../bindings/iio/imu/adi,adis16475.yaml | 137 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 138 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +137 -0
@@ -0,0 +1,137 @@ +# 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 + +allOf: + - 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, 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
@@ -1016,6 +1016,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.17.1