[alsa-devel] Customizing simple audio card?
Hello,
I'm developing ALSA driver for sound hardware on Xtensa FPGA boards. The hardware is very simple, we have AIC23 codec connected to I2S bus and I2S bus master that pumps data pushed by CPU into its FIFO. Both are connected to the same clock synthesizer output. There are no other devices that need to be supported now.
Due to its simplicity the setup could happily use the simple sound card driver. But to support both 44100 and 48000 frequency ranges I need to change master clock, setting it either to 11289600 or to 12288000 Hz. I can do it in the I2S driver, but I see no way to inform audio codec of that change. I used the following hack to debug everything with the simple audio card:
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?
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
Hi Kuninori,
Thanks for your reply.
On Mon, Oct 27, 2014 at 3:56 AM, Kuninori Morimoto kuninori.morimoto.gx@renesas.com wrote:
Current simple-card already has mclk_fs support on hw_param.
Thought some more about it, indeed I can change my I2S master driver to just use constant factor to derive MCLK frequency from the requested sample rate.
So, we can add similar method ? Below is my idea. priv->xxx is new option here.
Hardcoding it seemed a bit awkward to me as well as providing full lookup table to map sample rate to MCLK frequency in the device tree. So I'll stick with the mclk_fs feature for now.
Or you can update mclk_fs feature somehow ?
participants (2)
-
Kuninori Morimoto
-
Max Filippov