Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753990AbdCOPeJ (ORCPT ); Wed, 15 Mar 2017 11:34:09 -0400 Received: from mail-eopbgr10045.outbound.protection.outlook.com ([40.107.1.45]:55018 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753948AbdCOPdX (ORCPT ); Wed, 15 Mar 2017 11:33:23 -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: [RFC PATCH 2/2] ASoC: codec: wm8960: Relax bit clock computation Date: Wed, 15 Mar 2017 17:33:06 +0200 Message-ID: <1489591986-6302-3-git-send-email-daniel.baluta@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489591986-6302-1-git-send-email-daniel.baluta@nxp.com> References: <1489591986-6302-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: HE1PR0701CA0064.eurprd07.prod.outlook.com (10.168.191.32) To DB4PR04MB507.eurprd04.prod.outlook.com (10.141.239.149) X-MS-Office365-Filtering-Correlation-Id: 388dce9e-29cd-4222-543d-08d46bb89bbd X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081);SRVR:DB4PR04MB507; X-Microsoft-Exchange-Diagnostics: 1;DB4PR04MB507;3:+KzXVI8saZLSr2HDLNVqlCHL/yQ9BRfGa+/Fk1AEQgm95ThWAPWQyoQ+60u2isp6fMuW39CmpPqV5N+Pe6YcJyQOiO7rtbLMXAObspdIH0MHcWUCazv2AE22oxX6ruaSw71Ro4ZGt6XdLsfxdOcXR/dndajiyztvFY2j91m3PXcDMJjfxTwAgXYy+Ct8FISEsJi95gG0skCsMWNipBgqKht/bwBdhLeEmw9pWBK+2MLpBuN/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w3nv8ScAsgKbt9xF8Ha3TFffOCXFS74t/Y3FDotovTGjxbPT6p/Zgl0iZPmHzQTqOoPIVdCrIxHZDYDeP60EP96wmjtxglJhEaD8htxGskkoFrA7uJi8oJNp902gSPvsMejifhWm/MofefMoUoiWlsYAeLs1+AsE6iXmpJGJK8yjYrZRuY+rOkOuK42VyayIq3LP6hLnhxrKXCE2gYDx+V0XvzR9d6XpLYixGBzgRnD9yQ413ccZ752dOysZzHW2iCXX8TqBhvCsbs36WDaquqnkpKMHu3jbH 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)(20161123555025)(20161123560025)(20161123564025)(20161123558025)(20161123562025)(6072148);SRVR:DB4PR04MB507;BCL:0;PCL:0;RULEID:;SRVR:DB4PR04MB507; X-Microsoft-Exchange-Diagnostics: 1;DB4PR04MB507;4:RpfMgw49VPobLfXz8nALPVOt6DrkahCkwHfV7r2GX3ZOYVurIyShhwpdRiINqSzZhHDvNccffQ1AAmSqRtmpc7MfWiZfeMnc5CqnhtvWlcG5vBXyKRFNp+y+uJwjVASVPe1dlLPFJYhywF9jo6oz2ZrrabkI4bKYIpq2/S5AMLy/aqNbbJ/tOOLSjFEvpFD0LIObVQd5fGrUFk/VvU3sZOgu4dNHRQBBVWWdVYjMzT05zDm/i70Yu3R9pRpBd+Mcvhr4f9xaRWKeCRJUDCr2Rkv9zroUYXoSU0rQOFMiY9rDkXRkM6XPsM9JTX0NtUi8Au+flDyrI55Rmu9h13ZNsOEpwLMG6IGxsTJF9ADOj2tGOeOPy9dpGnioR3colKemrYTELbANjaBebRDS1GF12TpIrXPNsmL0vpNJx/4aRRzoquttjMnwUhv9i8xjDOjBEPNOaTMXWacFOMNNnLhMbny/fmHgnCbfTGe6BeAY+rd10SVbD5Pna77u29N9ZGS2y7WSRZjioeqB5UDepUBGOMpCH3+IZiHijZvLGdSKEMIizWku1hwq0IzwuPJLLx880GeoNKhjaJciXWIdBfY0l4SkaY8laKHTlvPZhTo9bXe/BqygnXRjPQ5Yseb9gEG7Uaxipr977R/PoISUajCE55CxRqyqDmfIWyeizWSVy5o= X-Forefront-PRVS: 02475B2A01 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39860400002)(39410400002)(39450400003)(39840400002)(39850400002)(189998001)(53936002)(50226002)(66066001)(6506006)(48376002)(86362001)(50466002)(54906002)(81166006)(6486002)(5003940100001)(25786008)(8676002)(4326008)(5660300001)(33646002)(42186005)(6666003)(36756003)(50986999)(76176999)(47776003)(6116002)(2950100002)(38730400002)(7736002)(6512007)(2201001)(3846002)(2906002)(305945005)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB4PR04MB507;H:fsr-ub1664-118.ea.freescale.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB4PR04MB507;23:vZaRXGPdEqcYm9ZLj0LjZJL9MgnvBSHfVSPwRkDhc/?= =?us-ascii?Q?/4ZhN4nwTUSheqWtavl3UQtNIRKJNape1XFigqLfXG9m6LxW4bTDiDW113pP?= =?us-ascii?Q?XFuggOiQ+5YEYJQnvJVIhWrpO52YBEtD0DidOqMmiMB72RTvTcv93+p6W7aB?= =?us-ascii?Q?Mjd3ZL9pOyxAhTaufMcpjoJBTsHcmkZ15IDCPWJGGc0sos5X4TaRaX2iYCSe?= =?us-ascii?Q?TFvoIbhcXkYCjqoGPOj47Buba8+dbghUsooiZPADeE6uFZN2y07yMoFKHyNv?= =?us-ascii?Q?uWTyAvHirPhBqaHQvZ7aWh44EjX6FZfAEaJoEamRg65hkIdJ9RcKjMiXRFzP?= =?us-ascii?Q?Tblit4qX3nGivjbnvW7HVjXnEIu2O6iSUXakeDw75ajjeIy/ZYQaADf8brLi?= =?us-ascii?Q?BU0lIBRBurGOkNjy/mol9+G8Xg6cKIUwLssaja1w8b45Erdi9AqXG72+LtVq?= =?us-ascii?Q?VydO0quSTSiojwRHVV5uKsyabRaYEkE2mWK7MCiA4d46p/xVaHvC2Ji0+mZs?= =?us-ascii?Q?/lLuJznyClQ8YjDIcvQn81RNLO8Fcc6euuE1GJ1jAkCy/75VormhMKJnNfKu?= =?us-ascii?Q?pGh+HlElOK+Jk6fgZ1GFTmWyerZInrR79UTojBOzx/+anqN7WktIOjQVkmj8?= =?us-ascii?Q?qACJ3Dni4iB00cIgetIVtOhhPmZJ2Q9jcUTELXOgkLSP2ai8cvvStCtvdWtF?= =?us-ascii?Q?CloIkD5nvzl0/hRsl7hqQFdopypYVwGIWfb6nxuctba5Q2mmGKRKR53FY4M/?= =?us-ascii?Q?i+J25gAmgwPbES5yCtq8bOhwdsPqSp6KrRFOXrMDozfZ/m0UVfdpeLlYxnqA?= =?us-ascii?Q?VGnSZdsL3kWnQn5Mh1deet48oXCa873E/zruQYfQSn7zMu3YLgItTESDCsCC?= =?us-ascii?Q?9ks9hzbUCNLm7yen1obVx986CRgQNou7MRnRR5cAxev+x16NofOfw/42hHhv?= =?us-ascii?Q?aQMoqwchQhgl02h5QCdye7cuTCw9eGvuFn3Z7eHAWQRBm/EztdH4zDP7vUdS?= =?us-ascii?Q?ic0ex/R5n6ycgI+1ki3D1icH6DJFLhBlM5hBMgkkzERQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;DB4PR04MB507;6:gQLeku7qHaOLTAwaugB3lwF5iWcQcwmWtELfNBqT+FEDu/z/xS/AvFOTVa4/PTpoG4T4uJHKbe3CYge7+lfKay2guEkGXdd8tQrvW5JpU1a+3KOfZuAqTuonEiSZeFJ9uYRaoVz2hJcAtdJlNkDdhOHKneX0hCfozM0IeSMwi1M4Fs17coYxvveQqnCO2pGFhCiTZ+wdIiPlMWBmaaeXEirJgcrSM8zxqC/J9rKpslrWsq2DnX+32pMZlMLUoO3anWJ+j3Um2yB6NRWTZrOU4RIsumm+xlUT4/B63OlLfPcfLimb3Rif3ajf9Z8xaefSk/JFglE6lc7iCCZEcPPdfRng8B6hJkjYxpXhvIADBkoGUxSFuw+5YIG7G/y1lcYKHrYVqjBB2V1dMDryBjPvzjwV9/vWsJMDJBil0EdqfYo=;5:DUfg/weLqiNIKA54xh+1YO0U9dnuYoeT80dPLEIbFvj89BM11H4r+CbFl5L6EIvk1X8LKQPFf+gLjA9kdOVkZMZuOmch3zVOqM/jSRP6eb+G70AppE3hGa5jUBuC29xhQH7o2wpDATNJtqx+rYeFJg==;24:wbKTBGnVaEUT2m1/yCM2nz5KACP8YE3lVFZiki4wKTFBi7zMw/0FEx7xPd8G0p246C7wlenFQIs7Ca3zxsV3DzcueROcQ9528IYDtwv7iz8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB4PR04MB507;7:pd6Jt8R64vvFu0aHQ+a4YQvQktGPF6Ph5PFWWPv6ASmMeXArROATo6c1rsFCULHu1q0L4YqrltCobPW0W8+l36j8Ce0DStjMwEe5J/53lyMAkSR3b8E7gi8Tfah5Tux5rbGRXCn7FEBo3yTonMtCYJgk/SkWR6EJ+YBMJKUrCYfhefbIZjbp/ouD+Gakjo641zktBsLdzvxsR63fFmP/89yiJIjrIw4Yi9h6DjHT5/VW8RSIjbwPjILSTysKvzkS3WmimvoaJzOOU9w8A6HKtrjUK5Gty6g9smKTgpkDSnhGYqVzjf7KNhJ6ZHrpZ/anuvdabaRQbSZZQPi7wr570A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2017 15:33:18.2581 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR04MB507 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3851 Lines: 125 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 --- sound/soc/codecs/wm8960.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index cb2ff2d..1669b45 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 * @_i: sysclk_divs index for found sysclk @@ -620,14 +624,14 @@ static const int bclk_divs[] = { * Returns: * -1, in case no sysclk frequency available found * 0, in case an exact match is found. See @_i, @_j, @_k - * + * >0, in case a relaxed match is found. See @_i, @_j, @_k */ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, int *_i, int *_j, int *_k) { int sysclk, bclk, lrclk; int i, j, k; - int diff; + int diff, closest = mclk; bclk = wm8960->bclk; lrclk = wm8960->lrclk; @@ -648,6 +652,12 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, *_k = k; break; } + if (diff > 0 && closest > diff) { + *_i = i; + *_j = j; + *_k = k; + closest = diff; + } } if (k != ARRAY_SIZE(bclk_divs)) break; @@ -656,10 +666,16 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk, break; } + /* exact match */ if (i != ARRAY_SIZE(sysclk_divs)) return 0; - return -1; + /* no match */ + if (closest == mclk) + return -1; + + /* relaxed match */ + return 1; } static int wm8960_configure_clocking(struct snd_soc_codec *codec) @@ -668,6 +684,7 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec) int sysclk, bclk, lrclk, freq_out, freq_in; u16 iface1 = snd_soc_read(codec, WM8960_IFACE1); int i, j, k; + int best_sysclk_div, best_dac_div, best_bclk_div = -1; int ret; if (!(iface1 & (1<<6))) { @@ -705,10 +722,14 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec) ret = wm8960_configure_sysclk(wm8960, freq_out, &i, &j, &k); if (ret == 0) goto configure_clock; - else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) { + else if (ret < 0 && wm8960->clk_id != WM8960_SYSCLK_AUTO) { dev_err(codec->dev, "failed to configure clock\n"); return -EINVAL; } + /* there is still hope, keep this if no PLL out available */ + best_sysclk_div = i; + best_dac_div = j; + best_bclk_div = k; } /* get a available pll out frequency and set pll */ for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) { @@ -736,8 +757,14 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec) } if (i == ARRAY_SIZE(sysclk_divs)) { - dev_err(codec->dev, "failed to configure clock\n"); - return -EINVAL; + if (best_bclk_div != -1) { + i = best_sysclk_div; + j = best_dac_div; + k = best_bclk_div; + } else { + dev_err(codec->dev, "failed to configure clock\n"); + return -EINVAL; + } } configure_clock: -- 2.7.4