diff mbox series

[4/4] ASoC: codecs: adau1373: add powerdown gpio

Message ID 20241021-adau1373-shutdown-v1-4-bec4ff9dfa16@analog.com (mailing list archive)
State New
Headers show
Series ASoC: codecs: adau1373: drop platform data | expand

Commit Message

Nuno Sa Oct. 21, 2024, 1:46 p.m. UTC
If the powerdown GPIO is specified, we use it for reset. Otherwise,
fallback to a software reset.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 sound/soc/codecs/adau1373.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

Mark Brown Oct. 21, 2024, 3:30 p.m. UTC | #1
On Mon, Oct 21, 2024 at 03:46:48PM +0200, Nuno Sa wrote:
> If the powerdown GPIO is specified, we use it for reset. Otherwise,
> fallback to a software reset.

Ideally we'd also put the device into reset when we unload, but that's
not essential.
Nuno Sá Oct. 22, 2024, 6:39 a.m. UTC | #2
On Mon, 2024-10-21 at 16:30 +0100, Mark Brown wrote:
> On Mon, Oct 21, 2024 at 03:46:48PM +0200, Nuno Sa wrote:
> > If the powerdown GPIO is specified, we use it for reset. Otherwise,
> > fallback to a software reset.
> 
> Ideally we'd also put the device into reset when we unload, but that's
> not essential.

Alright... I can do a v2 with that. Will just wait for some more feedback on the
rest.

- Nuno Sá
diff mbox series

Patch

diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
index 9568ff933e12ba939134a696c8d9c16a2ef04795..d5566b4c444f3a8be07cc17fbdbb5fee1b6442e9 100644
--- a/sound/soc/codecs/adau1373.c
+++ b/sound/soc/codecs/adau1373.c
@@ -8,6 +8,7 @@ 
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/gpio/consumer.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/property.h>
@@ -1547,6 +1548,7 @@  static int adau1373_parse_fw(struct device *dev, struct adau1373 *adau1373)
 static int adau1373_i2c_probe(struct i2c_client *client)
 {
 	struct adau1373 *adau1373;
+	struct gpio_desc *gpiod;
 	int ret;
 
 	adau1373 = devm_kzalloc(&client->dev, sizeof(*adau1373), GFP_KERNEL);
@@ -1558,7 +1560,21 @@  static int adau1373_i2c_probe(struct i2c_client *client)
 	if (IS_ERR(adau1373->regmap))
 		return PTR_ERR(adau1373->regmap);
 
-	regmap_write(adau1373->regmap, ADAU1373_SOFT_RESET, 0x00);
+	/*
+	 * If the powerdown GPIO is specified, we use it for reset. Otherwise
+	 * a software reset is done.
+	 */
+	gpiod = devm_gpiod_get_optional(&client->dev, "powerdown",
+					GPIOD_OUT_HIGH);
+	if (IS_ERR(gpiod))
+		return PTR_ERR(gpiod);
+
+	if (gpiod) {
+		gpiod_set_value_cansleep(gpiod, 0);
+		fsleep(10);
+	} else {
+		regmap_write(adau1373->regmap, ADAU1373_SOFT_RESET, 0x00);
+	}
 
 	dev_set_drvdata(&client->dev, adau1373);