Skip to content

Commit 20afe58

Browse files
omn29broonie
authored andcommitted
ASoC: cs42l51: manage mclk shutdown delay
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> Link: https://lore.kernel.org/r/20201020150109.482-1-olivier.moysan@st.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 3f48b6e commit 20afe58

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

sound/soc/codecs/cs42l51.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,28 @@ static const struct snd_soc_dapm_widget cs42l51_dapm_widgets[] = {
254254
&cs42l51_adcr_mux_controls),
255255
};
256256

257+
static int mclk_event(struct snd_soc_dapm_widget *w,
258+
struct snd_kcontrol *kcontrol, int event)
259+
{
260+
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
261+
struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(comp);
262+
263+
switch (event) {
264+
case SND_SOC_DAPM_PRE_PMU:
265+
return clk_prepare_enable(cs42l51->mclk_handle);
266+
case SND_SOC_DAPM_POST_PMD:
267+
/* Delay mclk shutdown to fulfill power-down sequence requirements */
268+
msleep(20);
269+
clk_disable_unprepare(cs42l51->mclk_handle);
270+
break;
271+
}
272+
273+
return 0;
274+
}
275+
257276
static const struct snd_soc_dapm_widget cs42l51_dapm_mclk_widgets[] = {
258-
SND_SOC_DAPM_CLOCK_SUPPLY("MCLK")
277+
SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, mclk_event,
278+
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
259279
};
260280

261281
static const struct snd_soc_dapm_route cs42l51_routes[] = {

0 commit comments

Comments
 (0)