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

ASoC: codec: tpa6130a2: 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 with default
polarity GPIOD_OUT_LOW, set consumer name.
- Use gpiod_set_value to configure output value.

Checking the DTS polarity, all users are using GPIOD_ACTIVE_HIGH.
so all should work as expected with this patch.

Cc: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://patch.msgid.link/20250414-asoc-tpa6130a2-v1-3-5f4052e656a0@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Peng Fan and committed by
Mark Brown
f198b6b2 63a9362c

+11 -21
+11 -21
sound/soc/codecs/tpa6130a2.c
··· 9 9 10 10 #include <linux/device.h> 11 11 #include <linux/errno.h> 12 - #include <linux/gpio.h> 12 + #include <linux/gpio/consumer.h> 13 13 #include <linux/i2c.h> 14 14 #include <linux/module.h> 15 15 #include <linux/of.h> 16 - #include <linux/of_gpio.h> 17 16 #include <linux/regmap.h> 18 17 #include <linux/regulator/consumer.h> 19 18 #include <linux/slab.h> ··· 31 32 struct device *dev; 32 33 struct regmap *regmap; 33 34 struct regulator *supply; 34 - int power_gpio; 35 + struct gpio_desc *power_gpio; 35 36 enum tpa_model id; 36 37 }; 37 38 ··· 47 48 return ret; 48 49 } 49 50 /* Power on */ 50 - if (data->power_gpio >= 0) 51 - gpio_set_value(data->power_gpio, 1); 51 + gpiod_set_value(data->power_gpio, 1); 52 52 53 53 /* Sync registers */ 54 54 regcache_cache_only(data->regmap, false); ··· 56 58 dev_err(data->dev, 57 59 "Failed to sync registers: %d\n", ret); 58 60 regcache_cache_only(data->regmap, true); 59 - if (data->power_gpio >= 0) 60 - gpio_set_value(data->power_gpio, 0); 61 + gpiod_set_value(data->power_gpio, 0); 61 62 ret2 = regulator_disable(data->supply); 62 63 if (ret2 != 0) 63 64 dev_err(data->dev, ··· 72 75 regcache_cache_only(data->regmap, true); 73 76 74 77 /* Power off */ 75 - if (data->power_gpio >= 0) 76 - gpio_set_value(data->power_gpio, 0); 78 + gpiod_set_value(data->power_gpio, 0); 77 79 78 80 ret = regulator_disable(data->supply); 79 81 if (ret != 0) { ··· 226 230 return PTR_ERR(data->regmap); 227 231 228 232 if (np) { 229 - data->power_gpio = of_get_named_gpio(np, "power-gpio", 0); 233 + data->power_gpio = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW); 234 + if (IS_ERR(data->power_gpio)) { 235 + return dev_err_probe(dev, PTR_ERR(data->power_gpio), 236 + "Failed to request power GPIO\n"); 237 + } 238 + gpiod_set_consumer_name(data->power_gpio, "tpa6130a2 enable"); 230 239 } else { 231 240 dev_err(dev, "Platform data not set\n"); 232 241 dump_stack(); ··· 241 240 i2c_set_clientdata(client, data); 242 241 243 242 data->id = (uintptr_t)i2c_get_match_data(client); 244 - 245 - if (data->power_gpio >= 0) { 246 - ret = devm_gpio_request(dev, data->power_gpio, 247 - "tpa6130a2 enable"); 248 - if (ret < 0) { 249 - dev_err(dev, "Failed to request power GPIO (%d)\n", 250 - data->power_gpio); 251 - return ret; 252 - } 253 - gpio_direction_output(data->power_gpio, 0); 254 - } 255 243 256 244 switch (data->id) { 257 245 default: