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

ASoC: rt5677: Switch to use descriptor-based gpiod API

This patch makes the driver use the new descriptor-based gpiod API
so that gpio assignment info can be provided by Device Tree, ACPI
or board files.

Signed-off-by: Ben Zhang <benzh@chromium.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Ben Zhang and committed by
Mark Brown
efd901ee aa0bcc5c

+34 -58
+31 -56
sound/soc/codecs/rt5677.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/delay.h> 17 17 #include <linux/pm.h> 18 - #include <linux/of_gpio.h> 19 18 #include <linux/regmap.h> 20 19 #include <linux/i2c.h> 21 20 #include <linux/platform_device.h> 22 21 #include <linux/spi/spi.h> 23 22 #include <linux/firmware.h> 24 - #include <linux/gpio.h> 25 23 #include <sound/core.h> 26 24 #include <sound/pcm.h> 27 25 #include <sound/pcm_params.h> ··· 4762 4764 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4763 4765 4764 4766 regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); 4765 - if (gpio_is_valid(rt5677->pow_ldo2)) 4766 - gpio_set_value_cansleep(rt5677->pow_ldo2, 0); 4767 - if (gpio_is_valid(rt5677->reset_pin)) 4768 - gpio_set_value_cansleep(rt5677->reset_pin, 0); 4767 + if (rt5677->pow_ldo2) 4768 + gpiod_set_value_cansleep(rt5677->pow_ldo2, 0); 4769 + if (rt5677->reset_pin) 4770 + gpiod_set_value_cansleep(rt5677->reset_pin, 0); 4769 4771 4770 4772 return 0; 4771 4773 } ··· 4779 4781 regcache_cache_only(rt5677->regmap, true); 4780 4782 regcache_mark_dirty(rt5677->regmap); 4781 4783 4782 - if (gpio_is_valid(rt5677->pow_ldo2)) 4783 - gpio_set_value_cansleep(rt5677->pow_ldo2, 0); 4784 - if (gpio_is_valid(rt5677->reset_pin)) 4785 - gpio_set_value_cansleep(rt5677->reset_pin, 0); 4784 + if (rt5677->pow_ldo2) 4785 + gpiod_set_value_cansleep(rt5677->pow_ldo2, 0); 4786 + if (rt5677->reset_pin) 4787 + gpiod_set_value_cansleep(rt5677->reset_pin, 0); 4786 4788 } 4787 4789 4788 4790 return 0; ··· 4793 4795 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4794 4796 4795 4797 if (!rt5677->dsp_vad_en) { 4796 - if (gpio_is_valid(rt5677->pow_ldo2)) 4797 - gpio_set_value_cansleep(rt5677->pow_ldo2, 1); 4798 - if (gpio_is_valid(rt5677->reset_pin)) 4799 - gpio_set_value_cansleep(rt5677->reset_pin, 1); 4800 - if (gpio_is_valid(rt5677->pow_ldo2) || 4801 - gpio_is_valid(rt5677->reset_pin)) 4798 + if (rt5677->pow_ldo2) 4799 + gpiod_set_value_cansleep(rt5677->pow_ldo2, 1); 4800 + if (rt5677->reset_pin) 4801 + gpiod_set_value_cansleep(rt5677->reset_pin, 1); 4802 + if (rt5677->pow_ldo2 || rt5677->reset_pin) 4802 4803 msleep(10); 4803 4804 4804 4805 regcache_cache_only(rt5677->regmap, false); ··· 5034 5037 rt5677->pdata.lout3_diff = of_property_read_bool(np, 5035 5038 "realtek,lout3-differential"); 5036 5039 5037 - rt5677->pow_ldo2 = of_get_named_gpio(np, 5038 - "realtek,pow-ldo2-gpio", 0); 5039 - rt5677->reset_pin = of_get_named_gpio(np, 5040 - "realtek,reset-gpio", 0); 5041 - 5042 - /* 5043 - * POW_LDO2 is optional (it may be statically tied on the board). 5044 - * -ENOENT means that the property doesn't exist, i.e. there is no 5045 - * GPIO, so is not an error. Any other error code means the property 5046 - * exists, but could not be parsed. 5047 - */ 5048 - if (!gpio_is_valid(rt5677->pow_ldo2) && 5049 - (rt5677->pow_ldo2 != -ENOENT)) 5050 - return rt5677->pow_ldo2; 5051 - if (!gpio_is_valid(rt5677->reset_pin) && 5052 - (rt5677->reset_pin != -ENOENT)) 5053 - return rt5677->reset_pin; 5054 - 5055 5040 of_property_read_u8_array(np, "realtek,gpio-config", 5056 5041 rt5677->pdata.gpio_config, RT5677_GPIO_NUM); 5057 5042 ··· 5137 5158 rt5677->reset_pin = -EINVAL; 5138 5159 } 5139 5160 5140 - if (gpio_is_valid(rt5677->pow_ldo2)) { 5141 - ret = devm_gpio_request_one(&i2c->dev, rt5677->pow_ldo2, 5142 - GPIOF_OUT_INIT_HIGH, 5143 - "RT5677 POW_LDO2"); 5144 - if (ret < 0) { 5145 - dev_err(&i2c->dev, "Failed to request POW_LDO2 %d: %d\n", 5146 - rt5677->pow_ldo2, ret); 5147 - return ret; 5148 - } 5161 + /* pow-ldo2 and reset are optional. The codec pins may be statically 5162 + * connected on the board without gpios. If the gpio device property 5163 + * isn't specified, devm_gpiod_get_optional returns NULL. 5164 + */ 5165 + rt5677->pow_ldo2 = devm_gpiod_get_optional(&i2c->dev, 5166 + "realtek,pow-ldo2", GPIOD_OUT_HIGH); 5167 + if (IS_ERR(rt5677->pow_ldo2)) { 5168 + ret = PTR_ERR(rt5677->pow_ldo2); 5169 + dev_err(&i2c->dev, "Failed to request POW_LDO2: %d\n", ret); 5170 + rt5677->pow_ldo2 = 0; 5171 + } 5172 + rt5677->reset_pin = devm_gpiod_get_optional(&i2c->dev, 5173 + "realtek,reset", GPIOD_OUT_HIGH); 5174 + if (IS_ERR(rt5677->reset_pin)) { 5175 + ret = PTR_ERR(rt5677->reset_pin); 5176 + dev_err(&i2c->dev, "Failed to request RESET: %d\n", ret); 5177 + rt5677->reset_pin = 0; 5149 5178 } 5150 5179 5151 - if (gpio_is_valid(rt5677->reset_pin)) { 5152 - ret = devm_gpio_request_one(&i2c->dev, rt5677->reset_pin, 5153 - GPIOF_OUT_INIT_HIGH, 5154 - "RT5677 RESET"); 5155 - if (ret < 0) { 5156 - dev_err(&i2c->dev, "Failed to request RESET %d: %d\n", 5157 - rt5677->reset_pin, ret); 5158 - return ret; 5159 - } 5160 - } 5161 - 5162 - if (gpio_is_valid(rt5677->pow_ldo2) || 5163 - gpio_is_valid(rt5677->reset_pin)) { 5180 + if (rt5677->pow_ldo2 || rt5677->reset_pin) { 5164 5181 /* Wait a while until I2C bus becomes available. The datasheet 5165 5182 * does not specify the exact we should wait but startup 5166 5183 * sequence mentiones at least a few milliseconds.
+3 -2
sound/soc/codecs/rt5677.h
··· 14 14 15 15 #include <sound/rt5677.h> 16 16 #include <linux/gpio/driver.h> 17 + #include <linux/gpio/consumer.h> 17 18 18 19 /* Info */ 19 20 #define RT5677_RESET 0x00 ··· 1776 1775 int pll_src; 1777 1776 int pll_in; 1778 1777 int pll_out; 1779 - int pow_ldo2; /* POW_LDO2 pin */ 1780 - int reset_pin; /* RESET pin */ 1778 + struct gpio_desc *pow_ldo2; /* POW_LDO2 pin */ 1779 + struct gpio_desc *reset_pin; /* RESET pin */ 1781 1780 enum rt5677_type type; 1782 1781 #ifdef CONFIG_GPIOLIB 1783 1782 struct gpio_chip gpio_chip;