Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH v2] staging: iio: adc: ad7816: Use devm_gpiod_get_optional() for busy GPIO
@ 2026-06-03 12:33 Taha Narimani
  2026-06-03  9:13 ` Joshua Crofts
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Taha Narimani @ 2026-06-03 12:33 UTC (permalink / raw)
  To: jic23, lars, Michael.Hennerich, gregkh
  Cc: dlechner, nuno.sa, andy, linux-iio, linux-staging, linux-kernel,
	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, and remove
the redundant conditional chip-ID check since the optional API handles
missing descriptors gracefully.

Signed-off-by: Taha Narimani <tahanarimani3443@gmail.com>
---
Changes in v2:
  - Fixed trailing whitespace and missing newline at the end of the file.
  - Converted the file format to Unix (LF) to remove carriage returns.
  - Removed the explicit chip-ID check around the busy pin logic.
  - Improved the commit message to provide clear architectural justification.

 drivers/staging/iio/adc/ad7816.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 0eac484..039b34d 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -84,7 +84,7 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
 		gpiod_set_value(chip->convert_pin, 1);
 	}
 
-	if (chip->id == ID_AD7817) {
+	if (chip->busy_pin) {
 		while (gpiod_get_value(chip->busy_pin))
 			cpu_relax();
 	}
@@ -380,15 +380,14 @@ static int ad7816_probe(struct spi_device *spi_dev)
 			ret);
 		return ret;
 	}
-	if (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(&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;
 	}
 
 	indio_dev->name = spi_get_device_id(spi_dev)->name;
-- 
2.53.0


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

end of thread, other threads:[~2026-06-03 10:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 12:33 [PATCH v2] staging: iio: adc: ad7816: Use devm_gpiod_get_optional() for busy GPIO Taha Narimani
2026-06-03  9:13 ` Joshua Crofts
2026-06-03  9:27   ` Andy Shevchenko
2026-06-03  9:26 ` Andy Shevchenko
2026-06-03 10:20   ` Dan Carpenter
2026-06-03 10:37     ` Andy Shevchenko
2026-06-03 10:54       ` Dan Carpenter
2026-06-03 10:52 ` Jonathan Cameron

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