All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] ad7923 fixes and full range support
@ 2022-09-12  8:12 Nuno Sá
  2022-09-12  8:12 ` [PATCH v2 1/3] iio: adc: ad7923: fix channel readings for some variants Nuno Sá
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Nuno Sá @ 2022-09-12  8:12 UTC (permalink / raw)
  To: linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	Nuno Sá,
	Krzysztof Kozlowski, Rob Herring

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(-)

-- 
2.37.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] iio: adc: ad7923: fix channel readings for some variants
  2022-09-12  8:12 [PATCH v2 0/3] ad7923 fixes and full range support Nuno Sá
@ 2022-09-12  8:12 ` Nuno Sá
  2022-09-12  8:12 ` [PATCH v2 2/3] iio: adc: ad7923: support extended range Nuno Sá
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Nuno Sá @ 2022-09-12  8:12 UTC (permalink / raw)
  To: linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	Nuno Sá,
	Krzysztof Kozlowski, Rob Herring

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")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/iio/adc/ad7923.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index edad1f30121d..502253f53d96 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -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;
 
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] iio: adc: ad7923: support extended range
  2022-09-12  8:12 [PATCH v2 0/3] ad7923 fixes and full range support Nuno Sá
  2022-09-12  8:12 ` [PATCH v2 1/3] iio: adc: ad7923: fix channel readings for some variants Nuno Sá
@ 2022-09-12  8:12 ` Nuno Sá
  2022-09-12  8:12 ` [PATCH v2 3/3] dt-bindings: iio: adi,ad7923: add adi,range-double property Nuno Sá
  2022-09-18 15:33 ` [PATCH v2 0/3] ad7923 fixes and full range support Jonathan Cameron
  3 siblings, 0 replies; 6+ messages in thread
From: Nuno Sá @ 2022-09-12  8:12 UTC (permalink / raw)
  To: linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	Nuno Sá,
	Krzysztof Kozlowski, Rob Herring

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.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/iio/adc/ad7923.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 502253f53d96..9d6bf6d0927a 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -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];
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] dt-bindings: iio: adi,ad7923: add adi,range-double property
  2022-09-12  8:12 [PATCH v2 0/3] ad7923 fixes and full range support Nuno Sá
  2022-09-12  8:12 ` [PATCH v2 1/3] iio: adc: ad7923: fix channel readings for some variants Nuno Sá
  2022-09-12  8:12 ` [PATCH v2 2/3] iio: adc: ad7923: support extended range Nuno Sá
@ 2022-09-12  8:12 ` Nuno Sá
  2022-09-13 14:12   ` Krzysztof Kozlowski
  2022-09-18 15:33 ` [PATCH v2 0/3] ad7923 fixes and full range support Jonathan Cameron
  3 siblings, 1 reply; 6+ messages in thread
From: Nuno Sá @ 2022-09-12  8:12 UTC (permalink / raw)
  To: linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	Nuno Sá,
	Krzysztof Kozlowski, Rob Herring

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

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml
index 40b0a887db57..07f9d1c09c7d 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7923.yaml
@@ -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
 
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] dt-bindings: iio: adi,ad7923: add adi,range-double property
  2022-09-12  8:12 ` [PATCH v2 3/3] dt-bindings: iio: adi,ad7923: add adi,range-double property Nuno Sá
@ 2022-09-13 14:12   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-13 14:12 UTC (permalink / raw)
  To: Nuno Sá, linux-iio, devicetree
  Cc: Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
	Krzysztof Kozlowski, Rob Herring

On 12/09/2022 10:12, Nuno Sá wrote:
> Document the new property to enable doubling the analog input range.
> 
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] ad7923 fixes and full range support
  2022-09-12  8:12 [PATCH v2 0/3] ad7923 fixes and full range support Nuno Sá
                   ` (2 preceding siblings ...)
  2022-09-12  8:12 ` [PATCH v2 3/3] dt-bindings: iio: adi,ad7923: add adi,range-double property Nuno Sá
@ 2022-09-18 15:33 ` Jonathan Cameron
  3 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2022-09-18 15:33 UTC (permalink / raw)
  To: Nuno Sá
  Cc: linux-iio, devicetree, Michael Hennerich, Lars-Peter Clausen,
	Krzysztof Kozlowski, Rob Herring

On Mon, 12 Sep 2022 10:12:20 +0200
Nuno Sá <nuno.sa@analog.com> 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

> 
> 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(-)
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-18 15:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12  8:12 [PATCH v2 0/3] ad7923 fixes and full range support Nuno Sá
2022-09-12  8:12 ` [PATCH v2 1/3] iio: adc: ad7923: fix channel readings for some variants Nuno Sá
2022-09-12  8:12 ` [PATCH v2 2/3] iio: adc: ad7923: support extended range Nuno Sá
2022-09-12  8:12 ` [PATCH v2 3/3] dt-bindings: iio: adi,ad7923: add adi,range-double property Nuno Sá
2022-09-13 14:12   ` Krzysztof Kozlowski
2022-09-18 15:33 ` [PATCH v2 0/3] ad7923 fixes and full range support Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.