Introduce the Counter subsystem
Subsystems (13)
v10 cover Introduce the Counter subsystem
Changes in v10:
- Fix minor typographical errors in documentation
- Merge the FlexTimer Module Quadrature decoder counter driver patches
This revision is functionally identical to the last; changes in this version were made to fix minor typos in the documentation files and also to pull in the new FTM quadrature decoder counter driver.
The Generic Counter API has been and is still in a feature freeze until it is merged into the mainline. The following features will be investigated after the merge: interrupt support for counter devices, and a character device interface for low-latency applications.
Benjamin Gaignard (2):
counter: Add STM32 Timer quadrature encoder
dt-bindings: counter: Document stm32 quadrature encoder
Fabrice Gasnier (2):
counter: stm32-lptimer: add counter device
dt-bindings: counter: Adjust dt-bindings for STM32 lptimer move
Patrick Havelange (7):
include/fsl: add common FlexTimer #defines in a separate header. drivers/pwm: pwm-fsl-ftm: use common header for FlexTimer #defines drivers/clocksource: timer-fsl-ftm: use common header for FlexTimer
#defines
dt-bindings: counter: ftm-quaddec
counter: add FlexTimer Module Quadrature decoder counter driver
counter: ftm-quaddec: Documentation: Add specific counter sysfs
documentation
LS1021A: dtsi: add ftm quad decoder entries
William Breathitt Gray (7):
counter: Introduce the Generic Counter interface
counter: Documentation: Add Generic Counter sysfs documentation
docs: Add Generic Counter interface documentation
iio: 104-quad-8: Update license boilerplate
counter: 104-quad-8: Add Generic Counter interface support
counter: 104-quad-8: Documentation: Add Generic Counter sysfs
documentation
iio: counter: Add deprecation markings for IIO Counter attributes
Documentation/ABI/testing/sysfs-bus-counter | 230 +++
.../ABI/testing/sysfs-bus-counter-104-quad-8 | 36 +
.../ABI/testing/sysfs-bus-counter-ftm-quaddec | 16 +
Documentation/ABI/testing/sysfs-bus-iio | 8 +
.../testing/sysfs-bus-iio-counter-104-quad-8 | 16 +
.../bindings/counter/ftm-quaddec.txt | 18 +
.../{iio => }/counter/stm32-lptimer-cnt.txt | 0
.../bindings/counter/stm32-timer-cnt.txt | 31 +
.../devicetree/bindings/mfd/stm32-lptimer.txt | 2 +-
.../devicetree/bindings/mfd/stm32-timers.txt | 7 +
Documentation/driver-api/generic-counter.rst | 342 ++++
Documentation/driver-api/index.rst | 1 +
MAINTAINERS | 15 +-
arch/arm/boot/dts/ls1021a.dtsi | 28 +
drivers/Kconfig | 2 +
drivers/Makefile | 1 +
drivers/clocksource/timer-fsl-ftm.c | 15 +-
drivers/{iio => }/counter/104-quad-8.c | 782 +++++++-
drivers/counter/Kconfig | 60 +
drivers/counter/Makefile | 10 +
drivers/counter/counter.c | 1567 +++++++++++++++++
drivers/counter/ftm-quaddec.c | 356 ++++
drivers/{iio => }/counter/stm32-lptimer-cnt.c | 361 +++-
drivers/counter/stm32-timer-cnt.c | 390 ++++
drivers/iio/Kconfig | 1 -
drivers/iio/Makefile | 1 -
drivers/iio/counter/Kconfig | 34 -
drivers/iio/counter/Makefile | 8 -
drivers/pwm/pwm-fsl-ftm.c | 44 +-
include/linux/counter.h | 510 ++++++
include/linux/counter_enum.h | 45 +
include/linux/fsl/ftm.h | 88 +
32 files changed, 4877 insertions(+), 148 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-bus-counter
create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec
create mode 100644 Documentation/devicetree/bindings/counter/ftm-quaddec.txt
rename Documentation/devicetree/bindings/{iio => }/counter/stm32-lptimer-cnt.txt (100%)
create mode 100644 Documentation/devicetree/bindings/counter/stm32-timer-cnt.txt
create mode 100644 Documentation/driver-api/generic-counter.rst
rename drivers/{iio => }/counter/104-quad-8.c (44%)
create mode 100644 drivers/counter/Kconfig
create mode 100644 drivers/counter/Makefile
create mode 100644 drivers/counter/counter.c
create mode 100644 drivers/counter/ftm-quaddec.c
rename drivers/{iio => }/counter/stm32-lptimer-cnt.c (51%)
create mode 100644 drivers/counter/stm32-timer-cnt.c
delete mode 100644 drivers/iio/counter/Kconfig
delete mode 100644 drivers/iio/counter/Makefile
create mode 100644 include/linux/counter.h
create mode 100644 include/linux/counter_enum.h
create mode 100644 include/linux/fsl/ftm.hSignature · 1 line
2.21.0
PATCH v10 1/18 counter: Introduce the Generic Counter interface
This patch introduces the Generic Counter interface for supporting counter devices.
In the context of the Generic Counter interface, a counter is defined as a device that reports one or more "counts" based on the state changes of one or more "signals" as evaluated by a defined "count function."
Driver callbacks should be provided to communicate with the device: to read and write various Signals and Counts, and to set and get the "action mode" and "count function" for various Synapses and Counts respectively.
To support a counter device, a driver must first allocate the available Counter Signals via counter_signal structures. These Signals should be stored as an array and set to the signals array member of an allocated counter_device structure before the Counter is registered to the system.
Counter Counts may be allocated via counter_count structures, and respective Counter Signal associations (Synapses) made via counter_synapse structures. Associated counter_synapse structures are stored as an array and set to the the synapses array member of the respective counter_count structure. These counter_count structures are set to the counts array member of an allocated counter_device structure before the Counter is registered to the system.
A counter device is registered to the system by passing the respective initialized counter_device structure to the counter_register function; similarly, the counter_unregister function unregisters the respective Counter. The devm_counter_register and devm_counter_unregister functions serve as device memory-managed versions of the counter_register and counter_unregister functions respectively.
--- MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/counter/Kconfig | 10 + drivers/counter/Makefile | 5 + drivers/counter/counter.c | 1567 ++++++++++++++++++++++++++++++++++ include/linux/counter.h | 510 +++++++++++ include/linux/counter_enum.h | 45 + 8 files changed, 2148 insertions(+) create mode 100644 drivers/counter/Kconfig create mode 100644 drivers/counter/Makefile create mode 100644 drivers/counter/counter.c create mode 100644 include/linux/counter.h create mode 100644 include/linux/counter_enum.h
MAINTAINERS +8 -0
@@ -3966,6 +3966,14 @@ W: http://www.fi.muni.cz/~kas/cosa/ S: Maintained F: drivers/net/wan/cosa* +COUNTER SUBSYSTEM +M: William Breathitt Gray <[email protected]> +L: [email protected] +S: Maintained +F: drivers/counter/ +F: include/linux/counter.h +F: include/linux/counter_enum.h + CPMAC ETHERNET DRIVER M: Florian Fainelli <[email protected]> L: [email protected]
drivers/Kconfig +2 -0
@@ -228,4 +228,6 @@ source "drivers/siox/Kconfig" source "drivers/slimbus/Kconfig" +source "drivers/counter/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -186,3 +186,4 @@ obj-$(CONFIG_MULTIPLEXER) += mux/ obj-$(CONFIG_UNISYS_VISORBUS) += visorbus/ obj-$(CONFIG_SIOX) += siox/ obj-$(CONFIG_GNSS) += gnss/ +obj-$(CONFIG_COUNTER) += counter/
drivers/counter/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# +# Counter devices +# + +menuconfig COUNTER + tristate "Counter support" + help + This enables counter device support through the Generic Counter + interface. You only need to enable this, if you also want to enable + one or more of the counter device drivers below.
drivers/counter/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for Counter devices +# + +obj-$(CONFIG_COUNTER) += counter.o
drivers/counter/counter.c new file +1567 -0
1,567 lines not on this page · raw message
include/linux/counter.h new file +510 -0
510 lines not on this page · raw message
include/linux/counter_enum.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH v10 01/18] counter: Introduce the Generic Counter interface
Hi!
drivers/counter/counter.c line 35
Quoted 13 lines
drivers/counter/counter.c new file +13
-0+const char *const counter_count_direction_str[2 ] = { + [COUNTER_COUNT_DIRECTION_FORWARD ] ="forward" , + [COUNTER_COUNT_DIRECTION_BACKWARD ] ="backward" +}; +EXPORT_SYMBOL_GPL (counter_count_direction_str); + +const char *const counter_count_mode_str[4 ] = { + [COUNTER_COUNT_MODE_NORMAL ] ="normal" , + [COUNTER_COUNT_MODE_RANGE_LIMIT ] ="range limit" , + [COUNTER_COUNT_MODE_NON_RECYCLE ] ="non-recycle" , + [COUNTER_COUNT_MODE_MODULO_N ] ="modulo-n" +}; +EXPORT_SYMBOL_GPL (counter_count_mode_str);
Dunno. Exporting const tables saying "forward" and "backward". Can we ... somehow make it work without need to export this?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v10 01/18] counter: Introduce the Generic Counter interface
Quoted 22 lines · Pavel Machek
Hi!
drivers/counter/counter.c line 35
Quoted 13 lines
drivers/counter/counter.c new file +13
-0+const char *const counter_count_direction_str[2 ] = { + [COUNTER_COUNT_DIRECTION_FORWARD ] ="forward" , + [COUNTER_COUNT_DIRECTION_BACKWARD ] ="backward" +}; +EXPORT_SYMBOL_GPL (counter_count_direction_str); + +const char *const counter_count_mode_str[4 ] = { + [COUNTER_COUNT_MODE_NORMAL ] ="normal" , + [COUNTER_COUNT_MODE_RANGE_LIMIT ] ="range limit" , + [COUNTER_COUNT_MODE_NON_RECYCLE ] ="non-recycle" , + [COUNTER_COUNT_MODE_MODULO_N ] ="modulo-n" +}; +EXPORT_SYMBOL_GPL (counter_count_mode_str);Dunno. Exporting const tables saying "forward" and "backward". Can we ... somehow make it work without need to export this?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Right now there are only have 4 counter devices supported in this patchset, but it is expected that support for a greater variety of devices will be added. For these future cases, new count directions will be added to match their functionality.
For example, suppose support for a rotary encoder device is added. These type of devices do not move forward/backward but rather rotate. In these cases, the following count directions may be added:
[COUNTER_COUNT_DIRECTION_CLOCKWISE] = "clockwise", [COUNTER_COUNT_DIRECTION_COUNTERCLOCKWISE] = "counterclockwise"
Or as another example, suppose support for a two-axis precision positioning table is added. These devices support positioning in a cartesian coordinate system. In these cases, spatial direction may serve as useful count directions:
[COUNTER_COUNT_DIRECTION_NORTH] = "north", [COUNTER_COUNT_DIRECTION_NORTHEAST] = "northeast", [COUNTER_COUNT_DIRECTION_EAST] = "east", [COUNTER_COUNT_DIRECTION_SOUTHEAST] = "southeast", [COUNTER_COUNT_DIRECTION_SOUTH] = "south", [COUNTER_COUNT_DIRECTION_SOUTHWEST] = "southwest", [COUNTER_COUNT_DIRECTION_WEST] = "west", [COUNTER_COUNT_DIRECTION_NORTHWEST] = "northwest"
A const table is conveinent in these scenarios because support for new count directions may be easily added by simple entry into the table.
William Breathitt Gray
PATCH v10 2/18 counter: Documentation: Add Generic Counter sysfs documentation
In reply to William Breathitt GrayThis patch adds standard documentation for the userspace sysfs attributes of the Generic Counter interface.
--- Documentation/ABI/testing/sysfs-bus-counter | 230 ++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 231 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-counter
Documentation/ABI/testing/sysfs-bus-counter new file +230 -0
@@ -0,0 +1,230 @@ +What: /sys/bus/counter/devices/counterX/countY/count +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count data of Count Y represented as a string. + +What: /sys/bus/counter/devices/counterX/countY/ceiling +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count value ceiling for Count Y. This is the upper limit for the + respective counter. + +What: /sys/bus/counter/devices/counterX/countY/floor +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count value floor for Count Y. This is the lower limit for the + respective counter. + +What: /sys/bus/counter/devices/counterX/countY/count_mode +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count mode for channel Y. The ceiling and floor values for + Count Y are used by the count mode where required. The following + count modes are available: + + normal: + Counting is continuous in either direction. + + range limit: + An upper or lower limit is set, mimicking limit switches + in the mechanical counterpart. The upper limit is set to + the Count Y ceiling value, while the lower limit is set + to the Count Y floor value. The counter freezes at + count = ceiling when counting up, and at count = floor + when counting down. At either of these limits, the + counting is resumed only when the count direction is + reversed. + + non-recycle: + The counter is disabled whenever a counter overflow or + underflow takes place. The counter is re-enabled when a + new count value is loaded to the counter via a preset + operation or direct write. + + modulo-n: + A count value boundary is set between the Count Y floor + value and the Count Y ceiling value. The counter is + reset to the Count Y floor value at count = ceiling when + counting up, while the counter is set to the Count Y + ceiling value at count = floor when counting down; the + counter does not freeze at the boundary points, but + counts continuously throughout. + +What: /sys/bus/counter/devices/counterX/countY/count_mode_available +What: /sys/bus/counter/devices/counterX/countY/error_noise_available +What: /sys/bus/counter/devices/counterX/countY/function_available +What: /sys/bus/counter/devices/counterX/countY/signalZ_action_available +KernelVersion: 5.2 +Contact: [email protected] +Description: + Discrete set of available values for the respective Count Y + configuration are listed in this file. Values are delimited by + newline characters. + +What: /sys/bus/counter/devices/counterX/countY/direction +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates the count direction of Count + Y. Two count directions are available: forward and backward. + + Some counter devices are able to determine the direction of + their counting. For example, quadrature encoding counters can + determine the direction of movement by evaluating the leading + phase of the respective A and B quadrature encoding signals. + This attribute exposes such count directions. + +What: /sys/bus/counter/devices/counterX/countY/enable +KernelVersion: 5.2 +Contact: [email protected] +Description: + Whether channel Y counter is enabled. Valid attribute values are + boolean. + + This attribute is intended to serve as a pause/unpause mechanism + for Count Y. Suppose a counter device is used to count the total + movement of a conveyor belt: this attribute allows an operator + to temporarily pause the counter, service the conveyor belt, + and then finally unpause the counter to continue where it had + left off. + +What: /sys/bus/counter/devices/counterX/countY/error_noise +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates whether excessive noise is + present at the channel Y counter inputs. + +What: /sys/bus/counter/devices/counterX/countY/function +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count function mode of Count Y; count function evaluation is + triggered by conditions specified by the Count Y signalZ_action + attributes. The following count functions are available: + + increase: + Accumulated count is incremented. + + decrease: + Accumulated count is decremented. + + pulse-direction: + Rising edges on signal A updates the respective count. + The input level of signal B determines direction. + + quadrature x1 a: + If direction is forward, rising edges on quadrature pair + signal A updates the respective count; if the direction + is backward, falling edges on quadrature pair signal A + updates the respective count. Quadrature encoding + determines the direction. + + quadrature x1 b: + If direction is forward, rising edges on quadrature pair + signal B updates the respective count; if the direction + is backward, falling edges on quadrature pair signal B + updates the respective count. Quadrature encoding + determines the direction. + + quadrature x2 a: + Any state transition on quadrature pair signal A updates + the respective count. Quadrature encoding determines the + direction. + + quadrature x2 b: + Any state transition on quadrature pair signal B updates + the respective count. Quadrature encoding determines the + direction. + + quadrature x4: + Any state transition on either quadrature pair signals + updates the respective count. Quadrature encoding + determines the direction. + +What: /sys/bus/counter/devices/counterX/countY/name +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates the device-specific name of + Count Y. If possible, this should match the name of the + respective channel as it appears in the device datasheet. + +What: /sys/bus/counter/devices/counterX/countY/preset +KernelVersion: 5.2 +Contact: [email protected] +Description: + If the counter device supports preset registers -- registers + used to load counter channels to a set count upon device-defined + preset operation trigger events -- the preset count for channel + Y is provided by this attribute. + +What: /sys/bus/counter/devices/counterX/countY/preset_enable +KernelVersion: 5.2 +Contact: [email protected] +Description: + Whether channel Y counter preset operation is enabled. Valid + attribute values are boolean. + +What: /sys/bus/counter/devices/counterX/countY/signalZ_action +KernelVersion: 5.2 +Contact: [email protected] +Description: + Action mode of Count Y for Signal Z. This attribute indicates + the condition of Signal Z that triggers the count function + evaluation for Count Y. The following action modes are + available: + + none: + Signal does not trigger the count function. In + Pulse-Direction count function mode, this Signal is + evaluated as Direction. + + rising edge: + Low state transitions to high state. + + falling edge: + High state transitions to low state. + + both edges: + Any state transition. + +What: /sys/bus/counter/devices/counterX/name +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates the device-specific name of + the Counter. This should match the name of the device as it + appears in its respective datasheet. + +What: /sys/bus/counter/devices/counterX/num_counts +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates the total number of Counts + belonging to the Counter. + +What: /sys/bus/counter/devices/counterX/num_signals +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates the total number of Signals + belonging to the Counter. + +What: /sys/bus/counter/devices/counterX/signalY/signal +KernelVersion: 5.2 +Contact: [email protected] +Description: + Signal data of Signal Y represented as a string. + +What: /sys/bus/counter/devices/counterX/signalY/name +KernelVersion: 5.2 +Contact: [email protected] +Description: + Read-only attribute that indicates the device-specific name of + Signal Y. If possible, this should match the name of the + respective signal as it appears in the device datasheet.
MAINTAINERS +1 -0
@@ -3970,6 +3970,7 @@ COUNTER SUBSYSTEM M: William Breathitt Gray <[email protected]> L: [email protected] S: Maintained +F: Documentation/ABI/testing/sysfs-bus-counter* F: drivers/counter/ F: include/linux/counter.h F: include/linux/counter_enum.h
Signature · 1 line
2.21.0
Re: [PATCH v10 02/18] counter: Documentation: Add Generic Counter sysfs documentation
Quoted 73 lines · William Breathitt Gray
This patch adds standard documentation for the userspace sysfs attributes of the Generic Counter interface.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by William Breathitt Gray <[email protected]>--- Documentation/ABI/testing/sysfs-bus-counter | 230 ++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 231 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-counterDocumentation/ABI/testing/sysfs-bus-counter new file +56
-0@@ -0,0 +1,230 @@ +What: /sys/bus/counter/devices/counterX/countY/count +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count data of Count Y represented as a string. + +What: /sys/bus/counter/devices/counterX/countY/ceiling +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count value ceiling for Count Y. This is the upper limit for the + respective counter. + +What: /sys/bus/counter/devices/counterX/countY/floor +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count value floor for Count Y. This is the lower limit for the + respective counter. + +What: /sys/bus/counter/devices/counterX/countY/count_mode +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count mode for channel Y. The ceiling and floor values for + Count Y are used by the count mode where required. The following + count modes are available: + + normal: + Counting is continuous in either direction. + + range limit: + An upper or lower limit is set, mimicking limit switches + in the mechanical counterpart. The upper limit is set to + the Count Y ceiling value, while the lower limit is set + to the Count Y floor value. The counter freezes at + count = ceiling when counting up, and at count = floor + when counting down. At either of these limits, the + counting is resumed only when the count direction is + reversed. + + non-recycle: + The counter is disabled whenever a counter overflow or + underflow takes place. The counter is re-enabled when a + new count value is loaded to the counter via a preset + operation or direct write. + + modulo-n: + A count value boundary is set between the Count Y floor + value and the Count Y ceiling value. The counter is + reset to the Count Y floor value at count = ceiling when + counting up, while the counter is set to the Count Y + ceiling value at count = floor when counting down; the + counter does not freeze at the boundary points, but + counts continuously throughout. +
Documentation/ABI/testing/sysfs-bus-counter line 66
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-counter new file +10
-0+What: /sys/bus/counter/devices/counterX/countY/count_mode_available +What: /sys/bus/counter/devices/counterX/countY/error_noise_available +What: /sys/bus/counter/devices/counterX/countY/function_available +What: /sys/bus/counter/devices/counterX/countY/signalZ_action_available +KernelVersion: 5.2 +Contact: [email protected] +Description: + Discrete set of available values for the respective Count Y + configuration are listed in this file. Values are delimited by + newline characters.
Elsewhere in sysfs we do space-separated:
pavel@amd:~$ cat /sys/power/state freeze mem disk
And we use [] to mark current selection:
pavel@amd:~$ cat /sys/class/leds/tpacpi\:\:thinkvantage/trigger [none] bluetooth-power rfkill-any rfkill-none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock AC-online BAT0-charging-or-full BAT0-charging BAT0-full BAT0-charging-blink-full-solid rfkill0 phy0rx phy0tx phy0assoc phy0radio phy0tpt mmc0 timer heartbeat audio-mute audio-micmute rfkill1
Note this only works if you have less than PAGE_SIZE of entries... and will never have more.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v10 02/18] counter: Documentation: Add Generic Counter sysfs documentation
Quoted 101 lines · Pavel Machek
Quoted 73 lines · William Breathitt Gray
This patch adds standard documentation for the userspace sysfs attributes of the Generic Counter interface.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by William Breathitt Gray <[email protected]>--- Documentation/ABI/testing/sysfs-bus-counter | 230 ++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 231 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-counterDocumentation/ABI/testing/sysfs-bus-counter new file +56
-0@@ -0,0 +1,230 @@ +What: /sys/bus/counter/devices/counterX/countY/count +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count data of Count Y represented as a string. + +What: /sys/bus/counter/devices/counterX/countY/ceiling +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count value ceiling for Count Y. This is the upper limit for the + respective counter. + +What: /sys/bus/counter/devices/counterX/countY/floor +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count value floor for Count Y. This is the lower limit for the + respective counter. + +What: /sys/bus/counter/devices/counterX/countY/count_mode +KernelVersion: 5.2 +Contact: [email protected] +Description: + Count mode for channel Y. The ceiling and floor values for + Count Y are used by the count mode where required. The following + count modes are available: + + normal: + Counting is continuous in either direction. + + range limit: + An upper or lower limit is set, mimicking limit switches + in the mechanical counterpart. The upper limit is set to + the Count Y ceiling value, while the lower limit is set + to the Count Y floor value. The counter freezes at + count = ceiling when counting up, and at count = floor + when counting down. At either of these limits, the + counting is resumed only when the count direction is + reversed. + + non-recycle: + The counter is disabled whenever a counter overflow or + underflow takes place. The counter is re-enabled when a + new count value is loaded to the counter via a preset + operation or direct write. + + modulo-n: + A count value boundary is set between the Count Y floor + value and the Count Y ceiling value. The counter is + reset to the Count Y floor value at count = ceiling when + counting up, while the counter is set to the Count Y + ceiling value at count = floor when counting down; the + counter does not freeze at the boundary points, but + counts continuously throughout. +Documentation/ABI/testing/sysfs-bus-counter line 66
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-counter new file +10
-0+What: /sys/bus/counter/devices/counterX/countY/count_mode_available +What: /sys/bus/counter/devices/counterX/countY/error_noise_available +What: /sys/bus/counter/devices/counterX/countY/function_available +What: /sys/bus/counter/devices/counterX/countY/signalZ_action_available +KernelVersion: 5.2 +Contact: [email protected] +Description: + Discrete set of available values for the respective Count Y + configuration are listed in this file. Values are delimited by + newline characters.Elsewhere in sysfs we do space-separated:
pavel@amd:~$ cat /sys/power/state freeze mem diskAnd we use [] to mark current selection:
pavel@amd:~$ cat /sys/class/leds/tpacpi\:\:thinkvantage/trigger [none] bluetooth-power rfkill-any rfkill-none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock AC-online BAT0-charging-or-full BAT0-charging BAT0-full BAT0-charging-blink-full-solid rfkill0 phy0rx phy0tx phy0assoc phy0radio phy0tpt mmc0 timer heartbeat audio-mute audio-micmute rfkill1
Quoted 7 lines
Note this only works if you have less than
PAGE_SIZEof entries... and will never have more.Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Marking the current selection with [] or similar does seem useful. But delimiting by space does seem to cause confusion in cases where the values also include spaces (e.g. "quadrature x1 a"). I see that in these cases a "-" is used in place of a space, but that wouldn't work very well when values can also contain hyphens (e.g. "pulse-direction").
William Breathitt Gray
Re: [PATCH v10 02/18] counter: Documentation: Add Generic Counter sysfs documentation
In reply to Pavel MachekQuoted 5 lines · Pavel Machek
pavel@amd:~$ cat /sys/power/state freeze mem diskAnd we use [] to mark current selection:
I know this is used elsewhere, but I don't think it is a good pattern to copy. Parsing it from user-space is annoying. Also it breaks the sysfs rule of "one item per file" since it tells us two things - the list of possible values _and_ the current active value.
Quoted 15 lines
pavel@amd:~$ cat /sys/class/leds/tpacpi\:\:thinkvantage/trigger [none] bluetooth-power rfkill-any rfkill-none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock AC-online BAT0-charging-or-full BAT0-charging BAT0-full BAT0-charging-blink-full-solid rfkill0 phy0rx phy0tx phy0assoc phy0radio phy0tpt mmc0 timer heartbeat audio-mute audio-micmute rfkill1Note this only works if you have less than
PAGE_SIZEof entries... and will never have more.Pavel
PATCH v10 3/18 docs: Add Generic Counter interface documentation
In reply to William Breathitt GrayThis patch adds high-level documentation about the Generic Counter interface.
--- Documentation/driver-api/generic-counter.rst | 342 +++++++++++++++++++ Documentation/driver-api/index.rst | 1 + MAINTAINERS | 1 + 3 files changed, 344 insertions(+) create mode 100644 Documentation/driver-api/generic-counter.rst
Documentation/driver-api/generic-counter.rst new file +342 -0
@@ -0,0 +1,342 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================= +Generic Counter Interface +========================= + +Introduction +============ + +Counter devices are prevalent within a diverse spectrum of industries. +The ubiquitous presence of these devices necessitates a common interface +and standard of interaction and exposure. This driver API attempts to +resolve the issue of duplicate code found among existing counter device +drivers by introducing a generic counter interface for consumption. The +Generic Counter interface enables drivers to support and expose a common +set of components and functionality present in counter devices. + +Theory +====== + +Counter devices can vary greatly in design, but regardless of whether +some devices are quadrature encoder counters or tally counters, all +counter devices consist of a core set of components. This core set of +components, shared by all counter devices, is what forms the essence of +the Generic Counter interface. + +There are three core components to a counter: + +* Count: + Count data for a set of Signals. + +* Signal: + Input data that is evaluated by the counter to determine the count + data. + +* Synapse: + The association of a Signal with a respective Count. + +COUNT +----- +A Count represents the count data for a set of Signals. The Generic +Counter interface provides the following available count data types: + +* COUNT_POSITION: + Unsigned integer value representing position. + +A Count has a count function mode which represents the update behavior +for the count data. The Generic Counter interface provides the following +available count function modes: + +* Increase: + Accumulated count is incremented. + +* Decrease: + Accumulated count is decremented. + +* Pulse-Direction: + Rising edges on signal A updates the respective count. The input level + of signal B determines direction. + +* Quadrature: + A pair of quadrature encoding signals are evaluated to determine + position and direction. The following Quadrature modes are available: + + - x1 A: + If direction is forward, rising edges on quadrature pair signal A + updates the respective count; if the direction is backward, falling + edges on quadrature pair signal A updates the respective count. + Quadrature encoding determines the direction. + + - x1 B: + If direction is forward, rising edges on quadrature pair signal B + updates the respective count; if the direction is backward, falling + edges on quadrature pair signal B updates the respective count. + Quadrature encoding determines the direction. + + - x2 A: + Any state transition on quadrature pair signal A updates the + respective count. Quadrature encoding determines the direction. + + - x2 B: + Any state transition on quadrature pair signal B updates the + respective count. Quadrature encoding determines the direction. + + - x4: + Any state transition on either quadrature pair signals updates the + respective count. Quadrature encoding determines the direction. + +A Count has a set of one or more associated Signals. + +SIGNAL +------ +A Signal represents a counter input data; this is the input data that is +evaluated by the counter to determine the count data; e.g. a quadrature +signal output line of a rotary encoder. Not all counter devices provide +user access to the Signal data. + +The Generic Counter interface provides the following available signal +data types for when the Signal data is available for user access: + +* SIGNAL_LEVEL: + Signal line state level. The following states are possible: + + - SIGNAL_LEVEL_LOW: + Signal line is in a low state. + + - SIGNAL_LEVEL_HIGH: + Signal line is in a high state. + +A Signal may be associated with one or more Counts. + +SYNAPSE +------- +A Synapse represents the association of a Signal with a respective +Count. Signal data affects respective Count data, and the Synapse +represents this relationship. + +The Synapse action mode specifies the Signal data condition which +triggers the respective Count's count function evaluation to update the +count data. The Generic Counter interface provides the following +available action modes: + +* None: + Signal does not trigger the count function. In Pulse-Direction count + function mode, this Signal is evaluated as Direction. + +* Rising Edge: + Low state transitions to high state. + +* Falling Edge: + High state transitions to low state. + +* Both Edges: + Any state transition. + +A counter is defined as a set of input signals associated with count +data that are generated by the evaluation of the state of the associated +input signals as defined by the respective count functions. Within the +context of the Generic Counter interface, a counter consists of Counts +each associated with a set of Signals, whose respective Synapse +instances represent the count function update conditions for the +associated Counts. + +Paradigm +======== + +The most basic counter device may be expressed as a single Count +associated with a single Signal via a single Synapse. Take for example +a counter device which simply accumulates a count of rising edges on a +source input line:: + + Count Synapse Signal + ----- ------- ------ + +---------------------+ + | Data: Count | Rising Edge ________ + | Function: Increase | <------------- / Source \ + | | ____________ + +---------------------+ + +In this example, the Signal is a source input line with a pulsing +voltage, while the Count is a persistent count value which is repeatedly +incremented. The Signal is associated with the respective Count via a +Synapse. The increase function is triggered by the Signal data condition +specified by the Synapse -- in this case a rising edge condition on the +voltage input line. In summary, the counter device existence and +behavior is aptly represented by respective Count, Signal, and Synapse +components: a rising edge condition triggers an increase function on an +accumulating count datum. + +A counter device is not limited to a single Signal; in fact, in theory +many Signals may be associated with even a single Count. For example, a +quadrature encoder counter device can keep track of position based on +the states of two input lines:: + + Count Synapse Signal + ----- ------- ------ + +-------------------------+ + | Data: Position | Both Edges ___ + | Function: Quadrature x4 | <------------ / A \ + | | _______ + | | + | | Both Edges ___ + | | <------------ / B \ + | | _______ + +-------------------------+ + +In this example, two Signals (quadrature encoder lines A and B) are +associated with a single Count: a rising or falling edge on either A or +B triggers the "Quadrature x4" function which determines the direction +of movement and updates the respective position data. The "Quadrature +x4" function is likely implemented in the hardware of the quadrature +encoder counter device; the Count, Signals, and Synapses simply +represent this hardware behavior and functionality. + +Signals associated with the same Count can have differing Synapse action +mode conditions. For example, a quadrature encoder counter device +operating in a non-quadrature Pulse-Direction mode could have one input +line dedicated for movement and a second input line dedicated for +direction:: + + Count Synapse Signal + ----- ------- ------ + +---------------------------+ + | Data: Position | Rising Edge ___ + | Function: Pulse-Direction | <------------- / A \ (Movement) + | | _______ + | | + | | None ___ + | | <------------- / B \ (Direction) + | | _______ + +---------------------------+ + +Only Signal A triggers the "Pulse-Direction" update function, but the +instantaneous state of Signal B is still required in order to know the +direction so that the position data may be properly updated. Ultimately, +both Signals are associated with the same Count via two respective +Synapses, but only one Synapse has an active action mode condition which +triggers the respective count function while the other is left with a +"None" condition action mode to indicate its respective Signal's +availability for state evaluation despite its non-triggering mode. + +Keep in mind that the Signal, Synapse, and Count are abstract +representations which do not need to be closely married to their +respective physical sources. This allows the user of a counter to +divorce themselves from the nuances of physical components (such as +whether an input line is differential or single-ended) and instead focus +on the core idea of what the data and process represent (e.g. position +as interpreted from quadrature encoding data). + +Userspace Interface +=================== + +Several sysfs attributes are generated by the Generic Counter interface, +and reside under the /sys/bus/counter/devices/counterX directory, where +counterX refers to the respective counter device. Please see +Documentation/ABI/testing/sys-bus-counter-generic-sysfs for detailed +information on each Generic Counter interface sysfs attribute. + +Through these sysfs attributes, programs and scripts may interact with +the Generic Counter paradigm Counts, Signals, and Synapses of respective +counter devices. + +Driver API +========== + +Driver authors may utilize the Generic Counter interface in their code +by including the include/linux/counter.h header file. This header file +provides several core data structures, function prototypes, and macros +for defining a counter device. + +.. kernel-doc:: include/linux/counter.h + :internal: + +.. kernel-doc:: drivers/counter/generic-counter.c + :export: + +Implementation +============== + +To support a counter device, a driver must first allocate the available +Counter Signals via counter_signal structures. These Signals should +be stored as an array and set to the signals array member of an +allocated counter_device structure before the Counter is registered to +the system. + +Counter Counts may be allocated via counter_count structures, and +respective Counter Signal associations (Synapses) made via +counter_synapse structures. Associated counter_synapse structures are +stored as an array and set to the the synapses array member of the +respective counter_count structure. These counter_count structures are +set to the counts array member of an allocated counter_device structure +before the Counter is registered to the system. + +Driver callbacks should be provided to the counter_device structure via +a constant counter_ops structure in order to communicate with the +device: to read and write various Signals and Counts, and to set and get +the "action mode" and "function mode" for various Synapses and Counts +respectively. + +A defined counter_device structure may be registered to the system by +passing it to the counter_register function, and unregistered by passing +it to the counter_unregister function. Similarly, the +devm_counter_register and devm_counter_unregister functions may be used +if device memory-managed registration is desired. + +Extension sysfs attributes can be created for auxiliary functionality +and data by passing in defined counter_device_ext, counter_count_ext, +and counter_signal_ext structures. In these cases, the +counter_device_ext structure is used for global configuration of the +respective Counter device, while the counter_count_ext and +counter_signal_ext structures allow for auxiliary exposure and +configuration of a specific Count or Signal respectively. + +Architecture +============ + +When the Generic Counter interface counter module is loaded, the +counter_init function is called which registers a bus_type named +"counter" to the system. Subsequently, when the module is unloaded, the +counter_exit function is called which unregisters the bus_type named +"counter" from the system. + +Counter devices are registered to the system via the counter_register +function, and later removed via the counter_unregister function. The +counter_register function establishes a unique ID for the Counter +device and creates a respective sysfs directory, where X is the +mentioned unique ID: + + /sys/bus/counter/devices/counterX + +Sysfs attributes are created within the counterX directory to expose +functionality, configurations, and data relating to the Counts, Signals, +and Synapses of the Counter device, as well as options and information +for the Counter device itself. + +Each Signal has a directory created to house its relevant sysfs +attributes, where Y is the unique ID of the respective Signal: + + /sys/bus/counter/devices/counterX/signalY + +Similarly, each Count has a directory created to house its relevant +sysfs attributes, where Y is the unique ID of the respective Count: + + /sys/bus/counter/devices/counterX/countY + +For a more detailed breakdown of the available Generic Counter interface +sysfs attributes, please refer to the +Documentation/ABI/testing/sys-bus-counter file. + +The Signals and Counts associated with the Counter device are registered +to the system as well by the counter_register function. The +signal_read/signal_write driver callbacks are associated with their +respective Signal attributes, while the count_read/count_write and +function_get/function_set driver callbacks are associated with their +respective Count attributes; similarly, the same is true for the +action_get/action_set driver callbacks and their respective Synapse +attributes. If a driver callback is left undefined, then the respective +read/write permission is left disabled for the relevant attributes. + +Similarly, extension sysfs attributes are created for the defined +counter_device_ext, counter_count_ext, and counter_signal_ext +structures that are passed in.
Documentation/driver-api/index.rst +1 -0
@@ -55,6 +55,7 @@ available subsections can be seen below. slimbus soundwire/index fpga/index + generic-counter .. only:: subproject and html
MAINTAINERS +1 -0
@@ -3971,6 +3971,7 @@ M: William Breathitt Gray <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-bus-counter* +F: Documentation/driver-api/generic-counter.rst F: drivers/counter/ F: include/linux/counter.h F: include/linux/counter_enum.h
Signature · 1 line
2.21.0
PATCH v10 4/18 iio: 104-quad-8: Update license boilerplate
In reply to William Breathitt GrayThis patch simplifies the boilerplate license text by making use of a SPDX license identifier line.
--- drivers/iio/counter/104-quad-8.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/iio/counter/104-quad-8.c +1 -9
@@ -1,16 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * IIO driver for the ACCES 104-QUAD-8 * Copyright (C) 2016 William Breathitt Gray * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License, version 2, as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* * This driver supports the ACCES 104-QUAD-8 and ACCES 104-QUAD-4. */ #include <linux/bitops.h>
Signature · 1 line
2.21.0
PATCH v10 5/18 counter: 104-quad-8: Add Generic Counter interface support
In reply to William Breathitt GrayThis patch adds support for the Generic Counter interface to the 104-QUAD-8 driver. The existing 104-QUAD-8 device interface should not be affected by this patch; all changes are intended as supplemental additions as perceived by the user.
Generic Counter Counts are created for the eight quadrature channel counts, as well as their respective quadrature A and B Signals (which are associated via respective Synapse structures) and respective index Signals.
The new Generic Counter interface sysfs attributes are intended to expose the same functionality and data available via the existing 104-QUAD-8 IIO device interface; the Generic Counter interface serves to provide the respective functionality and data in a standard way expected of counter devices.
---
MAINTAINERS | 4 +-
drivers/{iio => }/counter/104-quad-8.c | 772 ++++++++++++++++++++++++-
drivers/counter/Kconfig | 21 +
drivers/counter/Makefile | 2 +
drivers/iio/counter/Kconfig | 17 -
drivers/iio/counter/Makefile | 1 -
6 files changed, 783 insertions(+), 34 deletions(-)
rename drivers/{iio => }/counter/104-quad-8.c (44%)MAINTAINERS +2 -2
@@ -268,12 +268,12 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-104-idio-16.c -ACCES 104-QUAD-8 IIO DRIVER +ACCES 104-QUAD-8 DRIVER M: William Breathitt Gray <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-bus-iio-counter-104-quad-8 -F: drivers/iio/counter/104-quad-8.c +F: drivers/counter/104-quad-8.c ACCES PCI-IDIO-16 GPIO DRIVER M: William Breathitt Gray <[email protected]>
drivers/counter/104-quad-8.c renamed from drivers/iio/counter/104-quad-8.c +758 -14
839 lines not on this page · raw message
drivers/counter/Kconfig +21 -0
@@ -8,3 +8,24 @@ menuconfig COUNTER This enables counter device support through the Generic Counter interface. You only need to enable this, if you also want to enable one or more of the counter device drivers below. + +if COUNTER + +config 104_QUAD_8 + tristate "ACCES 104-QUAD-8 driver" + depends on PC104 && X86 && IIO + select ISA_BUS_API + help + Say yes here to build support for the ACCES 104-QUAD-8 quadrature + encoder counter/interface device family (104-QUAD-8, 104-QUAD-4). + + A counter's respective error flag may be cleared by performing a write + operation on the respective count value attribute. Although the + 104-QUAD-8 counters have a 25-bit range, only the lower 24 bits may be + set, either directly or via the counter's preset attribute. Interrupts + are not supported by this driver. + + The base port addresses for the devices may be configured via the base + array module parameter. + +endif # COUNTER
drivers/counter/Makefile +2 -0
@@ -3,3 +3,5 @@ # obj-$(CONFIG_COUNTER) += counter.o + +obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o
drivers/iio/counter/Kconfig +0 -17
@@ -5,23 +5,6 @@ menu "Counters" -config 104_QUAD_8 - tristate "ACCES 104-QUAD-8 driver" - depends on PC104 && X86 - select ISA_BUS_API - help - Say yes here to build support for the ACCES 104-QUAD-8 quadrature - encoder counter/interface device family (104-QUAD-8, 104-QUAD-4). - - Performing a write to a counter's IIO_CHAN_INFO_RAW sets the counter and - also clears the counter's respective error flag. Although the counters - have a 25-bit range, only the lower 24 bits may be set, either directly - or via a counter's preset attribute. Interrupts are not supported by - this driver. - - The base port addresses for the devices may be configured via the base - array module parameter. - config STM32_LPTIMER_CNT tristate "STM32 LP Timer encoder counter driver" depends on MFD_STM32_LPTIMER || COMPILE_TEST
drivers/iio/counter/Makefile +0 -1
@@ -4,5 +4,4 @@ # When adding new entries keep the list in alphabetical order -obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o
Signature · 1 line
2.21.0
PATCH v10 6/18 counter: 104-quad-8: Documentation: Add Generic Counter sysfs documentation
In reply to William Breathitt GrayThis patch adds standard documentation for the Generic Counter interface userspace sysfs attributes of the 104-QUAD-8 driver.
--- .../ABI/testing/sysfs-bus-counter-104-quad-8 | 36 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 37 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
Documentation/ABI/testing/sysfs-bus-counter-104-quad-8 new file +36 -0
@@ -0,0 +1,36 @@ +What: /sys/bus/counter/devices/counterX/signalY/index_polarity +KernelVersion: 5.2 +Contact: [email protected] +Description: + Active level of index input Signal Y; irrelevant in + non-synchronous load mode. + +What: /sys/bus/counter/devices/counterX/signalY/index_polarity_available +What: /sys/bus/counter/devices/counterX/signalY/synchronous_mode_available +KernelVersion: 5.2 +Contact: [email protected] +Description: + Discrete set of available values for the respective Signal Y + configuration are listed in this file. + +What: /sys/bus/counter/devices/counterX/signalY/synchronous_mode +KernelVersion: 5.2 +Contact: [email protected] +Description: + Configure the counter associated with Signal Y for + non-synchronous or synchronous load mode. Synchronous load mode + cannot be selected in non-quadrature (Pulse-Direction) clock + mode. + + non-synchronous: + A logic low level is the active level at this index + input. The index function (as enabled via preset_enable) + is performed directly on the active level of the index + input. + + synchronous: + Intended for interfacing with encoder Index output in + quadrature clock mode. The active level is configured + 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.
MAINTAINERS +1 -0
@@ -272,6 +272,7 @@ ACCES 104-QUAD-8 DRIVER M: William Breathitt Gray <[email protected]> L: [email protected] S: Maintained +F: Documentation/ABI/testing/sysfs-bus-counter-104-quad-8 F: Documentation/ABI/testing/sysfs-bus-iio-counter-104-quad-8 F: drivers/counter/104-quad-8.c
Signature · 1 line
2.21.0
PATCH v10 7/18 counter: Add STM32 Timer quadrature encoder
In reply to William Breathitt GrayFrom: Benjamin Gaignard <[email protected]>
Implement counter part of the STM32 timer hardware block by using counter API. Hardware only supports X2 and X4 quadrature modes. A ceiling value can be set to define the maximum value reachable by the counter.
--- drivers/counter/Kconfig | 10 + drivers/counter/Makefile | 1 + drivers/counter/stm32-timer-cnt.c | 390 ++++++++++++++++++++++++++++++ 3 files changed, 401 insertions(+) create mode 100644 drivers/counter/stm32-timer-cnt.c
drivers/counter/Kconfig +10 -0
@@ -28,4 +28,14 @@ config 104_QUAD_8 The base port addresses for the devices may be configured via the base array module parameter. +config STM32_TIMER_CNT + tristate "STM32 Timer encoder counter driver" + depends on MFD_STM32_TIMERS || COMPILE_TEST + help + Select this option to enable STM32 Timer quadrature encoder + and counter driver. + + To compile this driver as a module, choose M here: the + module will be called stm32-timer-cnt. + endif # COUNTER
drivers/counter/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_COUNTER) += counter.o obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o +obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o
drivers/counter/stm32-timer-cnt.c new file +390 -0
390 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v10 8/18 dt-bindings: counter: Document stm32 quadrature encoder
In reply to William Breathitt GrayFrom: Benjamin Gaignard <[email protected]>
Add bindings for STM32 Timer quadrature encoder. It is a sub-node of STM32 Timer which implement the quadratic encoder part of the hardware.
--- .../bindings/counter/stm32-timer-cnt.txt | 31 +++++++++++++++++++ .../devicetree/bindings/mfd/stm32-timers.txt | 7 +++++ 2 files changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/counter/stm32-timer-cnt.txt
Documentation/devicetree/bindings/counter/stm32-timer-cnt.txt new file +31 -0
@@ -0,0 +1,31 @@ +STMicroelectronics STM32 Timer quadrature encoder + +STM32 Timer provides quadrature encoder to detect +angular position and direction of rotary elements, +from IN1 and IN2 input signals. + +Must be a sub-node of an STM32 Timer device tree node. +See ../mfd/stm32-timers.txt for details about the parent node. + +Required properties: +- compatible: Must be "st,stm32-timer-counter". +- pinctrl-names: Set to "default". +- pinctrl-0: List of phandles pointing to pin configuration nodes, + to set CH1/CH2 pins in mode of operation for STM32 + Timer input on external pin. + +Example: + timers@40010000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "st,stm32-timers"; + reg = <0x40010000 0x400>; + clocks = <&rcc 0 160>; + clock-names = "int"; + + counter { + compatible = "st,stm32-timer-counter"; + pinctrl-names = "default"; + pinctrl-0 = <&tim1_in_pins>; + }; + };
Documentation/devicetree/bindings/mfd/stm32-timers.txt +7 -0
@@ -28,6 +28,7 @@ Optional parameters: Optional subnodes: - pwm: See ../pwm/pwm-stm32.txt - timer: See ../iio/timer/stm32-timer-trigger.txt +- counter: See ../counter/stm32-timer-cnt.txt Example: timers@40010000 {
@@ -48,6 +49,12 @@ Example: compatible = "st,stm32-timer-trigger"; reg = <0>; }; + + counter { + compatible = "st,stm32-timer-counter"; + pinctrl-names = "default"; + pinctrl-0 = <&tim1_in_pins>; + }; }; Example with all dmas:
Signature · 1 line
2.21.0
PATCH v10 9/18 counter: stm32-lptimer: add counter device
In reply to William Breathitt GrayFrom: Fabrice Gasnier <[email protected]>
Add support for new counter device to stm32-lptimer.
---
drivers/counter/Kconfig | 10 +
drivers/counter/Makefile | 1 +
drivers/{iio => }/counter/stm32-lptimer-cnt.c | 361 ++++++++++++++++--
drivers/iio/Kconfig | 1 -
drivers/iio/Makefile | 1 -
drivers/iio/counter/Kconfig | 17 -
drivers/iio/counter/Makefile | 7 -
7 files changed, 350 insertions(+), 48 deletions(-)
rename drivers/{iio => }/counter/stm32-lptimer-cnt.c (51%)
delete mode 100644 drivers/iio/counter/Kconfig
delete mode 100644 drivers/iio/counter/Makefiledrivers/counter/Kconfig +10 -0
@@ -38,4 +38,14 @@ config STM32_TIMER_CNT To compile this driver as a module, choose M here: the module will be called stm32-timer-cnt. +config STM32_LPTIMER_CNT + tristate "STM32 LP Timer encoder counter driver" + depends on (MFD_STM32_LPTIMER || COMPILE_TEST) && IIO + help + Select this option to enable STM32 Low-Power Timer quadrature encoder + and counter driver. + + To compile this driver as a module, choose M here: the + module will be called stm32-lptimer-cnt. + endif # COUNTER
drivers/counter/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_COUNTER) += counter.o obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o +obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o
drivers/counter/stm32-lptimer-cnt.c renamed from drivers/iio/counter/stm32-lptimer-cnt.c +339 -22
442 lines not on this page · raw message
drivers/iio/Kconfig +0 -1
@@ -74,7 +74,6 @@ source "drivers/iio/afe/Kconfig" source "drivers/iio/amplifiers/Kconfig" source "drivers/iio/chemical/Kconfig" source "drivers/iio/common/Kconfig" -source "drivers/iio/counter/Kconfig" source "drivers/iio/dac/Kconfig" source "drivers/iio/dummy/Kconfig" source "drivers/iio/frequency/Kconfig"
drivers/iio/Makefile +0 -1
@@ -20,7 +20,6 @@ obj-y += amplifiers/ obj-y += buffer/ obj-y += chemical/ obj-y += common/ -obj-y += counter/ obj-y += dac/ obj-y += dummy/ obj-y += gyro/
drivers/iio/counter/Kconfig deleted +0 -17
@@ -1,17 +0,0 @@ -# -# Counter devices -# -# When adding new entries keep the list in alphabetical order - -menu "Counters" - -config STM32_LPTIMER_CNT - tristate "STM32 LP Timer encoder counter driver" - depends on MFD_STM32_LPTIMER || COMPILE_TEST - help - Select this option to enable STM32 Low-Power Timer quadrature encoder - and counter driver. - - To compile this driver as a module, choose M here: the - module will be called stm32-lptimer-cnt. -endmenu
drivers/iio/counter/Makefile deleted +0 -7
@@ -1,7 +0,0 @@ -# -# Makefile for IIO counter devices -# - -# When adding new entries keep the list in alphabetical order - -obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o
Signature · 1 line
2.21.0
PATCH v10 10/18 dt-bindings: counter: Adjust dt-bindings for STM32 lptimer move
In reply to William Breathitt GrayFrom: Fabrice Gasnier <[email protected]>
The STM32 LP Timer counter driver now resides under the Counter subsystem. This patch adjusts dt-bindings to account for the STM32 lptimer driver move.
---
.../devicetree/bindings/{iio => }/counter/stm32-lptimer-cnt.txt | 0
Documentation/devicetree/bindings/mfd/stm32-lptimer.txt | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename Documentation/devicetree/bindings/{iio => }/counter/stm32-lptimer-cnt.txt (100%)Documentation/devicetree/bindings/counter/stm32-lptimer-cnt.txt renamed from Documentation/devicetree/bindings/iio/counter/stm32-lptimer-cnt.txt +0 -0
Documentation/devicetree/bindings/mfd/stm32-lptimer.txt +1 -1
@@ -16,7 +16,7 @@ Required properties: Optional subnodes: - pwm: See ../pwm/pwm-stm32-lp.txt -- counter: See ../iio/timer/stm32-lptimer-cnt.txt +- counter: See ../counter/stm32-lptimer-cnt.txt - trigger: See ../iio/timer/stm32-lptimer-trigger.txt Example:
Signature · 1 line
2.21.0
PATCH v10 11/18 iio: counter: Add deprecation markings for IIO Counter attributes
In reply to William Breathitt GrayThe IIO counter subdirectory is now superceded by the Counter subsystem. This patch adds deprecation warnings to the documentation of the relevant IIO Counter sysfs attributes.
--- Documentation/ABI/testing/sysfs-bus-iio | 8 ++++++++ .../ABI/testing/sysfs-bus-iio-counter-104-quad-8 | 16 ++++++++++++++++ 2 files changed, 24 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +8 -0
@@ -1656,6 +1656,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_raw KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Raw counter device counts from channel Y. For quadrature counters, multiplication by an available [Y]_scale results in the counts of a single quadrature signal phase from channel Y.
@@ -1664,6 +1666,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_indexY_raw KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Raw counter device index value from channel Y. This attribute provides an absolute positional reference (e.g. a pulse once per revolution) which may be used to home positional systems as
@@ -1673,6 +1677,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_count_count_direction_available KernelVersion: 4.12 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + A list of possible counting directions which are: - "up" : counter device is increasing. - "down": counter device is decreasing.
@@ -1681,6 +1687,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_count_direction KernelVersion: 4.12 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Raw counter device counters direction for channel Y. What: /sys/bus/iio/devices/iio:deviceX/in_phaseY_raw
Documentation/ABI/testing/sysfs-bus-iio-counter-104-quad-8 +16 -0
@@ -6,6 +6,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_index_synchronous_mode_available KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Discrete set of available values for the respective counter configuration are listed in this file.
@@ -13,6 +15,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_count_mode KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Count mode for channel Y. Four count modes are available: normal, range limit, non-recycle, and modulo-n. The preset value for channel Y is used by the count mode where required.
@@ -47,6 +51,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_noise_error KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Read-only attribute that indicates whether excessive noise is present at the channel Y count inputs in quadrature clock mode; irrelevant in non-quadrature clock mode.
@@ -55,6 +61,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_preset KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + If the counter device supports preset registers, the preset count for channel Y is provided by this attribute.
@@ -62,6 +70,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_quadrature_mode KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Configure channel Y counter for non-quadrature or quadrature clock mode. Selecting non-quadrature clock mode will disable synchronous load mode. In quadrature clock mode, the channel Y
@@ -83,6 +93,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_countY_set_to_preset_on_index KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Whether to set channel Y counter with channel Y preset value when channel Y index input is active, or continuously count. Valid attribute values are boolean.
@@ -91,6 +103,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_indexY_index_polarity KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Active level of channel Y index input; irrelevant in non-synchronous load mode.
@@ -98,6 +112,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_indexY_synchronous_mode KernelVersion: 4.10 Contact: [email protected] Description: + This interface is deprecated; please use the Counter subsystem. + Configure channel Y counter for non-synchronous or synchronous load mode. Synchronous load mode cannot be selected in non-quadrature clock mode.
Signature · 1 line
2.21.0
PATCH v10 12/18 include/fsl: add common FlexTimer #defines in a separate header.
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
Several files are/will be using the same #defines to use the Flextimer module. Regroup them in a common file.
--- include/linux/fsl/ftm.h | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 include/linux/fsl/ftm.h
include/linux/fsl/ftm.h new file +88 -0
@@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef __FSL_FTM_H__ +#define __FSL_FTM_H__ + +#define FTM_SC 0x0/* Status And Control */ +#define FTM_CNT 0x4/* Counter */ +#define FTM_MOD 0x8/* Modulo */ + +#define FTM_CNTIN 0x4C/* Counter Initial Value */ +#define FTM_STATUS 0x50/* Capture And Compare Status */ +#define FTM_MODE 0x54/* Features Mode Selection */ +#define FTM_SYNC 0x58/* Synchronization */ +#define FTM_OUTINIT 0x5C/* Initial State For Channels Output */ +#define FTM_OUTMASK 0x60/* Output Mask */ +#define FTM_COMBINE 0x64/* Function For Linked Channels */ +#define FTM_DEADTIME 0x68/* Deadtime Insertion Control */ +#define FTM_EXTTRIG 0x6C/* FTM External Trigger */ +#define FTM_POL 0x70/* Channels Polarity */ +#define FTM_FMS 0x74/* Fault Mode Status */ +#define FTM_FILTER 0x78/* Input Capture Filter Control */ +#define FTM_FLTCTRL 0x7C/* Fault Control */ +#define FTM_QDCTRL 0x80/* Quadrature Decoder Control And Status */ +#define FTM_CONF 0x84/* Configuration */ +#define FTM_FLTPOL 0x88/* FTM Fault Input Polarity */ +#define FTM_SYNCONF 0x8C/* Synchronization Configuration */ +#define FTM_INVCTRL 0x90/* FTM Inverting Control */ +#define FTM_SWOCTRL 0x94/* FTM Software Output Control */ +#define FTM_PWMLOAD 0x98/* FTM PWM Load */ + +#define FTM_SC_CLK_MASK_SHIFT 3 +#define FTM_SC_CLK_MASK (3 << FTM_SC_CLK_MASK_SHIFT) +#define FTM_SC_TOF 0x80 +#define FTM_SC_TOIE 0x40 +#define FTM_SC_CPWMS 0x20 +#define FTM_SC_CLKS 0x18 +#define FTM_SC_PS_1 0x0 +#define FTM_SC_PS_2 0x1 +#define FTM_SC_PS_4 0x2 +#define FTM_SC_PS_8 0x3 +#define FTM_SC_PS_16 0x4 +#define FTM_SC_PS_32 0x5 +#define FTM_SC_PS_64 0x6 +#define FTM_SC_PS_128 0x7 +#define FTM_SC_PS_MASK 0x7 + +#define FTM_MODE_FAULTIE 0x80 +#define FTM_MODE_FAULTM 0x60 +#define FTM_MODE_CAPTEST 0x10 +#define FTM_MODE_PWMSYNC 0x8 +#define FTM_MODE_WPDIS 0x4 +#define FTM_MODE_INIT 0x2 +#define FTM_MODE_FTMEN 0x1 + +/* NXP Errata: The PHAFLTREN and PHBFLTREN bits are tide to zero internally +* and these bits cannot be set. Flextimer cannot use Filter in +* Quadrature Decoder Mode. +* https://community.nxp.com/thread/467648#comment-1010319 +*/ +#define FTM_QDCTRL_PHAFLTREN 0x80 +#define FTM_QDCTRL_PHBFLTREN 0x40 +#define FTM_QDCTRL_PHAPOL 0x20 +#define FTM_QDCTRL_PHBPOL 0x10 +#define FTM_QDCTRL_QUADMODE 0x8 +#define FTM_QDCTRL_QUADDIR 0x4 +#define FTM_QDCTRL_TOFDIR 0x2 +#define FTM_QDCTRL_QUADEN 0x1 + +#define FTM_FMS_FAULTF 0x80 +#define FTM_FMS_WPEN 0x40 +#define FTM_FMS_FAULTIN 0x10 +#define FTM_FMS_FAULTF3 0x8 +#define FTM_FMS_FAULTF2 0x4 +#define FTM_FMS_FAULTF1 0x2 +#define FTM_FMS_FAULTF0 0x1 + +#define FTM_CSC_BASE 0xC +#define FTM_CSC_MSB 0x20 +#define FTM_CSC_MSA 0x10 +#define FTM_CSC_ELSB 0x8 +#define FTM_CSC_ELSA 0x4 +#define FTM_CSC (_channel) (FTM_CSC_BASE + ((_channel) * 8)) + +#define FTM_CV_BASE 0x10 +#define FTM_CV (_channel) (FTM_CV_BASE + ((_channel) * 8)) + +#define FTM_PS_MAX 7 + +#endif
Signature · 1 line
2.21.0
PATCH v10 13/18 drivers/pwm: pwm-fsl-ftm: use common header for FlexTimer #defines
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
This also fixes the wrong value for the previously defined FTM_MODE_INIT macro (it was not used).
--- drivers/pwm/pwm-fsl-ftm.c | 44 +-------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-)
drivers/pwm/pwm-fsl-ftm.c +1 -43
@@ -22,51 +22,9 @@#include <linux/pwm.h> #include <linux/regmap.h> #include <linux/slab.h> +#include <linux/fsl/ftm.h> -#define FTM_SC 0x00 -#define FTM_SC_CLK_MASK_SHIFT 3 -#define FTM_SC_CLK_MASK (3 << FTM_SC_CLK_MASK_SHIFT)#define FTM_SC_CLK (c) (((c) + 1) << FTM_SC_CLK_MASK_SHIFT) -#define FTM_SC_PS_MASK 0x7 - -#define FTM_CNT 0x04 -#define FTM_MOD 0x08 - -#define FTM_CSC_BASE 0x0C -#define FTM_CSC_MSB BIT(5) -#define FTM_CSC_MSA BIT(4) -#define FTM_CSC_ELSB BIT(3) -#define FTM_CSC_ELSA BIT(2) -#define FTM_CSC (_channel) (FTM_CSC_BASE + ((_channel) * 8)) - -#define FTM_CV_BASE 0x10 -#define FTM_CV (_channel) (FTM_CV_BASE + ((_channel) * 8)) - -#define FTM_CNTIN 0x4C -#define FTM_STATUS 0x50 - -#define FTM_MODE 0x54 -#define FTM_MODE_FTMEN BIT(0) -#define FTM_MODE_INIT BIT(2) -#define FTM_MODE_PWMSYNC BIT(3) - -#define FTM_SYNC 0x58 -#define FTM_OUTINIT 0x5C -#define FTM_OUTMASK 0x60 -#define FTM_COMBINE 0x64 -#define FTM_DEADTIME 0x68 -#define FTM_EXTTRIG 0x6C -#define FTM_POL 0x70 -#define FTM_FMS 0x74 -#define FTM_FILTER 0x78 -#define FTM_FLTCTRL 0x7C -#define FTM_QDCTRL 0x80 -#define FTM_CONF 0x84 -#define FTM_FLTPOL 0x88 -#define FTM_SYNCONF 0x8C -#define FTM_INVCTRL 0x90 -#define FTM_SWOCTRL 0x94 -#define FTM_PWMLOAD 0x98enum fsl_pwm_clk {FSL_PWM_CLK_SYS ,
Signature · 1 line
2.21.0
PATCH v10 14/18 drivers/clocksource: timer-fsl-ftm: use common header for FlexTimer #defines
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
Common #defines have been moved to "linux/fsl/ftm.h". Thus making use of this file.
Also FTM_SC_CLK_SHIFT has been renamed to FTM_SC_CLK_MASK_SHIFT.
--- drivers/clocksource/timer-fsl-ftm.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/clocksource/timer-fsl-ftm.c +2 -13
@@ -19,20 +19,9 @@#include <linux/of_irq.h> #include <linux/sched_clock.h> #include <linux/slab.h> +#include <linux/fsl/ftm.h> -#define FTM_SC 0x00 -#define FTM_SC_CLK_SHIFT 3 -#define FTM_SC_CLK_MASK (0x3 << FTM_SC_CLK_SHIFT) -#define FTM_SC_CLK (c) ((c) << FTM_SC_CLK_SHIFT) -#define FTM_SC_PS_MASK 0x7 -#define FTM_SC_TOIE BIT(6) -#define FTM_SC_TOF BIT(7) - -#define FTM_CNT 0x04 -#define FTM_MOD 0x08 -#define FTM_CNTIN 0x4C - -#define FTM_PS_MAX 7 +#define FTM_SC_CLK (c) ((c) << FTM_SC_CLK_MASK_SHIFT)struct ftm_clock_device {void __iomem *clksrc_base;
Signature · 1 line
2.21.0
Re: [PATCH v10 14/18] drivers/clocksource: timer-fsl-ftm: use common header for FlexTimer #defines
Quoted 9 lines · William Breathitt Gray
From: Patrick Havelange <[email protected]>
Common #defines have been moved to "
linux/fsl/ftm.h". Thus making use of this file.
AlsoFTM_SC_CLK_SHIFThas been renamed toFTM_SC_CLK_MASK_SHIFT.Reviewed-by Esben Haabendal <[email protected]>Signed-off-by Patrick Havelange <[email protected]>Signed-off-by William Breathitt Gray <[email protected]>
Please, do pick my Acked-by from V2.
Quoted 32 lines
--- drivers/clocksource/timer-fsl-ftm.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)drivers/clocksource/timer-fsl-ftm.c +2
-13@@ -19,20 +19,9 @@#include <linux/of_irq.h> #include <linux/sched_clock.h> #include <linux/slab.h> +#include <linux/fsl/ftm.h> -#define FTM_SC 0x00 -#define FTM_SC_CLK_SHIFT 3 -#define FTM_SC_CLK_MASK (0x3 << FTM_SC_CLK_SHIFT) -#define FTM_SC_CLK (c) ((c) << FTM_SC_CLK_SHIFT) -#define FTM_SC_PS_MASK 0x7 -#define FTM_SC_TOIE BIT(6) -#define FTM_SC_TOF BIT(7) - -#define FTM_CNT 0x04 -#define FTM_MOD 0x08 -#define FTM_CNTIN 0x4C - -#define FTM_PS_MAX 7 +#define FTM_SC_CLK (c) ((c) << FTM_SC_CLK_MASK_SHIFT)struct ftm_clock_device {void __iomem *clksrc_base;
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
PATCH v10 15/18 dt-bindings: counter: ftm-quaddec
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
FlexTimer quadrature decoder driver.
--- .../bindings/counter/ftm-quaddec.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/counter/ftm-quaddec.txt
Documentation/devicetree/bindings/counter/ftm-quaddec.txt new file +18 -0
@@ -0,0 +1,18 @@ +FlexTimer Quadrature decoder counter + +This driver exposes a simple counter for the quadrature decoder mode. + +Required properties: +- compatible: Must be "fsl,ftm-quaddec". +- reg: Must be set to the memory region of the flextimer. + +Optional property: +- big-endian: Access the device registers in big-endian mode. + +Example: + counter0: counter@29d0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29d0000 0x0 0x10000>; + big-endian; + status = "disabled"; + };
Signature · 1 line
2.21.0
Rob Herring
maintainerRe: [PATCH v10 15/18] dt-bindings: counter: ftm-quaddec
Quoted 18 lines · William Breathitt Gray
From: Patrick Havelange <[email protected]>
FlexTimer quadrature decoder driver.
Reviewed-by Esben Haabendal <[email protected]>Signed-off-by Patrick Havelange <[email protected]>Signed-off-by William Breathitt Gray <[email protected]>--- .../bindings/counter/ftm-quaddec.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/counter/ftm-quaddec.txtDocumentation/devicetree/bindings/counter/ftm-quaddec.txt new file +0
-0
Documentation/devicetree/bindings/counter/ftm-quaddec.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/counter/ftm-quaddec.txt new file +6
-0@@ -0,0 +1,18 @@ +FlexTimer Quadrature decoder counter + +This driver exposes a simple counter for the quadrature decoder mode. + +Required properties: +- compatible: Must be "fsl,ftm-quaddec".
This needs an SoC specific compatible.
Documentation/devicetree/bindings/counter/ftm-quaddec.txt line 17
Quoted 11 lines
Documentation/devicetree/bindings/counter/ftm-quaddec.txt new file +11
-0+- reg: Must be set to the memory region of the flextimer. + +Optional property: +- big-endian: Access the device registers in big-endian mode. + +Example: + counter0: counter@29d0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29d0000 0x0 0x10000>; + big-endian; + status = "disabled";
Don't show status in examples.
Quoted 4 lines
Documentation/devicetree/bindings/counter/ftm-quaddec.txt new file +1
-0+ };Signature · 1 line
2.21.0
PATCH v10 16/18 counter: add FlexTimer Module Quadrature decoder counter driver
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
This driver exposes the counter for the quadrature decoder of the FlexTimer Module, present in the LS1021A soc.
--- drivers/counter/Kconfig | 9 + drivers/counter/Makefile | 1 + drivers/counter/ftm-quaddec.c | 356 ++++++++++++++++++++++++++++++++++ 3 files changed, 366 insertions(+) create mode 100644 drivers/counter/ftm-quaddec.c
drivers/counter/Kconfig +9 -0
@@ -48,4 +48,13 @@ config STM32_LPTIMER_CNT To compile this driver as a module, choose M here: the module will be called stm32-lptimer-cnt. +config FTM_QUADDEC + tristate "Flex Timer Module Quadrature decoder driver" + help + Select this option to enable the Flex Timer Quadrature decoder + driver. + + To compile this driver as a module, choose M here: the + module will be called ftm-quaddec. + endif # COUNTER
drivers/counter/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_COUNTER) += counter.o obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o +obj-$(CONFIG_FTM_QUADDEC) += ftm-quaddec.o
drivers/counter/ftm-quaddec.c new file +356 -0
356 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v10 17/18 counter: ftm-quaddec: Documentation: Add specific counter sysfs documentation
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
This adds documentation for the specific prescaler entry.
--- .../ABI/testing/sysfs-bus-counter-ftm-quaddec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec
Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec new file +16 -0
@@ -0,0 +1,16 @@ +What: /sys/bus/counter/devices/counterX/countY/prescaler_available +KernelVersion: 5.2 +Contact: [email protected] +Description: + Discrete set of available values for the respective Count Y + configuration are listed in this file. Values are delimited by + newline characters. + +What: /sys/bus/counter/devices/counterX/countY/prescaler +KernelVersion: 5.2 +Contact: [email protected] +Description: + Configure the prescaler value associated with Count Y. + On the FlexTimer, the counter clock source passes through a + prescaler (i.e. a counter). This acts like a clock + divider.
Signature · 1 line
2.21.0
PATCH v10 18/18 LS1021A: dtsi: add ftm quad decoder entries
In reply to William Breathitt GrayFrom: Patrick Havelange <[email protected]>
Add the 4 Quadrature counters for this board.
--- arch/arm/boot/dts/ls1021a.dtsi | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/arm/boot/dts/ls1021a.dtsi +28 -0
@@ -433,6 +433,34 @@ status = "disabled"; }; + counter0: counter@29d0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29d0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + + counter1: counter@29e0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29e0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + + counter2: counter@29f0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29f0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + + counter3: counter@2a00000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x2a00000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + gpio0: gpio@2300000 { compatible = "fsl,ls1021a-gpio", "fsl,qoriq-gpio"; reg = <0x0 0x2300000 0x0 0x10000>;
Signature · 1 line
2.21.0
Jonathan Cameron
maintainerQuoted 4 lines · On Tue, 2 Apr 2019 15:30:35 +0900 William Breathitt Gray…
Changes in v10:
- Fix minor typographical errors in documentation
- Merge the FlexTimer Module Quadrature decoder counter driver patches
Quoted 8 lines
This revision is functionally identical to the last; changes in this version were made to fix minor typos in the documentation files and also to pull in the new FTM quadrature decoder counter driver.
The Generic Counter API has been and is still in a feature freeze until it is merged into the mainline. The following features will be investigated after the merge: interrupt support for counter devices, and a character device interface for low-latency applications.
Hi William / al,
So the question is how to move this forwards? I'm happy with how it turned out and the existing drivers we had in IIO are a lot cleaner under the counter subsystem (other than the backwards compatibility for those that ever existed in IIO). For those not following closely the situation is:
1. Counter drivers never really fitted that well in IIO, because IIO is focused on an abstraction of individual channels that just doesn't match to these devices. It's just the wrong model.
2. William tried hard in earlier proposals to extend IIO to support these devices well, but it became so convoluted and involved I advised him that we were better off with a separate subsystem. The amount of code overlap between the core IIO support for counters and the reset of IIO was become very small and it would have been a maintenance problem for both.
https://lwn.net/Articles/729363/ gives some of the history
3. The new subsystem introduced by this series is fairly simple, clean and well aligned with the way these devices work. There are (I think) 4 initial drivers in this series from 4 different authors so it's got some practical review that way!
There are a couple more drivers under development. Right now, not everyone is aware of this work and so we have had a few developers potentially waste their time writing IIO drivers (which are then ported to this) rather that starting with the counter subsystem.
So what we are after is more review, or agreement that we can move this series forwards. For now the intent is that the counter subsystem will share the linux-iio mailing list etc but I don't think either William or I have any particularly strong views on how we actually handle the patches. I'm more than happy to take them through the IIO tree, if that works for everyone, particularly Greg as IIO goes through him after me. Once it is in a release, the cross dependency is broken and we can think about longer term approaches.
So Greg and others, how do we make progress here? If there are any obvious reviewers not on the CC list, please do draw their attention to this.
Thanks,
Jonathan
+CC linux-api as obviously one of the biggest areas for review is the new userspace ABI.
Quoted 83 lines
Benjamin Gaignard (2):
counter: Add STM32 Timer quadrature encoder
dt-bindings: counter: Document stm32 quadrature encoderFabrice Gasnier (2):
counter: stm32-lptimer: add counter device
dt-bindings: counter: Adjust dt-bindings for STM32 lptimer movePatrick Havelange (7):
include/fsl: add common FlexTimer #defines in a separate header.drivers/pwm: pwm-fsl-ftm: use common header for FlexTimer #definesdrivers/clocksource: timer-fsl-ftm: use common header for FlexTimer#definesdt-bindings: counter: ftm-quaddec
counter: add FlexTimer Module Quadrature decoder counter driver
counter: ftm-quaddec: Documentation: Add specific counter sysfs
documentation
LS1021A: dtsi: add ftm quad decoder entriesWilliam Breathitt Gray (7):
counter: Introduce the Generic Counter interface
counter: Documentation: Add Generic Counter sysfs documentation
docs: Add Generic Counter interface documentation
iio: 104-quad-8: Update license boilerplate
counter: 104-quad-8: Add Generic Counter interface support
counter: 104-quad-8: Documentation: Add Generic Counter sysfs
documentation
iio: counter: Add deprecation markings for IIO Counter attributesDocumentation/ABI/testing/sysfs-bus-counter | 230 +++ .../ABI/testing/sysfs-bus-counter-104-quad-8 | 36 + .../ABI/testing/sysfs-bus-counter-ftm-quaddec | 16 + Documentation/ABI/testing/sysfs-bus-iio | 8 + .../testing/sysfs-bus-iio-counter-104-quad-8 | 16 + .../bindings/counter/ftm-quaddec.txt | 18 + .../{iio => }/counter/stm32-lptimer-cnt.txt | 0 .../bindings/counter/stm32-timer-cnt.txt | 31 + .../devicetree/bindings/mfd/stm32-lptimer.txt | 2 +- .../devicetree/bindings/mfd/stm32-timers.txt | 7 + Documentation/driver-api/generic-counter.rst | 342 ++++ Documentation/driver-api/index.rst | 1 + MAINTAINERS | 15 +- arch/arm/boot/dts/ls1021a.dtsi | 28 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/clocksource/timer-fsl-ftm.c | 15 +- drivers/{iio => }/counter/104-quad-8.c | 782 +++++++- drivers/counter/Kconfig | 60 + drivers/counter/Makefile | 10 + drivers/counter/counter.c | 1567 +++++++++++++++++ drivers/counter/ftm-quaddec.c | 356 ++++ drivers/{iio => }/counter/stm32-lptimer-cnt.c | 361 +++- drivers/counter/stm32-timer-cnt.c | 390 ++++ drivers/iio/Kconfig | 1 - drivers/iio/Makefile | 1 - drivers/iio/counter/Kconfig | 34 - drivers/iio/counter/Makefile | 8 - drivers/pwm/pwm-fsl-ftm.c | 44 +- include/linux/counter.h | 510 ++++++ include/linux/counter_enum.h | 45 + include/linux/fsl/ftm.h | 88 + 32 files changed, 4877 insertions(+), 148 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-counter create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-104-quad-8 create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec create mode 100644 Documentation/devicetree/bindings/counter/ftm-quaddec.txt rename Documentation/devicetree/bindings/{iio => }/counter/stm32-lptimer-cnt.txt (100%) create mode 100644 Documentation/devicetree/bindings/counter/stm32-timer-cnt.txt create mode 100644 Documentation/driver-api/generic-counter.rst rename drivers/{iio => }/counter/104-quad-8.c (44%) create mode 100644 drivers/counter/Kconfig create mode 100644 drivers/counter/Makefile create mode 100644 drivers/counter/counter.c create mode 100644 drivers/counter/ftm-quaddec.c rename drivers/{iio => }/counter/stm32-lptimer-cnt.c (51%) create mode 100644 drivers/counter/stm32-timer-cnt.c delete mode 100644 drivers/iio/counter/Kconfig delete mode 100644 drivers/iio/counter/Makefile create mode 100644 include/linux/counter.h create mode 100644 include/linux/counter_enum.h create mode 100644 include/linux/fsl/ftm.h
Quoted 16 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 2 Apr 2019 15:30:35 +0900 William Breathitt Gray…
Changes in v10:
- Fix minor typographical errors in documentation
- Merge the FlexTimer Module Quadrature decoder counter driver patchesQuoted 8 lines
This revision is functionally identical to the last; changes in this version were made to fix minor typos in the documentation files and also to pull in the new FTM quadrature decoder counter driver.
The Generic Counter API has been and is still in a feature freeze until it is merged into the mainline. The following features will be investigated after the merge: interrupt support for counter devices, and a character device interface for low-latency applications.
Quoted 6 lines
Hi William / al,
So the question is how to move this forwards? I'm happy with how it turned out and the existing drivers we had in IIO are a lot cleaner under the counter subsystem (other than the backwards compatibility for those that ever existed in IIO). For those not following closely the situation is:
I've now sucked this into my staging-testing branch and if 0-day is fine with it, I'll merge it to staging-next in a day or so. This way you can build on it for any iio drivers that might be coming.
I do have reservations about that one sysfs file that is multi-line, and I think it will come to bite you in the end over time, so I reserve the right to say "I told you so" when that happens...
But, I don't have a better answer for it now, so don't really worry about it :)
thanks,
greg k-h
Jonathan Cameron
maintainerQuoted 19 lines · On Thu, 25 Apr 2019 21:36:24 +0200 Greg KH <[email protected]> wrote:
Quoted 18 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 2 Apr 2019 15:30:35 +0900 William Breathitt Gray…
Changes in v10:
- Fix minor typographical errors in documentation
- Merge the FlexTimer Module Quadrature decoder counter driver patchesQuoted 8 lines
This revision is functionally identical to the last; changes in this version were made to fix minor typos in the documentation files and also to pull in the new FTM quadrature decoder counter driver.
The Generic Counter API has been and is still in a feature freeze until it is merged into the mainline. The following features will be investigated after the merge: interrupt support for counter devices, and a character device interface for low-latency applications.
Hi William / al,
Quoted 8 lines
Quoted 4 lines
So the question is how to move this forwards? I'm happy with how it turned out and the existing drivers we had in IIO are a lot cleaner under the counter subsystem (other than the backwards compatibility for those that ever existed in IIO). For those not following closely the situation is:
I've now sucked this into my staging-testing branch and if 0-day is fine with it, I'll merge it to staging-next in a day or so. This way you can build on it for any iio drivers that might be coming.
Great thanks.
Quoted 11 lines
I do have reservations about that one sysfs file that is multi-line, and I think it will come to bite you in the end over time, so I reserve the right to say "I told you so" when that happens...
But, I don't have a better answer for it now, so don't really worry about it :)
thanks,
greg k-h
Looks like a few late breaking comments came in, but nothing that can't be fixed up before this reaches a release.
Thanks,
Jonathan