ECAP support on TI AM62x SoC
Subsystems (4)
Julien Panis
reviewerv6 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.
This driver leverages counter subsystem to :
- select edge polarity for all 4 capture events (event mode)
- log timestamps for each capture event
Event polarity, and CAP0/1/2/3 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 v5:
- Fix descriptions for capture items in sysfs-bus-counter ABI file
- Modify TI_ECAP_CAPTURE help in Kconfig file
- Replace ecap_event_id enum with defines
- Add callbacks to reset nb_ovf & TSCNT
- Modify action_read callback to serve both clock and input signals
- Modify watch_validate callback
- Replace 'count_cumul' with 'num_overflows' & 'ceiling' components
- Replace one-based index with zero-based index for polarityX & captureX
- Reverse clock & input signal order (0/1)
- Move the check for overflow outside of the for-loop (in ISR)
- Push each CAPx event to respective counter event channels (in ISR)
Userspace commands :
### CLOCK SIGNAL ###
cd /sys/bus/counter/devices/counter0/signal0
# Get frequency
cat frequency
### INPUT SIGNAL ###
cd /sys/bus/counter/devices/counter0/signal1
# Get available polarities for each capture event cat polarity0_available
cat polarity1_available
cat polarity2_available
cat polarity3_available
# Get polarity for each capture event
cat polarity0
cat polarity1
cat polarity2
cat polarity3
# Set polarity for each capture event
echo rising edge > polarity0
echo falling edge > polarity1
echo rising edge > polarity2
echo falling edge > polarity3
### COUNT ###
cd /sys/bus/counter/devices/counter0/count0
# Get ceiling (counter max value)
cat ceiling
# Reset number of overflows & current timebase counter value echo 0 > num_overflows
echo 0 > count
# Run ECAP
echo 1 > enable
# Get number of overflows & current timebase counter value cat num_overflows
cat count
# Get captured timestamps
cat capture0
cat capture1
cat capture2
cat capture3
# Note that counter watches can also be used to get # data from userspace application
# -> see tools/counter/counter_example.c
# Pause ECAP
echo 0 > enable
Julien Panis (3):
dt-bindings: counter: add ti,am62-ecap-capture.yaml
Documentation: ABI: sysfs-bus-counter: add capture items
counter: ti-ecap-capture: capture driver support for ECAP
Documentation/ABI/testing/sysfs-bus-counter | 45 ++ .../counter/ti,am62-ecap-capture.yaml | 61 ++ drivers/counter/Kconfig | 15 + drivers/counter/Makefile | 1 + drivers/counter/ti-ecap-capture.c | 653 ++++++++++++++++++ include/uapi/linux/counter.h | 2 + 6 files changed, 777 insertions(+) create mode 100644 Documentation/devicetree/bindings/counter/ti,am62-ecap-capture.yaml create mode 100644 drivers/counter/ti-ecap-capture.c
Signature · 1 line
2.37.3
Julien Panis
reviewerPATCH v6 1/3 dt-bindings: counter: add ti,am62-ecap-capture.yaml
This commit adds a YAML binding for TI ECAP used in capture operating mode.
--- .../counter/ti,am62-ecap-capture.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/counter/ti,am62-ecap-capture.yaml
Documentation/devicetree/bindings/counter/ti,am62-ecap-capture.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/counter/ti,am62-ecap-capture.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>; + + 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.37.3
Julien Panis
reviewerPATCH v6 2/3 Documentation: ABI: sysfs-bus-counter: add capture items
In reply to Julien PanisThis commit adds capture items to counter ABI file (e.g. TI ECAP used in capture operating mode).
--- Documentation/ABI/testing/sysfs-bus-counter | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+)
Documentation/ABI/testing/sysfs-bus-counter +45 -0
@@ -203,6 +203,19 @@ Description: both edges: Any state transition. +What: /sys/bus/counter/devices/counterX/countY/num_overflows +KernelVersion: 6.0 +Contact: [email protected] +Description: + This attribute indicates the number of overflows since count Y start. + +What: /sys/bus/counter/devices/counterX/countY/captureZ +KernelVersion: 6.0 +Contact: [email protected] +Description: + This read-only attributes is a historical capture of the Count Y count data + where Z (if present) is the respective capture buffer element offset. + What: /sys/bus/counter/devices/counterX/countY/ceiling_component_id What: /sys/bus/counter/devices/counterX/countY/floor_component_id What: /sys/bus/counter/devices/counterX/countY/count_mode_component_id
@@ -213,11 +226,15 @@ What: /sys/bus/counter/devices/counterX/countY/prescaler_component_id What: /sys/bus/counter/devices/counterX/countY/preset_component_id What: /sys/bus/counter/devices/counterX/countY/preset_enable_component_id What: /sys/bus/counter/devices/counterX/countY/signalZ_action_component_id +What: /sys/bus/counter/devices/counterX/countY/num_overflows_component_id +What: /sys/bus/counter/devices/counterX/countY/captureZ_component_id What: /sys/bus/counter/devices/counterX/signalY/cable_fault_component_id What: /sys/bus/counter/devices/counterX/signalY/cable_fault_enable_component_id What: /sys/bus/counter/devices/counterX/signalY/filter_clock_prescaler_component_id What: /sys/bus/counter/devices/counterX/signalY/index_polarity_component_id What: /sys/bus/counter/devices/counterX/signalY/synchronous_mode_component_id +What: /sys/bus/counter/devices/counterX/signalY/polarityZ_component_id +What: /sys/bus/counter/devices/counterX/signalY/frequency_component_id KernelVersion: 5.16 Contact: [email protected] Description:
@@ -345,3 +362,31 @@ Description: via index_polarity. The index function (as enabled via preset_enable) is performed synchronously with the quadrature clock on the active level of the index input. + +What: /sys/bus/counter/devices/counterX/signalY/polarityZ +KernelVersion: 6.0 +Contact: [email protected] +Description: + Select the signal Y edge polarity where Z (if present) is the + respective polarity sequence position. The following polarities + are available: + + rising edge: + Low state transitions to high state. + + falling edge: + High state transitions to low state. + +What: /sys/bus/counter/devices/counterX/signalY/polarityZ_available +KernelVersion: 6.0 +Contact: [email protected] +Description: + Discrete set of available values for the respective polarity Z + configuration are listed in this file. Values are delimited by + newline characters. + +What: /sys/bus/counter/devices/counterX/signalY/frequency +KernelVersion: 6.0 +Contact: [email protected] +Description: + Read-only attribute that indicates the signal Y frequency, in Hz.
Signature · 1 line
2.37.3
Julien Panis
reviewerPATCH v6 3/3 counter: ti-ecap-capture: capture driver support for ECAP
In reply to Julien PanisECAP hardware on TI AM62x SoC supports capture feature. It can be used to timestamp events (falling/rising edges) detected on input signal.
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/counter/Kconfig | 15 + drivers/counter/Makefile | 1 + drivers/counter/ti-ecap-capture.c | 653 ++++++++++++++++++++++++++++++ include/uapi/linux/counter.h | 2 + 4 files changed, 671 insertions(+) create mode 100644 drivers/counter/ti-ecap-capture.c
drivers/counter/Kconfig +15 -0
@@ -101,4 +101,19 @@ config INTEL_QEP To compile this driver as a module, choose M here: the module will be called intel-qep. +config TI_ECAP_CAPTURE + tristate "TI eCAP capture driver" + depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE || ARCH_K3 || COMPILE_TEST + depends on HAS_IOMEM + select REGMAP_MMIO + help + Select this option to enable the Texas Instruments Enhanced Capture + (eCAP) driver in input mode. + + It can be used to timestamp events (falling/rising edges) detected + on ECAP input signal. + + To compile this driver as a module, choose M here: the module + will be called ti-ecap-capture. + endif # COUNTER
drivers/counter/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_TI_EQEP) += ti-eqep.o obj-$(CONFIG_FTM_QUADDEC) += ftm-quaddec.o obj-$(CONFIG_MICROCHIP_TCB_CAPTURE) += microchip-tcb-capture.o obj-$(CONFIG_INTEL_QEP) += intel-qep.o +obj-$(CONFIG_TI_ECAP_CAPTURE) += ti-ecap-capture.o
drivers/counter/ti-ecap-capture.c new file +653 -0
653 lines not on this page · raw message
include/uapi/linux/counter.h +2 -0
@@ -63,6 +63,8 @@ enum counter_event_type {COUNTER_EVENT_INDEX ,/* State of counter is changed */ COUNTER_EVENT_CHANGE_OF_STATE , +/* Count value is captured */ + COUNTER_EVENT_CAPTURE, };/**
Signature · 1 line
2.37.3