Skip to contentSkip to conversation

iio: adc: meson-saradc: add support for Meson S4

PATCH Superseded Nick Xie 4 participants 11 messages Mar 23 – Mar 24

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nick Xie

author
#0 lore raw

v2 cover iio: adc: meson-saradc: add support for Meson S4

This series adds support for the SARADC IP block found in the Amlogic Meson S4 (S905Y4) SoC and enables it for the Khadas VIM1S board.

Changes in v2:
- Addressed feedback from Krzysztof Kozlowski:
- Updated dt-bindings commit message to explain the hardware compatibility.
- Separated the S4 compatible string in the YAML bindings to ensure it correctly falls back to the specific "amlogic,meson-g12a-saradc" rather than the generic "amlogic,meson-saradc".
- Updated the S4 SoC dtsi to use the correct G12A fallback.
- Added Martin's Reviewed-by tags where appropriate.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Nick Xie (4):
dt-bindings: iio: adc: amlogic,meson-saradc: add S4 compatible
iio: adc: meson-saradc: add support for Meson S4
arm64: dts: amlogic: meson-s4: add internal SARADC controller
arm64: dts: amlogic: meson-s4-s905y4-khadas-vim1s: add Function key
support

 .../iio/adc/amlogic,meson-saradc.yaml         |  4 ++++
 .../amlogic/meson-s4-s905y4-khadas-vim1s.dts  | 19 +++++++++++++++++++
 arch/arm64/boot/dts/amlogic/meson-s4.dtsi     | 14 ++++++++++++++
 drivers/iio/adc/meson_saradc.c                |  8 ++++++++
 4 files changed, 45 insertions(+)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/4 dt-bindings: iio: adc: amlogic,meson-saradc: add S4 compatible

Add the compatible string for the SARADC (Successive Approximation Register ADC) IP block found in the Amlogic Meson S4 SoC.

There are no known differences between the SARADC on S4 and the one on G12A. Therefore, it uses "amlogic,meson-g12a-saradc" as a proper specific fallback.

---
 .../devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml     | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml +4 -0
index bb9825e7346dd..70ab4e140e71b 100644
@@ -27,7 +27,11 @@ properties:
               - amlogic,meson-gxm-saradc
               - amlogic,meson-axg-saradc
               - amlogic,meson-g12a-saradc
+          # Usage of this generic fallback is not allowed for new devices
           - const: amlogic,meson-saradc
+      - items:
+          - const: amlogic,meson-s4-saradc
+          - const: amlogic,meson-g12a-saradc
 
   reg:
     maxItems: 1
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/4] dt-bindings: iio: adc: amlogic,meson-saradc: add S4 compatible

Quoted 6 lines · Nick Xie

Add the compatible string for the SARADC (Successive Approximation Register ADC) IP block found in the Amlogic Meson S4 SoC.

There are no known differences between the SARADC on S4 and the one on G12A. Therefore, it uses "amlogic,meson-g12a-saradc" as a proper specific fallback.

You should explain here why you are adding that comment.

Quoted 11 lines
---
 .../devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml     | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml +0 -0
index bb9825e7346dd..70ab4e140e71b 100644

Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml properties: · line 30

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/amlogic,meson-saradc.yaml +1 -0
@@ -27,7 +27,11 @@ properties:
               - amlogic,meson-gxm-saradc
               - amlogic,meson-axg-saradc
               - amlogic,meson-g12a-saradc
+          # Usage of this generic fallback is not allowed for new devices

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 1/4] dt-bindings: iio: adc: amlogic,meson-saradc: add S4 compatible

Quoted 10 lines · Krzysztof Kozlowski
Quoted 6 lines · Nick Xie

Add the compatible string for the SARADC (Successive Approximation Register ADC) IP block found in the Amlogic Meson S4 SoC.

There are no known differences between the SARADC on S4 and the one on G12A. Therefore, it uses "amlogic,meson-g12a-saradc" as a proper specific fallback.

You should explain here why you are adding that comment.

What do you think about:
Also add a comment indicating that "amlogic,meson-saradc" must not be used for new devices. It's a made up compatible string that does not correspond to a specific hardware generation and is not used to match any driver. For old devices we keep it as it's part of the ABI.

author
#4 lore raw

PATCH v2 2/4 iio: adc: meson-saradc: add support for Meson S4

In reply to Nick Xie

Add support for the SARADC found on the Amlogic Meson S4 SoC. According to the documentation and current testing, it is fully compatible with the G12A parameter set, so we reuse meson_sar_adc_g12a_data for this new compatible string.

---
 drivers/iio/adc/meson_saradc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/meson_saradc.c +8 -0
index 47cd350498a0d..3ac48b7842c4f 100644
@@ -1313,6 +1313,11 @@ static const struct meson_sar_adc_data meson_sar_adc_g12a_data = {
 	.name = "meson-g12a-saradc",
 };
 
+static const struct meson_sar_adc_data meson_sar_adc_s4_data = {
+	.param = &meson_sar_adc_g12a_param,
+	.name = "meson-s4-saradc",
+};
+
 static const struct of_device_id meson_sar_adc_of_match[] = {
 	{
 		.compatible = "amlogic,meson8-saradc",
@@ -1341,6 +1346,9 @@ static const struct of_device_id meson_sar_adc_of_match[] = {
 	}, {
 		.compatible = "amlogic,meson-g12a-saradc",
 		.data = &meson_sar_adc_g12a_data,
+	}, {
+		.compatible = "amlogic,meson-s4-saradc",
+		.data = &meson_sar_adc_s4_data,
 	},
 	{ }
 };
Signature · 1 line
2.34.1
#5 lore raw
Quoted 28 lines · Nick Xie

Add support for the SARADC found on the Amlogic Meson S4 SoC. According to the documentation and current testing, it is fully compatible with the G12A parameter set, so we reuse meson_sar_adc_g12a_data for this new compatible string.

---
 drivers/iio/adc/meson_saradc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/meson_saradc.c +5 -0
index 47cd350498a0d..3ac48b7842c4f 100644
@@ -1313,6 +1313,11 @@ static const struct meson_sar_adc_data meson_sar_adc_g12a_data = {
 	.name = "meson-g12a-saradc",
 };
 
+static const struct meson_sar_adc_data meson_sar_adc_s4_data = {
+	.param = &meson_sar_adc_g12a_param,
+	.name = "meson-s4-saradc",
+};
+
 static const struct of_device_id meson_sar_adc_of_match[] = {
 	{
 		.compatible = "amlogic,meson8-saradc",

drivers/iio/adc/meson_saradc.c static const struct of_device_id meson_sar_adc_of_match[] = { · line 1350

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +2 -0
@@ -1341,6 +1346,9 @@ static const struct of_device_id meson_sar_adc_of_match[] = {
 	}, {
 		.compatible = "amlogic,meson-g12a-saradc",
 		.data = &meson_sar_adc_g12a_data,
+	}, {
+		.compatible = "amlogic,meson-s4-saradc",

The point of compatible devices is to not add such entries. Drop.

Best regards,
Krzysztof

maintainer
#6 lore raw
Quoted 20 lines · On Mon, 23 Mar 2026 08:54:21 +0100 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 19 lines · Nick Xie

Add support for the SARADC found on the Amlogic Meson S4 SoC. According to the documentation and current testing, it is fully compatible with the G12A parameter set, so we reuse meson_sar_adc_g12a_data for this new compatible string.

---
 drivers/iio/adc/meson_saradc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/meson_saradc.c +0 -0
index 47cd350498a0d..3ac48b7842c4f 100644
@@ -1313,6 +1313,11 @@ static const struct meson_sar_adc_data meson_sar_adc_g12a_data = {
 	.name = "meson-g12a-saradc",
 };
 
Quoted 16 lines
Quoted 9 lines
drivers/iio/adc/meson_saradc.c +5 -0
+static const struct meson_sar_adc_data meson_sar_adc_s4_data = {
+	.param = &meson_sar_adc_g12a_param,
+	.name = "meson-s4-saradc",
+};
+
 static const struct of_device_id meson_sar_adc_of_match[] = {
 	{
 		.compatible = "amlogic,meson8-saradc",

drivers/iio/adc/meson_saradc.c static const struct of_device_id meson_sar_adc_of_match[] = { · line 1350

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +2 -0
@@ -1341,6 +1346,9 @@ static const struct of_device_id meson_sar_adc_of_match[] = {
 	}, {
 		.compatible = "amlogic,meson-g12a-saradc",
 		.data = &meson_sar_adc_g12a_data,
+	}, {
+		.compatible = "amlogic,meson-s4-saradc",  

The point of compatible devices is to not add such entries. Drop.

It's used for naming in the userspace ABI which is supposed to reflect the part number. I don't hugely mind the names reported showing the compatible part.

Jonathan

Quoted 4 lines

Best regards,
Krzysztof

#7 lore raw
Quoted 39 lines · Jonathan Cameron
Quoted 20 lines · On Mon, 23 Mar 2026 08:54:21 +0100 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 19 lines · Nick Xie

Add support for the SARADC found on the Amlogic Meson S4 SoC. According to the documentation and current testing, it is fully compatible with the G12A parameter set, so we reuse meson_sar_adc_g12a_data for this new compatible string.

---
 drivers/iio/adc/meson_saradc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/meson_saradc.c +0 -0
index 47cd350498a0d..3ac48b7842c4f 100644
@@ -1313,6 +1313,11 @@ static const struct meson_sar_adc_data meson_sar_adc_g12a_data = {
 	.name = "meson-g12a-saradc",
 };
 
Quoted 16 lines
Quoted 9 lines
drivers/iio/adc/meson_saradc.c +5 -0
+static const struct meson_sar_adc_data meson_sar_adc_s4_data = {
+	.param = &meson_sar_adc_g12a_param,
+	.name = "meson-s4-saradc",
+};
+
 static const struct of_device_id meson_sar_adc_of_match[] = {
 	{
 		.compatible = "amlogic,meson8-saradc",

drivers/iio/adc/meson_saradc.c static const struct of_device_id meson_sar_adc_of_match[] = { · line 1350

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +2 -0
@@ -1341,6 +1346,9 @@ static const struct of_device_id meson_sar_adc_of_match[] = {
 	}, {
 		.compatible = "amlogic,meson-g12a-saradc",
 		.data = &meson_sar_adc_g12a_data,
+	}, {
+		.compatible = "amlogic,meson-s4-saradc",  

The point of compatible devices is to not add such entries. Drop.

Quoted 1 line

It's used for naming in the userspace ABI which is supposed to reflect the part number.

Indeed, I saw this pattern in more places. Does userspace need it? There is no "compatible" entry shown?

If there is no, then probably this could be automated by taking the name from compatible after ',', but that would be out of scope for this set, so here it is fine.

Best regards,
Krzysztof

maintainer
#8 lore raw
Quoted 40 lines · On Tue, 24 Mar 2026 08:07:15 +0100 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 39 lines · Jonathan Cameron
Quoted 36 lines · On Mon, 23 Mar 2026 08:54:21 +0100 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 28 lines · Nick Xie

Add support for the SARADC found on the Amlogic Meson S4 SoC. According to the documentation and current testing, it is fully compatible with the G12A parameter set, so we reuse meson_sar_adc_g12a_data for this new compatible string.

---
 drivers/iio/adc/meson_saradc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/meson_saradc.c +5 -0
index 47cd350498a0d..3ac48b7842c4f 100644
@@ -1313,6 +1313,11 @@ static const struct meson_sar_adc_data meson_sar_adc_g12a_data = {
 	.name = "meson-g12a-saradc",
 };
 
+static const struct meson_sar_adc_data meson_sar_adc_s4_data = {
+	.param = &meson_sar_adc_g12a_param,
+	.name = "meson-s4-saradc",
+};
+
 static const struct of_device_id meson_sar_adc_of_match[] = {
 	{
 		.compatible = "amlogic,meson8-saradc",

drivers/iio/adc/meson_saradc.c static const struct of_device_id meson_sar_adc_of_match[] = { · line 1350

Quoted 5 lines
drivers/iio/adc/meson_saradc.c +2 -0
@@ -1341,6 +1346,9 @@ static const struct of_device_id meson_sar_adc_of_match[] = {
 	}, {
 		.compatible = "amlogic,meson-g12a-saradc",
 		.data = &meson_sar_adc_g12a_data,
+	}, {
+		.compatible = "amlogic,meson-s4-saradc",    

The point of compatible devices is to not add such entries. Drop.

Quoted 4 lines
Quoted 1 line

It's used for naming in the userspace ABI which is supposed to reflect the part number.

Indeed, I saw this pattern in more places. Does userspace need it? There is no "compatible" entry shown?

Yes. Userspace uses this (+ a label) to identify which of multiple devices it is talking to. Given some of these parts are very specific rather than covering a general purpose, people tend to be looking at datasheets if there are multiple parts and they want to know which is which. Knowing whether it's compatible with something else doesn't help with that identification part.

Quoted 4 lines

If there is no, then probably this could be automated by taking the name from compatible after ',', but that would be out of scope for this set, so here it is fine.

For DT that works but not for other firmware types. We had a bunch of bugs where people ended up putting out ACPI IDs (some of which we've had to leave in place to avoid regressions). Hence I've always been nervous about not encoding the string explicitly in the driver. Obviously this is a bit paranoid for DT where it's reasonably tightly defined.

Jonathan

Quoted 4 lines

Best regards,
Krzysztof

author
#9 lore raw

PATCH v2 3/4 arm64: dts: amlogic: meson-s4: add internal SARADC controller

In reply to Nick Xie

Add the SARADC (Successive Approximation Register ADC) controller node to the Meson S4 SoC dtsi.

It uses the S4-specific compatible string with a fallback to the G12A generation, as there are no known hardware differences.

---
 arch/arm64/boot/dts/amlogic/meson-s4.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm64/boot/dts/amlogic/meson-s4.dtsi +14 -0
index 4a3e9ad82d280..936a5c1353d15 100644
@@ -77,6 +77,20 @@ pwrc: power-controller {
 		};
 	};
 
+	saradc: adc@fe026000 {
+		compatible = "amlogic,meson-s4-saradc",
+			     "amlogic,meson-g12a-saradc";
+		reg = <0x0 0xfe026000 0x0 0x48>;
+		#io-channel-cells = <1>;
+		interrupts = <GIC_SPI 181 IRQ_TYPE_EDGE_RISING>;
+		clocks = <&xtal>,
+			 <&clkc_periphs CLKID_SAR_ADC>,
+			 <&clkc_periphs CLKID_SARADC>,
+			 <&clkc_periphs CLKID_SARADC_SEL>;
+		clock-names = "clkin", "core", "adc_clk", "adc_sel";
+		status = "disabled";
+	};
+
 	soc {
 		compatible = "simple-bus";
 		#address-cells = <2>;
Signature · 1 line
2.34.1
author
#10 lore raw

PATCH v2 4/4 arm64: dts: amlogic: meson-s4-s905y4-khadas-vim1s: add Function key support

In reply to Nick Xie

Enable the SARADC controller and add the adc-keys node to support the Function key found on the Khadas VIM1S board.

---
 .../amlogic/meson-s4-s905y4-khadas-vim1s.dts  | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm64/boot/dts/amlogic/meson-s4-s905y4-khadas-vim1s.dts +19 -0
index 664d64a267f2d..792ab45c4c944 100644
@@ -40,6 +40,20 @@ secmon_reserved: secmon@5000000 {
 		};
 	};
 
+	adc-keys {
+		compatible = "adc-keys";
+		io-channels = <&saradc 0>;
+		io-channel-names = "buttons";
+		keyup-threshold-microvolt = <1710000>;
+		poll-interval = <100>;
+
+		button-function {
+			label = "Function";
+			linux,code = <KEY_FN>;
+			press-threshold-microvolt = <10000>;
+		};
+	};
+
 	emmc_pwrseq: emmc-pwrseq {
 		compatible = "mmc-pwrseq-emmc";
 		reset-gpios = <&gpio GPIOB_9 GPIO_ACTIVE_LOW>;
@@ -278,6 +292,11 @@ brcmf: wifi@1 {
 	};
 };
 
+&saradc {
+	status = "okay";
+	vref-supply = <&vddio_ao1v8>;
+};
+
 &spicc0 {
 	status = "okay";
 	pinctrl-names = "default";
Signature · 1 line
2.34.1