From patchwork Fri Nov 9 14:00:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen Trumtrar X-Patchwork-Id: 1720681 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 9779BDF264 for ; Fri, 9 Nov 2012 14:05:06 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TWpAf-00078i-2r; Fri, 09 Nov 2012 14:02:57 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TWp9G-0006dt-KB for linux-arm-kernel@lists.infradead.org; Fri, 09 Nov 2012 14:01:31 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1TWp8g-0000Rg-JE; Fri, 09 Nov 2012 15:00:54 +0100 Received: from str by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1TWp8e-00021W-9K; Fri, 09 Nov 2012 15:00:52 +0100 From: Steffen Trumtrar To: devicetree-discuss@lists.ozlabs.org Subject: [PATCH 3/6] ASoC: wm8974: include MCLKDIV in pll_factors Date: Fri, 9 Nov 2012 15:00:22 +0100 Message-Id: <1352469625-32024-4-git-send-email-s.trumtrar@pengutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1352469625-32024-1-git-send-email-s.trumtrar@pengutronix.de> References: <1352469625-32024-1-git-send-email-s.trumtrar@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: str@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-20121109_090130_924083_9A8DC766 X-CRM114-Status: GOOD ( 17.99 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: alsa-devel@alsa-project.org, Mark Brown , Sascha Hauer , patches@opensource.wolfsonmicro.com, Grant Likely , Rob Landley , spi-devel-general@lists.sourceforge.net, Steffen Trumtrar , Liam Girdwood , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org To calculate the integer part of the frequency ratio, the whole output path has to be considered (post and pre are optional): Ndiv = (pre * target * 4 * post) / source In the current implementation only the fixed- and pre-divider is considered, but the post-divider is omitted. To calculate Ndiv, this post divider has to be applied before any calculation happens. Otherwise Ndiv is considered to be to low in the later stages. This leads to a wrong value in the PLLN register, which in turn produces a wrong playback speed of the audio signal. This patch adds the post divider to the pll calculation. Signed-off-by: Steffen Trumtrar --- sound/soc/codecs/wm8974.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c index 9a39511..b012e4d 100644 --- a/sound/soc/codecs/wm8974.c +++ b/sound/soc/codecs/wm8974.c @@ -275,16 +275,51 @@ struct pll_ { * to allow rounding later */ #define FIXED_PLL_SIZE ((1 << 24) * 10) -static void pll_factors(struct pll_ *pll_div, +static void pll_factors(struct pll_ *pll_div, struct snd_soc_codec *codec, unsigned int target, unsigned int source) { unsigned long long Kpart; unsigned int K, Ndiv, Nmod; + u16 reg; /* There is a fixed divide by 4 in the output path */ + target *= 4; + /* target also depends on MCLKDIV */ + reg = (snd_soc_read(codec, WM8974_CLOCK) & 0xe0) >> 5; + + switch (reg) { + case WM8974_MCLKDIV_1: + reg = 1; + break; + case WM8974_MCLKDIV_1_5: + case WM8974_MCLKDIV_2: + reg = 2; + break; + case WM8974_MCLKDIV_3: + reg = 3; + break; + case WM8974_MCLKDIV_4: + reg = 4; + break; + case WM8974_MCLKDIV_6: + reg = 6; + break; + case WM8974_MCLKDIV_8: + reg = 8; + break; + case WM8974_MCLKDIV_12: + reg = 12; + break; + default: + reg = 2; + } + + target *= reg; + Ndiv = target / source; + if (Ndiv < 6) { source /= 2; pll_div->pre_div = 1; @@ -333,7 +368,7 @@ static int wm8974_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, return 0; } - pll_factors(&pll_div, freq_out, freq_in); + pll_factors(&pll_div, codec, freq_out, freq_in); snd_soc_write(codec, WM8974_PLLN, (pll_div.pre_div << 4) | pll_div.n); snd_soc_write(codec, WM8974_PLLK1, pll_div.k >> 18);