Skip to contentSkip to conversation

ASoC: codec: wcd93xx: Convert to GPIO descriptors

PATCH In review Peng Fan (OSS) 5 participants 10 messages Mar 24, 2025 – Apr 8, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: codec: wcd93xx: Convert to GPIO descriptors

Steev,
I would appreciate if you have time to help test again. Hope V2 could work on your platform.

Linus,
Since v2 is only a minor change to use GPIOD_OUT_LOW to replace GPIOD_ASIS when devm_gpio_get, so I still keep you R-b. Appreciate for your quick action.

Johan,
Thanks for help look into V1. Appreciate if you have time to look into v2.

Sorry for this quick V2, there is no rush, but just wanna to avoid sending this out in coming merge window.

of_gpio.h is deprecated, so update driver to use gpiod API.

The current driver use value 0 to assert reset and 1 to deassert reset. The DTSes in tree that use the codec are using GPIO_ACTIVE_LOW. So it is safe to use devm_gpiod_get to get GPIO descriptors and use gpiod_set_value to configure output with value 1 means raw value 0, value 0 means raw value 1.

Note:
I not have devices to test, just my best pratice to do the convertion.

---
Changes in v2:
- Use GPIOD_OUT_LOW to replace GPIOD_ASIS to configure direction.
- Update commit log with "in-tree DTS files have the right polarity set up already so we can expect this to "just work"".
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Peng Fan (3):
ASoC: codec: wcd939x: Convert to GPIO descriptors
ASoC: codec: wcd938x: Convert to GPIO descriptors
ASoC: codec: wcd9335: Convert to GPIO descriptors

 sound/soc/codecs/wcd9335.c | 15 +++++++--------
 sound/soc/codecs/wcd938x.c | 13 ++++++-------
 sound/soc/codecs/wcd939x.c | 16 ++++++++--------
 3 files changed, 21 insertions(+), 23 deletions(-)

---
base-commit: 9388ec571cb1adba59d1cded2300eeb11827679c
change-id: 20250324-wcd-gpiod-782c4a0d8688

Best regards,

Signature · 1 line
Peng Fan <[email protected]>
#1 lore raw

PATCH v2 1/3 ASoC: codec: wcd939x: Convert to GPIO descriptors

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

The in-tree DTS files have the right polarity set up already so we can expect this to "just work".

---
 sound/soc/codecs/wcd939x.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/wcd939x.c +8 -8
index 0a87a79772da6c0ed3c7dd7d098e949b9cead2a4..837c86ceb1097254f4029087ce401c5a8645bf21 100644
@@ -15,7 +15,6 @@
 #include <linux/pm_runtime.h>
 #include <linux/component.h>
 #include <sound/tlv.h>
-#include <linux/of_gpio.h>
 #include <linux/of_graph.h>
 #include <linux/of.h>
 #include <sound/jack.h>
@@ -201,7 +200,7 @@ struct wcd939x_priv {
 	u32 hph_mode;
 	u32 tx_mode[TX_ADC_MAX];
 	int variant;
-	int reset_gpio;
+	struct gpio_desc *reset_gpio;
 	u32 micb1_mv;
 	u32 micb2_mv;
 	u32 micb3_mv;
@@ -3239,10 +3238,11 @@ static int wcd939x_populate_dt_data(struct wcd939x_priv *wcd939x, struct device
 #endif /* CONFIG_TYPEC */
 	int ret;
 
-	wcd939x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
-	if (wcd939x->reset_gpio < 0)
-		return dev_err_probe(dev, wcd939x->reset_gpio,
-				     "Failed to get reset gpio\n");
+	wcd939x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(wcd939x->reset_gpio)) {
+		ret = PTR_ERR(wcd939x->reset_gpio);
+		return dev_err_probe(dev, ret, "Failed to get reset gpio\n");
+	}
 
 	wcd939x->supplies[0].supply = "vdd-rxtx";
 	wcd939x->supplies[1].supply = "vdd-io";
@@ -3290,10 +3290,10 @@ static int wcd939x_populate_dt_data(struct wcd939x_priv *wcd939x, struct device
 
 static int wcd939x_reset(struct wcd939x_priv *wcd939x)
 {
-	gpio_direction_output(wcd939x->reset_gpio, 0);
+	gpiod_set_value(wcd939x->reset_gpio, 1);
 	/* 20us sleep required after pulling the reset gpio to LOW */
 	usleep_range(20, 30);
-	gpio_set_value(wcd939x->reset_gpio, 1);
+	gpiod_set_value(wcd939x->reset_gpio, 0);
 	/* 20us sleep required after pulling the reset gpio to HIGH */
 	usleep_range(20, 30);
 
Signature · 1 line
2.37.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] ASoC: codec: wcd939x: Convert to GPIO descriptors

Quoted 12 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

Quoted 6 lines

The in-tree DTS files have the right polarity set up already so we can expect this to "just work".

---

#3 lore raw

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

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

The in-tree DTS files have the right polarity set up already so we can expect this to "just work".

---
 sound/soc/codecs/wcd938x.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
sound/soc/codecs/wcd938x.c +6 -7
index 1ae498c323912ed799dcc033e7777936d90c9284..955a0d3a77d7cb45932faa0c7a6f5060232d33b4 100644
@@ -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_OUT_LOW);
+	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);
 
Signature · 1 line
2.37.1
Tested-by on v2 2/3
#4 lore raw

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

Hi Peng,

Quoted 70 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

The in-tree DTS files have the right polarity set up already so we can expect this to "just work".

---
 sound/soc/codecs/wcd938x.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
sound/soc/codecs/wcd938x.c +6 -8
index 1ae498c323912ed799dcc033e7777936d90c9284..955a0d3a77d7cb45932faa0c7a6f5060232d33b4 100644
@@ -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_OUT_LOW);
+       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);
 
 
--
Quoted 2 lines

2.37.1

I can verify that with v2 applied, I do still have working audio on the Thinkpad X13s. Apologies for not replying earlier, it was unfortunately my night time. For the record though, I do not use the firmware dtb files, but explicitly list the kernel that I am using and/or testing to be used on each boot.

Thanks!
-- steev

#5 lore raw

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

Quoted 3 lines

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

...

Quoted 8 lines
Quoted 1 line

I can verify that with v2 applied, I do still have working audio on the Thinkpad X13s. Apologies for not replying earlier, it was unfortunately my night time. For the record though, I do not use the firmware dtb files, but explicitly list the kernel that I am using and/or testing to be used on each boot.

Appreciate for helping test.

Thanks,
Peng.

Quoted 3 lines

Thanks!
-- steev

Reviewed-by on v2 2/3
#6 lore raw

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

In reply to Peng Fan (OSS)
Quoted 12 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

Quoted 6 lines

The in-tree DTS files have the right polarity set up already so we can expect this to "just work".

---

#7 lore raw

PATCH v2 3/3 ASoC: codec: wcd9335: Convert to GPIO descriptors

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

The in-tree DTS files have the right polarity set up already so we can expect this to "just work"

---
 sound/soc/codecs/wcd9335.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
sound/soc/codecs/wcd9335.c +7 -8
index 7cef43bb2a8800971604b0e1ac55aac26c5919bd..8ee4360aff9293178e338e3ef300c37f6f2ac809 100644
@@ -17,7 +17,7 @@
 #include <sound/soc.h>
 #include <sound/pcm_params.h>
 #include <sound/soc-dapm.h>
-#include <linux/of_gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
 #include <sound/tlv.h>
@@ -331,7 +331,7 @@ struct wcd9335_codec {
 	int comp_enabled[COMPANDER_MAX];
 
 	int intr1;
-	int reset_gpio;
+	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data supplies[WCD9335_MAX_SUPPLY];
 
 	unsigned int rx_port_value[WCD9335_RX_MAX];
@@ -4975,12 +4975,11 @@ static const struct regmap_irq_chip wcd9335_regmap_irq1_chip = {
 static int wcd9335_parse_dt(struct wcd9335_codec *wcd)
 {
 	struct device *dev = wcd->dev;
-	struct device_node *np = dev->of_node;
 	int ret;
 
-	wcd->reset_gpio = of_get_named_gpio(np,	"reset-gpios", 0);
-	if (wcd->reset_gpio < 0)
-		return dev_err_probe(dev, wcd->reset_gpio, "Reset GPIO missing from DT\n");
+	wcd->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(wcd->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(wcd->reset_gpio), "Reset GPIO missing from DT\n");
 
 	wcd->mclk = devm_clk_get(dev, "mclk");
 	if (IS_ERR(wcd->mclk))
@@ -5023,9 +5022,9 @@ static int wcd9335_power_on_reset(struct wcd9335_codec *wcd)
 	 */
 	usleep_range(600, 650);
 
-	gpio_direction_output(wcd->reset_gpio, 0);
+	gpiod_set_value(wcd->reset_gpio, 1);
 	msleep(20);
-	gpio_set_value(wcd->reset_gpio, 1);
+	gpiod_set_value(wcd->reset_gpio, 0);
 	msleep(20);
 
 	return 0;
Signature · 1 line
2.37.1
Reviewed-by on v2 3/3
#8 lore raw

Re: [PATCH v2 3/3] ASoC: codec: wcd9335: Convert to GPIO descriptors

Quoted 12 lines · Peng Fan (OSS)

From: Peng Fan <[email protected]>

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_OUT_LOW when get GPIO descriptors, and set value 1 means output low, set value 0 means output high with gpiod API.

Quoted 6 lines

The in-tree DTS files have the right polarity set up already so we can expect this to "just work"

---

maintainer
#9 lore raw
In reply to Peng Fan (OSS)
Quoted 10 lines · Peng Fan (OSS)

Steev,
I would appreciate if you have time to help test again. Hope V2 could work on your platform.

Linus,
Since v2 is only a minor change to use GPIOD_OUT_LOW to replace GPIOD_ASIS when devm_gpio_get, so I still keep you R-b. Appreciate for your quick action.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] ASoC: codec: wcd939x: Convert to GPIO descriptors

      commit: 4bba5d0e51647e06c83036b6c3f0ec65465adc68
[2/3] ASoC: codec: wcd938x: Convert to GPIO descriptors
      commit: c2d359b4acfbe847d3edcc25d3dc4e594daf9010
[3/3] ASoC: codec: wcd9335: Convert to GPIO descriptors
      commit: d5099bc1b56417733f4cccf10c61ee74dadd5562

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark