dt-bindings: iio: adc: add ad7816/7/8 digital temperature sensor / ADC
Subsystems (5)
RFC PATCH v3 1/1 dt-bindings: iio: adc: add ad7816/7/8 digital temperature sensor / ADC
Document the Analog Devices AD7816, AD7817, and AD7818 digital temperature sensor and ADC bindings in YAML format.
Please note that the driver for this device is currently in drivers/staging. This patch is sent as an RFC to clean up and standardize the device tree bindings prior to any major driver refactoring.
While reviewing the AD7816/7/8 datasheet to correctly document the properties, it was noted that the current staging driver attempts to request a 'busy' GPIO for both AD7816 and AD7817. However, the AD7816 is an 8-pin device and does not possess a BUSY pin (only the 16-pin AD7817 has it). Therefore, in this binding, busy-gpios is strictly limited to adi,ad7817.
This resolves the checkpatch.pl warnings regarding undocumented DT compatible strings.
---
Changes in v3:
- Removed redundant conditional check around gpiod_get_value() as suggested by Andy Shevchenko and Dan Carpenter.
- Switched to dev_err_probe() to avoid deferred probe spamming.
- Introduced local struct device *dev pointer in probe and kept the GPIO request on a single line for better readability.
- Added the missing Fixes tag requested by Jonathan Cameron.
.../bindings/iio/adc/adi,ad7816.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7816.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad7816.yaml new file +0 -0
--- /dev/null
Changes in v3:
- Removed redundant conditional check around gpiod_get_value() as suggested by Andy Shevchenko and Dan Carpenter.
- Switched to dev_err_probe() to avoid deferred probe spamming.
- Introduced local struct device *dev pointer in probe and kept the GPIO request on a single line for better readability.
- Added the missing Fixes tag requested by Jonathan Cameron.
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7816.yaml @@ -0,0 +1,105 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7816.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7816/7/8 digital temperature sensor / ADC +
+maintainers:
+ - Taha Narimani <[email protected]>
+
+description: |
+ Analog Devices AD7816, AD7817, and AD7818 10-Bit general purpose ADC and
+ temperature sensor. The device communicates via an SPI interface. +
+properties:
+ compatible:
+ enum:
+ - adi,ad7816 + - adi,ad7817 + - adi,ad7818
+
+ reg:
+ maxItems: 1
+
+ spi-max-frequency:
+ maximum: 12500000
+
+ vdd-supply:
+ description: Main power supply.
+
+ vref-supply:
+ description: |
+ Optional external reference voltage supply. If not provided, the
+ internal reference is used. Applicable for AD7816 and AD7817.
+
+ rdwr-gpios:
+ maxItems: 1
+ description: GPIO connected to the RD/WR pin.
+
+ convert-gpios:
+ maxItems: 1
+ description: GPIO connected to the CONVST (Convert Start) pin.
+
+ busy-gpios:
+ maxItems: 1
+ description: GPIO connected to the BUSY pin. Only applicable for AD7817.
+
+ interrupts:
+ maxItems: 1
+ description: OTI (Over Temperature Indicator) interrupt. Active low.
+
+required:
+ - compatible + - reg + - vdd-supply + - rdwr-gpios + - convert-gpios
+
+allOf:
+ - $ref: /schemas/spi/spi-peripheral-props.yaml#
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: adi,ad7817
+ then:
+ required:
+ - busy-gpios
+ else:
+ properties:
+ busy-gpios: false
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: adi,ad7818
+ then:
+ properties:
+ vref-supply: false
+
+unevaluatedProperties: false
+
+examples:
+ - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/interrupt-controller/irq.h>
+
+ spi {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ adc@0 {
+ compatible = "adi,ad7817"; + reg = <0>; + spi-max-frequency = <1000000>; + vdd-supply = <&vcc>; + vref-supply = <&vref>; + rdwr-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>; + convert-gpios = <&gpio 6 GPIO_ACTIVE_HIGH>; + busy-gpios = <&gpio 7 GPIO_ACTIVE_HIGH>; + interrupts = <20 IRQ_TYPE_LEVEL_LOW>; + interrupt-parent = <&gpio>;
+ };
+ };
Signature · 1 line
2.53.0
PATCH v3 1/1 staging: iio: adc: ad7816: Use devm_gpiod_get_optional() for busy GPIO
The driver currently utilizes devm_gpiod_get() for the 'busy' line, which makes the GPIO mandatory. However, the busy pin is hardware-optional depending on the specific board configuration.
Switch to devm_gpiod_get_optional() to allow boards that do not have this pin wired up to still probe the driver successfully. Clean up the redundant busy_pin conditional checks as gpiod_get_value() safely handles NULL descriptors. Additionally, use dev_err_probe() to prevent bootlog spamming during deferred probing.
---
Changes in v3:
- Removed redundant conditional check around gpiod_get_value() as suggested by Andy Shevchenko and Dan Carpenter.
- Switched to dev_err_probe() to avoid deferred probe spamming.
- Introduced local struct device *dev pointer in probe and kept the GPIO request on a single line for better readability.
- Added the missing Fixes tag requested by Jonathan Cameron.
drivers/staging/iio/adc/ad7816.c | 67 +++++++++++++------------------- 1 file changed, 28 insertions(+), 39 deletions(-)
drivers/staging/iio/adc/ad7816.c +0 -0
--- a/drivers/staging/iio/adc/ad7816.c
Changes in v3:
- Removed redundant conditional check around gpiod_get_value() as suggested by Andy Shevchenko and Dan Carpenter.
- Switched to dev_err_probe() to avoid deferred probe spamming.
- Introduced local struct device *dev pointer in probe and kept the GPIO request on a single line for better readability.
- Added the missing Fixes tag requested by Jonathan Cameron.
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -22,20 +22,20 @@
/*
* AD7816 config masks
*/
-#define AD7816_FULL 0x1
-#define AD7816_PD 0x2
-#define AD7816_CS_MASK 0x7
-#define AD7816_CS_MAX 0x4
+#define AD7816_FULL 0x1 +#define AD7816_PD 0x2 +#define AD7816_CS_MASK 0x7 +#define AD7816_CS_MAX 0x4
/*
* AD7816 temperature masks
*/
-#define AD7816_VALUE_OFFSET 6
-#define AD7816_BOUND_VALUE_BASE 0x8
-#define AD7816_BOUND_VALUE_MIN -95
-#define AD7816_BOUND_VALUE_MAX 152
-#define AD7816_TEMP_FLOAT_OFFSET 2
-#define AD7816_TEMP_FLOAT_MASK 0x3
+#define AD7816_VALUE_OFFSET 6 +#define AD7816_BOUND_VALUE_BASE 0x8 +#define AD7816_BOUND_VALUE_MIN -95 +#define AD7816_BOUND_VALUE_MAX 152 +#define AD7816_TEMP_FLOAT_OFFSET 2 +#define AD7816_TEMP_FLOAT_MASK 0x3
/*
* struct ad7816_chip_info - chip specific information
@@ -48,7 +48,7 @@ struct ad7816_chip_info {
struct gpio_desc *convert_pin;
struct gpio_desc *busy_pin;
u8 oti_data[AD7816_CS_MAX + 1]; - u8 channel_id; /* 0 always be temperature */ + u8 channel_id; /* 0 always be temperature */ u8 mode;
};
@@ -84,10 +84,8 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
gpiod_set_value(chip->convert_pin, 1);
}
-if (chip->id == ID_AD7816 || chip->id == ID_AD7817) {
- while (gpiod_get_value(chip->busy_pin))
- cpu_relax();
- }
+ while (gpiod_get_value(chip->busy_pin))
+ cpu_relax();
gpiod_set_value(chip->rdwr_pin, 0); gpiod_set_value(chip->rdwr_pin, 1);
@@ -254,8 +252,8 @@ static const struct attribute_group ad7816_attribute_group = {
* temperature bound events
*/
-#define IIO_EVENT_CODE_AD7816_OTI IIO_UNMOD_EVENT_CODE(IIO_TEMP, \
- 0, \
+#define IIO_EVENT_CODE_AD7816_OTI IIO_UNMOD_EVENT_CODE(IIO_TEMP, \
+ 0, \
IIO_EV_TYPE_THRESH, \
IIO_EV_DIR_FALLING)
@@ -351,11 +349,12 @@ static const struct iio_info ad7816_info = {
static int ad7816_probe(struct spi_device *spi_dev) {
+ struct device *dev = &spi_dev->dev;
struct ad7816_chip_info *chip; struct iio_dev *indio_dev;
int i, ret;
- indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*chip));
if (!indio_dev)
return -ENOMEM;
chip = iio_priv(indio_dev);
@@ -365,31 +364,22 @@ static int ad7816_probe(struct spi_device *spi_dev)
chip->oti_data[i] = 203;
chip->id = spi_get_device_id(spi_dev)->driver_data;
- chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_OUT_HIGH);
+ chip->rdwr_pin = devm_gpiod_get(dev, "rdwr", GPIOD_OUT_HIGH);
if (IS_ERR(chip->rdwr_pin)) {
ret = PTR_ERR(chip->rdwr_pin);
- dev_err(&spi_dev->dev, "Failed to request rdwr GPIO: %d\n",
- ret);
+ dev_err(dev, "Failed to request rdwr GPIO: %d\n", ret);
return ret;
}
- chip->convert_pin = devm_gpiod_get(&spi_dev->dev, "convert",
- GPIOD_OUT_HIGH);
+ chip->convert_pin = devm_gpiod_get(dev, "convert", GPIOD_OUT_HIGH);
if (IS_ERR(chip->convert_pin)) {
ret = PTR_ERR(chip->convert_pin);
- dev_err(&spi_dev->dev, "Failed to request convert GPIO: %d\n",
- ret);
+ dev_err(dev, "Failed to request convert GPIO: %d\n", ret);
return ret;
}
- if (chip->id == ID_AD7816 || chip->id == ID_AD7817) {
- chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy",
- GPIOD_IN);
- if (IS_ERR(chip->busy_pin)) {
- ret = PTR_ERR(chip->busy_pin);
- dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n",
- ret);
- return ret;
- }
- }
+
+ chip->busy_pin = devm_gpiod_get_optional(dev, "busy", GPIOD_IN);
+ if (IS_ERR(chip->busy_pin))
+ return dev_err_probe(dev, PTR_ERR(chip->busy_pin), "Failed to request busy GPIO\n");
indio_dev->name = spi_get_device_id(spi_dev)->name; indio_dev->info = &ad7816_info;
@@ -397,7 +387,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
if (spi_dev->irq) {
/* Only low trigger is supported in ad7816/7/8 */
- ret = devm_request_threaded_irq(&spi_dev->dev, spi_dev->irq,
+ ret = devm_request_threaded_irq(dev, spi_dev->irq,
NULL, &ad7816_event_handler, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
@@ -407,11 +397,11 @@ static int ad7816_probe(struct spi_device *spi_dev)
return ret;
}
- ret = devm_iio_device_register(&spi_dev->dev, indio_dev);
+ ret = devm_iio_device_register(dev, indio_dev);
if (ret)
return ret;
- dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
+ dev_info(dev, "%s temperature sensor and ADC registered.\n",
indio_dev->name);
return 0;
@@ -431,7 +421,6 @@ static const struct spi_device_id ad7816_id[] = {
{ "ad7818", ID_AD7818 },
{ }
};
-
MODULE_DEVICE_TABLE(spi, ad7816_id);
static struct spi_driver ad7816_driver = {
Signature · 1 line
2.53.0
Re: [PATCH v3] staging: iio: adc: ad7816: Use devm_gpiod_get_optional() for busy GPIO
Review struct ad7816_chip_info { · line 51
Quoted 8 lines · Taha Narimani
/*
* structad7816_chip_info- chip specific information(quoted diff) +1
-1@@ -48,7 +48,7 @@ struct ad7816_chip_info { struct gpio_desc *convert_pin; struct gpio_desc *busy_pin; u8 oti_data[AD7816_CS_MAX + 1]; - u8 channel_id; /* 0 always be temperature */ + u8 channel_id; /* 0 always be temperature */
What changed here??
Review static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) · line 89
Quoted 10 lines
(quoted diff) +0
-3u8 mode; };@@ -84,10 +84,8 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) gpiod_set_value(chip->convert_pin, 1); } -if (chip->id == ID_AD7816 || chip->id == ID_AD7817) { - while (gpiod_get_value(chip->busy_pin)) - cpu_relax();
This patch doesn't apply. Not sure what went wrong but maybe it's related to this?
Review static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) · line 91
Quoted 6 lines
(quoted diff) +2
-1- } + while (gpiod_get_value(chip->busy_pin)) + cpu_relax(); gpiod_set_value(chip->rdwr_pin, 0); gpiod_set_value(chip->rdwr_pin, 1);
regards,
dan carpenter
Re: [PATCH v3] staging: iio: adc: ad7816: Use devm_gpiod_get_optional() for busy GPIO
In reply to Taha NarimaniHi Taha,
Quoted 11 lines · CDT Taha Narimani
The driver currently utilizes
devm_gpiod_get()for the 'busy' line, which makes the GPIO mandatory. However, the busy pin is hardware-optional depending on the specific board configuration.Switch to
devm_gpiod_get_optional()to allow boards that do not have this pin wired up to still probe the driver successfully. Clean up the redundantbusy_pinconditional checks asgpiod_get_value()safely handles NULL descriptors. Additionally, usedev_err_probe()to prevent bootlog spamming during deferred probing.Fixes 3e5971b2ddb6 ("base: original ad7816.c")
If this is a fix, then why are we making style changes?
Quoted 6 lines
Signed-off-by Taha Narimani <[email protected]>---
Changes in v3:
- Removed redundant conditional check aroundgpiod_get_value()as suggested by Andy Shevchenko and Dan Carpenter.
- Switched todev_err_probe()to avoid deferred probe spamming.
- Introduced local struct device *dev pointer in probe and kept the GPIO request on a single line for better readability.
Unless someone requested this during review this doesn't make sense. Please see my above comment, and I'd also suggest to take a look at Documentation/process/submitting-patches.rst.
Quoted 8 lines
- Added the missing Fixes tag requested by Jonathan Cameron.
drivers/staging/iio/adc/ad7816.c | 67 +++++++++++++------------------- 1 file changed, 28 insertions(+), 39 deletions(-)drivers/staging/iio/adc/ad7816.c +0
-1--- a/drivers/staging/iio/adc/ad7816.c
Quoted 6 lines
Changes in v3:
- Removed redundant conditional check aroundgpiod_get_value()as suggested by Andy Shevchenko and Dan Carpenter.
- Switched todev_err_probe()to avoid deferred probe spamming.
- Introduced local struct device *dev pointer in probe and kept the GPIO request on a single line for better readability.
- Added the missing Fixes tag requested by Jonathan Cameron.
Wrong spot for this + causes the patch to not apply. It should be below the --- right after the list of tags.
Quoted 4 lines
+++
b/drivers/staging/iio/adc/ad7816.cdrivers/staging/iio/adc/ad7816.c +0
-0@@ -22,20 +22,20 @@/* * AD7816 config masks
drivers/staging/iio/adc/ad7816.c line 29
Quoted 10 lines
drivers/staging/iio/adc/ad7816.c +4
-4*/ -#define AD7816_FULL 0x1 -#define AD7816_PD 0x2 -#define AD7816_CS_MASK 0x7 -#define AD7816_CS_MAX 0x4 +#define AD7816_FULL 0x1 +#define AD7816_PD 0x2 +#define AD7816_CS_MASK 0x7 +#define AD7816_CS_MAX 0x4
Nothing changed? Seems like a stray change.
Quoted 6 lines
drivers/staging/iio/adc/ad7816.c +0
-3/* * AD7816 temperature masks */ -#define AD7816_VALUE_OFFSET 6 -#define AD7816_BOUND_VALUE_BASE 0x8 -#define AD7816_BOUND_VALUE_MIN -95
drivers/staging/iio/adc/ad7816.c line 39
Quoted 10 lines
drivers/staging/iio/adc/ad7816.c +6
-3-#define AD7816_BOUND_VALUE_MAX 152 -#define AD7816_TEMP_FLOAT_OFFSET 2 -#define AD7816_TEMP_FLOAT_MASK 0x3 +#define AD7816_VALUE_OFFSET 6 +#define AD7816_BOUND_VALUE_BASE 0x8 +#define AD7816_BOUND_VALUE_MIN -95 +#define AD7816_BOUND_VALUE_MAX 152 +#define AD7816_TEMP_FLOAT_OFFSET 2 +#define AD7816_TEMP_FLOAT_MASK 0x3
Ditto.
drivers/staging/iio/adc/ad7816.c struct ad7816_chip_info { · line 54
Quoted 11 lines
drivers/staging/iio/adc/ad7816.c +1
-1/* * struct ad7816_chip_info - chip specific information @@ -48,7 +48,7 @@ struct ad7816_chip_info {struct gpio_desc *convert_pin;struct gpio_desc *busy_pin;u8 oti_data[AD7816_CS_MAX +1 ]; -u8 channel_id;/* 0 always be temperature */ +u8 channel_id;/* 0 always be temperature */ u8 mode; };
Here as well.
drivers/staging/iio/adc/ad7816.c static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) · line 89
Quoted 11 lines
drivers/staging/iio/adc/ad7816.c +2
-4@@ -84,10 +84,8 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)gpiod_set_value (chip->convert_pin,1 ); } -if (chip->id ==ID_AD7816 || chip->id ==ID_AD7817 ) { -while (gpiod_get_value (chip->busy_pin)) -cpu_relax (); - } +while (gpiod_get_value (chip->busy_pin)) +cpu_relax ();
Can you explain why we're removing this check? There also seems to be a spot in _probe() where the check gets removed as well.
drivers/staging/iio/adc/ad7816.c static const struct attribute_group ad7816_attribute_group = { · line 259
Quoted 13 lines
drivers/staging/iio/adc/ad7816.c +2
-2gpiod_set_value (chip->rdwr_pin,0 );gpiod_set_value (chip->rdwr_pin,1 );@@ -254,8 +252,8 @@ static const struct attribute_group ad7816_attribute_group = {* temperature bound events */ -#define IIO_EVENT_CODE_AD7816_OTI IIO_UNMOD_EVENT_CODE(IIO_TEMP, \ - 0, \ +#define IIO_EVENT_CODE_AD7816_OTI IIO_UNMOD_EVENT_CODE(IIO_TEMP, \ + 0, \ IIO_EV_TYPE_THRESH, \ IIO_EV_DIR_FALLING)
Seems like another stray change.
drivers/staging/iio/adc/ad7816.c static const struct iio_info ad7816_info = { · line 352
Quoted 5 lines
drivers/staging/iio/adc/ad7816.c +1
-0@@ -351,11 +349,12 @@ static const struct iio_info ad7816_info = {static int ad7816_probe (struct spi_device *spi_dev) { +struct device *dev = &spi_dev->dev;
Again, why are we doing style changes? This seems to be a fix instead of a style patch.
Quoted 9 lines
drivers/staging/iio/adc/ad7816.c +1
-1struct ad7816_chip_info *chip;struct iio_dev *indio_dev;int i, ret; - indio_dev =devm_iio_device_alloc (&spi_dev->dev,sizeof (*chip)); + indio_dev =devm_iio_device_alloc (dev,sizeof (*chip));if (!indio_dev)return -ENOMEM ; chip =iio_priv (indio_dev);
...
drivers/staging/iio/adc/ad7816.c static const struct spi_device_id ad7816_id[] = { · line 434
Quoted 5 lines
drivers/staging/iio/adc/ad7816.c +0
-1@@ -431,7 +421,6 @@ static const struct spi_device_id ad7816_id[] = { { "ad7818", ID_AD7818 }, { } }; -
Stray change.
Quoted 3 lines
drivers/staging/iio/adc/ad7816.c +0
-0MODULE_DEVICE_TABLE (spi, ad7816_id);static struct spi_driver ad7816_driver = {
Signature · 2 lines
best regards, max
Quoted 4 lines · Taha Narimani
Document the Analog Devices AD7816, AD7817, and AD7818 digital temperature sensor and ADC bindings in YAML format.
Please note that the driver for this device is currently in
drivers/staging.
So you should not send it.
Quoted 11 lines
This patch is sent as an RFC to clean up and standardize the device tree bindings prior to any major driver refactoring.
While reviewing the AD7816/7/8 datasheet to correctly document the properties, it was noted that the current staging driver attempts to request a 'busy' GPIO for both AD7816 and AD7817. However, the AD7816 is an 8-pin device and does not possess a BUSY pin (only the 16-pin AD7817 has it). Therefore, in this binding, busy-gpios is strictly limited to adi,ad7817.
This resolves the checkpatch.pl warnings regarding undocumented DT compatible strings.
That's not necessary.
Best regards,
Krzysztof