From patchwork Tue Mar 21 15:03:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Baluta X-Patchwork-Id: 9636769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4430560328 for ; Tue, 21 Mar 2017 15:10:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38D7D28329 for ; Tue, 21 Mar 2017 15:10:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DB4C28356; Tue, 21 Mar 2017 15:10:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E68228329 for ; Tue, 21 Mar 2017 15:10:57 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 50FCC267190; Tue, 21 Mar 2017 16:03:47 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 35A2526717B; Tue, 21 Mar 2017 16:03:45 +0100 (CET) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10087.outbound.protection.outlook.com [40.107.1.87]) by alsa0.perex.cz (Postfix) with ESMTP id 54F62267176 for ; Tue, 21 Mar 2017 16:03:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=sNk2ILxItSb+eMMLbyoUkBrf1I5nQmQcSeztXE7AWzI=; b=u7hC5YmVplfpObfUiTqOfHLR0lGPXDJFYfl9EXqjGE81Gla8ukkLx3kA+Lie5wjebj8RBnKKqsVhSB4+T3NlBs2syTd83r4RL7TJ6c+14R79DCUrnDaaz9fagiUwiM5vE2EmJ8SJ24NDRjJ6LlIRGZnG/ZyZxfFiSSn+QHCPK4o= Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none; gmail.com; dmarc=none action=none header.from=nxp.com; Received: from fsr-ub1664-118.ea.freescale.net (192.88.146.1) by DBXPR04MB509.eurprd04.prod.outlook.com (10.141.233.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.977.11; Tue, 21 Mar 2017 15:03:38 +0000 From: Daniel Baluta To: , , 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 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/DHWae2ttOhXE6kGX7dOvq5qn4BX2KPRmVpXnZfLx4p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rXFE9LKowtQCQZhYrY9zyrxb9EguGgt9wqkSn8QFHVZX2BMTCmbxIbe4vrnXT1dLfCoKJ/VmhVzhXUxLexMp5APoaTJJU/562aAmP7zXSykNx9HUgR/aJro2jF9R8pQjsyQ5A3x4USzhQY/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?3J4y0K4I5fUTzc95vvUWWkwZH6pZM2KA5aSapTh/i4unpzaKP3A8nXKQv8JN?= =?us-ascii?Q?q6jVkeCadP/zo8v6hfgVHgmuzdcGpjvc/LqDIyP0vRHT5aXCtO2N10frkV5Y?= =?us-ascii?Q?WPDw6butdRgI8pw3SAYfdW7M/5BPZKFHunP1RJmF35m0fgejgPk0l5uMAl1l?= =?us-ascii?Q?7nQOlVn13COcy3fMr02UJ1wmJ1EQY3IHdtiQonleC/iHgq9gy2rgw0noDhYN?= =?us-ascii?Q?O/i50thmJPZbSHFcxTl1oD+rOs58zviy2Fuv7PoWerpnsXJfcVmv5jqqYyxL?= =?us-ascii?Q?b0YCeXbIpRevveqwy5DDAdl4Cbk1sQlamtVsLC+R5yt6kaQnUKOw/c5pdmER?= =?us-ascii?Q?2LPkgTrtbxmqbOJ0za2T2+/0DsGT9HFQwwlJHC9F0Jr0p/LTKx6xsGZyh1D+?= =?us-ascii?Q?J7SRJSwfmWFphWcvm+Zv/9WVtb+9kGc5TnHumDw8vMDKnoOmniTBBmyvmW1y?= =?us-ascii?Q?htRHa/zeeEVIujemigKmLtLLGAl4cQwppKqh+5/GPYEhz3/SCknW0WesKY43?= =?us-ascii?Q?IIIvor1l6/ZlEkLmmAtQn5ePToBsG6LxIeVjZVnBomvAAhCxzp1rAmELPkOd?= =?us-ascii?Q?SL4PWDrM7ezMe83EoDdcIE?= X-Microsoft-Exchange-Diagnostics: 1; DBXPR04MB509; 6:wKbFkyyTA1qt/wyYGYepX+lFLzp1SBqUEbHyEZLalOp8+Xn7b/10ZGj2oUNqFhtnV4HoYboXOJf6h+eHopB7Slku0E8D0vQn1EEG4THtpJJpCraeIY+x/r9BSGhl4acyj0JZNa9QhegR4AMn8EcANvo+zKAgjYle+7Cde3JCuEb9hU7Bj/Ko6BEtTFrwAkMHQ8jghd3NsUgrJfP5yf8MNe6Rq+UHsD6WooQaQlX0+ZiIA0GOYy8IlKvehvRyBvT70KaDChG43sQZL/88NMt221j2u9AxHBvxSdrRkcK07eX7HmTCeXJNSHzD9FLJnR1uQ1EBHsIUnuv+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 Cc: shengjiu.wang@freescale.com, patches@opensource.wolfsonmicro.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, viorel.suman@nxp.com, mihai.serban@nxp.com, ckeepax@opensource.wolfsonmicro.com Subject: [alsa-devel] [PATCH v3 2/2] ASoC: codec: wm8960: Relax bit clock computation X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Charles Keepax --- 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");