Skip to contentSkip to conversation

ad7923 fixes and full range support

PATCH Applied Nuno Sá 3 participants 6 messages Sep 12, 2022 – Sep 18, 2022

Subsystems (3)
lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

v2 cover ad7923 fixes and full range support

This patchset adds important fixes for some of the variants supported by the driver with respect with raw and buffered reads. On top of this way, adds a new firmware property to be able to support all the scales supported by the hardware.

v2:

[1/3]
* Calculate shift using 12 - realbits.

[2/3]
* Use a boolean property and change the code accordingly.

[3/3]
* Use a boolean property (adi,range-double).

Nuno Sá (3):
iio: adc: ad7923: fix channel readings for some variants
iio: adc: ad7923: support extended range
dt-bindings: iio: adi,ad7923: add adi,range-double property

 .../devicetree/bindings/iio/adc/adi,ad7923.yaml       |  4 ++++
 drivers/iio/adc/ad7923.c                              | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v2 1/3 iio: adc: ad7923: fix channel readings for some variants

Some of the supported devices have 4 or 2 LSB trailing bits that should not be taken into account. Hence we need to shift these bits out which fits perfectly on the scan type shift property. This change fixes both raw and buffered reads.

Fixes f2f7a449707e ("iio:adc:ad7923: Add support for the ad7904/ad7914/ad7924")
Fixes 851644a60d20 ("iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928")
---
 drivers/iio/adc/ad7923.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7923.c +3 -1
index edad1f30121d..502253f53d96 100644
@@ -93,6 +93,7 @@ enum ad7923_id {
 			.sign = 'u',					\
 			.realbits = (bits),				\
 			.storagebits = 16,				\
+			.shift = 12 - (bits),				\
 			.endianness = IIO_BE,				\
 		},							\
 	}
@@ -268,7 +269,8 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
 			return ret;
 
 		if (chan->address == EXTRACT(ret, 12, 4))
-			*val = EXTRACT(ret, 0, 12);
+			*val = EXTRACT(ret, chan->scan_type.shift,
+				       chan->scan_type.realbits);
 		else
 			return -EIO;
 
Signature · 1 line
2.37.3
author maintainer
#2 lore raw

PATCH v2 2/3 iio: adc: ad7923: support extended range

In reply to Nuno Sá

By default the driver was always setting the RANGE bit which means that the analog input goes from 0 to VREF. However, we might want to have 0 to 2xVREF. This change adds a new Firmware property to allow for the extended range while keeping the default behavior if nothing is provided.

---
 drivers/iio/adc/ad7923.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7923.c +6 -1
index 502253f53d96..9d6bf6d0927a 100644
@@ -8,6 +8,7 @@
 
 #include <linux/device.h>
 #include <linux/kernel.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
 #include <linux/spi/spi.h>
@@ -300,6 +301,7 @@ static void ad7923_regulator_disable(void *data)
 
 static int ad7923_probe(struct spi_device *spi)
 {
+	u32 ad7923_range = AD7923_RANGE;
 	struct ad7923_state *st;
 	struct iio_dev *indio_dev;
 	const struct ad7923_chip_info *info;
@@ -311,8 +313,11 @@ static int ad7923_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 
+	if (device_property_read_bool(&spi->dev, "adi,range-double"))
+		ad7923_range = 0;
+
 	st->spi = spi;
-	st->settings = AD7923_CODING | AD7923_RANGE |
+	st->settings = AD7923_CODING | ad7923_range |
 			AD7923_PM_MODE_WRITE(AD7923_PM_MODE_OPS);
 
 	info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];
Signature · 1 line
2.37.3
author maintainer
#3 lore raw

PATCH v2 3/3 dt-bindings: iio: adi,ad7923: add adi,range-double property

In reply to Nuno Sá

Document the new property to enable doubling the analog input range.

---
 Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml +4 -0
index 40b0a887db57..07f9d1c09c7d 100644
@@ -36,6 +36,10 @@ properties:
     description: |
       The regulator supply for ADC reference voltage.
 
+  adi,range-double:
+    description: Sets the analog input range from 0 to 2xVREF.
+    type: boolean
+
   '#address-cells':
     const: 1
 
Signature · 1 line
2.37.3
maintainer Applied
#5 lore raw
In reply to Nuno Sá
Quoted 4 lines · On Mon, 12 Sep 2022 10:12:20 +0200 Nuno Sá <[email protected]> wrote:

This patchset adds important fixes for some of the variants supported by the driver with respect with raw and buffered reads. On top of this way, adds a new firmware property to be able to support all the scales supported by the hardware.

Applied.

Thanks,

Jonathan

Quoted 21 lines

v2:

[1/3]
* Calculate shift using 12 - realbits.

[2/3]
* Use a boolean property and change the code accordingly.

[3/3]
* Use a boolean property (adi,range-double).

Nuno Sá (3):
iio: adc: ad7923: fix channel readings for some variants
iio: adc: ad7923: support extended range
dt-bindings: iio: adi,ad7923: add adi,range-double property

 .../devicetree/bindings/iio/adc/adi,ad7923.yaml       |  4 ++++
 drivers/iio/adc/ad7923.c                              | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)