Skip to contentSkip to conversation

ASoC: wm8960: Let wm8960 codec driver manage its own MCLK

PATCH Superseded Zidan Wang 2 participants 2 messages Dec 3, 2014

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zidan Wang

author
#0 lore raw

PATCH 1/1 ASoC: wm8960: Let wm8960 codec driver manage its own MCLK

When we want to use wm8960 codec, we should enable its MCLK in machine driver. It's reasonable for wm8960 codec driver to manage its own MCLK to save power.

Enable runtime power management, and auto enable/disable MCLK in pm_runtime resume and suspend. When wm8960 codec is being used, it will triger resume() to enable MCLK. When codec is not being used, it will triger suspend() to disable MCLK and power down PLL.

---
 include/sound/wm8960.h    |  1 +
 sound/soc/codecs/wm8960.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
include/sound/wm8960.h +1 -0
index e8ce8ee..d7e84ed 100644
@@ -16,6 +16,7 @@
 #define WM8960_DRES_MAX  3
 
 struct wm8960_data {
+	struct clk *mclk;
 	bool capless;  /* Headphone outputs configured in capless mode */
 
 	bool shared_lrclk;  /* DAC and ADC LRCLKs are wired together */
sound/soc/codecs/wm8960.c +51 -0

87 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw

sound/soc/codecs/wm8960.c static void wm8960_set_pdata_from_of(struct i2c_client *i2c, · line 994

Quoted 7 lines · Zidan Wang

#include <sound/core.h>

sound/soc/codecs/wm8960.c +2 -0
@@ -988,6 +990,8 @@ static void wm8960_set_pdata_from_of(struct i2c_client *i2c,
 
 	if (of_property_read_bool(np, "wlf,shared-lrclk"))
 		pdata->shared_lrclk = true;
+
+	pdata->mclk = devm_clk_get(&i2c->dev, NULL);

This isn't platform data then... we also need to check the return code here and handle at least probe deferral.

sound/soc/codecs/wm8960.c static int wm8960_i2c_probe(struct i2c_client *i2c, · line 1019

Quoted 2 lines
sound/soc/codecs/wm8960.c +2 -0
+    /* Mark the mclk pointer to NULL if no mclk assigned */
+	if (IS_ERR(wm8960->pdata.mclk)) {

Indentation is wrong for the comment here.

sound/soc/codecs/wm8960.c static int wm8960_i2c_probe(struct i2c_client *i2c, · line 1024

Quoted 5 lines
sound/soc/codecs/wm8960.c +5 -0
+		/* But do not ignore the request for probe defer */
+		if (PTR_ERR(wm8960->pdata.mclk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		wm8960->pdata.mclk = NULL;
+	}

OK, so we are trying to handle probe deferral - but this should be next to the clk_get().

sound/soc/codecs/wm8960.c static int wm8960_i2c_remove(struct i2c_client *client) · line 1078

Quoted 2 lines
sound/soc/codecs/wm8960.c +2 -0
+	if (wm8960->pdata.mclk) {
+		ret = clk_prepare_enable(wm8960->pdata.mclk);

Just continue to use !IS_ERR() - NULL is a valid clock.

sound/soc/codecs/wm8960.c static int wm8960_i2c_remove(struct i2c_client *client) · line 1093

Quoted 6 lines
sound/soc/codecs/wm8960.c +6 -0
+static int wm8960_runtime_suspend(struct device *dev)
+{
+	struct wm8960_priv *wm8960 = dev_get_drvdata(dev);
+
+	/* Power down PLL to save power */
+	regmap_update_bits(wm8960->regmap, WM8960_POWER2, 0x1, 0);

This isn't undone by the resume.