All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: Timur Tabi <timur@freescale.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	alsa-devel@alsa-project.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 2/2] ALSA: soc - cs4270: fix ADC/DAC rate matching
Date: Fri, 4 Jul 2008 19:44:04 +0400	[thread overview]
Message-ID: <20080704154404.GB27136@polina.dev.rtsoft.ru> (raw)
In-Reply-To: <20080704154313.GA11635@polina.dev.rtsoft.ru>

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
-- 
1.5.5.4

  parent reply	other threads:[~2008-07-04 15:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-03 14:37 [PATCH] ALSA: soc - fsl_ssi.c fix audio capture Anton Vorontsov
2008-07-03 14:42 ` Mark Brown
2008-07-04 11:02   ` Timur Tabi
2008-07-04 11:01     ` Mark Brown
2008-07-04 11:08       ` Timur Tabi
2008-07-04 14:49     ` Takashi Iwai
2008-07-04 15:43     ` Anton Vorontsov
2008-07-04 15:43       ` [PATCH 1/2] " Anton Vorontsov
2008-07-21 14:56         ` Timur Tabi
2008-07-04 15:44       ` Anton Vorontsov [this message]
2008-07-21 14:54         ` [PATCH 2/2] ALSA: soc - cs4270: fix ADC/DAC rate matching Timur Tabi
2008-07-21 11:15       ` [PATCH] ALSA: soc - fsl_ssi.c fix audio capture Anton Vorontsov
2008-07-21 14:35         ` Timur Tabi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080704154404.GB27136@polina.dev.rtsoft.ru \
    --to=avorontsov@ru.mvista.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=timur@freescale.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.