public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues
@ 2024-10-22 13:22 Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 1/5] dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply Julien Stephan
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-22 13:22 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Liam Girdwood, Mark Brown, Jonathan Corbet
  Cc: linux-iio, devicetree, linux-kernel, Conor Dooley,
	Jonathan Cameron, linux-doc, Julien Stephan

Hello,

This series tries to fix several issues found on the ad7380 driver about
supplies:

- vcc and vlogic are required, but are not retrieved and enabled in the
probe function
- ad7380-4 is the only device from the family that does not have internal
reference and uses REFIN instead of REFIO for external reference.

driver, bindings, and doc are fixed accordingly

Signed-off-by: Julien Stephan <jstephan@baylibre.com>
---
Changes in v3:
- Use fsleep instead of msleep
- Add all trailers from review
- Link to v2: https://lore.kernel.org/r/20241021-ad7380-fix-supplies-v2-0-2ca551b3352a@baylibre.com

Changes in v2:
- Fix kernel test robot warning about variable uninitialized when used [1]
- drop commit removing supply description in bindings
- after discussion on [2] we decided to add refin supply here, as it
  will be needed in the futur

- Link to v1: https://lore.kernel.org/r/20241007-ad7380-fix-supplies-v1-0-badcf813c9b9@baylibre.com

[1] https://lore.kernel.org/oe-kbuild-all/202410081608.ZxEPPZ0u-lkp@intel.com/
[2] https://lore.kernel.org/all/20241015-ad7380-add-adaq4380-4-support-v1-0-d2e1a95fb248@baylibre.com/:warning

---
Julien Stephan (5):
      dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply
      iio: adc: ad7380: use devm_regulator_get_enable_read_voltage()
      iio: adc: ad7380: add missing supplies
      iio: adc: ad7380: fix supplies for ad7380-4
      docs: iio: ad7380: fix supply for ad7380-4

 .../devicetree/bindings/iio/adc/adi,ad7380.yaml    |  21 ++++
 Documentation/iio/ad7380.rst                       |  13 +-
 drivers/iio/adc/ad7380.c                           | 136 ++++++++++++---------
 3 files changed, 110 insertions(+), 60 deletions(-)
---
base-commit: 1a8b58362f6a6fef975032f7fceb7c4b80d20d60
change-id: 20241004-ad7380-fix-supplies-3677365cf8aa

Best regards,
-- 
Julien Stephan <jstephan@baylibre.com>


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

* [PATCH v3 1/5] dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply
  2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
@ 2024-10-22 13:22 ` Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 2/5] iio: adc: ad7380: use devm_regulator_get_enable_read_voltage() Julien Stephan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-22 13:22 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Liam Girdwood, Mark Brown, Jonathan Corbet
  Cc: linux-iio, devicetree, linux-kernel, Conor Dooley,
	Jonathan Cameron, linux-doc, Julien Stephan

ad7380-4 is the only device from ad738x family that doesn't have an
internal reference. Moreover its external reference is called REFIN in
the datasheet while all other use REFIO as an optional external
reference. If refio-supply is omitted the internal reference is
used.

Fix the binding by adding refin-supply and makes it required for
ad7380-4 only.

Fixes: 1a291cc8ee17 ("dt-bindings: iio: adc: ad7380: add support for ad738x-4 4 channels variants")
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Julien Stephan <jstephan@baylibre.com>
---
 .../devicetree/bindings/iio/adc/adi,ad7380.yaml     | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
index bd19abb867d98d46bdd1c9e0c197e10f06979204..0065d650882489e21b952bb9fb25f1e3a070ee68 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
@@ -67,6 +67,10 @@ properties:
       A 2.5V to 3.3V supply for the external reference voltage. When omitted,
       the internal 2.5V reference is used.
 
+  refin-supply:
+    description:
+      A 2.5V to 3.3V supply for external reference voltage, for ad7380-4 only.
+
   aina-supply:
     description:
       The common mode voltage supply for the AINA- pin on pseudo-differential
@@ -135,6 +139,23 @@ allOf:
         ainc-supply: false
         aind-supply: false
 
+  # ad7380-4 uses refin-supply as external reference.
+  # All other chips from ad738x family use refio as optional external reference.
+  # When refio-supply is omitted, internal reference is used.
+  - if:
+      properties:
+        compatible:
+          enum:
+            - adi,ad7380-4
+    then:
+      properties:
+        refio-supply: false
+      required:
+        - refin-supply
+    else:
+      properties:
+        refin-supply: false
+
 examples:
   - |
     #include <dt-bindings/interrupt-controller/irq.h>

-- 
2.47.0


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

* [PATCH v3 2/5] iio: adc: ad7380: use devm_regulator_get_enable_read_voltage()
  2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 1/5] dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply Julien Stephan
@ 2024-10-22 13:22 ` Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 3/5] iio: adc: ad7380: add missing supplies Julien Stephan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-22 13:22 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Liam Girdwood, Mark Brown, Jonathan Corbet
  Cc: linux-iio, devicetree, linux-kernel, Conor Dooley,
	Jonathan Cameron, linux-doc, Julien Stephan

Use devm_regulator_get_enable_read_voltage() to simplify the code.

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Julien Stephan <jstephan@baylibre.com>
---
 drivers/iio/adc/ad7380.c | 81 +++++++++++++-----------------------------------
 1 file changed, 21 insertions(+), 60 deletions(-)

diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index e8bddfb0d07dbcf3e2a43344a4e0516f4d617548..e033c734191143a25a490b09c730dbf95f796737 100644
--- a/drivers/iio/adc/ad7380.c
+++ b/drivers/iio/adc/ad7380.c
@@ -956,7 +956,7 @@ static const struct iio_info ad7380_info = {
 	.debugfs_reg_access = &ad7380_debugfs_reg_access,
 };
 
-static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
+static int ad7380_init(struct ad7380_state *st, bool external_ref_en)
 {
 	int ret;
 
@@ -968,13 +968,13 @@ static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
 	if (ret < 0)
 		return ret;
 
-	/* select internal or external reference voltage */
-	ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
-				 AD7380_CONFIG1_REFSEL,
-				 FIELD_PREP(AD7380_CONFIG1_REFSEL,
-					    vref ? 1 : 0));
-	if (ret < 0)
-		return ret;
+	if (external_ref_en) {
+		/* select external reference voltage */
+		ret = regmap_set_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
+				      AD7380_CONFIG1_REFSEL);
+		if (ret < 0)
+			return ret;
+	}
 
 	/* This is the default value after reset. */
 	st->oversampling_ratio = 1;
@@ -987,16 +987,11 @@ static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
 				  FIELD_PREP(AD7380_CONFIG2_SDO, 1));
 }
 
-static void ad7380_regulator_disable(void *p)
-{
-	regulator_disable(p);
-}
-
 static int ad7380_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
 	struct ad7380_state *st;
-	struct regulator *vref;
+	bool external_ref_en;
 	int ret, i;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
@@ -1009,37 +1004,17 @@ static int ad7380_probe(struct spi_device *spi)
 	if (!st->chip_info)
 		return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n");
 
-	vref = devm_regulator_get_optional(&spi->dev, "refio");
-	if (IS_ERR(vref)) {
-		if (PTR_ERR(vref) != -ENODEV)
-			return dev_err_probe(&spi->dev, PTR_ERR(vref),
-					     "Failed to get refio regulator\n");
-
-		vref = NULL;
-	}
-
 	/*
 	 * If there is no REFIO supply, then it means that we are using
 	 * the internal 2.5V reference, otherwise REFIO is reference voltage.
 	 */
-	if (vref) {
-		ret = regulator_enable(vref);
-		if (ret)
-			return ret;
+	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "refio");
+	if (ret < 0 && ret != -ENODEV)
+		return dev_err_probe(&spi->dev, ret,
+				     "Failed to get refio regulator\n");
 
-		ret = devm_add_action_or_reset(&spi->dev,
-					       ad7380_regulator_disable, vref);
-		if (ret)
-			return ret;
-
-		ret = regulator_get_voltage(vref);
-		if (ret < 0)
-			return ret;
-
-		st->vref_mv = ret / 1000;
-	} else {
-		st->vref_mv = AD7380_INTERNAL_REF_MV;
-	}
+	external_ref_en = ret != -ENODEV;
+	st->vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV;
 
 	if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv))
 		return dev_err_probe(&spi->dev, -EINVAL,
@@ -1050,27 +1025,13 @@ static int ad7380_probe(struct spi_device *spi)
 	 * input pin.
 	 */
 	for (i = 0; i < st->chip_info->num_vcm_supplies; i++) {
-		struct regulator *vcm;
-
-		vcm = devm_regulator_get(&spi->dev,
-					 st->chip_info->vcm_supplies[i]);
-		if (IS_ERR(vcm))
-			return dev_err_probe(&spi->dev, PTR_ERR(vcm),
-					     "Failed to get %s regulator\n",
-					     st->chip_info->vcm_supplies[i]);
+		const char *vcm = st->chip_info->vcm_supplies[i];
 
-		ret = regulator_enable(vcm);
-		if (ret)
-			return ret;
-
-		ret = devm_add_action_or_reset(&spi->dev,
-					       ad7380_regulator_disable, vcm);
-		if (ret)
-			return ret;
-
-		ret = regulator_get_voltage(vcm);
+		ret = devm_regulator_get_enable_read_voltage(&spi->dev, vcm);
 		if (ret < 0)
-			return ret;
+			return dev_err_probe(&spi->dev, ret,
+					     "Failed to get %s regulator\n",
+					     vcm);
 
 		st->vcm_mv[i] = ret / 1000;
 	}
@@ -1135,7 +1096,7 @@ static int ad7380_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = ad7380_init(st, vref);
+	ret = ad7380_init(st, external_ref_en);
 	if (ret)
 		return ret;
 

-- 
2.47.0


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

* [PATCH v3 3/5] iio: adc: ad7380: add missing supplies
  2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 1/5] dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 2/5] iio: adc: ad7380: use devm_regulator_get_enable_read_voltage() Julien Stephan
@ 2024-10-22 13:22 ` Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 4/5] iio: adc: ad7380: fix supplies for ad7380-4 Julien Stephan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-22 13:22 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Liam Girdwood, Mark Brown, Jonathan Corbet
  Cc: linux-iio, devicetree, linux-kernel, Conor Dooley,
	Jonathan Cameron, linux-doc, Julien Stephan

vcc and vlogic are required but are not retrieved and enabled in the
probe. Add them.

In order to prepare support for additional parts requiring different
supplies, add vcc and vlogic to the platform specific structures

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Julien Stephan <jstephan@baylibre.com>
---
 drivers/iio/adc/ad7380.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index e033c734191143a25a490b09c730dbf95f796737..b107d8e97ab36f7aed4685f18e0f398d63fd1e8d 100644
--- a/drivers/iio/adc/ad7380.c
+++ b/drivers/iio/adc/ad7380.c
@@ -75,6 +75,7 @@
 #define T_CONVERT_NS 190		/* conversion time */
 #define T_CONVERT_0_NS 10		/* 1st conversion start time (oversampling) */
 #define T_CONVERT_X_NS 500		/* xth conversion start time (oversampling) */
+#define T_POWERUP_US 5000		/* Power up */
 
 struct ad7380_timing_specs {
 	const unsigned int t_csh_ns;	/* CS minimum high time */
@@ -86,6 +87,8 @@ struct ad7380_chip_info {
 	unsigned int num_channels;
 	unsigned int num_simult_channels;
 	bool has_mux;
+	const char * const *supplies;
+	unsigned int num_supplies;
 	const char * const *vcm_supplies;
 	unsigned int num_vcm_supplies;
 	const unsigned long *available_scan_masks;
@@ -243,6 +246,10 @@ DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u);
 DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u);
 DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u);
 
+static const char * const ad7380_supplies[] = {
+	"vcc", "vlogic",
+};
+
 static const char * const ad7380_2_channel_vcm_supplies[] = {
 	"aina", "ainb",
 };
@@ -338,6 +345,8 @@ static const struct ad7380_chip_info ad7380_chip_info = {
 	.channels = ad7380_channels,
 	.num_channels = ARRAY_SIZE(ad7380_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.available_scan_masks = ad7380_2_channel_scan_masks,
 	.timing_specs = &ad7380_timing,
 };
@@ -347,6 +356,8 @@ static const struct ad7380_chip_info ad7381_chip_info = {
 	.channels = ad7381_channels,
 	.num_channels = ARRAY_SIZE(ad7381_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.available_scan_masks = ad7380_2_channel_scan_masks,
 	.timing_specs = &ad7380_timing,
 };
@@ -356,6 +367,8 @@ static const struct ad7380_chip_info ad7383_chip_info = {
 	.channels = ad7383_channels,
 	.num_channels = ARRAY_SIZE(ad7383_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.vcm_supplies = ad7380_2_channel_vcm_supplies,
 	.num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
 	.available_scan_masks = ad7380_2_channel_scan_masks,
@@ -367,6 +380,8 @@ static const struct ad7380_chip_info ad7384_chip_info = {
 	.channels = ad7384_channels,
 	.num_channels = ARRAY_SIZE(ad7384_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.vcm_supplies = ad7380_2_channel_vcm_supplies,
 	.num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
 	.available_scan_masks = ad7380_2_channel_scan_masks,
@@ -378,6 +393,8 @@ static const struct ad7380_chip_info ad7386_chip_info = {
 	.channels = ad7386_channels,
 	.num_channels = ARRAY_SIZE(ad7386_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.has_mux = true,
 	.available_scan_masks = ad7380_2x2_channel_scan_masks,
 	.timing_specs = &ad7380_timing,
@@ -388,6 +405,8 @@ static const struct ad7380_chip_info ad7387_chip_info = {
 	.channels = ad7387_channels,
 	.num_channels = ARRAY_SIZE(ad7387_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.has_mux = true,
 	.available_scan_masks = ad7380_2x2_channel_scan_masks,
 	.timing_specs = &ad7380_timing,
@@ -398,6 +417,8 @@ static const struct ad7380_chip_info ad7388_chip_info = {
 	.channels = ad7388_channels,
 	.num_channels = ARRAY_SIZE(ad7388_channels),
 	.num_simult_channels = 2,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.has_mux = true,
 	.available_scan_masks = ad7380_2x2_channel_scan_masks,
 	.timing_specs = &ad7380_timing,
@@ -408,6 +429,8 @@ static const struct ad7380_chip_info ad7380_4_chip_info = {
 	.channels = ad7380_4_channels,
 	.num_channels = ARRAY_SIZE(ad7380_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.available_scan_masks = ad7380_4_channel_scan_masks,
 	.timing_specs = &ad7380_4_timing,
 };
@@ -417,6 +440,8 @@ static const struct ad7380_chip_info ad7381_4_chip_info = {
 	.channels = ad7381_4_channels,
 	.num_channels = ARRAY_SIZE(ad7381_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.available_scan_masks = ad7380_4_channel_scan_masks,
 	.timing_specs = &ad7380_4_timing,
 };
@@ -426,6 +451,8 @@ static const struct ad7380_chip_info ad7383_4_chip_info = {
 	.channels = ad7383_4_channels,
 	.num_channels = ARRAY_SIZE(ad7383_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.vcm_supplies = ad7380_4_channel_vcm_supplies,
 	.num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
 	.available_scan_masks = ad7380_4_channel_scan_masks,
@@ -437,6 +464,8 @@ static const struct ad7380_chip_info ad7384_4_chip_info = {
 	.channels = ad7384_4_channels,
 	.num_channels = ARRAY_SIZE(ad7384_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.vcm_supplies = ad7380_4_channel_vcm_supplies,
 	.num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
 	.available_scan_masks = ad7380_4_channel_scan_masks,
@@ -448,6 +477,8 @@ static const struct ad7380_chip_info ad7386_4_chip_info = {
 	.channels = ad7386_4_channels,
 	.num_channels = ARRAY_SIZE(ad7386_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.has_mux = true,
 	.available_scan_masks = ad7380_2x4_channel_scan_masks,
 	.timing_specs = &ad7380_4_timing,
@@ -458,6 +489,8 @@ static const struct ad7380_chip_info ad7387_4_chip_info = {
 	.channels = ad7387_4_channels,
 	.num_channels = ARRAY_SIZE(ad7387_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.has_mux = true,
 	.available_scan_masks = ad7380_2x4_channel_scan_masks,
 	.timing_specs = &ad7380_4_timing,
@@ -468,6 +501,8 @@ static const struct ad7380_chip_info ad7388_4_chip_info = {
 	.channels = ad7388_4_channels,
 	.num_channels = ARRAY_SIZE(ad7388_4_channels),
 	.num_simult_channels = 4,
+	.supplies = ad7380_supplies,
+	.num_supplies = ARRAY_SIZE(ad7380_supplies),
 	.has_mux = true,
 	.available_scan_masks = ad7380_2x4_channel_scan_masks,
 	.timing_specs = &ad7380_4_timing,
@@ -1004,6 +1039,14 @@ static int ad7380_probe(struct spi_device *spi)
 	if (!st->chip_info)
 		return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n");
 
+	ret = devm_regulator_bulk_get_enable(&spi->dev, st->chip_info->num_supplies,
+					     st->chip_info->supplies);
+
+	if (ret)
+		return dev_err_probe(&spi->dev, ret,
+				     "Failed to enable power supplies\n");
+	fsleep(T_POWERUP_US);
+
 	/*
 	 * If there is no REFIO supply, then it means that we are using
 	 * the internal 2.5V reference, otherwise REFIO is reference voltage.

-- 
2.47.0


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

* [PATCH v3 4/5] iio: adc: ad7380: fix supplies for ad7380-4
  2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
                   ` (2 preceding siblings ...)
  2024-10-22 13:22 ` [PATCH v3 3/5] iio: adc: ad7380: add missing supplies Julien Stephan
@ 2024-10-22 13:22 ` Julien Stephan
  2024-10-22 13:22 ` [PATCH v3 5/5] docs: iio: ad7380: fix supply " Julien Stephan
  2024-10-22 20:02 ` [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Jonathan Cameron
  5 siblings, 0 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-22 13:22 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Liam Girdwood, Mark Brown, Jonathan Corbet
  Cc: linux-iio, devicetree, linux-kernel, Conor Dooley,
	Jonathan Cameron, linux-doc, Julien Stephan

ad7380-4 is the only device in the family that does not have an internal
reference. It uses "refin" as a required external reference.
All other devices in the family use "refio"" as an optional external
reference.

Fixes: 737413da8704 ("iio: adc: ad7380: add support for ad738x-4 4 channels variants")
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Julien Stephan <jstephan@baylibre.com>
---
 drivers/iio/adc/ad7380.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index b107d8e97ab36f7aed4685f18e0f398d63fd1e8d..fb728570debe6432d5f991595cb35e9e7af8b740 100644
--- a/drivers/iio/adc/ad7380.c
+++ b/drivers/iio/adc/ad7380.c
@@ -89,6 +89,7 @@ struct ad7380_chip_info {
 	bool has_mux;
 	const char * const *supplies;
 	unsigned int num_supplies;
+	bool external_ref_only;
 	const char * const *vcm_supplies;
 	unsigned int num_vcm_supplies;
 	const unsigned long *available_scan_masks;
@@ -431,6 +432,7 @@ static const struct ad7380_chip_info ad7380_4_chip_info = {
 	.num_simult_channels = 4,
 	.supplies = ad7380_supplies,
 	.num_supplies = ARRAY_SIZE(ad7380_supplies),
+	.external_ref_only = true,
 	.available_scan_masks = ad7380_4_channel_scan_masks,
 	.timing_specs = &ad7380_4_timing,
 };
@@ -1047,17 +1049,31 @@ static int ad7380_probe(struct spi_device *spi)
 				     "Failed to enable power supplies\n");
 	fsleep(T_POWERUP_US);
 
-	/*
-	 * If there is no REFIO supply, then it means that we are using
-	 * the internal 2.5V reference, otherwise REFIO is reference voltage.
-	 */
-	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "refio");
-	if (ret < 0 && ret != -ENODEV)
-		return dev_err_probe(&spi->dev, ret,
-				     "Failed to get refio regulator\n");
+	if (st->chip_info->external_ref_only) {
+		ret = devm_regulator_get_enable_read_voltage(&spi->dev,
+							     "refin");
+		if (ret < 0)
+			return dev_err_probe(&spi->dev, ret,
+					     "Failed to get refin regulator\n");
+
+		st->vref_mv = ret / 1000;
 
-	external_ref_en = ret != -ENODEV;
-	st->vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV;
+		/* these chips don't have a register bit for this */
+		external_ref_en = false;
+	} else {
+		/*
+		 * If there is no REFIO supply, then it means that we are using
+		 * the internal reference, otherwise REFIO is reference voltage.
+		 */
+		ret = devm_regulator_get_enable_read_voltage(&spi->dev,
+							     "refio");
+		if (ret < 0 && ret != -ENODEV)
+			return dev_err_probe(&spi->dev, ret,
+					     "Failed to get refio regulator\n");
+
+		external_ref_en = ret != -ENODEV;
+		st->vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV;
+	}
 
 	if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv))
 		return dev_err_probe(&spi->dev, -EINVAL,

-- 
2.47.0


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

* [PATCH v3 5/5] docs: iio: ad7380: fix supply for ad7380-4
  2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
                   ` (3 preceding siblings ...)
  2024-10-22 13:22 ` [PATCH v3 4/5] iio: adc: ad7380: fix supplies for ad7380-4 Julien Stephan
@ 2024-10-22 13:22 ` Julien Stephan
  2024-10-22 20:02 ` [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Jonathan Cameron
  5 siblings, 0 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-22 13:22 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Jonathan Cameron, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Liam Girdwood, Mark Brown, Jonathan Corbet
  Cc: linux-iio, devicetree, linux-kernel, Conor Dooley,
	Jonathan Cameron, linux-doc, Julien Stephan

ad7380-4 is the only device from ad738x family that doesn't have an
internal reference. Moreover it's external reference is called REFIN in
the datasheet while all other use REFIO as an optional external
reference. Update documentation to highlight this.

Fixes: 3e82dfc82f38 ("docs: iio: new docs for ad7380 driver")
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Julien Stephan <jstephan@baylibre.com>
---
 Documentation/iio/ad7380.rst | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/iio/ad7380.rst b/Documentation/iio/ad7380.rst
index 9c784c1e652e9afc116fd206a6cdb70fa6e2adf0..6f70b49b9ef27c1ac32acaefecd1146e5c8bd6cc 100644
--- a/Documentation/iio/ad7380.rst
+++ b/Documentation/iio/ad7380.rst
@@ -41,13 +41,22 @@ supports only 1 SDO line.
 Reference voltage
 -----------------
 
-2 possible reference voltage sources are supported:
+ad7380-4
+~~~~~~~~
+
+ad7380-4 supports only an external reference voltage (2.5V to 3.3V). It must be
+declared in the device tree as ``refin-supply``.
+
+All other devices from ad738x family
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+All other devices from ad738x support 2 possible reference voltage sources:
 
 - Internal reference (2.5V)
 - External reference (2.5V to 3.3V)
 
 The source is determined by the device tree. If ``refio-supply`` is present,
-then the external reference is used, else the internal reference is used.
+then it is used as external reference, else the internal reference is used.
 
 Oversampling and resolution boost
 ---------------------------------

-- 
2.47.0


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

* Re: [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues
  2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
                   ` (4 preceding siblings ...)
  2024-10-22 13:22 ` [PATCH v3 5/5] docs: iio: ad7380: fix supply " Julien Stephan
@ 2024-10-22 20:02 ` Jonathan Cameron
  2024-10-23  7:31   ` Julien Stephan
  5 siblings, 1 reply; 8+ messages in thread
From: Jonathan Cameron @ 2024-10-22 20:02 UTC (permalink / raw)
  To: Julien Stephan
  Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Liam Girdwood, Mark Brown, Jonathan Corbet, linux-iio, devicetree,
	linux-kernel, Conor Dooley, Jonathan Cameron, linux-doc

On Tue, 22 Oct 2024 15:22:35 +0200
Julien Stephan <jstephan@baylibre.com> wrote:

> Hello,
> 
> This series tries to fix several issues found on the ad7380 driver about
> supplies:
> 
> - vcc and vlogic are required, but are not retrieved and enabled in the
> probe function
> - ad7380-4 is the only device from the family that does not have internal
> reference and uses REFIN instead of REFIO for external reference.
> 
> driver, bindings, and doc are fixed accordingly

I considered a few responses to this series.

1) Asking you to pull the fixes to the front even though it would be painful.
2) Asking if the missing supplies patch should really be tagged as a fix.

In the end I opted for the variant that may just confuse the stable folk
the most and just took it as is + added stable to the 3 fixes.  Hopefully
it will be obvious they should just pick up all 5 (or maybe not the docs).

You are correct that the refactors make it easier to review the fixes
and this is a fairly new driver so I'm not that worried by pushing back the fix
as it's only to 6.11.

Applied to the fixes-togreg branch of iio.git.

Note the side effect of this is timing is tight for having this available
in the char-misc-next branch, so it may push back additional device
support until next cycle.

Thanks,

Jonathan

> 
> Signed-off-by: Julien Stephan <jstephan@baylibre.com>
> ---
> Changes in v3:
> - Use fsleep instead of msleep
> - Add all trailers from review
> - Link to v2: https://lore.kernel.org/r/20241021-ad7380-fix-supplies-v2-0-2ca551b3352a@baylibre.com
> 
> Changes in v2:
> - Fix kernel test robot warning about variable uninitialized when used [1]
> - drop commit removing supply description in bindings
> - after discussion on [2] we decided to add refin supply here, as it
>   will be needed in the futur
> 
> - Link to v1: https://lore.kernel.org/r/20241007-ad7380-fix-supplies-v1-0-badcf813c9b9@baylibre.com
> 
> [1] https://lore.kernel.org/oe-kbuild-all/202410081608.ZxEPPZ0u-lkp@intel.com/
> [2] https://lore.kernel.org/all/20241015-ad7380-add-adaq4380-4-support-v1-0-d2e1a95fb248@baylibre.com/:warning
> 
> ---
> Julien Stephan (5):
>       dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply
>       iio: adc: ad7380: use devm_regulator_get_enable_read_voltage()
>       iio: adc: ad7380: add missing supplies
>       iio: adc: ad7380: fix supplies for ad7380-4
>       docs: iio: ad7380: fix supply for ad7380-4
> 
>  .../devicetree/bindings/iio/adc/adi,ad7380.yaml    |  21 ++++
>  Documentation/iio/ad7380.rst                       |  13 +-
>  drivers/iio/adc/ad7380.c                           | 136 ++++++++++++---------
>  3 files changed, 110 insertions(+), 60 deletions(-)
> ---
> base-commit: 1a8b58362f6a6fef975032f7fceb7c4b80d20d60
> change-id: 20241004-ad7380-fix-supplies-3677365cf8aa
> 
> Best regards,


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

* Re: [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues
  2024-10-22 20:02 ` [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Jonathan Cameron
@ 2024-10-23  7:31   ` Julien Stephan
  0 siblings, 0 replies; 8+ messages in thread
From: Julien Stephan @ 2024-10-23  7:31 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, Nuno Sá,
	David Lechner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Liam Girdwood, Mark Brown, Jonathan Corbet, linux-iio, devicetree,
	linux-kernel, Conor Dooley, Jonathan Cameron, linux-doc

Le mar. 22 oct. 2024 à 22:02, Jonathan Cameron <jic23@kernel.org> a écrit :
>
> On Tue, 22 Oct 2024 15:22:35 +0200
> Julien Stephan <jstephan@baylibre.com> wrote:
>
> > Hello,
> >
> > This series tries to fix several issues found on the ad7380 driver about
> > supplies:
> >
> > - vcc and vlogic are required, but are not retrieved and enabled in the
> > probe function
> > - ad7380-4 is the only device from the family that does not have internal
> > reference and uses REFIN instead of REFIO for external reference.
> >
> > driver, bindings, and doc are fixed accordingly
>
> I considered a few responses to this series.
>
> 1) Asking you to pull the fixes to the front even though it would be painful.
> 2) Asking if the missing supplies patch should really be tagged as a fix.
>
> In the end I opted for the variant that may just confuse the stable folk
> the most and just took it as is + added stable to the 3 fixes.  Hopefully
> it will be obvious they should just pick up all 5 (or maybe not the docs).
>
> You are correct that the refactors make it easier to review the fixes
> and this is a fairly new driver so I'm not that worried by pushing back the fix
> as it's only to 6.11.
>
> Applied to the fixes-togreg branch of iio.git.
>
> Note the side effect of this is timing is tight for having this available
> in the char-misc-next branch, so it may push back additional device
> support until next cycle.
>
> Thanks,
>

Thank you!

Cheers
Julien

> Jonathan
>
> >
> > Signed-off-by: Julien Stephan <jstephan@baylibre.com>
> > ---
> > Changes in v3:
> > - Use fsleep instead of msleep
> > - Add all trailers from review
> > - Link to v2: https://lore.kernel.org/r/20241021-ad7380-fix-supplies-v2-0-2ca551b3352a@baylibre.com
> >
> > Changes in v2:
> > - Fix kernel test robot warning about variable uninitialized when used [1]
> > - drop commit removing supply description in bindings
> > - after discussion on [2] we decided to add refin supply here, as it
> >   will be needed in the futur
> >
> > - Link to v1: https://lore.kernel.org/r/20241007-ad7380-fix-supplies-v1-0-badcf813c9b9@baylibre.com
> >
> > [1] https://lore.kernel.org/oe-kbuild-all/202410081608.ZxEPPZ0u-lkp@intel.com/
> > [2] https://lore.kernel.org/all/20241015-ad7380-add-adaq4380-4-support-v1-0-d2e1a95fb248@baylibre.com/:warning
> >
> > ---
> > Julien Stephan (5):
> >       dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply
> >       iio: adc: ad7380: use devm_regulator_get_enable_read_voltage()
> >       iio: adc: ad7380: add missing supplies
> >       iio: adc: ad7380: fix supplies for ad7380-4
> >       docs: iio: ad7380: fix supply for ad7380-4
> >
> >  .../devicetree/bindings/iio/adc/adi,ad7380.yaml    |  21 ++++
> >  Documentation/iio/ad7380.rst                       |  13 +-
> >  drivers/iio/adc/ad7380.c                           | 136 ++++++++++++---------
> >  3 files changed, 110 insertions(+), 60 deletions(-)
> > ---
> > base-commit: 1a8b58362f6a6fef975032f7fceb7c4b80d20d60
> > change-id: 20241004-ad7380-fix-supplies-3677365cf8aa
> >
> > Best regards,
>

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

end of thread, other threads:[~2024-10-23  7:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 13:22 [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Julien Stephan
2024-10-22 13:22 ` [PATCH v3 1/5] dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply Julien Stephan
2024-10-22 13:22 ` [PATCH v3 2/5] iio: adc: ad7380: use devm_regulator_get_enable_read_voltage() Julien Stephan
2024-10-22 13:22 ` [PATCH v3 3/5] iio: adc: ad7380: add missing supplies Julien Stephan
2024-10-22 13:22 ` [PATCH v3 4/5] iio: adc: ad7380: fix supplies for ad7380-4 Julien Stephan
2024-10-22 13:22 ` [PATCH v3 5/5] docs: iio: ad7380: fix supply " Julien Stephan
2024-10-22 20:02 ` [PATCH v3 0/5] iio: adc: ad7380: fix several supplies issues Jonathan Cameron
2024-10-23  7:31   ` Julien Stephan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox