Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1577173pxb; Mon, 8 Mar 2021 00:37:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3yUwvdHoAhXQpkodOqqzjN/8/LFoR6ylnyyjxGKIPvRo3Bsz9NYWnkThQXzZA1AChm2eU X-Received: by 2002:a17:907:119b:: with SMTP id uz27mr13692723ejb.464.1615192632006; Mon, 08 Mar 2021 00:37:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615192632; cv=none; d=google.com; s=arc-20160816; b=Xgs0CsBOHqVgEiqny+QhvGeOGgk1Ylml2GwbgzwAx1sc8RDABhKO9ga0ksMylXk6N9 mRquKkMa7p31yFQSU+PFhuZTRfmGNo8T8MoZnhlgA/E/KSoC38yz1V8CRTg2MDfUtvqn jfehdUuio9elo4DXHFR32CoP7k/dVjSXbymV+96NXIHqdqfD0JuQbExfipEzEvWW3he3 vX7Il9EEXDpJw9kK5OAL2LukDOkooe73l9pXkVNLPTwb+dWUWrLKYhcw137aoHJLMv6x LUXKMpOHOK+VYEAUiizwwZsmb2uGLVDO5FYUi3NShxMyegZSdw6zZBk3eJiJgRTaL+3C GvCQ== 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=Jisb0P28WTR2AVIGZt5C1q0rWz/EyW5mtzpaycigV/w=; b=OUOj5noIft0aN7nhAUypTwGFmSkBswPI39CggPdwPzPUBS2KirnEdivw0iVMXgJaYF CPZb2zYONdXD9u4vFEm97HCvh9PQJIS4Llgx+h/PjJeCHozU/BsDQCMjX04VBX+KBSuw SPC/Zv/uolXeA08g4RA5bzHS7IiV7vO4U0KLUMtOB+zkbrPuqNfAIfcuSkQLmSOij0iy KStGEEwryeGwrYHy8WMbV8zBoDNOtqJ/TDEVd//wTjrNTrJ9dBuoO+IEIxK4eIwQ+08v iPqcw0k9ZA0umvJ3lJ++ZxVh3UE8BjewiWKrLFuHnuN87TiOnl9Pu1iMJ5CSj8Fpg3I1 1eug== 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 s23si6384396eja.266.2021.03.08.00.36.49; Mon, 08 Mar 2021 00:37:11 -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 S231335AbhCHCr6 (ORCPT + 99 others); Sun, 7 Mar 2021 21:47:58 -0500 Received: from inva021.nxp.com ([92.121.34.21]:42820 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231522AbhCHCrd (ORCPT ); Sun, 7 Mar 2021 21:47:33 -0500 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 720F1200E4D; Mon, 8 Mar 2021 03:47:30 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id CEBFF20177F; Mon, 8 Mar 2021 03:47:23 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 1308A402C9; Mon, 8 Mar 2021 03:47:16 +0100 (CET) From: Shengjiu Wang To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, ckeepax@opensource.cirrus.com, kuninori.morimoto.gx@renesas.com, shengjiu.wang@nxp.com, festevam@gmail.com, gustavoars@kernel.org, sebastian.krzyszkowiak@puri.sm, patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ASoC: wm8962: Relax bit clock divider searching Date: Mon, 8 Mar 2021 10:34:37 +0800 Message-Id: <1615170877-25918-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 With S20_3LE format case, the sysclk = rate * 384, the bclk = rate * 20 * 2, there is no proper bclk divider for 384 / 40, because current condition needs exact match. So driver fails to configure the clocking: wm8962 3-001a: Unsupported BCLK ratio 9 Fix this by relaxing bitclk divider searching, so that when no exact value can be derived from sysclk pick the closest value greater than expected bitclk. Signed-off-by: Shengjiu Wang Reviewed-by: Daniel Baluta --- changes in v2: - Add debug message according to Charles's comments sound/soc/codecs/wm8962.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c index ce4666a74793..34080f497584 100644 --- a/sound/soc/codecs/wm8962.c +++ b/sound/soc/codecs/wm8962.c @@ -2403,6 +2403,7 @@ static const int sysclk_rates[] = { static void wm8962_configure_bclk(struct snd_soc_component *component) { struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component); + int best, min_diff, diff; int dspclk, i; int clocking2 = 0; int clocking4 = 0; @@ -2473,23 +2474,25 @@ static void wm8962_configure_bclk(struct snd_soc_component *component) dev_dbg(component->dev, "DSPCLK is %dHz, BCLK %d\n", dspclk, wm8962->bclk); - /* We're expecting an exact match */ + /* Search a proper bclk, not exact match. */ + best = 0; + min_diff = INT_MAX; for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) { if (bclk_divs[i] < 0) continue; - if (dspclk / bclk_divs[i] == wm8962->bclk) { - dev_dbg(component->dev, "Selected BCLK_DIV %d for %dHz\n", - bclk_divs[i], wm8962->bclk); - clocking2 |= i; + diff = (dspclk / bclk_divs[i]) - wm8962->bclk; + if (diff < 0) /* Table is sorted */ break; + if (diff < min_diff) { + best = i; + min_diff = diff; } } - if (i == ARRAY_SIZE(bclk_divs)) { - dev_err(component->dev, "Unsupported BCLK ratio %d\n", - dspclk / wm8962->bclk); - return; - } + wm8962->bclk = dspclk / bclk_divs[best]; + clocking2 |= best; + dev_dbg(component->dev, "Selected BCLK_DIV %d for %dHz\n", + bclk_divs[best], wm8962->bclk); aif2 |= wm8962->bclk / wm8962->lrclk; dev_dbg(component->dev, "Selected LRCLK divisor %d for %dHz\n", -- 2.27.0