Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1574290pxb; Thu, 4 Mar 2021 15:15:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIKJjrb3MFkCNqtLvEaoM2DxP+55q7eg5j8bzkvaktc2Y5T+L7v2P1LNSosiwUXWVHKK/A X-Received: by 2002:a5e:9513:: with SMTP id r19mr5729720ioj.35.1614899703346; Thu, 04 Mar 2021 15:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614899703; cv=none; d=google.com; s=arc-20160816; b=alYy5Ycs22ABJs96MLuziJ65CSW46/wvZIr1bYp+HwqqZEwQTCUi58aT4Vvj6oyfWc VxmN4psjDIWCdSYlTOdGN+/4PskeCVwfAZAUjAGWduRf92nEKKQ8mZm2RPOudjd7Utzy qzutMZmo2zPDb/Z3w8p34QSwpiiYWfe0TpyW2y77kMSYDnZV3Xw29fM/dOXZACja7J3k iL/61OK5tErPCC2QdGH+uxAP2b/Svhtid+H2PK8vLLNMdkwmTuYTBhDsr3sppo53y81C ZDoS+RgsMYFGTqhWZioSJt+WDd7ZUin9y4cRVzUNi8v63DC9dGCAo/DGVIpmA/oEoJhX 9O7Q== 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=Giibq9z44Ta/sogARPK2C0nXFK9lcuvXF/eh6uuaZFE=; b=QwzdJjlx3Gj4WoGqz6WB04Lku7Swfz3JT1FBrzSuSrKmztnZuOfdcHA1v3C1WTp/MQ ykV0M0o6BtMFc1FDckBk9uyH0sfMr6PBpWfMwseAS2Mo54n1vNd96aEIfPAsOe0wuMjd npiBSJCpG4ZovS61MdtFc3JYnMqStCVG0GKQxh2XJCPSAgm8Ea5XB8cLHnzwkMJeJIfk G5xbm6Ki/Zw+xgTSi7tVWwsRslKrwFFOlqfStEnXmhhuuS9xwL4pk/FJb9q1q2febHlG I43mIRlkBclXYtUCG97qcY4LGRwWQumoT4IXiAhSQW97n5BZLzfgZ4QwTUuEKtMmuRez rvqQ== 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 n16si895862jat.35.2021.03.04.15.14.50; Thu, 04 Mar 2021 15:15:03 -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 S1345171AbhCCQHf (ORCPT + 99 others); Wed, 3 Mar 2021 11:07:35 -0500 Received: from inva021.nxp.com ([92.121.34.21]:37594 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346986AbhCCLfS (ORCPT ); Wed, 3 Mar 2021 06:35:18 -0500 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 800442004F6; Wed, 3 Mar 2021 12:34:08 +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 C5829200507; Wed, 3 Mar 2021 12:34:01 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 0B94C402C1; Wed, 3 Mar 2021 12:33:53 +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, patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH] ASoC: wm8962: Relax bit clock divider searching Date: Wed, 3 Mar 2021 19:21:28 +0800 Message-Id: <1614770488-12861-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 --- sound/soc/codecs/wm8962.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c index ce4666a74793..f5cd22450190 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,23 @@ 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; aif2 |= wm8962->bclk / wm8962->lrclk; dev_dbg(component->dev, "Selected LRCLK divisor %d for %dHz\n", -- 2.27.0