]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ASoC: tas5086: Convert to GPIO descriptors
authorLinus Walleij <linus.walleij@linaro.org>
Mon, 1 Jul 2024 07:02:12 +0000 (09:02 +0200)
committerMark Brown <broonie@kernel.org>
Wed, 3 Jul 2024 20:28:36 +0000 (21:28 +0100)
Switch the driver to use GPIO descriptors.

Notice that we let the gpiolib handle line inversion for the
active low reset line (nreset !reset).

There are no upstream device trees using the tas5086 compatible
string, if there were, we would need to ascertain that they all
set the GPIO_ACTIVE_LOW flag on their GPIO lines.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://patch.msgid.link/20240701-asoc-tas-gpios-v1-1-d69ec5d79939@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/tas5086.c

index 6d45df3b9ba4922d6575dfa2c111062f85fa7cf6..4bc1fdd232bb78feb476d0c1178805be597def3e 100644 (file)
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
@@ -246,7 +245,7 @@ struct tas5086_private {
        /* Current sample rate for de-emphasis control */
        int             rate;
        /* GPIO driving Reset pin, if any */
-       int             gpio_nreset;
+       struct gpio_desc *reset;
        struct          regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
 };
 
@@ -462,11 +461,11 @@ static int tas5086_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
 
 static void tas5086_reset(struct tas5086_private *priv)
 {
-       if (gpio_is_valid(priv->gpio_nreset)) {
+       if (priv->reset) {
                /* Reset codec - minimum assertion time is 400ns */
-               gpio_direction_output(priv->gpio_nreset, 0);
+               gpiod_direction_output(priv->reset, 1);
                udelay(1);
-               gpio_set_value(priv->gpio_nreset, 1);
+               gpiod_set_value(priv->reset, 0);
 
                /* Codec needs ~15ms to wake up */
                msleep(15);
@@ -867,9 +866,9 @@ static void tas5086_remove(struct snd_soc_component *component)
 {
        struct tas5086_private *priv = snd_soc_component_get_drvdata(component);
 
-       if (gpio_is_valid(priv->gpio_nreset))
+       if (priv->reset)
                /* Set codec to the reset state */
-               gpio_set_value(priv->gpio_nreset, 0);
+               gpiod_set_value(priv->reset, 1);
 
        regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
 };
@@ -914,7 +913,6 @@ static int tas5086_i2c_probe(struct i2c_client *i2c)
 {
        struct tas5086_private *priv;
        struct device *dev = &i2c->dev;
-       int gpio_nreset = -EINVAL;
        int i, ret;
 
        priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -940,12 +938,11 @@ static int tas5086_i2c_probe(struct i2c_client *i2c)
 
        i2c_set_clientdata(i2c, priv);
 
-       gpio_nreset = of_get_named_gpio(dev->of_node, "reset-gpio", 0);
-       if (gpio_is_valid(gpio_nreset))
-               if (devm_gpio_request(dev, gpio_nreset, "TAS5086 Reset"))
-                       gpio_nreset = -EINVAL;
-
-       priv->gpio_nreset = gpio_nreset;
+       /* Request line asserted */
+       priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(priv->reset))
+               return PTR_ERR(priv->reset);
+       gpiod_set_consumer_name(priv->reset, "TAS5086 Reset");
 
        ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
        if (ret < 0) {