LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
@ 2014-12-04 12:41 Zidan Wang
2014-12-05 17:01 ` Charles Keepax
2014-12-08 10:15 ` Charles Keepax
0 siblings, 2 replies; 8+ messages in thread
From: Zidan Wang @ 2014-12-04 12:41 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, perex, tiwai, lars, ckeepax, Li.Xiubo, patches,
alsa-devel, linux-kernel, Zidan Wang
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.
If platform data is not supplied, we will get MCLK from device tree and check
the return code to handle probe deferral.
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.
Signed-off-by: Zidan Wang <b50113@freescale.com>
---
include/sound/wm8960.h | 1 +
sound/soc/codecs/wm8960.c | 56 ++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/include/sound/wm8960.h b/include/sound/wm8960.h
index e8ce8ee..d7e84ed 100644
--- a/include/sound/wm8960.h
+++ b/include/sound/wm8960.h
@@ -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 */
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 031a1ae..ea5f0b7 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -15,6 +15,8 @@
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <sound/core.h>
@@ -978,7 +980,7 @@ static const struct regmap_config wm8960_regmap = {
.volatile_reg = wm8960_volatile,
};
-static void wm8960_set_pdata_from_of(struct i2c_client *i2c,
+static int wm8960_set_pdata_from_of(struct i2c_client *i2c,
struct wm8960_data *pdata)
{
const struct device_node *np = i2c->dev.of_node;
@@ -988,6 +990,15 @@ 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);
+
+ if (IS_ERR(pdata->mclk)) {
+ if (PTR_ERR(pdata->mclk) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ }
+
+ return 0;
}
static int wm8960_i2c_probe(struct i2c_client *i2c,
@@ -1008,8 +1019,11 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
if (pdata)
memcpy(&wm8960->pdata, pdata, sizeof(struct wm8960_data));
- else if (i2c->dev.of_node)
- wm8960_set_pdata_from_of(i2c, &wm8960->pdata);
+ else if (i2c->dev.of_node) {
+ ret = wm8960_set_pdata_from_of(i2c, &wm8960->pdata);
+ if (ret != 0)
+ return ret;
+ }
ret = wm8960_reset(wm8960->regmap);
if (ret != 0) {
@@ -1041,6 +1055,9 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
i2c_set_clientdata(i2c, wm8960);
+ pm_runtime_enable(&i2c->dev);
+ pm_request_idle(&i2c->dev);
+
ret = snd_soc_register_codec(&i2c->dev,
&soc_codec_dev_wm8960, &wm8960_dai, 1);
@@ -1053,6 +1070,38 @@ static int wm8960_i2c_remove(struct i2c_client *client)
return 0;
}
+#ifdef CONFIG_PM_RUNTIME
+static int wm8960_runtime_resume(struct device *dev)
+{
+ struct wm8960_priv *wm8960 = dev_get_drvdata(dev);
+ int ret;
+
+ if (!IS_ERR(wm8960->pdata.mclk)) {
+ ret = clk_prepare_enable(wm8960->pdata.mclk);
+ if (ret) {
+ dev_err(dev, "Failed to enable MCLK: %d\n", ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int wm8960_runtime_suspend(struct device *dev)
+{
+ struct wm8960_priv *wm8960 = dev_get_drvdata(dev);
+
+ if (!IS_ERR(wm8960->pdata.mclk))
+ clk_disable_unprepare(wm8960->pdata.mclk);
+
+ return 0;
+}
+#endif
+
+static const struct dev_pm_ops wm8960_pm = {
+ SET_RUNTIME_PM_OPS(wm8960_runtime_suspend, wm8960_runtime_resume, NULL)
+};
+
static const struct i2c_device_id wm8960_i2c_id[] = {
{ "wm8960", 0 },
{ }
@@ -1070,6 +1119,7 @@ static struct i2c_driver wm8960_i2c_driver = {
.name = "wm8960",
.owner = THIS_MODULE,
.of_match_table = wm8960_of_match,
+ .pm = &wm8960_pm,
},
.probe = wm8960_i2c_probe,
.remove = wm8960_i2c_remove,
--
1.9.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-04 12:41 [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK Zidan Wang
@ 2014-12-05 17:01 ` Charles Keepax
2014-12-05 17:39 ` Mark Brown
2014-12-08 10:15 ` Charles Keepax
1 sibling, 1 reply; 8+ messages in thread
From: Charles Keepax @ 2014-12-05 17:01 UTC (permalink / raw)
To: Zidan Wang
Cc: broonie, lgirdwood, perex, tiwai, lars, Li.Xiubo, patches,
alsa-devel, linux-kernel
On Thu, Dec 04, 2014 at 08:41:19PM +0800, Zidan Wang wrote:
> 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.
>
> If platform data is not supplied, we will get MCLK from device tree and check
> the return code to handle probe deferral.
>
> 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.
>
> Signed-off-by: Zidan Wang <b50113@freescale.com>
> ---
> include/sound/wm8960.h | 1 +
> sound/soc/codecs/wm8960.c | 56 ++++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 54 insertions(+), 3 deletions(-)
>
> diff --git a/include/sound/wm8960.h b/include/sound/wm8960.h
> index e8ce8ee..d7e84ed 100644
> --- a/include/sound/wm8960.h
> +++ b/include/sound/wm8960.h
> @@ -16,6 +16,7 @@
> #define WM8960_DRES_MAX 3
>
> struct wm8960_data {
> + struct clk *mclk;
Is this really pdata? Would the pdata entry to locate the clock
not be a string holding the clock name that you call clk_get on,
rather than a clk pointer itself? Probably this should go in
wm8960_priv instead.
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-05 17:01 ` Charles Keepax
@ 2014-12-05 17:39 ` Mark Brown
2014-12-08 9:49 ` Zidan Wang
0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2014-12-05 17:39 UTC (permalink / raw)
To: Charles Keepax
Cc: Zidan Wang, lgirdwood, perex, tiwai, lars, Li.Xiubo, patches,
alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
On Fri, Dec 05, 2014 at 05:01:56PM +0000, Charles Keepax wrote:
> On Thu, Dec 04, 2014 at 08:41:19PM +0800, Zidan Wang wrote:
> > struct wm8960_data {
> > + struct clk *mclk;
> Is this really pdata? Would the pdata entry to locate the clock
> not be a string holding the clock name that you call clk_get on,
> rather than a clk pointer itself? Probably this should go in
> wm8960_priv instead.
There should be no platform data of any kind for the clock, the name
should be fixed and defined in terms of the name of the clock on the
device requesting it. The code is actually doing the right thing here,
it's just that it's put the variable into the platform data because
currently the driver just uses the platform data as the driver data.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-05 17:39 ` Mark Brown
@ 2014-12-08 9:49 ` Zidan Wang
2014-12-08 10:15 ` Charles Keepax
2014-12-08 11:14 ` Mark Brown
0 siblings, 2 replies; 8+ messages in thread
From: Zidan Wang @ 2014-12-08 9:49 UTC (permalink / raw)
To: Mark Brown, Charles Keepax
Cc: lgirdwood, perex, tiwai, lars, Li.Xiubo, patches, alsa-devel,
linux-kernel
So I should move mclk to wm8960_priv.
And doing wm8960_priv->mclk = devm_clk_get(&i2c->dev, "codec_mclk") in wm8960_i2c_probe.
Best Regards,
Zidan
-----Original Message-----
From: Mark Brown [mailto:broonie@kernel.org]
Sent: Saturday, December 06, 2014 1:40 AM
To: Charles Keepax
Cc: Wang Zidan-B50113; lgirdwood@gmail.com; perex@perex.cz; tiwai@suse.de; lars@metafoo.de; Xiubo Li-B47053; patches@opensource.wolfsonmicro.com; alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org
Subject: Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
On Fri, Dec 05, 2014 at 05:01:56PM +0000, Charles Keepax wrote:
> On Thu, Dec 04, 2014 at 08:41:19PM +0800, Zidan Wang wrote:
> > struct wm8960_data {
> > + struct clk *mclk;
> Is this really pdata? Would the pdata entry to locate the clock not be
> a string holding the clock name that you call clk_get on, rather than
> a clk pointer itself? Probably this should go in wm8960_priv instead.
There should be no platform data of any kind for the clock, the name should be fixed and defined in terms of the name of the clock on the device requesting it. The code is actually doing the right thing here, it's just that it's put the variable into the platform data because currently the driver just uses the platform data as the driver data.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-08 9:49 ` Zidan Wang
@ 2014-12-08 10:15 ` Charles Keepax
2014-12-08 11:14 ` Mark Brown
1 sibling, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2014-12-08 10:15 UTC (permalink / raw)
To: Zidan Wang
Cc: Mark Brown, lgirdwood, perex, tiwai, lars, Li.Xiubo, patches,
alsa-devel, linux-kernel
On Mon, Dec 08, 2014 at 09:49:51AM +0000, Zidan Wang wrote:
> So I should move mclk to wm8960_priv.
> And doing wm8960_priv->mclk = devm_clk_get(&i2c->dev, "codec_mclk") in wm8960_i2c_probe.
>
> Best Regards,
> Zidan
>
> -----Original Message-----
>From the sounds of Mark's comment I believe he is happy with it
where it is, and if he is happy so am I.
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-08 9:49 ` Zidan Wang
2014-12-08 10:15 ` Charles Keepax
@ 2014-12-08 11:14 ` Mark Brown
2014-12-08 11:57 ` Charles Keepax
1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2014-12-08 11:14 UTC (permalink / raw)
To: Zidan Wang
Cc: Charles Keepax, lgirdwood, perex, tiwai, lars, Li.Xiubo, patches,
alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 211 bytes --]
On Mon, Dec 08, 2014 at 09:49:51AM +0000, Zidan Wang wrote:
> So I should move mclk to wm8960_priv.
> And doing wm8960_priv->mclk = devm_clk_get(&i2c->dev, "codec_mclk") in wm8960_i2c_probe.
Yes, please.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-08 11:14 ` Mark Brown
@ 2014-12-08 11:57 ` Charles Keepax
0 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2014-12-08 11:57 UTC (permalink / raw)
To: Mark Brown
Cc: Zidan Wang, lgirdwood, perex, tiwai, lars, Li.Xiubo, patches,
alsa-devel, linux-kernel
On Mon, Dec 08, 2014 at 11:14:45AM +0000, Mark Brown wrote:
> On Mon, Dec 08, 2014 at 09:49:51AM +0000, Zidan Wang wrote:
> > So I should move mclk to wm8960_priv.
> > And doing wm8960_priv->mclk = devm_clk_get(&i2c->dev, "codec_mclk") in wm8960_i2c_probe.
>
> Yes, please.
Apologies I totally misread you last email.
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK
2014-12-04 12:41 [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK Zidan Wang
2014-12-05 17:01 ` Charles Keepax
@ 2014-12-08 10:15 ` Charles Keepax
1 sibling, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2014-12-08 10:15 UTC (permalink / raw)
To: Zidan Wang
Cc: broonie, lgirdwood, perex, tiwai, lars, Li.Xiubo, patches,
alsa-devel, linux-kernel
On Thu, Dec 04, 2014 at 08:41:19PM +0800, Zidan Wang wrote:
> 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.
>
> If platform data is not supplied, we will get MCLK from device tree and check
> the return code to handle probe deferral.
>
> 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.
>
> Signed-off-by: Zidan Wang <b50113@freescale.com>
> ---
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-12-08 11:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-04 12:41 [alsa-devel][PATCH v3] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK Zidan Wang
2014-12-05 17:01 ` Charles Keepax
2014-12-05 17:39 ` Mark Brown
2014-12-08 9:49 ` Zidan Wang
2014-12-08 10:15 ` Charles Keepax
2014-12-08 11:14 ` Mark Brown
2014-12-08 11:57 ` Charles Keepax
2014-12-08 10:15 ` Charles Keepax
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).