From patchwork Fri Jun 12 13:57:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Scheel X-Patchwork-Id: 6598851 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 747E49F2F4 for ; Fri, 12 Jun 2015 13:58:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A46302066D for ; Fri, 12 Jun 2015 13:58:39 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id E18972034A for ; Fri, 12 Jun 2015 13:58:37 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0D2C326698D; Fri, 12 Jun 2015 15:58:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 5C7132669B1; Fri, 12 Jun 2015 15:58:17 +0200 (CEST) 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 73EB4266968; Fri, 12 Jun 2015 15:58:16 +0200 (CEST) Received: from sender163-mail.zoho.com (sender163-mail.zoho.com [74.201.84.163]) by alsa0.perex.cz (Postfix) with ESMTP id 73775266968 for ; Fri, 12 Jun 2015 15:57:51 +0200 (CEST) Received: from juli-workstation.net.jusst.de. (x2f13434.dyn.telefonica.de [2.241.52.52]) by mx.zohomail.com with SMTPS id 1434117468234985.3091061827367; Fri, 12 Jun 2015 06:57:48 -0700 (PDT) From: Julian Scheel To: Mark Brown , Liam Girdwood Date: Fri, 12 Jun 2015 15:57:32 +0200 Message-Id: <1434117452-25223-1-git-send-email-julian@jusst.de> X-Mailer: git-send-email 2.4.0 X-ZohoMail: Ss SS_10 UW UB CHF_INT_SMD_EXT SGR4_1_28055_0 X-ZohoMail-Owner: <1434117452-25223-1-git-send-email-julian@jusst.de>+zmo_0_ X-ZohoMail-Sender: 2.241.52.52 X-Zoho-Virus-Status: 2 Cc: Julian Scheel , alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com Subject: [alsa-devel] [PATCH] ASoC: wm8523: Set bclk ratio for master mode 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP When running in master mode the bclk divider must be configured to generate a sane bitclock. Pick the smallest fs multiplicator, which can hold all transmitted bits. Signed-off-by: Julian Scheel Acked-by: Charles Keepax --- sound/soc/codecs/wm8523.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c index ec1f574..9c60058 100644 --- a/sound/soc/codecs/wm8523.c +++ b/sound/soc/codecs/wm8523.c @@ -113,6 +113,15 @@ static struct { { 7, 1152 }, }; +static struct { + int value; + int ratio; +} bclk_ratios[WM8523_NUM_RATES] = { + { 2, 32 }, + { 3, 64 }, + { 4, 128 }, +}; + static int wm8523_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { @@ -162,6 +171,23 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream, aifctrl2 &= ~WM8523_SR_MASK; aifctrl2 |= lrclk_ratios[i].value; + if (aifctrl1 & WM8523_AIF_MSTR) { + /* Find a fs->bclk ratio */ + for (i = 0; i < ARRAY_SIZE(bclk_ratios); i++) + if (params_width(params) * 2 <= bclk_ratios[i].ratio) + break; + + if (i == ARRAY_SIZE(bclk_ratios)) { + dev_err(codec->dev, + "No matching BCLK/fs ratio for word length %d\n", + params_width(params)); + return -EINVAL; + } + + aifctrl2 &= ~WM8523_BCLKDIV_MASK; + aifctrl2 |= bclk_ratios[i].value << WM8523_BCLKDIV_SHIFT; + } + aifctrl1 &= ~WM8523_WL_MASK; switch (params_width(params)) { case 16: