diff mbox

[2/2] ASoC: davinci-mcasp: Allow best effort in selecting BCLK divider

Message ID 6f645a7d31219c4410db31030a3ab07a4af6ae0e.1402652359.git.jsarha@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jyri Sarha June 13, 2014, 9:50 a.m. UTC
Do not fail if the exact BLCK rate can not be produced, just print a
warning. Check that sysclk frequency is set before implicitly setting
the BCLK divider.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
---
 sound/soc/davinci/davinci-mcasp.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Mark Brown June 21, 2014, 10:04 a.m. UTC | #1
On Fri, Jun 13, 2014 at 12:50:00PM +0300, Jyri Sarha wrote:
> Do not fail if the exact BLCK rate can not be produced, just print a
> warning. Check that sysclk frequency is set before implicitly setting
> the BCLK divider.

I've appled this but not as a fix - it's kind of on the edge if we
should be doing this at all, it's helpful for interoperability but
getting an inexact frequency obviously impacts the resulting audio.
diff mbox

Patch

diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 0ee4986..e26a89d 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -676,14 +676,18 @@  static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
 	int ret;
 
 	/* If mcasp is BCLK master we need to set BCLK divider */
-	if (mcasp->bclk_master) {
+	if (mcasp->bclk_master && mcasp->sysclk_freq) {
 		unsigned int bclk_freq = snd_soc_params_to_bclk(params);
+		unsigned int div = mcasp->sysclk_freq / bclk_freq;
 		if (mcasp->sysclk_freq % bclk_freq != 0) {
-			dev_err(mcasp->dev, "Can't produce required BCLK\n");
-			return -EINVAL;
+			if (((mcasp->sysclk_freq / div) - bclk_freq) >
+			    (bclk_freq - (mcasp->sysclk_freq / (div+1))))
+				div++;
+			dev_warn(mcasp->dev,
+				 "Inaccurate BCLK: %u Hz / %u != %u Hz\n",
+				 mcasp->sysclk_freq, div, bclk_freq);
 		}
-		davinci_mcasp_set_clkdiv(
-			cpu_dai, 1, mcasp->sysclk_freq / bclk_freq);
+		davinci_mcasp_set_clkdiv(cpu_dai, 1, div);
 	}
 
 	ret = mcasp_common_hw_param(mcasp, substream->stream,