From b0d0e0e7cbe9d70a50a8a9cfdcfdffb028d6cef7 Mon Sep 17 00:00:00 2001
From: Exodus <zjemcikolege@protonmail.com>
Date: Wed, 30 Apr 2025 23:55:25 +0200
Subject: [PATCH 1/6] h616: add keys

KEY1 and KEY2 VOL +/-
---
 .../arm64/boot/dts/allwinner/overlay/Makefile |  1 +
 .../allwinner/overlay/sun50i-h616-keys.dtso   | 28 +++++++++++++++++++
 .../arm64/boot/dts/allwinner/sun50i-h616.dtsi |  1 +
 drivers/input/keyboard/sun4i-lradc-keys.c     |  8 ++++++
 4 files changed, 38 insertions(+)
 create mode 100644 arch/arm64/boot/dts/allwinner/overlay/sun50i-h616-keys.dtso

diff --git a/arch/arm64/boot/dts/allwinner/overlay/Makefile b/arch/arm64/boot/dts/allwinner/overlay/Makefile
index 3b0e2393552d..f637933c003f 100644
--- a/arch/arm64/boot/dts/allwinner/overlay/Makefile
+++ b/arch/arm64/boot/dts/allwinner/overlay/Makefile
@@ -71,6 +71,7 @@ dtb-$(CONFIG_ARCH_SUNXI) += \
 	sun50i-h616-i2c3-ph.dtbo \
 	sun50i-h616-i2c4-pg.dtbo \
 	sun50i-h616-i2c4-ph.dtbo \
+	sun50i-h616-keys.dtbo \
 	sun50i-h616-pwm1-ph3.dtbo \
 	sun50i-h616-pwm1-pi11.dtbo \
 	sun50i-h616-pwm2-ph2.dtbo \
diff --git a/arch/arm64/boot/dts/allwinner/overlay/sun50i-h616-keys.dtso b/arch/arm64/boot/dts/allwinner/overlay/sun50i-h616-keys.dtso
new file mode 100644
index 000000000000..e8a5665d77ce
--- /dev/null
+++ b/arch/arm64/boot/dts/allwinner/overlay/sun50i-h616-keys.dtso
@@ -0,0 +1,28 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+	compatible = "xunlong,orangepi-zero2w", "allwinner,sun50i-h616", "allwinner,sun50i-h618";
+
+	fragment@0 {
+		target = <&lradc>;
+		__overlay__ {
+			vref-supply = <&reg_aldo1>;
+			status = "okay";
+
+			button-500 {
+				label = "KEY_VOLUMEUP";
+				linux,code = <115>;    // KEY_VOLUMEUP
+				channel = <0>;
+				voltage = <500000>;
+			};
+
+			button-800 {
+				label = "KEY_VOLUMEDOWN";
+				linux,code = <114>; // KEY_VOLUMEDOWN
+				channel = <0>;
+				voltage = <800000>;
+			};
+		};
+	};
+};
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi
index 0f4587be1c0e..7ccc45ff3446 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi
@@ -13,6 +13,7 @@
 #include <dt-bindings/reset/sun50i-h6-r-ccu.h>
 #include <dt-bindings/reset/sun8i-de2.h>
 #include <dt-bindings/thermal/thermal.h>
+#include <dt-bindings/input/input.h>
 
 / {
 	interrupt-parent = <&gic>;
diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c
index 5730f08f82d7..0ee681630f9c 100644
--- a/drivers/input/keyboard/sun4i-lradc-keys.c
+++ b/drivers/input/keyboard/sun4i-lradc-keys.c
@@ -86,6 +86,12 @@ static const struct lradc_variant lradc_variant_r329 = {
 	.has_clock_reset = true,
 };
 
+static const struct lradc_variant lradc_variant_h616 = {
+	.divisor_numerator = 3,
+	.divisor_denominator = 4,
+	.has_clock_reset = true,
+};
+
 struct sun4i_lradc_keymap {
 	u32 voltage;
 	u32 keycode;
@@ -341,6 +347,8 @@ static const struct of_device_id sun4i_lradc_of_match[] = {
 		.data = &r_lradc_variant_a83t },
 	{ .compatible = "allwinner,sun50i-r329-lradc",
 		.data = &lradc_variant_r329 },
+	{ .compatible = "allwinner,sun50i-h616-lradc",
+		.data = &lradc_variant_h616 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, sun4i_lradc_of_match);
-- 
2.35.3

