ASoC: max98373: Convert to use GPIO descriptors
authorLinus Walleij <linus.walleij@linaro.org>
Fri, 25 Aug 2023 08:12:13 +0000 (10:12 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 11 Sep 2023 00:19:03 +0000 (01:19 +0100)
Instead of relying on legacy interfaces, convert the driver to
use GPIO descriptors. This is a straight-forward conversion,
we support also sdw devices providing GPIO descriptor tables
if they so desire.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-3-b212292b2f08@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/max98373-i2c.c
sound/soc/codecs/max98373.c
sound/soc/codecs/max98373.h

index 0fa5ceca62a26555ae1ba533cb59477aa58aa371..e7ec7875c4a9a7633b1c3b03dda8cab2161aafa5 100644 (file)
@@ -3,12 +3,10 @@
 
 #include <linux/acpi.h>
 #include <linux/delay.h>
-#include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
@@ -560,21 +558,6 @@ static int max98373_i2c_probe(struct i2c_client *i2c)
        /* voltage/current slot & gpio configuration */
        max98373_slot_config(&i2c->dev, max98373);
 
-       /* Power on device */
-       if (gpio_is_valid(max98373->reset_gpio)) {
-               ret = devm_gpio_request(&i2c->dev, max98373->reset_gpio,
-                                       "MAX98373_RESET");
-               if (ret) {
-                       dev_err(&i2c->dev, "%s: Failed to request gpio %d\n",
-                               __func__, max98373->reset_gpio);
-                       return -EINVAL;
-               }
-               gpio_direction_output(max98373->reset_gpio, 0);
-               msleep(50);
-               gpio_direction_output(max98373->reset_gpio, 1);
-               msleep(20);
-       }
-
        /* Check Revision ID */
        ret = regmap_read(max98373->regmap,
                          MAX98373_R21FF_REV_ID, &reg);
index fde055c6c89466b361b441814c70ec9a89ee8653..33eb4576da2345eb202713609d5d3f8701a00bac 100644 (file)
@@ -12,9 +12,8 @@
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <sound/tlv.h>
 #include "max98373.h"
 
@@ -478,20 +477,24 @@ void max98373_slot_config(struct device *dev,
                max98373->i_slot = value & 0xF;
        else
                max98373->i_slot = 1;
-       if (dev->of_node) {
-               max98373->reset_gpio = of_get_named_gpio(dev->of_node,
-                                               "maxim,reset-gpio", 0);
-               if (!gpio_is_valid(max98373->reset_gpio)) {
-                       dev_err(dev, "Looking up %s property in node %s failed %d\n",
-                               "maxim,reset-gpio", dev->of_node->full_name,
-                               max98373->reset_gpio);
-               } else {
-                       dev_dbg(dev, "maxim,reset-gpio=%d",
-                               max98373->reset_gpio);
-               }
-       } else {
-               /* this makes reset_gpio as invalid */
-               max98373->reset_gpio = -1;
+
+       /* This will assert RESET */
+       max98373->reset = devm_gpiod_get_optional(dev,
+                                                 "maxim,reset",
+                                                 GPIOD_OUT_HIGH);
+       if (IS_ERR(max98373->reset)) {
+               dev_err(dev, "error %ld looking up RESET GPIO line\n",
+                       PTR_ERR(max98373->reset));
+               return;
+       }
+
+       /* Cycle reset */
+       if (max98373->reset) {
+               gpiod_set_consumer_name(max98373->reset ,"MAX98373_RESET");
+               gpiod_direction_output(max98373->reset, 1);
+               msleep(50);
+               gpiod_direction_output(max98373->reset, 0);
+               msleep(20);
        }
 
        if (!device_property_read_u32(dev, "maxim,spkfb-slot-no", &value))
index e1810b3b1620bd3e94055755dc19650731f075fd..af3b62217497262587b46f004d0b53cf94497a59 100644 (file)
@@ -213,7 +213,7 @@ struct max98373_cache {
 
 struct max98373_priv {
        struct regmap *regmap;
-       int reset_gpio;
+       struct gpio_desc *reset;
        unsigned int v_slot;
        unsigned int i_slot;
        unsigned int spkfb_slot;