Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756796AbdCUKKB (ORCPT ); Tue, 21 Mar 2017 06:10:01 -0400 Received: from mail-he1eur01on0081.outbound.protection.outlook.com ([104.47.0.81]:48002 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756404AbdCUKJ4 (ORCPT ); Tue, 21 Mar 2017 06:09:56 -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 v2 2/2] ASoC: codec: wm8960: Relax bit clock computation Date: Tue, 21 Mar 2017 12:09:36 +0200 Message-ID: <1490090976-25877-3-git-send-email-daniel.baluta@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490090976-25877-1-git-send-email-daniel.baluta@nxp.com> References: <1490090976-25877-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: DB6P193CA0014.EURP193.PROD.OUTLOOK.COM (10.175.237.24) To AMSPR04MB502.eurprd04.prod.outlook.com (10.242.107.147) X-MS-Office365-Filtering-Correlation-Id: 8444efa7-2079-44fc-aef8-08d4704267d3 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081);SRVR:AMSPR04MB502; X-Microsoft-Exchange-Diagnostics: 1;AMSPR04MB502;3:ipBJgPTV5/S1bPmPn9loMgwNceLH9NCsKpOOcPgDm01yNgExDuKqgyvlY+TjMLz9tc6SxepwBA0VswJzJ49e+QAnfWZDH7mkswlR9T1H4Z5Pv4slFFJmFTMWLArm2pumLXTSKpRRpV5RLAiFycxVVTU3Q7pIpts/f322deYGFn8MV/cRpN+Wy8t+2OOr/cD2ZqJiZLeAoQZL5+02s1pp4iSYJe8X+fCdm3eAmEZe8hr7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Q29k9jtDgehI/x6Ao+qcnQt8vFaC4FtHfpBSQhlYUP/KZOOjguxAyQhd7wQTlQlA7YM+3SKTHvIv1ywaxIGEXTGoB82vsKDyvgSWyrN9qpJ1o6enBHfPd+oJFNRnxFFAYbfpMsPA3YEBgv6ugqYY6M5PUkNBQkrvWi5xxPwyeQV+01aLpDmCxHsck/acJk6blc/j75vEJr56qBEosaQU8EJCS8ChUbIyjtaPUidVTACdoeFCfPY3jGuGaBuztnNqZ0zMl/jffG3AEtmXCYis+72tYmFK4CfERJQObzZ 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)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123564025)(20161123558025)(20161123555025)(20161123560025)(6072148);SRVR:AMSPR04MB502;BCL:0;PCL:0;RULEID:;SRVR:AMSPR04MB502; X-Microsoft-Exchange-Diagnostics: 1;AMSPR04MB502;4:q6RZMlTMsQMl1nwvvGvkNeS65Jmu4uIGQZvqQWYmu3IfHUwA9Z1rVHuCEvaPpWFlTRKeShgazIJK6qkscH79yQuYX+4LT1NwhWPgW9V8arjFXJQolHxo0mdwTjWZrkKvwevXwb9RorfEsU5ZOTqKA9ObIFPBu3bI8KhmmhSvppEA/1wzjabUop7Znod3ujeB9cK9GnnmdmHTXN16XbTStoSc6pmRJSBOeydDIoaRvIAHboYKP3yaBY8wR4HG5kQwmpQ9jLVOZp6Sz6hn8/9LOD0usfDGWh/596MZEr297xUPyzs0hYj7rhnZw9s2Fg45lx5lXEYFlAem8/ENj1BS/wzuszSqiTXbPeGALzRlLFVzzLK22PDVgWxlvmQ/SpvgAZopjBBDQQvoC2wwwEh9FOzw3+l1vAhWK8R1B8DIieeKnhrlZiwtUk3zXMLsFT5yYcYmGgNDbI0c0kvFkk9n0g63QXTS0JXvnr772CHZvfbDWqwudknnHU2KpkO+CuFkMMPwLt1DPkCBUcBap8gk7rCAGGtPROLY52qCBkas2TJVwt375/ZDTXHE1i2Nup4nwgs/cVHlh41N+YOhiXMO7vSM57raEUmw4L0DzDOtPXgA8DQdelRkfTF+8DE776eWOX/c42Zkz4+m7T7p6gId5t70nr7H74Ws1CLO3Mn0qAM= X-Forefront-PRVS: 02530BD3AA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39860400002)(39840400002)(39450400003)(39850400002)(54906002)(6512007)(6486002)(5003940100001)(6506006)(53936002)(33646002)(48376002)(50466002)(7736002)(2950100002)(6666003)(6116002)(42186005)(2906002)(305945005)(3846002)(25786008)(66066001)(47776003)(86362001)(36756003)(50226002)(8676002)(81166006)(2201001)(189998001)(4326008)(5660300001)(50986999)(76176999)(38730400002);DIR:OUT;SFP:1101;SCL:1;SRVR:AMSPR04MB502;H:fsr-ub1664-118.ea.freescale.net;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AMSPR04MB502;23:MZ/N4bMnAr9xq/Q8dNlbo4jItGzdrubKbFgXCS3aDC?= =?us-ascii?Q?1pZMiFtUr7uBd4JevqxRLddY8GgdSK26v+CCoHjE2DpVhKilJIsC1ULJ9ty9?= =?us-ascii?Q?gHHvizR1wPcMKMNAHS6opZaB2GFbbZD4L55upnW4G137B6i+A/yEArTGEOHN?= =?us-ascii?Q?wk6+KWiC7hTa/txt5Ki89fxk4v/tKxlgRYgkCDZYb3YWxXGvAqhM3ai73KiJ?= =?us-ascii?Q?a9AEyZP48qad6e4GTIW4SRXmqdpADz0t8mC+okdvebwI8kCXWcyUJ0zgQI/z?= =?us-ascii?Q?hZXx3w+Pxw0gtfbuZjtdpIkhl3jC7+smXlIQF3d6uXZeGoJ3U9iGJtZKBlsO?= =?us-ascii?Q?w6YwK7L8GkmczEfB3IcBN0GW/J5oZwBDUZvzZoHHrzzXY0s9Ustbii6FtWeY?= =?us-ascii?Q?Iilz4SOBx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amidImKCTLfADNf81JssWbUd2B3cCnDxxMFAUUxDmeaav75aMzobSViaiWbq4A==;5:jl3By8le9GMiPtwZ/HkTsklqCXsN/KdNLEsAZh//R1YeWDCiT0B4zlKNTj/8Hs6QTjGrh7JNCDtjjMIaUEK8PuiBvxi/njD98fdqXh+Ou5zorgy+oeZTGeY7PjLVCpiHNQ7nKdX71f25MaC5SIHCyg==;24:pV7BJOH2AALNIzsQPv2+bg2CjX7OqWR4x5uObVIaq30MDmN6U+MIPjVH9KP/u8kB3wiZQYzKoC+tsr/+NbMah38SnK9kkH3ycNd2GYSD3UI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AMSPR04MB502;7:gxCSJnQhI49G889vdfzbvfuVlT4IPXs33RnM1CietZKY4diuzTCzySJM0uWk5FmtN25p0F06+rcKQ+w2WfyHNdredrXJzGGrj49mYjN+Pjsr7BwZOjojS0UbTRy81LlG+lIVXAyF0rqnF/iUbjUZ2u8zeBGjnBhzIqkLSbnHoDBnLZgQNKDMAiwMFYznTlFE6GDmNjhIEwGZ2H7NXRjLBEzTfK2ZqEMkBX9iHl28CUCaeerf/mCdlgTzTDaIjqKU48fYEAuAnU88gOFLgFj2G1oVeF3eKwVMQGTKlT5pWsUb/K5RMAHd4jXFUK0tsgHIa0FOronEa84ZV+FzT2TyPA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2017 10:09:46.7782 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMSPR04MB502 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4334 Lines: 137 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 v1: * use a marker to check if a match is found * didn't removed PLL as Charles suggested because there is a special PLL mode which explictly uses PLL. We could start a discussion on not using PLL when deriving bitclk, but this is to be done in another patch. sound/soc/codecs/wm8960.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 25a4a11..ce4fcd0 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 @@ -620,6 +624,7 @@ static const int bclk_divs[] = { * Returns: * -1, in case no sysclk frequency available found * 0, in case an exact (@sysclk_idx, @dac_idx, @bclk_idx) match is found + * >0, in case a relaxed (@sysclk_idx, @dac_idx, @bclk_idx) match is found */ 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; @@ -656,10 +670,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 (*bclk_idx == -1) + return -1; + + /* relaxed match */ + return 1; } static int wm8960_configure_clocking(struct snd_soc_codec *codec) @@ -668,6 +688,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 +726,16 @@ 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 in case no PLL out avail */ + if (ret > 0) { + 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 +763,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