alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] ASoC: wm8904: configure sysclk/FLL automatically
@ 2019-11-07 23:15 Michael Walle
  2019-11-08 16:07 ` Charles Keepax
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Walle @ 2019-11-07 23:15 UTC (permalink / raw)
  To: alsa-devel, linux-kernel
  Cc: patches, Takashi Iwai, Liam Girdwood, Michael Walle, Mark Brown

This adds a new mode WM8904_CLK_AUTO which automatically enables the FLL
if a frequency different than the MCLK is set.

These additions make the codec work with the simple-card driver in
general and especially in systems where the MCLK doesn't match the
requested clock.

Signed-off-by: Michael Walle <michael@walle.cc>
---
Unfortunately, I had to move wm8904_sys_sysclk() below wm8904_set_fll(). So
that makes this patch a bit ugly. The added part is the WM8904_CLK_AUTO
branch.

 sound/soc/codecs/wm8904.c | 72 ++++++++++++++++++++++++---------------
 sound/soc/codecs/wm8904.h |  1 +
 2 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index bcb3c9d5abf0..2dd7addfd1a8 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -1410,34 +1410,6 @@ static int wm8904_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-
-static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id,
-			     unsigned int freq, int dir)
-{
-	struct snd_soc_component *component = dai->component;
-	struct wm8904_priv *priv = snd_soc_component_get_drvdata(component);
-
-	switch (clk_id) {
-	case WM8904_CLK_MCLK:
-		priv->sysclk_src = clk_id;
-		priv->mclk_rate = freq;
-		break;
-
-	case WM8904_CLK_FLL:
-		priv->sysclk_src = clk_id;
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq);
-
-	wm8904_configure_clocking(component);
-
-	return 0;
-}
-
 static int wm8904_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_component *component = dai->component;
@@ -1824,6 +1796,50 @@ static int wm8904_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
 	return 0;
 }
 
+static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id,
+			     unsigned int freq, int dir)
+{
+	struct snd_soc_component *component = dai->component;
+	struct wm8904_priv *priv = snd_soc_component_get_drvdata(component);
+	unsigned long mclk_freq;
+	int ret;
+
+	switch (clk_id) {
+	case WM8904_CLK_AUTO:
+		mclk_freq = clk_get_rate(priv->mclk);
+		/* enable FLL if a different sysclk is desired */
+		if (mclk_freq != freq) {
+			priv->sysclk_src = WM8904_CLK_FLL;
+			ret = wm8904_set_fll(dai, WM8904_FLL_MCLK,
+					     WM8904_FLL_MCLK,
+					     clk_get_rate(priv->mclk), freq);
+			if (ret)
+				return ret;
+			break;
+		}
+		clk_id = WM8904_CLK_MCLK;
+		/* fallthrough */
+
+	case WM8904_CLK_MCLK:
+		priv->sysclk_src = clk_id;
+		priv->mclk_rate = freq;
+		break;
+
+	case WM8904_CLK_FLL:
+		priv->sysclk_src = clk_id;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq);
+
+	wm8904_configure_clocking(component);
+
+	return 0;
+}
+
 static int wm8904_digital_mute(struct snd_soc_dai *codec_dai, int mute)
 {
 	struct snd_soc_component *component = codec_dai->component;
diff --git a/sound/soc/codecs/wm8904.h b/sound/soc/codecs/wm8904.h
index c1bca52f9927..de6340446b1f 100644
--- a/sound/soc/codecs/wm8904.h
+++ b/sound/soc/codecs/wm8904.h
@@ -10,6 +10,7 @@
 #ifndef _WM8904_H
 #define _WM8904_H
 
+#define WM8904_CLK_AUTO 0
 #define WM8904_CLK_MCLK 1
 #define WM8904_CLK_FLL  2
 
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: wm8904: configure sysclk/FLL automatically
  2019-11-07 23:15 [alsa-devel] [PATCH] ASoC: wm8904: configure sysclk/FLL automatically Michael Walle
@ 2019-11-08 16:07 ` Charles Keepax
  2019-11-08 17:14   ` Michael Walle
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Keepax @ 2019-11-08 16:07 UTC (permalink / raw)
  To: Michael Walle
  Cc: alsa-devel, Liam Girdwood, linux-kernel, Takashi Iwai,
	Mark Brown, patches

On Fri, Nov 08, 2019 at 12:15:48AM +0100, Michael Walle wrote:
> This adds a new mode WM8904_CLK_AUTO which automatically enables the FLL
> if a frequency different than the MCLK is set.
> 
> These additions make the codec work with the simple-card driver in
> general and especially in systems where the MCLK doesn't match the
> requested clock.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
> +static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id,
> +			     unsigned int freq, int dir)
> +{
> +	struct snd_soc_component *component = dai->component;
> +	struct wm8904_priv *priv = snd_soc_component_get_drvdata(component);
> +	unsigned long mclk_freq;
> +	int ret;
> +
> +	switch (clk_id) {
> +	case WM8904_CLK_AUTO:
> +		mclk_freq = clk_get_rate(priv->mclk);
> +		/* enable FLL if a different sysclk is desired */
> +		if (mclk_freq != freq) {
> +			priv->sysclk_src = WM8904_CLK_FLL;
> +			ret = wm8904_set_fll(dai, WM8904_FLL_MCLK,
> +					     WM8904_FLL_MCLK,
> +					     clk_get_rate(priv->mclk), freq);

minor nit, might as well use mclk_freq rather than calling
clk_get_rate again, other than that though I think this looks
good.

Thanks,
Charles
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [alsa-devel] [PATCH] ASoC: wm8904: configure sysclk/FLL automatically
  2019-11-08 16:07 ` Charles Keepax
@ 2019-11-08 17:14   ` Michael Walle
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Walle @ 2019-11-08 17:14 UTC (permalink / raw)
  To: Charles Keepax
  Cc: alsa-devel, Liam Girdwood, linux-kernel, Takashi Iwai,
	Mark Brown, patches

Am 2019-11-08 17:07, schrieb Charles Keepax:
> On Fri, Nov 08, 2019 at 12:15:48AM +0100, Michael Walle wrote:
>> This adds a new mode WM8904_CLK_AUTO which automatically enables the 
>> FLL
>> if a frequency different than the MCLK is set.
>> 
>> These additions make the codec work with the simple-card driver in
>> general and especially in systems where the MCLK doesn't match the
>> requested clock.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>> +static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>> +			     unsigned int freq, int dir)
>> +{
>> +	struct snd_soc_component *component = dai->component;
>> +	struct wm8904_priv *priv = snd_soc_component_get_drvdata(component);
>> +	unsigned long mclk_freq;
>> +	int ret;
>> +
>> +	switch (clk_id) {
>> +	case WM8904_CLK_AUTO:
>> +		mclk_freq = clk_get_rate(priv->mclk);
>> +		/* enable FLL if a different sysclk is desired */
>> +		if (mclk_freq != freq) {
>> +			priv->sysclk_src = WM8904_CLK_FLL;
>> +			ret = wm8904_set_fll(dai, WM8904_FLL_MCLK,
>> +					     WM8904_FLL_MCLK,
>> +					     clk_get_rate(priv->mclk), freq);
> 
> minor nit, might as well use mclk_freq rather than calling
> clk_get_rate again, other than that though I think this looks
> good.

whoops, I was too tired then. That was the whole intention of using the 
mclk_freq variable.. so yes, I'll fix that.

-michael
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-09  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 23:15 [alsa-devel] [PATCH] ASoC: wm8904: configure sysclk/FLL automatically Michael Walle
2019-11-08 16:07 ` Charles Keepax
2019-11-08 17:14   ` Michael Walle

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).