]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ASoC: codec: tpa6130a2: Convert to GPIO descriptors
authorPeng Fan <peng.fan@nxp.com>
Mon, 14 Apr 2025 08:34:25 +0000 (16:34 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 24 Apr 2025 11:53:05 +0000 (12:53 +0100)
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>
sound/soc/codecs/tpa6130a2.c

index 43cd957eaf321e8cff784e5d781e8e99d2c3ae89..38cc000891eacafb257a959b44f157413faee5fd 100644 (file)
@@ -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",