public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
From: Bo Shen <voice.shen@atmel.com>
To: Mark Brown <broonie@kernel.org>
Cc: nicolas.ferre@atmel.com, b.brezillon.dev@gmail.com,
	linux-arm-kernel@lists.infradead.org,
	linux-sound@vger.kernel.org, alsa-devel@alsa-project.org,
	Bo Shen <voice.shen@atmel.com>
Subject: [RFC PATCH] ASoC: wm8904: add CCF support
Date: Fri, 21 Mar 2014 02:51:02 +0000	[thread overview]
Message-ID: <1395370262-23305-1-git-send-email-voice.shen@atmel.com> (raw)

Enable WM8904 to support common clock framework.
And also supports different clk configuration.

Signed-off-by: Bo Shen <voice.shen@atmel.com>
---

 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 <linux/clk.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
@@ -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);
-- 
1.8.5.2


             reply	other threads:[~2014-03-21  2:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-21  2:51 Bo Shen [this message]
2014-03-21 10:37 ` [RFC PATCH] ASoC: wm8904: add CCF support Mark Rutland
2014-03-21 11:55   ` Mark Brown
2014-03-24  2:15     ` Bo Shen
2014-03-24 11:06       ` Mark Brown
2014-03-25  8:01         ` Bo Shen
2014-03-25  8:19           ` Bo Shen
2014-03-24  9:44     ` Boris BREZILLON
2014-03-24 11:07       ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395370262-23305-1-git-send-email-voice.shen@atmel.com \
    --to=voice.shen@atmel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=b.brezillon.dev@gmail.com \
    --cc=broonie@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox