Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757908AbdCUPEP (ORCPT ); Tue, 21 Mar 2017 11:04:15 -0400 Received: from mail-ve1eur01on0065.outbound.protection.outlook.com ([104.47.1.65]:33696 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757847AbdCUPDm (ORCPT ); Tue, 21 Mar 2017 11:03:42 -0400 Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=nxp.com; From: Daniel Baluta To: , , CC: , , , , , , Subject: [PATCH v3 2/2] ASoC: codec: wm8960: Relax bit clock computation Date: Tue, 21 Mar 2017 17:03:25 +0200 Message-ID: <1490108605-20538-3-git-send-email-daniel.baluta@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490108605-20538-1-git-send-email-daniel.baluta@nxp.com> References: <1490108605-20538-1-git-send-email-daniel.baluta@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.88.146.1] X-ClientProxiedBy: AM5PR0201CA0015.eurprd02.prod.outlook.com (10.169.248.25) To DBXPR04MB509.eurprd04.prod.outlook.com (10.141.233.12) X-MS-Office365-Filtering-Correlation-Id: 52096cb3-8985-46b3-c5a6-08d4706b7516 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081);SRVR:DBXPR04MB509; X-Microsoft-Exchange-Diagnostics: 1;DBXPR04MB509;3:gwtJvVSrNraNT2jQDV7v8jDkp6W0/MIvxo0M1UjwporPdwM9PwoHhs/hK/DHWae2ttOhXE6kGX7dOvq5qn4BX2KPRmVpXnZfLx4pZrR2A+jnjbZsQ8crpI9yRLJqcYo5geKWLz2A3bKI78ZqLXFV8qG+NOqfcHpu0BLOJ7ESszPTqd7D0rXAx+By1s1Kc62uHBUZaRgqnf3RT7zE00C2b6Kk4tzq6ugzSBaHV20UEK9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/0ezevU98W/zadkEaUxxdyw/duS5wqMRWez60AVRswuRvWJcCiO8QiRt0Hn91a5Bu0u1Gu7HbdA/vGjyQslUoM81xps1d4JKwEi4tfEH60rPUV1VeBNy0EBodJg2ek2gpROHTU9D7I/2jWDp1OMsTXSpdtGAZZBA37m6KSx5qYBqc0wIwGogorIPIDTWANzyLfnCC/sWQJPF7NlA7wBORYlnMZMgeMyLVJn+Mg2xoEVCYNNEFQZzFx7aLkF87VSisN8abPwun X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123558025)(20161123564025)(20161123555025)(20161123560025)(20161123562025)(6072148);SRVR:DBXPR04MB509;BCL:0;PCL:0;RULEID:;SRVR:DBXPR04MB509; X-Microsoft-Exchange-Diagnostics: 1;DBXPR04MB509;4:jhumjI++xNrBfpiFxPv+gdQWj56FSuZiPYKuzgAdZ0taSKbw9rN8eZ095qeIs97YfEukXM/3Gxcxmb5Asc+HVDgFrInEPNbaBi5tSwvX9A9bNJDtfEYGegDn/LJ9zs9A22CfRFWX5rgTQsxxWH8fAIkiWdI8HX2lC0kiFP8IJzhNijw44ERPvwPnhwajqe8YnuexBW4V2kwhrOxaAVSjJjQisTFDeyVOzOyaWymMmX2MKpJbEb+FGOfHChuo80gaYQSHbZ14C45ZYxCaNG8PdVT/rPkfNPO3gJrNtuL7Lq/Xdjk9AibGn/icqOhXLKU5oe/0wUECUllQ+F4fMso8m+9KgeVqh8iiFiDiH/uNiMnxlhLc33kPHA3qFSibHenHN8MkGvove8G48ECG/smXsZC5ylUEnOtL2+YPb8ONNWXiACim+rtv66/CxfHOiEHV2t6ObNhYKPCK9ywhzqV+p4pepxmZP33u98eeD7CLxiWui5NAgjjNEzm8/4FkGNjj042GMrMJcxogVUgBlj/hJccAQWFtiSxyB7J8Rhk2RInr8Z8uVXiR4qBEpPmuZettmh67M/my5XOBK5RzYmXjFSyJX/ZxHjlw/r4MJ+nsmNFGoMVbpLdjwaFO10Eg4eIuTPaFmEPARlRGSY8WQ0VX7UDsxhD/OrA3n5Glrpw5+1g= X-Forefront-PRVS: 02530BD3AA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39840400002)(39860400002)(39410400002)(39850400002)(39450400003)(53936002)(189998001)(81166006)(38730400002)(33646002)(305945005)(8676002)(25786008)(48376002)(6486002)(6506006)(7736002)(42186005)(76176999)(50986999)(6512007)(54906002)(50466002)(5660300001)(36756003)(47776003)(66066001)(3846002)(2950100002)(2906002)(86362001)(50226002)(2201001)(6116002)(5003940100001)(6666003)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:DBXPR04MB509;H:fsr-ub1664-118.ea.freescale.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DBXPR04MB509;23:JP7Ah1qr8gSqgvaezNMVFb/nQbTl8pnb9vdG/cs3Qk?= =?us-ascii?Q?7rKjq5285Nnqb6muU6OE+k6PlcPwF1N5/gPDfCbDEXBEhXoNfLe40zIurMCz?= =?us-ascii?Q?xhdEyVovh+9XSm7nUqCfdHDrYlGbJ1Qg1rJPCLCPa/2ocv6wuFJ4bMrmBpvP?= =?us-ascii?Q?/1Owyb2ytntnFrBy60Up+PKARjMbNGfcq+wR/BIY0DRr01gYOSauEGWQSuVX?= =?us-ascii?Q?JZ9pqXdlV8KG7w3fV/iSQQrL9G7EZ/YCop60uGngQwAlXrvashAu/VDks1Nq?= =?us-ascii?Q?6Klrt2XX/I1e42bj/0hl/Mhnpv3eKZyZyuyjqcAFa6tfNWDWl+6F4UBAXmwh?= =?us-ascii?Q?BYdKDC//na40Sse0fr7gv4/bOZH/cBGakQOnIBpgUla7/gSoZR7k+ldrYA2r?= =?us-ascii?Q?3J4y0K4I5fUTzc95vvUWWkwZH6pZM2KA5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nR1uQ1EBHsIUnuv+oa/N4M+aMeAJyNVGdBp7P/f+Ymyxiomu75O374mB5OqiGI4qCHgFlq/n73LsbO+niLSokVnTV/DjXy+yLp3ni4zZZgceN84=;5:7ekNDDZkUuJtL8m/Rn6/JgJxsi6jk15NEZjNZK5B9hM2ifkI/zhzF9PED6wnvscSvmWDE7c6H5l/s0e1BXA4qdUEEBEXTnpmOvLu3EMhcZZvoLldzq0LU9aKqXGWC9NQmzOjyer4lByAj1wlGEoXNg==;24:8WUjYLvyOYWnaFS7q9apQRl9beESy8A4eapTzXsbtFKUCmTdOI7BI2Hl+VMFynUxzx36wSfzYwGE1stYPh1Z5l68PEKAauki2kyEO53MTDc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DBXPR04MB509;7:9LZNdZGCo0IQFK96fjNU7maqEKnaTJpCtwO1PT+ex84GHftmdXjRXkfo3d//OyKm+81qP7AQQlpkfvsqcggY+juvCIhv6i9V+50CwSdep8+X7KXoQp6Ln8xvnf3EjIFrCzvnp3p5f/vvOOOwHx7f9lknpS999r4+jKuqgmBdG2WpYzP9EnfGEAjLsXGRMqnh6//5PStlrjL+r9/jNAEZupyDcPA6zc5EgrWS+HokMRXsfQrfl42+CEM5e3WgKnabXriQ7h/Dxem2k7hDGpyATeBjQ+Gry/2YnCwTL5z5dE0XRFBNVuaecXPd7yd/zjeZe1igQ0bFnqxqw39YDgBvOg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2017 15:03:38.4753 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBXPR04MB509 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3193 Lines: 98 WM8960 derives bit clock from sysclock using BCLKDIV[3:0] of R8 clocking register (See WM8960 datasheet, page 71). There are use cases, like this: aplay -Dhw:0,0 -r 48000 -c 1 -f S20_3LE -t raw audio48k20b_3LE1c.pcm where no BCLKDIV applied to sysclock can give us the exact requested bitclk, so driver fails to configure clocking and aplay fails to run. Fix this by relaxing bitclk computation, so that when no exact value can be derived from sysclk pick the closest value greater than expected bitclk. Suggested-by: Charles Keepax Signed-off-by: Daniel Baluta --- Changes since v2: * do not differentiate between relaxed and exact match sound/soc/codecs/wm8960.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 25a4a11..ce159f1 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -611,6 +611,10 @@ 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_priv: wm8960 codec private data * @mclk: MCLK used to derive sysclk * @sysclk_idx: sysclk_divs index for found sysclk @@ -618,8 +622,9 @@ static const int bclk_divs[] = { * @bclk_idx: bclk_divs index for found bclk * * Returns: - * -1, in case no sysclk frequency available found - * 0, in case an exact (@sysclk_idx, @dac_idx, @bclk_idx) match is found + * -1, in case no sysclk frequency available found + * >=0, in case we could derive bclk and lrclk from sysclk using + * (@sysclk_idx, @dac_idx, @bclk_idx) dividers */ static int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, @@ -627,7 +632,10 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, { int sysclk, bclk, lrclk; int i, j, k; - int diff; + int diff, closest = mclk; + + /* marker for no match */ + *bclk_idx = -1; bclk = wm8960->bclk; lrclk = wm8960->lrclk; @@ -648,6 +656,12 @@ 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; @@ -655,11 +669,7 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, if (j != ARRAY_SIZE(dac_divs)) break; } - - if (i != ARRAY_SIZE(sysclk_divs)) - return 0; - - return -1; + return *bclk_idx; } static int wm8960_configure_clocking(struct snd_soc_codec *codec) @@ -703,7 +713,7 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec) if (wm8960->clk_id != WM8960_SYSCLK_PLL) { ret = wm8960_configure_sysclk(wm8960, freq_out, &i, &j, &k); - if (ret == 0) { + if (ret >= 0) { goto configure_clock; } else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) { dev_err(codec->dev, "failed to configure clock\n"); -- 2.7.4