Commit efd901ee authored by Ben Zhang's avatar Ben Zhang Committed by Mark Brown

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: default avatarBen Zhang <benzh@chromium.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent aa0bcc5c
...@@ -15,13 +15,11 @@ ...@@ -15,13 +15,11 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/of_gpio.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/firmware.h> #include <linux/firmware.h>
#include <linux/gpio.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/pcm.h> #include <sound/pcm.h>
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
...@@ -4764,10 +4762,10 @@ static int rt5677_remove(struct snd_soc_codec *codec) ...@@ -4764,10 +4762,10 @@ static int rt5677_remove(struct snd_soc_codec *codec)
struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec);
if (gpio_is_valid(rt5677->pow_ldo2)) if (rt5677->pow_ldo2)
gpio_set_value_cansleep(rt5677->pow_ldo2, 0); gpiod_set_value_cansleep(rt5677->pow_ldo2, 0);
if (gpio_is_valid(rt5677->reset_pin)) if (rt5677->reset_pin)
gpio_set_value_cansleep(rt5677->reset_pin, 0); gpiod_set_value_cansleep(rt5677->reset_pin, 0);
return 0; return 0;
} }
...@@ -4781,10 +4779,10 @@ static int rt5677_suspend(struct snd_soc_codec *codec) ...@@ -4781,10 +4779,10 @@ static int rt5677_suspend(struct snd_soc_codec *codec)
regcache_cache_only(rt5677->regmap, true); regcache_cache_only(rt5677->regmap, true);
regcache_mark_dirty(rt5677->regmap); regcache_mark_dirty(rt5677->regmap);
if (gpio_is_valid(rt5677->pow_ldo2)) if (rt5677->pow_ldo2)
gpio_set_value_cansleep(rt5677->pow_ldo2, 0); gpiod_set_value_cansleep(rt5677->pow_ldo2, 0);
if (gpio_is_valid(rt5677->reset_pin)) if (rt5677->reset_pin)
gpio_set_value_cansleep(rt5677->reset_pin, 0); gpiod_set_value_cansleep(rt5677->reset_pin, 0);
} }
return 0; return 0;
...@@ -4795,12 +4793,11 @@ static int rt5677_resume(struct snd_soc_codec *codec) ...@@ -4795,12 +4793,11 @@ static int rt5677_resume(struct snd_soc_codec *codec)
struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
if (!rt5677->dsp_vad_en) { if (!rt5677->dsp_vad_en) {
if (gpio_is_valid(rt5677->pow_ldo2)) if (rt5677->pow_ldo2)
gpio_set_value_cansleep(rt5677->pow_ldo2, 1); gpiod_set_value_cansleep(rt5677->pow_ldo2, 1);
if (gpio_is_valid(rt5677->reset_pin)) if (rt5677->reset_pin)
gpio_set_value_cansleep(rt5677->reset_pin, 1); gpiod_set_value_cansleep(rt5677->reset_pin, 1);
if (gpio_is_valid(rt5677->pow_ldo2) || if (rt5677->pow_ldo2 || rt5677->reset_pin)
gpio_is_valid(rt5677->reset_pin))
msleep(10); msleep(10);
regcache_cache_only(rt5677->regmap, false); regcache_cache_only(rt5677->regmap, false);
...@@ -5037,24 +5034,6 @@ static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np) ...@@ -5037,24 +5034,6 @@ static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np)
rt5677->pdata.lout3_diff = of_property_read_bool(np, rt5677->pdata.lout3_diff = of_property_read_bool(np,
"realtek,lout3-differential"); "realtek,lout3-differential");
rt5677->pow_ldo2 = of_get_named_gpio(np,
"realtek,pow-ldo2-gpio", 0);
rt5677->reset_pin = of_get_named_gpio(np,
"realtek,reset-gpio", 0);
/*
* POW_LDO2 is optional (it may be statically tied on the board).
* -ENOENT means that the property doesn't exist, i.e. there is no
* GPIO, so is not an error. Any other error code means the property
* exists, but could not be parsed.
*/
if (!gpio_is_valid(rt5677->pow_ldo2) &&
(rt5677->pow_ldo2 != -ENOENT))
return rt5677->pow_ldo2;
if (!gpio_is_valid(rt5677->reset_pin) &&
(rt5677->reset_pin != -ENOENT))
return rt5677->reset_pin;
of_property_read_u8_array(np, "realtek,gpio-config", of_property_read_u8_array(np, "realtek,gpio-config",
rt5677->pdata.gpio_config, RT5677_GPIO_NUM); rt5677->pdata.gpio_config, RT5677_GPIO_NUM);
...@@ -5158,30 +5137,26 @@ static int rt5677_i2c_probe(struct i2c_client *i2c, ...@@ -5158,30 +5137,26 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
rt5677->reset_pin = -EINVAL; rt5677->reset_pin = -EINVAL;
} }
if (gpio_is_valid(rt5677->pow_ldo2)) { /* pow-ldo2 and reset are optional. The codec pins may be statically
ret = devm_gpio_request_one(&i2c->dev, rt5677->pow_ldo2, * connected on the board without gpios. If the gpio device property
GPIOF_OUT_INIT_HIGH, * isn't specified, devm_gpiod_get_optional returns NULL.
"RT5677 POW_LDO2"); */
if (ret < 0) { rt5677->pow_ldo2 = devm_gpiod_get_optional(&i2c->dev,
dev_err(&i2c->dev, "Failed to request POW_LDO2 %d: %d\n", "realtek,pow-ldo2", GPIOD_OUT_HIGH);
rt5677->pow_ldo2, ret); if (IS_ERR(rt5677->pow_ldo2)) {
return ret; ret = PTR_ERR(rt5677->pow_ldo2);
} dev_err(&i2c->dev, "Failed to request POW_LDO2: %d\n", ret);
} rt5677->pow_ldo2 = 0;
if (gpio_is_valid(rt5677->reset_pin)) {
ret = devm_gpio_request_one(&i2c->dev, rt5677->reset_pin,
GPIOF_OUT_INIT_HIGH,
"RT5677 RESET");
if (ret < 0) {
dev_err(&i2c->dev, "Failed to request RESET %d: %d\n",
rt5677->reset_pin, ret);
return ret;
} }
rt5677->reset_pin = devm_gpiod_get_optional(&i2c->dev,
"realtek,reset", GPIOD_OUT_HIGH);
if (IS_ERR(rt5677->reset_pin)) {
ret = PTR_ERR(rt5677->reset_pin);
dev_err(&i2c->dev, "Failed to request RESET: %d\n", ret);
rt5677->reset_pin = 0;
} }
if (gpio_is_valid(rt5677->pow_ldo2) || if (rt5677->pow_ldo2 || rt5677->reset_pin) {
gpio_is_valid(rt5677->reset_pin)) {
/* Wait a while until I2C bus becomes available. The datasheet /* Wait a while until I2C bus becomes available. The datasheet
* does not specify the exact we should wait but startup * does not specify the exact we should wait but startup
* sequence mentiones at least a few milliseconds. * sequence mentiones at least a few milliseconds.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sound/rt5677.h> #include <sound/rt5677.h>
#include <linux/gpio/driver.h> #include <linux/gpio/driver.h>
#include <linux/gpio/consumer.h>
/* Info */ /* Info */
#define RT5677_RESET 0x00 #define RT5677_RESET 0x00
...@@ -1775,8 +1776,8 @@ struct rt5677_priv { ...@@ -1775,8 +1776,8 @@ struct rt5677_priv {
int pll_src; int pll_src;
int pll_in; int pll_in;
int pll_out; int pll_out;
int pow_ldo2; /* POW_LDO2 pin */ struct gpio_desc *pow_ldo2; /* POW_LDO2 pin */
int reset_pin; /* RESET pin */ struct gpio_desc *reset_pin; /* RESET pin */
enum rt5677_type type; enum rt5677_type type;
#ifdef CONFIG_GPIOLIB #ifdef CONFIG_GPIOLIB
struct gpio_chip gpio_chip; struct gpio_chip gpio_chip;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment