[PATCH v4 09/11] ASoC: cs530x: Correct MCLK reference frequency values

Vitaly Rodionov posted 11 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH v4 09/11] ASoC: cs530x: Correct MCLK reference frequency values
Posted by Vitaly Rodionov 3 months, 3 weeks ago
The MCLK frequency must be 49.152 MHz (for 48 kHz-related
sample rates) or 45.1584 MHz (for 44.1 kHz-related sample rates).

Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
---
 sound/soc/codecs/cs530x.c | 9 ++++++---
 sound/soc/codecs/cs530x.h | 6 ++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/cs530x.c b/sound/soc/codecs/cs530x.c
index cdd050c0fa2b..f0c3ed931fa8 100644
--- a/sound/soc/codecs/cs530x.c
+++ b/sound/soc/codecs/cs530x.c
@@ -1100,9 +1100,12 @@ static int cs530x_set_sysclk(struct snd_soc_component *component, int clk_id,
 
 	switch (source) {
 	case CS530X_SYSCLK_SRC_MCLK:
-		if (freq != 24560000 && freq != 22572000) {
-			dev_err(component->dev, "Invalid MCLK source rate %d\n",
-				freq);
+		switch (freq) {
+		case CS530X_SYSCLK_REF_45_1MHZ:
+		case CS530X_SYSCLK_REF_49_1MHZ:
+			break;
+		default:
+			dev_err(component->dev, "Invalid MCLK source rate %d\n", freq);
 			return -EINVAL;
 		}
 		break;
diff --git a/sound/soc/codecs/cs530x.h b/sound/soc/codecs/cs530x.h
index 758d9b1eb39d..c48a29cad702 100644
--- a/sound/soc/codecs/cs530x.h
+++ b/sound/soc/codecs/cs530x.h
@@ -174,6 +174,12 @@
 /* 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
-- 
2.43.0
Re: [PATCH v4 09/11] ASoC: cs530x: Correct MCLK reference frequency values
Posted by Mark Brown 3 months, 3 weeks ago
On Fri, Oct 17, 2025 at 05:15:36PM +0100, Vitaly Rodionov wrote:
> The MCLK frequency must be 49.152 MHz (for 48 kHz-related
> sample rates) or 45.1584 MHz (for 44.1 kHz-related sample rates).

>  	switch (source) {
>  	case CS530X_SYSCLK_SRC_MCLK:
> -		if (freq != 24560000 && freq != 22572000) {
> -			dev_err(component->dev, "Invalid MCLK source rate %d\n",
> -				freq);
> +		switch (freq) {
> +		case CS530X_SYSCLK_REF_45_1MHZ:
> +		case CS530X_SYSCLK_REF_49_1MHZ:
> +			break;
> +		default:
> +			dev_err(component->dev, "Invalid MCLK source rate %d\n", freq);
>  			return -EINVAL;
>  		}
>  		break;

This will break any existing user that sets MCLK won't it?  Hopefully
they were managing to function, even if the clocks were out of spec.
Re: [PATCH v4 09/11] ASoC: cs530x: Correct MCLK reference frequency values
Posted by Vitaly Rodionov 3 months, 3 weeks ago
On Fri, Oct 17, 2025 at 05:44:06PM +0100, Mark Brown wrote:
> On Fri, Oct 17, 2025 at 05:15:36PM +0100, Vitaly Rodionov wrote:
> > The MCLK frequency must be 49.152 MHz (for 48 kHz-related
> > sample rates) or 45.1584 MHz (for 44.1 kHz-related sample rates).
> 
> >  	switch (source) {
> >  	case CS530X_SYSCLK_SRC_MCLK:
> > -		if (freq != 24560000 && freq != 22572000) {
> > -			dev_err(component->dev, "Invalid MCLK source rate %d\n",
> > -				freq);
> > +		switch (freq) {
> > +		case CS530X_SYSCLK_REF_45_1MHZ:
> > +		case CS530X_SYSCLK_REF_49_1MHZ:
> > +			break;
> > +		default:
> > +			dev_err(component->dev, "Invalid MCLK source rate %d\n", freq);
> >  			return -EINVAL;
> >  		}
> >  		break;
> 
> This will break any existing user that sets MCLK won't it?  Hopefully
> they were managing to function, even if the clocks were out of spec.

Hopefully, there are no existing users yet. This was used only on our development board,
and we’d like to fix it proactively before any users encounter issues.