Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp951157pxb; Wed, 3 Mar 2021 22:15:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5E8NBCUZ4AlS6/iLc3rX5PHnPZNXWRGKeOv/8yjmuILoP41t/5syKwC13F7zJjZjbVTZd X-Received: by 2002:a05:6402:30a2:: with SMTP id df2mr2599236edb.29.1614838555508; Wed, 03 Mar 2021 22:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614838555; cv=none; d=google.com; s=arc-20160816; b=NVBCl3vmYAcopcqvOAIyZudeVvFvbo7wGJAz5fQDcQDwDYvcx0RVVqW13bqaIZpbSx 6UgL6y4oILH7wZz07pRpY8YSVywM0TOg5f4IEkId+lbyUGuwgVJOYv9J0xqkU0701sjf WYZvagVCrnjeK3+awfF+hcf1Lt6y70B9JByDsffwhMh3Jc7Ah6cNTiDluT0bP4VTHDJz uqCdBzM2EAAXvC9tDZ1xPkhwcp+PjxvktiUsk6qKtxNsuG+tNhsHo1D6iXyXsnjiAlb1 qcAko+2MiYVFmTBGXS+CsOk5mKF7Kq6qAVXMS+RB5u/zLXkCxh7mLYcLX1I03z92d4Wa +SKQ== 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=L+57s0Z1jQULMGdtU3DhEsJxoWYOFEt5V4T5puHN10o=; b=qeRPM+boJR0Yuf+7aOhBE0CY3LAHvjnDvGRnHRImv7ihWFpAxeQ64n6Xq7Jw+82kZP kd2vpE7i/ayXZJYfyygxcxmV9BUrzCDmDEq/RP0optUJI4N8QsG3sBHvjoed36WSnXwU DOoeZ84S0wTrvX9CWspXGsPOM9C3te1tooeTdt8SUq8DgB/ezsqE1Ve5rdhUqTtI8gCk tzAZ3cVTDLHeN98Zo6Hk90eWV4bRpx8Rkzz2zPwV3/sXs8Szoe/ZG4Xh/DufZxbg3GHh mbFyFaSjvmrv46eVFeYOBGcCR+bdF/GfLq8sBcwfODfC68J0xhHWIprg3X9X7HwpW//N A/DQ== 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 r25si4102447ejs.195.2021.03.03.22.15.32; Wed, 03 Mar 2021 22:15:55 -0800 (PST) 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 S1350395AbhCBMVJ (ORCPT + 99 others); Tue, 2 Mar 2021 07:21:09 -0500 Received: from inva020.nxp.com ([92.121.34.13]:51238 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383694AbhCBL5m (ORCPT ); Tue, 2 Mar 2021 06:57:42 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 232CA1A0716; Tue, 2 Mar 2021 12:30:57 +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 494451A06FF; Tue, 2 Mar 2021 12:30:50 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 8515F402B4; Tue, 2 Mar 2021 12:30:42 +0100 (CET) From: Shengjiu Wang To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, kstewart@linuxfoundation.org, allison@lohutok.net, shengjiu.wang@nxp.com, tglx@linutronix.de, info@metux.net, ckeepax@opensource.wolfsonmicro.com, patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: wm8960: Remove bitclk relax condition Date: Tue, 2 Mar 2021 19:18:11 +0800 Message-Id: <1614683891-29255-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 From: Daniel Baluta Using a higher bitclk then expected doesn't always work. Here is an example: aplay -Dhw:0,0 -d 5 -r 48000 -f S24_LE -c 2 audio48k24b2c.wav In this case, the required bitclk is 48000 * 24 * 2 = 2304000 but the closest bitclk that can be derived is 3072000. Since the clock is faster than expected, it will start to send bytes from the next channel so the sound will be corrupted. Fixes: 82bab88910ee ("ASoC: codec: wm8960: Relax bit clock computation when using PLL") Fixes: 3c01b9ee2ab9 ("ASoC: codec: wm8960: Relax bit clock computation") Signed-off-by: Daniel Baluta Signed-off-by: Shengjiu Wang --- sound/soc/codecs/wm8960.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index df351519a3a6..368bec1dfbdb 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -608,10 +608,6 @@ static const int bclk_divs[] = { * - lrclk = sysclk / dac_divs * - 10 * bclk = sysclk / bclk_divs * - * If we cannot find an exact match for (sysclk, lrclk, bclk) - * triplet, we relax the bclk such that bclk is chosen as the - * closest available frequency greater than expected bclk. - * * @wm8960: codec private data * @mclk: MCLK used to derive sysclk * @sysclk_idx: sysclk_divs index for found sysclk @@ -629,7 +625,7 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, { int sysclk, bclk, lrclk; int i, j, k; - int diff, closest = mclk; + int diff; /* marker for no match */ *bclk_idx = -1; @@ -653,12 +649,6 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, *bclk_idx = k; break; } - if (diff > 0 && closest > diff) { - *sysclk_idx = i; - *dac_idx = j; - *bclk_idx = k; - closest = diff; - } } if (k != ARRAY_SIZE(bclk_divs)) break; @@ -676,10 +666,6 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, * - freq_out = sysclk * sysclk_divs * - 10 * sysclk = bclk * bclk_divs * - * If we cannot find an exact match for (sysclk, lrclk, bclk) - * triplet, we relax the bclk such that bclk is chosen as the - * closest available frequency greater than expected bclk. - * * @component: component structure * @freq_in: input frequency used to derive freq out via PLL * @sysclk_idx: sysclk_divs index for found sysclk @@ -697,14 +683,12 @@ int wm8960_configure_pll(struct snd_soc_component *component, int freq_in, { struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component); int sysclk, bclk, lrclk, freq_out; - int diff, closest, best_freq_out; + int diff; int i, j, k; bclk = wm8960->bclk; lrclk = wm8960->lrclk; - closest = freq_in; - best_freq_out = -EINVAL; *sysclk_idx = *dac_idx = *bclk_idx = -1; for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) { @@ -725,18 +709,11 @@ int wm8960_configure_pll(struct snd_soc_component *component, int freq_in, *bclk_idx = k; return freq_out; } - if (diff > 0 && closest > diff) { - *sysclk_idx = i; - *dac_idx = j; - *bclk_idx = k; - closest = diff; - best_freq_out = freq_out; - } } } } - return best_freq_out; + return -EINVAL; } static int wm8960_configure_clocking(struct snd_soc_component *component) { -- 2.27.0