Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1294068pxf; Fri, 19 Mar 2021 04:04:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ9KH2pZQWur5w2oiqPrJpFHB1a4WCvmcl8CEbyV9UocrObRiyPBmwEYjmv/2uJsl0eOHH X-Received: by 2002:a17:906:a3d1:: with SMTP id ca17mr3686088ejb.92.1616151876736; Fri, 19 Mar 2021 04:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616151876; cv=none; d=google.com; s=arc-20160816; b=HAg7B9lZM1iLQKWtXUBN7YMZaCJ8Gm48SyFb6pQ54HaLDzTsJuzaNWPT9UhchVsRjW sgGmqVXOibcH653rtDfGjdA1QjtjILMtJreaeYiraQSE7c2BbLZCFKtTaAO9STEJgflA dbYZ8YuEaRRVUPS1KMlF39Ebz+jsm7uvk2wtRNfh+1DPhlGfAw01A97GlFkDzN7CxRP6 Uw7OWE4ne6PVMv8j29n+cOqbjH256Ka1uPdlZwokcdswGY/ColEJ88gR+iGapZ/bJIcK hk58weQMQdJuQXIEE9fgncJc/X9KD48SL44ccybVTkLtnX3axL3HR4eqXGUZEMrgMesS bQBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from; bh=yOcgmDJsVyA+dwBJU1kSVzrCxMbd2x05/S5cAl+ZruE=; b=gVde0l24huVBsWR5lUcniFlrqiy8VWMYopZff8GEauAvL0OgrTqk8Bw7Lz6m6k6S/T prOTAVyLu1tzRLqYfcoXR0iWoVtxesFH999dDGYpr2b2llYec/JdBOKTK1N7TzGF0sHh 8tz2PlQfTXHxKrbbE2cgTD4FA26f3QEDaI56k+lZC6Q/EaRcjf4U6QGHMeg0dAVBg4we lWbAV1msNDKo0SKtPwQcs8FrA7oPtrx8AMuk2FZZD5e0rLdh1MItPeE9unIq+bgzEcqa 1Gr2qMxbzKHcpGfGUEjB/uh3ohjwbdMr+wshRaFpICI5MbLvwt8/grYisy03mYY/hWe8 sDhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si3992231edr.552.2021.03.19.04.04.14; Fri, 19 Mar 2021 04:04:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230324AbhCSLDQ (ORCPT + 99 others); Fri, 19 Mar 2021 07:03:16 -0400 Received: from inva020.nxp.com ([92.121.34.13]:56274 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbhCSLCr (ORCPT ); Fri, 19 Mar 2021 07:02:47 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 92FD71A0F72; Fri, 19 Mar 2021 12:02:46 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 7A7E01A28BD; Fri, 19 Mar 2021 12:02:39 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id B4F154029D; Fri, 19 Mar 2021 12:02:30 +0100 (CET) From: Shengjiu Wang To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, shengjiu.wang@nxp.com, ckeepax@opensource.cirrus.com, kuninori.morimoto.gx@renesas.com, peter.ujfalusi@ti.com, gustavoars@kernel.org, pierre-louis.bossart@linux.intel.com, daniel.baluta@nxp.com, patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: wm8960: Fix wrong bclk and lrclk with pll enabled for some chips Date: Fri, 19 Mar 2021 18:48:46 +0800 Message-Id: <1616150926-22892-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The input MCLK is 12.288MHz, the desired output sysclk is 11.2896MHz and sample rate is 44100Hz, with the configuration pllprescale=2, postscale=sysclkdiv=1, some chip may have wrong bclk and lrclk output with pll enabled in master mode, but with the configuration pllprescale=1, postscale=2, the output clock is correct. From Datasheet, the PLL performs best when f2 is between 90MHz and 100MHz when the desired sysclk output is 11.2896MHz or 12.288MHz, so sysclkdiv = 2 (f2/8) is the best choice. So search available sysclk_divs from 2 to 1 other than from 1 to 2. Fixes: 84fdc00d519f ("ASoC: codec: wm9860: Refactor PLL out freq search") Signed-off-by: Shengjiu Wang --- sound/soc/codecs/wm8960.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index df351519a3a6..cda9cd935d4f 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -707,7 +707,13 @@ int wm8960_configure_pll(struct snd_soc_component *component, int freq_in, best_freq_out = -EINVAL; *sysclk_idx = *dac_idx = *bclk_idx = -1; - for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) { + /* + * From Datasheet, the PLL performs best when f2 is between + * 90MHz and 100MHz, the desired sysclk output is 11.2896MHz + * or 12.288MHz, then sysclkdiv = 2 is the best choice. + * So search sysclk_divs from 2 to 1 other than from 1 to 2. + */ + for (i = ARRAY_SIZE(sysclk_divs) - 1; i >= 0; --i) { if (sysclk_divs[i] == -1) continue; for (j = 0; j < ARRAY_SIZE(dac_divs); ++j) { -- 2.17.1