Skip to contentSkip to conversation

iio: adc: ad7291: convert to device tree

PATCH In review Michael Auchter 2 participants 3 messages Sep 22, 2020 – Sep 23, 2020

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

PATCH v3 1/2 iio: adc: ad7291: convert to device tree

There are no in-tree users of the platform data for this driver, so remove it and convert the driver to use device tree instead.

---
Changes since v1:
- Fix regulator handling as suggested by Lars v2:
- use positive conditional for regulator error path
- drop of_match_ptr
- drop trailing comma

 drivers/iio/adc/ad7291.c             | 35 +++++++++++++++++-----------
 include/linux/platform_data/ad7291.h | 13 -----------
 2 files changed, 21 insertions(+), 27 deletions(-)
 delete mode 100644 include/linux/platform_data/ad7291.h
drivers/iio/adc/ad7291.c +21 -14
index 62fde2aad282..2301a0e27f23 100644
@@ -20,8 +20,6 @@
 #include <linux/iio/sysfs.h>
 #include <linux/iio/events.h>
 
-#include <linux/platform_data/ad7291.h>
-
 /*
  * Simplified handling
  *
@@ -465,7 +463,6 @@ static const struct iio_info ad7291_info = {
 static int ad7291_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
-	struct ad7291_platform_data *pdata = client->dev.platform_data;
 	struct ad7291_chip_info *chip;
 	struct iio_dev *indio_dev;
 	int ret;
@@ -475,16 +472,6 @@ static int ad7291_probe(struct i2c_client *client,
 		return -ENOMEM;
 	chip = iio_priv(indio_dev);
 
-	if (pdata && pdata->use_external_ref) {
-		chip->reg = devm_regulator_get(&client->dev, "vref");
-		if (IS_ERR(chip->reg))
-			return PTR_ERR(chip->reg);
-
-		ret = regulator_enable(chip->reg);
-		if (ret)
-			return ret;
-	}
-
 	mutex_init(&chip->state_lock);
 	/* this is only used for device removal purposes */
 	i2c_set_clientdata(client, indio_dev);
@@ -495,8 +482,21 @@ static int ad7291_probe(struct i2c_client *client,
 			AD7291_T_SENSE_MASK | /* Tsense always enabled */
 			AD7291_ALERT_POLARITY; /* set irq polarity low level */
 
-	if (pdata && pdata->use_external_ref)
+	chip->reg = devm_regulator_get_optional(&client->dev, "vref");
+	if (IS_ERR(chip->reg)) {
+		if (PTR_ERR(chip->reg) != -ENODEV)
+			return PTR_ERR(chip->reg);
+
+		chip->reg = NULL;
+	}
+
+	if (chip->reg) {
+		ret = regulator_enable(chip->reg);
+		if (ret)
+			return ret;
+
 		chip->command |= AD7291_EXT_REF;
+	}
 
 	indio_dev->name = id->name;
 	indio_dev->channels = ad7291_channels;
@@ -567,9 +567,16 @@ static const struct i2c_device_id ad7291_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ad7291_id);
 
+static const struct of_device_id ad7291_of_match[] = {
+	{ .compatible = "adi,ad7291" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, ad7291_of_match);
+
 static struct i2c_driver ad7291_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,
+		.of_match_table = ad7291_of_match,
 	},
 	.probe = ad7291_probe,
 	.remove = ad7291_remove,
include/linux/platform_data/ad7291.h deleted +0 -13
deleted file mode 100644
index b1fd1530c9a5..000000000000
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __IIO_AD7291_H__
-#define __IIO_AD7291_H__
-
-/**
- * struct ad7291_platform_data - AD7291 platform data
- * @use_external_ref: Whether to use an external or internal reference voltage
- */
-struct ad7291_platform_data {
-	bool use_external_ref;
-};
-
-#endif
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 2/2 dt-bindings: iio: adc: ad7291: add binding

Add device-tree binding for ADI AD7291 ADC.

---
 .../bindings/iio/adc/adi,ad7291.yaml          | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml new file +50 -0
new file mode 100644
index 000000000000..93aa29413049
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7291.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AD7291 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor
+
+maintainers:
+  - Michael Auchter <[email protected]>
+
+description: |
+  Analog Devices AD7291 8-Channel I2C 12-Bit SAR ADC with Temperature Sensor
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad7291.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7291
+
+  reg:
+    maxItems: 1
+
+  vref-supply:
+    description: |
+      The regulator supply for ADC reference voltage.
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      ad7291: adc@0 {
+        compatible = "adi,ad7291";
+        reg = <0>;
+        vref-supply = <&adc_vref>;
+      };
+    };
+
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v3 2/2] dt-bindings: iio: adc: ad7291: add binding

Quoted 4 lines · On Tue, 22 Sep 2020 09:44:21 -0500 Michael Auchter <[email protected]>…

Add device-tree binding for ADI AD7291 ADC.

Hi Michael,

I tweaked this a bit whilst applying as below.

Hope that's fine with you. Let me know if not.

Applied series to the togreg branch of iio.git and pushed out as testing. I'm not sure if this will make 5.10 or not as we are rather tight for a final IIO pull request.

Thanks,

Jonathan

Quoted 33 lines
---
 .../bindings/iio/adc/adi,ad7291.yaml          | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml new file +22 -0
new file mode 100644
index 000000000000..93aa29413049
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7291.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: AD7291 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor
+
+maintainers:
+  - Michael Auchter <[email protected]>
+
+description: |
+  Analog Devices AD7291 8-Channel I2C 12-Bit SAR ADC with Temperature Sensor
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad7291.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7291
+
+  reg:
+    maxItems: 1

Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml line 32

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml new file +10 -0
+
+  vref-supply:
+    description: |
+      The regulator supply for ADC reference voltage.
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0

These two don't need to be here.

Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml line 36

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml new file +4 -0
+
+required:
+  - compatible
+  - reg

additionalProperties: false

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml new file +4 -0
+
+examples:
+  - |
+    i2c {

Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml line 50

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7291.yaml new file +10 -0
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      ad7291: adc@0 {
+        compatible = "adi,ad7291";
+        reg = <0>;
+        vref-supply = <&adc_vref>;
+      };
+    };
+

... added and empty blank line removed.