From patchwork Thu Jul 28 21:57:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 9251775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DBE06075F for ; Thu, 28 Jul 2016 22:44:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DBC027F60 for ; Thu, 28 Jul 2016 22:44:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2164127F80; Thu, 28 Jul 2016 22:44:20 +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=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no 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 6824C27F60 for ; Thu, 28 Jul 2016 22:44:19 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5EED92665C2; Fri, 29 Jul 2016 00:44:18 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E4E392665F0; Fri, 29 Jul 2016 00:38:09 +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 451E92665F0; Fri, 29 Jul 2016 00:38:09 +0200 (CEST) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by alsa0.perex.cz (Postfix) with ESMTP id DD49526667C for ; Thu, 28 Jul 2016 23:57:21 +0200 (CEST) Received: by mail-pf0-f195.google.com with SMTP id y134so4307179pfg.3 for ; Thu, 28 Jul 2016 14:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=HlSnxQhhrlOkkmI/qjkwDNjT3dRaGGty/YP5aINJjug=; b=zifEKRHsgNVhbMtDpg4N+xGq8HZ4fFf94MiFsmUQadhsmSeYpZA4d900TBZmKoWCDy FgctZTCdePlVwMLxVdn2xUrZ4OAiJKK0WHc8P9TzamyaEbESJw10pQQO0yUi6e1w/uxj TCfPgePvpvjWltJ+nTP6vVFkMp8n3jw0VlKXGgaUnaPEDlm2i5zx09KWYNltYV/Wndrs oIERDrix91tDgefyBG0YQ/cVdIXi4zVXLD0yvvhSDTlTzFOs084Il6GLxYBOpmwICoEI lxsuUjFzadc1P9nKQTgw93Ke7khEoxELfZ4Rcwt43ugi2eIIG0JPjCIJDTKyqyTTbkBa n4pQ== 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; bh=HlSnxQhhrlOkkmI/qjkwDNjT3dRaGGty/YP5aINJjug=; b=Olodx9AHV2ee64y4aW4DV4vr7VQJ5jCbu09hpVB7QGwOdOV2VcrYef1nz5ZIWeekQA Kqi023/D73Cgnl9NoCguZJ2M8WUWIIC8xo0RhEGupxBHGjdlmDbaFjxq/pf0lxELxqI2 fp/lb5LfpV5hHw0+GXIBNRjD70sfeHaouL5lzeazZPDzltLhWp9SmK7GxmfL52HemTTo uyTh82/YmExMIYWE9Bc/fKbSO558OwiTdxVTEWZ7RjqJlq8lfXLC9XTKebWnh0usRo18 y3FN08Yh6GMa1iGuFN8BkjZN5i+AotCvwRrEmqHhVX962eInMNnJ62kodkLpWGfxLz53 bN/w== X-Gm-Message-State: AEkoouv2MjOya2NlX90fiUWkbTUGPK532yVD1J4YwGSWVzXVvC6YoLB4VIJOH1oCCHMDKg== X-Received: by 10.98.13.157 with SMTP id 29mr62778628pfn.105.1469743040352; Thu, 28 Jul 2016 14:57:20 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id 191sm19407409pfx.68.2016.07.28.14.57.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jul 2016 14:57:19 -0700 (PDT) From: Nicolin Chen To: broonie@kernel.org Date: Thu, 28 Jul 2016 14:57:16 -0700 Message-Id: <1469743036-20034-1-git-send-email-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.1.4 Cc: mark.rutland@arm.com, oder_chiou@realtek.com, alsa-devel@alsa-project.org, devicetree@vger.kernel.org, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, bardliao@realtek.com Subject: [alsa-devel] [PATCH v2] ASoC: rt5659: Add mclk controls 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The codec driver should control the mclk. So this patch adds this support. Signed-off-by: Nicolin Chen Acked-by: Rob Herring --- Changlog: v1->v2 * Only set the mclk pointer to NULL when getting an ENOENT error code (i.e. no clock is specified) -- corrected by Lars-Peter Documentation/devicetree/bindings/sound/rt5659.txt | 3 +++ sound/soc/codecs/rt5659.c | 24 ++++++++++++++++++++++ sound/soc/codecs/rt5659.h | 1 + 3 files changed, 28 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/rt5659.txt b/Documentation/devicetree/bindings/sound/rt5659.txt index 5f79e7f..1766e05 100644 --- a/Documentation/devicetree/bindings/sound/rt5659.txt +++ b/Documentation/devicetree/bindings/sound/rt5659.txt @@ -12,6 +12,9 @@ Required properties: Optional properties: +- clocks: The phandle of the master clock to the CODEC +- clock-names: Should be "mclk" + - realtek,in1-differential - realtek,in3-differential - realtek,in4-differential diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c index 1b30914..42c183f 100644 --- a/sound/soc/codecs/rt5659.c +++ b/sound/soc/codecs/rt5659.c @@ -9,6 +9,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -3565,7 +3566,9 @@ static int rt5659_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) static int rt5659_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { + struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); + int ret; switch (level) { case SND_SOC_BIAS_PREPARE: @@ -3582,6 +3585,17 @@ static int rt5659_set_bias_level(struct snd_soc_codec *codec, RT5659_PWR_FV1 | RT5659_PWR_FV2); break; + case SND_SOC_BIAS_STANDBY: + if (dapm->bias_level == SND_SOC_BIAS_OFF) { + ret = clk_prepare_enable(rt5659->mclk); + if (ret) { + dev_err(codec->dev, + "failed to enable MCLK: %d\n", ret); + return ret; + } + } + break; + case SND_SOC_BIAS_OFF: regmap_update_bits(rt5659->regmap, RT5659_PWR_DIG_1, RT5659_PWR_LDO, 0); @@ -3591,6 +3605,7 @@ static int rt5659_set_bias_level(struct snd_soc_codec *codec, RT5659_PWR_MB | RT5659_PWR_VREF2); regmap_update_bits(rt5659->regmap, RT5659_DIG_MISC, RT5659_DIG_GATE_CTRL, 0); + clk_disable_unprepare(rt5659->mclk); break; default: @@ -4020,6 +4035,15 @@ static int rt5659_i2c_probe(struct i2c_client *i2c, regmap_write(rt5659->regmap, RT5659_RESET, 0); + /* Check if MCLK provided */ + rt5659->mclk = devm_clk_get(&i2c->dev, "mclk"); + if (IS_ERR(rt5659->mclk)) { + if (PTR_ERR(rt5659->mclk) != -ENOENT) + return PTR_ERR(rt5659->mclk); + /* Otherwise mark the mclk pointer to NULL */ + rt5659->mclk = NULL; + } + rt5659_calibrate(rt5659); /* line in diff mode*/ diff --git a/sound/soc/codecs/rt5659.h b/sound/soc/codecs/rt5659.h index d31c9e5..d69b0eb 100644 --- a/sound/soc/codecs/rt5659.h +++ b/sound/soc/codecs/rt5659.h @@ -1796,6 +1796,7 @@ struct rt5659_priv { struct gpio_desc *gpiod_reset; struct snd_soc_jack *hs_jack; struct delayed_work jack_detect_work; + struct clk *mclk; int sysclk; int sysclk_src;