From patchwork Fri Mar 21 02:51:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Shen X-Patchwork-Id: 3871081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BF6ECBF540 for ; Fri, 21 Mar 2014 02:54:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CC76420220 for ; Fri, 21 Mar 2014 02:54:19 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FCB1201F4 for ; Fri, 21 Mar 2014 02:54:18 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WQpav-0003I7-II; Fri, 21 Mar 2014 02:54:05 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WQpas-00076n-Vv; Fri, 21 Mar 2014 02:54:03 +0000 Received: from nasmtp01.atmel.com ([192.199.1.246] helo=DVREDG02.corp.atmel.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WQpap-00075W-MO for linux-arm-kernel@lists.infradead.org; Fri, 21 Mar 2014 02:54:00 +0000 Received: from sjogate2.atmel.com (10.42.103.223) by DVREDG02.corp.atmel.com (10.42.103.31) with Microsoft SMTP Server id 14.2.347.0; Thu, 20 Mar 2014 20:51:30 -0600 Received: from Dev4Android.corp.atmel.com ([10.217.2.124]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id s2L2iT9J013061; Thu, 20 Mar 2014 19:44:29 -0700 (PDT) From: Bo Shen To: Mark Brown Subject: [RFC PATCH] ASoC: wm8904: add CCF support Date: Fri, 21 Mar 2014 10:51:02 +0800 Message-ID: <1395370262-23305-1-git-send-email-voice.shen@atmel.com> X-Mailer: git-send-email 1.8.5.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140320_225359_902451_45DF5913 X-CRM114-Status: GOOD ( 11.54 ) X-Spam-Score: -1.9 (-) Cc: alsa-devel@alsa-project.org, b.brezillon.dev@gmail.com, nicolas.ferre@atmel.com, linux-sound@vger.kernel.org, Bo Shen , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Enable WM8904 to support common clock framework. And also supports different clk configuration. Signed-off-by: Bo Shen --- Documentation/devicetree/bindings/sound/wm8904.txt | 57 ++++++++++++++++++++++ sound/soc/codecs/wm8904.c | 39 +++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/wm8904.txt diff --git a/Documentation/devicetree/bindings/sound/wm8904.txt b/Documentation/devicetree/bindings/sound/wm8904.txt new file mode 100644 index 0000000..039374d --- /dev/null +++ b/Documentation/devicetree/bindings/sound/wm8904.txt @@ -0,0 +1,57 @@ +WM8904 audio CODEC + +This device supports I2C only. + +Required properties: + - compatible: "wlf,wm8904" + - reg: the I2C address of the device. + + if work with CCF, the following properties as required: + - wlf,sysclk-from-mclk: set the sys clock is driven from mclk, + - wlf,mclk-use-xtal: if the mclk is generated by crystal. + if without this property, the mclk is generated from SOC. + - clocks: which clock generated clock to mclk. + - clock-names: the clock names use for retrieve. + - wlf,mclk-freq: mclk's frequency + + +Pins on the device (for linking into audio routes): + + * IN1L + * IN1R + * IN2L + * IN2R + * IN3L + * IN3R + * HPOUTL + * HPOUTR + * LINEOUTL + * LINEOUTR + * MICBIAS + +Examples: + +1. General usage: +codec: wm8904@1a { + compatible = "wlf,wm8904"; + reg = <0x1a>; +}; + +2. Working with CCF supports and using crystall provide mclk: +codec: wm8904@1a { + compatible = "wlf,wm8904"; + reg = <0x1a>; + wlf,sysclk-from-mclk; + wlf,mclk-use-xtal; + wlf,mclk-freq = <12000000>; +}; + +3. Working with CCF supports and using SoC provide mclk: +codec: wm8904@1a { + compatible = "wlf,wm8904"; + reg = <0x1a>; + wlf,sysclk-from-mclk; + clocks = <&pck0>; + clock-names = "mclk"; + wlf,mclk-freq = <32768>; +}; diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c index 49c35c3..99e3e90 100644 --- a/sound/soc/codecs/wm8904.c +++ b/sound/soc/codecs/wm8904.c @@ -11,6 +11,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -49,6 +50,10 @@ static const char *wm8904_supply_names[WM8904_NUM_SUPPLIES] = { /* codec private data */ struct wm8904_priv { struct regmap *regmap; + struct clk *mclk; + bool sysclk_from_mclk; + bool mclk_use_xtal; + u32 mclk_freq; enum wm8904_type devtype; @@ -1828,6 +1833,9 @@ static int wm8904_set_bias_level(struct snd_soc_codec *codec, switch (level) { case SND_SOC_BIAS_ON: + if (IS_ENABLED(CONFIG_COMMON_CLK)) + if (!wm8904->mclk_use_xtal) + clk_prepare_enable(wm8904->mclk); break; case SND_SOC_BIAS_PREPARE: @@ -1894,6 +1902,9 @@ static int wm8904_set_bias_level(struct snd_soc_codec *codec, regulator_bulk_disable(ARRAY_SIZE(wm8904->supplies), wm8904->supplies); + if (IS_ENABLED(CONFIG_COMMON_CLK)) + if (!wm8904->mclk_use_xtal) + clk_disable_unprepare(wm8904->mclk); break; } codec->dapm.bias_level = level; @@ -2139,6 +2150,34 @@ static int wm8904_i2c_probe(struct i2c_client *i2c, return ret; } + if (IS_ENABLED(CONFIG_COMMON_CLK)) { + struct device_node *np = i2c->dev.of_node; + wm8904->sysclk_from_mclk = + of_property_read_bool(np, "wlf,sysclk-from-mclk"); + if (wm8904->sysclk_from_mclk) { + wm8904->mclk_use_xtal = + of_property_read_bool(np, "wlf,mclk-use-xtal"); + + ret = of_property_read_u32(np, "wlf,mclk-freq", + &wm8904->mclk_freq); + if (ret) { + dev_err(&i2c->dev, "Failed to read mclk freq"); + goto err_enable; + } + + if (!wm8904->mclk_use_xtal) { + wm8904->mclk = devm_clk_get(&i2c->dev, "mclk"); + if (IS_ERR(wm8904->mclk)) { + dev_err(&i2c->dev, "Failed to get MCLK\n"); + ret = PTR_ERR(wm8904->mclk); + goto err_enable; + } + + clk_set_rate(wm8904->mclk, wm8904->mclk_freq); + } + } + } + ret = regmap_read(wm8904->regmap, WM8904_SW_RESET_AND_ID, &val); if (ret < 0) { dev_err(&i2c->dev, "Failed to read ID register: %d\n", ret);