ECAP support on TI AM62x SoC
Subsystems (2)
v2 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...
Modifications since v1:
- Fix yaml issues (id and example)
- Use regmap instead of writel/readl
- Enable/Disable clock explicitly
- Simplify power management (suspend/resume)
- Remove unnecessary using of ev_mode variable
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):
dt-binding: iio: time: add capture-tiecap.yaml
iio: time: capture-tiecap: capture driver support for ECAP
.../bindings/iio/time/capture-tiecap.yaml | 68 +++ drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/time/Kconfig | 22 + drivers/iio/time/Makefile | 6 + drivers/iio/time/capture-tiecap.c | 521 ++++++++++++++++++ 6 files changed, 619 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
PATCH v2 1/2 dt-binding: iio: time: add capture-tiecap.yaml
This commit adds a YAML binding for TI ECAP used in capture operating mode.
--- .../bindings/iio/time/capture-tiecap.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +68 -0
@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/time/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: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/soc/ti,sci_pm_domain.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + bus@f0000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x20000000 0x00 0x20000000 0x00 0x0a008000>; + + 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
Re: [PATCH v2 1/2] dt-binding: iio: time: add capture-tiecap.yaml
Quoted 14 lines · Julien Panis
This commit adds a YAML binding for TI ECAP used in capture operating mode.
Signed-off-by Julien Panis <[email protected]>--- .../bindings/iio/time/capture-tiecap.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/time/capture-tiecap.yamlDocumentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +0
-0
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 5
Quoted 5 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +5
-0@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/time/capture-tiecap.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml#
Still wrong file name.
Do not ignore comments you received. Either you implement them or you keep the discussion going.
Quoted 6 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +6
-0+ +title: Texas Instruments Enhanced Capture (eCAP) Module + +maintainers: + - Julien Panis <[email protected]> +
(...)
Quoted 5 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +5
-0+ +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/soc/ti,sci_pm_domain.h>
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +10
-0+ + soc { + #address-cells = <2>; + #size-cells = <2>; + + bus@f0000 { + compatible = "simple-bus"; + #address-cells = <2>; + #size-cells = <2>; + ranges = <0x00 0x20000000 0x00 0x20000000 0x00 0x0a008000>;
A bit too many nodes. Just keep one, bus or soc. Look at other examples.
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-binding: iio: time: add capture-tiecap.yaml
Quoted 22 lines · Krzysztof Kozlowski
Quoted 14 lines · Julien Panis
This commit adds a YAML binding for TI ECAP used in capture operating mode.
Signed-off-by Julien Panis <[email protected]>--- .../bindings/iio/time/capture-tiecap.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/time/capture-tiecap.yamlDocumentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +0
-0Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml line 5
Quoted 5 lines
Documentation/devicetree/bindings/iio/time/capture-tiecap.yaml new file +5
-0@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/time/capture-tiecap.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml#Still wrong file name.
Quoted 2 lines
Do not ignore comments you received. Either you implement them or you keep the discussion going.
Sorry, that was not intentional. I have prepared a new version which takes into account your last comments.
Julien
PATCH v2 2/2 iio: time: capture-tiecap: capture driver support for ECAP
In reply to Julien PanisECAP 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 | 521 ++++++++++++++++++++++++++++++ 5 files changed, 551 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
@@ -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
@@ -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
@@ -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
@@ -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 +521 -0
521 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] iio: time: capture-tiecap: capture driver support for ECAP
Quoted 6 lines · Julien Panis
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
Thank you for your patch. There is something to discuss/improve.
(...)
drivers/iio/time/capture-tiecap.c line 366
Quoted 11 lines
drivers/iio/time/capture-tiecap.c new file +11
-0+static int ecap_iio_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct ecap_iio_dev *ecap_dev; +struct iio_dev *indio_dev; +void __iomem *mmio_base; +int ret; + + indio_dev =devm_iio_device_alloc (dev,sizeof (*ecap_dev)); +if (IS_ERR (indio_dev)) { +dev_err (dev,"failed to allocate memory for iio device\n" );
Do not print messages, which core takes care of.
Quoted 27 lines
drivers/iio/time/capture-tiecap.c new file +27
-0+return PTR_ERR (indio_dev); + } + + ecap_dev =iio_priv (indio_dev); + + ecap_dev->clk =devm_clk_get (dev,"fck" ); +if (IS_ERR (ecap_dev->clk)) { +dev_err (dev,"failed to get clock\n" ); +return PTR_ERR (ecap_dev->clk); + } + + ret =clk_prepare_enable (ecap_dev->clk); +if (ret) { +dev_err (dev,"failed to enable clock\n" ); +return ret; + } + + ret =devm_add_action_or_reset (dev, ecap_iio_clk_disable, ecap_dev->clk); +if (ret) { +dev_err (dev,"failed to add clock disable action\n" ); +return ret; + } + + ecap_dev->clk_rate =clk_get_rate (ecap_dev->clk); +if (!ecap_dev->clk_rate) { +dev_err (dev,"failed to get clock rate\n" ); +return -EINVAL ;
drivers/iio/time/capture-tiecap.c line 403
Quoted 10 lines
drivers/iio/time/capture-tiecap.c new file +10
-0+ } + +if (prescaler >ECAP_PS_MAX_VAL ) { + prescaler =ECAP_PS_MAX_VAL ; +dev_warn (dev,"prescaler out of range, forced to %d\n" , prescaler); + } + + mmio_base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (mmio_base)) { +dev_err (dev,"failed to remap io\n" );
No need for msg.
Quoted 23 lines
drivers/iio/time/capture-tiecap.c new file +23
-0+return PTR_ERR (mmio_base); + } + + ecap_dev->regmap =regmap_init_mmio (dev, mmio_base, &ecap_iio_regmap_config); +if (IS_ERR (ecap_dev->regmap)) { +dev_err (dev,"failed to init regmap\n" ); +return PTR_ERR (ecap_dev->regmap); + } + + indio_dev->name =devm_kasprintf (dev,GFP_KERNEL , +"ecap-iio-%p" , mmio_base); + indio_dev->info = &ecap_iio_info; + indio_dev->channels = ecap_iio_channels; + indio_dev->num_channels =ARRAY_SIZE (ecap_iio_channels); + indio_dev->modes =INDIO_BUFFER_SOFTWARE ; + + ret =devm_iio_kfifo_buffer_setup_ext (dev, indio_dev,NULL ,NULL ); +if (ret) { +dev_err (dev,"failed to setup iio buffer\n" ); +return ret; + } + + ret =platform_get_irq (pdev,0 );
drivers/iio/time/capture-tiecap.c line 436
Quoted 10 lines
drivers/iio/time/capture-tiecap.c new file +10
-0+if (ret <0 ) { +dev_err (dev,"failed to get irq\n" ); +return ret; + } + + ret =devm_request_irq (dev, ret, ecap_iio_isr,0 , pdev->name, indio_dev); +if (ret) { +dev_err (dev,"failed to request irq\n" ); +return ret; + }
Best regards,
Krzysztof