mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org
Subject: [PATCH 02/11] ASoC: max98373: switch to using gpiod API
Date: Tue, 15 Nov 2022 21:38:08 -0800	[thread overview]
Message-ID: <20221116053817.2929810-2-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20221116053817.2929810-1-dmitry.torokhov@gmail.com>

Switch the driver from legacy gpio API that is deprecated to the newer
gpiod API that respects line polarities described in ACPI/DT.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 sound/soc/codecs/max98373-i2c.c | 39 +++++++++++++++++++--------------
 sound/soc/codecs/max98373.c     | 18 ---------------
 sound/soc/codecs/max98373.h     |  1 -
 3 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/sound/soc/codecs/max98373-i2c.c b/sound/soc/codecs/max98373-i2c.c
index 3e04c7f0cce4..969cdca83bc1 100644
--- a/sound/soc/codecs/max98373-i2c.c
+++ b/sound/soc/codecs/max98373-i2c.c
@@ -3,12 +3,12 @@
 
 #include <linux/acpi.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
@@ -520,14 +520,13 @@ static int max98373_i2c_probe(struct i2c_client *i2c)
 	int ret = 0;
 	int reg = 0;
 	int i;
-	struct max98373_priv *max98373 = NULL;
+	struct max98373_priv *max98373;
+	struct gpio_desc *reset_gpio;
 
 	max98373 = devm_kzalloc(&i2c->dev, sizeof(*max98373), GFP_KERNEL);
+	if (!max98373)
+		return -ENOMEM;
 
-	if (!max98373) {
-		ret = -ENOMEM;
-		return ret;
-	}
 	i2c_set_clientdata(i2c, max98373);
 
 	/* update interleave mode info */
@@ -557,17 +556,23 @@ static int max98373_i2c_probe(struct i2c_client *i2c)
 	max98373_slot_config(&i2c->dev, max98373);
 
 	/* Power on device */
-	if (gpio_is_valid(max98373->reset_gpio)) {
-		ret = devm_gpio_request(&i2c->dev, max98373->reset_gpio,
-					"MAX98373_RESET");
-		if (ret) {
-			dev_err(&i2c->dev, "%s: Failed to request gpio %d\n",
-				__func__, max98373->reset_gpio);
-			return -EINVAL;
-		}
-		gpio_direction_output(max98373->reset_gpio, 0);
+	/* Acquire and assert reset line */
+	reset_gpio = devm_gpiod_get_optional(&i2c->dev, "maxim,reset",
+					     GPIOD_OUT_HIGH);
+	ret = PTR_ERR_OR_ZERO(reset_gpio);
+	if (ret) {
+		dev_err(&i2c->dev, "%s: Failed to request reset gpio: %d\n",
+			__func__, ret);
+		return ret;
+	}
+
+	gpiod_set_consumer_name(reset_gpio, "MAX98373_RESET");
+
+	if (reset_gpio) {
+		/* Keep line asserted to reset device */
 		msleep(50);
-		gpio_direction_output(max98373->reset_gpio, 1);
+		/* Deassert reset line */
+		gpiod_set_value_cansleep(reset_gpio, 0);
 		msleep(20);
 	}
 
diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c
index f90a6a7ba83b..401546c1084e 100644
--- a/sound/soc/codecs/max98373.c
+++ b/sound/soc/codecs/max98373.c
@@ -12,9 +12,6 @@
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
-#include <linux/gpio.h>
-#include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <sound/tlv.h>
 #include "max98373.h"
 
@@ -478,21 +475,6 @@ void max98373_slot_config(struct device *dev,
 		max98373->i_slot = value & 0xF;
 	else
 		max98373->i_slot = 1;
-	if (dev->of_node) {
-		max98373->reset_gpio = of_get_named_gpio(dev->of_node,
-						"maxim,reset-gpio", 0);
-		if (!gpio_is_valid(max98373->reset_gpio)) {
-			dev_err(dev, "Looking up %s property in node %s failed %d\n",
-				"maxim,reset-gpio", dev->of_node->full_name,
-				max98373->reset_gpio);
-		} else {
-			dev_dbg(dev, "maxim,reset-gpio=%d",
-				max98373->reset_gpio);
-		}
-	} else {
-		/* this makes reset_gpio as invalid */
-		max98373->reset_gpio = -1;
-	}
 
 	if (!device_property_read_u32(dev, "maxim,spkfb-slot-no", &value))
 		max98373->spkfb_slot = value & 0xF;
diff --git a/sound/soc/codecs/max98373.h b/sound/soc/codecs/max98373.h
index e1810b3b1620..7b259789e1be 100644
--- a/sound/soc/codecs/max98373.h
+++ b/sound/soc/codecs/max98373.h
@@ -213,7 +213,6 @@ struct max98373_cache {
 
 struct max98373_priv {
 	struct regmap *regmap;
-	int reset_gpio;
 	unsigned int v_slot;
 	unsigned int i_slot;
 	unsigned int spkfb_slot;
-- 
2.38.1.431.g37b22c650d-goog


  reply	other threads:[~2022-11-16  5:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16  5:38 [PATCH 01/11] ASoC: ak5386: " Dmitry Torokhov
2022-11-16  5:38 ` Dmitry Torokhov [this message]
2022-11-16  5:38 ` [PATCH 03/11] ASoC: tas5086: " Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 04/11] ASoC: tpa6130a2: remove support for platform data Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 05/11] ASoC: tpa6130a2: switch to using gpiod API Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 06/11] ASoC: tlv320aic32x4: remove support for platform data Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 07/11] ASoC: tlv320aic32x4: switch to using gpiod API Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 08/11] ASoC: dt-bindings: wcd9335: fix reset line polarity in example Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 09/11] ASoC: wcd9335: switch to using gpiod API Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 10/11] ASoC: dt-bindings: wcd938x: fix codec reset line polarity in example Dmitry Torokhov
2022-11-16  5:38 ` [PATCH 11/11] ASoC: wcd938x: switch to using gpiod API Dmitry Torokhov
2023-03-08 18:11   ` Krzysztof Kozlowski
2022-11-16 10:36 ` [PATCH 01/11] ASoC: ak5386: " Mark Brown
2022-11-16 19:07   ` Dmitry Torokhov
2022-11-17 11:34     ` Mark Brown
2022-11-18  6:31       ` Dmitry Torokhov
2022-11-18 13:12         ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221116053817.2929810-2-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®