Commit 02890535 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown

ASoC: ssm2602: Support setting the oscillator and the clock output state

Currently the oscillator is always enabled and the clock output is always
disabled. This patch adds support for controlling the oscillator and clock
output state through snd_soc_dai_set_sysclk. Which makes it possible to
disable or enable them dynamically according to the requirements of the board
on which the CODEC is used.

This patch also slightly modifies the behavior as to when the oscillator is
going to be disabled in low-power states. Previously it would only be disabled
in BIAS_OFF, now it is also going to be disabled in BIAS_STANDBY, since no
components which depend on it should be active in this state.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent a9d1974e
...@@ -59,6 +59,7 @@ struct ssm2602_priv { ...@@ -59,6 +59,7 @@ struct ssm2602_priv {
struct snd_pcm_substream *slave_substream; struct snd_pcm_substream *slave_substream;
enum ssm2602_type type; enum ssm2602_type type;
unsigned int clk_out_pwr;
}; };
/* /*
...@@ -356,16 +357,46 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, ...@@ -356,16 +357,46 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
{ {
struct snd_soc_codec *codec = codec_dai->codec; struct snd_soc_codec *codec = codec_dai->codec;
struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
switch (freq) {
case 11289600: if (dir == SND_SOC_CLOCK_IN) {
case 12000000: if (clk_id != SSM2602_SYSCLK)
case 12288000: return -EINVAL;
case 16934400:
case 18432000: switch (freq) {
ssm2602->sysclk = freq; case 11289600:
return 0; case 12000000:
case 12288000:
case 16934400:
case 18432000:
ssm2602->sysclk = freq;
break;
default:
return -EINVAL;
}
} else {
unsigned int mask;
switch (clk_id) {
case SSM2602_CLK_CLKOUT:
mask = PWR_CLK_OUT_PDN;
break;
case SSM2602_CLK_XTO:
mask = PWR_OSC_PDN;
break;
default:
return -EINVAL;
}
if (freq == 0)
ssm2602->clk_out_pwr |= mask;
else
ssm2602->clk_out_pwr &= ~mask;
snd_soc_update_bits(codec, SSM2602_PWR,
PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr);
} }
return -EINVAL;
return 0;
} }
static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
...@@ -430,23 +461,27 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, ...@@ -430,23 +461,27 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,
static int ssm2602_set_bias_level(struct snd_soc_codec *codec, static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level) enum snd_soc_bias_level level)
{ {
u16 reg = snd_soc_read(codec, SSM2602_PWR); struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
reg &= ~(PWR_POWER_OFF | PWR_OSC_PDN);
switch (level) { switch (level) {
case SND_SOC_BIAS_ON: case SND_SOC_BIAS_ON:
/* vref/mid, osc on, dac unmute */ /* vref/mid on, osc and clkout on if enabled */
snd_soc_write(codec, SSM2602_PWR, reg); snd_soc_update_bits(codec, SSM2602_PWR,
PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
ssm2602->clk_out_pwr);
break; break;
case SND_SOC_BIAS_PREPARE: case SND_SOC_BIAS_PREPARE:
break; break;
case SND_SOC_BIAS_STANDBY: case SND_SOC_BIAS_STANDBY:
/* everything off except vref/vmid, */ /* everything off except vref/vmid, */
snd_soc_write(codec, SSM2602_PWR, reg | PWR_CLK_OUT_PDN); snd_soc_update_bits(codec, SSM2602_PWR,
PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN,
PWR_CLK_OUT_PDN | PWR_OSC_PDN);
break; break;
case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_OFF:
/* everything off, dac mute, inactive */ /* everything off */
snd_soc_write(codec, SSM2602_PWR, 0xffff); snd_soc_update_bits(codec, SSM2602_PWR,
PWR_POWER_OFF, PWR_POWER_OFF);
break; break;
} }
......
...@@ -116,6 +116,10 @@ ...@@ -116,6 +116,10 @@
#define SSM2602_CACHEREGNUM 10 #define SSM2602_CACHEREGNUM 10
#define SSM2602_SYSCLK 0 enum ssm2602_clk {
SSM2602_SYSCLK,
SSM2602_CLK_CLKOUT,
SSM2602_CLK_XTO
};
#endif #endif
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