From patchwork Wed Oct 17 07:38:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Khoruzhick X-Patchwork-Id: 10644967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF813109C for ; Wed, 17 Oct 2018 08:16:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E10C2A04F for ; Wed, 17 Oct 2018 08:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FC2A2AA78; Wed, 17 Oct 2018 08:16:47 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable 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 A549C2AA60 for ; Wed, 17 Oct 2018 08:16:46 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 384E12675AC; Wed, 17 Oct 2018 09:38:31 +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 F1E972675AC; Wed, 17 Oct 2018 09:38:28 +0200 (CEST) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by alsa0.perex.cz (Postfix) with ESMTP id B91292675A4 for ; Wed, 17 Oct 2018 09:38:26 +0200 (CEST) Received: by mail-pg1-f196.google.com with SMTP id n31-v6so12111703pgm.7 for ; Wed, 17 Oct 2018 00:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BiLXUZy34XrJ92K1gl+adlcStiWf5foNbLUzU9xCuQ0=; b=sMJ4c7m1dmdrLl+e0Et47RwDPzQjG8qX6RW/NVmVJusJuipTrTyzZByRsPtbj6rRb8 eHm7wuevtOgs5LlYKpXeFQLQk7vgMvOE3cRUl3hdvVB6k/7DuFnOGo96N//O7O1kzMvU JjpyVmckE1WCAKenJaQoxkTu449L97RlILp4swKo258KSRrZcy2UJQkGfaj2IStAoa5K xC2DyO1aKFX/zvjJztFO1WYt03mCLjFpAPz2SEJzZ/c61+L7pJBv9r341A21o26b8547 PLvF6CpewObs019mnTKqNbizd62Di4ki7oglFG5zicbzJCF5/Hj9+RTROFVGC3EF/WlH jJIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BiLXUZy34XrJ92K1gl+adlcStiWf5foNbLUzU9xCuQ0=; b=Ji1QVdVisai3z4kzAyPDbClt3i29V7t1SAD6/sql2YULNOn5LLvrlB3ZrWx9LpOdl7 wO0tYxT7JYI2lT28yB2yJg4fG8cKkXEY6AtvVPiiBVgMyuEsrjsGNSI3iBPHA0aCb/ze krLTEalCfw8/zupIKQTImmXzoO/pDpa7KGjGRiOb+RgRkCauWl49D/tXyIHeA3rdirDe 97S5bdl9jpP2ofeaV61qSXtNld6z3toccQSCLNLEHito4yqiaBKiAp1dc3egleWYV8Z+ XVn41v3OEJGa5ZXV1rxLwPH168YFOSQlPrCybcCjNiQgmRIfTbgRHskQTWWq+2iqOg3k M1Zg== X-Gm-Message-State: ABuFfoh46hVW4pEvUDT3j+0sx65QZ6d1OAGKxB+P3rDYQjcEL9iZmia6 9EbI0p/T6MKm+7EshHp4vEg= X-Google-Smtp-Source: ACcGV61kgjOXQ+Gx0hrUyBWTtGBdE9yUuvKqcuPYNC90rMhPEAaQTUjb0Jj1kpUNAJ11yYa2QF92JA== X-Received: by 2002:a62:8910:: with SMTP id v16-v6mr25365509pfd.106.1539761905613; Wed, 17 Oct 2018 00:38:25 -0700 (PDT) Received: from anarsoul-thinkpad.lan (216-71-193-140.dyn.novuscom.net. [216.71.193.140]) by smtp.gmail.com with ESMTPSA id o12-v6sm23426387pfh.20.2018.10.17.00.38.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:38:24 -0700 (PDT) From: Vasily Khoruzhick To: Liam Girdwood , Mark Brown , Rob Herring , Mark Rutland , Maxime Ripard , Jaroslav Kysela , Takashi Iwai , Marcus Cooper , Mylene JOSSERAND , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jerome Brunet Date: Wed, 17 Oct 2018 00:38:06 -0700 Message-Id: <20181017073813.14127-3-anarsoul@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073813.14127-1-anarsoul@gmail.com> References: <20181017073813.14127-1-anarsoul@gmail.com> MIME-Version: 1.0 Cc: Vasily Khoruzhick Subject: [alsa-devel] [PATCH v5 2/9] ASoC: sun8i-codec: Don't hardcode BCLK / LRCK ratio 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 BCLK / LRCK ratio should be sample size * channels, but it was hardcoded to 32 (0x1 is 32 as per A33 and A64 datasheets). Calculate it basing on sample size and number of channels. Signed-off-by: Vasily Khoruzhick Acked-by: Maxime Ripard --- sound/soc/sunxi/sun8i-codec.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index fb37dd927e33..522a72fde78d 100644 --- a/sound/soc/sunxi/sun8i-codec.c +++ b/sound/soc/sunxi/sun8i-codec.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,6 @@ #define SUN8I_AIF1CLK_CTRL_AIF1_LRCK_INV 13 #define SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV 9 #define SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV 6 -#define SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_16 (1 << 6) #define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ 4 #define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_16 (1 << 4) #define SUN8I_AIF1CLK_CTRL_AIF1_DATA_FMT 2 @@ -300,12 +300,23 @@ static u8 sun8i_codec_get_bclk_div(struct sun8i_codec *scodec, return best_val; } +static int sun8i_codec_get_lrck_div(unsigned int channels, + unsigned int word_size) +{ + unsigned int div = word_size * channels; + + if (div < 16 || div > 256) + return -EINVAL; + + return ilog2(div) - 4; +} + static int sun8i_codec_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct sun8i_codec *scodec = snd_soc_component_get_drvdata(dai->component); - int sample_rate; + int sample_rate, lrck_div; u8 bclk_div; /* @@ -321,9 +332,14 @@ static int sun8i_codec_hw_params(struct snd_pcm_substream *substream, SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV_MASK, bclk_div << SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV); + lrck_div = sun8i_codec_get_lrck_div(params_channels(params), + params_physical_width(params)); + if (lrck_div < 0) + return lrck_div; + regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL, SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_MASK, - SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_16); + lrck_div << SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV); sample_rate = sun8i_codec_get_hw_rate(params); if (sample_rate < 0)