[alsa-devel] [PATCH] SoC: sta32x: use devm_gpiod_get_optional for optional reset gpio

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Tue May 19 08:54:27 CEST 2015


Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions)
which appeared in v3.17-rc1, the gpiod_get* functions take an additional
parameter that allows to specify direction and initial value for output.

Also there is a variant to find optional gpios that returns NULL if
there is no gpio instead of -ENOENT.

Make use of both features to simplify the driver.

This changes behaviour if gpiod_get returns -ENOSYS which is the case if
CONFIG_GPIOLIB is not enabled. This is a good change because without
GPIOLIB there is no way to determine if the reset gpio is specified in
the device tree. And if it is it must be handled, so erroring out is the
right thing to do.

Furthermore this is one caller less that stops us making the flags
argument to gpiod_get*() mandatory.

Fixes: b66a29808e1f ("ASoC: sta32x: make sta32x a gpio consumer for the reset GPIO")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
 sound/soc/codecs/sta32x.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 007a0e3bc273..0111baf9a5d4 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -1096,16 +1096,10 @@ static int sta32x_i2c_probe(struct i2c_client *i2c,
 #endif
 
 	/* GPIOs */
-	sta32x->gpiod_nreset = devm_gpiod_get(dev, "reset");
-	if (IS_ERR(sta32x->gpiod_nreset)) {
-		ret = PTR_ERR(sta32x->gpiod_nreset);
-		if (ret != -ENOENT && ret != -ENOSYS)
-			return ret;
-
-		sta32x->gpiod_nreset = NULL;
-	} else {
-		gpiod_direction_output(sta32x->gpiod_nreset, 0);
-	}
+	sta32x->gpiod_nreset = devm_gpiod_get_optional(dev, "reset",
+						       GPIOD_OUT_LOW);
+	if (IS_ERR(sta32x->gpiod_nreset))
+		return PTR_ERR(sta32x->gpiod_nreset);
 
 	/* regulators */
 	for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++)
-- 
2.1.4



More information about the Alsa-devel mailing list