Skip to content

Commit f198b6b

Browse files
MrVanbroonie
authored andcommitted
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 <[email protected]> Signed-off-by: Peng Fan <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 63a9362 commit f198b6b

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

sound/soc/codecs/tpa6130a2.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
#include <linux/device.h>
1111
#include <linux/errno.h>
12-
#include <linux/gpio.h>
12+
#include <linux/gpio/consumer.h>
1313
#include <linux/i2c.h>
1414
#include <linux/module.h>
1515
#include <linux/of.h>
16-
#include <linux/of_gpio.h>
1716
#include <linux/regmap.h>
1817
#include <linux/regulator/consumer.h>
1918
#include <linux/slab.h>
@@ -32,7 +31,7 @@ struct tpa6130a2_data {
3231
struct device *dev;
3332
struct regmap *regmap;
3433
struct regulator *supply;
35-
int power_gpio;
34+
struct gpio_desc *power_gpio;
3635
enum tpa_model id;
3736
};
3837

@@ -48,8 +47,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
4847
return ret;
4948
}
5049
/* Power on */
51-
if (data->power_gpio >= 0)
52-
gpio_set_value(data->power_gpio, 1);
50+
gpiod_set_value(data->power_gpio, 1);
5351

5452
/* Sync registers */
5553
regcache_cache_only(data->regmap, false);
@@ -58,8 +56,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
5856
dev_err(data->dev,
5957
"Failed to sync registers: %d\n", ret);
6058
regcache_cache_only(data->regmap, true);
61-
if (data->power_gpio >= 0)
62-
gpio_set_value(data->power_gpio, 0);
59+
gpiod_set_value(data->power_gpio, 0);
6360
ret2 = regulator_disable(data->supply);
6461
if (ret2 != 0)
6562
dev_err(data->dev,
@@ -75,8 +72,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
7572
regcache_cache_only(data->regmap, true);
7673

7774
/* Power off */
78-
if (data->power_gpio >= 0)
79-
gpio_set_value(data->power_gpio, 0);
75+
gpiod_set_value(data->power_gpio, 0);
8076

8177
ret = regulator_disable(data->supply);
8278
if (ret != 0) {
@@ -230,7 +226,12 @@ static int tpa6130a2_probe(struct i2c_client *client)
230226
return PTR_ERR(data->regmap);
231227

232228
if (np) {
233-
data->power_gpio = of_get_named_gpio(np, "power-gpio", 0);
229+
data->power_gpio = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
230+
if (IS_ERR(data->power_gpio)) {
231+
return dev_err_probe(dev, PTR_ERR(data->power_gpio),
232+
"Failed to request power GPIO\n");
233+
}
234+
gpiod_set_consumer_name(data->power_gpio, "tpa6130a2 enable");
234235
} else {
235236
dev_err(dev, "Platform data not set\n");
236237
dump_stack();
@@ -241,17 +242,6 @@ static int tpa6130a2_probe(struct i2c_client *client)
241242

242243
data->id = (uintptr_t)i2c_get_match_data(client);
243244

244-
if (data->power_gpio >= 0) {
245-
ret = devm_gpio_request(dev, data->power_gpio,
246-
"tpa6130a2 enable");
247-
if (ret < 0) {
248-
dev_err(dev, "Failed to request power GPIO (%d)\n",
249-
data->power_gpio);
250-
return ret;
251-
}
252-
gpio_direction_output(data->power_gpio, 0);
253-
}
254-
255245
switch (data->id) {
256246
default:
257247
dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",

0 commit comments

Comments
 (0)