Skip to contentSkip to conversation

iio: adc: ad7124: Remove input number limitation

PATCH RESEND Superseded Mircea Caprioru 2 participants 5 messages Jun 20, 2019

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/4 iio: adc: ad7124: Remove input number limitation

The driver limits the user to use only 4/8 differential inputs, but this device has the option to use pseudo-differential channels. This will increase the number of channels to be equal with the number of inputs so 8 channels for ad7124-4 and 16 for ad7124-8.

This patch removes the check between channel nodes and num_inputs value.

---
 drivers/iio/adc/ad7124.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/iio/adc/ad7124.c +0 -7
index 659ef37d5fe8..810234db9c0d 100644
@@ -462,13 +462,6 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 		if (ret)
 			goto err;
 
-		if (ain[0] >= st->chip_info->num_inputs ||
-		    ain[1] >= st->chip_info->num_inputs) {
-			dev_err(indio_dev->dev.parent,
-				"Input pin number out of range.\n");
-			ret = -EINVAL;
-			goto err;
-		}
 		st->channel_config[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
 						  AD7124_CHANNEL_AINM(ain[1]);
 		st->channel_config[channel].bipolar =
Signature · 1 line
2.17.1
#1 lore raw

PATCH RESEND 2/4 iio: adc: ad7124: Add buffered input support

This patch adds the option to enable the buffered mode for positive and negative inputs. Each option can be enabled independently.

In buffered mode, the input channel feeds into a high impedance input stage of the buffer amplifier. Therefore, the input can tolerate significant source impedances and is tailored for direct connection to external resistive type sensors such as strain gages or RTDs.

---
 drivers/iio/adc/ad7124.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/iio/adc/ad7124.c +15 -2
index 810234db9c0d..ab52c5e9ecb1 100644
@@ -61,6 +61,8 @@
 #define AD7124_CONFIG_REF_SEL(x)	FIELD_PREP(AD7124_CONFIG_REF_SEL_MSK, x)
 #define AD7124_CONFIG_PGA_MSK		GENMASK(2, 0)
 #define AD7124_CONFIG_PGA(x)		FIELD_PREP(AD7124_CONFIG_PGA_MSK, x)
+#define AD7124_CONFIG_IN_BUFF_MSK	GENMASK(7, 6)
+#define AD7124_CONFIG_IN_BUFF(x)	FIELD_PREP(AD7124_CONFIG_IN_BUFF_MSK, x)
 
 /* AD7124_FILTER_X */
 #define AD7124_FILTER_FS_MSK		GENMASK(10, 0)
@@ -108,6 +110,8 @@ struct ad7124_chip_info {
 struct ad7124_channel_config {
 	enum ad7124_ref_sel refsel;
 	bool bipolar;
+	bool buf_positive;
+	bool buf_negative;
 	unsigned int ain;
 	unsigned int vref_mv;
 	unsigned int pga_bits;
@@ -473,6 +477,11 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 		else
 			st->channel_config[channel].refsel = tmp;
 
+		st->channel_config[channel].buf_positive =
+			of_property_read_bool(child, "adi,buffered-positive");
+		st->channel_config[channel].buf_negative =
+			of_property_read_bool(child, "adi,buffered-negative");
+
 		*chan = ad7124_channel_template;
 		chan->address = channel;
 		chan->scan_index = channel;
@@ -492,7 +501,7 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 static int ad7124_setup(struct ad7124_state *st)
 {
 	unsigned int val, fclk, power_mode;
-	int i, ret;
+	int i, ret, tmp;
 
 	fclk = clk_get_rate(st->mclk);
 	if (!fclk)
@@ -525,8 +534,12 @@ static int ad7124_setup(struct ad7124_state *st)
 		if (ret < 0)
 			return ret;
 
+		tmp = (st->channel_config[i].buf_positive << 1)  +
+			st->channel_config[i].buf_negative;
+
 		val = AD7124_CONFIG_BIPOLAR(st->channel_config[i].bipolar) |
-		      AD7124_CONFIG_REF_SEL(st->channel_config[i].refsel);
+		      AD7124_CONFIG_REF_SEL(st->channel_config[i].refsel) |
+		      AD7124_CONFIG_IN_BUFF(tmp);
 		ret = ad_sd_write_reg(&st->sd, AD7124_CONFIG(i), 2, val);
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.17.1
#2 lore raw

PATCH RESEND 3/4 iio: adc: ad7124: Shift to dynamic allocation for channel configuration

In reply to Mircea Caprioru

This patch changes the channel configuration member of the device structure from a fixed size array to a dynamic allocated one with a size equal to the number of channels specified in the device tree. This will ensure a more flexibility for compatible devices.

Ex. ad7124-4 - can have 4 differential or 8 pseudo-differential channels ad7124-8 - can have 8 differential or 16 pseudo-differential channels

Also the device can suspport any other combination of differential and pseudo-differential channels base on the physical number of inputs available.

---
 drivers/iio/adc/ad7124.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7124.c +8 -1
index ab52c5e9ecb1..edc6f1cc90b2 100644
@@ -121,7 +121,7 @@ struct ad7124_channel_config {
 struct ad7124_state {
 	const struct ad7124_chip_info *chip_info;
 	struct ad_sigma_delta sd;
-	struct ad7124_channel_config channel_config[4];
+	struct ad7124_channel_config *channel_config;
 	struct regulator *vref[4];
 	struct clk *mclk;
 	unsigned int adc_control;
@@ -439,6 +439,7 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 	struct ad7124_state *st = iio_priv(indio_dev);
 	struct device_node *child;
 	struct iio_chan_spec *chan;
+	struct ad7124_channel_config *chan_config;
 	unsigned int ain[2], channel = 0, tmp;
 	int ret;
 
@@ -453,8 +454,14 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev,
 	if (!chan)
 		return -ENOMEM;
 
+	chan_config = devm_kcalloc(indio_dev->dev.parent, st->num_channels,
+				   sizeof(*chan_config), GFP_KERNEL);
+	if (!chan_config)
+		return -ENOMEM;
+
 	indio_dev->channels = chan;
 	indio_dev->num_channels = st->num_channels;
+	st->channel_config = chan_config;
 
 	for_each_available_child_of_node(np, child) {
 		ret = of_property_read_u32(child, "reg", &channel);
Signature · 1 line
2.17.1
#3 lore raw

PATCH RESEND 4/4 dt-bindings: iio: adc: Convert ad7124 documentation to YAML

In reply to Mircea Caprioru

Convert AD7124 bindings documentation to YAML format.

---
 .../bindings/iio/adc/adi,ad7124.yaml          | 146 ++++++++++++++++++
 1 file changed, 146 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +146 -0
new file mode 100644
index 000000000000..2dba3759b8e3
@@ -0,0 +1,146 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2019 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bindings/iio/adc/adi,ad7124.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7124 ADC device driver
+
+maintainers:
+  - Stefan Popa <[email protected]>
+
+description: |
+  Bindings for the Analog Devices AD7124 ADC device. Datasheet can be
+  found here:
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-8.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7124-4
+      - adi,ad7124-8
+
+  reg:
+    description: SPI chip select number for the device
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+    description: phandle to the master clock (mclk)
+
+  clock-names:
+    items:
+      - const: mclk
+
+  interrupts:
+    description: IRQ line for the ADC
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  refin1-supply:
+    description: refin1 supply can be used as reference for conversion.
+    maxItems: 1
+
+  refin2-supply:
+    description: refin2 supply can be used as reference for conversion.
+    maxItems: 1
+
+  avdd-supply:
+    description: avdd supply can be used as reference for conversion.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+
+patternProperties:
+  "^channel@[01]$":
+    type: object
+    description: |
+      Represents the external channels which are connected to the ADC.
+      See Documentation/devicetree/bindings/iio/adc/adc.txt.
+
+    properties:
+      reg:
+        description: |
+          The channel number. It can have up to 8 channels on ad7124-4
+          and 16 channels on ad7124-8, numbered from 0 to 15.
+        maxItems: 1
+
+      adi,reference-select:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel.
+          If this field is left empty, internal reference is selected.
+        maxItems: 1
+
+      diff-channels:
+        description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+        maxItems: 1
+
+      bipolar:
+        description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+        maxItems: 1
+
+      adi,buffered-positive:
+        description: Enable buffered mode for positive input.
+        maxItems: 1
+
+      adi,buffered-negative:
+        description: Enable buffered mode for negative input.
+        maxItems: 1
+
+    required:
+      - reg
+      - diff-channels
+
+examples:
+  - |
+    adc@0 {
+      compatible = "adi,ad7124-4";
+      reg = <0>;
+      spi-max-frequency = <5000000>;
+      interrupts = <25 2>;
+      interrupt-parent = <&gpio>;
+      refin1-supply = <&adc_vref>;
+      clocks = <&ad7124_mclk>;
+      clock-names = "mclk";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      channel@0 {
+        reg = <0>;
+        diff-channels = <0 1>;
+        adi,reference-select = <0>;
+        adi,buffered-positive;
+      };
+
+      channel@1 {
+        reg = <1>;
+        bipolar;
+        diff-channels = <2 3>;
+        adi,reference-select = <0>;
+        adi,buffered-positive;
+        adi,buffered-negative;
+      };
+
+      channel@2 {
+        reg = <2>;
+        diff-channels = <4 5>;
+      };
+
+      channel@3 {
+        reg = <3>;
+        diff-channels = <6 7>;
+      };
+    };
Signature · 1 line
2.17.1
#4 lore raw

Re: [RESEND PATCH 4/4] dt-bindings: iio: adc: Convert ad7124 documentation to YAML

Quoted 15 lines · Mircea Caprioru

Convert AD7124 bindings documentation to YAML format.

---
 .../bindings/iio/adc/adi,ad7124.yaml          | 146 ++++++++++++++++++
 1 file changed, 146 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +0 -0
new file mode 100644
index 000000000000..2dba3759b8e3

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 1

Quoted 1 line
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +1 -0
@@ -0,0 +1,146 @@
+# SPDX-License-Identifier: GPL-2.0

The preference for new bindings is dual (GPL-2.0 OR BSD-2-Clause) if that is okay with you.

Quoted 55 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +55 -0
+# Copyright 2019 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bindings/iio/adc/adi,ad7124.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7124 ADC device driver
+
+maintainers:
+  - Stefan Popa <[email protected]>
+
+description: |
+  Bindings for the Analog Devices AD7124 ADC device. Datasheet can be
+  found here:
+    https://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-8.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7124-4
+      - adi,ad7124-8
+
+  reg:
+    description: SPI chip select number for the device
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+    description: phandle to the master clock (mclk)
+
+  clock-names:
+    items:
+      - const: mclk
+
+  interrupts:
+    description: IRQ line for the ADC
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  refin1-supply:
+    description: refin1 supply can be used as reference for conversion.
+    maxItems: 1
+
+  refin2-supply:
+    description: refin2 supply can be used as reference for conversion.
+    maxItems: 1
+
+  avdd-supply:
+    description: avdd supply can be used as reference for conversion.
+    maxItems: 1

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 66

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +10 -0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+
+patternProperties:
+  "^channel@[01]$":

Need to allow 2-15?

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 76

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +10 -0
+    type: object
+    description: |
+      Represents the external channels which are connected to the ADC.
+      See Documentation/devicetree/bindings/iio/adc/adc.txt.
+
+    properties:
+      reg:
+        description: |
+          The channel number. It can have up to 8 channels on ad7124-4
+          and 16 channels on ad7124-8, numbered from 0 to 15.

Sounds like constraints.

items:
- minimum: 0

    maximum: 15

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 77

Quoted 1 line
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +1 -0
+        maxItems: 1

And then you can drop this as it is implied with the number of 'items' entries.

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 84

Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +7 -0
+
+      adi,reference-select:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel.
+          If this field is left empty, internal reference is selected.
+        maxItems: 1

Type? Range of values?

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 88

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +4 -0
+
+      diff-channels:
+        description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+        maxItems: 1

Not correct as this is an array. Assuming this is covered by a common adc schema, you just need to define constraints on the values:

items:
minimum: 0
maximum: 15

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 92

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +4 -0
+
+      bipolar:
+        description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+        maxItems: 1

You can assume this is covered by common adc schema. So just 'bipolar:
true' is enough.

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 96

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +4 -0
+
+      adi,buffered-positive:
+        description: Enable buffered mode for positive input.
+        maxItems: 1

Not right as this is bool. Needs 'type: boolean'

Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml line 100

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +3 -0
+      adi,buffered-negative:
+        description: Enable buffered mode for negative input.
+        maxItems: 1

ditto

Quoted 49 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml new file +46 -1
+
+    required:
+      - reg
+      - diff-channels
+
+examples:
+  - |
+    adc@0 {
+      compatible = "adi,ad7124-4";
+      reg = <0>;
+      spi-max-frequency = <5000000>;
+      interrupts = <25 2>;
+      interrupt-parent = <&gpio>;
+      refin1-supply = <&adc_vref>;
+      clocks = <&ad7124_mclk>;
+      clock-names = "mclk";
+
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      channel@0 {
+        reg = <0>;
+        diff-channels = <0 1>;
+        adi,reference-select = <0>;
+        adi,buffered-positive;
+      };
+
+      channel@1 {
+        reg = <1>;
+        bipolar;
+        diff-channels = <2 3>;
+        adi,reference-select = <0>;
+        adi,buffered-positive;
+        adi,buffered-negative;
+      };
+
+      channel@2 {
+        reg = <2>;
+        diff-channels = <4 5>;
+      };
+
+      channel@3 {
+        reg = <3>;
+        diff-channels = <6 7>;
+      };
+    };
--

2.17.1