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: 10644825 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 356F53C13 for ; Wed, 17 Oct 2018 07:40:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2566B2A90F for ; Wed, 17 Oct 2018 07:40:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 192B52A90C; Wed, 17 Oct 2018 07:40:24 +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=ham 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 9DC512A8F7 for ; Wed, 17 Oct 2018 07:40:23 +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=mPytJ0PDCcKWBPe+GdWvpXCsYOG+nd6+h66vzORlMbE=; b=ombvPeflEuuLrJ 5/8zuD/CRH8pcwCpTKl3j1LTlcMWF4+2kueE8gPUiUmzo2n8rD28usvlNsYvsGngOMl9FdHNs/UeU GSJoUqxpxnVDUHVOUZ2AYtIoM31eIkHZOpHpgs25yrtH9Ll/lsys5uKvz82lDFXQF56q/H5JoF/4m Qx1NWl4VTCvEhQbYNL/0OZwbFJ3A9M3KKWOnk02iWKvITJ2y+ikjnc/FQeryo6svvEMgz0Wjtk5L3 03IAQ0y65i0OVMM/n/szmUEd6hWjpnUK52PNT4dLCshDjFP242H8x588Glk0VTQ6dzJW92TcbSpzh MzKiH/e73AiOY0+8r5BQ==; 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 1gCgR2-0006is-Ll; Wed, 17 Oct 2018 07:40:04 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCgPc-00067F-6x for linux-arm-kernel@lists.infradead.org; Wed, 17 Oct 2018 07:38:38 +0000 Received: by mail-pg1-x544.google.com with SMTP id g12-v6so12115813pgs.1 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=MRDS5tk++0YbDBNZ5RJmVI63u81bayLQUdfVPbeLJbYURIEe5olbpZXYSuS/MPsoF0 FtD6fbsnqnckkNxg8h/MOjlwqiCc1Dvtv7EoGRfLoP+Jw8KVzKtZR582VTPPHJTaiMfJ lvdq8vR9eqi6svraAdKjPFQd55TWR5RuSxVOg+XX2uwKZ/m1Vsej01cLRjN3vCFXEHqN XSdYSon1VhRInTSaw4fmVEfpNxQgf6JIRlvVyTD9DTcnt6/9UOyL/vTXrJKNCVvL67cm p9ta2CZ7Zvefe3FVea2HKHw68eskF5zbc1jl+CJeg4dmJMO5TrvVioAbs+VCnj9vZoA9 W/gg== X-Gm-Message-State: ABuFfohS2Dnbon0dML4lG3xz7HzzwdQ1gUaMfsFWzvroCXPqrDsbjPNT pioXI28WkVp/tGl32Kl0Mdk= 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 Subject: [PATCH v5 2/9] ASoC: sun8i-codec: Don't hardcode BCLK / LRCK ratio 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181017_003836_293610_A5E9DAF8 X-CRM114-Status: GOOD ( 14.59 ) 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 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)