From b84b8a9ad2046a855a7044b6368def01ddd5de6e Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Fri, 21 Jul 2023 16:50:56 +0100 Subject: [PATCH] rpi sound cards: Fix Codec Zero rate switching The Raspberry Pi Codec Zero (and IQaudIO Codec) don't notify the DA7213 codec when it needs to change PLL frequencies. As a result, audio can be played at the wrong rate - play a 48kHz sound immediately after a 44.1kHz sound to see the effect, but in some configurations the codec can lock into the wrong state and always get some rates wrong. Add the necessary notification to fix the issue. Signed-off-by: Phil Elwell --- sound/soc/bcm/iqaudio-codec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/sound/soc/bcm/iqaudio-codec.c +++ b/sound/soc/bcm/iqaudio-codec.c @@ -143,6 +143,7 @@ static int snd_rpi_iqaudio_codec_hw_para struct snd_pcm_hw_params *params) { struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); unsigned int samplerate = params_rate(params); switch (samplerate) { @@ -152,15 +153,17 @@ static int snd_rpi_iqaudio_codec_hw_para case 48000: case 96000: pll_out = DA7213_PLL_FREQ_OUT_98304000; - return 0; + break; case 44100: case 88200: pll_out = DA7213_PLL_FREQ_OUT_90316800; - return 0; + break; default: dev_err(rtd->dev,"Unsupported samplerate %d\n", samplerate); return -EINVAL; } + + return snd_soc_dai_set_pll(codec_dai, 0, DA7213_SYSCLK_PLL, 0, pll_out); } static const struct snd_soc_ops snd_rpi_iqaudio_codec_ops = {