linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: cs42l51: manage mclk shutdown delay
@ 2020-10-20  9:04 Olivier Moysan
  2020-10-20 12:19 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Olivier Moysan @ 2020-10-20  9:04 UTC (permalink / raw)
  To: lgirdwood, broonie, perex, tiwai, alexandre.torgue,
	arnaud.patard, olivier.moysan
  Cc: alsa-devel, linux-arm-kernel, linux-stm32, linux-kernel,
	arnaud.pouliquen

A delay must be introduced before the shutdown down of the mclk,
as stated in CS42L51 datasheet. Otherwise the codec may
produce some noise after the end of DAPM power down sequence.
The delay between DAC and CLOCK_SUPPLY widgets is too short.
Add a delay in mclk shutdown request to manage the shutdown delay
explicitly. From experiments, at least 10ms delay is necessary.
Set delay to 20ms as recommended in Documentation/timers/timers-howto.rst
when using msleep().

Signed-off-by: Olivier Moysan <olivier.moysan@st.com>
---
Recommended Power-Down Sequence:
(see https://statics.cirrus.com/pubs/proDatasheet/CS42L51_F2.pdf)
1.    Mute the DACs and ADCs.
2.    Disable soft ramp and zero-cross volume transitions
3.    Set the PDN bit to 1.
4.    Wait at least 100 μs.
The codec will be fully powered down after this 100 μs delay.
Prior to the removal of the master clock(MCLK),
this delay of at least 100 μs must be implemented after step 3
to avoid premature disruption of the codec’s power down sequence.
---
 sound/soc/codecs/cs42l51.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index 097c4e8d9950..d151a1aa313e 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -254,8 +254,25 @@ static const struct snd_soc_dapm_widget cs42l51_dapm_widgets[] = {
 		&cs42l51_adcr_mux_controls),
 };
 
+static int mclk_event(struct snd_soc_dapm_widget *w,
+		      struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
+	struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(comp);
+
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		return clk_prepare_enable(cs42l51->mclk_handle);
+
+	/* Delay mclk shutdown to fulfill power-down sequence requirements */
+	msleep(20);
+	clk_disable_unprepare(cs42l51->mclk_handle);
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget cs42l51_dapm_mclk_widgets[] = {
-	SND_SOC_DAPM_CLOCK_SUPPLY("MCLK")
+	SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, mclk_event,
+			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 };
 
 static const struct snd_soc_dapm_route cs42l51_routes[] = {
-- 
2.17.1


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

* Re: [PATCH] ASoC: cs42l51: manage mclk shutdown delay
  2020-10-20  9:04 [PATCH] ASoC: cs42l51: manage mclk shutdown delay Olivier Moysan
@ 2020-10-20 12:19 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2020-10-20 12:19 UTC (permalink / raw)
  To: Olivier Moysan
  Cc: lgirdwood, perex, tiwai, alexandre.torgue, arnaud.patard,
	alsa-devel, linux-arm-kernel, linux-stm32, linux-kernel,
	arnaud.pouliquen

[-- Attachment #1: Type: text/plain, Size: 768 bytes --]

On Tue, Oct 20, 2020 at 11:04:57AM +0200, Olivier Moysan wrote:

> +static int mclk_event(struct snd_soc_dapm_widget *w,
> +		      struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
> +	struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(comp);
> +
> +	if (SND_SOC_DAPM_EVENT_ON(event))
> +		return clk_prepare_enable(cs42l51->mclk_handle);
> +
> +	/* Delay mclk shutdown to fulfill power-down sequence requirements */
> +	msleep(20);
> +	clk_disable_unprepare(cs42l51->mclk_handle);

Why not use a switch statement here?  The control flow is a bit odd with
what's basically an if/else done with only one branch in the if - this
isn't idiomatic for DAPM stuff apart from anything else.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2020-10-20 12:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20  9:04 [PATCH] ASoC: cs42l51: manage mclk shutdown delay Olivier Moysan
2020-10-20 12:19 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).