[PATCH] pinctrl/sunxi: adding input-debounce-ns property
Marjan Pascolo
marjan.pascolo at trexom.it
Wed Feb 10 11:22:37 EST 2021
On Allwinner SoC interrupt debounce can be controlled by two oscillator
(32KHz and 24MHz) and a prescale divider.
Oscillator and prescale divider are set through
device tree property "input-debounce" which have 1uS accuracy.
For acheive nS precision a new device tree poperty is made
named "input-debounce-ns".
"input-debounce-ns" is checked only if "input-debounce"
property is not defined.
Suggested-by: Maxime Ripard <maxime at cerno.tech>
Signed-off-by: Marjan Pascolo <marjan.pascolo at trexom.it>
---
---
.../pinctrl/allwinner,sun4i-a10-pinctrl.yaml | 9 +++++++
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 25 ++++++++++++++++---
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git
a/Documentation/devicetree/bindings/pinctrl/allwinner,sun4i-a10-pinctrl.yaml
b/Documentation/devicetree/bindings/pinctrl/allwinner,sun4i-a10-pinctrl.yaml
index 5240487dfe50..346776de3a44 100644
---
a/Documentation/devicetree/bindings/pinctrl/allwinner,sun4i-a10-pinctrl.yaml
+++
b/Documentation/devicetree/bindings/pinctrl/allwinner,sun4i-a10-pinctrl.yaml
@@ -93,6 +93,15 @@ properties:
minItems: 1
maxItems: 5
+ input-debounce-ns:
+ description:
+ Debouncing periods in nanoseconds, one period per interrupt
+ bank found in the controller.
+ Only checked if input-debounce is not present
+ $ref: /schemas/types.yaml#/definitions/uint32-array
+ minItems: 1
+ maxItems: 5
+
patternProperties:
# It's pretty scary, but the basic idea is that:
# - One node name can start with either s- or r- for PRCM nodes,
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index dc8d39ae045b..869b6d5743ba 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -1335,14 +1335,31 @@ static int sunxi_pinctrl_setup_debounce(struct
sunxi_pinctrl *pctl,
struct clk *hosc, *losc;
u8 div, src;
int i, ret;
+ /* Keeping for loop below clean */
+ const char* debounce_prop_name;
+ unsigned long debounce_dividend;
/* Deal with old DTs that didn't have the oscillators */
if (of_clk_get_parent_count(node) != 3)
return 0;
+ /*
+ * Distinguish between simple input-debounce
+ * and new input-debounce-ns
+ */
+
/* If we don't have any setup, bail out */
- if (!of_find_property(node, "input-debounce", NULL))
- return 0;
+ if (!of_find_property(node, "input-debounce", NULL)) {
+ if(!of_find_property(node, "input-debounce-ns", NULL)) {
+ return 0;
+ } else {
+ debounce_prop_name="input-debounce-ns";
+ debounce_dividend=NSEC_PER_SEC;
+ }
+ } else {
+ debounce_prop_name="input-debounce";
+ debounce_dividend=USEC_PER_SEC;
+ }
losc = devm_clk_get(pctl->dev, "losc");
if (IS_ERR(losc))
@@ -1356,7 +1373,7 @@ static int sunxi_pinctrl_setup_debounce(struct
sunxi_pinctrl *pctl,
unsigned long debounce_freq;
u32 debounce;
- ret = of_property_read_u32_index(node, "input-debounce",
+ ret = of_property_read_u32_index(node, debounce_prop_name,
i, &debounce);
if (ret)
return ret;
@@ -1364,7 +1381,7 @@ static int sunxi_pinctrl_setup_debounce(struct
sunxi_pinctrl *pctl,
if (!debounce)
continue;
- debounce_freq = DIV_ROUND_CLOSEST(USEC_PER_SEC, debounce);
+ debounce_freq = DIV_ROUND_CLOSEST(debounce_dividend, debounce);
losc_div = sunxi_pinctrl_get_debounce_div(losc,
debounce_freq,
&losc_diff);
--
2.22.0.windows.1
More information about the linux-arm-kernel
mailing list