ad1836/ad1938: PM and typo fix/cleanup
Subsystems (3)
cover ad1836/ad1938: PM and typo fix/cleanup
Hi Mark,
The following 3 patches fix/cleanup PM and typo of ad1836/ad1938 codec driver:
1. ad1836: reset and restore clock control mode in suspend/resume entry
2. ad1938: fix typo, rename mask to rx_mask for ad1938_set_tdm_slot
3. ad1938:let soc-core dapm handle PLL power
As I will send patches special for moving to soc-cache, in patch 1, I still use the old way to read/write codec registers.
Thanks
Barry
PATCH 1/3 ad1836: reset and restore clock control mode in suspend/resume entry
Tests show frequent suspend/resume(frequent poweroff/on ad1836 internal components) maybe make ad1836 clock mode wrong sometimes after wakeup. This patch reset/restore ad1836 clock mode while executing PM, then ad1836 can always resume to right clock status.
--- sound/soc/codecs/ad1836.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-)
sound/soc/codecs/ad1836.c +32 -0
@@ -223,6 +223,36 @@ static unsigned int ad1836_read_reg_cache(struct snd_soc_codec *codec,return reg_cache[reg]; } +#ifdef CONFIG_PM +static int ad1836_soc_suspend (struct platform_device *pdev, +pm_message_t state) +{ +struct snd_soc_device *socdev =platform_get_drvdata (pdev); +struct snd_soc_codec *codec = socdev->card->codec; + +/* reset clock control mode */ +u16 adc_ctrl2 = codec->read (codec,AD1836_ADC_CTRL2 ); + adc_ctrl2 &= ~AD1836_ADC_SERFMT_MASK ; + +return codec->write (codec,AD1836_ADC_CTRL2 , adc_ctrl2); +} + +static int ad1836_soc_resume (struct platform_device *pdev) +{ +struct snd_soc_device *socdev =platform_get_drvdata (pdev); +struct snd_soc_codec *codec = socdev->card->codec; + +/* restore clock control mode */ +u16 adc_ctrl2 = codec->read (codec,AD1836_ADC_CTRL2 ); + adc_ctrl2 |=AD1836_ADC_AUX ; + +return codec->write (codec,AD1836_ADC_CTRL2 , adc_ctrl2); +} +#else +#define ad1836_soc_suspend NULL +#define ad1836_soc_resume NULL +#endif +static int __devinit ad1836_spi_probe (struct spi_device *spi) {struct snd_soc_codec *codec;
@@ -404,6 +434,8 @@ static int ad1836_remove(struct platform_device *pdev)struct snd_soc_codec_device soc_codec_dev_ad1836 = { .probe = ad1836_probe, .remove = ad1836_remove, + .suspend = ad1836_soc_suspend, + .resume = ad1836_soc_resume, };EXPORT_SYMBOL_GPL (soc_codec_dev_ad1836);
Signature · 1 line
1.5.6.3
PATCH 2/3 ad1938: fix typo, rename mask to rx_mask for ad1938_set_tdm_slot
--- sound/soc/codecs/ad1938.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
sound/soc/codecs/ad1938.c +1 -1
@@ -145,7 +145,7 @@ static inline int ad1938_pll_powerctrl(struct snd_soc_codec *codec, int cmd) }static int ad1938_set_tdm_slot (struct snd_soc_dai *dai,unsigned int tx_mask, -unsigned int mask,int slots,int width) +unsigned int rx_mask,int slots,int width) {struct snd_soc_codec *codec = dai->codec;int dac_reg = codec->read (codec,AD1938_DAC_CTRL1 );
Signature · 1 line
1.5.6.3
PATCH 3/3 ad1938:let soc-core dapm handle PLL power
PM architecture of ad1938 is simple, we don't need a bundle of functions like ad1938_pll_powerctrl, ad1938_set_bias_level for only PLL. A dapm supply will handle on/off of PLL.
Since soc-core can poweron/off PLL on-demand, we don't need to poweron/off PLL in suspend/resume entries too.
--- sound/soc/codecs/ad1938.c | 62 ++------------------------------------------ 1 files changed, 3 insertions(+), 59 deletions(-)
sound/soc/codecs/ad1938.c +3 -59
@@ -97,6 +97,7 @@ static const struct snd_kcontrol_new ad1938_snd_controls[] = {static const struct snd_soc_dapm_widget ad1938_dapm_widgets[] = {SND_SOC_DAPM_DAC ("DAC" ,"Playback" ,AD1938_DAC_CTRL0 ,0 ,1 ),SND_SOC_DAPM_ADC ("ADC" ,"Capture" ,SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_SUPPLY ("PLL_PWR" ,AD1938_PLL_CLK_CTRL0 ,0 ,1 ,NULL ,0 ),SND_SOC_DAPM_SUPPLY ("ADC_PWR" ,AD1938_ADC_CTRL0 ,0 ,1 ,NULL ,0 ),SND_SOC_DAPM_OUTPUT ("DAC1OUT" ),SND_SOC_DAPM_OUTPUT ("DAC2OUT" ),
@@ -107,6 +108,8 @@ static const struct snd_soc_dapm_widget ad1938_dapm_widgets[] = { };static const struct snd_soc_dapm_route audio_paths[] = { + {"DAC" ,NULL ,"PLL_PWR" }, + {"ADC" ,NULL ,"PLL_PWR" }, {"DAC" ,NULL ,"ADC_PWR" }, {"ADC" ,NULL ,"ADC_PWR" }, {"DAC1OUT" ,"DAC1 Switch" ,"DAC" },
@@ -134,16 +137,6 @@ static int ad1938_mute(struct snd_soc_dai *dai, int mute)return 0 ; } -static inline int ad1938_pll_powerctrl (struct snd_soc_codec *codec,int cmd) -{ -int reg = codec->read (codec,AD1938_PLL_CLK_CTRL0 ); - reg = (cmd >0 ) ? reg & (~AD1938_PLL_POWERDOWN ) : reg | -AD1938_PLL_POWERDOWN ; - codec->write (codec,AD1938_PLL_CLK_CTRL0 , reg); - -return 0 ; -} -static int ad1938_set_tdm_slot (struct snd_soc_dai *dai,unsigned int tx_mask,unsigned int rx_mask,int slots,int width) {
@@ -306,24 +299,6 @@ static int ad1938_hw_params(struct snd_pcm_substream *substream,return 0 ; } -static int ad1938_set_bias_level (struct snd_soc_codec *codec, -enum snd_soc_bias_level level) -{ -switch (level) { -case SND_SOC_BIAS_ON : -ad1938_pll_powerctrl (codec,1 ); -break ; -case SND_SOC_BIAS_PREPARE : -break ; -case SND_SOC_BIAS_STANDBY : -case SND_SOC_BIAS_OFF : -ad1938_pll_powerctrl (codec,0 ); -break ; - } - codec->bias_level = level; -return 0 ; -} -/* * interface to read/write ad1938 register */
@@ -514,7 +489,6 @@ static int ad1938_register(struct ad1938_priv *ad1938) codec->num_dai =1 ; codec->write = ad1938_write_reg; codec->read = ad1938_read_reg_cache; - codec->set_bias_level = ad1938_set_bias_level;INIT_LIST_HEAD (&codec->dapm_widgets);INIT_LIST_HEAD (&codec->dapm_paths);
@@ -559,7 +533,6 @@ static int ad1938_register(struct ad1938_priv *ad1938)static void ad1938_unregister (struct ad1938_priv *ad1938) { -ad1938_set_bias_level (&ad1938->codec,SND_SOC_BIAS_OFF );snd_soc_unregister_dai (&ad1938_dai);snd_soc_unregister_codec (&ad1938->codec);kfree (ad1938);
@@ -593,7 +566,6 @@ static int ad1938_probe(struct platform_device *pdev) ARRAY_SIZE(ad1938_dapm_widgets));snd_soc_dapm_add_routes (codec, audio_paths,ARRAY_SIZE (audio_paths)); -ad1938_set_bias_level (codec,SND_SOC_BIAS_STANDBY ); pcm_err:return ret;
@@ -610,37 +582,9 @@ static int ad1938_remove(struct platform_device *pdev)return 0 ; } -#ifdef CONFIG_PM -static int ad1938_suspend (struct platform_device *pdev, -pm_message_t state) -{ -struct snd_soc_device *socdev =platform_get_drvdata (pdev); -struct snd_soc_codec *codec = socdev->card->codec; - -ad1938_set_bias_level (codec,SND_SOC_BIAS_OFF ); -return 0 ; -} - -static int ad1938_resume (struct platform_device *pdev) -{ -struct snd_soc_device *socdev =platform_get_drvdata (pdev); -struct snd_soc_codec *codec = socdev->card->codec; - -if (codec->suspend_bias_level ==SND_SOC_BIAS_ON ) -ad1938_set_bias_level (codec,SND_SOC_BIAS_ON ); - -return 0 ; -} -#else -#define ad1938_suspend NULL -#define ad1938_resume NULL -#endif -struct snd_soc_codec_device soc_codec_dev_ad1938 = { .probe = ad1938_probe, .remove = ad1938_remove, - .suspend = ad1938_suspend, - .resume = ad1938_resume, };EXPORT_SYMBOL_GPL (soc_codec_dev_ad1938);
Signature · 1 line
1.5.6.3
Mark Brown
AppliedRe: [PATCH 1/3] ad1836: reset and restore clock control mode in suspend/resume entry
In reply to Barry SongQuoted 6 lines · Barry Song
Tests show frequent suspend/resume(frequent poweroff/on ad1836 internal components) maybe make ad1836 clock mode wrong sometimes after wakeup. This patch reset/restore ad1836 clock mode while executing PM, then ad1836 can always resume to right clock status.
Signed-off-by Barry Song <[email protected]>
Applied all three, thanks.