From patchwork Mon Mar 23 14:46:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Kleine-Budde X-Patchwork-Id: 6073691 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2A885BF90F for ; Mon, 23 Mar 2015 14:48:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E1332026D for ; Mon, 23 Mar 2015 14:48:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97E002024F for ; Mon, 23 Mar 2015 14:48:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ya3cp-0004Gq-8g; Mon, 23 Mar 2015 14:46:43 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ya3ck-00049a-98 for linux-arm-kernel@lists.infradead.org; Mon, 23 Mar 2015 14:46:39 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1Ya3cL-0000lp-UC; Mon, 23 Mar 2015 15:46:13 +0100 Received: from mkl by dude.hi.pengutronix.de with local (Exim 4.84) (envelope-from ) id 1Ya3cL-0001KH-3N; Mon, 23 Mar 2015 15:46:13 +0100 From: Marc Kleine-Budde To: alsa-devel@alsa-project.org Subject: [PATCH resend] ASoC: fsl-ssi: Fix bitclock calculation for master mode Date: Mon, 23 Mar 2015 15:46:12 +0100 Message-Id: <1427121972-5059-1-git-send-email-mkl@pengutronix.de> X-Mailer: git-send-email 2.1.4 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150323_074638_544227_95D29884 X-CRM114-Status: GOOD ( 17.19 ) X-Spam-Score: -0.0 (/) Cc: Sascha Hauer , broonie@kernel.org, Marc Kleine-Budde , linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sascha Hauer in fsl_ssi_set_bclk we are looking for the best divider by iterating over all possible dividers. The divider is in the range 1..256, so make this clear by using 'div' as name for the loop counter and iterate from 1 to 256 instead of 0 to 255. This makes obvious that tmprate is calculated wrong, it has to be freq * factor * div, not freq * factor * (i + 2). Signed-off-by: Sascha Hauer Signed-off-by: Marc Kleine-Budde --- sound/soc/fsl/fsl_ssi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index b9fabbf69db6..b8af08e49085 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c @@ -578,7 +578,7 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream, struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai); struct regmap *regs = ssi_private->regs; int synchronous = ssi_private->cpu_dai_drv.symmetric_rates, ret; - u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i; + u32 pm = 999, div2, psr, stccr, mask, afreq, factor, div; unsigned long clkrate, baudrate, tmprate; u64 sub, savesub = 100000; unsigned int freq; @@ -602,8 +602,8 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream, factor = (div2 + 1) * (7 * psr + 1) * 2; - for (i = 0; i < 255; i++) { - tmprate = freq * factor * (i + 2); + for (div = 1; div < 256; div++) { + tmprate = freq * factor * div; if (baudclk_is_used) clkrate = clk_get_rate(ssi_private->baudclk); @@ -618,7 +618,7 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream, continue; clkrate /= factor; - afreq = clkrate / (i + 1); + afreq = clkrate / div; if (freq == afreq) sub = 0; @@ -636,7 +636,7 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream, if (sub < savesub) { baudrate = tmprate; savesub = sub; - pm = i; + pm = div - 1; } /* We are lucky */