Skip to contentSkip to conversation

Add support for Allwinner GPADC on D1/T113s/R329/T507 SoCs

PATCH Superseded Maksim Kiselev 4 participants 10 messages Jun 10, 2023

Subsystems (4)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support for Allwinner GPADC on D1/T113s/R329/T507 SoCs

This series adds support for general purpose ADC (GPADC) on new Allwinner's SoCs, such as D1, T113s, T507 and R329. The implemented driver provides basic functionality for getting ADC channels data.

Change History:
v4:
- Fixed DT bindings warnings
- Used GENMASK to clear the irq register
- Minor formatting fixes

v3:
- Added DT bindings dual license, fixed property order and example formatting
- Added explanations comments for timeout and mutex
- Dropped unnecessary regmap and used readl/writel instead
- Added error message about getting channel number
- Renamed labels and variables to make them self-explanatory

v2:
- Added lastch flag to avoid addition work for already selected channel
- Added reset assertion on module remove
- Added dynamic channel allocation and dropped iio_chan_spec arrays
- Changed IIO_CHAN_INFO_SCALE type to FRACTIONAL_LOG2
- Dropped separate compatible strings and configs for T113s and R329
- Fixed includes
- Fixed Kconfig description
- Removed duplicate probe error messages
- Used FIELD_PREP for bit setup

v1:
- Initial version
Maxim Kiselev (3):
iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC
dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC
riscv: dts: allwinner: d1: Add GPADC node

 .../iio/adc/allwinner,sun20i-d1-gpadc.yaml    |  91 ++++++
 .../boot/dts/allwinner/sunxi-d1s-t113.dtsi    |  10 +
 drivers/iio/adc/Kconfig                       |  10 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/sun20i-gpadc-iio.c            | 281 ++++++++++++++++++
 5 files changed, 393 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml
 create mode 100644 drivers/iio/adc/sun20i-gpadc-iio.c
Signature · 1 line
2.39.2
#1 lore raw

PATCH v4 1/3 iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

From: Maxim Kiselev <[email protected]>

The General Purpose ADC (GPADC) can convert the external signal into a certain proportion of digital value, to realize the measurement of analog signal, which can be applied to power detection and key detection.

Theoretically, this ADC can support up to 16 channels. All SoCs below contain this GPADC IP. The only difference between them is the number of available channels:

T113 - 1 channel
D1 - 2 channels
R329 - 4 channels
T507 - 4 channels

---
 drivers/iio/adc/Kconfig            |  10 +
 drivers/iio/adc/Makefile           |   1 +
 drivers/iio/adc/sun20i-gpadc-iio.c | 281 +++++++++++++++++++++++++++++
 3 files changed, 292 insertions(+)
 create mode 100644 drivers/iio/adc/sun20i-gpadc-iio.c
drivers/iio/adc/Kconfig +10 -0
index eb2b09ef5d5b..deff7ae704ce 100644
@@ -1123,6 +1123,16 @@ config SUN4I_GPADC
 	  To compile this driver as a module, choose M here: the module will be
 	  called sun4i-gpadc-iio.
 
+config SUN20I_GPADC
+	tristate "Support for the Allwinner SoCs GPADC"
+	depends on ARCH_SUNXI || COMPILE_TEST
+	help
+	  Say yes here to build support for Allwinner (D1, T113, T507 and R329)
+	  SoCs GPADC. This ADC provides up to 16 channels.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called sun20i-gpadc-iio.
+
 config TI_ADC081C
 	tristate "Texas Instruments ADC081C/ADC101C/ADC121C family"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index e07e4a3e6237..fc4ef71d5f8f 100644
@@ -95,6 +95,7 @@ obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o
 obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o
 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
 obj-$(CONFIG_SUN4I_GPADC) += sun4i-gpadc-iio.o
+obj-$(CONFIG_SUN20I_GPADC) += sun20i-gpadc-iio.o
 obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o
 obj-$(CONFIG_STM32_ADC) += stm32-adc.o
 obj-$(CONFIG_STM32_DFSDM_CORE) += stm32-dfsdm-core.o
drivers/iio/adc/sun20i-gpadc-iio.c new file +281 -0

281 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH v4 1/3] iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

Quoted 10 lines · On Sat, 10 Jun 2023 15:29:07 +0300 Maksim Kiselev <[email protected]> wrote:

From: Maxim Kiselev <[email protected]>

The General Purpose ADC (GPADC) can convert the external signal into a certain proportion of digital value, to realize the measurement of analog signal, which can be applied to power detection and key detection.

Theoretically, this ADC can support up to 16 channels. All SoCs below contain this GPADC IP. The only difference between them is the number of available channels:

Quoted 7 lines

T113 - 1 channel
D1 - 2 channels
R329 - 4 channels
T507 - 4 channels

Looks good to me. Just the issue Connor pointed out in the DT binding to resolve. Note that this will be cutting it fine for this cycle, but 'might' make it in if the stars align. If not it will need to wait for next cycle.

Jonathan

maintainer
#3 lore raw

Re: [PATCH v4 1/3] iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

Dne sobota, 10. junij 2023 ob 20:12:04 CEST je Jonathan Cameron napisal(a):

Quoted 18 lines
Quoted 15 lines · On Sat, 10 Jun 2023 15:29:07 +0300 Maksim Kiselev <[email protected]> wrote:

From: Maxim Kiselev <[email protected]>

The General Purpose ADC (GPADC) can convert the external signal into a certain proportion of digital value, to realize the measurement of analog signal, which can be applied to power detection and key detection.

Theoretically, this ADC can support up to 16 channels. All SoCs below contain this GPADC IP. The only difference between them is the number of available channels:

T113 - 1 channel
D1 - 2 channels
R329 - 4 channels
T507 - 4 channels

Quoted 6 lines
Quoted 2 lines

Looks good to me. Just the issue Connor pointed out in the DT binding to resolve. Note that this will be cutting it fine for this cycle, but 'might' make it in if the stars align. If not it will need to wait for next cycle.

Cutoff for sunxi DT changes is at -rc6, so I would say at least that part will land in 6.6 for sure.

Best regards,
Jernej

#4 lore raw

PATCH v4 2/3 dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

In reply to Maksim Kiselev

From: Maxim Kiselev <[email protected]>

Allwinner's D1/T113s/R329/T507 SoCs have a new general purpose ADC. This ADC is the same for all of this SoCs. The only difference is the number of available channels.

---
 .../iio/adc/allwinner,sun20i-d1-gpadc.yaml    | 91 +++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +91 -0
new file mode 100644
index 000000000000..2b59844b7c07
@@ -0,0 +1,91 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/allwinner,sun20i-d1-gpadc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Allwinner D1 General Purpose ADC
+
+maintainers:
+  - Maksim Kiselev <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - allwinner,sun20i-d1-gpadc
+
+  "#io-channel-cells":
+    const: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  clocks:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reg:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+patternProperties:
+  "^channel@([0-15])$":
+    $ref: adc.yaml
+    type: object
+    description:
+      Represents the internal channels of the ADC.
+
+    properties:
+      reg:
+        items:
+          minimum: 0
+          maximum: 15
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - "#io-channel-cells"
+  - clocks
+  - compatible
+  - interrupts
+  - reg
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sun20i-d1-ccu.h>
+    #include <dt-bindings/reset/sun20i-d1-ccu.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    gpadc: adc@2009000 {
+        compatible = "allwinner,sun20i-d1-gpadc";
+        reg = <0x2009000 0x1000>;
+        clocks = <&ccu CLK_BUS_GPADC>;
+        resets = <&ccu RST_BUS_GPADC>;
+        interrupts = <73 IRQ_TYPE_LEVEL_HIGH>;
+        #io-channel-cells = <1>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+            reg = <0>;
+        };
+
+        channel@1 {
+            reg = <1>;
+        };
+    };
+...
Signature · 1 line
2.39.2
#5 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

Hey,

Quoted 72 lines · Maksim Kiselev

From: Maxim Kiselev <[email protected]>

Allwinner's D1/T113s/R329/T507 SoCs have a new general purpose ADC. This ADC is the same for all of this SoCs. The only difference is the number of available channels.

---
 .../iio/adc/allwinner,sun20i-d1-gpadc.yaml    | 91 +++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +54 -0
new file mode 100644
index 000000000000..2b59844b7c07
@@ -0,0 +1,91 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/allwinner,sun20i-d1-gpadc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Allwinner D1 General Purpose ADC
+
+maintainers:
+  - Maksim Kiselev <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - allwinner,sun20i-d1-gpadc
+
+  "#io-channel-cells":
+    const: 1
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  clocks:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reg:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+patternProperties:
+  "^channel@([0-15])$":
+    $ref: adc.yaml
+    type: object
+    description:
+      Represents the internal channels of the ADC.
+
+    properties:
+      reg:
+        items:
+          minimum: 0
+          maximum: 15
+
+    required:
+      - reg
+
+    additionalProperties: false

Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +10 -0
+
+required:
+  - "#io-channel-cells"
+  - clocks
+  - compatible
+  - interrupts
+  - reg
+  - resets
+
+unevaluatedProperties: false

How come this one changed to unevaluatedProperties: false? Wasn't it for the ADC that we previously discussed whether
additionalProperties: false was correct or not?

Cheers,
Conor.

Quoted 30 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +27 -0
+
+examples:
+  - |
+    #include <dt-bindings/clock/sun20i-d1-ccu.h>
+    #include <dt-bindings/reset/sun20i-d1-ccu.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    gpadc: adc@2009000 {
+        compatible = "allwinner,sun20i-d1-gpadc";
+        reg = <0x2009000 0x1000>;
+        clocks = <&ccu CLK_BUS_GPADC>;
+        resets = <&ccu RST_BUS_GPADC>;
+        interrupts = <73 IRQ_TYPE_LEVEL_HIGH>;
+        #io-channel-cells = <1>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+            reg = <0>;
+        };
+
+        channel@1 {
+            reg = <1>;
+        };
+    };
+...
Signature · 1 line
2.39.2
#6 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

Hey,

сб, 10 июн. 2023 г. в 18:06, Conor Dooley <[email protected]>:

...

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +11 -0
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - "#io-channel-cells"
+  - clocks
+  - compatible
+  - interrupts
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml line 64

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +4 -0
+  - reg
+  - resets
+
+unevaluatedProperties: false

How come this one changed to unevaluatedProperties: false? Wasn't it for the ADC that we previously discussed whether
additionalProperties: false was correct or not?

Hmm, I changed it to unevaluatedProperties: false as you suggested in this message
https://lore.kernel.org/lkml/20230604-afternoon-frighten-42222010557b@spud/

#7 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

Quoted 11 lines · Maxim Kiselev

Hey,

сб, 10 июн. 2023 г. в 18:06, Conor Dooley <[email protected]>:

...

Quoted 5 lines

Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml line 54

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +5 -0
+
+    required:
+      - reg
+
+    additionalProperties: false

[1]

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +6 -0
+
+required:
+  - "#io-channel-cells"
+  - clocks
+  - compatible
+  - interrupts
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml line 64

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +4 -0
+  - reg
+  - resets
+
+unevaluatedProperties: false

How come this one changed to unevaluatedProperties: false? Wasn't it for the ADC that we previously discussed whether
additionalProperties: false was correct or not?

Quoted 3 lines

Hmm, I changed it to unevaluatedProperties: false as you suggested in this message
https://lore.kernel.org/lkml/20230604-afternoon-frighten-42222010557b@spud/

That was about the adc child nodes [1], not at the top level, no?

Cheers,
Conor.

#8 lore raw

Re: [PATCH v4 2/3] dt-bindings: iio: adc: Add Allwinner D1/T113s/R329/T507 SoCs GPADC

сб, 10 июн. 2023 г. в 18:53, Conor Dooley <[email protected]>:

Quoted 31 lines · Maxim Kiselev
Quoted 11 lines

Hey,

сб, 10 июн. 2023 г. в 18:06, Conor Dooley <[email protected]>:

...

Quoted 5 lines

Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml line 54

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +5 -0
+
+    required:
+      - reg
+
+    additionalProperties: false

[1]

Quoted 15 lines
Quoted 14 lines

Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/allwinner,sun20i-d1-gpadc.yaml new file +10 -0
+
+required:
+  - "#io-channel-cells"
+  - clocks
+  - compatible
+  - interrupts
+  - reg
+  - resets
+
+unevaluatedProperties: false

How come this one changed to unevaluatedProperties: false? Wasn't it for the ADC that we previously discussed whether
additionalProperties: false was correct or not?

Quoted 5 lines
Quoted 3 lines

Hmm, I changed it to unevaluatedProperties: false as you suggested in this message
https://lore.kernel.org/lkml/20230604-afternoon-frighten-42222010557b@spud/

That was about the adc child nodes [1], not at the top level, no?

Indeed, I confused it, sorry.

#9 lore raw

PATCH v4 3/3 riscv: dts: allwinner: d1: Add GPADC node

In reply to Maksim Kiselev

From: Maxim Kiselev <[email protected]>

This patch adds declaration of the general purpose ADC for D1 and T113s SoCs.

---
 arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/riscv/boot/dts/allwinner/sunxi-d1s-t113.dtsi +10 -0
index 922e8e0e2c09..90c79041cfba 100644
@@ -138,6 +138,16 @@ ccu: clock-controller@2001000 {
 			#reset-cells = <1>;
 		};
 
+		gpadc: adc@2009000 {
+			compatible = "allwinner,sun20i-d1-gpadc";
+			reg = <0x2009000 0x1000>;
+			clocks = <&ccu CLK_BUS_GPADC>;
+			resets = <&ccu RST_BUS_GPADC>;
+			interrupts = <SOC_PERIPHERAL_IRQ(57) IRQ_TYPE_LEVEL_HIGH>;
+			status = "disabled";
+			#io-channel-cells = <1>;
+		};
+
 		dmic: dmic@2031000 {
 			compatible = "allwinner,sun20i-d1-dmic",
 				     "allwinner,sun50i-h6-dmic";
Signature · 1 line
2.39.2