alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: codecs: va-macro: use fsgen as clock
@ 2022-07-27 12:47 Srinivas Kandagatla
  2022-07-27 13:38 ` Srinivasa Rao Mandadapu
  2022-07-27 21:25 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Srinivas Kandagatla @ 2022-07-27 12:47 UTC (permalink / raw)
  To: broonie
  Cc: alsa-devel, lgirdwood, linux-kernel, tiwai, Srinivas Kandagatla,
	Srinivasa Rao Mandadapu

VA Macro fsgen clock is supplied to other LPASS Macros using proper
clock apis, however the internal user uses the registers directly without
clk apis. This approch has race condition where in external users of
the clock might cut the clock while VA macro is actively using this.

Moving the internal usage to clk apis would provide a proper refcounting
and avoid such race conditions.

This issue was noticed while headset was pulled out while recording is
in progress and shifting record patch to DMIC.

Reported-by: Srinivasa Rao Mandadapu <quic_srivasam@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 sound/soc/codecs/lpass-va-macro.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c
index d18b56e60433..1ea10dc70748 100644
--- a/sound/soc/codecs/lpass-va-macro.c
+++ b/sound/soc/codecs/lpass-va-macro.c
@@ -199,6 +199,7 @@ struct va_macro {
 	struct clk *mclk;
 	struct clk *macro;
 	struct clk *dcodec;
+	struct clk *fsgen;
 	struct clk_hw hw;
 	struct lpass_macro *pds;
 
@@ -467,9 +468,9 @@ static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
 
 	switch (event) {
 	case SND_SOC_DAPM_PRE_PMU:
-		return va_macro_mclk_enable(va, true);
+		return clk_prepare_enable(va->fsgen);
 	case SND_SOC_DAPM_POST_PMD:
-		return va_macro_mclk_enable(va, false);
+		clk_disable_unprepare(va->fsgen);
 	}
 
 	return 0;
@@ -1473,6 +1474,12 @@ static int va_macro_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_clkout;
 
+	va->fsgen = clk_hw_get_clk(&va->hw, "fsgen");
+	if (IS_ERR(va->fsgen)) {
+		ret = PTR_ERR(va->fsgen);
+		goto err_clkout;
+	}
+
 	ret = devm_snd_soc_register_component(dev, &va_macro_component_drv,
 					      va_macro_dais,
 					      ARRAY_SIZE(va_macro_dais));
-- 
2.25.1


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

* Re: [PATCH] ASoC: codecs: va-macro: use fsgen as clock
  2022-07-27 12:47 [PATCH] ASoC: codecs: va-macro: use fsgen as clock Srinivas Kandagatla
@ 2022-07-27 13:38 ` Srinivasa Rao Mandadapu
  2022-07-27 21:25 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Srinivasa Rao Mandadapu @ 2022-07-27 13:38 UTC (permalink / raw)
  To: Srinivas Kandagatla, broonie; +Cc: linux-kernel, alsa-devel, tiwai, lgirdwood

Thanks for the Patch Srini!!!

On 7/27/2022 6:17 PM, Srinivas Kandagatla wrote:
> VA Macro fsgen clock is supplied to other LPASS Macros using proper
> clock apis, however the internal user uses the registers directly without
> clk apis. This approch has race condition where in external users of
> the clock might cut the clock while VA macro is actively using this.
>
> Moving the internal usage to clk apis would provide a proper refcounting
> and avoid such race conditions.
>
> This issue was noticed while headset was pulled out while recording is
> in progress and shifting record patch to DMIC.
>
> Reported-by: Srinivasa Rao Mandadapu <quic_srivasam@quicinc.com>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
This is verified on SC7280 based platform.

Tested-by: Srinivasa Rao Mandadapu <quic_srivasam@quicinc.com>

>   sound/soc/codecs/lpass-va-macro.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c
> index d18b56e60433..1ea10dc70748 100644
> --- a/sound/soc/codecs/lpass-va-macro.c
> +++ b/sound/soc/codecs/lpass-va-macro.c
> @@ -199,6 +199,7 @@ struct va_macro {
>   	struct clk *mclk;
>   	struct clk *macro;
>   	struct clk *dcodec;
> +	struct clk *fsgen;
>   	struct clk_hw hw;
>   	struct lpass_macro *pds;
>   
> @@ -467,9 +468,9 @@ static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
>   
>   	switch (event) {
>   	case SND_SOC_DAPM_PRE_PMU:
> -		return va_macro_mclk_enable(va, true);
> +		return clk_prepare_enable(va->fsgen);
>   	case SND_SOC_DAPM_POST_PMD:
> -		return va_macro_mclk_enable(va, false);
> +		clk_disable_unprepare(va->fsgen);
>   	}
>   
>   	return 0;
> @@ -1473,6 +1474,12 @@ static int va_macro_probe(struct platform_device *pdev)
>   	if (ret)
>   		goto err_clkout;
>   
> +	va->fsgen = clk_hw_get_clk(&va->hw, "fsgen");
> +	if (IS_ERR(va->fsgen)) {
> +		ret = PTR_ERR(va->fsgen);
> +		goto err_clkout;
> +	}
> +
>   	ret = devm_snd_soc_register_component(dev, &va_macro_component_drv,
>   					      va_macro_dais,
>   					      ARRAY_SIZE(va_macro_dais));

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

* Re: [PATCH] ASoC: codecs: va-macro: use fsgen as clock
  2022-07-27 12:47 [PATCH] ASoC: codecs: va-macro: use fsgen as clock Srinivas Kandagatla
  2022-07-27 13:38 ` Srinivasa Rao Mandadapu
@ 2022-07-27 21:25 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2022-07-27 21:25 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: alsa-devel, linux-kernel, tiwai, lgirdwood, Srinivasa Rao Mandadapu

On Wed, 27 Jul 2022 13:47:49 +0100, Srinivas Kandagatla wrote:
> VA Macro fsgen clock is supplied to other LPASS Macros using proper
> clock apis, however the internal user uses the registers directly without
> clk apis. This approch has race condition where in external users of
> the clock might cut the clock while VA macro is actively using this.
> 
> Moving the internal usage to clk apis would provide a proper refcounting
> and avoid such race conditions.
> 
> [...]

Applied to

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

Thanks!

[1/1] ASoC: codecs: va-macro: use fsgen as clock
      commit: 30097967e0566cac817273ef76add100f6b0f463

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

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

end of thread, other threads:[~2022-07-27 21:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 12:47 [PATCH] ASoC: codecs: va-macro: use fsgen as clock Srinivas Kandagatla
2022-07-27 13:38 ` Srinivasa Rao Mandadapu
2022-07-27 21:25 ` 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).