Skip to contentSkip to conversation

iio: adc: ad7192: Add support for AD7194

PATCH Superseded [email protected] 4 participants 14 messages Nov 5, 2023 – Nov 14, 2023

Subsystems (4)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover iio: adc: ad7192: Add support for AD7194

From: Alisa-Dariana Roman <[email protected]>

Dear maintainers,

I am submitting a series of patches to improve the ad7192 driver by adding suport for AD7194 also.

Please consider applying these patches in order.

Thank you for your time and attention.

Kind regards,

Alisa-Dariana Roman (3):
iio: adc: ad7192: Use device api
dt-bindings: iio: adc: ad7192: Add AD7194 support
iio: adc: ad7192: Add AD7194 support

 .../bindings/iio/adc/adi,ad7192.yaml          |  69 +++++++
 drivers/iio/adc/Kconfig                       |   4 +-
 drivers/iio/adc/ad7192.c                      | 176 ++++++++++++++++--
 3 files changed, 228 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 iio: adc: ad7192: Use device api

From: Alisa-Dariana Roman <[email protected]>

Replace of.h and corresponding functions with preferred device specific functions.

Also replace of_device_get_match_data function with spi_get_device_match_data.

---
 drivers/iio/adc/ad7192.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
drivers/iio/adc/ad7192.c +15 -17
index adc3cbe92d6e..48e0357564af 100644
@@ -17,7 +17,6 @@
 #include <linux/err.h>
 #include <linux/sched.h>
 #include <linux/delay.h>
-#include <linux/of.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -364,19 +363,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
 		freq <= AD7192_EXT_FREQ_MHZ_MAX);
 }
 
-static int ad7192_of_clock_select(struct ad7192_state *st)
+static int ad7192_device_clock_select(struct ad7192_state *st)
 {
-	struct device_node *np = st->sd.spi->dev.of_node;
+	struct device *dev = &st->sd.spi->dev;
 	unsigned int clock_sel;
 
 	clock_sel = AD7192_CLK_INT;
 
 	/* use internal clock */
 	if (!st->mclk) {
-		if (of_property_read_bool(np, "adi,int-clock-output-enable"))
+		if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
 			clock_sel = AD7192_CLK_INT_CO;
 	} else {
-		if (of_property_read_bool(np, "adi,clock-xtal"))
+		if (device_property_read_bool(dev, "adi,clock-xtal"))
 			clock_sel = AD7192_CLK_EXT_MCLK1_2;
 		else
 			clock_sel = AD7192_CLK_EXT_MCLK2;
@@ -385,9 +384,10 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
 	return clock_sel;
 }
 
-static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
+static int ad7192_setup(struct iio_dev *indio_dev)
 {
 	struct ad7192_state *st = iio_priv(indio_dev);
+	struct device *dev = &st->sd.spi->dev;
 	bool rej60_en, refin2_en;
 	bool buf_en, bipolar, burnout_curr_en;
 	unsigned long long scale_uv;
@@ -416,26 +416,26 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
 
 	st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
 
-	rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
+	rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");
 	if (rej60_en)
 		st->mode |= AD7192_MODE_REJ60;
 
-	refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable");
+	refin2_en = device_property_read_bool(dev, "adi,refin2-pins-enable");
 	if (refin2_en && st->chip_info->chip_id != CHIPID_AD7195)
 		st->conf |= AD7192_CONF_REFSEL;
 
 	st->conf &= ~AD7192_CONF_CHOP;
 
-	buf_en = of_property_read_bool(np, "adi,buffer-enable");
+	buf_en = device_property_read_bool(dev, "adi,buffer-enable");
 	if (buf_en)
 		st->conf |= AD7192_CONF_BUF;
 
-	bipolar = of_property_read_bool(np, "bipolar");
+	bipolar = device_property_read_bool(dev, "bipolar");
 	if (!bipolar)
 		st->conf |= AD7192_CONF_UNIPOLAR;
 
-	burnout_curr_en = of_property_read_bool(np,
-						"adi,burnout-currents-enable");
+	burnout_curr_en =
+		device_property_read_bool(dev, "adi,burnout-currents-enable");
 	if (burnout_curr_en && buf_en) {
 		st->conf |= AD7192_CONF_BURN;
 	} else if (burnout_curr_en) {
@@ -1117,9 +1117,7 @@ static int ad7192_probe(struct spi_device *spi)
 	}
 	st->int_vref_mv = ret / 1000;
 
-	st->chip_info = of_device_get_match_data(&spi->dev);
-	if (!st->chip_info)
-		st->chip_info = (void *)spi_get_device_id(spi)->driver_data;
+	st->chip_info = spi_get_device_match_data(spi);
 	indio_dev->name = st->chip_info->name;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->channels = st->chip_info->channels;
@@ -1140,7 +1138,7 @@ static int ad7192_probe(struct spi_device *spi)
 	if (IS_ERR(st->mclk))
 		return PTR_ERR(st->mclk);
 
-	st->clock_sel = ad7192_of_clock_select(st);
+	st->clock_sel = ad7192_device_clock_select(st);
 
 	if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
 	    st->clock_sel == AD7192_CLK_EXT_MCLK2) {
@@ -1152,7 +1150,7 @@ static int ad7192_probe(struct spi_device *spi)
 		}
 	}
 
-	ret = ad7192_setup(indio_dev, spi->dev.of_node);
+	ret = ad7192_setup(indio_dev);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] iio: adc: ad7192: Use device api

Quoted 62 lines · On 05/11/2023 20:31, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Replace of.h and corresponding functions with preferred device specific functions.

Also replace of_device_get_match_data function with spi_get_device_match_data.

---
 drivers/iio/adc/ad7192.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
drivers/iio/adc/ad7192.c +6 -6
index adc3cbe92d6e..48e0357564af 100644
@@ -17,7 +17,6 @@
 #include <linux/err.h>
 #include <linux/sched.h>
 #include <linux/delay.h>
-#include <linux/of.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -364,19 +363,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
 		freq <= AD7192_EXT_FREQ_MHZ_MAX);
 }
 
-static int ad7192_of_clock_select(struct ad7192_state *st)
+static int ad7192_device_clock_select(struct ad7192_state *st)
 {
-	struct device_node *np = st->sd.spi->dev.of_node;
+	struct device *dev = &st->sd.spi->dev;
 	unsigned int clock_sel;
 
 	clock_sel = AD7192_CLK_INT;
 
 	/* use internal clock */
 	if (!st->mclk) {
-		if (of_property_read_bool(np, "adi,int-clock-output-enable"))
+		if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
 			clock_sel = AD7192_CLK_INT_CO;
 	} else {
-		if (of_property_read_bool(np, "adi,clock-xtal"))
+		if (device_property_read_bool(dev, "adi,clock-xtal"))
 			clock_sel = AD7192_CLK_EXT_MCLK1_2;
 		else
 			clock_sel = AD7192_CLK_EXT_MCLK2;
@@ -385,9 +384,10 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
 	return clock_sel;
 }
 
-static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
+static int ad7192_setup(struct iio_dev *indio_dev)
 {
 	struct ad7192_state *st = iio_priv(indio_dev);
+	struct device *dev = &st->sd.spi->dev;
 	bool rej60_en, refin2_en;
 	bool buf_en, bipolar, burnout_curr_en;
 	unsigned long long scale_uv;

drivers/iio/adc/ad7192.c static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np) · line 419

Quoted 5 lines
drivers/iio/adc/ad7192.c +1 -1
@@ -416,26 +416,26 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
 
 	st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
 
-	rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
+	rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");

Not strictly related to your patch, but where are these properties documented?

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/3] iio: adc: ad7192: Use device api

Quoted 73 lines · Krzysztof Kozlowski
Quoted 62 lines · On 05/11/2023 20:31, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Replace of.h and corresponding functions with preferred device specific functions.

Also replace of_device_get_match_data function with spi_get_device_match_data.

---
  drivers/iio/adc/ad7192.c | 32 +++++++++++++++-----------------
  1 file changed, 15 insertions(+), 17 deletions(-)
drivers/iio/adc/ad7192.c +6 -6
index adc3cbe92d6e..48e0357564af 100644
@@ -17,7 +17,6 @@
  #include <linux/err.h>
  #include <linux/sched.h>
  #include <linux/delay.h>
-#include <linux/of.h>
 
  #include <linux/iio/iio.h>
  #include <linux/iio/sysfs.h>
@@ -364,19 +363,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
  		freq <= AD7192_EXT_FREQ_MHZ_MAX);
  }
 
-static int ad7192_of_clock_select(struct ad7192_state *st)
+static int ad7192_device_clock_select(struct ad7192_state *st)
  {
-	struct device_node *np = st->sd.spi->dev.of_node;
+	struct device *dev = &st->sd.spi->dev;
  	unsigned int clock_sel;
 
  	clock_sel = AD7192_CLK_INT;
 
  	/* use internal clock */
  	if (!st->mclk) {
-		if (of_property_read_bool(np, "adi,int-clock-output-enable"))
+		if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
  			clock_sel = AD7192_CLK_INT_CO;
  	} else {
-		if (of_property_read_bool(np, "adi,clock-xtal"))
+		if (device_property_read_bool(dev, "adi,clock-xtal"))
  			clock_sel = AD7192_CLK_EXT_MCLK1_2;
  		else
  			clock_sel = AD7192_CLK_EXT_MCLK2;
@@ -385,9 +384,10 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
  	return clock_sel;
  }
 
-static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
+static int ad7192_setup(struct iio_dev *indio_dev)
  {
  	struct ad7192_state *st = iio_priv(indio_dev);
+	struct device *dev = &st->sd.spi->dev;
  	bool rej60_en, refin2_en;
  	bool buf_en, bipolar, burnout_curr_en;
  	unsigned long long scale_uv;

drivers/iio/adc/ad7192.c static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np) · line 419

Quoted 5 lines
drivers/iio/adc/ad7192.c +1 -1
@@ -416,26 +416,26 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
 
  	st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
 
-	rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
+	rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");

Not strictly related to your patch, but where are these properties documented?

Quoted 3 lines

Best regards,
Krzysztof

Thank you for the feedback! The properties are documented in Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml. But the properties related to the clock configuration are indeed missing. I will add them.

Kind regards,
Alisa-Dariana Roman

Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] iio: adc: ad7192: Use device api

In reply to [email protected]
Quoted 6 lines · On Sun, Nov 05, 2023 at 09:31:29PM +0200, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Replace of.h and corresponding functions with preferred device specific functions.

Also replace of_device_get_match_data function with

of_device_get_match_data()

Quoted 1 line

spi_get_device_match_data.

spi_get_device_match_data()

With the above fixed,

The first patch should be documentation of the properties as Krzysztof noted.

P.S. Also consider using or taking an ideas from the "smart" script [1] I wrote to send patches, it will put the better list of people into the proper places, including maintainers and mailing lists.

[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

PATCH 2/3 dt-bindings: iio: adc: ad7192: Add AD7194 support

In reply to [email protected]

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

Also add an example for AD7194 devicetree.

---
 .../bindings/iio/adc/adi,ad7192.yaml          | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +69 -0
index 16def2985ab4..b9a9f7b20670 100644
@@ -21,8 +21,15 @@ properties:
       - adi,ad7190
       - adi,ad7192
       - adi,ad7193
+      - adi,ad7194
       - adi,ad7195
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
   reg:
     maxItems: 1
 
@@ -96,6 +103,31 @@ required:
   - spi-cpol
   - spi-cpha
 
+patternProperties:
+  "^channel@([0-9a-f])$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        description: The channel index.
+        minimum: 0
+        maximum: 7
+
+      diff-channels:
+        description: |
+          The differential channel pair for Ad7194 configurable channels. The
+          first channel is the positive input, the second channel is the
+          negative input.
+        items:
+          minimum: 1
+          maximum: 16
+
+    required:
+      - reg
+      - diff-channels
+
 allOf:
   - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
@@ -127,3 +159,40 @@ examples:
             adi,burnout-currents-enable;
         };
     };
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "adi,ad7194";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            spi-cpol;
+            spi-cpha;
+            clocks = <&ad7192_mclk>;
+            clock-names = "mclk";
+            interrupts = <25 0x2>;
+            interrupt-parent = <&gpio>;
+            dvdd-supply = <&dvdd>;
+            avdd-supply = <&avdd>;
+            vref-supply = <&vref>;
+
+            adi,refin2-pins-enable;
+            adi,rejection-60-Hz-enable;
+            adi,buffer-enable;
+            adi,burnout-currents-enable;
+
+            channel@0 {
+                reg = <0>;
+                diff-channels = <1 6>;
+            };
+
+            channel@1 {
+                reg = <1>;
+                diff-channels = <2 3>;
+            };
+        };
+    };
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 2/3] dt-bindings: iio: adc: ad7192: Add AD7194 support

Quoted 38 lines · On 05/11/2023 20:31, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

Also add an example for AD7194 devicetree.

---
 .../bindings/iio/adc/adi,ad7192.yaml          | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +8 -0
index 16def2985ab4..b9a9f7b20670 100644
@@ -21,8 +21,15 @@ properties:
       - adi,ad7190
       - adi,ad7192
       - adi,ad7193
+      - adi,ad7194
       - adi,ad7195
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
   reg:
     maxItems: 1
 
@@ -96,6 +103,31 @@ required:
   - spi-cpol
   - spi-cpha
 
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml required: · line 116

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+  "^channel@([0-9a-f])$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        description: The channel index.
+        minimum: 0
+        maximum: 7

Your pattern a bit above is not correct then: [0-7]

Quoted 38 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +31 -0
+
+      diff-channels:
+        description: |
+          The differential channel pair for Ad7194 configurable channels. The
+          first channel is the positive input, the second channel is the
+          negative input.
+        items:
+          minimum: 1
+          maximum: 16
+
+    required:
+      - reg
+      - diff-channels
+
 allOf:
   - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
@@ -127,3 +159,40 @@ examples:
             adi,burnout-currents-enable;
         };
     };
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "adi,ad7194";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            spi-cpol;
+            spi-cpha;
+            clocks = <&ad7192_mclk>;
+            clock-names = "mclk";
+            interrupts = <25 0x2>;
+            interrupt-parent = <&gpio>;

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml examples: · line 188

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+            dvdd-supply = <&dvdd>;
+            avdd-supply = <&avdd>;
+            vref-supply = <&vref>;
+
+            adi,refin2-pins-enable;
+            adi,rejection-60-Hz-enable;
+            adi,buffer-enable;
+            adi,burnout-currents-enable;
+
+            channel@0 {

Why cannot you add this to the existing example?

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH 2/3] dt-bindings: iio: adc: ad7192: Add AD7194 support

Quoted 105 lines · Krzysztof Kozlowski
Quoted 38 lines · On 05/11/2023 20:31, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

Also add an example for AD7194 devicetree.

---
  .../bindings/iio/adc/adi,ad7192.yaml          | 69 +++++++++++++++++++
  1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +8 -0
index 16def2985ab4..b9a9f7b20670 100644
@@ -21,8 +21,15 @@ properties:
        - adi,ad7190
        - adi,ad7192
        - adi,ad7193
+      - adi,ad7194
        - adi,ad7195
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
    reg:
      maxItems: 1
 
@@ -96,6 +103,31 @@ required:
    - spi-cpol
    - spi-cpha
 
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml required: · line 116

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+  "^channel@([0-9a-f])$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        description: The channel index.
+        minimum: 0
+        maximum: 7

Your pattern a bit above is not correct then: [0-7]

Quoted 38 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +31 -0
+
+      diff-channels:
+        description: |
+          The differential channel pair for Ad7194 configurable channels. The
+          first channel is the positive input, the second channel is the
+          negative input.
+        items:
+          minimum: 1
+          maximum: 16
+
+    required:
+      - reg
+      - diff-channels
+
  allOf:
    - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
@@ -127,3 +159,40 @@ examples:
              adi,burnout-currents-enable;
          };
      };
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "adi,ad7194";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            spi-cpol;
+            spi-cpha;
+            clocks = <&ad7192_mclk>;
+            clock-names = "mclk";
+            interrupts = <25 0x2>;
+            interrupt-parent = <&gpio>;

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml examples: · line 188

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+            dvdd-supply = <&dvdd>;
+            avdd-supply = <&avdd>;
+            vref-supply = <&vref>;
+
+            adi,refin2-pins-enable;
+            adi,rejection-60-Hz-enable;
+            adi,buffer-enable;
+            adi,burnout-currents-enable;
+
+            channel@0 {

Why cannot you add this to the existing example?

Quoted 3 lines

Best regards,
Krzysztof

I added another example to highlight the fact that only AD7194 supports configurable channels. How should I proceed?

Kind regards,
Alisa-Dariana Roman

#8 lore raw

Re: [PATCH 2/3] dt-bindings: iio: adc: ad7192: Add AD7194 support

Quoted 106 lines · Alisa-Dariana Roman
Quoted 105 lines · Krzysztof Kozlowski
Quoted 38 lines · On 05/11/2023 20:31, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

Also add an example for AD7194 devicetree.

---
  .../bindings/iio/adc/adi,ad7192.yaml          | 69 +++++++++++++++++++
  1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +8 -0
index 16def2985ab4..b9a9f7b20670 100644
@@ -21,8 +21,15 @@ properties:
        - adi,ad7190
        - adi,ad7192
        - adi,ad7193
+      - adi,ad7194
        - adi,ad7195
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
    reg:
      maxItems: 1
 
@@ -96,6 +103,31 @@ required:
    - spi-cpol
    - spi-cpha
 
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml required: · line 116

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+  "^channel@([0-9a-f])$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        description: The channel index.
+        minimum: 0
+        maximum: 7

Your pattern a bit above is not correct then: [0-7]

Quoted 38 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +31 -0
+
+      diff-channels:
+        description: |
+          The differential channel pair for Ad7194 configurable channels. The
+          first channel is the positive input, the second channel is the
+          negative input.
+        items:
+          minimum: 1
+          maximum: 16
+
+    required:
+      - reg
+      - diff-channels
+
  allOf:
    - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
@@ -127,3 +159,40 @@ examples:
              adi,burnout-currents-enable;
          };
      };
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "adi,ad7194";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            spi-cpol;
+            spi-cpha;
+            clocks = <&ad7192_mclk>;
+            clock-names = "mclk";
+            interrupts = <25 0x2>;
+            interrupt-parent = <&gpio>;

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml examples: · line 188

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+            dvdd-supply = <&dvdd>;
+            avdd-supply = <&avdd>;
+            vref-supply = <&vref>;
+
+            adi,refin2-pins-enable;
+            adi,rejection-60-Hz-enable;
+            adi,buffer-enable;
+            adi,burnout-currents-enable;
+
+            channel@0 {

Why cannot you add this to the existing example?

Quoted 5 lines
Quoted 3 lines

Best regards,
Krzysztof

I added another example to highlight the fact that only AD7194 supports configurable channels. How should I proceed?

Bindings did not tell that, so it seems you miss that part - allOf constraining channels per variant.

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH 2/3] dt-bindings: iio: adc: ad7192: Add AD7194 support

Quoted 110 lines · Krzysztof Kozlowski
Quoted 109 lines · Alisa-Dariana Roman
Quoted 108 lines · Krzysztof Kozlowski
Quoted 38 lines · On 05/11/2023 20:31, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

Also add an example for AD7194 devicetree.

---
   .../bindings/iio/adc/adi,ad7192.yaml          | 69 +++++++++++++++++++
   1 file changed, 69 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +8 -0
index 16def2985ab4..b9a9f7b20670 100644
@@ -21,8 +21,15 @@ properties:
         - adi,ad7190
         - adi,ad7192
         - adi,ad7193
+      - adi,ad7194
         - adi,ad7195
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
     reg:
       maxItems: 1
 
@@ -96,6 +103,31 @@ required:
     - spi-cpol
     - spi-cpha
 
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml required: · line 116

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+  "^channel@([0-9a-f])$":
+    type: object
+    $ref: adc.yaml
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        description: The channel index.
+        minimum: 0
+        maximum: 7

Your pattern a bit above is not correct then: [0-7]

Quoted 38 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +31 -0
+
+      diff-channels:
+        description: |
+          The differential channel pair for Ad7194 configurable channels. The
+          first channel is the positive input, the second channel is the
+          negative input.
+        items:
+          minimum: 1
+          maximum: 16
+
+    required:
+      - reg
+      - diff-channels
+
   allOf:
     - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
@@ -127,3 +159,40 @@ examples:
               adi,burnout-currents-enable;
           };
       };
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            compatible = "adi,ad7194";
+            reg = <0>;
+            spi-max-frequency = <1000000>;
+            spi-cpol;
+            spi-cpha;
+            clocks = <&ad7192_mclk>;
+            clock-names = "mclk";
+            interrupts = <25 0x2>;
+            interrupt-parent = <&gpio>;

Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml examples: · line 188

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml +10 -0
+            dvdd-supply = <&dvdd>;
+            avdd-supply = <&avdd>;
+            vref-supply = <&vref>;
+
+            adi,refin2-pins-enable;
+            adi,rejection-60-Hz-enable;
+            adi,buffer-enable;
+            adi,burnout-currents-enable;
+
+            channel@0 {

Why cannot you add this to the existing example?

Best regards,
Krzysztof

Quoted 9 lines
Quoted 2 lines

I added another example to highlight the fact that only AD7194 supports configurable channels. How should I proceed?

Bindings did not tell that, so it seems you miss that part - allOf constraining channels per variant.

Best regards,
Krzysztof

And should I remove the AD7194 example?

Kind regards,
Alisa-Dariana Roman

#10 lore raw

Re: [PATCH 2/3] dt-bindings: iio: adc: ad7192: Add AD7194 support

Quoted 7 lines · Alisa-Dariana Roman
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

Best regards,
Krzysztof

I added another example to highlight the fact that only AD7194 supports configurable channels. How should I proceed?

Quoted 7 lines
Quoted 6 lines

Bindings did not tell that, so it seems you miss that part - allOf constraining channels per variant.

Best regards,
Krzysztof

And should I remove the AD7194 example?

You can add new example in such case (and keep old).

Best regards,
Krzysztof

#11 lore raw

PATCH 3/3 iio: adc: ad7192: Add AD7194 support

In reply to [email protected]

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

The default configuration is hardcoded in order to have a stable number of channels.

---
 drivers/iio/adc/Kconfig  |   4 +-
 drivers/iio/adc/ad7192.c | 144 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 144 insertions(+), 4 deletions(-)
drivers/iio/adc/Kconfig +2 -2
index 1e2b7a2c67c6..020d37457d81 100644
@@ -55,12 +55,12 @@ config AD7124
 	  called ad7124.
 
 config AD7192
-	tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver"
+	tristate "Analog Devices AD7190 AD7192 AD7193 AD7194 AD7195 ADC driver"
 	depends on SPI
 	select AD_SIGMA_DELTA
 	help
 	  Say yes here to build support for Analog Devices AD7190,
-	  AD7192, AD7193 or AD7195 SPI analog to digital converters (ADC).
+	  AD7192, AD7193, AD7194 or AD7195 SPI analog to digital converters (ADC).
 	  If unsure, say N (but it's safe to say "Y").
 
 	  To compile this driver as a module, choose M here: the
drivers/iio/adc/ad7192.c +142 -2

218 lines not on this page · raw message

Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH 3/3] iio: adc: ad7192: Add AD7194 support

Quoted 8 lines · On Sun, Nov 05, 2023 at 09:31:31PM +0200, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

The default configuration is hardcoded in order to have a stable number of channels.

...

drivers/iio/adc/Kconfig config AD7124 · line 58

Quoted 3 lines

config AD7192

drivers/iio/adc/Kconfig +1 -1
-	tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver"
+	tristate "Analog Devices AD7190 AD7192 AD7193 AD7194 AD7195 ADC driver"

This doesn't scale. Please change this and below like:

tristate "Analog Devices AD719x ADC driver"

drivers/iio/adc/Kconfig config AD7124 · line 63

Quoted 6 lines
drivers/iio/adc/Kconfig +1 -1
 	depends on SPI
 	select AD_SIGMA_DELTA
 	help
 	  Say yes here to build support for Analog Devices AD7190,
-	  AD7192, AD7193 or AD7195 SPI analog to digital converters (ADC).
+	  AD7192, AD7193, AD7194 or AD7195 SPI analog to digital converters (ADC).

Say yes here to build support for Analog Devices SPI analog to digital converters (ADC):
- AD7190
- AD7192
- AD7193
- AD7194
- AD7195

Quoted 1 line

If unsure, say N (but it's safe to say "Y").

With above change adding a new one will be just a mater of adding a single line.

...

drivers/iio/adc/ad7192.c static void ad7192_reg_disable(void *reg) · line 1152

Quoted 12 lines
drivers/iio/adc/ad7192.c +11 -0
+static int ad7192_parse_channel(struct iio_dev *indio_dev,
+				struct fwnode_handle *child)
+{
+	u32 reg, ain[2];
+	int ret;
+
+	ret = fwnode_property_read_u32(child, "reg", &reg);
+	if (ret)
+		return ret;
 
+	if (reg < AD7194_CH_DIFF_NR_MIN || reg > AD7194_CH_DIFF_NR_MAX)
+		return -EINVAL;

in_range()

drivers/iio/adc/ad7192.c static void ad7192_reg_disable(void *reg) · line 1160

Quoted 7 lines
drivers/iio/adc/ad7192.c +7 -0
+	ret = fwnode_property_read_u32_array(child, "diff-channels", ain,
+					     ARRAY_SIZE(ain));
+	if (ret)
+		return ret;
+
+	if (ain[0] < AD7194_CH_AIN_MIN || ain[0] > AD7194_CH_AIN_MAX ||
+	    ain[1] < AD7194_CH_AIN_MIN || ain[1] > AD7194_CH_AIN_MAX)

Ditto.

Quoted 8 lines
drivers/iio/adc/ad7192.c +8 -0
+		return -EINVAL;
+
+	ad7194_channels[reg].channel = ain[0];
+	ad7194_channels[reg].channel2 = ain[1];
+	ad7194_channels[reg].address = AD7194_CH_DIFF(ain[0], ain[1]);
+
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#13 lore raw

Re: [PATCH 3/3] iio: adc: ad7192: Add AD7194 support

Quoted 12 lines · On Mon, 6 Nov 2023 12:27:29 +0200 Andy Shevchenko…
Quoted 8 lines · On Sun, Nov 05, 2023 at 09:31:31PM +0200, [email protected] wrote:

From: Alisa-Dariana Roman <[email protected]>

Unlike the other AD719Xs, AD7194 has configurable differential channels. The default configuration for these channels can be changed from the devicetree.

The default configuration is hardcoded in order to have a stable number of channels.

...

Quoted 7 lines

drivers/iio/adc/Kconfig config AD7124 · line 58

Quoted 3 lines

config AD7192

drivers/iio/adc/Kconfig +1 -1
-	tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver"
+	tristate "Analog Devices AD7190 AD7192 AD7193 AD7194 AD7195 ADC driver"  

This doesn't scale. Please change this and below like:

tristate "Analog Devices AD719x ADC driver"

Also tends to cause trouble given habit of manufacturers to not have consistent naming.

"AD7194 and similar ADC driver"
would be my preference.