From d6943541158985030108e4a0a483cdadc3c80ee1 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 16 Feb 2009 13:38:11 +0000 Subject: ASoC: Improve diagnostics for AT91SAM9G20-EK probe We should display an error by default if we fail to register. Signed-off-by: Mark Brown --- sound/soc/atmel/sam9g20_wm8731.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sound/soc/atmel/sam9g20_wm8731.c') diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c index 6ea04be..be3f923 100644 --- a/sound/soc/atmel/sam9g20_wm8731.c +++ b/sound/soc/atmel/sam9g20_wm8731.c @@ -273,6 +273,7 @@ static int __init at91sam9g20ek_init(void) */ ssc = ssc_request(0); if (IS_ERR(ssc)) { + printk(KERN_ERR "ASoC: Failed to request SSC 0\n"); ret = PTR_ERR(ssc); ssc = NULL; goto err_ssc; @@ -281,8 +282,7 @@ static int __init at91sam9g20ek_init(void) at91sam9g20ek_snd_device = platform_device_alloc("soc-audio", -1); if (!at91sam9g20ek_snd_device) { - printk(KERN_DEBUG - "platform device allocation failed\n"); + printk(KERN_ERR "ASoC: Platform device allocation failed\n"); ret = -ENOMEM; } @@ -292,8 +292,7 @@ static int __init at91sam9g20ek_init(void) ret = platform_device_add(at91sam9g20ek_snd_device); if (ret) { - printk(KERN_DEBUG - "platform device allocation failed\n"); + printk(KERN_ERR "ASoC: Platform device allocation failed\n"); platform_device_put(at91sam9g20ek_snd_device); } -- cgit v1.1 From 40135ea07190316a789b2edfbf7c8131598bdf81 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 16 Feb 2009 16:04:05 +0000 Subject: ASoC: Check machine type before loading on AT91SAM9G20-EK Signed-off-by: Mark Brown --- sound/soc/atmel/sam9g20_wm8731.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sound/soc/atmel/sam9g20_wm8731.c') diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c index be3f923..b7efdc8 100644 --- a/sound/soc/atmel/sam9g20_wm8731.c +++ b/sound/soc/atmel/sam9g20_wm8731.c @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -268,6 +269,9 @@ static int __init at91sam9g20ek_init(void) struct ssc_device *ssc = NULL; int ret; + if (!machine_is_at91sam9g20ek()) + return -ENODEV; + /* * Request SSC device */ -- cgit v1.1 From 5de7f9b20069257aa5f0bb74723c8603adc5841a Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 16 Feb 2009 17:51:54 +0000 Subject: ASoC: Actively manage MCLK for AT91SAM9G20-EK 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 Signed-off-by: Mark Brown --- sound/soc/atmel/sam9g20_wm8731.c | 68 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) (limited to 'sound/soc/atmel/sam9g20_wm8731.c') 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); -- cgit v1.1 From 7ee753804185eb0a46ac964fd6a6564bd67290c9 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 16 Feb 2009 18:00:58 +0000 Subject: ASoC: Rename AT91SAMG20-EK for applications This is a bit more idiomatic and makes identifying a configuration based on the board type work better. Signed-off-by: Mark Brown --- sound/soc/atmel/sam9g20_wm8731.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound/soc/atmel/sam9g20_wm8731.c') diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c index ab32514..aa52423 100644 --- a/sound/soc/atmel/sam9g20_wm8731.c +++ b/sound/soc/atmel/sam9g20_wm8731.c @@ -273,7 +273,7 @@ static struct snd_soc_dai_link at91sam9g20ek_dai = { }; static struct snd_soc_card snd_soc_at91sam9g20ek = { - .name = "WM8731", + .name = "AT91SAMG20-EK", .platform = &atmel_soc_platform, .dai_link = &at91sam9g20ek_dai, .num_links = 1, -- cgit v1.1 From 5998102b9095fdb7c67755812038612afea315c5 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 16 Feb 2009 20:49:16 +0000 Subject: ASoC: Refactor WM8731 device registration Move the WM8731 driver to use a more standard device registration scheme where the device can be registered independantly of the ASoC probe. As a transition measure push the current manual code for registering the WM8731 into the individual machine driver probes. This allows separate patches to update the relevant architecture files with less risk of merge issues. Signed-off-by: Mark Brown --- sound/soc/atmel/sam9g20_wm8731.c | 43 +++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'sound/soc/atmel/sam9g20_wm8731.c') diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c index aa52423..173a239 100644 --- a/sound/soc/atmel/sam9g20_wm8731.c +++ b/sound/soc/atmel/sam9g20_wm8731.c @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -280,15 +281,41 @@ static struct snd_soc_card snd_soc_at91sam9g20ek = { .set_bias_level = at91sam9g20ek_set_bias_level, }; -static struct wm8731_setup_data at91sam9g20ek_wm8731_setup = { - .i2c_bus = 0, - .i2c_address = 0x1b, -}; +/* + * FIXME: This is a temporary bodge to avoid cross-tree merge issues. + * New drivers should register the wm8731 I2C device in the machine + * setup code (under arch/arm for ARM systems). + */ +static int wm8731_i2c_register(void) +{ + struct i2c_board_info info; + struct i2c_adapter *adapter; + struct i2c_client *client; + + memset(&info, 0, sizeof(struct i2c_board_info)); + info.addr = 0x1b; + strlcpy(info.type, "wm8731", I2C_NAME_SIZE); + + adapter = i2c_get_adapter(0); + if (!adapter) { + printk(KERN_ERR "can't get i2c adapter 0\n"); + return -ENODEV; + } + + client = i2c_new_device(adapter, &info); + i2c_put_adapter(adapter); + if (!client) { + printk(KERN_ERR "can't add i2c device at 0x%x\n", + (unsigned int)info.addr); + return -ENODEV; + } + + return 0; +} static struct snd_soc_device at91sam9g20ek_snd_devdata = { .card = &snd_soc_at91sam9g20ek, .codec_dev = &soc_codec_dev_wm8731, - .codec_data = &at91sam9g20ek_wm8731_setup, }; static struct platform_device *at91sam9g20ek_snd_device; @@ -340,6 +367,10 @@ static int __init at91sam9g20ek_init(void) } ssc_p->ssc = ssc; + ret = wm8731_i2c_register(); + if (ret != 0) + goto err_ssc; + at91sam9g20ek_snd_device = platform_device_alloc("soc-audio", -1); if (!at91sam9g20ek_snd_device) { printk(KERN_ERR "ASoC: Platform device allocation failed\n"); @@ -359,6 +390,8 @@ static int __init at91sam9g20ek_init(void) return ret; err_ssc: + ssc_free(ssc); + ssc_p->ssc = NULL; err_mclk: clk_put(mclk); mclk = NULL; -- cgit v1.1