CS4270 is unable to handle different rates separately for ADC and DAC, so the rates should always match. This patch fixes it so that the first substream that configured the codec will own hardware parameters, thus subsequent substreams should comply with existing parameters or bail out.
This patch fixes the issue when capture substream may ruin the playback, and vice versa.
Signed-off-by: Anton Vorontsov avorontsov@ru.mvista.com --- sound/soc/codecs/cs4270.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index d250491..d5a7a00 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -45,6 +45,8 @@ struct cs4270_private { unsigned int mclk; /* Input frequency of the MCLK pin */ unsigned int mode; /* The mode (I2S or left-justified) */ + struct snd_pcm_substream *master_substream; /* Owns hw_params */ + unsigned int rate; /* Rate that master substream has configured */ };
/* @@ -383,6 +385,19 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, rate = params_rate(params); /* Sampling rate, in Hz */ ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
+ /* + * CODEC is using the same rate for ADC and DAC. If, for example, + * we're currently playing something with one rate, we must use the + * same rate for recording. The substream that did hw_params first + * wins. + */ + if (!cs4270->master_substream) + cs4270->master_substream = substream; + else if (cs4270->master_substream != substream && + cs4270->rate != rate) + return -EINVAL; + cs4270->rate = rate; + for (i = 0; i < NUM_MCLK_RATIOS; i++) { if (cs4270_mode_ratios[i].ratio == ratio) break; @@ -462,6 +477,20 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, return ret; }
+static int cs4270_hw_free(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct cs4270_private *cs4270 = rtd->socdev->codec->private_data; + + /* + * Master substream don't want to own the hw params anymore, so from + * now on other streams could do their own params. + */ + if (cs4270->master_substream == substream) + cs4270->master_substream = NULL; + return 0; +} + #ifdef CONFIG_SND_SOC_CS4270_HWMUTE
/* @@ -745,6 +774,7 @@ static int cs4270_probe(struct platform_device *pdev) if (codec->control_data) { /* Initialize codec ops */ cs4270_dai.ops.hw_params = cs4270_hw_params; + cs4270_dai.ops.hw_free = cs4270_hw_free; cs4270_dai.dai_ops.set_sysclk = cs4270_set_dai_sysclk; cs4270_dai.dai_ops.set_fmt = cs4270_set_dai_fmt; #ifdef CONFIG_SND_SOC_CS4270_HWMUTE