Skip to contentSkip to conversation

ECAP support on TI AM62x SoC

PATCH Superseded Julien Panis 3 participants 6 messages Jul 26, 2022

Subsystems (2)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover ECAP support on TI AM62x SoC

The Enhanced Capture (ECAP) module can be used to timestamp events detected on signal input pin. It can be used for time measurements of pulse train signals.

ECAP module includes 4 timestamp capture registers. For all 4 sequenced timestamp capture events (0->1->2->3->0->...), edge polarity (falling/rising edge) can be selected. Moreover, input signal can be prescaled.

This driver leverages IIO subsystem to :
- select edge polarity for all 4 capture events (event mode)
- log both event index and timestamp for each capture event Event polarity, event indexes, and timestamps give all the information about the input pulse train. Further information can easily be computed :
period and/or duty cycle if frequency is constant, elapsed time between pulses, etc...

Userspace commands :
cd /sys/devices/platform/bus@f0000/23120000.capture/iio\:device2/

# Configure/Enable data buffers
echo 1 > scan_elements/in_index_en
echo 1 > scan_elements/in_timestamp_en
echo 100 > buffer/length
echo 1 > buffer/enable

# Set event mode in range [0 ; 15]
# One bit for each CAPx register : 1 = falling edge / 0 = rising edge # e.g. mode = 13 = 0xd = 0b1101
# -> falling edge for CAP1-3-4 / rising edge for CAP2 echo 13 > events/change_falling_value

# Run ECAP
echo 1 > en

# Get the number of available data
cat buffer/data_available

# Read data
hexdump -v /dev/iio\:device2

# Stop ECAP
echo 0 > en

Julien Panis (2):
iio: time: capture-tiecap: capture driver support for ECAP
dt-binding: iio: time: add capture-tiecap.yaml

 .../bindings/iio/time/capture-tiecap.yaml     |  53 ++
 drivers/iio/Kconfig                           |   1 +
 drivers/iio/Makefile                          |   1 +
 drivers/iio/time/Kconfig                      |  22 +
 drivers/iio/time/Makefile                     |   6 +
 drivers/iio/time/capture-tiecap.c             | 532 ++++++++++++++++++
 6 files changed, 615 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml
 create mode 100644 drivers/iio/time/Kconfig
 create mode 100644 drivers/iio/time/Makefile
 create mode 100644 drivers/iio/time/capture-tiecap.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 iio: time: capture-tiecap: capture driver support for ECAP

ECAP hardware on AM62x SoC supports capture feature. It can be used to timestamp events (falling/rising edges) detected on signal input pin.

This commit adds capture driver support for ECAP hardware on AM62x SoC.

In the ECAP hardware, capture pin can also be configured to be in PWM mode. Current implementation only supports capture operating mode. Hardware also supports timebase sync between multiple instances, but this driver supports simple independent capture functionality.

---
 drivers/iio/Kconfig               |   1 +
 drivers/iio/Makefile              |   1 +
 drivers/iio/time/Kconfig          |  22 ++
 drivers/iio/time/Makefile         |   6 +
 drivers/iio/time/capture-tiecap.c | 532 ++++++++++++++++++++++++++++++
 5 files changed, 562 insertions(+)
 create mode 100644 drivers/iio/time/Kconfig
 create mode 100644 drivers/iio/time/Makefile
 create mode 100644 drivers/iio/time/capture-tiecap.c
drivers/iio/Kconfig +1 -0
index b190846c3dc2..ba11b8824071 100644
@@ -99,5 +99,6 @@ source "drivers/iio/pressure/Kconfig"
 source "drivers/iio/proximity/Kconfig"
 source "drivers/iio/resolver/Kconfig"
 source "drivers/iio/temperature/Kconfig"
+source "drivers/iio/time/Kconfig"
 
 endif # IIO
drivers/iio/Makefile +1 -0
index 3be08cdadd7e..09283402a2c6 100644
@@ -42,4 +42,5 @@ obj-y += proximity/
 obj-y += resolver/
 obj-y += temperature/
 obj-y += test/
+obj-y += time/
 obj-y += trigger/
drivers/iio/time/Kconfig new file +22 -0
new file mode 100644
index 000000000000..02f6cf7ff79e
@@ -0,0 +1,22 @@
+#
+# Time drivers
+#
+
+menu "Time"
+
+config CAPTURE_TIECAP
+	tristate "ECAP capture support"
+	depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE || ARCH_K3 || COMPILE_TEST
+	depends on HAS_IOMEM
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
+	help
+	  IIO driver support for the ECAP capture hardware found on TI SoCs.
+
+	  It can be used to timestamp events (falling/rising edges) detected
+	  on signal input pin.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called capture-tiecap.
+
+endmenu
drivers/iio/time/Makefile new file +6 -0
new file mode 100644
index 000000000000..3a27f3557d1e
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for industrial I/O Time drivers
+#
+
+obj-$(CONFIG_CAPTURE_TIECAP) += capture-tiecap.o
drivers/iio/time/capture-tiecap.c new file +532 -0

532 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 dt-binding: iio: time: add capture-tiecap.yaml

In reply to Julien Panis

This commit adds a YAML binding for TI ECAP used in capture operating mode.

---
 .../bindings/iio/time/capture-tiecap.yaml     | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +53 -0
new file mode 100644
index 000000000000..4f08e49a8506
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/capture-tiecap.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments Enhanced Capture (eCAP) Module
+
+maintainers:
+  - Julien Panis <[email protected]>
+
+description: |
+  The eCAP module resources can be used to capture timestamps
+  on input signal events (falling/rising edges).
+
+properties:
+  compatible:
+    const: ti,am62-ecap-capture
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: fck
+
+  power-domains:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    ecap0: capture@23100000 { /* eCAP in capture mode on am62x */
+        compatible = "ti,am62-ecap-capture";
+        reg = <0x00 0x23100000 0x00 0x100>;
+        interrupts = <GIC_SPI 113 IRQ_TYPE_EDGE_RISING>;
+        power-domains = <&k3_pds 51 TI_SCI_PD_EXCLUSIVE>;
+        clocks = <&k3_clks 51 0>;
+        clock-names = "fck";
+    };
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v1 2/2] dt-binding: iio: time: add capture-tiecap.yaml

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml

Quoted 13 lines · Julien Panis

This commit adds a YAML binding for TI ECAP used in capture operating mode.

---
 .../bindings/iio/time/capture-tiecap.yaml     | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +0 -0
new file mode 100644
index 000000000000..4f08e49a8506

Use filename based on compatible, so:
ti,am62-ecap-capture.yaml

Quoted 41 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +40 -0
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/capture-tiecap.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments Enhanced Capture (eCAP) Module
+
+maintainers:
+  - Julien Panis <[email protected]>
+
+description: |
+  The eCAP module resources can be used to capture timestamps
+  on input signal events (falling/rising edges).
+
+properties:
+  compatible:
+    const: ti,am62-ecap-capture
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: fck
+
+  power-domains:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 50

Quoted 10 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +10 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    ecap0: capture@23100000 { /* eCAP in capture mode on am62x */
+        compatible = "ti,am62-ecap-capture";
+        reg = <0x00 0x23100000 0x00 0x100>;
+        interrupts = <GIC_SPI 113 IRQ_TYPE_EDGE_RISING>;
+        power-domains = <&k3_pds 51 TI_SCI_PD_EXCLUSIVE>;

Does not look like you tested the bindings. Please run make dt_binding_check (see Documentation/devicetree/bindings/writing-schema.rst for instructions).

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 53

Quoted 3 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +3 -0
+        clocks = <&k3_clks 51 0>;
+        clock-names = "fck";
+    };

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v1 2/2] dt-binding: iio: time: add capture-tiecap.yaml

Quoted 63 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml

Quoted 13 lines · Julien Panis

This commit adds a YAML binding for TI ECAP used in capture operating mode.

---
  .../bindings/iio/time/capture-tiecap.yaml     | 53 +++++++++++++++++++
  1 file changed, 53 insertions(+)

create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +0 -0
new file mode 100644
index 000000000000..4f08e49a8506

Use filename based on compatible, so:
ti,am62-ecap-capture.yaml

Quoted 46 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +45 -0
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/capture-tiecap.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments Enhanced Capture (eCAP) Module
+
+maintainers:
+  - Julien Panis <[email protected]>
+
+description: |
+  The eCAP module resources can be used to capture timestamps
+  on input signal events (falling/rising edges).
+
+properties:
+  compatible:
+    const: ti,am62-ecap-capture
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: fck
+
+  power-domains:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
Quoted 8 lines

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 50

Quoted 5 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +5 -0
+    ecap0: capture@23100000 { /* eCAP in capture mode on am62x */
+        compatible = "ti,am62-ecap-capture";
+        reg = <0x00 0x23100000 0x00 0x100>;
+        interrupts = <GIC_SPI 113 IRQ_TYPE_EDGE_RISING>;
+        power-domains = <&k3_pds 51 TI_SCI_PD_EXCLUSIVE>;

Does not look like you tested the bindings. Please run make dt_binding_check (see Documentation/devicetree/bindings/writing-schema.rst for instructions).

I did not indeed, sorry. I thought that checkpath also checked binding.

Thank you for your feedback. I'm going to prepare a new version.

Quoted 7 lines

Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 53

Quoted 4 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +3 -0
+        clocks = <&k3_clks 51 0>;
+        clock-names = "fck";
+    };

Best regards,
Krzysztof

maintainer
#5 lore raw

Re: [PATCH v1 2/2] dt-binding: iio: time: add capture-tiecap.yaml

In reply to Julien Panis
Quoted 8 lines · Julien Panis

This commit adds a YAML binding for TI ECAP used in capture operating mode.

---
 .../bindings/iio/time/capture-tiecap.yaml     | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml: $id: relative path/filename doesn't match actual path or filename
expected: http://devicetree.org/schemas/iio/time/capture-tiecap.yaml#
Error: Documentation/devicetree/bindings/iio/time/capture-tiecap.example.dts:24.27-28 syntax error
FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:383: Documentation/devicetree/bindings/iio/time/capture-tiecap.example.dtb] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1404: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

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.