[PATCH 2/3] ASoC: codec: wcd938x: Convert to GPIO descriptors

Peng Fan (OSS) posted 3 patches 10 months, 3 weeks ago
There is a newer version of this series
[PATCH 2/3] ASoC: codec: wcd938x: Convert to GPIO descriptors
Posted by Peng Fan (OSS) 10 months, 3 weeks ago
From: Peng Fan <peng.fan@nxp.com>

of_gpio.h is deprecated, update the driver to use GPIO descriptors.
 - Use dev_gpiod_get to get GPIO descriptor.
 - Use gpiod_set_value to configure output value.

With legacy of_gpio API, the driver set gpio value 0 to assert reset,
and 1 to deassert reset. And the reset-gpios use GPIO_ACTIVE_LOW flag in
DTS, so set GPIOD_ASIS when get GPIO descriptors, and set value 1 means
output low, set value 0 means output high with gpiod API.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 sound/soc/codecs/wcd938x.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index 1ae498c323912ed799dcc033e7777936d90c9284..c70da29406f36883e4926eca40ab5ba5df02c383 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -11,7 +11,6 @@
 #include <linux/pm_runtime.h>
 #include <linux/component.h>
 #include <sound/tlv.h>
-#include <linux/of_gpio.h>
 #include <linux/of.h>
 #include <sound/jack.h>
 #include <sound/pcm.h>
@@ -171,7 +170,7 @@ struct wcd938x_priv {
 	int flyback_cur_det_disable;
 	int ear_rx_path;
 	int variant;
-	int reset_gpio;
+	struct gpio_desc *reset_gpio;
 	struct gpio_desc *us_euro_gpio;
 	u32 micb1_mv;
 	u32 micb2_mv;
@@ -3251,9 +3250,9 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
 	struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg;
 	int ret;
 
-	wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
-	if (wcd938x->reset_gpio < 0)
-		return dev_err_probe(dev, wcd938x->reset_gpio,
+	wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
+	if (IS_ERR(wcd938x->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(wcd938x->reset_gpio),
 				     "Failed to get reset gpio\n");
 
 	wcd938x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro",
@@ -3297,10 +3296,10 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
 
 static int wcd938x_reset(struct wcd938x_priv *wcd938x)
 {
-	gpio_direction_output(wcd938x->reset_gpio, 0);
+	gpiod_set_value(wcd938x->reset_gpio, 1);
 	/* 20us sleep required after pulling the reset gpio to LOW */
 	usleep_range(20, 30);
-	gpio_set_value(wcd938x->reset_gpio, 1);
+	gpiod_set_value(wcd938x->reset_gpio, 0);
 	/* 20us sleep required after pulling the reset gpio to HIGH */
 	usleep_range(20, 30);
 

-- 
2.37.1
Re: [PATCH 2/3] ASoC: codec: wcd938x: Convert to GPIO descriptors
Posted by Linus Walleij 10 months, 3 weeks ago
On Mon, Mar 24, 2025 at 3:28 AM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote:

> From: Peng Fan <peng.fan@nxp.com>
>
> of_gpio.h is deprecated, update the driver to use GPIO descriptors.
>  - Use dev_gpiod_get to get GPIO descriptor.
>  - Use gpiod_set_value to configure output value.
>
> With legacy of_gpio API, the driver set gpio value 0 to assert reset,
> and 1 to deassert reset. And the reset-gpios use GPIO_ACTIVE_LOW flag in
> DTS, so set GPIOD_ASIS when get GPIO descriptors, and set value 1 means
> output low, set value 0 means output high with gpiod API.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Re: [PATCH 2/3] ASoC: codec: wcd938x: Convert to GPIO descriptors
Posted by Steev Klimaszewski 10 months, 3 weeks ago
Hi Peng Fan,

On Sun, Mar 23, 2025 at 9:28 PM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote:
>
> From: Peng Fan <peng.fan@nxp.com>
>
> of_gpio.h is deprecated, update the driver to use GPIO descriptors.
>  - Use dev_gpiod_get to get GPIO descriptor.
>  - Use gpiod_set_value to configure output value.
>
> With legacy of_gpio API, the driver set gpio value 0 to assert reset,
> and 1 to deassert reset. And the reset-gpios use GPIO_ACTIVE_LOW flag in
> DTS, so set GPIOD_ASIS when get GPIO descriptors, and set value 1 means
> output low, set value 0 means output high with gpiod API.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  sound/soc/codecs/wcd938x.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
> index 1ae498c323912ed799dcc033e7777936d90c9284..c70da29406f36883e4926eca40ab5ba5df02c383 100644
> --- a/sound/soc/codecs/wcd938x.c
> +++ b/sound/soc/codecs/wcd938x.c
> @@ -11,7 +11,6 @@
>  #include <linux/pm_runtime.h>
>  #include <linux/component.h>
>  #include <sound/tlv.h>
> -#include <linux/of_gpio.h>
>  #include <linux/of.h>
>  #include <sound/jack.h>
>  #include <sound/pcm.h>
> @@ -171,7 +170,7 @@ struct wcd938x_priv {
>         int flyback_cur_det_disable;
>         int ear_rx_path;
>         int variant;
> -       int reset_gpio;
> +       struct gpio_desc *reset_gpio;
>         struct gpio_desc *us_euro_gpio;
>         u32 micb1_mv;
>         u32 micb2_mv;
> @@ -3251,9 +3250,9 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
>         struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg;
>         int ret;
>
> -       wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
> -       if (wcd938x->reset_gpio < 0)
> -               return dev_err_probe(dev, wcd938x->reset_gpio,
> +       wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
> +       if (IS_ERR(wcd938x->reset_gpio))
> +               return dev_err_probe(dev, PTR_ERR(wcd938x->reset_gpio),
>                                      "Failed to get reset gpio\n");
>
>         wcd938x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro",
> @@ -3297,10 +3296,10 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
>
>  static int wcd938x_reset(struct wcd938x_priv *wcd938x)
>  {
> -       gpio_direction_output(wcd938x->reset_gpio, 0);
> +       gpiod_set_value(wcd938x->reset_gpio, 1);
>         /* 20us sleep required after pulling the reset gpio to LOW */
>         usleep_range(20, 30);
> -       gpio_set_value(wcd938x->reset_gpio, 1);
> +       gpiod_set_value(wcd938x->reset_gpio, 0);
>         /* 20us sleep required after pulling the reset gpio to HIGH */
>         usleep_range(20, 30);
>
>
> --
> 2.37.1
>
>

With this patchset applied, the wcd938x codec used in the Thinkpad
X13s stops working:

wcd938x_codec audio-codec: soundwire device init timeout
wcd938x_codec audio-codec: ASoC: error at snd_soc_component_probe on
audio-codec: -110
snd-sc8280xp sound: ASoC: failed to instantiate card -110
snd-sc8280xp sound: probe with driver snd-sc8280xp failed with error -110

-- steev
Re: [PATCH 2/3] ASoC: codec: wcd938x: Convert to GPIO descriptors
Posted by Johan Hovold 10 months, 3 weeks ago
On Sun, Mar 23, 2025 at 10:40:51PM -0500, Steev Klimaszewski wrote:
> On Sun, Mar 23, 2025 at 9:28 PM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote:
> >
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > of_gpio.h is deprecated, update the driver to use GPIO descriptors.
> >  - Use dev_gpiod_get to get GPIO descriptor.
> >  - Use gpiod_set_value to configure output value.
> >
> > With legacy of_gpio API, the driver set gpio value 0 to assert reset,
> > and 1 to deassert reset. And the reset-gpios use GPIO_ACTIVE_LOW flag in
> > DTS, so set GPIOD_ASIS when get GPIO descriptors, and set value 1 means
> > output low, set value 0 means output high with gpiod API.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>

> > @@ -3251,9 +3250,9 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
> >         struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg;
> >         int ret;
> >
> > -       wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
> > -       if (wcd938x->reset_gpio < 0)
> > -               return dev_err_probe(dev, wcd938x->reset_gpio,
> > +       wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
> > +       if (IS_ERR(wcd938x->reset_gpio))
> > +               return dev_err_probe(dev, PTR_ERR(wcd938x->reset_gpio),
> >                                      "Failed to get reset gpio\n");
> >
> >         wcd938x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro",
> > @@ -3297,10 +3296,10 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device
> >
> >  static int wcd938x_reset(struct wcd938x_priv *wcd938x)
> >  {
> > -       gpio_direction_output(wcd938x->reset_gpio, 0);
> > +       gpiod_set_value(wcd938x->reset_gpio, 1);

This may be what is causing the regression; the driver no longer
configures the reset line as an output. From the docs:

	* GPIOD_ASIS or 0 to not initialize the GPIO at all. The
	  direction must be set later with one of the dedicated
	  functions.

> >         /* 20us sleep required after pulling the reset gpio to LOW */
> >         usleep_range(20, 30);
> > -       gpio_set_value(wcd938x->reset_gpio, 1);
> > +       gpiod_set_value(wcd938x->reset_gpio, 0);
> >         /* 20us sleep required after pulling the reset gpio to HIGH */
> >         usleep_range(20, 30);

> With this patchset applied, the wcd938x codec used in the Thinkpad
> X13s stops working:
> 
> wcd938x_codec audio-codec: soundwire device init timeout
> wcd938x_codec audio-codec: ASoC: error at snd_soc_component_probe on
> audio-codec: -110
> snd-sc8280xp sound: ASoC: failed to instantiate card -110
> snd-sc8280xp sound: probe with driver snd-sc8280xp failed with error -110

Johan