From patchwork Tue Feb 2 03:44:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 8186761 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 79549BEEED for ; Tue, 2 Feb 2016 03:45:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9281620166 for ; Tue, 2 Feb 2016 03:45:58 +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 AF76B20270 for ; Tue, 2 Feb 2016 03:45:57 +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 1aQRuf-0006IC-Bp; Tue, 02 Feb 2016 03:45:57 +0000 Received: from mail-pf0-f193.google.com ([209.85.192.193]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aQRua-00065w-3t for linux-rockchip@lists.infradead.org; Tue, 02 Feb 2016 03:45:53 +0000 Received: by mail-pf0-f193.google.com with SMTP id n128so8304485pfn.3 for ; Mon, 01 Feb 2016 19:45:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZMHw715budfjuOi+dyNSTTKD1/fZdp8XGhGeiic3S1M=; b=bwWulWCtM3mNSw/3HIiyeWCK9X6KFu7jodsZ/n+vbGt92rSIE6ImrjW+Q4n4xFg/iL Lv3Blv+XM8MCcK5l/BNi85oOWMRdvzS1oTmouvtWvnZrq4Y3jYmEYUPeD5+Gjgqj0/i0 nuxXWzzbBksjB5PQHS++YCfJ2bofiAQ/HRrvPS/zEg1lyFpM2ZAhivgK+4kLxe9B7l0y vGJLrhDgwMsSHV0Tmxb6dXNtbukKX4KY9YRM2ExhekF1Hcv9JzdhkxwQe8EQ9JfT2H1M 7MleGyDc9dxr5mLaKPtfSzs5zo0G7KY1voNlzIQ4rfeTxlUszmGsgh3qeEGpjXYgUGxn 4Kmw== X-Gm-Message-State: AG10YOTd3M0owAC3UobACWs5y6aR9tZsIOnPiJ+Py5X8NnR6GN+jC40E+/vtfLkVoOzKtQ== X-Received: by 10.98.79.28 with SMTP id d28mr27169981pfb.77.1454384731761; Mon, 01 Feb 2016 19:45:31 -0800 (PST) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id 85sm32510204pfl.18.2016.02.01.19.45.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Feb 2016 19:45:30 -0800 (PST) From: Caesar Wang To: broonie@kernel.org, bardliao@realtek.com Subject: [PATCH v5 7/8] ASoC: rt5616: add the mclk for the codec driver Date: Tue, 2 Feb 2016 11:44:40 +0800 Message-Id: <1454384680-7197-3-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454384680-7197-1-git-send-email-wxt@rock-chips.com> References: <1454384032-6794-1-git-send-email-wxt@rock-chips.com> <1454384680-7197-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160201_194552_327417_23DDCD63 X-CRM114-Status: GOOD ( 16.91 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: oder_chiou@realtek.com, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, heiko@sntech.de, jeffy.chen@rock-chips.com, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, robh+dt@kernel.org, keescook@google.com, leozwang@google.com, Caesar Wang MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 adds the code to enable the clock to the CODEC driver if it needs the clock enabled. In some case, We need to claim the clock which is driving the codec so that when we enable clock gating, we continue to clock the codec when needed. We can enable and disable the clock source if mclk provided. Signed-off-by: Caesar Wang Cc: alsa-devel@alsa-project.org Cc: Mark Brown Cc: Bard Liao --- Changes in v5: - Cc related alsa experts. Changes in v4: - AS the previous discussed by them, add the mclk for codec. (https://patchwork.kernel.org/patch/8041001/) sound/soc/codecs/rt5616.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sound/soc/codecs/rt5616.c b/sound/soc/codecs/rt5616.c index d4bdf9f..fdca636 100644 --- a/sound/soc/codecs/rt5616.c +++ b/sound/soc/codecs/rt5616.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,7 @@ struct rt5616_priv { struct snd_soc_codec *codec; struct delayed_work patch_work; struct regmap *regmap; + struct clk *mclk; int sysclk; int sysclk_src; @@ -1159,7 +1161,34 @@ static int rt5616_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, static int rt5616_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { + struct rt5616_priv *rt5616 = snd_soc_codec_get_drvdata(codec); + int ret; + switch (level) { + + case SND_SOC_BIAS_ON: + break; + + case SND_SOC_BIAS_PREPARE: + /* + * SND_SOC_BIAS_PREPARE is called while preparing for a + * transition to ON or away from ON. If current bias_level + * is SND_SOC_BIAS_ON, then it is preparing for a transition + * away from ON. Disable the clock in that case, otherwise + * enable it. + */ + if (IS_ERR(rt5616->mclk)) + break; + + if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) { + clk_disable_unprepare(rt5616->mclk); + } else { + ret = clk_prepare_enable(rt5616->mclk); + if (ret) + return ret; + } + break; + case SND_SOC_BIAS_STANDBY: if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { snd_soc_update_bits(codec, RT5616_PWR_ANLG1, @@ -1198,6 +1227,11 @@ static int rt5616_probe(struct snd_soc_codec *codec) { struct rt5616_priv *rt5616 = snd_soc_codec_get_drvdata(codec); + /* Check if MCLK provided */ + rt5616->mclk = devm_clk_get(codec->dev, "mclk"); + if (PTR_ERR(rt5616->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + rt5616->codec = codec; return 0;