]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: cs530x: Fix expected MCLK rates for CS5302/4/8
authorAhmad Fatoum <a.fatoum@pengutronix.de>
Wed, 17 Jun 2026 14:47:53 +0000 (16:47 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 22 Jun 2026 17:28:52 +0000 (18:28 +0100)
When this driver was first added, it accepted rates of 24.56 MHz and
22.572 MHz for the MCLK when PLL bypass is enabled.

These rates seem to have no basis in the datasheets and were thus replaced
with 45.1584 MHz and 49.152 MHz, respectively, in commit e7ab858390f2
("ASoC: cs530x: Correct MCLK reference frequency values").

While the new rates are indeed correct for the CS4xxx ICs[0][1][2][3],
they are incorrect for the CS530x ICs the driver was originally written to
support as the MCLK frequencies are halved there[4][5][6].

Fix this by checking against the correct type-appropriate rates.

While at it, drop the CS530X_SYSCLK_REF_* macros. They arguably confuse
more than they help, especially as they are not applicable to the
cs5302/4/8.

[0]: https://statics.cirrus.com/pubs/proDatasheet/CS4282P_DS1318F1.pdf
[1]: https://statics.cirrus.com/pubs/proDatasheet/CS4302P_DS1315F1.pdf
[2]: https://statics.cirrus.com/pubs/proDatasheet/CS4304P_DS1316F1.pdf
[3]: https://statics.cirrus.com/pubs/proDatasheet/CS4308P_DS1317F1.pdf
[4]: https://statics.cirrus.com/pubs/proDatasheet/CS5302P_DS1312F1.pdf
[5]: https://statics.cirrus.com/pubs/proDatasheet/CS5304P_DS1313F1.pdf
[6]: https://statics.cirrus.com/pubs/proDatasheet/CS5308P_DS1314F1.pdf

Fixes: 2884c29152c0 ("ASoC: cs530x: Support for cs530x ADCs")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20260617-cs530x-mclk-v1-1-0215b5f1a0a4@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cs530x.c
sound/soc/codecs/cs530x.h

index 18b5ff75feec4b84871ac5553e0357b80742366e..2c7e331359117c0d348a5d3284118100488763c1 100644 (file)
@@ -1093,6 +1093,29 @@ static int cs530x_component_probe(struct snd_soc_component *component)
        return 0;
 }
 
+static bool cs530x_mclk_freq_is_valid(struct cs530x_priv *cs530x,
+                                     unsigned int freq)
+{
+       /*
+        * All these chips support 48 kHz- and 44.1 kHz-related sample rates,
+        * but they differ in what MCLK frequency is required for achieving
+        * the sample rate.
+        */
+       switch (cs530x->devtype) {
+       case CS4282:
+       case CS4302:
+       case CS4304:
+       case CS4308:
+               return freq == 49152000 || freq == 45158400;
+       case CS5302:
+       case CS5304:
+       case CS5308:
+               return freq == 24576000 || freq == 22579200;
+       }
+
+       return false;
+}
+
 static int cs530x_set_sysclk(struct snd_soc_component *component, int clk_id,
                             int source, unsigned int freq, int dir)
 {
@@ -1101,11 +1124,7 @@ static int cs530x_set_sysclk(struct snd_soc_component *component, int clk_id,
 
        switch (source) {
        case CS530X_SYSCLK_SRC_MCLK:
-               switch (freq) {
-               case CS530X_SYSCLK_REF_45_1MHZ:
-               case CS530X_SYSCLK_REF_49_1MHZ:
-                       break;
-               default:
+               if (!cs530x_mclk_freq_is_valid(cs530x, freq)) {
                        dev_err(component->dev, "Invalid MCLK source rate %d\n", freq);
                        return -EINVAL;
                }
index 1e2f6a7a589c1989c5e7bedc88a7afb6df4ac394..18aa4dfd0c860781e61c89b1a67cfd38ea133648 100644 (file)
 /* IN_VOL_CTL5 and OUT_VOL_CTL5 */
 #define CS530X_INOUT_VU                        BIT(0)
 
-/* MCLK Reference Source Frequency */
-/* 41KHz related */
-#define CS530X_SYSCLK_REF_45_1MHZ      45158400
-/* 48KHz related */
-#define CS530X_SYSCLK_REF_49_1MHZ      49152000
-
 /* System Clock Source */
 #define CS530X_SYSCLK_SRC_MCLK         0
 #define CS530X_SYSCLK_SRC_PLL          1