Skip to contentSkip to conversation

dt-bindings: input: sun4i-lradc-keys: Add R329 and D1 compatibles

PATCH Applied Samuel Holland 3 participants 8 messages Apr 14, 2022 – Apr 25, 2022

Subsystems (5)
lore
Share & tools
lore

Samuel Holland

author maintainer
#0 lore raw

PATCH v2 1/3 dt-bindings: input: sun4i-lradc-keys: Add R329 and D1 compatibles

The R329 and D1 SoCs each contain an LRADC with a programming interface compatible to earlier LRADCs. However, the LRADC now has its own clock gate and reset line, instead of being always active.

To support this, add clock/reset properties to the binding, and require them for the variant in the new SoCs.

---

(no changes since v1)

 .../input/allwinner,sun4i-a10-lradc-keys.yaml | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
Documentation/devicetree/bindings/input/allwinner,sun4i-a10-lradc-keys.yaml +22 -0
index d74f2002409e..3399fc288afb 100644
@@ -18,10 +18,20 @@ properties:
       - items:
           - const: allwinner,sun50i-a64-lradc
           - const: allwinner,sun8i-a83t-r-lradc
+      - const: allwinner,sun50i-r329-lradc
+      - items:
+          - const: allwinner,sun20i-d1-lradc
+          - const: allwinner,sun50i-r329-lradc
 
   reg:
     maxItems: 1
 
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
   interrupts:
     maxItems: 1
 
@@ -68,6 +78,18 @@ required:
   - interrupts
   - vref-supply
 
+if:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - allwinner,sun50i-r329-lradc
+
+then:
+  required:
+    - clocks
+    - resets
+
 additionalProperties: false
 
 examples:
Signature · 1 line
2.35.1
author maintainer
#1 lore raw

PATCH v2 2/3 Input: sun4i-lradc-keys: Add optional clock/reset support

Until the R329, the LRADC hardware was always active. Now it requires enabling a clock gate and deasserting a reset line. Add support for this variant of the hardware.

---

Changes in v2:
- Guard the code with a flag instead of using "_optional" variants.

 drivers/input/keyboard/sun4i-lradc-keys.c | 33 +++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/input/keyboard/sun4i-lradc-keys.c +33 -0
index 4a796bed48ac..5630334a6c09 100644
@@ -14,6 +14,7 @@
  * there are no boards known to use channel 1.
  */
 
+#include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/input.h>
@@ -23,6 +24,7 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 #include <linux/slab.h>
 
 #define LRADC_CTRL		0x00
@@ -58,10 +60,12 @@
 /* struct lradc_variant - Describe sun4i-a10-lradc-keys hardware variant
  * @divisor_numerator:		The numerator of lradc Vref internally divisor
  * @divisor_denominator:	The denominator of lradc Vref internally divisor
+ * @has_clock_reset:		If the binding requires a clock and reset
  */
 struct lradc_variant {
 	u8 divisor_numerator;
 	u8 divisor_denominator;
+	bool has_clock_reset;
 };
 
 static const struct lradc_variant lradc_variant_a10 = {
@@ -83,6 +87,8 @@ struct sun4i_lradc_data {
 	struct device *dev;
 	struct input_dev *input;
 	void __iomem *base;
+	struct clk *clk;
+	struct reset_control *reset;
 	struct regulator *vref_supply;
 	struct sun4i_lradc_keymap *chan0_map;
 	const struct lradc_variant *variant;
@@ -140,6 +146,14 @@ static int sun4i_lradc_open(struct input_dev *dev)
 	if (error)
 		return error;
 
+	error = reset_control_deassert(lradc->reset);
+	if (error)
+		goto err_disable_reg;
+
+	error = clk_prepare_enable(lradc->clk);
+	if (error)
+		goto err_assert_reset;
+
 	lradc->vref = regulator_get_voltage(lradc->vref_supply) *
 		      lradc->variant->divisor_numerator /
 		      lradc->variant->divisor_denominator;
@@ -153,6 +167,13 @@ static int sun4i_lradc_open(struct input_dev *dev)
 	writel(CHAN0_KEYUP_IRQ | CHAN0_KEYDOWN_IRQ, lradc->base + LRADC_INTC);
 
 	return 0;
+
+err_assert_reset:
+	reset_control_assert(lradc->reset);
+err_disable_reg:
+	regulator_disable(lradc->vref_supply);
+
+	return error;
 }
 
 static void sun4i_lradc_close(struct input_dev *dev)
@@ -164,6 +185,8 @@ static void sun4i_lradc_close(struct input_dev *dev)
 		SAMPLE_RATE(2), lradc->base + LRADC_CTRL);
 	writel(0, lradc->base + LRADC_INTC);
 
+	clk_disable_unprepare(lradc->clk);
+	reset_control_assert(lradc->reset);
 	regulator_disable(lradc->vref_supply);
 }
 
@@ -243,6 +266,16 @@ static int sun4i_lradc_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	if (lradc->variant->has_clock_reset) {
+		lradc->clk = devm_clk_get(dev, NULL);
+		if (IS_ERR(lradc->clk))
+			return PTR_ERR(lradc->clk);
+
+		lradc->reset = devm_reset_control_get_exclusive(dev, NULL);
+		if (IS_ERR(lradc->reset))
+			return PTR_ERR(lradc->reset);
+	}
+
 	lradc->vref_supply = devm_regulator_get(dev, "vref");
 	if (IS_ERR(lradc->vref_supply))
 		return PTR_ERR(lradc->vref_supply);
Signature · 1 line
2.35.1
maintainer Acked-by on v2 2/3
#2 lore raw

Re: [PATCH v2 2/3] Input: sun4i-lradc-keys: Add optional clock/reset support

Dne četrtek, 14. april 2022 ob 02:23:47 CEST je Samuel Holland napisal(a):

Quoted 5 lines

Until the R329, the LRADC hardware was always active. Now it requires enabling a clock gate and deasserting a reset line. Add support for this variant of the hardware.

Best regards,
Jernej

Quoted 30 lines

---

Changes in v2:
- Guard the code with a flag instead of using "_optional" variants.

 drivers/input/keyboard/sun4i-lradc-keys.c | 33 +++++++++++++++++++++++
 1 file changed, 33 insertions(+)
(quoted diff) +0 -0

b/drivers/input/keyboard/sun4i-lradc-keys.c index
4a796bed48ac..5630334a6c09 100644

drivers/input/keyboard/sun4i-lradc-keys.c +2 -0
@@ -14,6 +14,7 @@
  * there are no boards known to use channel 1.
  */
 
+#include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/input.h>
@@ -23,6 +24,7 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
 #include <linux/slab.h>
 
 #define LRADC_CTRL		0x00

drivers/input/keyboard/sun4i-lradc-keys.c line 61

Quoted 2 lines
drivers/input/keyboard/sun4i-lradc-keys.c +0 -0
@@ -58,10 +60,12 @@
 /* struct lradc_variant - Describe sun4i-a10-lradc-keys hardware variant
  * @divisor_numerator:		The numerator of lradc Vref internally 

divisor

drivers/input/keyboard/sun4i-lradc-keys.c line 62

Quoted 1 line
drivers/input/keyboard/sun4i-lradc-keys.c +0 -0
  * @divisor_denominator:	The denominator of lradc Vref internally 

divisor

Quoted 34 lines
drivers/input/keyboard/sun4i-lradc-keys.c +12 -0
+ * @has_clock_reset:		If the binding requires a clock and reset
  */
 struct lradc_variant {
 	u8 divisor_numerator;
 	u8 divisor_denominator;
+	bool has_clock_reset;
 };
 
 static const struct lradc_variant lradc_variant_a10 = {
@@ -83,6 +87,8 @@ struct sun4i_lradc_data {
 	struct device *dev;
 	struct input_dev *input;
 	void __iomem *base;
+	struct clk *clk;
+	struct reset_control *reset;
 	struct regulator *vref_supply;
 	struct sun4i_lradc_keymap *chan0_map;
 	const struct lradc_variant *variant;
@@ -140,6 +146,14 @@ static int sun4i_lradc_open(struct input_dev *dev)
 	if (error)
 		return error;
 
+	error = reset_control_deassert(lradc->reset);
+	if (error)
+		goto err_disable_reg;
+
+	error = clk_prepare_enable(lradc->clk);
+	if (error)
+		goto err_assert_reset;
+
 	lradc->vref = regulator_get_voltage(lradc->vref_supply) *
 		      lradc->variant->divisor_numerator /
 		      lradc->variant->divisor_denominator;

drivers/input/keyboard/sun4i-lradc-keys.c static int sun4i_lradc_open(struct input_dev *dev) · line 167

Quoted 1 line
drivers/input/keyboard/sun4i-lradc-keys.c +0 -0
@@ -153,6 +167,13 @@ static int sun4i_lradc_open(struct input_dev *dev)
 	writel(CHAN0_KEYUP_IRQ | CHAN0_KEYDOWN_IRQ, lradc->base + 

LRADC_INTC);

Quoted 22 lines
drivers/input/keyboard/sun4i-lradc-keys.c +9 -0
 	return 0;
+
+err_assert_reset:
+	reset_control_assert(lradc->reset);
+err_disable_reg:
+	regulator_disable(lradc->vref_supply);
+
+	return error;
 }
 
 static void sun4i_lradc_close(struct input_dev *dev)
@@ -164,6 +185,8 @@ static void sun4i_lradc_close(struct input_dev *dev)
 		SAMPLE_RATE(2), lradc->base + LRADC_CTRL);
 	writel(0, lradc->base + LRADC_INTC);
 
+	clk_disable_unprepare(lradc->clk);
+	reset_control_assert(lradc->reset);
 	regulator_disable(lradc->vref_supply);
 }
 

drivers/input/keyboard/sun4i-lradc-keys.c static int sun4i_lradc_probe(struct platform_device · line 274

Quoted 9 lines
drivers/input/keyboard/sun4i-lradc-keys.c +6 -0
@@ -243,6 +266,16 @@ static int sun4i_lradc_probe(struct platform_device
 *pdev) return -EINVAL;
 	}
 
+	if (lradc->variant->has_clock_reset) {
+		lradc->clk = devm_clk_get(dev, NULL);
+		if (IS_ERR(lradc->clk))
+			return PTR_ERR(lradc->clk);
+
+		lradc->reset = devm_reset_control_get_exclusive(dev, 

NULL);

Quoted 7 lines
drivers/input/keyboard/sun4i-lradc-keys.c +4 -0
+		if (IS_ERR(lradc->reset))
+			return PTR_ERR(lradc->reset);
+	}
+
 	lradc->vref_supply = devm_regulator_get(dev, "vref");
 	if (IS_ERR(lradc->vref_supply))
 		return PTR_ERR(lradc->vref_supply);
maintainer Applied
#3 lore raw

Re: [PATCH v2 2/3] Input: sun4i-lradc-keys: Add optional clock/reset support

In reply to Samuel Holland
Quoted 5 lines · Samuel Holland

Until the R329, the LRADC hardware was always active. Now it requires enabling a clock gate and deasserting a reset line. Add support for this variant of the hardware.

Applied, thank you.

Signature · 1 line
Dmitry
author maintainer
#4 lore raw

PATCH v2 3/3 Input: sun4i-lradc-keys: Add support for R329 and D1

In reply to Samuel Holland

This LRADC variant uses the same 3/4*AVCC reference voltage as the A83T variant. The R329 and D1 LRADCs appear to be identical, so D1 support is accomplished through having the R329 LRADC as a fallback compatible.

---

Changes in v2:
- Set the new flag for the R329 variant.

 drivers/input/keyboard/sun4i-lradc-keys.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/input/keyboard/sun4i-lradc-keys.c +8 -0
index 5630334a6c09..8f9bfb05244d 100644
@@ -78,6 +78,12 @@ static const struct lradc_variant r_lradc_variant_a83t = {
 	.divisor_denominator = 4
 };
 
+static const struct lradc_variant lradc_variant_r329 = {
+	.divisor_numerator = 3,
+	.divisor_denominator = 4,
+	.has_clock_reset = true,
+};
+
 struct sun4i_lradc_keymap {
 	u32 voltage;
 	u32 keycode;
@@ -323,6 +329,8 @@ static const struct of_device_id sun4i_lradc_of_match[] = {
 		.data = &lradc_variant_a10 },
 	{ .compatible = "allwinner,sun8i-a83t-r-lradc",
 		.data = &r_lradc_variant_a83t },
+	{ .compatible = "allwinner,sun50i-r329-lradc",
+		.data = &lradc_variant_r329 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, sun4i_lradc_of_match);
Signature · 1 line
2.35.1
maintainer Acked-by on v2 3/3
#5 lore raw

Re: [PATCH v2 3/3] Input: sun4i-lradc-keys: Add support for R329 and D1

Dne četrtek, 14. april 2022 ob 02:23:48 CEST je Samuel Holland napisal(a):

Quoted 5 lines

This LRADC variant uses the same 3/4*AVCC reference voltage as the A83T variant. The R329 and D1 LRADCs appear to be identical, so D1 support is accomplished through having the R329 LRADC as a fallback compatible.

Best regards,
Jernej

Quoted 35 lines

---

Changes in v2:
- Set the new flag for the R329 variant.

 drivers/input/keyboard/sun4i-lradc-keys.c | 8 ++++++++
 1 file changed, 8 insertions(+)
(quoted diff) +0 -0

b/drivers/input/keyboard/sun4i-lradc-keys.c index
5630334a6c09..8f9bfb05244d 100644

drivers/input/keyboard/sun4i-lradc-keys.c +0 -0
@@ -78,6 +78,12 @@ static const struct lradc_variant r_lradc_variant_a83t =

{ .divisor_denominator = 4
};

drivers/input/keyboard/sun4i-lradc-keys.c +8 -0
+static const struct lradc_variant lradc_variant_r329 = {
+	.divisor_numerator = 3,
+	.divisor_denominator = 4,
+	.has_clock_reset = true,
+};
+
 struct sun4i_lradc_keymap {
 	u32 voltage;
 	u32 keycode;
@@ -323,6 +329,8 @@ static const struct of_device_id sun4i_lradc_of_match[]
 = { .data = &lradc_variant_a10 },
 	{ .compatible = "allwinner,sun8i-a83t-r-lradc",
 		.data = &r_lradc_variant_a83t },
+	{ .compatible = "allwinner,sun50i-r329-lradc",
+		.data = &lradc_variant_r329 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, sun4i_lradc_of_match);
maintainer Applied
#6 lore raw

Re: [PATCH v2 3/3] Input: sun4i-lradc-keys: Add support for R329 and D1

In reply to Samuel Holland
Quoted 5 lines · Samuel Holland

This LRADC variant uses the same 3/4*AVCC reference voltage as the A83T variant. The R329 and D1 LRADCs appear to be identical, so D1 support is accomplished through having the R329 LRADC as a fallback compatible.

Applied, thank you.

Signature · 1 line
Dmitry
maintainer Applied
#7 lore raw
In reply to Samuel Holland
Quoted 10 lines · Samuel Holland

The R329 and D1 SoCs each contain an LRADC with a programming interface compatible to earlier LRADCs. However, the LRADC now has its own clock gate and reset line, instead of being always active.

To support this, add clock/reset properties to the binding, and require them for the variant in the new SoCs.

Applied, thank you.

Signature · 1 line
Dmitry