Skip to contentSkip to conversation

iio: gyro: adxrs290: Add triggered buffer & debugfs support

PATCH RESEND Applied Nishant Malpani 3 participants 7 messages Sep 10, 2020 – Sep 13, 2020

Subsystems (4)
lore
Share & tools
lore

Nishant Malpani

author maintainer
#0 lore raw

v3 cover iio: gyro: adxrs290: Add triggered buffer & debugfs support

Introduce DATA_RDY trigger for triggered buffer setup; this enables continuous data capture. Additionally, add support for direct register access using the debugfs iio interface.

The device-tree bindings documentation illustrates an example of using a GPIO irq line to trigger a data capture.

Nishant Malpani (3):
iio: gyro: adxrs290: Add triggered buffer support
dt-bindings: iio: gyro: adxrs290: Add interrupts support
iio: gyro: adxrs290: Add debugfs register access support

 .../bindings/iio/gyroscope/adi,adxrs290.yaml  |   6 +
 drivers/iio/gyro/Kconfig                      |   2 +
 drivers/iio/gyro/adxrs290.c                   | 237 ++++++++++++++++--
 3 files changed, 231 insertions(+), 14 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH RESEND v3 1/3 iio: gyro: adxrs290: Add triggered buffer support

Provide a way for continuous data capture by setting up buffer support. The data ready signal exposed at the SYNC pin of the ADXRS290 is exploited as a hardware interrupt which triggers to fill the buffer.

Triggered buffer setup was tested with both hardware trigger (DATA_RDY) and software triggers (sysfs-trig & hrtimer).

---

Changes in v3:
- issue a separate precursor patch for the devm resource unwinding hook
- rename labels in the error-path
- use dev_err_probe() (which handles deferred probing) only for calls which request h/w resources

Changes in v2:

- In adxrs290_set_mode(), move 'if' block outside the locked section
- use break statement for error handling instead of goto labels in switch-case blocks
- remove outer parentheses when conditional ternary operator is used
- use dev_err_probe() saving a few lines of code
- re-align 'buffer' variable name in 'struct adxrs290_state'
- don't return errors in 'try_reenable' callback
- use 'st->spi' inline in 'adxrs290_trigger_handler'
- unnecessary to mention default 'shift' (= 0) in iio_chan_spec.scan_type
- bring in consistent wrapping of parameters while staying under the advised 80 chars line limit

---
 drivers/iio/gyro/Kconfig    |   2 +
 drivers/iio/gyro/adxrs290.c | 211 +++++++++++++++++++++++++++++++++---
 2 files changed, 199 insertions(+), 14 deletions(-)
drivers/iio/gyro/Kconfig +2 -0
index 024a34139875..5824f2edf975 100644
@@ -44,6 +44,8 @@ config ADIS16260
 config ADXRS290
 	tristate "Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope SPI driver"
 	depends on SPI
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to build support for Analog Devices ADXRS290 programmable
 	  digital output gyroscope.
drivers/iio/gyro/adxrs290.c +197 -14

319 lines not on this page · raw message

Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH RESEND v3 2/3 dt-bindings: iio: gyro: adxrs290: Add interrupts support

In reply to Nishant Malpani

Include 'interrupts' property and provide a suitable example for using a GPIO interrupt line.

---

Changes in v3:
- remove gpio.h header since unused

Changes in v2:

- remove 'interrupts' property from the required properties list
- rewrite commit message

---
 .../devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml     | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml +6 -0
index 61adb2c2454b..662ec59ca0af 100644
@@ -28,6 +28,9 @@ properties:
 
   spi-cpha: true
 
+  interrupts:
+    maxItems: 1
+
 required:
   - compatible
   - reg
@@ -39,6 +42,7 @@ additionalProperties: false
 
 examples:
   - |
+    #include <dt-bindings/interrupt-controller/irq.h>
     spi {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -48,6 +52,8 @@ examples:
                    spi-max-frequency = <5000000>;
                    spi-cpol;
                    spi-cpha;
+                   interrupt-parent = <&gpio>;
+                   interrupts = <25 IRQ_TYPE_EDGE_RISING>;
         };
     };
 ...
Signature · 1 line
2.20.1
maintainer Applied
#3 lore raw

Re: [RESEND PATCH v3 2/3] dt-bindings: iio: gyro: adxrs290: Add interrupts support

Quoted 4 lines · On Thu, 10 Sep 2020 23:34:49 +0530 Nishant Malpani <[email protected]>…

Include 'interrupts' property and provide a suitable example for using a GPIO interrupt line.

This one is 'so trivial' (famous last words) that I'm not going to wait for Rob H to get to it. Obviously anything Rob wants to add will be most welcome and might beat me pushing this out as non rebasing.

Applied to the togreg branch of iio.git.

Thanks,
Jonathan

Quoted 44 lines

---

Changes in v3:
- remove gpio.h header since unused

Changes in v2:

- remove 'interrupts' property from the required properties list
- rewrite commit message

---
 .../devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml     | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml +6 -0
index 61adb2c2454b..662ec59ca0af 100644
@@ -28,6 +28,9 @@ properties:
 
   spi-cpha: true
 
+  interrupts:
+    maxItems: 1
+
 required:
   - compatible
   - reg
@@ -39,6 +42,7 @@ additionalProperties: false
 
 examples:
   - |
+    #include <dt-bindings/interrupt-controller/irq.h>
     spi {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -48,6 +52,8 @@ examples:
                    spi-max-frequency = <5000000>;
                    spi-cpol;
                    spi-cpha;
+                   interrupt-parent = <&gpio>;
+                   interrupts = <25 IRQ_TYPE_EDGE_RISING>;
         };
     };
...
author maintainer
#4 lore raw

PATCH RESEND v3 3/3 iio: gyro: adxrs290: Add debugfs register access support

In reply to Nishant Malpani

Extend support to read/write byte data from/to the device using debugfs iio interface.

---

Changes in v3:
- refactor code based on Andy's suggestions

No changes in v2

---
 drivers/iio/gyro/adxrs290.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/iio/gyro/adxrs290.c +26 -0
index 41b1f995a143..ca6fc234076e 100644
@@ -436,6 +436,31 @@ static int adxrs290_read_avail(struct iio_dev *indio_dev,
 	}
 }
 
+static int adxrs290_reg_access_rw(struct spi_device *spi, unsigned int reg,
+				  unsigned int *readval)
+{
+	int ret;
+
+	ret = spi_w8r8(spi, ADXRS290_READ_REG(reg));
+	if (ret < 0)
+		return ret;
+
+	*readval = ret;
+
+	return 0;
+}
+
+static int adxrs290_reg_access(struct iio_dev *indio_dev, unsigned int reg,
+			       unsigned int writeval, unsigned int *readval)
+{
+	struct adxrs290_state *st = iio_priv(indio_dev);
+
+	if (readval)
+		return adxrs290_reg_access_rw(st->spi, reg, readval);
+	else
+		return adxrs290_spi_write_reg(st->spi, reg, writeval);
+}
+
 static int adxrs290_data_rdy_trigger_set_state(struct iio_trigger *trig,
 					       bool state)
 {
@@ -551,6 +576,7 @@ static const struct iio_info adxrs290_info = {
 	.read_raw = &adxrs290_read_raw,
 	.write_raw = &adxrs290_write_raw,
 	.read_avail = &adxrs290_read_avail,
+	.debugfs_reg_access = &adxrs290_reg_access,
 };
 
 static int adxrs290_probe_trigger(struct iio_dev *indio_dev)
Signature · 1 line
2.20.1
#5 lore raw
In reply to Nishant Malpani
Quoted 12 lines · On Thu, 10 Sep 2020 23:34:47 +0530 Nishant Malpani <[email protected]>…

Introduce DATA_RDY trigger for triggered buffer setup; this enables continuous data capture. Additionally, add support for direct register access using the debugfs iio interface.

The device-tree bindings documentation illustrates an example of using a GPIO irq line to trigger a data capture.

Nishant Malpani (3):
iio: gyro: adxrs290: Add triggered buffer support
dt-bindings: iio: gyro: adxrs290: Add interrupts support
iio: gyro: adxrs290: Add debugfs register access support

Quoted 5 lines
 .../bindings/iio/gyroscope/adi,adxrs290.yaml  |   6 +
 drivers/iio/gyro/Kconfig                      |   2 +
 drivers/iio/gyro/adxrs290.c                   | 237 ++++++++++++++++--
 3 files changed, 231 insertions(+), 14 deletions(-)

Odd. The original patch one eventually made it (I'd checked it hadn't gotten to me or to lore.kernel.org yesterday :(

Ah well, one of those quirks of life and resend does no harm.

Will catch up with this tomorrow probably.

Jonathan

maintainer
#6 lore raw
Quoted 21 lines · On Fri, 11 Sep 2020 09:14:07 +0100 Jonathan Cameron…
Quoted 12 lines · On Thu, 10 Sep 2020 23:34:47 +0530 Nishant Malpani <[email protected]>…

Introduce DATA_RDY trigger for triggered buffer setup; this enables continuous data capture. Additionally, add support for direct register access using the debugfs iio interface.

The device-tree bindings documentation illustrates an example of using a GPIO irq line to trigger a data capture.

Nishant Malpani (3):
iio: gyro: adxrs290: Add triggered buffer support
dt-bindings: iio: gyro: adxrs290: Add interrupts support
iio: gyro: adxrs290: Add debugfs register access support

Quoted 5 lines
 .../bindings/iio/gyroscope/adi,adxrs290.yaml  |   6 +
 drivers/iio/gyro/Kconfig                      |   2 +
 drivers/iio/gyro/adxrs290.c                   | 237 ++++++++++++++++--
 3 files changed, 231 insertions(+), 14 deletions(-)
Quoted 6 lines

Odd. The original patch one eventually made it (I'd checked it hadn't gotten to me or to lore.kernel.org yesterday :(

Ah well, one of those quirks of life and resend does no harm.

Will catch up with this tomorrow probably.

I picked it up from this resend version because b4 doesn't like the earlier one due to the broken threading. This one has Andy's tags anyway so that all works out nicely.

Thanks,

Jonathan

Quoted 3 lines

Jonathan