Skip to content

Commit d895882

Browse files
Fabrice GasnierLee Jones
authored andcommitted
iio: counter: Add support for STM32 LPTimer
Add support for STM32 Low-Power Timer, that can be used as counter or quadrature encoder. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 717e692 commit d895882

File tree

4 files changed

+450
-0
lines changed

4 files changed

+450
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
What: /sys/bus/iio/devices/iio:deviceX/in_count0_preset
2+
KernelVersion: 4.13
3+
Contact: fabrice.gasnier@st.com
4+
Description:
5+
Reading returns the current preset value. Writing sets the
6+
preset value. Encoder counts continuously from 0 to preset
7+
value, depending on direction (up/down).
8+
9+
What: /sys/bus/iio/devices/iio:deviceX/in_count_quadrature_mode_available
10+
KernelVersion: 4.13
11+
Contact: fabrice.gasnier@st.com
12+
Description:
13+
Reading returns the list possible quadrature modes.
14+
15+
What: /sys/bus/iio/devices/iio:deviceX/in_count0_quadrature_mode
16+
KernelVersion: 4.13
17+
Contact: fabrice.gasnier@st.com
18+
Description:
19+
Configure the device counter quadrature modes:
20+
- non-quadrature:
21+
Encoder IN1 input servers as the count input (up
22+
direction).
23+
- quadrature:
24+
Encoder IN1 and IN2 inputs are mixed to get direction
25+
and count.
26+
27+
What: /sys/bus/iio/devices/iio:deviceX/in_count_polarity_available
28+
KernelVersion: 4.13
29+
Contact: fabrice.gasnier@st.com
30+
Description:
31+
Reading returns the list possible active edges.
32+
33+
What: /sys/bus/iio/devices/iio:deviceX/in_count0_polarity
34+
KernelVersion: 4.13
35+
Contact: fabrice.gasnier@st.com
36+
Description:
37+
Configure the device encoder/counter active edge:
38+
- rising-edge
39+
- falling-edge
40+
- both-edges
41+
42+
In non-quadrature mode, device counts up on active edge.
43+
In quadrature mode, encoder counting scenarios are as follows:
44+
----------------------------------------------------------------
45+
| Active | Level on | IN1 signal | IN2 signal |
46+
| edge | opposite |------------------------------------------
47+
| | signal | Rising | Falling | Rising | Falling |
48+
----------------------------------------------------------------
49+
| Rising | High -> | Down | - | Up | - |
50+
| edge | Low -> | Up | - | Down | - |
51+
----------------------------------------------------------------
52+
| Falling | High -> | - | Up | - | Down |
53+
| edge | Low -> | - | Down | - | Up |
54+
----------------------------------------------------------------
55+
| Both | High -> | Down | Up | Up | Down |
56+
| edges | Low -> | Up | Down | Down | Up |
57+
----------------------------------------------------------------

drivers/iio/counter/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ config 104_QUAD_8
2121
The base port addresses for the devices may be configured via the base
2222
array module parameter.
2323

24+
config STM32_LPTIMER_CNT
25+
tristate "STM32 LP Timer encoder counter driver"
26+
depends on MFD_STM32_LPTIMER || COMPILE_TEST
27+
help
28+
Select this option to enable STM32 Low-Power Timer quadrature encoder
29+
and counter driver.
30+
31+
To compile this driver as a module, choose M here: the
32+
module will be called stm32-lptimer-cnt.
2433
endmenu

drivers/iio/counter/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
# When adding new entries keep the list in alphabetical order
66

77
obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o
8+
obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o

0 commit comments

Comments
 (0)