From patchwork Tue Oct 16 03:02:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Khoruzhick X-Patchwork-Id: 10642677 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 44C8C157A for ; Tue, 16 Oct 2018 03:08:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 325E828DAF for ; Tue, 16 Oct 2018 03:08:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25ED5291EF; Tue, 16 Oct 2018 03:08:03 +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.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BFAA228DAF for ; Tue, 16 Oct 2018 03:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8X+g7LeNgG6Ccbv4qOTDyzjDOPJ+L5DrbbU3stBXywo=; b=IGxLCRd7eavtwd /C05SjQzfh097dtZK4Qk3Cc7ZrneFLRgE85JAALP4hiCIUI7ooFt3n6Cl30XCicr8QY7oLW4HAV+f qVJf6PcEQPdBucQHSwRLP0kQrHjpi4aDCTf5oAU2dPuXhMoj24SlxeZST1m+oxxUnlTbpSQLooUih eLY6lJK/pDbxJWALFsvUrjVHGMY0AaXBfCCExPtKezKBwc2kXTP8s+EnAtFQ1RXLmdwoyouD/Um18 aPYAWrcUhvUFZ4Hb0Gb6PxE7KXX+VKvApDdxuXseAcIU4UfE5dLtYyIQ/HOE7ec66pepIt9FAaO1+ N5SfUSa6gZusJaT0IHVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCFiA-00038X-5k; Tue, 16 Oct 2018 03:07:58 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCFdM-0008Ep-1x for linux-arm-kernel@lists.infradead.org; Tue, 16 Oct 2018 03:03:44 +0000 Received: by mail-pl1-x642.google.com with SMTP id c8-v6so10231972plo.9 for ; Mon, 15 Oct 2018 20:02:50 -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=fIAQlwXczbC2gniBQeYyLs3k83/bIOmc+eN5RWHd0Vc=; b=W1NWg/ENASfOUDrcyOlw0kf6iLESuSQYMwbmoy1R9wRzZymzbdWU2SJd0eIW3s6Urz bfIBTz90lob9fqOs2ZLpUmOMJlBAP2gZ972XDuAc9LmEah/S+vr8jvImKy0m9IKtFyVc VPFBmVumhavZxTB7wYWLqzXh4czAebgNECp6Z5w+ku9g5uPafk/OZqBH6m9TZdsnBb7e aNw7l4JbxHDq+OptbWhPeMU/9wsr5Gb9gZg72kV+JXg9X1vt8t7geAk5GW0JA0sjU+/q gN+YogxZelZPiPGnFvvc1wUehO3lTzpCIuaC7wVJLOxirjANlGaDIYjBwQwrJcdbbqZk 2iSA== 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=fIAQlwXczbC2gniBQeYyLs3k83/bIOmc+eN5RWHd0Vc=; b=DMDelHWRje8d84YbhaGXu8Tt7U081Ue6ZtrNr//FLtFgoi+15NVN7x811Be7OwlGKQ AfhGwWpxsi1G/AmOWdI5/KE84tTDpKt25k6JQAt0L3kV1UsXk2oSo/acnyVs1K3vePqf Y+q0tISqh+owVaAPV8VHMZtO15CDMoRLFn12hUHu5b8DABTohoNMrTFbgT11YO4f7WTe 59VXlObU93gkDXIcExcFnHGOAD3ftt5jPj7dfRfY4zf2ZpxHBwaIj0EEZJ3giM/uWreR gFcPbnzJJym09Rb3eeOgqr1uFaczwH/FVmx6vIyJ6xAE12jOqSv5SRkNZ58PRY6BW8a4 AiaQ== X-Gm-Message-State: ABuFfoi2Q12RPm77UW6wJumIv7GbLjD7Riv6Bty9jLrMfLzNsyKIv1ek G7n60tN92YTLLDudeWON1qM= X-Google-Smtp-Source: ACcGV62leXxnrGpi5OK34njcnaCJTQcu1ttRF+BjC6RPRNTJ61cvxpRJ6pLQjKncYJ6eQpu2cMnVdg== X-Received: by 2002:a17:902:2825:: with SMTP id e34-v6mr10828994plb.244.1539658970032; Mon, 15 Oct 2018 20:02:50 -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 p18-v6sm12812390pgi.5.2018.10.15.20.02.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:02:49 -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 Subject: [PATCH v4 2/9] ASoC: sun8i-codec: Don't hardcode BCLK / LRCK ratio Date: Mon, 15 Oct 2018 20:02:32 -0700 Message-Id: <20181016030239.15449-3-anarsoul@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181016030239.15449-1-anarsoul@gmail.com> References: <20181016030239.15449-1-anarsoul@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181015_200300_250675_41A4B3B0 X-CRM114-Status: GOOD ( 15.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vasily Khoruzhick Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index fb37dd927e33..2467fab94a19 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 @@ -257,8 +257,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 +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)