mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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>
This commit is contained in:
@@ -9,11 +9,10 @@
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/slab.h>
|
||||
@@ -32,7 +31,7 @@ struct tpa6130a2_data {
|
||||
struct device *dev;
|
||||
struct regmap *regmap;
|
||||
struct regulator *supply;
|
||||
int power_gpio;
|
||||
struct gpio_desc *power_gpio;
|
||||
enum tpa_model id;
|
||||
};
|
||||
|
||||
@@ -48,8 +47,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
|
||||
return ret;
|
||||
}
|
||||
/* Power on */
|
||||
if (data->power_gpio >= 0)
|
||||
gpio_set_value(data->power_gpio, 1);
|
||||
gpiod_set_value(data->power_gpio, 1);
|
||||
|
||||
/* Sync registers */
|
||||
regcache_cache_only(data->regmap, false);
|
||||
@@ -58,8 +56,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
|
||||
dev_err(data->dev,
|
||||
"Failed to sync registers: %d\n", ret);
|
||||
regcache_cache_only(data->regmap, true);
|
||||
if (data->power_gpio >= 0)
|
||||
gpio_set_value(data->power_gpio, 0);
|
||||
gpiod_set_value(data->power_gpio, 0);
|
||||
ret2 = regulator_disable(data->supply);
|
||||
if (ret2 != 0)
|
||||
dev_err(data->dev,
|
||||
@@ -75,8 +72,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
|
||||
regcache_cache_only(data->regmap, true);
|
||||
|
||||
/* Power off */
|
||||
if (data->power_gpio >= 0)
|
||||
gpio_set_value(data->power_gpio, 0);
|
||||
gpiod_set_value(data->power_gpio, 0);
|
||||
|
||||
ret = regulator_disable(data->supply);
|
||||
if (ret != 0) {
|
||||
@@ -230,7 +226,12 @@ static int tpa6130a2_probe(struct i2c_client *client)
|
||||
return PTR_ERR(data->regmap);
|
||||
|
||||
if (np) {
|
||||
data->power_gpio = of_get_named_gpio(np, "power-gpio", 0);
|
||||
data->power_gpio = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
|
||||
if (IS_ERR(data->power_gpio)) {
|
||||
return dev_err_probe(dev, PTR_ERR(data->power_gpio),
|
||||
"Failed to request power GPIO\n");
|
||||
}
|
||||
gpiod_set_consumer_name(data->power_gpio, "tpa6130a2 enable");
|
||||
} else {
|
||||
dev_err(dev, "Platform data not set\n");
|
||||
dump_stack();
|
||||
@@ -241,17 +242,6 @@ static int tpa6130a2_probe(struct i2c_client *client)
|
||||
|
||||
data->id = (uintptr_t)i2c_get_match_data(client);
|
||||
|
||||
if (data->power_gpio >= 0) {
|
||||
ret = devm_gpio_request(dev, data->power_gpio,
|
||||
"tpa6130a2 enable");
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Failed to request power GPIO (%d)\n",
|
||||
data->power_gpio);
|
||||
return ret;
|
||||
}
|
||||
gpio_direction_output(data->power_gpio, 0);
|
||||
}
|
||||
|
||||
switch (data->id) {
|
||||
default:
|
||||
dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
|
||||
|
||||
Reference in New Issue
Block a user