Skip to contentSkip to conversation

Add GPADC for Allwinner H616

PATCH Applied Chris Morgan 3 participants 10 messages Jun 5, 2024 – Jun 22, 2024

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover Add GPADC for Allwinner H616

From: Chris Morgan <[email protected]>

Add support for the general purpose analog-to-digital converter (GPADC) for the Allwinner H616 SoC to support the ADC joysticks as found on the Anbernic RG35XX-H.

Changes since V1:
- Split dt-binding include additions to a separate patch.
- Removed patch adding compatible string as it was already upstreamed.
- Added patch to add the adc-joystick function to the RG35XX-H.

Chris Morgan (4):
dt-bindings: clock: sun50i-h616-ccu: Add GPADC clocks
clk: sunxi-ng: h616: Add clock/reset for GPADC
arm64: dts: allwinner: h616: Add GPADC device node
arm64: dts: allwinner: anbernic-rg35xx-h: Add ADC joysticks

 .../arm64/boot/dts/allwinner/sun50i-h616.dtsi | 11 +++
 .../sun50i-h700-anbernic-rg35xx-h.dts         | 79 +++++++++++++++++++
 drivers/clk/sunxi-ng/ccu-sun50i-h616.c        |  5 ++
 drivers/clk/sunxi-ng/ccu-sun50i-h616.h        |  2 +-
 include/dt-bindings/clock/sun50i-h616-ccu.h   |  1 +
 include/dt-bindings/reset/sun50i-h616-ccu.h   |  1 +
 6 files changed, 98 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/4 dt-bindings: clock: sun50i-h616-ccu: Add GPADC clocks

From: Chris Morgan <[email protected]>

Add the required clock bindings for the GPADC.

---
 include/dt-bindings/clock/sun50i-h616-ccu.h | 1 +
 include/dt-bindings/reset/sun50i-h616-ccu.h | 1 +
 2 files changed, 2 insertions(+)
include/dt-bindings/clock/sun50i-h616-ccu.h +1 -0
index 6f8f01e67628..ebb146ab7f8c 100644
@@ -112,5 +112,6 @@
 #define CLK_HDCP		126
 #define CLK_BUS_HDCP		127
 #define CLK_PLL_SYSTEM_32K	128
+#define CLK_BUS_GPADC		129
 
 #endif /* _DT_BINDINGS_CLK_SUN50I_H616_H_ */
include/dt-bindings/reset/sun50i-h616-ccu.h +1 -0
index 1bd8bb0a11be..ed177c04afdd 100644
@@ -66,5 +66,6 @@
 #define RST_BUS_TVE0		57
 #define RST_BUS_HDCP		58
 #define RST_BUS_KEYADC		59
+#define RST_BUS_GPADC		60
 
 #endif /* _DT_BINDINGS_RESET_SUN50I_H616_H_ */
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 2/4 clk: sunxi-ng: h616: Add clock/reset for GPADC

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add the GPADC required clock and reset which is used for the onboard GPADC.

---
 drivers/clk/sunxi-ng/ccu-sun50i-h616.c | 5 +++++
 drivers/clk/sunxi-ng/ccu-sun50i-h616.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/clk/sunxi-ng/ccu-sun50i-h616.c +5 -0
index 45aae1ae5178..64f476c46f5b 100644
@@ -489,6 +489,8 @@ static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x9b0,
 
 static SUNXI_CCU_GATE(bus_ts_clk, "bus-ts", "ahb3", 0x9bc, BIT(0), 0);
 
+static SUNXI_CCU_GATE(bus_gpadc_clk, "bus-gpadc", "apb1", 0x9ec, BIT(0), 0);
+
 static SUNXI_CCU_GATE(bus_ths_clk, "bus-ths", "apb1", 0x9fc, BIT(0), 0);
 
 static const char * const audio_parents[] = { "pll-audio-1x", "pll-audio-2x",
@@ -807,6 +809,7 @@ static struct ccu_common *sun50i_h616_ccu_clks[] = {
 	&bus_emac1_clk.common,
 	&ts_clk.common,
 	&bus_ts_clk.common,
+	&bus_gpadc_clk.common,
 	&bus_ths_clk.common,
 	&spdif_clk.common,
 	&bus_spdif_clk.common,
@@ -940,6 +943,7 @@ static struct clk_hw_onecell_data sun50i_h616_hw_clks = {
 		[CLK_BUS_EMAC1]		= &bus_emac1_clk.common.hw,
 		[CLK_TS]		= &ts_clk.common.hw,
 		[CLK_BUS_TS]		= &bus_ts_clk.common.hw,
+		[CLK_BUS_GPADC]		= &bus_gpadc_clk.common.hw,
 		[CLK_BUS_THS]		= &bus_ths_clk.common.hw,
 		[CLK_SPDIF]		= &spdif_clk.common.hw,
 		[CLK_BUS_SPDIF]		= &bus_spdif_clk.common.hw,
@@ -1021,6 +1025,7 @@ static struct ccu_reset_map sun50i_h616_ccu_resets[] = {
 	[RST_BUS_EMAC0]		= { 0x97c, BIT(16) },
 	[RST_BUS_EMAC1]		= { 0x97c, BIT(17) },
 	[RST_BUS_TS]		= { 0x9bc, BIT(16) },
+	[RST_BUS_GPADC]		= { 0x9ec, BIT(16) },
 	[RST_BUS_THS]		= { 0x9fc, BIT(16) },
 	[RST_BUS_SPDIF]		= { 0xa2c, BIT(16) },
 	[RST_BUS_DMIC]		= { 0xa4c, BIT(16) },
drivers/clk/sunxi-ng/ccu-sun50i-h616.h +1 -1
index fdd2f4d5103f..a75803b49f6a 100644
@@ -51,6 +51,6 @@
 
 #define CLK_BUS_DRAM		56
 
-#define CLK_NUMBER		(CLK_PLL_SYSTEM_32K + 1)
+#define CLK_NUMBER		(CLK_BUS_GPADC + 1)
 
 #endif /* _CCU_SUN50I_H616_H_ */
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 3/4 arm64: dts: allwinner: h616: Add GPADC device node

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

The H616 has a GPADC controller which is identical to the one found on the D1/T113s/R329/T507 SoCs.

---
 arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi +11 -0
index 921d5f61d8d6..30ebc0d23760 100644
@@ -589,6 +589,17 @@ spdif: spdif@5093000 {
 			status = "disabled";
 		};
 
+		gpadc: adc@5070000 {
+			compatible = "allwinner,sun50i-h616-gpadc",
+				     "allwinner,sun20i-d1-gpadc";
+			reg = <0x05070000 0x400>;
+			clocks = <&ccu CLK_BUS_GPADC>;
+			resets = <&ccu RST_BUS_GPADC>;
+			interrupts = <GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH>;
+			status = "disabled";
+			#io-channel-cells = <1>;
+		};
+
 		ths: thermal-sensor@5070400 {
 			compatible = "allwinner,sun50i-h616-ths";
 			reg = <0x05070400 0x400>;
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 4/4 arm64: dts: allwinner: anbernic-rg35xx-h: Add ADC joysticks

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the ADC joysticks found on the Anbernic RG35XX-H. The joysticks use one channel of the GPADC which is muxed 4 ways by an ADC mux.

---
 .../sun50i-h700-anbernic-rg35xx-h.dts         | 79 +++++++++++++++++++
 1 file changed, 79 insertions(+)
arch/arm64/boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-h.dts +79 -0
index 63036256917f..ff453336eab1 100644
@@ -9,6 +9,78 @@
 / {
 	model = "Anbernic RG35XX H";
 	compatible = "anbernic,rg35xx-h", "allwinner,sun50i-h700";
+
+	adc-joystick {
+		compatible = "adc-joystick";
+		io-channels = <&adc_mux 0>,
+			      <&adc_mux 1>,
+			      <&adc_mux 2>,
+			      <&adc_mux 3>;
+		pinctrl-0 = <&joy_mux_pin>;
+		pinctrl-names = "default";
+		poll-interval = <60>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		axis@0 {
+			reg = <0>;
+			abs-flat = <32>;
+			abs-fuzz = <32>;
+			abs-range = <4096 0>;
+			linux,code = <ABS_X>;
+		};
+
+		axis@1 {
+			reg = <1>;
+			abs-flat = <32>;
+			abs-fuzz = <32>;
+			abs-range = <0 4096>;
+			linux,code = <ABS_Y>;
+		};
+
+		axis@2 {
+			reg = <2>;
+			abs-flat = <32>;
+			abs-fuzz = <32>;
+			abs-range = <0 4096>;
+			linux,code = <ABS_RX>;
+		};
+
+		axis@3 {
+			reg = <3>;
+			abs-flat = <32>;
+			abs-fuzz = <32>;
+			abs-range = <4096 0>;
+			linux,code = <ABS_RY>;
+		};
+	};
+
+	adc_mux: adc-mux {
+		compatible = "io-channel-mux";
+		channels = "left_x", "left_y", "right_x", "right_y";
+		#io-channel-cells = <1>;
+		io-channels = <&gpadc 0>;
+		io-channel-names = "parent";
+		mux-controls = <&gpio_mux>;
+		settle-time-us = <100>;
+	};
+
+	gpio_mux: mux-controller {
+		compatible = "gpio-mux";
+		mux-gpios = <&pio 8 1 GPIO_ACTIVE_LOW>,
+			    <&pio 8 2 GPIO_ACTIVE_LOW>;
+		#mux-control-cells = <0>;
+	};
+};
+
+&gpadc {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	status = "okay";
+
+	channel@0 {
+		reg = <0>;
+	};
 };
 
 &gpio_keys_gamepad {
@@ -34,3 +106,10 @@ &ehci1 {
 &ohci1 {
 	status = "okay";
 };
+
+&pio {
+	joy_mux_pin: joy-mux-pin {
+		pins = "PI0";
+		function = "gpio_out";
+	};
+};
Signature · 1 line
2.34.1
#6 lore raw
In reply to Chris Morgan
Quoted 11 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the general purpose analog-to-digital converter (GPADC) for the Allwinner H616 SoC to support the ADC joysticks as found on the Anbernic RG35XX-H.

Changes since V1:
- Split dt-binding include additions to a separate patch.
- Removed patch adding compatible string as it was already upstreamed.
- Added patch to add the adc-joystick function to the RG35XX-H.

Please carry relevant Reviewed-by and other tags forward.

ChenYu

Quoted 17 lines

Chris Morgan (4):
dt-bindings: clock: sun50i-h616-ccu: Add GPADC clocks
clk: sunxi-ng: h616: Add clock/reset for GPADC
arm64: dts: allwinner: h616: Add GPADC device node
arm64: dts: allwinner: anbernic-rg35xx-h: Add ADC joysticks

 .../arm64/boot/dts/allwinner/sun50i-h616.dtsi | 11 +++
 .../sun50i-h700-anbernic-rg35xx-h.dts         | 79 +++++++++++++++++++
 drivers/clk/sunxi-ng/ccu-sun50i-h616.c        |  5 ++
 drivers/clk/sunxi-ng/ccu-sun50i-h616.h        |  2 +-
 include/dt-bindings/clock/sun50i-h616-ccu.h   |  1 +
 include/dt-bindings/reset/sun50i-h616-ccu.h   |  1 +
 6 files changed, 98 insertions(+), 1 deletion(-)

--
2.34.1

Applied
#7 lore raw

Re: (subset) [PATCH V2 0/4] Add GPADC for Allwinner H616

In reply to Chris Morgan
Quoted 10 lines · Chris Morgan

Add support for the general purpose analog-to-digital converter (GPADC) for the Allwinner H616 SoC to support the ADC joysticks as found on the Anbernic RG35XX-H.

Changes since V1:
- Split dt-binding include additions to a separate patch.
- Removed patch adding compatible string as it was already upstreamed.
- Added patch to add the adc-joystick function to the RG35XX-H.

[...]

Applied to sunxi/shared-clk-ids-for-6.11 in sunxi/linux.git, thanks!

[1/4] dt-bindings: clock: sun50i-h616-ccu: Add GPADC clocks

      https://git.kernel.org/sunxi/linux/c/532857c2a76b

Best regards,

Signature · 1 line
Chen-Yu Tsai <[email protected]>
Applied
#8 lore raw

Re: (subset) [PATCH V2 0/4] Add GPADC for Allwinner H616

In reply to Chris Morgan
Quoted 10 lines · Chris Morgan

Add support for the general purpose analog-to-digital converter (GPADC) for the Allwinner H616 SoC to support the ADC joysticks as found on the Anbernic RG35XX-H.

Changes since V1:
- Split dt-binding include additions to a separate patch.
- Removed patch adding compatible string as it was already upstreamed.
- Added patch to add the adc-joystick function to the RG35XX-H.

[...]

Applied to sunxi/clk-for-6.11 in sunxi/linux.git, thanks!

[2/4] clk: sunxi-ng: h616: Add clock/reset for GPADC

      https://git.kernel.org/sunxi/linux/c/002cf0dfa201

Best regards,

Signature · 1 line
Chen-Yu Tsai <[email protected]>
Applied
#9 lore raw

Re: (subset) [PATCH V2 0/4] Add GPADC for Allwinner H616

In reply to Chris Morgan
Quoted 10 lines · Chris Morgan

Add support for the general purpose analog-to-digital converter (GPADC) for the Allwinner H616 SoC to support the ADC joysticks as found on the Anbernic RG35XX-H.

Changes since V1:
- Split dt-binding include additions to a separate patch.
- Removed patch adding compatible string as it was already upstreamed.
- Added patch to add the adc-joystick function to the RG35XX-H.

[...]

Applied to sunxi/dt-for-6.11 in sunxi/linux.git, thanks!

[3/4] arm64: dts: allwinner: h616: Add GPADC device node

      https://git.kernel.org/sunxi/linux/c/59678cc9cc54
[4/4] arm64: dts: allwinner: anbernic-rg35xx-h: Add ADC joysticks
      https://git.kernel.org/sunxi/linux/c/e41e5973bf45

Best regards,

Signature · 1 line
Chen-Yu Tsai <[email protected]>