aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnatol Pomozov <anatol.pomozov@gmail.com>2014-09-17 16:14:20 -0400
committerMark Brown <broonie@kernel.org>2014-09-24 04:59:03 -0400
commitf9f6a592cf4f35e7b614f1fb2e8d73969ee39a6d (patch)
tree60a1b73c67ffa679a5cc1ad9e9a839fc1d6a2617
parent90bdbb46f41c9fa670d7b0709e0c8a92ad82bdfe (diff)
ASoC: rt5677: Add a configuration option for LDO2_POW pin
Some boards have this pin statically tied and do not require any configuration, some other boards allow to enable chip using GPIO. Add an option that tells which GPIO is used to power the audio codec. Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--Documentation/devicetree/bindings/sound/rt5677.txt41
-rw-r--r--sound/soc/codecs/rt5677.c54
-rw-r--r--sound/soc/codecs/rt5677.h1
3 files changed, 96 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/rt5677.txt b/Documentation/devicetree/bindings/sound/rt5677.txt
new file mode 100644
index 000000000000..98509fb7481b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/rt5677.txt
@@ -0,0 +1,41 @@
1RT5677 audio CODEC
2
3This device supports I2C only.
4
5Required properties:
6
7- compatible : "realtek,rt5677".
8
9- reg : The I2C address of the device.
10
11- interrupts : The CODEC's interrupt output.
12
13Optional properties:
14
15- realtek,pow-ldo2-gpio : The GPIO that controls the CODEC's POW_LDO2 pin.
16
17Pins on the device (for linking into audio routes):
18
19 * IN1P
20 * IN1N
21 * IN2P
22 * IN2N
23 * MICBIAS1
24 * DMIC1
25 * DMIC2
26 * DMIC3
27 * DMIC4
28 * LOUT1
29 * LOUT2
30 * LOUT3
31
32Example:
33
34rt5677 {
35 compatible = "realtek,rt5677";
36 reg = <0x2c>;
37 interrupt-parent = <&gpio>;
38 interrupts = <TEGRA_GPIO(W, 3) GPIO_ACTIVE_HIGH>;
39 realtek,pow-ldo2-gpio =
40 <&gpio TEGRA_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
41};
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index 4a0f3dfb2a47..d2c6abf38ad2 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/pm.h> 17#include <linux/pm.h>
18#include <linux/of_gpio.h>
18#include <linux/regmap.h> 19#include <linux/regmap.h>
19#include <linux/i2c.h> 20#include <linux/i2c.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
@@ -3381,6 +3382,8 @@ static int rt5677_remove(struct snd_soc_codec *codec)
3381 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 3382 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
3382 3383
3383 regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); 3384 regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec);
3385 if (gpio_is_valid(rt5677->pow_ldo2))
3386 gpio_set_value_cansleep(rt5677->pow_ldo2, 0);
3384 3387
3385 return 0; 3388 return 0;
3386} 3389}
@@ -3392,6 +3395,8 @@ static int rt5677_suspend(struct snd_soc_codec *codec)
3392 3395
3393 regcache_cache_only(rt5677->regmap, true); 3396 regcache_cache_only(rt5677->regmap, true);
3394 regcache_mark_dirty(rt5677->regmap); 3397 regcache_mark_dirty(rt5677->regmap);
3398 if (gpio_is_valid(rt5677->pow_ldo2))
3399 gpio_set_value_cansleep(rt5677->pow_ldo2, 0);
3395 3400
3396 return 0; 3401 return 0;
3397} 3402}
@@ -3400,6 +3405,10 @@ static int rt5677_resume(struct snd_soc_codec *codec)
3400{ 3405{
3401 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 3406 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
3402 3407
3408 if (gpio_is_valid(rt5677->pow_ldo2)) {
3409 gpio_set_value_cansleep(rt5677->pow_ldo2, 1);
3410 msleep(10);
3411 }
3403 regcache_cache_only(rt5677->regmap, false); 3412 regcache_cache_only(rt5677->regmap, false);
3404 regcache_sync(rt5677->regmap); 3413 regcache_sync(rt5677->regmap);
3405 3414
@@ -3558,6 +3567,24 @@ static const struct i2c_device_id rt5677_i2c_id[] = {
3558}; 3567};
3559MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id); 3568MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id);
3560 3569
3570static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np)
3571{
3572 rt5677->pow_ldo2 = of_get_named_gpio(np,
3573 "realtek,pow-ldo2-gpio", 0);
3574
3575 /*
3576 * POW_LDO2 is optional (it may be statically tied on the board).
3577 * -ENOENT means that the property doesn't exist, i.e. there is no
3578 * GPIO, so is not an error. Any other error code means the property
3579 * exists, but could not be parsed.
3580 */
3581 if (!gpio_is_valid(rt5677->pow_ldo2) &&
3582 (rt5677->pow_ldo2 != -ENOENT))
3583 return rt5677->pow_ldo2;
3584
3585 return 0;
3586}
3587
3561static int rt5677_i2c_probe(struct i2c_client *i2c, 3588static int rt5677_i2c_probe(struct i2c_client *i2c,
3562 const struct i2c_device_id *id) 3589 const struct i2c_device_id *id)
3563{ 3590{
@@ -3576,6 +3603,33 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
3576 if (pdata) 3603 if (pdata)
3577 rt5677->pdata = *pdata; 3604 rt5677->pdata = *pdata;
3578 3605
3606 if (i2c->dev.of_node) {
3607 ret = rt5677_parse_dt(rt5677, i2c->dev.of_node);
3608 if (ret) {
3609 dev_err(&i2c->dev, "Failed to parse device tree: %d\n",
3610 ret);
3611 return ret;
3612 }
3613 } else {
3614 rt5677->pow_ldo2 = -EINVAL;
3615 }
3616
3617 if (gpio_is_valid(rt5677->pow_ldo2)) {
3618 ret = devm_gpio_request_one(&i2c->dev, rt5677->pow_ldo2,
3619 GPIOF_OUT_INIT_HIGH,
3620 "RT5677 POW_LDO2");
3621 if (ret < 0) {
3622 dev_err(&i2c->dev, "Failed to request POW_LDO2 %d: %d\n",
3623 rt5677->pow_ldo2, ret);
3624 return ret;
3625 }
3626 /* Wait a while until I2C bus becomes available. The datasheet
3627 * does not specify the exact we should wait but startup
3628 * sequence mentiones at least a few milliseconds.
3629 */
3630 msleep(10);
3631 }
3632
3579 rt5677->regmap = devm_regmap_init_i2c(i2c, &rt5677_regmap); 3633 rt5677->regmap = devm_regmap_init_i2c(i2c, &rt5677_regmap);
3580 if (IS_ERR(rt5677->regmap)) { 3634 if (IS_ERR(rt5677->regmap)) {
3581 ret = PTR_ERR(rt5677->regmap); 3635 ret = PTR_ERR(rt5677->regmap);
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h
index 1fe88727a063..d4eb6d5e6746 100644
--- a/sound/soc/codecs/rt5677.h
+++ b/sound/soc/codecs/rt5677.h
@@ -1554,6 +1554,7 @@ struct rt5677_priv {
1554 int pll_src; 1554 int pll_src;
1555 int pll_in; 1555 int pll_in;
1556 int pll_out; 1556 int pll_out;
1557 int pow_ldo2; /* POW_LDO2 pin */
1557#ifdef CONFIG_GPIOLIB 1558#ifdef CONFIG_GPIOLIB
1558 struct gpio_chip gpio_chip; 1559 struct gpio_chip gpio_chip;
1559#endif 1560#endif