[alsa-devel] Customizing simple audio card?

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Mon Oct 27 01:56:41 CET 2014


Hi Max

> diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> index cef7776..abef5ed 100644
> --- a/sound/soc/generic/simple-card.c
> +++ b/sound/soc/generic/simple-card.c
> @@ -43,6 +44,22 @@ static int asoc_simple_card_hw_params(struct
> snd_pcm_substream *substream,
>                                              SND_SOC_CLOCK_IN);
>         }
> 
> +       switch (params_rate(params)) {
> +       case 48000:
> +       case 32000:
> +       case 16000:
> +       case 8000:
> +               ret = snd_soc_dai_set_sysclk(codec_dai, 0, 12288000,
> +                                            SND_SOC_CLOCK_IN);
> +               break;
> +       case 44100:
> +       case 22050:
> +       case 11025:
> +               ret = snd_soc_dai_set_sysclk(codec_dai, 0, 11289600,
> +                                            SND_SOC_CLOCK_IN);
> +               break;
> +
> +       }
>         return ret;
>  }
> 
> but that's of course not a solution. So my question is is there any way I can
> subclass or inherit from the simple audio card driver to add such functionality
> to it?

Current simple-card already has mclk_fs support on hw_param.
So, we can add similar method ?
Below is my idea. priv->xxx is new option here.
Or you can update mclk_fs feature somehow ?

--------------
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 4f192ee..5d943a1 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -43,14 +43,21 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
-       unsigned int mclk;
+       unsigned int mclk = 0;
        int ret = 0;
 
        if (priv->mclk_fs) {
                mclk = params_rate(params) * priv->mclk_fs;
+       } else if (priv->xxx) {
+               if (0 == (12288000 % params_rate(params)))
+                       mclk = 12288000;
+               if (0 == (11289600 % params_rate(params)))
+                       mclk = 11289600;
+       }
+
+       if (mclk)
                ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
                                             SND_SOC_CLOCK_IN);
-       }
 
        return ret;
 }
--------------

Best regards
---
Kuninori Morimoto


More information about the Alsa-devel mailing list