ASoC: da7219: Resolve HP detect issues relating to MCLK
Subsystems (4)
cover ASoC: da7219: Resolve HP detect issues relating to MCLK
The patch set resolves issues in the HP detect feature, relating to MCLK, where the feature can misdetect headphones as lineout.
Adam Thomson (2):
ASoC: da7219: Fix HP detection procedure for all MCLK frequencies
ASoC: Intel: bxt: Move codec sysclk config to codec_init function
sound/soc/codecs/da7219-aad.c | 31 ++++++++++++---- sound/soc/codecs/da7219.c | 53 ++++++++++++++++++--------- sound/soc/codecs/da7219.h | 5 ++- sound/soc/intel/boards/bxt_da7219_max98357a.c | 14 ++++--- 4 files changed, 73 insertions(+), 30 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 ASoC: da7219: Fix HP detection procedure for all MCLK frequencies
Currently when HP detection procedure runs for certain MCLK frequencies, when PLL is bypassed, the procedure will incorrectly report Lineout instead of Headphones due to timing incosistencies. To avoid this problem, the PLL is temporarily enabled (if currently bypassed and MCLK present) to provide consistent timings for the procedure, regardless of MCLK frequency.
--- sound/soc/codecs/da7219-aad.c | 31 +++++++++++++++++++------ sound/soc/codecs/da7219.c | 53 +++++++++++++++++++++++++++++-------------- sound/soc/codecs/da7219.h | 5 +++- 3 files changed, 64 insertions(+), 25 deletions(-)
sound/soc/codecs/da7219-aad.c +24 -7
@@ -115,19 +115,21 @@ static void da7219_aad_hptest_work(struct work_struct *work)struct da7219_priv *da7219 =snd_soc_codec_get_drvdata (codec);u16 tonegen_freq_hptest; -u8 pll_srm_sts, gain_ramp_ctrl, accdet_cfg8; +u8 pll_srm_sts, pll_ctrl, gain_ramp_ctrl, accdet_cfg8;int report =0 , ret =0 ; -/* Lock DAPM and any Kcontrols that are affected by this test */ +/* Lock DAPM, Kcontrols affected by this test and the PLL */ snd_soc_dapm_mutex_lock (dapm); -mutex_lock (&da7219->lock); +mutex_lock (&da7219->ctrl_lock); +mutex_lock (&da7219->pll_lock);/* Ensure MCLK is available for HP test procedure */ if (da7219->mclk) { ret =clk_prepare_enable (da7219->mclk);if (ret) {dev_err (codec->dev,"Failed to enable mclk - %d\n" , ret); -mutex_unlock (&da7219->lock); +mutex_unlock (&da7219->pll_lock); +mutex_unlock (&da7219->ctrl_lock);snd_soc_dapm_mutex_unlock (dapm);return ; }
@@ -136,12 +138,21 @@ static void da7219_aad_hptest_work(struct work_struct *work)/* * If MCLK not present, then we're using the internal oscillator and * require different frequency settings to achieve the same result. +* +* If MCLK is present, but PLL is not enabled then we enable it here to +* ensure a consistent detection procedure. */ pll_srm_sts =snd_soc_read (codec,DA7219_PLL_SRM_STS ); -if (pll_srm_sts &DA7219_PLL_SRM_STS_MCLK ) +if (pll_srm_sts &DA7219_PLL_SRM_STS_MCLK ) { tonegen_freq_hptest =cpu_to_le16 (DA7219_AAD_HPTEST_RAMP_FREQ ); -else + + pll_ctrl =snd_soc_read (codec,DA7219_PLL_CTRL ); +if ((pll_ctrl &DA7219_PLL_MODE_MASK ) ==DA7219_PLL_MODE_BYPASS ) +da7219_set_pll (codec,DA7219_SYSCLK_PLL , +DA7219_PLL_FREQ_OUT_98304 ); + }else { tonegen_freq_hptest =cpu_to_le16 (DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC ); + }/* Ensure gain ramping at fastest rate */ gain_ramp_ctrl =snd_soc_read (codec,DA7219_GAIN_RAMP_CTRL );
@@ -302,11 +313,17 @@ static void da7219_aad_hptest_work(struct work_struct *work)snd_soc_update_bits (codec,DA7219_HP_R_CTRL ,DA7219_HP_R_AMP_OE_MASK ,DA7219_HP_R_AMP_OE_MASK ); +/* Restore PLL to previous configuration, if re-configured */ +if ((pll_srm_sts &DA7219_PLL_SRM_STS_MCLK ) && + ((pll_ctrl &DA7219_PLL_MODE_MASK ) ==DA7219_PLL_MODE_BYPASS )) +da7219_set_pll (codec,DA7219_SYSCLK_MCLK ,0 ); +/* Remove MCLK, if previously enabled */ if (da7219->mclk)clk_disable_unprepare (da7219->mclk); -mutex_unlock (&da7219->lock); +mutex_unlock (&da7219->pll_lock); +mutex_unlock (&da7219->ctrl_lock);snd_soc_dapm_mutex_unlock (dapm);/*
sound/soc/codecs/da7219.c +36 -17
141 lines not on this page · raw message
sound/soc/codecs/da7219.h +4 -1
@@ -810,7 +810,8 @@ struct da7219_priv {bool wakeup_source;struct regulator_bulk_data supplies[DA7219_NUM_SUPPLIES ];struct regmap *regmap; -struct mutex lock; +struct mutex ctrl_lock; +struct mutex pll_lock;struct clk *mclk;unsigned int mclk_rate;
@@ -821,4 +822,6 @@ struct da7219_priv { u8 gain_ramp_ctrl; }; +int da7219_set_pll (struct snd_soc_codec *codec,int source,unsigned int fout); +#endif /* __DA7219_H */
Signature · 1 line
1.9.1
Mark Brown
maintainerApplied "ASoC: da7219: Fix HP detection procedure for all MCLK frequencies" to the asoc tree
The patch
ASoC: da7219: Fix HP detection procedure for all MCLK frequencies
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
2a0c2189d8170d52da64543cbf955f0908c15e70Mon Sep 17 00:00:00 2001
From: Adam Thomson <[email protected]>
Date: Mon, 19 Jun 2017 10:56:33 +0100
Subject: [PATCH] ASoC: da7219: Fix HP detection procedure for all MCLK
frequencies
Currently when HP detection procedure runs for certain MCLK frequencies, when PLL is bypassed, the procedure will incorrectly report Lineout instead of Headphones due to timing incosistencies. To avoid this problem, the PLL is temporarily enabled (if currently bypassed and MCLK present) to provide consistent timings for the procedure, regardless of MCLK frequency.
--- sound/soc/codecs/da7219-aad.c | 31 +++++++++++++++++++------ sound/soc/codecs/da7219.c | 53 +++++++++++++++++++++++++++++-------------- sound/soc/codecs/da7219.h | 5 +++- 3 files changed, 64 insertions(+), 25 deletions(-)
sound/soc/codecs/da7219-aad.c +24 -7
@@ -115,19 +115,21 @@ static void da7219_aad_hptest_work(struct work_struct *work)struct da7219_priv *da7219 =snd_soc_codec_get_drvdata (codec);u16 tonegen_freq_hptest; -u8 pll_srm_sts, gain_ramp_ctrl, accdet_cfg8; +u8 pll_srm_sts, pll_ctrl, gain_ramp_ctrl, accdet_cfg8;int report =0 , ret =0 ; -/* Lock DAPM and any Kcontrols that are affected by this test */ +/* Lock DAPM, Kcontrols affected by this test and the PLL */ snd_soc_dapm_mutex_lock (dapm); -mutex_lock (&da7219->lock); +mutex_lock (&da7219->ctrl_lock); +mutex_lock (&da7219->pll_lock);/* Ensure MCLK is available for HP test procedure */ if (da7219->mclk) { ret =clk_prepare_enable (da7219->mclk);if (ret) {dev_err (codec->dev,"Failed to enable mclk - %d\n" , ret); -mutex_unlock (&da7219->lock); +mutex_unlock (&da7219->pll_lock); +mutex_unlock (&da7219->ctrl_lock);snd_soc_dapm_mutex_unlock (dapm);return ; }
@@ -136,12 +138,21 @@ static void da7219_aad_hptest_work(struct work_struct *work)/* * If MCLK not present, then we're using the internal oscillator and * require different frequency settings to achieve the same result. +* +* If MCLK is present, but PLL is not enabled then we enable it here to +* ensure a consistent detection procedure. */ pll_srm_sts =snd_soc_read (codec,DA7219_PLL_SRM_STS ); -if (pll_srm_sts &DA7219_PLL_SRM_STS_MCLK ) +if (pll_srm_sts &DA7219_PLL_SRM_STS_MCLK ) { tonegen_freq_hptest =cpu_to_le16 (DA7219_AAD_HPTEST_RAMP_FREQ ); -else + + pll_ctrl =snd_soc_read (codec,DA7219_PLL_CTRL ); +if ((pll_ctrl &DA7219_PLL_MODE_MASK ) ==DA7219_PLL_MODE_BYPASS ) +da7219_set_pll (codec,DA7219_SYSCLK_PLL , +DA7219_PLL_FREQ_OUT_98304 ); + }else { tonegen_freq_hptest =cpu_to_le16 (DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC ); + }/* Ensure gain ramping at fastest rate */ gain_ramp_ctrl =snd_soc_read (codec,DA7219_GAIN_RAMP_CTRL );
@@ -302,11 +313,17 @@ static void da7219_aad_hptest_work(struct work_struct *work)snd_soc_update_bits (codec,DA7219_HP_R_CTRL ,DA7219_HP_R_AMP_OE_MASK ,DA7219_HP_R_AMP_OE_MASK ); +/* Restore PLL to previous configuration, if re-configured */ +if ((pll_srm_sts &DA7219_PLL_SRM_STS_MCLK ) && + ((pll_ctrl &DA7219_PLL_MODE_MASK ) ==DA7219_PLL_MODE_BYPASS )) +da7219_set_pll (codec,DA7219_SYSCLK_MCLK ,0 ); +/* Remove MCLK, if previously enabled */ if (da7219->mclk)clk_disable_unprepare (da7219->mclk); -mutex_unlock (&da7219->lock); +mutex_unlock (&da7219->pll_lock); +mutex_unlock (&da7219->ctrl_lock);snd_soc_dapm_mutex_unlock (dapm);/*
sound/soc/codecs/da7219.c +36 -17
141 lines not on this page · raw message
sound/soc/codecs/da7219.h +4 -1
@@ -810,7 +810,8 @@ struct da7219_priv {bool wakeup_source;struct regulator_bulk_data supplies[DA7219_NUM_SUPPLIES ];struct regmap *regmap; -struct mutex lock; +struct mutex ctrl_lock; +struct mutex pll_lock;struct clk *mclk;unsigned int mclk_rate;
@@ -821,4 +822,6 @@ struct da7219_priv { u8 gain_ramp_ctrl; }; +int da7219_set_pll (struct snd_soc_codec *codec,int source,unsigned int fout); +#endif /* __DA7219_H */
Signature · 1 line
2.11.0
PATCH 2/2 ASoC: Intel: bxt: Move codec sysclk config to codec_init function
In reply to Adam ThomsonThe MCLK for DA7219 does not change in this platform, but is currently being configured everytime as part of the platform_clock event handler for DAPM. The upshot of this is that we have unnecessary calls to this function, and it also means that if a stream hasn't yet been started, DA7219 driver does not have the correct MCLK rates programmed and so the HP detection feature does not operate as expected.
This patch rectifies this issue by moving the sysclk call to codec_init function so it's only called once at initialisation.
--- sound/soc/intel/boards/bxt_da7219_max98357a.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
sound/soc/intel/boards/bxt_da7219_max98357a.c +9 -5
@@ -89,11 +89,6 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (ret)dev_err (card->dev,"failed to stop PLL: %d\n" , ret); }else if (SND_SOC_DAPM_EVENT_ON (event)) { - ret =snd_soc_dai_set_sysclk (codec_dai, -DA7219_CLKSRC_MCLK ,19200000 ,SND_SOC_CLOCK_IN ); -if (ret) -dev_err (card->dev,"can't set codec sysclk configuration\n" ); - ret =snd_soc_dai_set_pll (codec_dai,0 ,DA7219_SYSCLK_PLL_SRM ,0 ,DA7219_PLL_FREQ_OUT_98304 );if (ret)
@@ -187,8 +182,17 @@ static int broxton_ssp_fixup(struct snd_soc_pcm_runtime *rtd,static int broxton_da7219_codec_init (struct snd_soc_pcm_runtime *rtd) {int ret; +struct snd_soc_dai *codec_dai = rtd->codec_dai;struct snd_soc_codec *codec = rtd->codec; +/* Configure sysclk for codec */ + ret =snd_soc_dai_set_sysclk (codec_dai,DA7219_CLKSRC_MCLK ,19200000 , +SND_SOC_CLOCK_IN ); +if (ret) { +dev_err (rtd->dev,"can't set codec sysclk configuration\n" ); +return ret; + } +/* * Headset buttons map to the google Reference headset. * These can be configured by userspace.
Signature · 1 line
1.9.1
Mark Brown
maintainerApplied "ASoC: Intel: bxt: Move codec sysclk config to codec_init function" to the asoc tree
The patch
ASoC: Intel: bxt: Move codec sysclk config to codec_init function
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
fd0f237572ada2b18fe1e8684ae9fa131b577a17Mon Sep 17 00:00:00 2001
From: Adam Thomson <[email protected]>
Date: Mon, 19 Jun 2017 10:56:34 +0100
Subject: [PATCH] ASoC: Intel: bxt: Move codec sysclk config to codec_init
function
The MCLK for DA7219 does not change in this platform, but is currently being configured everytime as part of the platform_clock event handler for DAPM. The upshot of this is that we have unnecessary calls to this function, and it also means that if a stream hasn't yet been started, DA7219 driver does not have the correct MCLK rates programmed and so the HP detection feature does not operate as expected.
This patch rectifies this issue by moving the sysclk call to codec_init function so it's only called once at initialisation.
--- sound/soc/intel/boards/bxt_da7219_max98357a.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
sound/soc/intel/boards/bxt_da7219_max98357a.c +9 -5
@@ -89,11 +89,6 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (ret)dev_err (card->dev,"failed to stop PLL: %d\n" , ret); }else if (SND_SOC_DAPM_EVENT_ON (event)) { - ret =snd_soc_dai_set_sysclk (codec_dai, -DA7219_CLKSRC_MCLK ,19200000 ,SND_SOC_CLOCK_IN ); -if (ret) -dev_err (card->dev,"can't set codec sysclk configuration\n" ); - ret =snd_soc_dai_set_pll (codec_dai,0 ,DA7219_SYSCLK_PLL_SRM ,0 ,DA7219_PLL_FREQ_OUT_98304 );if (ret)
@@ -187,8 +182,17 @@ static int broxton_ssp_fixup(struct snd_soc_pcm_runtime *rtd,static int broxton_da7219_codec_init (struct snd_soc_pcm_runtime *rtd) {int ret; +struct snd_soc_dai *codec_dai = rtd->codec_dai;struct snd_soc_codec *codec = rtd->codec; +/* Configure sysclk for codec */ + ret =snd_soc_dai_set_sysclk (codec_dai,DA7219_CLKSRC_MCLK ,19200000 , +SND_SOC_CLOCK_IN ); +if (ret) { +dev_err (rtd->dev,"can't set codec sysclk configuration\n" ); +return ret; + } +/* * Headset buttons map to the google Reference headset. * These can be configured by userspace.
Signature · 1 line
2.11.0