From patchwork Fri Nov 6 11:38:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 7568561 Return-Path: X-Original-To: patchwork-linux-arm@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 EE72D9F71A for ; Fri, 6 Nov 2015 11:41:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A2AD2074A for ; Fri, 6 Nov 2015 11:41:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 350A3205B5 for ; Fri, 6 Nov 2015 11:41:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZufMR-0001zu-AL; Fri, 06 Nov 2015 11:39:15 +0000 Received: from mail-pa0-f67.google.com ([209.85.220.67]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZufMM-0001pK-Io; Fri, 06 Nov 2015 11:39:11 +0000 Received: by pabfh17 with SMTP id fh17so14760219pab.3; Fri, 06 Nov 2015 03:38:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T1zBdbdrwXGsb1XfJGqSUdNaxuxikJemQVg7mlLeMrw=; b=HcM9aYYeAIHZMncsxMsSp8t0eqx7VIfer+HLMwm74esOEIfYpZu5ECuEhdGDDhArGW Vln24cxTjT6y36GYvfoUQDNNwvw0+BWNlc2wUh8qCXB+zzJUUxbnFov0PKKRjbzT6DYq xricgcjd+oyQYDRo5G4S67AyhsIBUY1MW4Lem9yBOUcNCml1RmuVjJ4hq6ccsyjZeYu1 V5+awavO6Ai7R+LgmkiJ1YSaluBd+WFhKEWgAUSq/AYd8eG1OsL4Z7qGgsKSmZXkKfln TPfsjYNMvJlT0CxDppdU/V3yA7lfIxCr6mib18bM8FMac8+VNrHtZDBBrAy8dMuMwCj8 MlbQ== X-Received: by 10.66.228.199 with SMTP id sk7mr17104781pac.78.1446809929909; Fri, 06 Nov 2015 03:38:49 -0800 (PST) Received: from localhost.localdomain ([103.46.142.42]) by smtp.gmail.com with ESMTPSA id pn8sm13672592pbb.16.2015.11.06.03.38.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Nov 2015 03:38:48 -0800 (PST) From: Caesar Wang To: Heiko Stuebner , Mark Brown Subject: [PATCH v2 1/3] ASoC: rockchip: i2s: change bclk and lrck according to sample rates Date: Fri, 6 Nov 2015 19:38:14 +0800 Message-Id: <1446809896-11254-2-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446809896-11254-1-git-send-email-wxt@rock-chips.com> References: <1446809896-11254-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151106_033910_828430_2C598705 X-CRM114-Status: GOOD ( 14.24 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kmixter@chromium.org, alsa-devel@alsa-project.org, Liam Girdwood , linux-kernel@vger.kernel.org, Takashi Iwai , Doug Anderson , Jaroslav Kysela , linux-rockchip@lists.infradead.org, Dylan Reid , Caesar Wang , Sonny Rao , benchan@chromium.org, linux-arm-kernel@lists.infradead.org, Cheng-Yi Chiang MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch sets the dividers autonomously. when i2s works on master mode, and sample rates changed. We need to change bclk and lrck at the same time for cpu internal side. As the input source clock to the module is MCLK_I2S, and by the divider of the module, the clock generator generates SCLK and LRCK to transmitter and receiver. Signed-off-by: Caesar Wang --- Changes in v2: - move the set clock divider into rockchip i2s. sound/soc/rockchip/rockchip_i2s.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c index b936102..b349935 100644 --- a/sound/soc/rockchip/rockchip_i2s.c +++ b/sound/soc/rockchip/rockchip_i2s.c @@ -41,6 +41,7 @@ struct rk_i2s_dev { */ bool tx_start; bool rx_start; + bool is_master_mode; }; static int i2s_runtime_suspend(struct device *dev) @@ -174,9 +175,11 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, case SND_SOC_DAIFMT_CBS_CFS: /* Set source clock in Master mode */ val = I2S_CKR_MSS_MASTER; + i2s->is_master_mode = true; break; case SND_SOC_DAIFMT_CBM_CFM: val = I2S_CKR_MSS_SLAVE; + i2s->is_master_mode = false; break; default: return -EINVAL; @@ -227,6 +230,26 @@ static int rockchip_i2s_hw_params(struct snd_pcm_substream *substream, { struct rk_i2s_dev *i2s = to_info(dai); unsigned int val = 0; + unsigned int mclk_rate, bclk_rate, div_bclk, div_lrck; + + if (i2s->is_master_mode) { + mclk_rate = clk_get_rate(i2s->mclk); + bclk_rate = 2 * 32 * params_rate(params); + if (bclk_rate && mclk_rate % bclk_rate) + return -EINVAL; + + div_bclk = mclk_rate / bclk_rate; + div_lrck = bclk_rate / params_rate(params); + regmap_update_bits(i2s->regmap, I2S_CKR, + I2S_CKR_MDIV_MASK, + I2S_CKR_MDIV(div_bclk)); + + regmap_update_bits(i2s->regmap, I2S_CKR, + I2S_CKR_TSD_MASK | + I2S_CKR_RSD_MASK, + I2S_CKR_TSD(div_lrck) | + I2S_CKR_RSD(div_lrck)); + } switch (params_format(params)) { case SNDRV_PCM_FORMAT_S8: