aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSugar Zhang <sugar.zhang@rock-chips.com>2016-02-22 02:56:55 -0500
committerMark Brown <broonie@kernel.org>2016-02-22 06:05:21 -0500
commit6049af00fc2fac8d27f8bd064ff68b16991a80f7 (patch)
treec55281881daecb581cc7dd3a462a5e2d78edf234
parent92e963f50fc74041b5e9e744c330dca48e04f08d (diff)
ASoC: rt5640: add master clock handling for rt5640
enable/disable master clock when codec is active or not. Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--Documentation/devicetree/bindings/sound/rt5640.txt3
-rw-r--r--sound/soc/codecs/rt5640.c31
-rw-r--r--sound/soc/codecs/rt5640.h2
3 files changed, 36 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/rt5640.txt b/Documentation/devicetree/bindings/sound/rt5640.txt
index 9e62f6eb348f..57fe64643050 100644
--- a/Documentation/devicetree/bindings/sound/rt5640.txt
+++ b/Documentation/devicetree/bindings/sound/rt5640.txt
@@ -12,6 +12,9 @@ Required properties:
12 12
13Optional properties: 13Optional properties:
14 14
15- clocks: The phandle of the master clock to the CODEC
16- clock-names: Should be "mclk"
17
15- realtek,in1-differential 18- realtek,in1-differential
16- realtek,in2-differential 19- realtek,in2-differential
17- realtek,in3-differential 20- realtek,in3-differential
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index 11d032cdc658..6cd84fb2196a 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -1949,7 +1949,33 @@ static int rt5640_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
1949static int rt5640_set_bias_level(struct snd_soc_codec *codec, 1949static int rt5640_set_bias_level(struct snd_soc_codec *codec,
1950 enum snd_soc_bias_level level) 1950 enum snd_soc_bias_level level)
1951{ 1951{
1952 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1953 int ret;
1954
1952 switch (level) { 1955 switch (level) {
1956 case SND_SOC_BIAS_ON:
1957 break;
1958
1959 case SND_SOC_BIAS_PREPARE:
1960 /*
1961 * SND_SOC_BIAS_PREPARE is called while preparing for a
1962 * transition to ON or away from ON. If current bias_level
1963 * is SND_SOC_BIAS_ON, then it is preparing for a transition
1964 * away from ON. Disable the clock in that case, otherwise
1965 * enable it.
1966 */
1967 if (IS_ERR(rt5640->mclk))
1968 break;
1969
1970 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) {
1971 clk_disable_unprepare(rt5640->mclk);
1972 } else {
1973 ret = clk_prepare_enable(rt5640->mclk);
1974 if (ret)
1975 return ret;
1976 }
1977 break;
1978
1953 case SND_SOC_BIAS_STANDBY: 1979 case SND_SOC_BIAS_STANDBY:
1954 if (SND_SOC_BIAS_OFF == snd_soc_codec_get_bias_level(codec)) { 1980 if (SND_SOC_BIAS_OFF == snd_soc_codec_get_bias_level(codec)) {
1955 snd_soc_update_bits(codec, RT5640_PWR_ANLG1, 1981 snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
@@ -2088,6 +2114,11 @@ static int rt5640_probe(struct snd_soc_codec *codec)
2088 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); 2114 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2089 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 2115 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
2090 2116
2117 /* Check if MCLK provided */
2118 rt5640->mclk = devm_clk_get(codec->dev, "mclk");
2119 if (PTR_ERR(rt5640->mclk) == -EPROBE_DEFER)
2120 return -EPROBE_DEFER;
2121
2091 rt5640->codec = codec; 2122 rt5640->codec = codec;
2092 2123
2093 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF); 2124 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/rt5640.h b/sound/soc/codecs/rt5640.h
index 83a7150ddc24..1761c3a98b76 100644
--- a/sound/soc/codecs/rt5640.h
+++ b/sound/soc/codecs/rt5640.h
@@ -12,6 +12,7 @@
12#ifndef _RT5640_H 12#ifndef _RT5640_H
13#define _RT5640_H 13#define _RT5640_H
14 14
15#include <linux/clk.h>
15#include <sound/rt5640.h> 16#include <sound/rt5640.h>
16 17
17/* Info */ 18/* Info */
@@ -2097,6 +2098,7 @@ struct rt5640_priv {
2097 struct snd_soc_codec *codec; 2098 struct snd_soc_codec *codec;
2098 struct rt5640_platform_data pdata; 2099 struct rt5640_platform_data pdata;
2099 struct regmap *regmap; 2100 struct regmap *regmap;
2101 struct clk *mclk;
2100 2102
2101 int sysclk; 2103 int sysclk;
2102 int sysclk_src; 2104 int sysclk_src;