wm8904: adapt driver for use with audio-graph-card
Subsystems (5)
v2 cover wm8904: adapt driver for use with audio-graph-card
This series allows to use WM8904 codec as audio-graph-card component. It starts with rework of FLL handling in the codec's driver, and as an example includes (untested) rework for codec with similar FLL: WM8994.
Series based on tiwai/sound/for-next tree. You can also pull from:
https://rere.qmqm.pl/git/linux
branch:
wm8904
(branch includes two fixes already sent to alsa-devel, but not merged yet).
Michał Mirosław (4):
ASoC: wm_fll: extract common code for Wolfson FLLs
ASoC: wm8904: use common FLL code
ASoC: wm8904: automatically choose clock source [RFT] ASoC: wm8994: use common FLL code
sound/soc/atmel/atmel_wm8904.c | 11 +- sound/soc/codecs/Kconfig | 9 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/wm8904.c | 516 +++++++++++--------------------- sound/soc/codecs/wm8904.h | 5 - sound/soc/codecs/wm8994.c | 281 +++++------------- sound/soc/codecs/wm8994.h | 4 +- sound/soc/codecs/wm_fll.c | 518 +++++++++++++++++++++++++++++++++ sound/soc/codecs/wm_fll.h | 60 ++++ 9 files changed, 849 insertions(+), 557 deletions(-) create mode 100644 sound/soc/codecs/wm_fll.c create mode 100644 sound/soc/codecs/wm_fll.h
Signature · 1 line
2.20.1
PATCH v2 1/4 ASoC: wm_fll: extract common code for Wolfson FLLs
A new implementation for FLLs as contained in WM8904, WM8994 and a few other Cirrus Logic (formerly Wolfson) codecs. Patches using this common code follow.
--- sound/soc/codecs/Kconfig | 6 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/wm_fll.c | 518 ++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/wm_fll.h | 60 +++++ 4 files changed, 586 insertions(+)
sound/soc/codecs/Kconfig +6 -0
@@ -281,6 +281,12 @@ config SND_SOC_ARIZONA default m if SND_SOC_WM8997=m default m if SND_SOC_WM8998=m +config SND_SOC_WM_FLL + tristate + +config SND_SOC_WM_FLL_EFS + bool + config SND_SOC_WM_HUBS tristate default y if SND_SOC_WM8993=y || SND_SOC_WM8994=y
sound/soc/codecs/Makefile +2 -0
@@ -269,6 +269,7 @@ snd-soc-wm9090-objs := wm9090.o snd-soc-wm9705-objs := wm9705.o snd-soc-wm9712-objs := wm9712.o snd-soc-wm9713-objs := wm9713.o +snd-soc-wm-fll-objs := wm_fll.o snd-soc-wm-hubs-objs := wm_hubs.o snd-soc-zx-aud96p22-objs := zx_aud96p22.o # Amp
@@ -549,6 +550,7 @@ obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o obj-$(CONFIG_SND_SOC_WM_ADSP) += snd-soc-wm-adsp.o +obj-$(CONFIG_SND_SOC_WM_FLL) += snd-soc-wm-fll.o obj-$(CONFIG_SND_SOC_WM_HUBS) += snd-soc-wm-hubs.o obj-$(CONFIG_SND_SOC_ZX_AUD96P22) += snd-soc-zx-aud96p22.o
sound/soc/codecs/wm_fll.c new file +518 -0
518 lines not on this page · raw message
sound/soc/codecs/wm_fll.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v2 2/4 ASoC: wm8904: use common FLL code
In reply to Michał MirosławRework FLL handling to use common code introduced earlier.
--- sound/soc/atmel/atmel_wm8904.c | 11 +- sound/soc/codecs/Kconfig | 1 + sound/soc/codecs/wm8904.c | 476 ++++++++++----------------------- sound/soc/codecs/wm8904.h | 5 - 4 files changed, 140 insertions(+), 353 deletions(-)
sound/soc/atmel/atmel_wm8904.c +1 -10
@@ -30,20 +30,11 @@ static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream *substream,struct snd_soc_dai *codec_dai = rtd->codec_dai;int ret; - ret =snd_soc_dai_set_pll (codec_dai,WM8904_FLL_MCLK ,WM8904_FLL_MCLK , -32768 ,params_rate (params) *256 ); -if (ret <0 ) { -pr_err ("%s - failed to set wm8904 codec PLL." , __func__); -return ret; - } -/* * As here wm8904 use FLL output as its system clock -* so calling set_sysclk won't care freq parameter -* then we pass 0 */ ret =snd_soc_dai_set_sysclk (codec_dai,WM8904_CLK_FLL , -0 ,SND_SOC_CLOCK_IN ); +params_rate (params) *256 ,SND_SOC_CLOCK_IN );if (ret <0 ) {pr_err ("%s -failed to set wm8904 SYSCLK\n" , __func__);return ret;
sound/soc/codecs/Kconfig +1 -0
@@ -1331,6 +1331,7 @@ config SND_SOC_WM8903 config SND_SOC_WM8904 tristate "Wolfson Microelectronics WM8904 CODEC" depends on I2C + select SND_SOC_WM_FLL config SND_SOC_WM8940 tristate
sound/soc/codecs/wm8904.c +138 -338
597 lines not on this page · raw message
sound/soc/codecs/wm8904.h +0 -5
@@ -13,11 +13,6 @@#define WM8904_CLK_MCLK 1#define WM8904_CLK_FLL 2 -#define WM8904_FLL_MCLK 1 -#define WM8904_FLL_BCLK 2 -#define WM8904_FLL_LRCLK 3 -#define WM8904_FLL_FREE_RUNNING 4 -/* * Register values. */
Signature · 1 line
2.20.1
Re: [PATCH v2 2/4] ASoC: wm8904: use common FLL code
Quoted 4 lines · Michał Mirosław
Rework FLL handling to use common code introduced earlier.
Signed-off-by Michał Mirosław <[email protected]>---
Apologies for the slight delay in getting around to looking at this one, been quite busy and its a lot to go through.
Quoted 11 lines
sound/soc/atmel/atmel_wm8904.c | 11 +- sound/soc/codecs/Kconfig | 1 + sound/soc/codecs/wm8904.c | 476 ++++++++++----------------------- sound/soc/codecs/wm8904.h | 5 - 4 files changed, 140 insertions(+), 353 deletions(-)sound/soc/atmel/atmel_wm8904.c +0
-0
sound/soc/atmel/atmel_wm8904.c static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream *substream, · line 39
Quoted 10 lines
sound/soc/atmel/atmel_wm8904.c +0
-7@@ -30,20 +30,11 @@ static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream *substream,struct snd_soc_dai *codec_dai = rtd->codec_dai;int ret; - ret =snd_soc_dai_set_pll (codec_dai,WM8904_FLL_MCLK ,WM8904_FLL_MCLK , -32768 ,params_rate (params) *256 ); -if (ret <0 ) { -pr_err ("%s - failed to set wm8904 codec PLL." , __func__); -return ret; - } -
As per my last comment it would be better to move the existing functionality of the driver over to the new library, then make actual functional changes in a separate patch. Clearly we have changed how the driver works here, since we no longer need to set the FLL.
This both makes review easier and proves that the new library approach can support the existing functionality of the driver.
Quoted 5 lines
sound/soc/atmel/atmel_wm8904.c +5
-0+static int wm8904_prepare_sysclk (struct wm8904_priv *priv) +{ +int err; + +switch (priv->sysclk_src) {
sound/soc/atmel/atmel_wm8904.c static int atmel_asoc_wm8904_hw_params(struct snd_pcm_substream *substream,
Quoted 10 lines
sound/soc/atmel/atmel_wm8904.c +10
-0+case WM8904_CLK_MCLK : + err =clk_set_rate (priv->mclk, priv->mclk_rate); +if (!err) + err =clk_prepare_enable (priv->mclk); +break ; + +case WM8904_CLK_FLL : + err =wm_fll_enable (&priv->fll); +break ; +
Given the FLL can be sourced from the MCLK pin why is the mclk clock never enabled in the FLL case?
sound/soc/atmel/atmel_wm8904.c static int wm8904_configure_clocking(struct snd_soc_component *component) · line 433
Quoted 9 lines
sound/soc/atmel/atmel_wm8904.c +2
-3@@ -356,11 +429,18 @@ static int wm8904_configure_clocking(struct snd_soc_component *component) wm8904->sysclk_rate = rate; } -snd_soc_component_update_bits (component,WM8904_CLOCK_RATES_0 ,WM8904_MCLK_DIV , - clock0); - +snd_soc_component_update_bits (component,WM8904_CLOCK_RATES_0 , +WM8904_MCLK_DIV , clock0);
Appreciate this is probably a good formatting change but with a large hard to review patch its better to keep unrelated changes out of it to easy review.
sound/soc/atmel/atmel_wm8904.c static int wm8904_hw_params(struct snd_pcm_substream *substream, · line 1449
Quoted 8 lines
sound/soc/atmel/atmel_wm8904.c +2
-2@@ -1382,8 +1445,8 @@ static int wm8904_hw_params(struct snd_pcm_substream *substream, } } wm8904->bclk = (wm8904->sysclk_rate *10 ) / bclk_divs[best].div; -dev_dbg (component->dev,"Selected BCLK_DIV of %d for %dHz BCLK\n" , - bclk_divs[best].div, wm8904->bclk); +dev_dbg (component->dev,"Selected BCLK_DIV of %d.%d for %dHz BCLK\n" , + bclk_divs[best].div /10 , bclk_divs[best].div %10 , wm8904->bclk);
This is a nice tidy up as well but would also be nice to not have it in this patch.
sound/soc/atmel/atmel_wm8904.c static const struct snd_soc_dai_ops wm8904_dai_ops = { · line 1940
Quoted 5 lines
sound/soc/atmel/atmel_wm8904.c +0
-1@@ -1937,7 +1715,6 @@ static const struct snd_soc_dai_ops wm8904_dai_ops = { .set_sysclk = wm8904_set_sysclk, .set_fmt = wm8904_set_fmt, .set_tdm_slot = wm8904_set_tdm_slot, - .set_pll = wm8904_set_fll,
I am not keen on the way we are removing the ability to set the FLL source, there may be out of tree users using this and to my knowledge it is features that work at the moment so removing it seems like a step backwards.
sound/soc/atmel/atmel_wm8904.c static const struct snd_soc_dai_ops wm8904_dai_ops = {
Quoted 7 lines
sound/soc/atmel/atmel_wm8904.c +7
-0+static const struct wm_fll_desc wm8904_fll_desc = { + .ctl_offset =WM8904_FLL_CONTROL_1 , + .int_offset =WM8904_INTERRUPT_STATUS , + .int_mask =WM8904_FLL_LOCK_EINT_MASK , + .nco_reg0 =WM8904_FLL_NCO_TEST_0 , + .nco_reg1 =WM8904_FLL_NCO_TEST_1 , + .clk_ref_map = {FLL_REF_MCLK ,FLL_REF_BCLK ,FLL_REF_FSCLK ,/* reserved */ 0 },
Minor nit, but would probably look nice to split this across a couple of lines and would keep us under the 80 char line limit.
.clk_ref_map = {
....
},
sound/soc/atmel/atmel_wm8904.c static int wm8904_i2c_probe(struct i2c_client *i2c, · line 1952
Quoted 3 lines
sound/soc/atmel/atmel_wm8904.c +1
-0@@ -2165,6 +1951,19 @@ static int wm8904_i2c_probe(struct i2c_client *i2c,/* Can leave the device powered off until we need it */ +wm8904_disable_sysclk (wm8904);
How come this is now enabled during probe?
I trimmed down the CC list, for the next version I would suggest using a similar list, this one was a little over sized.
Thanks,
Charles
PATCH v2 3/4 ASoC: wm8904: automatically choose clock source
In reply to Michał MirosławChoose clock source automatically if not provided. This will be the case with eg. audio-graph-card.
--- sound/soc/codecs/wm8904.c | 42 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
sound/soc/codecs/wm8904.c +40 -2
@@ -367,15 +367,34 @@ static int wm8904_enable_sysclk(struct wm8904_priv *priv)return err; } +static int wm8904_bump_fll_sysclk (unsigned int *rate); +static int wm8904_set_sysclk (struct snd_soc_dai *dai,int clk_id,unsigned int rate,int dir) {struct snd_soc_component *component = dai->component;struct wm8904_priv *wm8904 =snd_soc_component_get_drvdata (component);unsigned int clock0, clock2; -int err; +int err, do_div = false;switch (clk_id) { +case 0 : +if (rate ==clk_round_rate (wm8904->mclk, rate)) { + clk_id =WM8904_CLK_MCLK ; + }else if (rate *2 ==clk_round_rate (wm8904->mclk, rate *2 )) { + rate *=2 ; + clk_id =WM8904_CLK_MCLK ; + do_div = true; + }else { + clk_id =WM8904_CLK_FLL ; + err =wm8904_bump_fll_sysclk (&rate); +if (err) { +dev_dbg (component->dev,"Can't match %u over FLL 1406250 Hz minimum\n" , rate); +return err; + } + } +break ; +case WM8904_CLK_MCLK :case WM8904_CLK_FLL :break ;
@@ -421,7 +440,9 @@ static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id, }/* SYSCLK shouldn't be over 13.5MHz */ -if (rate >13500000 ) { +if (rate >13500000 ) + do_div = true; +if (do_div) { clock0 =WM8904_MCLK_DIV ; wm8904->sysclk_rate = rate /2 ; }else {
@@ -1350,6 +1371,23 @@ static struct { { 480, 20 }, }; +static int wm8904_bump_fll_sysclk (unsigned int *rate) +{ +int i; + +/* bump SYSCLK rate if below minimal FLL output */ + +for (i =0 ; i <ARRAY_SIZE (bclk_divs); i++) { +if (*rate * bclk_divs[i].div >=1406250 *10 ) +break ; + } + +if (i ==ARRAY_SIZE (bclk_divs)) +return -ERANGE ; + + *rate = (*rate * bclk_divs[i].div) /10 ; +return 0 ; +} static int wm8904_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,
Signature · 1 line
2.20.1
PATCH v2 4/4 ASoC: wm8994: use common FLL code
In reply to Michał MirosławRework FLL handling to use common code.
This uses polling for now to wait for FLL lock.
--- sound/soc/codecs/Kconfig | 2 + sound/soc/codecs/wm8994.c | 281 +++++++++++--------------------------- sound/soc/codecs/wm8994.h | 4 +- 3 files changed, 84 insertions(+), 203 deletions(-)
sound/soc/codecs/Kconfig +2 -0
@@ -1382,6 +1382,8 @@ config SND_SOC_WM8993 config SND_SOC_WM8994 tristate + select SND_SOC_WM_FLL + select SND_SOC_WM_FLL_EFS config SND_SOC_WM8995 tristate
sound/soc/codecs/wm8994.c +80 -201
375 lines not on this page · raw message
sound/soc/codecs/wm8994.h +2 -2
@@ -13,6 +13,7 @@#include <linux/mutex.h> #include "wm_hubs.h" +#include "wm_fll.h" /* Sources for AIF1/2 SYSCLK - use with set_dai_sysclk() */ #define WM8994_SYSCLK_MCLK1 1
@@ -80,8 +81,7 @@ struct wm8994_priv {int aifdiv[2 ];int channels[2 ];struct wm8994_fll_config fll[2 ], fll_suspend[2 ]; -struct completion fll_locked[2 ]; -bool fll_locked_irq; +struct wm_fll_data fll_hw[2 ];bool fll_byp;bool clk_has_run;
Signature · 1 line
2.20.1
Mark Brown
maintainerQuoted 3 lines · Michał Mirosław
This series allows to use WM8904 codec as audio-graph-card component. It starts with rework of FLL handling in the codec's driver, and as an example includes (untested) rework for codec with similar FLL: WM8994.
Please make some effort to focus your CC list on only relevant people, many upstream developers get a lot of e-mail and cutting down on that helps everyone stay more productive, too many can also set off anti-spam software. You've sent this to a lot of people and I'm struggling to figure out why most of them are on the list.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel