summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.1/950-0816-rpi-sound-cards-Fix-Codec-Zero-rate-switching.patch
blob: 82a3c9ea5b0deee8c08797b5b6c5ca71620a92c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From b84b8a9ad2046a855a7044b6368def01ddd5de6e Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
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 <phil@raspberrypi.com>
---
 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 = {