diff mbox series

[2/2] Input: sun4i-lradc-keys - add support for R329 LRADC

Message ID BYAPR20MB2472CFFE1C453824BFF49219BCF79@BYAPR20MB2472.namprd20.prod.outlook.com (mailing list archive)
State New, archived
Headers show
Series [1/2] dt-bindings: input: sun4i-lradc-keys: add R329 LRADC binding | expand

Commit Message

icenowy@outlook.com April 22, 2022, 4:07 p.m. UTC
From: Icenowy Zheng <icenowy@sipeed.com>

Allwinner R329 has similar LRADC with previous Allwinner SoCs, with a
reference voltage of 3/4 AVCC. However, compared with previous SoCs, it
has bus clock and reset for LRADC.

Add support for it.

Signed-off-by: Icenowy Zheng <icenowy@sipeed.com>
---
 drivers/input/keyboard/sun4i-lradc-keys.c | 39 +++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff mbox series

Patch

diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c
index 4a796bed48ac..29365a0646dc 100644
--- a/drivers/input/keyboard/sun4i-lradc-keys.c
+++ b/drivers/input/keyboard/sun4i-lradc-keys.c
@@ -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_bus_gate_reset:		Whether the LRADC hardware has bus gate/reset
  */
 struct lradc_variant {
 	u8 divisor_numerator;
 	u8 divisor_denominator;
+	bool has_bus_gate_reset;
 };
 
 static const struct lradc_variant lradc_variant_a10 = {
@@ -74,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_bus_gate_reset = true,
+};
+
 struct sun4i_lradc_keymap {
 	u32 voltage;
 	u32 keycode;
@@ -84,6 +94,8 @@  struct sun4i_lradc_data {
 	struct input_dev *input;
 	void __iomem *base;
 	struct regulator *vref_supply;
+	struct clk *bus_clk;
+	struct reset_control *bus_rst;
 	struct sun4i_lradc_keymap *chan0_map;
 	const struct lradc_variant *variant;
 	u32 chan0_map_count;
@@ -140,6 +152,16 @@  static int sun4i_lradc_open(struct input_dev *dev)
 	if (error)
 		return error;
 
+	if (lradc->variant->has_bus_gate_reset) {
+		error = reset_control_deassert(lradc->bus_rst);
+		if (error)
+			return error;
+
+		error = clk_prepare_enable(lradc->bus_clk);
+		if (error)
+			return error;
+	}
+
 	lradc->vref = regulator_get_voltage(lradc->vref_supply) *
 		      lradc->variant->divisor_numerator /
 		      lradc->variant->divisor_denominator;
@@ -164,6 +186,11 @@  static void sun4i_lradc_close(struct input_dev *dev)
 		SAMPLE_RATE(2), lradc->base + LRADC_CTRL);
 	writel(0, lradc->base + LRADC_INTC);
 
+	if (lradc->variant->has_bus_gate_reset) {
+		clk_disable_unprepare(lradc->bus_clk);
+		reset_control_assert(lradc->bus_rst);
+	}
+
 	regulator_disable(lradc->vref_supply);
 }
 
@@ -272,6 +299,16 @@  static int sun4i_lradc_probe(struct platform_device *pdev)
 	if (IS_ERR(lradc->base))
 		return PTR_ERR(lradc->base);
 
+	if (lradc->variant->has_bus_gate_reset) {
+		lradc->bus_clk = devm_clk_get(dev, NULL);
+		if (IS_ERR(lradc->bus_clk))
+			return PTR_ERR(lradc->bus_clk);
+
+		lradc->bus_rst = devm_reset_control_get(dev, NULL);
+		if (IS_ERR(lradc->bus_rst))
+			return PTR_ERR(lradc->bus_rst);
+	}
+
 	error = devm_request_irq(dev, platform_get_irq(pdev, 0),
 				 sun4i_lradc_irq, 0,
 				 "sun4i-a10-lradc-keys", lradc);
@@ -290,6 +327,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);