[alsa-devel] [PATCH] ASoC: wm8731: let codec to manage clock by itself
Let the wm8731 codec to manage clock by itself.
Signed-off-by: Bo Shen voice.shen@atmel.com ---
sound/soc/codecs/wm8731.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index b115ed8..ecd8424 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c @@ -13,6 +13,7 @@ * published by the Free Software Foundation. */
+#include <linux/clk.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> @@ -45,6 +46,7 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { /* codec private data */ struct wm8731_priv { struct regmap *regmap; + struct clk *mclk; struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; const struct snd_pcm_hw_constraint_list *constraints; unsigned int sysclk; @@ -389,6 +391,9 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, switch (clk_id) { case WM8731_SYSCLK_XTAL: case WM8731_SYSCLK_MCLK: + if (IS_ENABLED(CONFIG_COMMON_CLK)) + if (clk_set_rate(wm8731->mclk, freq)) + return -EINVAL; wm8731->sysclk_type = clk_id; break; default: @@ -490,6 +495,9 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
switch (level) { case SND_SOC_BIAS_ON: + if (IS_ENABLED(CONFIG_COMMON_CLK)) + if (clk_prepare_enable(wm8731->mclk)) + return -EINVAL; break; case SND_SOC_BIAS_PREPARE: break; @@ -508,6 +516,8 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec, snd_soc_write(codec, WM8731_PWR, reg | 0x0040); break; case SND_SOC_BIAS_OFF: + if (IS_ENABLED(CONFIG_COMMON_CLK)) + clk_disable_unprepare(wm8731->mclk); snd_soc_write(codec, WM8731_PWR, 0xffff); regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); @@ -666,6 +676,15 @@ static int wm8731_spi_probe(struct spi_device *spi) if (wm8731 == NULL) return -ENOMEM;
+ if (IS_ENABLED(CONFIG_COMMON_CLK)) { + wm8731->mclk = devm_clk_get(&spi->dev, "mclk"); + if (IS_ERR(wm8731->mclk)) { + ret = PTR_ERR(wm8731->mclk); + dev_err(&spi->dev, "Failed to get MCLK\n"); + return ret; + } + } + mutex_init(&wm8731->lock);
wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); @@ -717,6 +736,15 @@ static int wm8731_i2c_probe(struct i2c_client *i2c, if (wm8731 == NULL) return -ENOMEM;
+ if (IS_ENABLED(CONFIG_COMMON_CLK)) { + wm8731->mclk = devm_clk_get(&i2c->dev, "mclk"); + if (IS_ERR(wm8731->mclk)) { + ret = PTR_ERR(wm8731->mclk); + dev_err(&i2c->dev, "Failed to get MCLK\n"); + return ret; + } + } + mutex_init(&wm8731->lock);
wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
Hi All,
On 02/05/2015 03:35 PM, Bo Shen wrote:
Let the wm8731 codec to manage clock by itself.
Signed-off-by: Bo Shen voice.shen@atmel.com
sound/soc/codecs/wm8731.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Any comments for this patch (aka ping?)
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index b115ed8..ecd8424 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c @@ -13,6 +13,7 @@
- published by the Free Software Foundation.
*/
+#include <linux/clk.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> @@ -45,6 +46,7 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { /* codec private data */ struct wm8731_priv { struct regmap *regmap;
- struct clk *mclk; struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; const struct snd_pcm_hw_constraint_list *constraints; unsigned int sysclk;
@@ -389,6 +391,9 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, switch (clk_id) { case WM8731_SYSCLK_XTAL: case WM8731_SYSCLK_MCLK:
if (IS_ENABLED(CONFIG_COMMON_CLK))
if (clk_set_rate(wm8731->mclk, freq))
wm8731->sysclk_type = clk_id; break; default:return -EINVAL;
@@ -490,6 +495,9 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
switch (level) { case SND_SOC_BIAS_ON:
if (IS_ENABLED(CONFIG_COMMON_CLK))
if (clk_prepare_enable(wm8731->mclk))
break; case SND_SOC_BIAS_PREPARE: break;return -EINVAL;
@@ -508,6 +516,8 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec, snd_soc_write(codec, WM8731_PWR, reg | 0x0040); break; case SND_SOC_BIAS_OFF:
if (IS_ENABLED(CONFIG_COMMON_CLK))
snd_soc_write(codec, WM8731_PWR, 0xffff); regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);clk_disable_unprepare(wm8731->mclk);
@@ -666,6 +676,15 @@ static int wm8731_spi_probe(struct spi_device *spi) if (wm8731 == NULL) return -ENOMEM;
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
wm8731->mclk = devm_clk_get(&spi->dev, "mclk");
if (IS_ERR(wm8731->mclk)) {
ret = PTR_ERR(wm8731->mclk);
dev_err(&spi->dev, "Failed to get MCLK\n");
return ret;
}
}
mutex_init(&wm8731->lock);
wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
@@ -717,6 +736,15 @@ static int wm8731_i2c_probe(struct i2c_client *i2c, if (wm8731 == NULL) return -ENOMEM;
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
wm8731->mclk = devm_clk_get(&i2c->dev, "mclk");
if (IS_ERR(wm8731->mclk)) {
ret = PTR_ERR(wm8731->mclk);
dev_err(&i2c->dev, "Failed to get MCLK\n");
return ret;
}
}
mutex_init(&wm8731->lock);
wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
Best Regards, Bo Shen
On Thu, Feb 12, 2015 at 04:23:06PM +0800, Bo Shen wrote:
Hi All,
On 02/05/2015 03:35 PM, Bo Shen wrote:
Let the wm8731 codec to manage clock by itself.
Signed-off-by: Bo Shen voice.shen@atmel.com
sound/soc/codecs/wm8731.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Any comments for this patch (aka ping?)
I preferred the idea of having the clock as optional and from the discussion on the last patch it didn't look too tricky to achieve. OTOH I think the Atmel system is the only one that uses both this CODEC and common clock so it doesn't look like this would cause any problems, but might be nice for this not to be one more thing for someone to fix up when moving a system to common clock.
Thanks, Charles
On Mon, Feb 16, 2015 at 11:31 AM, Charles Keepax ckeepax@opensource.wolfsonmicro.com wrote:
On Thu, Feb 12, 2015 at 04:23:06PM +0800, Bo Shen wrote:
Hi All,
On 02/05/2015 03:35 PM, Bo Shen wrote:
Let the wm8731 codec to manage clock by itself.
Signed-off-by: Bo Shen voice.shen@atmel.com
sound/soc/codecs/wm8731.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Any comments for this patch (aka ping?)
I preferred the idea of having the clock as optional and from the discussion on the last patch it didn't look too tricky to
me too
achieve. OTOH I think the Atmel system is the only one that uses both this CODEC and common clock so it doesn't look like this would cause any problems, but might be nice for this not to be one more thing for someone to fix up when moving a system to common clock.
Not quite, there's one MIPS platform I maintain which needs a patch like the one below (tested):
diff --git a/arch/mips/alchemy/devboards/db1200.c b/arch/mips/alchemy/devboards/db1200.c index 8c13675..aa01ab2 100644 --- a/arch/mips/alchemy/devboards/db1200.c +++ b/arch/mips/alchemy/devboards/db1200.c @@ -19,6 +19,8 @@ */
#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> #include <linux/dma-mapping.h> #include <linux/gpio.h> #include <linux/i2c.h> @@ -862,6 +864,12 @@ int __init db1200_dev_setup(void) irq_set_status_flags(DB1200_PC1_INSERT_INT, IRQ_NOAUTOEN); irq_set_status_flags(DB1200_PC1_EJECT_INT, IRQ_NOAUTOEN);
+ /* register the 12MHz crystal for the WM8731 I2S codec */ + c = clk_register_fixed_rate(NULL, "wm8731xtal", NULL, + CLK_IS_ROOT, 12000000); + if (!IS_ERR(c)) + clk_register_clkdev(c, "mclk", "0-001b"); + i2c_register_board_info(0, db1200_i2c_devs, ARRAY_SIZE(db1200_i2c_devs)); spi_register_board_info(db1200_spi_devs, diff --git a/arch/mips/alchemy/devboards/db1300.c b/arch/mips/alchemy/devboards/db1300.c index 1c64fdb..1aa01c8 100644 --- a/arch/mips/alchemy/devboards/db1300.c +++ b/arch/mips/alchemy/devboards/db1300.c @@ -5,6 +5,8 @@ */
#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> #include <linux/dma-mapping.h> #include <linux/gpio.h> #include <linux/gpio_keys.h> @@ -799,6 +801,12 @@ int __init db1300_dev_setup(void) if (platform_driver_register(&db1300_wm97xx_driver)) pr_warn("DB1300: failed to init touch pen irq support!\n");
+ /* register the 12MHz crystal for the WM8731 I2S codec */ + c = clk_register_fixed_rate(NULL, "wm8731xtal", NULL, + CLK_IS_ROOT, 12000000); + if (!IS_ERR(c)) + clk_register_clkdev(c, "mclk", "0-001b"); + /* Audio PSC clock is supplied by codecs (PSC1, 2) */ __raw_writel(PSC_SEL_CLK_SERCLK, (void __iomem *)KSEG1ADDR(AU1300_PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
On 02/16/2015 08:58 PM, Manuel Lauss wrote:
On Mon, Feb 16, 2015 at 11:31 AM, Charles Keepax ckeepax@opensource.wolfsonmicro.com wrote:
On Thu, Feb 12, 2015 at 04:23:06PM +0800, Bo Shen wrote:
Hi All,
On 02/05/2015 03:35 PM, Bo Shen wrote:
Let the wm8731 codec to manage clock by itself.
Signed-off-by: Bo Shen voice.shen@atmel.com
sound/soc/codecs/wm8731.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
Any comments for this patch (aka ping?)
I preferred the idea of having the clock as optional and from the discussion on the last patch it didn't look too tricky to
me too
OK, I will keep the clock as optional.
achieve. OTOH I think the Atmel system is the only one that uses both this CODEC and common clock so it doesn't look like this would cause any problems, but might be nice for this not to be one more thing for someone to fix up when moving a system to common clock.
Not quite, there's one MIPS platform I maintain which needs a patch like the one below (tested):
Do I need to seed the following patch together or you send it?
diff --git a/arch/mips/alchemy/devboards/db1200.c b/arch/mips/alchemy/devboards/db1200.c index 8c13675..aa01ab2 100644 --- a/arch/mips/alchemy/devboards/db1200.c +++ b/arch/mips/alchemy/devboards/db1200.c @@ -19,6 +19,8 @@ */
#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> #include <linux/dma-mapping.h> #include <linux/gpio.h> #include <linux/i2c.h> @@ -862,6 +864,12 @@ int __init db1200_dev_setup(void) irq_set_status_flags(DB1200_PC1_INSERT_INT, IRQ_NOAUTOEN); irq_set_status_flags(DB1200_PC1_EJECT_INT, IRQ_NOAUTOEN);
- /* register the 12MHz crystal for the WM8731 I2S codec */
- c = clk_register_fixed_rate(NULL, "wm8731xtal", NULL,
CLK_IS_ROOT, 12000000);
- if (!IS_ERR(c))
clk_register_clkdev(c, "mclk", "0-001b");
i2c_register_board_info(0, db1200_i2c_devs, ARRAY_SIZE(db1200_i2c_devs)); spi_register_board_info(db1200_spi_devs,
diff --git a/arch/mips/alchemy/devboards/db1300.c b/arch/mips/alchemy/devboards/db1300.c index 1c64fdb..1aa01c8 100644 --- a/arch/mips/alchemy/devboards/db1300.c +++ b/arch/mips/alchemy/devboards/db1300.c @@ -5,6 +5,8 @@ */
#include <linux/clk.h> +#include <linux/clkdev.h> +#include <linux/clk-provider.h> #include <linux/dma-mapping.h> #include <linux/gpio.h> #include <linux/gpio_keys.h> @@ -799,6 +801,12 @@ int __init db1300_dev_setup(void) if (platform_driver_register(&db1300_wm97xx_driver)) pr_warn("DB1300: failed to init touch pen irq support!\n");
- /* register the 12MHz crystal for the WM8731 I2S codec */
- c = clk_register_fixed_rate(NULL, "wm8731xtal", NULL,
CLK_IS_ROOT, 12000000);
- if (!IS_ERR(c))
clk_register_clkdev(c, "mclk", "0-001b");
/* Audio PSC clock is supplied by codecs (PSC1, 2) */ __raw_writel(PSC_SEL_CLK_SERCLK, (void __iomem *)KSEG1ADDR(AU1300_PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
Best Regards, Bo Shen
participants (3)
-
Bo Shen
-
Charles Keepax
-
Manuel Lauss