iio: accel: adxl345: add FIFO operating with IRQ triggered watermark events
Subsystems (4)
v7 cover iio: accel: adxl345: add FIFO operating with IRQ triggered watermark events
The adxl345 sensor offers several features. Most of them are based on using the hardware FIFO and reacting on events coming in on an interrupt line. Add access to configure and read out the FIFO, handling of interrupts and configuration and application of the watermark feature on that FIFO.
---
v6 -> v7:
- reorder dt-binding patches
- extracted FIFO specific from constants list
- reorder constants list in header patch to the end
- verify watermark input is within valid range
v5 -> v6:
- dropped justify patch, since unnecessary change to format mask
- added separate dt-bindings patch to remove required interrupts property
- merged FIFO watermark patches
- reworked bitfield handling
- group irq setup in probe()
- several type fixes by smatch and tools
v4 -> v5:
- fix dt-binding for enum array of INT1 and INT2
v3 -> v4:
- fix dt-binding indention
v2 -> v3:
- reorganize commits, merge the watermark handling
- INT lines are defined by binding
- kfifo is prepared by devm_iio_kfifo_buffer_setup()
- event handler is registered w/ devm_request_threaded_irq() v1 -> v2:
Fix comments according to Documentation/doc-guide/kernel-doc.rst and missing static declaration of function.
---
Lothar Rubusch (7):
iio: accel: adxl345: add function to switch measuring mode
dt-bindings: iio: accel: adxl345: make interrupts not a required
property
dt-bindings: iio: accel: adxl345: add interrupt-names
iio: accel: adxl345: introduce interrupt handling
iio: accel: adxl345: initialize FIFO delay value for SPI
iio: accel: adxl345: add FIFO with watermark events
iio: accel: adxl345: complete the list of defines
.../bindings/iio/accel/adi,adxl345.yaml | 11 +- drivers/iio/accel/adxl345.h | 85 +++- drivers/iio/accel/adxl345_core.c | 377 +++++++++++++++++- drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +- 5 files changed, 450 insertions(+), 32 deletions(-)
Signature · 1 line
2.39.5
PATCH v7 1/7 iio: accel: adxl345: add function to switch measuring mode
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
--- drivers/iio/accel/adxl345_core.c | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-)
drivers/iio/accel/adxl345_core.c +30 -12
@@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** +* adxl345_set_measure_en() - Enable and disable measuring. +* +* @st: The device data. +* @en: Enable measurements, else standby mode. +* +* For lowest power operation, standby mode can be used. In standby mode, +* current consumption is supposed to be reduced to 0.1uA (typical). In this +* mode no measurements are made. Placing the device into standby mode +* preserves the contents of FIFO. +* +* Return: Returns 0 if successful, or a negative error value. +*/ +static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ; + + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ; +return regmap_write (st->regmap,ADXL345_REG_POWER_CTL , val); +} + +static void adxl345_powerdown (void *ptr) +{ +struct adxl345_state *st = ptr; + +adxl345_set_measure_en (st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" );
@@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup (void *regmap) -{ -return regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_MEASURE ); -} - -static void adxl345_powerdown (void *regmap) -{ -regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); -} -/** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device
@@ -237,11 +255,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID);/* Enable measurement mode */ - ret =adxl345_powerup (st->regmap); + ret =adxl345_set_measure_en (st, true);if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable measurement mode\n" ); - ret =devm_add_action_or_reset (dev, adxl345_powerdown, st->regmap); + ret =devm_add_action_or_reset (dev, adxl345_powerdown, st);if (ret <0 )return ret;
Signature · 1 line
2.39.5
Re: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode
Le 13/12/2024 à 22:19, Lothar Rubusch a écrit :
Quoted 4 lines
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
...
drivers/iio/accel/adxl345_core.c static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, · line 156
Quoted 3 lines
drivers/iio/accel/adxl345_core.c +3
-0+static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ;
Nitpick: useless init
drivers/iio/accel/adxl345_core.c static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, · line 158
Quoted 2 lines
drivers/iio/accel/adxl345_core.c +2
-0+ + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ;
Nitpick: useless () around en.
Quoted 2 lines
(quoted diff) +2
-0+ return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); +}
...
Re: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode
Quoted 15 lines · Christophe JAILLET
Quoted 4 lines · Lothar Rubusch
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
...
drivers/iio/accel/adxl345_core.c static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, · line 156
Quoted 3 lines
drivers/iio/accel/adxl345_core.c +3
-0+static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ;Nitpick: useless init
Quoted 4 lines
drivers/iio/accel/adxl345_core.c static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, · line 158
Quoted 2 lines
drivers/iio/accel/adxl345_core.c +2
-0+ + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ;Nitpick: useless () around en.
Thank you for pointing out. I agree. This is better just in one line, initialization directly and no parens. Anyway, since I already can see the patch on the iio branch, I'll probably better leave it as is for now (?).
Question: Since I'm currently about to build up tooling for linters and static checkers. I'm doing checkpatch. I'm running Dan's smatch, now. I'm correcting indention/spaces/tabs by some emacs settings. DT/bindings I was doing wrong, and just figured out why after submitting the last patch (...).
What is the best approach to find such kind of nitpick issues automatically?
Best,
L
Quoted 5 lines
Quoted 3 lines
(quoted diff) +2
-0+ return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); +}...
Re: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode
Le 15/12/2024 à 10:32, Lothar Rubusch a écrit :
Quoted 20 lines
Quoted 18 lines · Christophe JAILLET
Quoted 4 lines · Lothar Rubusch
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
...
drivers/iio/accel/adxl345_core.c static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, · line 156
Quoted 3 lines
drivers/iio/accel/adxl345_core.c +3
-0+static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ;Nitpick: useless init
Quoted 2 lines
drivers/iio/accel/adxl345_core.c +2
-0+ + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ;
Quoted 6 lines
Quoted 1 line
Nitpick: useless () around en.
Thank you for pointing out. I agree. This is better just in one line, initialization directly and no parens. Anyway, since I already can see the patch on the iio branch, I'll probably better leave it as is for now (?).
It is just a nitpick, it can stay as-is forever.
Quoted 8 lines
Question: Since I'm currently about to build up tooling for linters and static checkers. I'm doing checkpatch. I'm running Dan's smatch, now. I'm correcting indention/spaces/tabs by some emacs settings. DT/bindings I was doing wrong, and just figured out why after submitting the last patch (...).
What is the best approach to find such kind of nitpick issues automatically?
I don't know any.
I only uses ./scripts/checkpatch.pl --strict
I guess that some coccinelle scripts could also spot some things, (the unneeded init in this case), but I don't really think that the effort would worth it.
Maybe using -Wall and or -Wextra gcc gcc would also trigger additional warning that could look relevant?
Adding Dan if he has more ideas.
CJ
Quoted 11 lines
Best,
LQuoted 5 lines
Quoted 3 lines
(quoted diff) +2
-0+ return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val); +}...
Re: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode
In reply to Lothar RubuschQuoted 6 lines · On Fri, 13 Dec 2024 21:19:03 +0000 Lothar Rubusch <[email protected]> wrote:
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
Signed-off-by Lothar Rubusch <[email protected]>
Mostly in the interests of trimming down the queue of patches in flight and because this one has been fine for a few versions without significant comment.
Applied this patch to the togreg branch of iio.git and pushed out initially as testing to let 0-day take a look.
Thanks
Jonathan
Quoted 74 lines
--- drivers/iio/accel/adxl345_core.c | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-)drivers/iio/accel/adxl345_core.c +30
-12@@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** +* adxl345_set_measure_en() - Enable and disable measuring. +* +* @st: The device data. +* @en: Enable measurements, else standby mode. +* +* For lowest power operation, standby mode can be used. In standby mode, +* current consumption is supposed to be reduced to 0.1uA (typical). In this +* mode no measurements are made. Placing the device into standby mode +* preserves the contents of FIFO. +* +* Return: Returns 0 if successful, or a negative error value. +*/ +static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ; + + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ; +return regmap_write (st->regmap,ADXL345_REG_POWER_CTL , val); +} + +static void adxl345_powerdown (void *ptr) +{ +struct adxl345_state *st = ptr; + +adxl345_set_measure_en (st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" );@@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup (void *regmap) -{ -return regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_MEASURE ); -} - -static void adxl345_powerdown (void *regmap) -{ -regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); -} -/** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device @@ -237,11 +255,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID);/* Enable measurement mode */ - ret =adxl345_powerup (st->regmap); + ret =adxl345_set_measure_en (st, true);if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable measurement mode\n" ); - ret =devm_add_action_or_reset (dev, adxl345_powerdown, st->regmap); + ret =devm_add_action_or_reset (dev, adxl345_powerdown, st);if (ret <0 )return ret;
Re: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode
Quoted 9 lines · Jonathan Cameron
Quoted 5 lines · On Fri, 13 Dec 2024 21:19:03 +0000 Lothar Rubusch <[email protected]> wrote:
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
Quoted 8 lines
Quoted 1 line
Signed-off-by Lothar Rubusch <[email protected]>Mostly in the interests of trimming down the queue of patches in flight and because this one has been fine for a few versions without significant comment.
Applied this patch to the togreg branch of iio.git and pushed out initially as testing to let 0-day take a look.
Question here: you applied this patch now to the iio branch. Now, Christophe Jaillet pointed still something out that could be improved, the function could be shortened to, e.g.
+static int adxl345_set_measure_en(struct adxl345_state *st, bool en) +{
+ unsigned int val = en ? ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY;
+
+ return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val);
+}
Should I present an improved patch? Or, in case this was urgent, would it require an additional patch/fix? What would be the way to deal with such fixes immediately after "applied"?
Best,
L
Quoted 79 lines
Thanks
Jonathan
Quoted 74 lines
--- drivers/iio/accel/adxl345_core.c | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-)drivers/iio/accel/adxl345_core.c +30
-12@@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** +* adxl345_set_measure_en() - Enable and disable measuring. +* +* @st: The device data. +* @en: Enable measurements, else standby mode. +* +* For lowest power operation, standby mode can be used. In standby mode, +* current consumption is supposed to be reduced to 0.1uA (typical). In this +* mode no measurements are made. Placing the device into standby mode +* preserves the contents of FIFO. +* +* Return: Returns 0 if successful, or a negative error value. +*/ +static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ; + + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ; +return regmap_write (st->regmap,ADXL345_REG_POWER_CTL , val); +} + +static void adxl345_powerdown (void *ptr) +{ +struct adxl345_state *st = ptr; + +adxl345_set_measure_en (st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" );@@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup (void *regmap) -{ -return regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_MEASURE ); -} - -static void adxl345_powerdown (void *regmap) -{ -regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); -} -/** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device @@ -237,11 +255,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID);/* Enable measurement mode */ - ret =adxl345_powerup (st->regmap); + ret =adxl345_set_measure_en (st, true);if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable measurement mode\n" ); - ret =devm_add_action_or_reset (dev, adxl345_powerdown, st->regmap); + ret =devm_add_action_or_reset (dev, adxl345_powerdown, st);if (ret <0 )return ret;
Jonathan Cameron
maintainerRe: [PATCH v7 1/7] iio: accel: adxl345: add function to switch measuring mode
Quoted 31 lines · On Sun, 15 Dec 2024 10:41:12 +0100 Lothar Rubusch <[email protected]> wrote:
Quoted 9 lines · Jonathan Cameron
Quoted 5 lines · On Fri, 13 Dec 2024 21:19:03 +0000 Lothar Rubusch <[email protected]> wrote:
Replace the powerup / powerdown functions by a generic function to put the sensor in STANDBY, or MEASURE mode. When configuring the FIFO for several features of the accelerometer, it is recommended to put measuring in STANDBY mode.
Quoted 8 lines
Quoted 1 line
Signed-off-by Lothar Rubusch <[email protected]>Mostly in the interests of trimming down the queue of patches in flight and because this one has been fine for a few versions without significant comment.
Applied this patch to the togreg branch of iio.git and pushed out initially as testing to let 0-day take a look.
Question here: you applied this patch now to the iio branch. Now, Christophe Jaillet pointed still something out that could be improved, the function could be shortened to, e.g.
drivers/iio/accel/adxl345_core.c +3
-0+static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ + unsigned int val = en ? ADXL345_POWER_CTL_MEASURE :
ADXL345_POWER_CTL_STANDBY;drivers/iio/accel/adxl345_core.c +3
-0+ +return regmap_write (st->regmap,ADXL345_REG_POWER_CTL , val); +}
Quoted 4 lines
Should I present an improved patch? Or, in case this was urgent, would it require an additional patch/fix? What would be the way to deal with such fixes immediately after "applied"?
Send me a patch on top. I may well squash it into the original (particularly if you stick a note on that being sensible under the --- for the patch!)
There is always a window in which I'm happy to rebase (or pull a patch if we get feedback needing bigger changes) because I typically give at least half a week for 0-day to poke the tree before I make a potential mess in linux-next. Ultimately I'll rebase after that for a sufficiently serious issue but for something like this I'll just apply the patch on top once it's out for linux-next to pick up.
Jonathan
Quoted 82 lines
Best,
LQuoted 79 lines
Thanks
Jonathan
Quoted 74 lines
--- drivers/iio/accel/adxl345_core.c | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-)drivers/iio/accel/adxl345_core.c +30
-12@@ -138,6 +138,34 @@ static int adxl345_write_raw_get_fmt(struct iio_dev *indio_dev, } } +/** +* adxl345_set_measure_en() - Enable and disable measuring. +* +* @st: The device data. +* @en: Enable measurements, else standby mode. +* +* For lowest power operation, standby mode can be used. In standby mode, +* current consumption is supposed to be reduced to 0.1uA (typical). In this +* mode no measurements are made. Placing the device into standby mode +* preserves the contents of FIFO. +* +* Return: Returns 0 if successful, or a negative error value. +*/ +static int adxl345_set_measure_en (struct adxl345_state *st,bool en) +{ +unsigned int val =0 ; + + val = (en) ?ADXL345_POWER_CTL_MEASURE :ADXL345_POWER_CTL_STANDBY ; +return regmap_write (st->regmap,ADXL345_REG_POWER_CTL , val); +} + +static void adxl345_powerdown (void *ptr) +{ +struct adxl345_state *st = ptr; + +adxl345_set_measure_en (st, false); +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.09765625 0.1953125 0.390625 0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600 3200" );@@ -158,16 +186,6 @@ static const struct iio_info adxl345_info = { .write_raw_get_fmt = adxl345_write_raw_get_fmt, }; -static int adxl345_powerup (void *regmap) -{ -return regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_MEASURE ); -} - -static void adxl345_powerdown (void *regmap) -{ -regmap_write (regmap,ADXL345_REG_POWER_CTL ,ADXL345_POWER_CTL_STANDBY ); -} -/** * adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device @@ -237,11 +255,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, regval, ADXL345_DEVID);/* Enable measurement mode */ - ret =adxl345_powerup (st->regmap); + ret =adxl345_set_measure_en (st, true);if (ret <0 )return dev_err_probe (dev, ret,"Failed to enable measurement mode\n" ); - ret =devm_add_action_or_reset (dev, adxl345_powerdown, st->regmap); + ret =devm_add_action_or_reset (dev, adxl345_powerdown, st);if (ret <0 )return ret;
PATCH v7 2/7 dt-bindings: iio: accel: adxl345: make interrupts not a required property
In reply to Lothar RubuschRemove interrupts from the list of required properties. The ADXL345 does not need interrupts for basic accelerometer functionality. The sensor offers optional events which can be indicated on one of two interrupt lines.
--- Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml | 1 - 1 file changed, 1 deletion(-)
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +0 -1
@@ -40,7 +40,6 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml#
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerRe: [PATCH v7 2/7] dt-bindings: iio: accel: adxl345: make interrupts not a required property
Quoted 4 lines · On Fri, 13 Dec 2024 21:19:04 +0000 Lothar Rubusch <[email protected]> wrote:
Remove interrupts from the list of required properties. The ADXL345 does not need interrupts for basic accelerometer functionality. The sensor offers optional events which can be indicated on one of two interrupt lines.
It is harmless but if you are spinning again, remove the last sentence. It isn't really anything to do with the reasoning behind this patch (well covered by the first sentence). If everyone is fine with this version I might just drop it whilst applying.
Jonathan
Quoted 18 lines
Signed-off-by Lothar Rubusch <[email protected]>--- Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml | 1 - 1 file changed, 1 deletion(-)Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +0
-1@@ -40,7 +40,6 @@ properties: required: - compatible - reg - - interrupts allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml#
Re: [PATCH v7 2/7] dt-bindings: iio: accel: adxl345: make interrupts not a required property
In reply to Lothar RubuschQuoted 9 lines · Lothar Rubusch
Remove interrupts from the list of required properties. The ADXL345 does not need interrupts for basic accelerometer functionality. The sensor offers optional events which can be indicated on one of two interrupt lines.
Signed-off-by Lothar Rubusch <[email protected]>--- Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml | 1 - 1 file changed, 1 deletion(-)
Best regards,
Krzysztof
PATCH v7 3/7 dt-bindings: iio: accel: adxl345: add interrupt-names
In reply to Lothar RubuschAdd interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
--- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +10 -0
@@ -37,6 +37,14 @@ properties: interrupts: maxItems: 1 + interrupt-names: + items: + - enum: [INT1, INT2] + +dependencies: + interrupts: [ 'interrupt-names' ] + interrupt-names: [ 'interrupts' ] + required: - compatible - reg
@@ -60,6 +68,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - |
@@ -78,5 +87,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; };
Signature · 1 line
2.39.5
Rob Herring (Arm)
maintainerRe: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
Quoted 7 lines · Lothar Rubusch
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
Quoted 9 lines
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Signed-off-by Lothar Rubusch <[email protected]>--- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:./Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml:45:17: [error] string value is redundantly quoted with any quotes (quoted-strings) ./Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml:46:22: [error] string value is redundantly quoted with any quotes (quoted-strings)
dtschema/dtc warnings/errors:
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Jonathan Cameron
maintainerRe: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
In reply to Lothar RubuschQuoted 7 lines · On Fri, 13 Dec 2024 21:19:05 +0000 Lothar Rubusch <[email protected]> wrote:
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
Quoted 5 lines
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Signed-off-by Lothar Rubusch <[email protected]>
Just to repeat what I sent in reply to v6 (well after you'd posted this). Maybe we can maintain compatibility with the binding before this by adding a default of INT1.
Then you'd need to drop the dependency on interrupt-names.
I'm not sure though if the checking of number of entries will work against a default. Give it a go and see what happens :)
We are lucky that we can't have bindings in the wild assuming ordering of the two interrupts due to the maxItems being set for interrupts.
It's a messy corner, perhaps we should just not bother in the binding, but keep that default handling in the driver?
DT binding folk, what do you think the best way of handling this is?
Jonathan
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml properties: · line 38
Quoted 11 lines
--- .../devicetree/bindings/iio/accel/adi,adxl345.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +0
-0@@ -37,6 +37,14 @@ properties: interrupts: maxItems: 1
That is not going to work if we have two interrupts specified. It does at least mean we only need
Quoted 27 lines
Documentation/devicetree/bindings/iio/accel/adi,adxl345.yaml +10
-0+ interrupt-names: + items: + - enum: [INT1, INT2] + +dependencies: + interrupts: [ 'interrupt-names' ] + interrupt-names: [ 'interrupts' ] + required: - compatible - reg@@ -60,6 +68,7 @@ examples: reg = <0x2a>; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT1"; }; }; - |@@ -78,5 +87,6 @@ examples: spi-cpha; interrupt-parent = <&gpio0>; interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "INT2"; }; };
Re: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 13 Dec 2024 21:19:05 +0000 Lothar Rubusch <[email protected]> wrote:
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Quoted 5 lines
Quoted 1 line
Signed-off-by Lothar Rubusch <[email protected]>Just to repeat what I sent in reply to v6 (well after you'd posted this). Maybe we can maintain compatibility with the binding before this by adding a default of INT1.
But can you make that assumption? If we did, and it's not universally true, we break systems that had INT2 connected that previously worked.
Quoted 12 lines
Then you'd need to drop the dependency on interrupt-names.
I'm not sure though if the checking of number of entries will work against a default. Give it a go and see what happens :)
We are lucky that we can't have bindings in the wild assuming ordering of the two interrupts due to the maxItems being set for interrupts.
It's a messy corner, perhaps we should just not bother in the binding, but keep that default handling in the driver?
DT binding folk, what do you think the best way of handling this is?
Jonathan Cameron
maintainerRe: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
Quoted 15 lines · On Sun, 15 Dec 2024 14:56:58 +0000 Conor Dooley <[email protected]> wrote:
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Fri, 13 Dec 2024 21:19:05 +0000 Lothar Rubusch <[email protected]> wrote:
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Lothar Rubusch <[email protected]>Just to repeat what I sent in reply to v6 (well after you'd posted this). Maybe we can maintain compatibility with the binding before this by adding a default of INT1.
But can you make that assumption? If we did, and it's not universally true, we break systems that had INT2 connected that previously worked.
I guess there is a possibility of a driver in some other OS assuming INT2, but seems an odd 'default' choice. Also odd for a writer of DT for a platform to assume it.
There is a thing that comes up in spec orgs when discussing whether to rush out an errata. "Is this bug something people would get wrong thinking the answer was clear, or something where the would ask a question?" Anyone who thinks INT2 is the obvious choice for me falls into the would ask category.
However, in the linux driver we would would go from assuming no interrupts to assuming the wrong one. That's indeed bad. So I guess this doesn't work. Oh well no default it is.
Jonathan
Quoted 13 lines
Quoted 13 lines
Then you'd need to drop the dependency on interrupt-names.
I'm not sure though if the checking of number of entries will work against a default. Give it a go and see what happens :)
We are lucky that we can't have bindings in the wild assuming ordering of the two interrupts due to the maxItems being set for interrupts.
It's a messy corner, perhaps we should just not bother in the binding, but keep that default handling in the driver?
DT binding folk, what do you think the best way of handling this is?
Re: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 15 Dec 2024 14:56:58 +0000 Conor Dooley <[email protected]> wrote:
Quoted 19 lines · Jonathan Cameron
Quoted 7 lines · On Fri, 13 Dec 2024 21:19:05 +0000 Lothar Rubusch <[email protected]> wrote:
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
Quoted 5 lines
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Signed-off-by Lothar Rubusch <[email protected]>Just to repeat what I sent in reply to v6 (well after you'd posted this). Maybe we can maintain compatibility with the binding before this by adding a default of INT1.
Quoted 5 lines
Quoted 2 lines
But can you make that assumption? If we did, and it's not universally true, we break systems that had INT2 connected that previously worked.
I guess there is a possibility of a driver in some other OS assuming INT2, but seems an odd 'default' choice.
Ye, I think that it is unlikely a driver author would think that way.
Quoted 2 lines
Also odd for a writer of DT for a platform
to assume it.
I agree, I think it is unlikely that someone would assume it'd work like this. I think a lack of attention paid to the schematic of the board is a more likely culprit.
Quoted 9 lines
There is a thing that comes up in spec orgs when discussing whether to rush out an errata. "Is this bug something people would get wrong thinking the answer was clear, or something where the would ask a question?" Anyone who thinks INT2 is the obvious choice for me falls into the would ask category.
However, in the linux driver we would would go from assuming no interrupts to assuming the wrong one. That's indeed bad. So I guess this doesn't work. Oh well no default it is.
I don't think you really lose anything from having no default. The driver works just fine without the interrupt, so the albeit small risk just doesn't seem worth it.
Re: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
Quoted 47 lines · Conor Dooley
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 15 Dec 2024 14:56:58 +0000 Conor Dooley <[email protected]> wrote:
Quoted 19 lines · Jonathan Cameron
Quoted 7 lines · On Fri, 13 Dec 2024 21:19:05 +0000 Lothar Rubusch <[email protected]> wrote:
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
Quoted 5 lines
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Signed-off-by Lothar Rubusch <[email protected]>Just to repeat what I sent in reply to v6 (well after you'd posted this). Maybe we can maintain compatibility with the binding before this by adding a default of INT1.
Quoted 5 lines
Quoted 2 lines
But can you make that assumption? If we did, and it's not universally true, we break systems that had INT2 connected that previously worked.
I guess there is a possibility of a driver in some other OS assuming INT2, but seems an odd 'default' choice.
Ye, I think that it is unlikely a driver author would think that way.
Quoted 2 lines
Also odd for a writer of DT for a platform
to assume it.I agree, I think it is unlikely that someone would assume it'd work like this. I think a lack of attention paid to the schematic of the board is a more likely culprit.
Quoted 6 lines
There is a thing that comes up in spec orgs when discussing whether to rush out an errata. "Is this bug something people would get wrong thinking the answer was clear, or something where the would ask a question?" Anyone who thinks INT2 is the obvious choice for me falls into the would ask category.
Quoted 7 lines
Quoted 3 lines
However, in the linux driver we would would go from assuming no interrupts to assuming the wrong one. That's indeed bad. So I guess this doesn't work. Oh well no default it is.
I don't think you really lose anything from having no default. The driver works just fine without the interrupt, so the albeit small risk just doesn't seem worth it.
Agree. To be honest, I'm not sure if I catch the point here. IMHO, falling back to FIFO bypass should match with backward compatibility. Please let me know what I'm missing here.
I would prefer just to check for a specified INT name. Then configure the specified interrupt line in the probe. In this sense, the interrupt line is only useful also if the INT name is defined in the DT. If no INT name is specified, the iio driver will setup FIFO_BYPASS which is the legacy behavior (according to the datasheet: if none of the FIFO mode bits are set, defaults to bypass mode). This is the new behavior.
The old iio driver did not use interrupts at all. It stayed in FIFO_BYPASS mode (or did not change it, after power on, it assumes FIFO_BYPASS to my interpretation). Thus declaring the IRQ line yes or no, with or without INT names - for the iio driver implementation before this patch series, should not make any difference. It uses FIFO_BYPASS in all cases.
The input driver (AFAIR we already agreed on ignoring this driver) needed interrupts. Defining INT names here does not change anything, either. The input driver configures by default INT1 and simply ignores what was specified as INT names in the DT.
I cannot really think of any third case here. Please, let me know if I'm wrong. If not I will keep the above explained behavior, since to my understanding it should match the desired compatibility requirements. Am I wrong here?
Sorry for the late answer. Best,
L
Re: [PATCH v7 3/7] dt-bindings: iio: accel: adxl345: add interrupt-names
Quoted 52 lines · Lothar Rubusch
Quoted 51 lines · Conor Dooley
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 15 Dec 2024 14:56:58 +0000 Conor Dooley <[email protected]> wrote:
Quoted 19 lines · Jonathan Cameron
Quoted 7 lines · On Fri, 13 Dec 2024 21:19:05 +0000 Lothar Rubusch <[email protected]> wrote:
Add interrupt-names INT1 and INT2 for the two interrupt lines of the sensor.
When one of the two interrupt lines is connected, the interrupt as its interrupt-name, need to be declared in the devicetree. The driver then configures the sensor to indicate its events on either INT1 or INT2.
Quoted 5 lines
If no interrupt is configured, then no interrupt-name should be configured, and vice versa. In this case the sensor runs in FIFO BYPASS mode. This allows sensor measurements, but none of the sensor events.
Signed-off-by Lothar Rubusch <[email protected]>Just to repeat what I sent in reply to v6 (well after you'd posted this). Maybe we can maintain compatibility with the binding before this by adding a default of INT1.
Quoted 5 lines
Quoted 2 lines
But can you make that assumption? If we did, and it's not universally true, we break systems that had INT2 connected that previously worked.
I guess there is a possibility of a driver in some other OS assuming INT2, but seems an odd 'default' choice.
Ye, I think that it is unlikely a driver author would think that way.
Quoted 2 lines
Also odd for a writer of DT for a platform
to assume it.I agree, I think it is unlikely that someone would assume it'd work like this. I think a lack of attention paid to the schematic of the board is a more likely culprit.
Quoted 9 lines
There is a thing that comes up in spec orgs when discussing whether to rush out an errata. "Is this bug something people would get wrong thinking the answer was clear, or something where the would ask a question?" Anyone who thinks INT2 is the obvious choice for me falls into the would ask category.
However, in the linux driver we would would go from assuming no interrupts to assuming the wrong one. That's indeed bad. So I guess this doesn't work. Oh well no default it is.
Quoted 7 lines
Quoted 3 lines
I don't think you really lose anything from having no default. The driver works just fine without the interrupt, so the albeit small risk just doesn't seem worth it.
Agree. To be honest, I'm not sure if I catch the point here. IMHO, falling back to FIFO bypass should match with backward compatibility. Please let me know what I'm missing here.
Ye, falling back to the current behaviour is fine. The only problematic thing is not checking "for a specified INT name" but assuming the provided interrupt is either INT1 or INT2 when interrupt-names is not provided.
Quoted 28 lines
I would prefer just to check for a specified INT name. Then configure the specified interrupt line in the probe. In this sense, the interrupt line is only useful also if the INT name is defined in the DT. If no INT name is specified, the iio driver will setup
FIFO_BYPASSwhich is the legacy behavior (according to the datasheet: if none of the FIFO mode bits are set, defaults to bypass mode). This is the new behavior.The old iio driver did not use interrupts at all. It stayed in
FIFO_BYPASSmode (or did not change it, after power on, it assumesFIFO_BYPASSto my interpretation). Thus declaring the IRQ line yes or no, with or without INT names - for the iio driver implementation before this patch series, should not make any difference. It usesFIFO_BYPASSin all cases.The input driver (AFAIR we already agreed on ignoring this driver) needed interrupts. Defining INT names here does not change anything, either. The input driver configures by default INT1 and simply ignores what was specified as INT names in the DT.
I cannot really think of any third case here. Please, let me know if I'm wrong. If not I will keep the above explained behavior, since to my understanding it should match the desired compatibility requirements. Am I wrong here?
Sorry for the late answer. Best,
L
PATCH v7 4/7 iio: accel: adxl345: introduce interrupt handling
In reply to Lothar RubuschAdd the possibility to claim an interrupt. Init the state structure with an interrupt line obtained from the DT. The adxl345 can use two different interrupt lines for event handling. Only one is used.
--- drivers/iio/accel/adxl345_core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/iio/accel/adxl345_core.c +17 -0
@@ -11,15 +11,22 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/units.h> +#include <linux/interrupt.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include "adxl345.h" +#define ADXL345_INT_NONE 0xff +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 +struct adxl345_state { +int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +u8 intio; };#define ADXL345_CHANNEL (index, axis) { \
@@ -213,6 +220,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st =iio_priv (indio_dev); st->regmap = regmap; + st->info =device_get_match_data (dev);if (!st->info)return -ENODEV ;
@@ -263,6 +271,15 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,if (ret <0 )return ret; + st->intio =ADXL345_INT1 ; + st->irq =fwnode_irq_get_byname (dev_fwnode (dev),"INT1" ); +if (st->irq <0 ) { + st->intio =ADXL345_INT2 ; + st->irq =fwnode_irq_get_byname (dev_fwnode (dev),"INT2" ); +if (st->irq <0 ) + st->intio =ADXL345_INT_NONE ; + } +return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_NS_GPL (adxl345_core_probe,IIO_ADXL345 );
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerRe: [PATCH v7 4/7] iio: accel: adxl345: introduce interrupt handling
Quoted 14 lines · On Fri, 13 Dec 2024 21:19:06 +0000 Lothar Rubusch <[email protected]> wrote:
Add the possibility to claim an interrupt. Init the state structure with an interrupt line obtained from the DT. The adxl345 can use two different interrupt lines for event handling. Only one is used.
Signed-off-by Lothar Rubusch <[email protected]>--- drivers/iio/accel/adxl345_core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/iio/accel/adxl345_core.c +0
-0
drivers/iio/accel/adxl345_core.c line 14
Quoted 4 lines
drivers/iio/accel/adxl345_core.c +1
-0@@ -11,15 +11,22 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/units.h> +#include <linux/interrupt.h>
Keep to local style. Headers in alphabetical order (with IIO ones separate obviously!)
drivers/iio/accel/adxl345_core.c line 26
Quoted 12 lines
drivers/iio/accel/adxl345_core.c +5
-0#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include "adxl345.h" +#define ADXL345_INT_NONE 0xff +#define ADXL345_INT1 0 +#define ADXL345_INT2 1 +struct adxl345_state { +int irq;
Whilst it doesn't really matter. I'm not seeing any logic in having this as first element and intio as last. Might as well put them both at the end.
drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 223
Quoted 11 lines
drivers/iio/accel/adxl345_core.c +2
-0const struct adxl345_chip_info *info;struct regmap *regmap; +u8 intio; };#define ADXL345_CHANNEL (index, axis) { \@@ -213,6 +220,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st =iio_priv (indio_dev); st->regmap = regmap; +
Check patches for unrelated changes like this and drop them as they are noise. If you want to tidy this sort of whitespace up, separate patch.
Quoted 4 lines
drivers/iio/accel/adxl345_core.c +0
-0st->info =device_get_match_data (dev);if (!st->info)return -ENODEV ;
drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 280
Quoted 10 lines
drivers/iio/accel/adxl345_core.c +7
-0@@ -263,6 +271,15 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,if (ret <0 )return ret; + st->intio =ADXL345_INT1 ; + st->irq =fwnode_irq_get_byname (dev_fwnode (dev),"INT1" ); +if (st->irq <0 ) { + st->intio =ADXL345_INT2 ; + st->irq =fwnode_irq_get_byname (dev_fwnode (dev),"INT2" ); +if (st->irq <0 ) + st->intio =ADXL345_INT_NONE ;
As in the DT binding, maybe we can fall back to an assumption of default. So if interrupt names missing we assume INT1.
Quoted 5 lines
drivers/iio/accel/adxl345_core.c +2
-0+ } +return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_NS_GPL (adxl345_core_probe,IIO_ADXL345 );
PATCH v7 5/7 iio: accel: adxl345: initialize FIFO delay value for SPI
In reply to Lothar RubuschAdd the possibility to delay FIFO access when SPI is used. According to the datasheet this is needed for the adxl345. When initialization happens over SPI the need for delay is to be signalized, and the delay will be used.
--- drivers/iio/accel/adxl345.h | 1 + drivers/iio/accel/adxl345_core.c | 12 ++++++++++++ drivers/iio/accel/adxl345_i2c.c | 2 +- drivers/iio/accel/adxl345_spi.c | 7 +++++-- 4 files changed, 19 insertions(+), 3 deletions(-)
drivers/iio/accel/adxl345.h +1 -0
@@ -62,6 +62,7 @@ struct adxl345_chip_info { };int adxl345_core_probe (struct device *dev,struct regmap *regmap, +bool fifo_delay_default,int (*setup)(struct device *,struct regmap *));#endif /* _ADXL345_H_ */
drivers/iio/accel/adxl345_core.c +12 -0
@@ -26,6 +26,7 @@ struct adxl345_state {int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +bool fifo_delay;/* delay: delay is needed for SPI */ u8 intio; };
@@ -197,12 +198,21 @@ static const struct iio_info adxl345_info = {* adxl345_core_probe() - Probe and setup for the accelerometer. * @dev: Driver model representation of the device * @regmap: Regmap instance for the device +* @fifo_delay_default: Using FIFO with SPI needs delay * @setup: Setup routine to be executed right before the standard device * setup * +* For SPI operation greater than 1.6 MHz, it is necessary to deassert the CS +* pin to ensure a total delay of 5 us; otherwise, the delay is not sufficient. +* The total delay necessary for 5 MHz operation is at most 3.4 us. This is not +* a concern when using I2C mode because the communication rate is low enough +* to ensure a sufficient delay between FIFO reads. +* Ref: "Retrieving Data from FIFO", p. 21 of 36, Data Sheet ADXL345 Rev. G +* * Return: 0 on success, negative errno on error */ int adxl345_core_probe (struct device *dev,struct regmap *regmap, +bool fifo_delay_default,int (*setup)(struct device *,struct regmap *)) {struct adxl345_state *st;
@@ -225,6 +235,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,if (!st->info)return -ENODEV ; + st->fifo_delay = fifo_delay_default; + indio_dev->name = st->info->name; indio_dev->info = &adxl345_info; indio_dev->modes =INDIO_DIRECT_MODE ;
drivers/iio/accel/adxl345_i2c.c +1 -1
@@ -27,7 +27,7 @@ static int adxl345_i2c_probe(struct i2c_client *client)if (IS_ERR (regmap))return dev_err_probe (&client->dev,PTR_ERR (regmap),"Error initializing regmap\n" ); -return adxl345_core_probe (&client->dev, regmap,NULL ); +return adxl345_core_probe (&client->dev, regmap, false,NULL ); }static const struct adxl345_chip_info adxl345_i2c_info = {
drivers/iio/accel/adxl345_spi.c +5 -2
@@ -12,6 +12,7 @@#include "adxl345.h" #define ADXL345_MAX_SPI_FREQ_HZ 5000000 +#define ADXL345_MAX_FREQ_NO_FIFO_DELAY 1500000static const struct regmap_config adxl345_spi_regmap_config = { .reg_bits =8 ,
@@ -28,6 +29,7 @@ static int adxl345_spi_setup(struct device *dev, struct regmap *regmap)static int adxl345_spi_probe (struct spi_device *spi) {struct regmap *regmap; +bool needs_delay;/* Bail out if max_speed_hz exceeds 5 MHz */ if (spi->max_speed_hz >ADXL345_MAX_SPI_FREQ_HZ )
@@ -38,10 +40,11 @@ static int adxl345_spi_probe(struct spi_device *spi)if (IS_ERR (regmap))return dev_err_probe (&spi->dev,PTR_ERR (regmap),"Error initializing regmap\n" ); + needs_delay = spi->max_speed_hz >ADXL345_MAX_FREQ_NO_FIFO_DELAY ;if (spi->mode &SPI_3WIRE ) -return adxl345_core_probe (&spi->dev, regmap, adxl345_spi_setup); +return adxl345_core_probe (&spi->dev, regmap, needs_delay, adxl345_spi_setup);else -return adxl345_core_probe (&spi->dev, regmap,NULL ); +return adxl345_core_probe (&spi->dev, regmap, needs_delay,NULL ); }static const struct adxl345_chip_info adxl345_spi_info = {
Signature · 1 line
2.39.5
PATCH v7 6/7 iio: accel: adxl345: add FIFO with watermark events
In reply to Lothar RubuschAdd a basic setup for FIFO with configurable watermark. Add a handler for watermark interrupt events and extend the channel for the scan_index needed for the iio channel. The sensor is configurable to use a FIFO_BYPASSED mode or a FIFO_STREAM mode. For the FIFO_STREAM mode now a watermark can be configured, or disabled by setting 0. Further features require a working FIFO setup.
--- drivers/iio/accel/adxl345.h | 27 ++- drivers/iio/accel/adxl345_core.c | 308 ++++++++++++++++++++++++++++++- 2 files changed, 324 insertions(+), 11 deletions(-)
drivers/iio/accel/adxl345.h +21 -6
@@ -15,18 +15,32 @@#define ADXL345_REG_OFS_AXIS (index) (ADXL345_REG_OFSX + (index))#define ADXL345_REG_BW_RATE 0x2C#define ADXL345_REG_POWER_CTL 0x2D +#define ADXL345_REG_INT_ENABLE 0x2E +#define ADXL345_REG_INT_MAP 0x2F +#define ADXL345_REG_INT_SOURCE 0x30 +#define ADXL345_REG_INT_SOURCE_MSK 0xFF#define ADXL345_REG_DATA_FORMAT 0x31 -#define ADXL345_REG_DATAX0 0x32 -#define ADXL345_REG_DATAY0 0x34 -#define ADXL345_REG_DATAZ0 0x36 -#define ADXL345_REG_DATA_AXIS (index) \ - (ADXL345_REG_DATAX0 + (index) * sizeof(__le16)) +#define ADXL345_REG_XYZ_BASE 0x32 +#define ADXL345_REG_DATA_AXIS (index) \ + (ADXL345_REG_XYZ_BASE + (index) * sizeof(__le16)) +#define ADXL345_REG_FIFO_CTL 0x38 +#define ADXL345_REG_FIFO_STATUS 0x39 +#define ADXL345_REG_FIFO_STATUS_MSK 0x3F + +#define ADXL345_FIFO_CTL_SAMPLES (x) FIELD_PREP(GENMASK(4, 0), x) +/* 0: INT1, 1: INT2 */ +#define ADXL345_FIFO_CTL_TRIGGER (x) FIELD_PREP(BIT(5), x) +#define ADXL345_FIFO_CTL_MODE (x) FIELD_PREP(GENMASK(7, 6), x) + +#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_WATERMARK BIT(1) +#define ADXL345_INT_OVERRUN BIT(0)#define ADXL345_BW_RATE GENMASK(3, 0)#define ADXL345_BASE_RATE_NANO_HZ 97656250LL -#define ADXL345_POWER_CTL_MEASURE BIT(3)#define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_MEASURE BIT(3)#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0)/* Set the g range */ #define ADXL345_DATA_FORMAT_JUSTIFY BIT(2)/* Left-justified (MSB) mode */
@@ -40,6 +54,7 @@#define ADXL345_DATA_FORMAT_16G 3#define ADXL345_DEVID 0xE5 +#define ADXL345_FIFO_SIZE 32/* * In full-resolution mode, scale factor is maintained at ~4 mg/LSB
drivers/iio/accel/adxl345_core.c +303 -5
374 lines not on this page · raw message
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerRe: [PATCH v7 6/7] iio: accel: adxl345: add FIFO with watermark events
Quoted 8 lines · On Fri, 13 Dec 2024 21:19:08 +0000 Lothar Rubusch <[email protected]> wrote:
Add a basic setup for FIFO with configurable watermark. Add a handler for watermark interrupt events and extend the channel for the
scan_indexneeded for the iio channel. The sensor is configurable to use aFIFO_BYPASSEDmode or aFIFO_STREAMmode. For theFIFO_STREAMmode now a watermark can be configured, or disabled by setting 0. Further features require a working FIFO setup.Signed-off-by Lothar Rubusch <[email protected]>
I missed a theoretical bug around the dma buffer in previous reviews. A few other minor things inline.
Thanks,
Jonathan
Quoted 25 lines
/*
* In full-resolution mode, scale factor is maintained at ~4 mg/LSBdrivers/iio/accel/adxl345_core.c +8
-0@@ -15,9 +15,17 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> +#include <linux/iio/buffer.h> +#include <linux/iio/kfifo_buf.h> #include "adxl345.h" +#define ADXL345_FIFO_BYPASS 0 +#define ADXL345_FIFO_FIFO 1 +#define ADXL345_FIFO_STREAM 2 + +#define ADXL345_DIRS 3 +#define ADXL345_INT_NONE 0xff#define ADXL345_INT1 0#define ADXL345_INT2 1
drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 37
Quoted 4 lines
drivers/iio/accel/adxl345_core.c +1
-0@@ -26,27 +34,68 @@ struct adxl345_state {int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +__le16 fifo_buf[ADXL345_DIRS *ADXL345_FIFO_SIZE +1 ];
Ah. The old corner case (sorry I missed this in earlier reviews!)
In theory at least regmap makes no additional guarantees on how it uses buffers on top of those provided by the underlying busses.
So we need to treat bulk reads the same way we do for those buses. That means we need to allow for direct DMA writes into the buffers we pass to bulk read. For that to be safe on all architectures (and not accidentally overwrite stuff in the same cacheline) we need to use what is known as a DMA safe buffer.
Long ago we contrived the data layout in IIO to make that easy to do. Just move it down to the end of this structure as...
drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 42
Quoted 5 lines
drivers/iio/accel/adxl345_core.c +3
-0bool fifo_delay;/* delay: delay is needed for SPI */ u8 intio; +u8 int_map; +u8 watermark; +u8 fifo_mode;
this
__le16 fifo_buf[ADXL345_DIRS * ADXL345_FIFO_SIZE + 1] __aligned(IIO_DMA_MINALIGN);
This structure already has the appropriate alignment (there is padding inserted in the allocation to make that true) so by doing this for the element we ask the compiler to make sure it adds sufficient padding before this element to ensure nothing else is in the same cacheline (if required by a particular
architecture). C also guarantees that the structure itself is large enough
to ensure padding is added after this element such that the overall structure size is a multiple of it's most aligned element (this one).
Thus we end up with the buffer in it's own cacheline and none of the mess of non coherent DMA can cause us problems.
If interested in learning more look for Wolfram's talk at ELCE a number of years back on trying to do DMA into the buffers passed to I2C calls.
The 'in theory' bit is because last time I checked regmap is always bounce buffering the data but there are obvious optimizations that could be made so it didn't bounce. A long back we asked the maintainer about this and he said definitely don't assume it won't use the buffers directly.
Note on arm64 for instance there is magic code that bounces all small DMA transfers, but that is not enabled on all architectures yet.
drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 75
Quoted 6 lines
drivers/iio/accel/adxl345_core.c +3
-0}; +static const unsigned long adxl345_scan_masks[] = { +BIT (chan_x) |BIT (chan_y) |BIT (chan_z), +0 ,
Trivial but drop that trailing comma. It's a terminator so we don't want to make it easy for anyone to accidentally put anything after it!
Quoted 7 lines
drivers/iio/accel/adxl345_core.c +1
-0+};static int adxl345_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)@@ -132,6 +181,25 @@ static int adxl345_write_raw(struct iio_dev *indio_dev,return -EINVAL ;
drivers/iio/accel/adxl345_core.c static int adxl345_write_raw(struct iio_dev *indio_dev, · line 191
Quoted 10 lines
drivers/iio/accel/adxl345_core.c +8
-0} +static int adxl345_set_watermark (struct iio_dev *indio_dev,unsigned int value) +{ +struct adxl345_state *st =iio_priv (indio_dev); +unsigned int fifo_mask =0x1F ; +int ret; + +if (value >ADXL345_FIFO_SIZE ) + value =ADXL345_FIFO_SIZE -1 ;
value = min(value, AD345_FIFO_SIZE - 1);
Shorter and maybe a tiny bit more readable. (trivial comment!)
Quoted 15 lines
drivers/iio/accel/adxl345_core.c +10
-0+ + ret =regmap_update_bits (st->regmap,ADXL345_REG_FIFO_CTL , fifo_mask, value); +if (ret) +return ret; + + st->watermark = value; + st->int_map |=ADXL345_INT_WATERMARK ; + +return 0 ; +}/**
drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 502
Quoted 4 lines
drivers/iio/accel/adxl345_core.c +1
-0@@ -222,6 +499,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,ADXL345_DATA_FORMAT_JUSTIFY |ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); +u8 fifo_ctl;
Might as well make this declaration local to where it's used.
Quoted 14 lines
drivers/iio/accel/adxl345_core.c +1
-0int ret; indio_dev =devm_iio_device_alloc (dev,sizeof (*st));@@ -242,6 +520,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->channels = adxl345_channels; indio_dev->num_channels =ARRAY_SIZE (adxl345_channels); + indio_dev->available_scan_masks = adxl345_scan_masks;if (setup) {/* Perform optional initial bus specific configuration */ @@ -292,6 +571,25 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st->intio =ADXL345_INT_NONE ; }
drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 582
Quoted 10 lines
drivers/iio/accel/adxl345_core.c +9
-0+if (st->intio !=ADXL345_INT_NONE ) { +/* FIFO_STREAM mode is going to be activated later */ + ret =devm_iio_kfifo_buffer_setup (dev, indio_dev, &adxl345_buffer_ops); +if (ret) +return ret; + + ret =devm_request_threaded_irq (dev, st->irq,NULL , &adxl345_irq_handler, +IRQF_SHARED |IRQF_ONESHOT , + indio_dev->name, indio_dev);
ret = devm_request_threaded_irq(dev, st->irq, NULL, &adxl345_irq_handler, IRQF_SHARED | IRQF_ONESHOT, indio_dev->name, indio_dev);
All under 80 chars (still the preference when no reason to do otherwise) and aligned with opening bracket which is preferred kernel style when there is no reason to do otherwise.
If you weren't going to be doing a v8 anyway I'd just tweak this whilst applying but seeing as you are... :)
Quoted 13 lines
drivers/iio/accel/adxl345_core.c +10
-0+if (ret) +return ret; + }else { +/* FIFO_BYPASS mode */ + fifo_ctl =ADXL345_FIFO_CTL_MODE (ADXL345_FIFO_BYPASS ); + ret =regmap_write (st->regmap,ADXL345_REG_FIFO_CTL , fifo_ctl); +if (ret <0 ) +return ret; + } +return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_NS_GPL (adxl345_core_probe,IIO_ADXL345 );
Re: [PATCH v7 6/7] iio: accel: adxl345: add FIFO with watermark events
Quoted 84 lines · Jonathan Cameron
Quoted 8 lines · On Fri, 13 Dec 2024 21:19:08 +0000 Lothar Rubusch <[email protected]> wrote:
Add a basic setup for FIFO with configurable watermark. Add a handler for watermark interrupt events and extend the channel for the
scan_indexneeded for the iio channel. The sensor is configurable to use aFIFO_BYPASSEDmode or aFIFO_STREAMmode. For theFIFO_STREAMmode now a watermark can be configured, or disabled by setting 0. Further features require a working FIFO setup.Signed-off-by Lothar Rubusch <[email protected]>I missed a theoretical bug around the dma buffer in previous reviews. A few other minor things inline.
Thanks,
Jonathan
Quoted 25 lines
/*
* In full-resolution mode, scale factor is maintained at ~4 mg/LSBdrivers/iio/accel/adxl345_core.c +8
-0@@ -15,9 +15,17 @@#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> +#include <linux/iio/buffer.h> +#include <linux/iio/kfifo_buf.h> #include "adxl345.h" +#define ADXL345_FIFO_BYPASS 0 +#define ADXL345_FIFO_FIFO 1 +#define ADXL345_FIFO_STREAM 2 + +#define ADXL345_DIRS 3 +#define ADXL345_INT_NONE 0xff#define ADXL345_INT1 0#define ADXL345_INT2 1drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 37
Quoted 4 lines
drivers/iio/accel/adxl345_core.c +1
-0@@ -26,27 +34,68 @@ struct adxl345_state {int irq;const struct adxl345_chip_info *info;struct regmap *regmap; +__le16 fifo_buf[ADXL345_DIRS *ADXL345_FIFO_SIZE +1 ];Ah. The old corner case (sorry I missed this in earlier reviews!)
In theory at least regmap makes no additional guarantees on how it uses buffers on top of those provided by the underlying busses.
So we need to treat bulk reads the same way we do for those buses. That means we need to allow for direct DMA writes into the buffers we pass to bulk read. For that to be safe on all architectures (and not accidentally overwrite stuff in the same cacheline) we need to use what is known as a DMA safe buffer.
Long ago we contrived the data layout in IIO to make that easy to do. Just move it down to the end of this structure as...drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 42
Quoted 5 lines
drivers/iio/accel/adxl345_core.c +3
-0bool fifo_delay;/* delay: delay is needed for SPI */ u8 intio; +u8 int_map; +u8 watermark; +u8 fifo_mode;this
__le16 fifo_buf[ADXL345_DIRS * ADXL345_FIFO_SIZE + 1] __aligned(IIO_DMA_MINALIGN);This structure already has the appropriate alignment (there is padding inserted in the allocation to make that true) so by doing this for the element we ask the compiler to make sure it adds sufficient padding before this element to ensure nothing else is in the same cacheline (if required by a particular
architecture). C also guarantees that the structure itself is large enough
to ensure padding is added after this element such that the overall structure size is a multiple of it's most aligned element (this one).
Thus we end up with the buffer in it's own cacheline and none of the mess of non coherent DMA can cause us problems.If interested in learning more look for Wolfram's talk at ELCE a number of years back on trying to do DMA into the buffers passed to I2C calls.
Quoted 7 lines
The 'in theory' bit is because last time I checked regmap is always bounce buffering the data but there are obvious optimizations that could be made so it didn't bounce. A long back we asked the maintainer about this and he said definitely don't assume it won't use the buffers directly.
Note on arm64 for instance there is magic code that bounces all small DMA transfers, but that is not enabled on all architectures yet.
Initially, I just copied the buffer definition for the fifo_buf from other drivers, inclusively the DMA alignment. In the hope 'probably works similarly' adn without further understanding how the makro works. Surely w/o knowing how to further verify, that it actually was working.
When you remarked that my usage of the DMA alignment never could work that way. I noticed that it was (probably) actually not even needed to explicitely declare an IIO_DMA_MINALIGN, at least for my setup. So, to not make it overly complicated, I simply dropped it.
I probably should have asked more questions, you now answered in detail. I appreciate.
Quoted 105 lines
drivers/iio/accel/adxl345_core.c struct adxl345_state { · line 75
Quoted 6 lines
drivers/iio/accel/adxl345_core.c +3
-0}; +static const unsigned long adxl345_scan_masks[] = { +BIT (chan_x) |BIT (chan_y) |BIT (chan_z), +0 ,Trivial but drop that trailing comma. It's a terminator so we don't want to make it easy for anyone to accidentally put anything after it!
Quoted 7 lines
drivers/iio/accel/adxl345_core.c +1
-0+};static int adxl345_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)@@ -132,6 +181,25 @@ static int adxl345_write_raw(struct iio_dev *indio_dev,return -EINVAL ;drivers/iio/accel/adxl345_core.c static int adxl345_write_raw(struct iio_dev *indio_dev, · line 191
Quoted 10 lines
drivers/iio/accel/adxl345_core.c +8
-0} +static int adxl345_set_watermark (struct iio_dev *indio_dev,unsigned int value) +{ +struct adxl345_state *st =iio_priv (indio_dev); +unsigned int fifo_mask =0x1F ; +int ret; + +if (value >ADXL345_FIFO_SIZE ) + value =ADXL345_FIFO_SIZE -1 ;value = min(value, AD345_FIFO_SIZE - 1);Shorter and maybe a tiny bit more readable. (trivial comment!)
Quoted 15 lines
drivers/iio/accel/adxl345_core.c +10
-0+ + ret =regmap_update_bits (st->regmap,ADXL345_REG_FIFO_CTL , fifo_mask, value); +if (ret) +return ret; + + st->watermark = value; + st->int_map |=ADXL345_INT_WATERMARK ; + +return 0 ; +}/** drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 502
Quoted 4 lines
drivers/iio/accel/adxl345_core.c +1
-0@@ -222,6 +499,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,ADXL345_DATA_FORMAT_JUSTIFY |ADXL345_DATA_FORMAT_FULL_RES | ADXL345_DATA_FORMAT_SELF_TEST); +u8 fifo_ctl;Might as well make this declaration local to where it's used.
Quoted 14 lines
drivers/iio/accel/adxl345_core.c +1
-0int ret; indio_dev =devm_iio_device_alloc (dev,sizeof (*st));@@ -242,6 +520,7 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, indio_dev->modes =INDIO_DIRECT_MODE ; indio_dev->channels = adxl345_channels; indio_dev->num_channels =ARRAY_SIZE (adxl345_channels); + indio_dev->available_scan_masks = adxl345_scan_masks;if (setup) {/* Perform optional initial bus specific configuration */ @@ -292,6 +571,25 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap, st->intio =ADXL345_INT_NONE ; }drivers/iio/accel/adxl345_core.c int adxl345_core_probe(struct device *dev, struct regmap *regmap, · line 582
Quoted 10 lines
drivers/iio/accel/adxl345_core.c +9
-0+if (st->intio !=ADXL345_INT_NONE ) { +/* FIFO_STREAM mode is going to be activated later */ + ret =devm_iio_kfifo_buffer_setup (dev, indio_dev, &adxl345_buffer_ops); +if (ret) +return ret; + + ret =devm_request_threaded_irq (dev, st->irq,NULL , &adxl345_irq_handler, +IRQF_SHARED |IRQF_ONESHOT , + indio_dev->name, indio_dev);ret = devm_request_threaded_irq(dev, st->irq, NULL, &adxl345_irq_handler, IRQF_SHARED | IRQF_ONESHOT, indio_dev->name, indio_dev);All under 80 chars (still the preference when no reason to do otherwise) and aligned with opening bracket which is preferred kernel style when there is no reason to do otherwise.
If you weren't going to be doing a v8 anyway I'd just tweak this whilst applying but seeing as you are... :)
Quoted 13 lines
drivers/iio/accel/adxl345_core.c +10
-0+if (ret) +return ret; + }else { +/* FIFO_BYPASS mode */ + fifo_ctl =ADXL345_FIFO_CTL_MODE (ADXL345_FIFO_BYPASS ); + ret =regmap_write (st->regmap,ADXL345_REG_FIFO_CTL , fifo_ctl); +if (ret <0 ) +return ret; + } +return devm_iio_device_register (dev, indio_dev); }EXPORT_SYMBOL_NS_GPL (adxl345_core_probe,IIO_ADXL345 );
PATCH v7 7/7 iio: accel: adxl345: complete the list of defines
In reply to Lothar RubuschHaving interrupts events and FIFO available allows to evaluate the sensor events. Cover the list of interrupt based sensor events. Keep them in the header file for readability.
--- drivers/iio/accel/adxl345.h | 57 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-)
drivers/iio/accel/adxl345.h +51 -6
@@ -9,10 +9,35 @@#define _ADXL345_H_#define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D#define ADXL345_REG_OFSX 0x1E#define ADXL345_REG_OFSY 0x1F#define ADXL345_REG_OFSZ 0x20#define ADXL345_REG_OFS_AXIS (index) (ADXL345_REG_OFSX + (index)) + +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C#define ADXL345_REG_POWER_CTL 0x2D#define ADXL345_REG_INT_ENABLE 0x2E
@@ -34,20 +59,40 @@#define ADXL345_FIFO_CTL_MODE (x) FIELD_PREP(GENMASK(7, 6), x)#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2)#define ADXL345_INT_WATERMARK BIT(1)#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +/* +* BW_RATE bits - Bandwidth and output data rate. The default value is +* 0x0A, which translates to a 100 Hz output data rate +*/ #define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4)#define ADXL345_BASE_RATE_NANO_HZ 97656250LL#define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2)#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) -#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0)/* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2)/* Left-justified (MSB) mode */ -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3)/* Up to 13-bits resolution */ -#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6)/* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)/* Enable a self test */ - +/* Set the g range */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) +/* Data is left justified */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) +/* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) +#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)#define ADXL345_DATA_FORMAT_2G 0#define ADXL345_DATA_FORMAT_4G 1#define ADXL345_DATA_FORMAT_8G 2
Signature · 1 line
2.39.5
Jonathan Cameron
maintainerRe: [PATCH v7 7/7] iio: accel: adxl345: complete the list of defines
Quoted 3 lines · On Fri, 13 Dec 2024 21:19:09 +0000 Lothar Rubusch <[email protected]> wrote:
Having interrupts events and FIFO available allows to evaluate the sensor events. Cover the list of interrupt based sensor events. Keep them in the header file for readability.
That makes sense for now, but longer term I'd attempt to restrict the scope of these by moving them to the top of core.c
The two bus drivers don't use any of them that I can immediately spot and if they do it is likely to be very few.
That may be a good first patch for your next series.
Jonathan
Quoted 93 lines
Signed-off-by Lothar Rubusch <[email protected]>--- drivers/iio/accel/adxl345.h | 57 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-)drivers/iio/accel/adxl345.h +51
-6@@ -9,10 +9,35 @@#define _ADXL345_H_#define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D#define ADXL345_REG_OFSX 0x1E#define ADXL345_REG_OFSY 0x1F#define ADXL345_REG_OFSZ 0x20#define ADXL345_REG_OFS_AXIS (index) (ADXL345_REG_OFSX + (index)) + +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C#define ADXL345_REG_POWER_CTL 0x2D#define ADXL345_REG_INT_ENABLE 0x2E@@ -34,20 +59,40 @@#define ADXL345_FIFO_CTL_MODE (x) FIELD_PREP(GENMASK(7, 6), x)#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2)#define ADXL345_INT_WATERMARK BIT(1)#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +/* +* BW_RATE bits - Bandwidth and output data rate. The default value is +* 0x0A, which translates to a 100 Hz output data rate +*/ #define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4)#define ADXL345_BASE_RATE_NANO_HZ 97656250LL#define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2)#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) -#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0)/* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2)/* Left-justified (MSB) mode */ -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3)/* Up to 13-bits resolution */ -#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6)/* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)/* Enable a self test */ - +/* Set the g range */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) +/* Data is left justified */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) +/* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) +#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)#define ADXL345_DATA_FORMAT_2G 0#define ADXL345_DATA_FORMAT_4G 1#define ADXL345_DATA_FORMAT_8G 2
Re: [PATCH v7 7/7] iio: accel: adxl345: complete the list of defines
Quoted 8 lines · Jonathan Cameron
Quoted 3 lines · On Fri, 13 Dec 2024 21:19:09 +0000 Lothar Rubusch <[email protected]> wrote:
Having interrupts events and FIFO available allows to evaluate the sensor events. Cover the list of interrupt based sensor events. Keep them in the header file for readability.
Quoted 7 lines
That makes sense for now, but longer term I'd attempt to restrict the scope of these by moving them to the top of
core.cThe two bus drivers don't use any of them that I can immediately spot and if they do it is likely to be very few.
That may be a good first patch for your next series.
I understand. Actually in v1 of the series I had a patch to move the defines into _core.c. There were bigger issues, though. Thank you so much for all the feedback the improvements are impressive to me.
Best,
L
Quoted 98 lines
Jonathan
Quoted 93 lines
Signed-off-by Lothar Rubusch <[email protected]>--- drivers/iio/accel/adxl345.h | 57 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-)drivers/iio/accel/adxl345.h +51
-6@@ -9,10 +9,35 @@#define _ADXL345_H_#define ADXL345_REG_DEVID 0x00 +#define ADXL345_REG_THRESH_TAP 0x1D#define ADXL345_REG_OFSX 0x1E#define ADXL345_REG_OFSY 0x1F#define ADXL345_REG_OFSZ 0x20#define ADXL345_REG_OFS_AXIS (index) (ADXL345_REG_OFSX + (index)) + +/* Tap duration */ +#define ADXL345_REG_DUR 0x21 +/* Tap latency */ +#define ADXL345_REG_LATENT 0x22 +/* Tap window */ +#define ADXL345_REG_WINDOW 0x23 +/* Activity threshold */ +#define ADXL345_REG_THRESH_ACT 0x24 +/* Inactivity threshold */ +#define ADXL345_REG_THRESH_INACT 0x25 +/* Inactivity time */ +#define ADXL345_REG_TIME_INACT 0x26 +/* Axis enable control for activity and inactivity detection */ +#define ADXL345_REG_ACT_INACT_CTRL 0x27 +/* Free-fall threshold */ +#define ADXL345_REG_THRESH_FF 0x28 +/* Free-fall time */ +#define ADXL345_REG_TIME_FF 0x29 +/* Axis control for single tap or double tap */ +#define ADXL345_REG_TAP_AXIS 0x2A +/* Source of single tap or double tap */ +#define ADXL345_REG_ACT_TAP_STATUS 0x2B +/* Data rate and power mode control */ #define ADXL345_REG_BW_RATE 0x2C#define ADXL345_REG_POWER_CTL 0x2D#define ADXL345_REG_INT_ENABLE 0x2E@@ -34,20 +59,40 @@#define ADXL345_FIFO_CTL_MODE (x) FIELD_PREP(GENMASK(7, 6), x)#define ADXL345_INT_DATA_READY BIT(7) +#define ADXL345_INT_SINGLE_TAP BIT(6) +#define ADXL345_INT_DOUBLE_TAP BIT(5) +#define ADXL345_INT_ACTIVITY BIT(4) +#define ADXL345_INT_INACTIVITY BIT(3) +#define ADXL345_INT_FREE_FALL BIT(2)#define ADXL345_INT_WATERMARK BIT(1)#define ADXL345_INT_OVERRUN BIT(0) + +#define ADXL345_S_TAP_MSK ADXL345_INT_SINGLE_TAP +#define ADXL345_D_TAP_MSK ADXL345_INT_DOUBLE_TAP + +/* +* BW_RATE bits - Bandwidth and output data rate. The default value is +* 0x0A, which translates to a 100 Hz output data rate +*/ #define ADXL345_BW_RATE GENMASK(3, 0) +#define ADXL345_BW_LOW_POWER BIT(4)#define ADXL345_BASE_RATE_NANO_HZ 97656250LL#define ADXL345_POWER_CTL_STANDBY 0x00 +#define ADXL345_POWER_CTL_WAKEUP GENMASK(1, 0) +#define ADXL345_POWER_CTL_SLEEP BIT(2)#define ADXL345_POWER_CTL_MEASURE BIT(3) +#define ADXL345_POWER_CTL_AUTO_SLEEP BIT(4) +#define ADXL345_POWER_CTL_LINK BIT(5) -#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0)/* Set the g range */ -#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2)/* Left-justified (MSB) mode */ -#define ADXL345_DATA_FORMAT_FULL_RES BIT(3)/* Up to 13-bits resolution */ -#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6)/* 3-wire SPI mode */ -#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)/* Enable a self test */ - +/* Set the g range */ +#define ADXL345_DATA_FORMAT_RANGE GENMASK(1, 0) +/* Data is left justified */ +#define ADXL345_DATA_FORMAT_JUSTIFY BIT(2) +/* Up to 13-bits resolution */ +#define ADXL345_DATA_FORMAT_FULL_RES BIT(3) +#define ADXL345_DATA_FORMAT_SPI_3WIRE BIT(6) +#define ADXL345_DATA_FORMAT_SELF_TEST BIT(7)#define ADXL345_DATA_FORMAT_2G 0#define ADXL345_DATA_FORMAT_4G 1#define ADXL345_DATA_FORMAT_8G 2