ASoC: ssm2602: Re-enable oscillator after suspend
Subsystems (3)
Lars-Peter Clausen
maintainerPATCH 1/3 ASoC: ssm2602: Re-enable oscillator after suspend
Currently the the internal oscillator is powered down when entering BIAS_OFF state, but not re-enabled when going back to BIAS_STANDBY. As a result the CODEC will stop working after suspend if the internal oscillator is used to generate the sysclock signal. This patch fixes it by clearing the appropriate bit in the power down register when the CODEC is re-enabled.
--- sound/soc/codecs/ssm2602.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
sound/soc/codecs/ssm2602.c +2 -1
@@ -430,7 +430,8 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai,static int ssm2602_set_bias_level (struct snd_soc_codec *codec,enum snd_soc_bias_level level) { -u16 reg =snd_soc_read (codec,SSM2602_PWR ) &0xff7f ; +u16 reg =snd_soc_read (codec,SSM2602_PWR ); + reg &= ~(PWR_POWER_OFF |PWR_OSC_PDN );switch (level) {case SND_SOC_BIAS_ON :
Signature · 1 line
1.7.2.5
Lars-Peter Clausen
maintainerPATCH 2/3 ASoC: ssm2602: Set initial bias level to standby
Set the initial bias level to standby during CODEC probe instead of leaving the CODEC powered off.
--- sound/soc/codecs/ssm2602.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
sound/soc/codecs/ssm2602.c +6 -1
@@ -577,7 +577,12 @@ static int ssm260x_probe(struct snd_soc_codec *codec)break ; } -return ret; +if (ret) +return ret; + +ssm2602_set_bias_level (codec,SND_SOC_BIAS_STANDBY ); + +return 0 ; }/* remove everything here */
Signature · 1 line
1.7.2.5
Mark Brown
AppliedRe: [PATCH 2/3] ASoC: ssm2602: Set initial bias level to standby
Quoted 4 lines · Lars-Peter Clausen
Set the initial bias level to standby during CODEC probe instead of leaving the CODEC powered off.
Signed-off-by Lars-Peter Clausen <[email protected]>
Applied, thanks.
Lars-Peter Clausen
maintainerPATCH 3/3 ASoC: ssm2602: Support setting the oscillator and the clock output state
In reply to Lars-Peter ClausenCurrently 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.
--- sound/soc/codecs/ssm2602.c | 67 +++++++++++++++++++++++++++++++++---------- sound/soc/codecs/ssm2602.h | 6 +++- 2 files changed, 56 insertions(+), 17 deletions(-)
sound/soc/codecs/ssm2602.c +51 -16
@@ -59,6 +59,7 @@ struct ssm2602_priv {struct snd_pcm_substream *slave_substream;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, {struct snd_soc_codec *codec = codec_dai->codec;struct ssm2602_priv *ssm2602 =snd_soc_codec_get_drvdata (codec); -switch (freq) { -case 11289600 : -case 12000000 : -case 12288000 : -case 16934400 : -case 18432000 : - ssm2602->sysclk = freq; -return 0 ; + +if (dir ==SND_SOC_CLOCK_IN ) { +if (clk_id !=SSM2602_SYSCLK ) +return -EINVAL ; + +switch (freq) { +case 11289600 : +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,
@@ -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,enum snd_soc_bias_level level) { -u16 reg =snd_soc_read (codec,SSM2602_PWR ); - reg &= ~(PWR_POWER_OFF |PWR_OSC_PDN ); +struct ssm2602_priv *ssm2602 =snd_soc_codec_get_drvdata (codec);switch (level) {case SND_SOC_BIAS_ON : -/* vref/mid, osc on, dac unmute */ -snd_soc_write (codec,SSM2602_PWR , reg); +/* vref/mid on, osc and clkout on if enabled */ +snd_soc_update_bits (codec,SSM2602_PWR , +PWR_POWER_OFF |PWR_CLK_OUT_PDN |PWR_OSC_PDN , + ssm2602->clk_out_pwr);break ;case SND_SOC_BIAS_PREPARE :break ;case SND_SOC_BIAS_STANDBY :/* 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 ;case SND_SOC_BIAS_OFF : -/* everything off, dac mute, inactive */ -snd_soc_write (codec,SSM2602_PWR ,0xffff ); +/* everything off */ +snd_soc_update_bits (codec,SSM2602_PWR , +PWR_POWER_OFF ,PWR_POWER_OFF );break ; }
sound/soc/codecs/ssm2602.h +5 -1
@@ -116,6 +116,10 @@#define SSM2602_CACHEREGNUM 10 -#define SSM2602_SYSCLK 0 +enum ssm2602_clk { +SSM2602_SYSCLK , +SSM2602_CLK_CLKOUT , +SSM2602_CLK_XTO +};#endif
Signature · 1 line
1.7.2.5
Re: [PATCH 3/3] ASoC: ssm2602: Support setting the oscillator and the clock output state
Quoted 10 lines · Lars-Peter Clausen
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 inBIAS_STANDBY, since no components which depend on it should be active in this state.
Is this last assumption actually true? Things like accessory detect can need clocks on devices even when they're idle from an audio point of view. Still, I've applied the patch - we can always fix up later if something needs the clock enabling.
Lars-Peter Clausen
maintainerRe: [PATCH 3/3] ASoC: ssm2602: Support setting the oscillator and the clock output state
Quoted 12 lines · Mark Brown
Quoted 10 lines · Lars-Peter Clausen
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 inBIAS_STANDBY, since no components which depend on it should be active in this state.
Quoted 4 lines
Is this last assumption actually true? Things like accessory detect can need clocks on devices even when they're idle from an audio point of view. Still, I've applied the patch - we can always fix up later if something needs the clock enabling.
At least for the ssm2602 the sysclk is only used to for audio processing and to drive the clock out signal. Audio is off in standby and the clock out signal was going to be disabled when switching to standby even before this patch. But you are correct the later might be a problem in systems where the clock out signal is used for another external component which needs a clock input signal in standby mode.
Thanks
- Lars
Mark Brown
AppliedQuoted 5 lines · Lars-Peter Clausen
Currently the the internal oscillator is powered down when entering
BIAS_OFFstate, but not re-enabled when going back toBIAS_STANDBY. As a result the CODEC will stop working after suspend if the internal oscillator is used to generate the sysclock signal. This patch fixes it by clearing the appropriate bit in the power down register when the CODEC is re-enabled.
Applied, thanks.