Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: codec: ak5386: Convert to GPIO descriptors

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

With legacy of_gpio API, the driver set GPIO value 1 to power up
AK5386, and set value 0 to power down.
Per datasheet for PDN(reset_gpio in the driver):
Power Down & Reset Mode Pin
“H”: Power up, “L”: Power down & Reset
The AK5386 must be reset once upon power-up.

There is no in-tree DTS using this codec, and the bindings does not
specify polarity. Per driver and datasheet, the GPIO polarity should be
active-high which is to power up the codec. So using GPIOD_OUT_LOW
when get the GPIO descriptor matches GPIOF_OUT_INIT_LOW when using
of_gpio API.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://patch.msgid.link/20250406010532.1212894-1-peng.fan@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Peng Fan and committed by
Mark Brown
82d8d336 ea61f39b

+13 -15
+13 -15
sound/soc/codecs/ak5386.c
··· 6 6 * (c) 2013 Daniel Mack <zonque@gmail.com> 7 7 */ 8 8 9 + #include <linux/device.h> 10 + #include <linux/dev_printk.h> 11 + #include <linux/err.h> 12 + #include <linux/gpio/consumer.h> 9 13 #include <linux/module.h> 10 - #include <linux/slab.h> 11 - #include <linux/of.h> 12 - #include <linux/of_gpio.h> 13 14 #include <linux/regulator/consumer.h> 15 + #include <linux/slab.h> 14 16 #include <sound/soc.h> 15 17 #include <sound/pcm.h> 16 18 #include <sound/initval.h> ··· 22 20 }; 23 21 24 22 struct ak5386_priv { 25 - int reset_gpio; 23 + struct gpio_desc *reset_gpio; 26 24 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; 27 25 }; 28 26 ··· 112 110 * the AK5386 in power-down mode (PDN pin = “L”). 113 111 */ 114 112 115 - if (gpio_is_valid(priv->reset_gpio)) 116 - gpio_set_value(priv->reset_gpio, 1); 113 + gpiod_set_value(priv->reset_gpio, 1); 117 114 118 115 return 0; 119 116 } ··· 123 122 struct snd_soc_component *component = dai->component; 124 123 struct ak5386_priv *priv = snd_soc_component_get_drvdata(component); 125 124 126 - if (gpio_is_valid(priv->reset_gpio)) 127 - gpio_set_value(priv->reset_gpio, 0); 125 + gpiod_set_value(priv->reset_gpio, 0); 128 126 129 127 return 0; 130 128 } ··· 177 177 if (ret < 0) 178 178 return ret; 179 179 180 - priv->reset_gpio = of_get_named_gpio(dev->of_node, 181 - "reset-gpio", 0); 180 + priv->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 181 + if (IS_ERR(priv->reset_gpio)) 182 + return dev_err_probe(dev, PTR_ERR(priv->reset_gpio), 183 + "Failed to get AK5386 reset GPIO\n"); 182 184 183 - if (gpio_is_valid(priv->reset_gpio)) 184 - if (devm_gpio_request_one(dev, priv->reset_gpio, 185 - GPIOF_OUT_INIT_LOW, 186 - "AK5386 Reset")) 187 - priv->reset_gpio = -EINVAL; 185 + gpiod_set_consumer_name(priv->reset_gpio, "AK5386 Reset"); 188 186 189 187 return devm_snd_soc_register_component(dev, &soc_component_ak5386, 190 188 &ak5386_dai, 1);