From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org,
Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 07/11] ASoC: Actively manage MCLK for AT91SAM9G20-EK
Date: Wed, 18 Feb 2009 12:02:29 +0000 [thread overview]
Message-ID: <1234958553-16049-7-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <20090218120135.GA15414@sirena.org.uk>
We have software control of the MCLK for the WM8731 so save a bit of
power by actively managing it within the machine driver, enabling it
only while the codec is active.
Once ASoC supports multiple boards and doesn't require the soc-audio
device the initial clock setup should be pushed down into the arch/arm
code but for now this reduces merge issues.
Tested-by: Sedji Gaouaou <sedji.gaouaou@atmel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
sound/soc/atmel/sam9g20_wm8731.c | 68 ++++++++++++++++++++++++++++++++++++--
1 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index b7efdc8..ab32514 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -53,6 +53,9 @@
#include "atmel-pcm.h"
#include "atmel_ssc_dai.h"
+#define MCLK_RATE 12000000
+
+static struct clk *mclk;
static int at91sam9g20ek_startup(struct snd_pcm_substream *substream)
{
@@ -60,11 +63,12 @@ static int at91sam9g20ek_startup(struct snd_pcm_substream *substream)
struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
int ret;
- /* codec system clock is supplied by PCK0, set to 12MHz */
ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK,
- 12000000, SND_SOC_CLOCK_IN);
- if (ret < 0)
+ MCLK_RATE, SND_SOC_CLOCK_IN);
+ if (ret < 0) {
+ clk_disable(mclk);
return ret;
+ }
return 0;
}
@@ -190,6 +194,31 @@ static struct snd_soc_ops at91sam9g20ek_ops = {
.shutdown = at91sam9g20ek_shutdown,
};
+static int at91sam9g20ek_set_bias_level(struct snd_soc_card *card,
+ enum snd_soc_bias_level level)
+{
+ static int mclk_on;
+ int ret = 0;
+
+ switch (level) {
+ case SND_SOC_BIAS_ON:
+ case SND_SOC_BIAS_PREPARE:
+ if (!mclk_on)
+ ret = clk_enable(mclk);
+ if (ret == 0)
+ mclk_on = 1;
+ break;
+
+ case SND_SOC_BIAS_OFF:
+ case SND_SOC_BIAS_STANDBY:
+ if (mclk_on)
+ clk_disable(mclk);
+ mclk_on = 0;
+ break;
+ }
+
+ return ret;
+}
static const struct snd_soc_dapm_widget at91sam9g20ek_dapm_widgets[] = {
SND_SOC_DAPM_MIC("Int Mic", NULL),
@@ -248,6 +277,7 @@ static struct snd_soc_card snd_soc_at91sam9g20ek = {
.platform = &atmel_soc_platform,
.dai_link = &at91sam9g20ek_dai,
.num_links = 1,
+ .set_bias_level = at91sam9g20ek_set_bias_level,
};
static struct wm8731_setup_data at91sam9g20ek_wm8731_setup = {
@@ -267,12 +297,38 @@ static int __init at91sam9g20ek_init(void)
{
struct atmel_ssc_info *ssc_p = at91sam9g20ek_dai.cpu_dai->private_data;
struct ssc_device *ssc = NULL;
+ struct clk *pllb;
int ret;
if (!machine_is_at91sam9g20ek())
return -ENODEV;
/*
+ * Codec MCLK is supplied by PCK0 - set it up.
+ */
+ mclk = clk_get(NULL, "pck0");
+ if (IS_ERR(mclk)) {
+ printk(KERN_ERR "ASoC: Failed to get MCLK\n");
+ ret = PTR_ERR(mclk);
+ goto err;
+ }
+
+ pllb = clk_get(NULL, "pllb");
+ if (IS_ERR(mclk)) {
+ printk(KERN_ERR "ASoC: Failed to get PLLB\n");
+ ret = PTR_ERR(mclk);
+ goto err_mclk;
+ }
+ ret = clk_set_parent(mclk, pllb);
+ clk_put(pllb);
+ if (ret != 0) {
+ printk(KERN_ERR "ASoC: Failed to set MCLK parent\n");
+ goto err_mclk;
+ }
+
+ clk_set_rate(mclk, MCLK_RATE);
+
+ /*
* Request SSC device
*/
ssc = ssc_request(0);
@@ -303,6 +359,10 @@ static int __init at91sam9g20ek_init(void)
return ret;
err_ssc:
+err_mclk:
+ clk_put(mclk);
+ mclk = NULL;
+err:
return ret;
}
@@ -320,6 +380,8 @@ static void __exit at91sam9g20ek_exit(void)
platform_device_unregister(at91sam9g20ek_snd_device);
at91sam9g20ek_snd_device = NULL;
+ clk_put(mclk);
+ mclk = NULL;
}
module_init(at91sam9g20ek_init);
--
1.5.6.3
next prev parent reply other threads:[~2009-02-18 12:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-18 12:01 ASoC updates for 2.6.30 Mark Brown
2009-02-18 12:02 ` [PATCH 01/11] ASoC: Fix DaVinci module unload error Mark Brown
2009-02-18 12:02 ` [PATCH 02/11] ASoC: Fix WM8753 DAIs unregistering Mark Brown
2009-02-18 12:02 ` [PATCH 03/11] ASoC: Remove version display from the WM8731 driver Mark Brown
2009-02-18 12:02 ` [PATCH 04/11] ASoC: Clean up WM8731 bias level configuration Mark Brown
2009-02-18 12:02 ` [PATCH 05/11] ASoC: Improve diagnostics for AT91SAM9G20-EK probe Mark Brown
2009-02-18 12:02 ` [PATCH 06/11] ASoC: Check machine type before loading on AT91SAM9G20-EK Mark Brown
2009-02-18 12:02 ` Mark Brown [this message]
2009-02-18 12:02 ` [PATCH 08/11] ASoC: Rename AT91SAMG20-EK for applications Mark Brown
2009-02-18 12:02 ` [PATCH 09/11] ASoC: Shuffle WM8731 SPI and I2C device registration Mark Brown
2009-02-18 12:02 ` [PATCH 10/11] ASoC: Refactor WM8731 " Mark Brown
2009-02-18 12:02 ` [PATCH 11/11] ASoC: Remove version display from the WM8753 driver Mark Brown
2009-02-18 12:18 ` ASoC updates for 2.6.30 Takashi Iwai
2009-02-18 12:22 ` Takashi Iwai
2009-02-18 12:27 ` Takashi Iwai
2009-02-18 12:37 ` Mark Brown
2009-02-18 12:44 ` Takashi Iwai
2009-02-18 12:29 ` Mark Brown
2009-02-18 12:31 ` Takashi Iwai
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=1234958553-16049-7-git-send-email-broonie@opensource.wolfsonmicro.com \
--to=broonie@opensource.wolfsonmicro.com \
--cc=alsa-devel@alsa-project.org \
--cc=tiwai@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.