alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown
@ 2019-09-07 17:45 Katsuhiro Suzuki
  2019-09-09  0:31 ` Kuninori Morimoto
  2019-09-09 10:07 ` [alsa-devel] Applied "SoC: simple-card-utils: set 0Hz to sysclk when shutdown" to the asoc tree Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Katsuhiro Suzuki @ 2019-09-07 17:45 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto; +Cc: Katsuhiro Suzuki, alsa-devel, linux-kernel

This patch set 0Hz to sysclk when shutdown the card.

Some codecs set rate constraints that derives from sysclk. This
mechanism works correctly if machine drivers give fixed frequency.

But simple-audio and audio-graph card set variable clock rate if
'mclk-fs' property exists. In this case, rate constraints will go
bad scenario. For example a codec accepts three limited rates
(mclk / 256, mclk / 384, mclk / 512).

Bad scenario as follows (mclk-fs = 256):
   - Initialize sysclk by correct value (Ex. 12.288MHz)
     - Codec set constraints of PCM rate by sysclk
       48kHz (1/256), 32kHz (1/384), 24kHz (1/512)
   - Play 48kHz sound, it's acceptable
   - Sysclk is not changed

   - Play 32kHz sound, it's acceptable
   - Set sysclk to 8.192MHz (= fs * mclk-fs = 32k * 256)
     - Codec set constraints of PCM rate by sysclk
       32kHz (1/256), 21.33kHz (1/384), 16kHz (1/512)

   - Play 48kHz again, but it's NOT acceptable because constraints
     do not allow 48kHz

So codecs treat 0Hz sysclk as signal of applying no constraints to
avoid this problem.

Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
---
 sound/soc/generic/simple-card-utils.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 556b1a789629..9b794775df53 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -213,10 +213,17 @@ EXPORT_SYMBOL_GPL(asoc_simple_startup);
 void asoc_simple_shutdown(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 	struct simple_dai_props *dai_props =
 		simple_priv_to_props(priv, rtd->num);
 
+	if (dai_props->mclk_fs) {
+		snd_soc_dai_set_sysclk(codec_dai, 0, 0, SND_SOC_CLOCK_IN);
+		snd_soc_dai_set_sysclk(cpu_dai, 0, 0, SND_SOC_CLOCK_OUT);
+	}
+
 	asoc_simple_clk_disable(dai_props->cpu_dai);
 
 	asoc_simple_clk_disable(dai_props->codec_dai);
-- 
2.23.0.rc1

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

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

* Re: [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown
  2019-09-07 17:45 [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown Katsuhiro Suzuki
@ 2019-09-09  0:31 ` Kuninori Morimoto
  2019-09-09  2:49   ` Katsuhiro Suzuki
  2019-09-09 10:07 ` [alsa-devel] Applied "SoC: simple-card-utils: set 0Hz to sysclk when shutdown" to the asoc tree Mark Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2019-09-09  0:31 UTC (permalink / raw)
  To: Katsuhiro Suzuki; +Cc: alsa-devel, Mark Brown, linux-kernel


Hi Katsuhiro

> This patch set 0Hz to sysclk when shutdown the card.
> 
> Some codecs set rate constraints that derives from sysclk. This
> mechanism works correctly if machine drivers give fixed frequency.
> 
> But simple-audio and audio-graph card set variable clock rate if
> 'mclk-fs' property exists. In this case, rate constraints will go
> bad scenario. For example a codec accepts three limited rates
> (mclk / 256, mclk / 384, mclk / 512).
> 
> Bad scenario as follows (mclk-fs = 256):
>    - Initialize sysclk by correct value (Ex. 12.288MHz)
>      - Codec set constraints of PCM rate by sysclk
>        48kHz (1/256), 32kHz (1/384), 24kHz (1/512)
>    - Play 48kHz sound, it's acceptable
>    - Sysclk is not changed
> 
>    - Play 32kHz sound, it's acceptable
>    - Set sysclk to 8.192MHz (= fs * mclk-fs = 32k * 256)
>      - Codec set constraints of PCM rate by sysclk
>        32kHz (1/256), 21.33kHz (1/384), 16kHz (1/512)
> 
>    - Play 48kHz again, but it's NOT acceptable because constraints
>      do not allow 48kHz
> 
> So codecs treat 0Hz sysclk as signal of applying no constraints to
> avoid this problem.
> 
> Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
> ---

I'm not 100% understand your issue.
.hw_params (= set mclk/sysclk) is not called in bad case ??
Or it is called but Codec driver ignores it somehow ??

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown
  2019-09-09  0:31 ` Kuninori Morimoto
@ 2019-09-09  2:49   ` Katsuhiro Suzuki
  2019-09-09  3:54     ` Kuninori Morimoto
  0 siblings, 1 reply; 5+ messages in thread
From: Katsuhiro Suzuki @ 2019-09-09  2:49 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: alsa-devel, Mark Brown, linux-kernel

On 2019/09/09 9:31, Kuninori Morimoto wrote:
> 
> Hi Katsuhiro
> 
>> This patch set 0Hz to sysclk when shutdown the card.
>>
>> Some codecs set rate constraints that derives from sysclk. This
>> mechanism works correctly if machine drivers give fixed frequency.
>>
>> But simple-audio and audio-graph card set variable clock rate if
>> 'mclk-fs' property exists. In this case, rate constraints will go
>> bad scenario. For example a codec accepts three limited rates
>> (mclk / 256, mclk / 384, mclk / 512).
>>
>> Bad scenario as follows (mclk-fs = 256):
>>     - Initialize sysclk by correct value (Ex. 12.288MHz)
>>       - Codec set constraints of PCM rate by sysclk
>>         48kHz (1/256), 32kHz (1/384), 24kHz (1/512)
>>     - Play 48kHz sound, it's acceptable
>>     - Sysclk is not changed
>>
>>     - Play 32kHz sound, it's acceptable
>>     - Set sysclk to 8.192MHz (= fs * mclk-fs = 32k * 256)
>>       - Codec set constraints of PCM rate by sysclk
>>         32kHz (1/256), 21.33kHz (1/384), 16kHz (1/512)
>>
>>     - Play 48kHz again, but it's NOT acceptable because constraints
>>       do not allow 48kHz
>>
>> So codecs treat 0Hz sysclk as signal of applying no constraints to
>> avoid this problem.
>>
>> Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
>> ---
> 
> I'm not 100% understand your issue.
> .hw_params (= set mclk/sysclk) is not called in bad case ??
> Or it is called but Codec driver ignores it somehow ??
> 

Ah, sorry for confusing. It's not either. hw_params() of machine
driver has been called even if constraints don't have a requested
PCM rate. But it's not expected.

For example, if constraints are 32k, 21.33k, 16k, hw_params() will
be called with 32k when an user requests to play 48k sounds.


> Thank you for your help !!
> Best regards
> ---
> Kuninori Morimoto
> 

Best Regards,
Katsuhiro Suzuki
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown
  2019-09-09  2:49   ` Katsuhiro Suzuki
@ 2019-09-09  3:54     ` Kuninori Morimoto
  0 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2019-09-09  3:54 UTC (permalink / raw)
  To: Katsuhiro Suzuki; +Cc: alsa-devel, Mark Brown, linux-kernel


Hi Katsuhiro

> >> Bad scenario as follows (mclk-fs = 256):
> >>     - Initialize sysclk by correct value (Ex. 12.288MHz)
> >>       - Codec set constraints of PCM rate by sysclk
> >>         48kHz (1/256), 32kHz (1/384), 24kHz (1/512)
> >>     - Play 48kHz sound, it's acceptable
> >>     - Sysclk is not changed
> >> 
> >>     - Play 32kHz sound, it's acceptable
> >>     - Set sysclk to 8.192MHz (= fs * mclk-fs = 32k * 256)
> >>       - Codec set constraints of PCM rate by sysclk
> >>         32kHz (1/256), 21.33kHz (1/384), 16kHz (1/512)
> >> 
> >>     - Play 48kHz again, but it's NOT acceptable because constraints
> >>       do not allow 48kHz
(snip)
> Ah, sorry for confusing. It's not either. hw_params() of machine
> driver has been called even if constraints don't have a requested
> PCM rate. But it's not expected.
> 
> For example, if constraints are 32k, 21.33k, 16k, hw_params() will
> be called with 32k when an user requests to play 48k sounds.

Oh, I see.
Thank you for explaining.

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* [alsa-devel] Applied "SoC: simple-card-utils: set 0Hz to sysclk when shutdown" to the asoc tree
  2019-09-07 17:45 [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown Katsuhiro Suzuki
  2019-09-09  0:31 ` Kuninori Morimoto
@ 2019-09-09 10:07 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2019-09-09 10:07 UTC (permalink / raw)
  To: Katsuhiro Suzuki; +Cc: alsa-devel, Mark Brown, linux-kernel, Kuninori Morimoto

The patch

   SoC: simple-card-utils: set 0Hz to sysclk when shutdown

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 2458adb8f92ad4d07ef7ab27c5bafa1d3f4678d6 Mon Sep 17 00:00:00 2001
From: Katsuhiro Suzuki <katsuhiro@katsuster.net>
Date: Sun, 8 Sep 2019 02:45:01 +0900
Subject: [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown

This patch set 0Hz to sysclk when shutdown the card.

Some codecs set rate constraints that derives from sysclk. This
mechanism works correctly if machine drivers give fixed frequency.

But simple-audio and audio-graph card set variable clock rate if
'mclk-fs' property exists. In this case, rate constraints will go
bad scenario. For example a codec accepts three limited rates
(mclk / 256, mclk / 384, mclk / 512).

Bad scenario as follows (mclk-fs = 256):
   - Initialize sysclk by correct value (Ex. 12.288MHz)
     - Codec set constraints of PCM rate by sysclk
       48kHz (1/256), 32kHz (1/384), 24kHz (1/512)
   - Play 48kHz sound, it's acceptable
   - Sysclk is not changed

   - Play 32kHz sound, it's acceptable
   - Set sysclk to 8.192MHz (= fs * mclk-fs = 32k * 256)
     - Codec set constraints of PCM rate by sysclk
       32kHz (1/256), 21.33kHz (1/384), 16kHz (1/512)

   - Play 48kHz again, but it's NOT acceptable because constraints
     do not allow 48kHz

So codecs treat 0Hz sysclk as signal of applying no constraints to
avoid this problem.

Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
Link: https://lore.kernel.org/r/20190907174501.19833-1-katsuhiro@katsuster.net
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/generic/simple-card-utils.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 556b1a789629..9b794775df53 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -213,10 +213,17 @@ EXPORT_SYMBOL_GPL(asoc_simple_startup);
 void asoc_simple_shutdown(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 	struct simple_dai_props *dai_props =
 		simple_priv_to_props(priv, rtd->num);
 
+	if (dai_props->mclk_fs) {
+		snd_soc_dai_set_sysclk(codec_dai, 0, 0, SND_SOC_CLOCK_IN);
+		snd_soc_dai_set_sysclk(cpu_dai, 0, 0, SND_SOC_CLOCK_OUT);
+	}
+
 	asoc_simple_clk_disable(dai_props->cpu_dai);
 
 	asoc_simple_clk_disable(dai_props->codec_dai);
-- 
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] 5+ messages in thread

end of thread, other threads:[~2019-09-09 10:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-07 17:45 [alsa-devel] [PATCH] SoC: simple-card-utils: set 0Hz to sysclk when shutdown Katsuhiro Suzuki
2019-09-09  0:31 ` Kuninori Morimoto
2019-09-09  2:49   ` Katsuhiro Suzuki
2019-09-09  3:54     ` Kuninori Morimoto
2019-09-09 10:07 ` [alsa-devel] Applied "SoC: simple-card-utils: set 0Hz to sysclk when shutdown" to the asoc tree Mark Brown

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