Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: rt5640: Convert to just use GPIO descriptors

The RT5640 driver is already using GPIO descriptors for some
stuff, all that is needed is to convert the remaining LDO1
control line to also use descriptors.

Simplify the code using gpiod_get_optional() and drop the
special "of" parsing function: these descriptors need not
come from device tree and it's optional so hey.

Keep some NULL checks around the GPIO operations even though
gpiolib is essentially NULL-tolerant, because by checking
for whether we have a valid GPIO descriptor or not we can
avoid a 400 ms delay which is great.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20230817-descriptors-asoc-rt-v2-1-02fa2ca3e5b0@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
a9b5f210 17b9f438

+16 -41
+15 -40
sound/soc/codecs/rt5640.c
··· 12 12 #include <linux/init.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/pm.h> 15 - #include <linux/gpio.h> 15 + #include <linux/gpio/consumer.h> 16 16 #include <linux/i2c.h> 17 17 #include <linux/regmap.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_gpio.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/spi/spi.h> 22 21 #include <linux/acpi.h> ··· 2811 2812 rt5640_reset(component); 2812 2813 regcache_cache_only(rt5640->regmap, true); 2813 2814 regcache_mark_dirty(rt5640->regmap); 2814 - if (gpio_is_valid(rt5640->ldo1_en)) 2815 - gpio_set_value_cansleep(rt5640->ldo1_en, 0); 2815 + if (rt5640->ldo1_en) 2816 + gpiod_set_value_cansleep(rt5640->ldo1_en, 0); 2816 2817 2817 2818 return 0; 2818 2819 } ··· 2821 2822 { 2822 2823 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component); 2823 2824 2824 - if (gpio_is_valid(rt5640->ldo1_en)) { 2825 - gpio_set_value_cansleep(rt5640->ldo1_en, 1); 2825 + if (rt5640->ldo1_en) { 2826 + gpiod_set_value_cansleep(rt5640->ldo1_en, 1); 2826 2827 msleep(400); 2827 2828 } 2828 2829 ··· 2985 2986 MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match); 2986 2987 #endif 2987 2988 2988 - static int rt5640_parse_dt(struct rt5640_priv *rt5640, struct device_node *np) 2989 - { 2990 - rt5640->ldo1_en = of_get_named_gpio(np, "realtek,ldo1-en-gpios", 0); 2991 - /* 2992 - * LDO1_EN is optional (it may be statically tied on the board). 2993 - * -ENOENT means that the property doesn't exist, i.e. there is no 2994 - * GPIO, so is not an error. Any other error code means the property 2995 - * exists, but could not be parsed. 2996 - */ 2997 - if (!gpio_is_valid(rt5640->ldo1_en) && 2998 - (rt5640->ldo1_en != -ENOENT)) 2999 - return rt5640->ldo1_en; 3000 - 3001 - return 0; 3002 - } 3003 - 3004 2989 static int rt5640_i2c_probe(struct i2c_client *i2c) 3005 2990 { 3006 2991 struct rt5640_priv *rt5640; ··· 2998 3015 return -ENOMEM; 2999 3016 i2c_set_clientdata(i2c, rt5640); 3000 3017 3001 - if (i2c->dev.of_node) { 3002 - ret = rt5640_parse_dt(rt5640, i2c->dev.of_node); 3003 - if (ret) 3004 - return ret; 3005 - } else 3006 - rt5640->ldo1_en = -EINVAL; 3018 + rt5640->ldo1_en = devm_gpiod_get_optional(&i2c->dev, 3019 + "realtek,ldo1-en", 3020 + GPIOD_OUT_HIGH); 3021 + if (IS_ERR(rt5640->ldo1_en)) 3022 + return PTR_ERR(rt5640->ldo1_en); 3023 + 3024 + if (rt5640->ldo1_en) { 3025 + gpiod_set_consumer_name(rt5640->ldo1_en, "RT5640 LDO1_EN"); 3026 + msleep(400); 3027 + } 3007 3028 3008 3029 rt5640->regmap = devm_regmap_init_i2c(i2c, &rt5640_regmap); 3009 3030 if (IS_ERR(rt5640->regmap)) { ··· 3015 3028 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 3016 3029 ret); 3017 3030 return ret; 3018 - } 3019 - 3020 - if (gpio_is_valid(rt5640->ldo1_en)) { 3021 - ret = devm_gpio_request_one(&i2c->dev, rt5640->ldo1_en, 3022 - GPIOF_OUT_INIT_HIGH, 3023 - "RT5640 LDO1_EN"); 3024 - if (ret < 0) { 3025 - dev_err(&i2c->dev, "Failed to request LDO1_EN %d: %d\n", 3026 - rt5640->ldo1_en, ret); 3027 - return ret; 3028 - } 3029 - msleep(400); 3030 3031 } 3031 3032 3032 3033 regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val);
+1 -1
sound/soc/codecs/rt5640.h
··· 2138 2138 struct regmap *regmap; 2139 2139 struct clk *mclk; 2140 2140 2141 - int ldo1_en; /* GPIO for LDO1_EN */ 2141 + struct gpio_desc *ldo1_en; /* GPIO for LDO1_EN */ 2142 2142 int irq; 2143 2143 int jd_gpio_irq; 2144 2144 int sysclk;