Skip to content

Commit ed11701

Browse files
Linus Walleijbroonie
authored andcommitted
ASoC: rt5682: Convert to use GPIO descriptors
Convert the RT5682 to use GPIO descriptors and drop the legacy GPIO headers. We remove the global GPIO number from the platform data, but it is still possible to create board files using GPIO descriptor tables, if desired. Make sure to make sure SDW devices can associate with an LDO1 EN descriptor too, if they so desire by putting the lookup into the common code. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230817-descriptors-asoc-rt-v2-4-02fa2ca3e5b0@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent ab2a5d1 commit ed11701

5 files changed

Lines changed: 27 additions & 15 deletions

File tree

include/sound/rt5682.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ enum rt5682_dai_clks {
3131
};
3232

3333
struct rt5682_platform_data {
34-
35-
int ldo1_en; /* GPIO for LDO1_EN */
36-
3734
enum rt5682_dmic1_data_pin dmic1_data_pin;
3835
enum rt5682_dmic1_clk_pin dmic1_clk_pin;
3936
enum rt5682_jd_src jd_src;

sound/soc/codecs/rt5682-i2c.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#include <linux/platform_device.h>
1616
#include <linux/spi/spi.h>
1717
#include <linux/acpi.h>
18-
#include <linux/gpio.h>
19-
#include <linux/of_gpio.h>
18+
#include <linux/gpio/consumer.h>
2019
#include <linux/mutex.h>
2120
#include <sound/core.h>
2221
#include <sound/pcm.h>
@@ -170,11 +169,9 @@ static int rt5682_i2c_probe(struct i2c_client *i2c)
170169
return ret;
171170
}
172171

173-
if (gpio_is_valid(rt5682->pdata.ldo1_en)) {
174-
if (devm_gpio_request_one(&i2c->dev, rt5682->pdata.ldo1_en,
175-
GPIOF_OUT_INIT_HIGH, "rt5682"))
176-
dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n");
177-
}
172+
ret = rt5682_get_ldo1(rt5682, &i2c->dev);
173+
if (ret)
174+
return ret;
178175

179176
/* Sleep for 300 ms miniumum */
180177
usleep_range(300000, 350000);

sound/soc/codecs/rt5682-sdw.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ static int rt5682_sdw_init(struct device *dev, struct regmap *regmap,
320320
return ret;
321321
}
322322

323+
324+
ret = rt5682_get_ldo1(rt5682, dev);
325+
if (ret)
326+
return ret;
327+
323328
regcache_cache_only(rt5682->sdw_regmap, true);
324329
regcache_cache_only(rt5682->regmap, true);
325330

sound/soc/codecs/rt5682.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#include <linux/platform_device.h>
1616
#include <linux/spi/spi.h>
1717
#include <linux/acpi.h>
18-
#include <linux/gpio.h>
19-
#include <linux/of_gpio.h>
18+
#include <linux/gpio/consumer.h>
2019
#include <linux/mutex.h>
2120
#include <sound/core.h>
2221
#include <sound/pcm.h>
@@ -3094,9 +3093,6 @@ int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev)
30943093
device_property_read_u32(dev, "realtek,dmic-delay-ms",
30953094
&rt5682->pdata.dmic_delay);
30963095

3097-
rt5682->pdata.ldo1_en = of_get_named_gpio(dev->of_node,
3098-
"realtek,ldo1-en-gpios", 0);
3099-
31003096
if (device_property_read_string_array(dev, "clock-output-names",
31013097
rt5682->pdata.dai_clk_names,
31023098
RT5682_DAI_NUM_CLKS) < 0)
@@ -3111,6 +3107,20 @@ int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev)
31113107
}
31123108
EXPORT_SYMBOL_GPL(rt5682_parse_dt);
31133109

3110+
int rt5682_get_ldo1(struct rt5682_priv *rt5682, struct device *dev)
3111+
{
3112+
rt5682->ldo1_en = devm_gpiod_get_optional(dev,
3113+
"realtek,ldo1-en",
3114+
GPIOD_OUT_HIGH);
3115+
if (IS_ERR(rt5682->ldo1_en)) {
3116+
dev_err(dev, "Fail gpio request ldo1_en\n");
3117+
return PTR_ERR(rt5682->ldo1_en);
3118+
}
3119+
3120+
return 0;
3121+
}
3122+
EXPORT_SYMBOL_GPL(rt5682_get_ldo1);
3123+
31143124
void rt5682_calibrate(struct rt5682_priv *rt5682)
31153125
{
31163126
int value, count;

sound/soc/codecs/rt5682.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <sound/rt5682.h>
1313
#include <linux/regulator/consumer.h>
14+
#include <linux/gpio/consumer.h>
1415
#include <linux/clk.h>
1516
#include <linux/clkdev.h>
1617
#include <linux/clk-provider.h>
@@ -1430,6 +1431,7 @@ struct rt5682_priv {
14301431
struct snd_soc_component *component;
14311432
struct device *i2c_dev;
14321433
struct rt5682_platform_data pdata;
1434+
struct gpio_desc *ldo1_en;
14331435
struct regmap *regmap;
14341436
struct regmap *sdw_regmap;
14351437
struct snd_soc_jack *hs_jack;
@@ -1481,6 +1483,7 @@ int rt5682_register_component(struct device *dev);
14811483
void rt5682_calibrate(struct rt5682_priv *rt5682);
14821484
void rt5682_reset(struct rt5682_priv *rt5682);
14831485
int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev);
1486+
int rt5682_get_ldo1(struct rt5682_priv *rt5682, struct device *dev);
14841487

14851488
int rt5682_register_dai_clks(struct rt5682_priv *rt5682);
14861489

0 commit comments

Comments
 (0)