From 0015a18acf9ceafbf7e24f5addefce566326132b Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:11 +0200 Subject: [PATCH 1/7] ASoC: max9768: Convert to use GPIO descriptors The MAX9768 is pretty straight forward to convert to GPIO descriptors. To name the GPIO properties, I looke at the bindings in maxim,max9759.yaml which names these GPIO "mute" and "shutdown" respectively. No board files using platform data exist in the kernel, new users can use GPIO descriptor tables if desired. Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-1-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- include/sound/max9768.h | 4 ---- sound/soc/codecs/max9768.c | 41 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/include/sound/max9768.h b/include/sound/max9768.h index 0f78b41d030e..8509ba0079b0 100644 --- a/include/sound/max9768.h +++ b/include/sound/max9768.h @@ -9,14 +9,10 @@ /** * struct max9768_pdata - optional platform specific MAX9768 configuration - * @shdn_gpio: GPIO to SHDN pin. If not valid, pin must be hardwired HIGH - * @mute_gpio: GPIO to MUTE pin. If not valid, control for mute won't be added * @flags: configuration flags, e.g. set classic PWM mode (check datasheet * regarding "filterless modulation" which is default). */ struct max9768_pdata { - int shdn_gpio; - int mute_gpio; unsigned flags; #define MAX9768_FLAG_CLASSIC_PWM (1 << 0) }; diff --git a/sound/soc/codecs/max9768.c b/sound/soc/codecs/max9768.c index d22b4ba51ed8..8d0ca1be99c0 100644 --- a/sound/soc/codecs/max9768.c +++ b/sound/soc/codecs/max9768.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -27,8 +27,8 @@ struct max9768 { struct regmap *regmap; - int mute_gpio; - int shdn_gpio; + struct gpio_desc *mute; + struct gpio_desc *shdn; u32 flags; }; @@ -42,7 +42,7 @@ static int max9768_get_gpio(struct snd_kcontrol *kcontrol, { struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol); struct max9768 *max9768 = snd_soc_component_get_drvdata(c); - int val = gpio_get_value_cansleep(max9768->mute_gpio); + int val = gpiod_get_value_cansleep(max9768->mute); ucontrol->value.integer.value[0] = !val; @@ -55,7 +55,7 @@ static int max9768_set_gpio(struct snd_kcontrol *kcontrol, struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol); struct max9768 *max9768 = snd_soc_component_get_drvdata(c); - gpio_set_value_cansleep(max9768->mute_gpio, !ucontrol->value.integer.value[0]); + gpiod_set_value_cansleep(max9768->mute, !ucontrol->value.integer.value[0]); return 0; } @@ -138,7 +138,7 @@ static int max9768_probe(struct snd_soc_component *component) return ret; } - if (gpio_is_valid(max9768->mute_gpio)) { + if (max9768->mute) { ret = snd_soc_add_component_controls(component, max9768_mute, ARRAY_SIZE(max9768_mute)); if (ret) @@ -171,28 +171,29 @@ static int max9768_i2c_probe(struct i2c_client *client) { struct max9768 *max9768; struct max9768_pdata *pdata = client->dev.platform_data; - int err; max9768 = devm_kzalloc(&client->dev, sizeof(*max9768), GFP_KERNEL); if (!max9768) return -ENOMEM; - if (pdata) { - /* Mute on powerup to avoid clicks */ - err = devm_gpio_request_one(&client->dev, pdata->mute_gpio, - GPIOF_INIT_HIGH, "MAX9768 Mute"); - max9768->mute_gpio = err ?: pdata->mute_gpio; + /* Mute on powerup to avoid clicks */ + max9768->mute = devm_gpiod_get_optional(&client->dev, + "mute", + GPIOD_OUT_HIGH); + if (IS_ERR(max9768->mute)) + return PTR_ERR(max9768->mute); + gpiod_set_consumer_name(max9768->mute, "MAX9768 Mute"); - /* Activate chip by releasing shutdown, enables I2C */ - err = devm_gpio_request_one(&client->dev, pdata->shdn_gpio, - GPIOF_INIT_HIGH, "MAX9768 Shutdown"); - max9768->shdn_gpio = err ?: pdata->shdn_gpio; + /* Activate chip by releasing shutdown, enables I2C */ + max9768->shdn = devm_gpiod_get_optional(&client->dev, + "shutdown", + GPIOD_OUT_HIGH); + if (IS_ERR(max9768->shdn)) + return PTR_ERR(max9768->shdn); + gpiod_set_consumer_name(max9768->shdn, "MAX9768 Shutdown"); + if (pdata) max9768->flags = pdata->flags; - } else { - max9768->shdn_gpio = -EINVAL; - max9768->mute_gpio = -EINVAL; - } i2c_set_clientdata(client, max9768); From a3b68ba9f594ae4f9a96e0730e9aeadb9f64c43e Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:12 +0200 Subject: [PATCH 2/7] ASoC: max98357a: Drop pointless include This driver is already using solely GPIO descriptors and do not need to include the legacy header . Drop it. Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-2-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- sound/soc/codecs/max98357a.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c index 2a2b286f1747..cc811f58c9d2 100644 --- a/sound/soc/codecs/max98357a.c +++ b/sound/soc/codecs/max98357a.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include From c5cb83a104a2d95ba4ba182051eff2a8c82d5beb Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:13 +0200 Subject: [PATCH 3/7] ASoC: max98373: Convert to use GPIO descriptors 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 Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-3-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- sound/soc/codecs/max98373-i2c.c | 17 ---------------- sound/soc/codecs/max98373.c | 35 ++++++++++++++++++--------------- sound/soc/codecs/max98373.h | 2 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/sound/soc/codecs/max98373-i2c.c b/sound/soc/codecs/max98373-i2c.c index 0fa5ceca62a2..e7ec7875c4a9 100644 --- a/sound/soc/codecs/max98373-i2c.c +++ b/sound/soc/codecs/max98373-i2c.c @@ -3,12 +3,10 @@ #include #include -#include #include #include #include #include -#include #include #include #include @@ -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, ®); diff --git a/sound/soc/codecs/max98373.c b/sound/soc/codecs/max98373.c index fde055c6c894..33eb4576da23 100644 --- a/sound/soc/codecs/max98373.c +++ b/sound/soc/codecs/max98373.c @@ -12,9 +12,8 @@ #include #include #include -#include +#include #include -#include #include #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)) diff --git a/sound/soc/codecs/max98373.h b/sound/soc/codecs/max98373.h index e1810b3b1620..af3b62217497 100644 --- a/sound/soc/codecs/max98373.h +++ b/sound/soc/codecs/max98373.h @@ -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; From 4b0dfc0e8cdebd6aa6ce25593c0dcc71d9d21961 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:14 +0200 Subject: [PATCH 4/7] ASoC: max98388: Correct the includes The MAX98388 driver is using the modern GPIO descriptor API but uses legacy includes. Include the proper header instead. Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-4-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- sound/soc/codecs/max98388.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/soc/codecs/max98388.c b/sound/soc/codecs/max98388.c index cde5e85946cb..078adec29312 100644 --- a/sound/soc/codecs/max98388.c +++ b/sound/soc/codecs/max98388.c @@ -3,12 +3,11 @@ #include #include -#include +#include #include #include #include #include -#include #include #include #include From 70f29a3078f7bc1f1011b7b5fee41fcd52ff189f Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:15 +0200 Subject: [PATCH 5/7] ASoC: max98396: Drop pointless include This driver is already using solely GPIO descriptors and do not need to include the legacy header . Drop it. Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-5-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- sound/soc/codecs/max98396.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sound/soc/codecs/max98396.c b/sound/soc/codecs/max98396.c index 3a1d8c211f3c..e52bb2266fa1 100644 --- a/sound/soc/codecs/max98396.c +++ b/sound/soc/codecs/max98396.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "max98396.h" From d9241aaea1418fa4bd6653bee093f63cf47a2c6e Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:16 +0200 Subject: [PATCH 6/7] ASoC: max98520: Drop pointless includes This driver is already using solely GPIO descriptors and do not need to include the legacy headers or . Drop them. Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-6-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- sound/soc/codecs/max98520.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sound/soc/codecs/max98520.c b/sound/soc/codecs/max98520.c index 8637fff307ad..edd05253d37c 100644 --- a/sound/soc/codecs/max98520.c +++ b/sound/soc/codecs/max98520.c @@ -11,10 +11,8 @@ #include #include #include -#include #include #include -#include #include #include "max98520.h" From 0307ba5420cd785615efc94be6b101b4ac2538cf Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 25 Aug 2023 10:12:17 +0200 Subject: [PATCH 7/7] ASoC: max98927: Drop pointless includes This driver is already using solely GPIO descriptors and do not need to include the legacy headers or . Drop them. Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20230825-descriptors-asoc-max-v1-7-b212292b2f08@linaro.org Signed-off-by: Mark Brown --- sound/soc/codecs/max98927.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c index 776f23d38ac5..70db9d3ff5a5 100644 --- a/sound/soc/codecs/max98927.c +++ b/sound/soc/codecs/max98927.c @@ -15,9 +15,7 @@ #include #include #include -#include #include -#include #include #include "max98927.h"