Commit 44cb08fd authored by Mark Brown's avatar Mark Brown

ASoC: Convert remaining Realtek codecs to GPIO

Merge series from Linus Walleij <linus.walleij@linaro.org>:

After dropping unused headers a few Realtek devices
actually using the GPIO descriptors remain.

Converting them to use optional GPIO descriptors is
pretty straight-forward.
parents b41efc22 8793bee7
......@@ -31,8 +31,6 @@ struct rt5665_platform_data {
bool in3_diff;
bool in4_diff;
int ldo1_en; /* GPIO for LDO1_EN */
enum rt5665_dmic1_data_pin dmic1_data_pin;
enum rt5665_dmic2_data_pin dmic2_data_pin;
enum rt5665_jd_src jd_src;
......
......@@ -25,9 +25,6 @@ enum rt5668_jd_src {
};
struct rt5668_platform_data {
int ldo1_en; /* GPIO for LDO1_EN */
enum rt5668_dmic1_data_pin dmic1_data_pin;
enum rt5668_dmic1_clk_pin dmic1_clk_pin;
enum rt5668_jd_src jd_src;
......
......@@ -31,9 +31,6 @@ enum rt5682_dai_clks {
};
struct rt5682_platform_data {
int ldo1_en; /* GPIO for LDO1_EN */
enum rt5682_dmic1_data_pin dmic1_data_pin;
enum rt5682_dmic1_clk_pin dmic1_clk_pin;
enum rt5682_jd_src jd_src;
......
......@@ -32,9 +32,6 @@ enum rt5682s_dai_clks {
};
struct rt5682s_platform_data {
int ldo1_en; /* GPIO for LDO1_EN */
enum rt5682s_dmic1_data_pin dmic1_data_pin;
enum rt5682s_dmic1_clk_pin dmic1_clk_pin;
enum rt5682s_jd_src jd_src;
......
......@@ -12,11 +12,10 @@
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
......@@ -2812,8 +2811,8 @@ static int rt5640_suspend(struct snd_soc_component *component)
rt5640_reset(component);
regcache_cache_only(rt5640->regmap, true);
regcache_mark_dirty(rt5640->regmap);
if (gpio_is_valid(rt5640->ldo1_en))
gpio_set_value_cansleep(rt5640->ldo1_en, 0);
if (rt5640->ldo1_en)
gpiod_set_value_cansleep(rt5640->ldo1_en, 0);
return 0;
}
......@@ -2822,8 +2821,8 @@ static int rt5640_resume(struct snd_soc_component *component)
{
struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
if (gpio_is_valid(rt5640->ldo1_en)) {
gpio_set_value_cansleep(rt5640->ldo1_en, 1);
if (rt5640->ldo1_en) {
gpiod_set_value_cansleep(rt5640->ldo1_en, 1);
msleep(400);
}
......@@ -2986,22 +2985,6 @@ static const struct acpi_device_id rt5640_acpi_match[] = {
MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match);
#endif
static int rt5640_parse_dt(struct rt5640_priv *rt5640, struct device_node *np)
{
rt5640->ldo1_en = of_get_named_gpio(np, "realtek,ldo1-en-gpios", 0);
/*
* LDO1_EN 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(rt5640->ldo1_en) &&
(rt5640->ldo1_en != -ENOENT))
return rt5640->ldo1_en;
return 0;
}
static int rt5640_i2c_probe(struct i2c_client *i2c)
{
struct rt5640_priv *rt5640;
......@@ -3015,12 +2998,16 @@ static int rt5640_i2c_probe(struct i2c_client *i2c)
return -ENOMEM;
i2c_set_clientdata(i2c, rt5640);
if (i2c->dev.of_node) {
ret = rt5640_parse_dt(rt5640, i2c->dev.of_node);
if (ret)
return ret;
} else
rt5640->ldo1_en = -EINVAL;
rt5640->ldo1_en = devm_gpiod_get_optional(&i2c->dev,
"realtek,ldo1-en",
GPIOD_OUT_HIGH);
if (IS_ERR(rt5640->ldo1_en))
return PTR_ERR(rt5640->ldo1_en);
if (rt5640->ldo1_en) {
gpiod_set_consumer_name(rt5640->ldo1_en, "RT5640 LDO1_EN");
msleep(400);
}
rt5640->regmap = devm_regmap_init_i2c(i2c, &rt5640_regmap);
if (IS_ERR(rt5640->regmap)) {
......@@ -3030,18 +3017,6 @@ static int rt5640_i2c_probe(struct i2c_client *i2c)
return ret;
}
if (gpio_is_valid(rt5640->ldo1_en)) {
ret = devm_gpio_request_one(&i2c->dev, rt5640->ldo1_en,
GPIOF_OUT_INIT_HIGH,
"RT5640 LDO1_EN");
if (ret < 0) {
dev_err(&i2c->dev, "Failed to request LDO1_EN %d: %d\n",
rt5640->ldo1_en, ret);
return ret;
}
msleep(400);
}
regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val);
if (val != RT5640_DEVICE_ID) {
dev_err(&i2c->dev,
......
......@@ -2138,7 +2138,7 @@ struct rt5640_priv {
struct regmap *regmap;
struct clk *mclk;
int ldo1_en; /* GPIO for LDO1_EN */
struct gpio_desc *ldo1_en; /* GPIO for LDO1_EN */
int irq;
int jd_gpio_irq;
int sysclk;
......
......@@ -15,8 +15,7 @@
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/regulator/consumer.h>
#include <linux/mutex.h>
#include <sound/core.h>
......@@ -4659,9 +4658,6 @@ static int rt5665_parse_dt(struct rt5665_priv *rt5665, struct device *dev)
of_property_read_u32(dev->of_node, "realtek,jd-src",
&rt5665->pdata.jd_src);
rt5665->pdata.ldo1_en = of_get_named_gpio(dev->of_node,
"realtek,ldo1-en-gpios", 0);
return 0;
}
......@@ -4795,10 +4791,13 @@ static int rt5665_i2c_probe(struct i2c_client *i2c)
return ret;
}
if (gpio_is_valid(rt5665->pdata.ldo1_en)) {
if (devm_gpio_request_one(&i2c->dev, rt5665->pdata.ldo1_en,
GPIOF_OUT_INIT_HIGH, "rt5665"))
dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n");
rt5665->gpiod_ldo1_en = devm_gpiod_get_optional(&i2c->dev,
"realtek,ldo1-en",
GPIOD_OUT_HIGH);
if (IS_ERR(rt5665->gpiod_ldo1_en)) {
dev_err(&i2c->dev, "Failed gpio request ldo1_en\n");
return PTR_ERR(rt5665->gpiod_ldo1_en);
}
/* Sleep for 300 ms miniumum */
......
......@@ -15,8 +15,7 @@
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/regulator/consumer.h>
#include <linux/mutex.h>
#include <sound/core.h>
......@@ -43,6 +42,7 @@ static const char *rt5668_supply_names[RT5668_NUM_SUPPLIES] = {
struct rt5668_priv {
struct snd_soc_component *component;
struct rt5668_platform_data pdata;
struct gpio_desc *ldo1_en;
struct regmap *regmap;
struct snd_soc_jack *hs_jack;
struct regulator_bulk_data supplies[RT5668_NUM_SUPPLIES];
......@@ -2393,9 +2393,6 @@ static int rt5668_parse_dt(struct rt5668_priv *rt5668, struct device *dev)
of_property_read_u32(dev->of_node, "realtek,jd-src",
&rt5668->pdata.jd_src);
rt5668->pdata.ldo1_en = of_get_named_gpio(dev->of_node,
"realtek,ldo1-en-gpios", 0);
return 0;
}
......@@ -2497,10 +2494,12 @@ static int rt5668_i2c_probe(struct i2c_client *i2c)
return ret;
}
if (gpio_is_valid(rt5668->pdata.ldo1_en)) {
if (devm_gpio_request_one(&i2c->dev, rt5668->pdata.ldo1_en,
GPIOF_OUT_INIT_HIGH, "rt5668"))
dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n");
rt5668->ldo1_en = devm_gpiod_get_optional(&i2c->dev,
"realtek,ldo1-en",
GPIOD_OUT_HIGH);
if (IS_ERR(rt5668->ldo1_en)) {
dev_err(&i2c->dev, "Fail gpio request ldo1_en\n");
return PTR_ERR(rt5668->ldo1_en);
}
/* Sleep for 300 ms miniumum */
......
......@@ -15,8 +15,7 @@
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/mutex.h>
#include <sound/core.h>
#include <sound/pcm.h>
......@@ -170,11 +169,9 @@ static int rt5682_i2c_probe(struct i2c_client *i2c)
return ret;
}
if (gpio_is_valid(rt5682->pdata.ldo1_en)) {
if (devm_gpio_request_one(&i2c->dev, rt5682->pdata.ldo1_en,
GPIOF_OUT_INIT_HIGH, "rt5682"))
dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n");
}
ret = rt5682_get_ldo1(rt5682, &i2c->dev);
if (ret)
return ret;
/* Sleep for 300 ms miniumum */
usleep_range(300000, 350000);
......
......@@ -320,6 +320,11 @@ static int rt5682_sdw_init(struct device *dev, struct regmap *regmap,
return ret;
}
ret = rt5682_get_ldo1(rt5682, dev);
if (ret)
return ret;
regcache_cache_only(rt5682->sdw_regmap, true);
regcache_cache_only(rt5682->regmap, true);
......
......@@ -15,8 +15,7 @@
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/mutex.h>
#include <sound/core.h>
#include <sound/pcm.h>
......@@ -3094,9 +3093,6 @@ int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev)
device_property_read_u32(dev, "realtek,dmic-delay-ms",
&rt5682->pdata.dmic_delay);
rt5682->pdata.ldo1_en = of_get_named_gpio(dev->of_node,
"realtek,ldo1-en-gpios", 0);
if (device_property_read_string_array(dev, "clock-output-names",
rt5682->pdata.dai_clk_names,
RT5682_DAI_NUM_CLKS) < 0)
......@@ -3111,6 +3107,20 @@ int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev)
}
EXPORT_SYMBOL_GPL(rt5682_parse_dt);
int rt5682_get_ldo1(struct rt5682_priv *rt5682, struct device *dev)
{
rt5682->ldo1_en = devm_gpiod_get_optional(dev,
"realtek,ldo1-en",
GPIOD_OUT_HIGH);
if (IS_ERR(rt5682->ldo1_en)) {
dev_err(dev, "Fail gpio request ldo1_en\n");
return PTR_ERR(rt5682->ldo1_en);
}
return 0;
}
EXPORT_SYMBOL_GPL(rt5682_get_ldo1);
void rt5682_calibrate(struct rt5682_priv *rt5682)
{
int value, count;
......
......@@ -11,6 +11,7 @@
#include <sound/rt5682.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/clk-provider.h>
......@@ -1430,6 +1431,7 @@ struct rt5682_priv {
struct snd_soc_component *component;
struct device *i2c_dev;
struct rt5682_platform_data pdata;
struct gpio_desc *ldo1_en;
struct regmap *regmap;
struct regmap *sdw_regmap;
struct snd_soc_jack *hs_jack;
......@@ -1481,6 +1483,7 @@ int rt5682_register_component(struct device *dev);
void rt5682_calibrate(struct rt5682_priv *rt5682);
void rt5682_reset(struct rt5682_priv *rt5682);
int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev);
int rt5682_get_ldo1(struct rt5682_priv *rt5682, struct device *dev);
int rt5682_register_dai_clks(struct rt5682_priv *rt5682);
......
......@@ -15,8 +15,7 @@
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/mutex.h>
#include <sound/core.h>
#include <sound/pcm.h>
......@@ -2973,9 +2972,6 @@ static int rt5682s_parse_dt(struct rt5682s_priv *rt5682s, struct device *dev)
device_property_read_u32(dev, "realtek,amic-delay-ms",
&rt5682s->pdata.amic_delay);
rt5682s->pdata.ldo1_en = of_get_named_gpio(dev->of_node,
"realtek,ldo1-en-gpios", 0);
if (device_property_read_string_array(dev, "clock-output-names",
rt5682s->pdata.dai_clk_names,
RT5682S_DAI_NUM_CLKS) < 0)
......@@ -3172,10 +3168,12 @@ static int rt5682s_i2c_probe(struct i2c_client *i2c)
return ret;
}
if (gpio_is_valid(rt5682s->pdata.ldo1_en)) {
if (devm_gpio_request_one(&i2c->dev, rt5682s->pdata.ldo1_en,
GPIOF_OUT_INIT_HIGH, "rt5682s"))
dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n");
rt5682s->ldo1_en = devm_gpiod_get_optional(&i2c->dev,
"realtek,ldo1-en",
GPIOD_OUT_HIGH);
if (IS_ERR(rt5682s->ldo1_en)) {
dev_err(&i2c->dev, "Fail gpio request ldo1_en\n");
return PTR_ERR(rt5682s->ldo1_en);
}
/* Sleep for 50 ms minimum */
......
......@@ -11,6 +11,7 @@
#include <sound/rt5682s.h>
#include <linux/regulator/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/clk-provider.h>
......@@ -1446,6 +1447,7 @@ enum {
struct rt5682s_priv {
struct snd_soc_component *component;
struct rt5682s_platform_data pdata;
struct gpio_desc *ldo1_en;
struct regmap *regmap;
struct snd_soc_jack *hs_jack;
struct regulator_bulk_data supplies[RT5682S_NUM_SUPPLIES];
......
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