From patchwork Sat Oct 13 03:32:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Khoruzhick X-Patchwork-Id: 10639847 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 CED79925 for ; Sat, 13 Oct 2018 03:33:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B43892B94E for ; Sat, 13 Oct 2018 03:33:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A54CE2B958; Sat, 13 Oct 2018 03:33:02 +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=ham 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 00AC72B94E for ; Sat, 13 Oct 2018 03:33:01 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 5B3692679B3; Sat, 13 Oct 2018 05:32:53 +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 382322679A8; Sat, 13 Oct 2018 05:32:50 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by alsa0.perex.cz (Postfix) with ESMTP id 01B222678CA for ; Sat, 13 Oct 2018 05:32:47 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id g21-v6so96691pfi.7 for ; Fri, 12 Oct 2018 20:32:47 -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=CSEHWxR5P0L2NKnexMzXdSKjP+Tcjjj7GTTsKPd2nLY=; b=pGuG7XN4fk6fEpydsWChqASs0TjyknxIt8XvXMtkRjaCczRJQgMoKm1FVJ2ICUVMxF bLAfl9gNGzS+IcwoMKoD4e8Eti+6HqcyUEhfji/abJMTglbnk7LCWmX+EzHPem4LFp8M Zxj6yawt+ujrwDz6nYVU+hZ7pyJauZjq0iaNA5vCkyScTkL9oDKTv2IYBp+s6C34g8S1 L7LwEby4EAMKoWeTUTKzX6FSb8AgBamM/sCYBD813R1rUIBbWcnjSHqPwIUkJepIIse9 CljEtt5fRIPvRjR3v12Hv0KmLJjeigyHWjv06ZE/OL74FIHZSApKI8IIWPB59dSK12W3 X+4w== 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=CSEHWxR5P0L2NKnexMzXdSKjP+Tcjjj7GTTsKPd2nLY=; b=C5ZK69EMVLCq9t2MwwKU0gvUMsHVOKc9rsrooEYF1ED88lnn4IztQuE1OdYLNq72s5 fQ4lgpYcv00BDhPXGWTsEy1h7z50MUTdcsUh4fJYpydsKDeT90UQDu6gufWUygVL6lVh FqzwYtGsEXga7aTlR3GQG5fBxnrE0k+FqR4MQYO0dUQPh2Mz5ALYKmZzdHeR71vUMWF/ SDp36uZs6TMiBwHPzEJZGHNokorjO/ArvtXTpe4KjQ+WlwX9r7gr5S8GmYWp1kprBUgz sOmQqVUygEKRFmP5z2F0ndJDAiYNV5tLx4RDdQuNDzfYYT/ShWs9RJF0OVB5Kr3W440N SUQA== X-Gm-Message-State: ABuFfohVLokztctcqd9FaXHU/XIHzk9KJKdzK+qhJI55V9TQVy0JOWiE Jcfb2W/ZJwiA7cOTIqyJEok= X-Google-Smtp-Source: ACcGV61ONS+crrOjCdznF3EhHA3oJjIqfxOPpRP1FlE9VGCZbwy6TqXMHipzz4WFknAxnoHTpczcXA== X-Received: by 2002:a63:145f:: with SMTP id 31-v6mr7785199pgu.35.1539401566789; Fri, 12 Oct 2018 20:32:46 -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 u79-v6sm5565039pfi.104.2018.10.12.20.32.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 20:32:46 -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 Date: Fri, 12 Oct 2018 20:32:22 -0700 Message-Id: <20181013033230.6506-3-anarsoul@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181013033230.6506-1-anarsoul@gmail.com> References: <20181013033230.6506-1-anarsoul@gmail.com> MIME-Version: 1.0 Cc: Vasily Khoruzhick Subject: [alsa-devel] [PATCH 02/10] 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 --- sound/soc/sunxi/sun8i-codec.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index fb37dd927e33..e681e194ad4c 100644 --- a/sound/soc/sunxi/sun8i-codec.c +++ b/sound/soc/sunxi/sun8i-codec.c @@ -52,7 +52,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 @@ -257,8 +256,8 @@ static int sun8i_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) } struct sun8i_codec_clk_div { - u8 div; - u8 val; + unsigned int div; + u8 val; }; static const struct sun8i_codec_clk_div sun8i_codec_bclk_div[] = { @@ -300,12 +299,33 @@ static u8 sun8i_codec_get_bclk_div(struct sun8i_codec *scodec, return best_val; } +static const struct sun8i_codec_clk_div sun8i_codec_lrck_div[] = { + { .div = 16, .val = 0 }, + { .div = 32, .val = 1 }, + { .div = 64, .val = 2 }, + { .div = 128, .val = 3 }, + { .div = 256, .val = 4 }, +}; + +static int sun8i_codec_get_lrck_div(unsigned int channels, + unsigned int word_size) +{ + unsigned int div = word_size * channels; + int i; + + for (i = 0; i < ARRAY_SIZE(sun8i_codec_lrck_div); i++) + if (sun8i_codec_lrck_div[i].div == div) + return sun8i_codec_lrck_div[i].val; + + return -EINVAL; +} + 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 +341,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)