All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback
@ 2021-10-01  7:41 derek.fang
  2021-10-01  7:41 ` [PATCH 2/2] ASoC: rt5682s: Fix HP noise caused by SAR mode switch when the system resumes derek.fang
  2021-10-02  0:16 ` [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: derek.fang @ 2021-10-01  7:41 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: oder_chiou, jack.yu, alsa-devel, lars, albertchen, Derek Fang,
	kevin_chen_ym, shumingf, flove

From: Derek Fang <derek.fang@realtek.com>

When codec's ASRC was enabled, the DA and AD filters use
the reference clk which tracks the I2S clks.
And if the I2S clks' timing of open and close are not expected,
this patch allows the filters to switch to use sysclk if
ASRC's ref clks disappeared and could fix the below possible issues:
1. Avoid DA filter to keep surplus samples.
2. Avoid that AD filter works failed during dapm's power on.

For example,
if I2S clks were closed before dacdat during playback off
due to jack unplug, it causes ref clks disappeared and
DA filter remained some samples which will produce pop noise
on the next HP playback.
ASRC auto-disable could clear the samples during the playback off.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
---
 sound/soc/codecs/rt5682s.c |  3 +++
 sound/soc/codecs/rt5682s.h | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c
index 122adeb7beb1..5ae54a51ff9e 100644
--- a/sound/soc/codecs/rt5682s.c
+++ b/sound/soc/codecs/rt5682s.c
@@ -1061,6 +1061,9 @@ int rt5682s_sel_asrc_clk_src(struct snd_soc_component *component,
 			RT5682S_FILTER_CLK_SEL_MASK, clk_src << RT5682S_FILTER_CLK_SEL_SFT);
 	}
 
+	snd_soc_component_update_bits(component, RT5682S_PLL_TRACK_11,
+		RT5682S_ASRCIN_AUTO_CLKOUT_MASK, RT5682S_ASRCIN_AUTO_CLKOUT_EN);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(rt5682s_sel_asrc_clk_src);
diff --git a/sound/soc/codecs/rt5682s.h b/sound/soc/codecs/rt5682s.h
index 55f1febb81e9..59ba4ea3b062 100644
--- a/sound/soc/codecs/rt5682s.h
+++ b/sound/soc/codecs/rt5682s.h
@@ -994,6 +994,19 @@
 #define RT5682S_ASRCIN_FTK_M2_MASK		(0x7 << 4)
 #define RT5682S_ASRCIN_FTK_M2_SFT		4
 
+/* ASRC Control 11 (0x008c) */
+#define RT5682S_ASRCIN_AUTO_CLKOUT_MASK		(0x1 << 5)
+#define RT5682S_ASRCIN_AUTO_CLKOUT_EN		(0x1 << 5)
+#define RT5682S_ASRCIN_AUTO_CLKOUT_DIS		(0x0 << 5)
+#define RT5682S_ASRCIN_AUTO_RST_MASK		(0x1 << 4)
+#define RT5682S_ASRCIN_AUTO_RST_EN		(0x1 << 4)
+#define RT5682S_ASRCIN_AUTO_RST_DIS		(0x0 << 4)
+#define RT5682S_SEL_LRCK_DET_MASK		(0x3)
+#define RT5682S_SEL_LRCK_DET_DIV8		(0x3)
+#define RT5682S_SEL_LRCK_DET_DIV4		(0x2)
+#define RT5682S_SEL_LRCK_DET_DIV2		(0x1)
+#define RT5682S_SEL_LRCK_DET_DIV1		(0x0)
+
 /* Depop Mode Control 1 (0x008e) */
 #define RT5682S_OUT_HP_L_EN			(0x1 << 6)
 #define RT5682S_OUT_HP_R_EN			(0x1 << 5)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ASoC: rt5682s: Fix HP noise caused by SAR mode switch when the system resumes
  2021-10-01  7:41 [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback derek.fang
@ 2021-10-01  7:41 ` derek.fang
  2021-10-02  0:16 ` [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: derek.fang @ 2021-10-01  7:41 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: oder_chiou, jack.yu, alsa-devel, lars, albertchen, Derek Fang,
	kevin_chen_ym, shumingf, flove

From: Derek Fang <derek.fang@realtek.com>

When the system resumes from S3, if the system plays a beep,
there is continuous "Zizi.." noise from HP that could be heard.
It is caused by the SAR mode switch during the combo jack
re-detection which be executed parallelly in a workqueue
after the system resumes.

This patch changes the behavior of SAR mode switch to
avoid this issue.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
---
 sound/soc/codecs/rt5682s.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/sound/soc/codecs/rt5682s.c b/sound/soc/codecs/rt5682s.c
index 5ae54a51ff9e..639a50fa95e2 100644
--- a/sound/soc/codecs/rt5682s.c
+++ b/sound/soc/codecs/rt5682s.c
@@ -779,7 +779,8 @@ static int rt5682s_headset_detect(struct snd_soc_component *component, int jack_
 				RT5682S_FAST_OFF_MASK, RT5682S_FAST_OFF_EN);
 			snd_soc_component_update_bits(component, RT5682S_SAR_IL_CMD_1,
 				RT5682S_SAR_SEL_MB1_2_MASK, val << RT5682S_SAR_SEL_MB1_2_SFT);
-			rt5682s_sar_power_mode(component, SAR_PWR_SAVING, 1);
+			if (!snd_soc_dapm_get_pin_status(&component->dapm, "SAR"))
+				rt5682s_sar_power_mode(component, SAR_PWR_SAVING, 1);
 			rt5682s_enable_push_button_irq(component);
 			break;
 		default:
@@ -1313,18 +1314,6 @@ static int is_using_asrc(struct snd_soc_dapm_widget *w,
 	}
 }
 
-static int is_headset_type(struct snd_soc_dapm_widget *w,
-		struct snd_soc_dapm_widget *sink)
-{
-	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
-	struct rt5682s_priv *rt5682s = snd_soc_component_get_drvdata(component);
-
-	if ((rt5682s->jack_type & SND_JACK_HEADSET) == SND_JACK_HEADSET)
-		return 1;
-
-	return 0;
-}
-
 static int rt5682s_hp_amp_event(struct snd_soc_dapm_widget *w,
 		struct snd_kcontrol *kcontrol, int event)
 {
@@ -1372,6 +1361,10 @@ static int sar_power_event(struct snd_soc_dapm_widget *w,
 		struct snd_kcontrol *kcontrol, int event)
 {
 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+	struct rt5682s_priv *rt5682s = snd_soc_component_get_drvdata(component);
+
+	if ((rt5682s->jack_type & SND_JACK_HEADSET) != SND_JACK_HEADSET)
+		return 0;
 
 	switch (event) {
 	case SND_SOC_DAPM_PRE_PMU:
@@ -1784,7 +1777,7 @@ static const struct snd_soc_dapm_route rt5682s_dapm_routes[] = {
 	{"CLKDET SYS", NULL, "MCLK0 DET PWR"},
 
 	{"BST1 CBJ", NULL, "IN1P"},
-	{"BST1 CBJ", NULL, "SAR", is_headset_type},
+	{"BST1 CBJ", NULL, "SAR"},
 
 	{"RECMIX1L", "CBJ Switch", "BST1 CBJ"},
 	{"RECMIX1L", NULL, "RECMIX1L Power"},
@@ -1890,7 +1883,7 @@ static const struct snd_soc_dapm_route rt5682s_dapm_routes[] = {
 	{"HP Amp", NULL, "DAC L1"},
 	{"HP Amp", NULL, "DAC R1"},
 	{"HP Amp", NULL, "CLKDET SYS"},
-	{"HP Amp", NULL, "SAR", is_headset_type},
+	{"HP Amp", NULL, "SAR"},
 
 	{"HPOL", NULL, "HP Amp"},
 	{"HPOR", NULL, "HP Amp"},
@@ -2823,8 +2816,9 @@ static int rt5682s_resume(struct snd_soc_component *component)
 
 	if (rt5682s->hs_jack) {
 		rt5682s->jack_type = 0;
+		rt5682s_sar_power_mode(component, SAR_PWR_NORMAL, 0);
 		mod_delayed_work(system_power_efficient_wq,
-			&rt5682s->jack_detect_work, msecs_to_jiffies(250));
+			&rt5682s->jack_detect_work, msecs_to_jiffies(0));
 	}
 
 	return 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback
  2021-10-01  7:41 [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback derek.fang
  2021-10-01  7:41 ` [PATCH 2/2] ASoC: rt5682s: Fix HP noise caused by SAR mode switch when the system resumes derek.fang
@ 2021-10-02  0:16 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2021-10-02  0:16 UTC (permalink / raw)
  To: lgirdwood, derek.fang
  Cc: oder_chiou, jack.yu, alsa-devel, lars, albertchen, Mark Brown,
	kevin_chen_ym, shumingf, flove

On Fri, 1 Oct 2021 15:41:12 +0800, derek.fang@realtek.com wrote:
> From: Derek Fang <derek.fang@realtek.com>
> 
> When codec's ASRC was enabled, the DA and AD filters use
> the reference clk which tracks the I2S clks.
> And if the I2S clks' timing of open and close are not expected,
> this patch allows the filters to switch to use sysclk if
> ASRC's ref clks disappeared and could fix the below possible issues:
> 1. Avoid DA filter to keep surplus samples.
> 2. Avoid that AD filter works failed during dapm's power on.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback
      commit: 04a8374c321db55834d5a9f3a9ceecb04b3cfbf5
[2/2] ASoC: rt5682s: Fix HP noise caused by SAR mode switch when the system resumes
      commit: 0b26ca1725fa16a2d28a86f89173f9df2a3fe8d7

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-02  0:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01  7:41 [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback derek.fang
2021-10-01  7:41 ` [PATCH 2/2] ASoC: rt5682s: Fix HP noise caused by SAR mode switch when the system resumes derek.fang
2021-10-02  0:16 ` [PATCH 1/2] ASoC: rt5682s: Enable ASRC auto-disable to fix pop during jack plug-in while playback Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.