iio: gyro: Add driver support for ADXRS290
Subsystems (3)
Nishant Malpani
maintainerPATCH v2 1/2 iio: gyro: Add driver support for ADXRS290
ADXRS290 is a high performance MEMS pitch and roll (dual-axis in-plane) angular rate sensor (gyroscope) designed for use in stabilization applications. It also features an internal temperature sensor and programmable high-pass and low-pass filters.
Add support for ADXRS290 in direct-access mode for now.
Datasheet:
---
Changes in v2:
- append copyright tag with author's info
- remove asm/unaligned.h header
- remove unnecessary comments about the registers' description
- rephrase comment on the usage of mutex_lock
- discard the usage of local tx, rx buffers; use DMA-safe buffers provided by the SPI core instead
- utilize spi_w8r16 provided by the SPI core instead of writing a wrapper over spi_sync_transfer which semantically does the same
- equip spi_write_then_read instead of plain spi_write since the latter requires a DMA-safe buffer
- implement exact matching of filter 3db frequencies instead of finding the "closest" match; rounding complexity is left to the userspace
- include 'info_mask_shared_by_type_available' when initialising iio_chan_spec instead of explicitly exposing attributes signifying available filter 3db frequencies; with this we can utilize read_avail core callback
--- MAINTAINERS | 6 + drivers/iio/gyro/Kconfig | 10 + drivers/iio/gyro/Makefile | 1 + drivers/iio/gyro/adxrs290.c | 444 ++++++++++++++++++++++++++++++++++++ 4 files changed, 461 insertions(+) create mode 100644 drivers/iio/gyro/adxrs290.c
MAINTAINERS +6 -0
@@ -1098,6 +1098,12 @@ L: [email protected] S: Maintained F: drivers/media/i2c/adv7842* +ANALOG DEVICES INC ADXRS290 DRIVER +M: Nishant Malpani <[email protected]> +L: [email protected] +S: Supported +F: drivers/iio/gyro/adxrs290.c + ANALOG DEVICES INC ASOC CODEC DRIVERS M: Lars-Peter Clausen <[email protected]> M: Nuno Sá <[email protected]>
drivers/iio/gyro/Kconfig +10 -0
@@ -41,6 +41,16 @@ config ADIS16260 This driver can also be built as a module. If so, the module will be called adis16260. +config ADXRS290 + tristate "Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADXRS290 programmable + digital output gyroscope. + + This driver can also be built as a module. If so, the module will be + called adxrs290. + config ADXRS450 tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver" depends on SPI
drivers/iio/gyro/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16130) += adis16130.o obj-$(CONFIG_ADIS16136) += adis16136.o obj-$(CONFIG_ADIS16260) += adis16260.o +obj-$(CONFIG_ADXRS290) += adxrs290.o obj-$(CONFIG_ADXRS450) += adxrs450.o obj-$(CONFIG_BMG160) += bmg160_core.o obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o
drivers/iio/gyro/adxrs290.c new file +444 -0
444 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 10 lines · Nishant Malpani
ADXRS290 is a high performance MEMS pitch and roll (dual-axis in-plane) angular rate sensor (gyroscope) designed for use in stabilization applications. It also features an internal temperature sensor and programmable high-pass and low-pass filters.
Add support for ADXRS290 in direct-access mode for now.
Datasheet:
Drop that 'Link:' part and followed blank line, so get something like
Datasheet: https://...
Signed-off-by: ...
Quoted 1 line
Signed-off-by Nishant Malpani <[email protected]>
...
Quoted 24 lines
(quoted diff) +21
-0+config ADXRS290 + tristate "Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADXRS290 programmable + digital output gyroscope. + + This driver can also be built as a module. If so, the module will be + called adxrs290. +enum adxrs290_mode { + STANDBY, + MEASUREMENT, +}; +struct adxrs290_state { + struct spi_device *spi; + /* Serialize reads and their subsequent processing */ + struct mutex lock; + enum adxrs290_mode mode; + unsigned int lpf_3db_freq_idx; + unsigned int hpf_3db_freq_idx; +};
...
drivers/iio/gyro/adxrs290.c line 66
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+/* +* Available cut-off frequencies of the low pass filter in Hz. +* The integer part and fractional part are represented separately. +*/ +static const int adxrs290_lpf_3db_freq_tbl[][2 ] = {
What about adxrs290_lpf_3db_freq_hz_table ?
drivers/iio/gyro/adxrs290.c line 81
Quoted 7 lines
drivers/iio/gyro/adxrs290.c new file +7
-0+}; + +/* +* Available cut-off frequencies of the high pass filter in Hz. +* The integer part and fractional part are represented separately. +*/ +static const int adxrs290_hpf_3db_freq_tbl[][2 ] = {
Ditto.
Quoted 1 line
+};
...
drivers/iio/gyro/adxrs290.c line 99
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+static int adxrs290_get_rate_data (struct iio_dev *indio_dev,const u8 cmd, +unsigned int *val) +{ +struct adxrs290_state *st =iio_priv (indio_dev); +int ret =0 ;
Purpose of this?
drivers/iio/gyro/adxrs290.c line 104
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+u16 temp; + +mutex_lock (&st->lock); + temp =spi_w8r16 (st->spi, cmd); +if (temp <0 ) {
How can this ever happen?
drivers/iio/gyro/adxrs290.c line 114
Quoted 10 lines
drivers/iio/gyro/adxrs290.c new file +10
-0+ ret = temp; + goto err_unlock; + } + + *val = temp; + +err_unlock: +mutex_unlock (&st->lock); +return ret; +}
Ditto for the rest of the similar cases.
...
drivers/iio/gyro/adxrs290.c line 240
Quoted 7 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+case IIO_CHAN_INFO_SCALE : +switch (chan->type) { +case IIO_ANGL_VEL : + *val =0 ; + *val2 =87266 ;
Magic!
drivers/iio/gyro/adxrs290.c line 243
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +3
-0+return IIO_VAL_INT_PLUS_NANO ; +case IIO_TEMP : + *val =100 ;
Magic!
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +4
-0+return IIO_VAL_INT ; +default : +return -EINVAL ; + }
...
Quoted 1 line
+ *vals = (const int *)adxrs290_lpf_3db_freq_tbl;
Why casting?
...
Quoted 1 line
+ *vals = (const int *)adxrs290_hpf_3db_freq_tbl;
Ditto.
...
drivers/iio/gyro/adxrs290.c line 371
Quoted 5 lines
drivers/iio/gyro/adxrs290.c new file +4
-0+struct iio_dev *indio_dev; +struct adxrs290_state *st; +int ret; +u8 val, val2;
Swap them to have in reversed spruce tree order.
...
Quoted 1 line
+
indio_dev->dev.parent=&spi->dev;
Do you need this?
drivers/iio/gyro/adxrs290.c line 415
Quoted 2 lines
drivers/iio/gyro/adxrs290.c new file +2
-0+/* max transition time to measurement mode */ +msleep_interruptible (ADXRS290_MAX_TRANSITION_TIME_MS );
I'm not sure what the point of interruptible variant here?
...
drivers/iio/gyro/adxrs290.c line 429
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +3
-0+static const struct of_device_id adxrs290_of_match[] = { + { .compatible ="adi,adxrs290" }, + { },
No comma here!
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nishant Malpani
maintainerHello Andy,
Thanks for the review. Comments inline...
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Nishant Malpani
ADXRS290 is a high performance MEMS pitch and roll (dual-axis in-plane) angular rate sensor (gyroscope) designed for use in stabilization applications. It also features an internal temperature sensor and programmable high-pass and low-pass filters.
Add support for ADXRS290 in direct-access mode for now.
Quoted 8 lines
Quoted 2 lines
Datasheet:
Drop that 'Link:' part and followed blank line, so get something like
Datasheet: https://...
Signed-off-by: ...
Okay. Will fix in v3.
Quoted 31 lines
Quoted 1 line
Signed-off-by Nishant Malpani <[email protected]>...
Quoted 24 lines
(quoted diff) +21
-0+config ADXRS290 + tristate "Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope SPI driver" + depends on SPI + help + Say yes here to build support for Analog Devices ADXRS290 programmable + digital output gyroscope. + + This driver can also be built as a module. If so, the module will be + called adxrs290. +enum adxrs290_mode { + STANDBY, + MEASUREMENT, +}; +struct adxrs290_state { + struct spi_device *spi; + /* Serialize reads and their subsequent processing */ + struct mutex lock; + enum adxrs290_mode mode; + unsigned int lpf_3db_freq_idx; + unsigned int hpf_3db_freq_idx; +};...
Quoted 9 lines
drivers/iio/gyro/adxrs290.c line 66
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+/* +* Available cut-off frequencies of the low pass filter in Hz. +* The integer part and fractional part are represented separately. +*/ +static const int adxrs290_lpf_3db_freq_tbl[][2 ] = {What about
adxrs290_lpf_3db_freq_hz_table?
Sure, makes it very precise. Will address in v3.
Quoted 10 lines
drivers/iio/gyro/adxrs290.c line 81
Quoted 7 lines
drivers/iio/gyro/adxrs290.c new file +7
-0+}; + +/* +* Available cut-off frequencies of the high pass filter in Hz. +* The integer part and fractional part are represented separately. +*/ +static const int adxrs290_hpf_3db_freq_tbl[][2 ] = {Ditto.
Yes.
Quoted 4 lines
Quoted 1 line
+};
...
Quoted 9 lines
drivers/iio/gyro/adxrs290.c line 99
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+static int adxrs290_get_rate_data (struct iio_dev *indio_dev,const u8 cmd, +unsigned int *val) +{ +struct adxrs290_state *st =iio_priv (indio_dev); +int ret =0 ;Purpose of this?
'ret' will not be initialized if a successful spi_w8r16() takes place i.e if it doesn't go into the 'if' block. (Doesn't make sense to have it now since the below block of code is erroneous, but will need this in v3).
Quoted 9 lines
drivers/iio/gyro/adxrs290.c line 104
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +5
-0+u16 temp; + +mutex_lock (&st->lock); + temp =spi_w8r16 (st->spi, cmd); +if (temp <0 ) {How can this ever happen?
Oops, you're right. Even though spi_w8r16() returns a negative error code on failure, 'temp' is declared unsigned. Thanks for pointing out. Will fix in v3.
Quoted 4 lines
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +4
-0+ ret = temp; + goto err_unlock; + } +
Quoted 9 lines
drivers/iio/gyro/adxrs290.c line 114
Quoted 6 lines
drivers/iio/gyro/adxrs290.c new file +6
-0+ *val = temp; + +err_unlock: +mutex_unlock (&st->lock); +return ret; +}Ditto for the rest of the similar cases.
Sure.
Quoted 8 lines
...
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +4
-0+case IIO_CHAN_INFO_SCALE : +switch (chan->type) { +case IIO_ANGL_VEL : + *val =0 ;
Quoted 4 lines
Quoted 1 line
+ *val2 = 87266;
Magic!
Haha, will add comments in v3!
Quoted 7 lines
drivers/iio/gyro/adxrs290.c line 243
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +3
-0+return IIO_VAL_INT_PLUS_NANO ; +case IIO_TEMP : + *val =100 ;Magic!
Will add comments in v3.
Quoted 11 lines
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +4
-0+return IIO_VAL_INT ; +default : +return -EINVAL ; + }...
Quoted 1 line
+ *vals = (const int *)adxrs290_lpf_3db_freq_tbl;
Why casting?
adxrs290_lpf_3db_freq_tbl is of type (int *)[2], right? Without the casting, an incompatible-pointer-type error is thrown.
Quoted 6 lines
...
Quoted 1 line
+ *vals = (const int *)adxrs290_hpf_3db_freq_tbl;
Ditto.
See above comment.
Quoted 11 lines
...
drivers/iio/gyro/adxrs290.c line 371
Quoted 5 lines
drivers/iio/gyro/adxrs290.c new file +4
-0+struct iio_dev *indio_dev; +struct adxrs290_state *st; +int ret; +u8 val, val2;Swap them to have in reversed spruce tree order.
Okay, will do so in v3.
Quoted 5 lines
...
Quoted 1 line
+
indio_dev->dev.parent=&spi->dev;Do you need this?
Oh, right (I'm aware of Alexandru's recent patch on this). Will address in v3.
Quoted 6 lines
drivers/iio/gyro/adxrs290.c line 415
Quoted 3 lines
drivers/iio/gyro/adxrs290.c new file +2
-0+/* max transition time to measurement mode */ +msleep_interruptible (ADXRS290_MAX_TRANSITION_TIME_MS );I'm not sure what the point of interruptible variant here?
I referred Documentation/timers/timers-howto.rst for this.
My reasoning was shaped to use the interruptible variant because the transition settles in a time *less than* 100ms and since 100ms is quite a huge time to sleep, it should be interrupted in case a signal arrives.
Quoted 9 lines
...
drivers/iio/gyro/adxrs290.c line 429
Quoted 4 lines
drivers/iio/gyro/adxrs290.c new file +3
-0+static const struct of_device_id adxrs290_of_match[] = { + { .compatible ="adi,adxrs290" }, + { },No comma here!
Okay. Will remove in v3.
With regards,
Nishant Malpani
Quoted 2 lines
Quoted 1 line
+};
Nishant Malpani
maintainerOn 22/07/20 2:05 am, Nishant Malpani wrote:
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+ return
IIO_VAL_INT;
+ default:
+ return-EINVAL;
+ }
Quoted 7 lines
Quoted 6 lines
...
Quoted 1 line
+ *vals = (const int *)adxrs290_lpf_3db_freq_tbl;
Why casting?
adxrs290_lpf_3db_freq_tblis of type (int *)[2], right? Without the casting, an incompatible-pointer-type error is thrown.
Sorry, the above is incorrect. adxrs290_lpf_3db_freq_tbl is a pointer to an array of two ints.
[...]
Regards,
Nishant Malpani
Quoted 3 lines · Nishant Malpani
Quoted 2 lines · Andy Shevchenko
On Tue, Jul 21, 2020 at 9:20 PM Nishant Malpani
<[email protected]> wrote:
...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+ *vals = (const int *)adxrs290_lpf_3db_freq_tbl;
Why casting?
adxrs290_lpf_3db_freq_tblis of type (int *)[2], right? Without the casting, an incompatible-pointer-type error is thrown.
Quoted 7 lines
Quoted 6 lines
...
Quoted 1 line
+ *vals = (const int *)adxrs290_hpf_3db_freq_tbl;
Ditto.
See above comment.
Can't you declare table as const int?
...
Quoted 9 lines
Quoted 5 lines
drivers/iio/gyro/adxrs290.c line 415
Quoted 2 lines
drivers/iio/gyro/adxrs290.c new file +2
-0+/* max transition time to measurement mode */ +msleep_interruptible (ADXRS290_MAX_TRANSITION_TIME_MS );I'm not sure what the point of interruptible variant here?
I referred
Documentation/timers/timers-howto.rstfor this. My reasoning was shaped to use the interruptible variant because the transition settles in a time *less than* 100ms and since 100ms is quite a huge time to sleep, it should be interrupted in case a signal arrives.
This is probe of the device,
What are the expectations here?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nishant Malpani
maintainerQuoted 17 lines · Andy Shevchenko
Quoted 3 lines · Nishant Malpani
Quoted 2 lines · Andy Shevchenko
On Tue, Jul 21, 2020 at 9:20 PM Nishant Malpani
<[email protected]> wrote:...
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+ *vals = (const int *)adxrs290_lpf_3db_freq_tbl;
Why casting?
adxrs290_lpf_3db_freq_tblis of type (int *)[2], right? Without the casting, an incompatible-pointer-type error is thrown.Quoted 2 lines
...
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+ *vals = (const int *)adxrs290_hpf_3db_freq_tbl;
Ditto.
See above comment.
Can't you declare table as const int?
I'm not sure I understand you completely here; do you mean const int *? So, an array of alternate integer and fractional parts? I suppose that's possible but we'd be introducing unwanted complexity I feel - for example, currently the index of the 3db frequency in the table is used to directly map & set bits in the filter register corresponding to that frequency but with the approach you share, we'd have to apply a transformation (div by 2) to set the same bits in the filter register. Do you think the added complexity justifies the removal of the casting?
Quoted 7 lines
...
Quoted 5 lines
Quoted 5 lines
drivers/iio/gyro/adxrs290.c line 415
Quoted 2 lines
drivers/iio/gyro/adxrs290.c new file +2
-0+/* max transition time to measurement mode */ +msleep_interruptible (ADXRS290_MAX_TRANSITION_TIME_MS );I'm not sure what the point of interruptible variant here?
Quoted 8 lines
Quoted 4 lines
I referred
Documentation/timers/timers-howto.rstfor this. My reasoning was shaped to use the interruptible variant because the transition settles in a time *less than* 100ms and since 100ms is quite a huge time to sleep, it should be interrupted in case a signal arrives.This is probe of the device,
What are the expectations here?
I fail to understand why this can't be used in the probe() but perhaps in a routine to standby/resume. Could you please elaborate?
With regards,
Nishant Malpani
Quoted 4 lines · Nishant Malpani
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Nishant Malpani
On 22/07/20 1:16 am, Andy Shevchenko wrote:
...
Quoted 10 lines
Quoted 2 lines
Can't you declare table as const int?
I'm not sure I understand you completely here; do you mean const int *? So, an array of alternate integer and fractional parts? I suppose that's possible but we'd be introducing unwanted complexity I feel - for example, currently the index of the 3db frequency in the table is used to directly map & set bits in the filter register corresponding to that frequency but with the approach you share, we'd have to apply a transformation (div by 2) to set the same bits in the filter register. Do you think the added complexity justifies the removal of the casting?
It was a question. If you think it is too much, don't change :-)
...
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
drivers/iio/gyro/adxrs290.c line 415
Quoted 2 lines
drivers/iio/gyro/adxrs290.c new file +2
-0+/* max transition time to measurement mode */ +msleep_interruptible (ADXRS290_MAX_TRANSITION_TIME_MS );I'm not sure what the point of interruptible variant here?
I referred
Documentation/timers/timers-howto.rstfor this. My reasoning was shaped to use the interruptible variant because the transition settles in a time *less than* 100ms and since 100ms is quite a huge time to sleep, it should be interrupted in case a signal arrives.
Quoted 5 lines
Quoted 3 lines
This is probe of the device,
What are the expectations here?I fail to understand why this can't be used in the
probe()but perhaps in a routine to standby/resume. Could you please elaborate?
I didn't say it can not be used, what I'm asking is what are the expectations of the interruptible part here.
In other words what is the benefit that makes you choose this over plain msleep().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Nishant Malpani
maintainerQuoted 36 lines · Andy Shevchenko
Quoted 4 lines · Nishant Malpani
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Nishant Malpani
On 22/07/20 1:16 am, Andy Shevchenko wrote:
...
Quoted 10 lines
Quoted 2 lines
Can't you declare table as const int?
I'm not sure I understand you completely here; do you mean const int *? So, an array of alternate integer and fractional parts? I suppose that's possible but we'd be introducing unwanted complexity I feel - for example, currently the index of the 3db frequency in the table is used to directly map & set bits in the filter register corresponding to that frequency but with the approach you share, we'd have to apply a transformation (div by 2) to set the same bits in the filter register. Do you think the added complexity justifies the removal of the casting?
It was a question. If you think it is too much, don't change :-)
Quoted 15 lines
...
Quoted 13 lines
Quoted 9 lines
Quoted 5 lines
drivers/iio/gyro/adxrs290.c line 415
Quoted 2 lines
drivers/iio/gyro/adxrs290.c new file +2
-0+/* max transition time to measurement mode */ +msleep_interruptible (ADXRS290_MAX_TRANSITION_TIME_MS );I'm not sure what the point of interruptible variant here?
I referred
Documentation/timers/timers-howto.rstfor this. My reasoning was shaped to use the interruptible variant because the transition settles in a time *less than* 100ms and since 100ms is quite a huge time to sleep, it should be interrupted in case a signal arrives.This is probe of the device,
What are the expectations here?
Quoted 8 lines
Quoted 2 lines
I fail to understand why this can't be used in the
probe()but perhaps in a routine to standby/resume. Could you please elaborate?I didn't say it can not be used, what I'm asking is what are the expectations of the interruptible part here.
In other words what is the benefit that makes you choose this over plainmsleep().
Oh, sorry for I misunderstood.
I cannot think of anything more to add to the reasoning that I explained earlier; in that case, I'll fall back to msleep() (in v3) unless someone else comes with a strong point in msleep_interruptible()'s favor.
With regards,
Nishant Malpani