[10/10] ASoC: soc.h: add for_each_pcm_stream()
diff mbox series

Message ID 87wo8rqfi3.wl-kuninori.morimoto.gx@renesas.com
State New
Headers show
Series
  • ASoC: soc-pcm cleanup step3
Related show

Commit Message

Kuninori Morimoto Feb. 13, 2020, 4:26 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

ALSA SoC has SNDRV_PCM_STREAM_PLAYBACK/CAPTURE everywhere.
Having for_each_xxxx macro is useful.
This patch adds for_each_pcm_stream() for it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/soc.h          |  5 +++++
 sound/soc/fsl/fsl_asrc_dma.c |  4 ++--
 sound/soc/soc-core.c         | 31 +++++++++++++------------------
 3 files changed, 20 insertions(+), 20 deletions(-)

Comments

Takashi Iwai Feb. 13, 2020, 6:35 a.m. UTC | #1
On Thu, 13 Feb 2020 05:26:53 +0100,
Kuninori Morimoto wrote:
> 
> 
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> ALSA SoC has SNDRV_PCM_STREAM_PLAYBACK/CAPTURE everywhere.
> Having for_each_xxxx macro is useful.
> This patch adds for_each_pcm_stream() for it.

This macro can be put in sound/pcm.h.  The similar pattern is found
also generically in many non-ASoC codes, too.


thanks,

Takashi

> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>  include/sound/soc.h          |  5 +++++
>  sound/soc/fsl/fsl_asrc_dma.c |  4 ++--
>  sound/soc/soc-core.c         | 31 +++++++++++++------------------
>  3 files changed, 20 insertions(+), 20 deletions(-)
> 
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index f0e4f36f83bf..58af52efa07d 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
> @@ -419,6 +419,11 @@ enum snd_soc_card_subclass {
>  	SND_SOC_CARD_CLASS_RUNTIME	= 1,
>  };
>  
> +#define for_each_pcm_stream(stream) \
> +	for (stream  = SNDRV_PCM_STREAM_PLAYBACK;	\
> +	     stream <= SNDRV_PCM_STREAM_LAST;		\
> +	     stream++)
> +
>  int snd_soc_register_card(struct snd_soc_card *card);
>  int snd_soc_unregister_card(struct snd_soc_card *card);
>  int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
> diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c
> index ece130f59d15..2f5a62381f94 100644
> --- a/sound/soc/fsl/fsl_asrc_dma.c
> +++ b/sound/soc/fsl/fsl_asrc_dma.c
> @@ -400,7 +400,7 @@ static int fsl_asrc_dma_pcm_new(struct snd_soc_component *component,
>  		return ret;
>  	}
>  
> -	for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_LAST; i++) {
> +	for_each_pcm_stream(i) {
>  		substream = pcm->streams[i].substream;
>  		if (!substream)
>  			continue;
> @@ -428,7 +428,7 @@ static void fsl_asrc_dma_pcm_free(struct snd_soc_component *component,
>  	struct snd_pcm_substream *substream;
>  	int i;
>  
> -	for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_LAST; i++) {
> +	for_each_pcm_stream(i) {
>  		substream = pcm->streams[i].substream;
>  		if (!substream)
>  			continue;
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index 068d809c349a..dc58ce766f3b 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -431,6 +431,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
>  	struct snd_soc_component *component;
>  	struct device *dev;
>  	int ret;
> +	int stream;
>  
>  	/*
>  	 * for rtd->dev
> @@ -465,10 +466,10 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
>  
>  	rtd->dev = dev;
>  	INIT_LIST_HEAD(&rtd->list);
> -	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
> -	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
> -	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
> -	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
> +	for_each_pcm_stream(stream) {
> +		INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients);
> +		INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients);
> +	}
>  	dev_set_drvdata(dev, rtd);
>  	INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
>  
> @@ -558,17 +559,14 @@ int snd_soc_suspend(struct device *dev)
>  	snd_soc_flush_all_delayed_work(card);
>  
>  	for_each_card_rtds(card, rtd) {
> +		int stream;
>  
>  		if (rtd->dai_link->ignore_suspend)
>  			continue;
>  
> -		snd_soc_dapm_stream_event(rtd,
> -					  SNDRV_PCM_STREAM_PLAYBACK,
> -					  SND_SOC_DAPM_STREAM_SUSPEND);
> -
> -		snd_soc_dapm_stream_event(rtd,
> -					  SNDRV_PCM_STREAM_CAPTURE,
> -					  SND_SOC_DAPM_STREAM_SUSPEND);
> +		for_each_pcm_stream(stream)
> +			snd_soc_dapm_stream_event(rtd, stream,
> +						  SND_SOC_DAPM_STREAM_SUSPEND);
>  	}
>  
>  	/* Recheck all endpoints too, their state is affected by suspend */
> @@ -664,17 +662,14 @@ static void soc_resume_deferred(struct work_struct *work)
>  	}
>  
>  	for_each_card_rtds(card, rtd) {
> +		int stream;
>  
>  		if (rtd->dai_link->ignore_suspend)
>  			continue;
>  
> -		snd_soc_dapm_stream_event(rtd,
> -					  SNDRV_PCM_STREAM_PLAYBACK,
> -					  SND_SOC_DAPM_STREAM_RESUME);
> -
> -		snd_soc_dapm_stream_event(rtd,
> -					  SNDRV_PCM_STREAM_CAPTURE,
> -					  SND_SOC_DAPM_STREAM_RESUME);
> +		for_each_pcm_stream(stream)
> +			snd_soc_dapm_stream_event(rtd, stream,
> +						  SND_SOC_DAPM_STREAM_RESUME);
>  	}
>  
>  	/* unmute any active DACs */
> -- 
> 2.17.1
> 
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
Kuninori Morimoto Feb. 13, 2020, 6:46 a.m. UTC | #2
Hi Takashi

Thank you for your feedback

> > From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > 
> > ALSA SoC has SNDRV_PCM_STREAM_PLAYBACK/CAPTURE everywhere.
> > Having for_each_xxxx macro is useful.
> > This patch adds for_each_pcm_stream() for it.
> 
> This macro can be put in sound/pcm.h.  The similar pattern is found
> also generically in many non-ASoC codes, too.
(snip)
> > +#define for_each_pcm_stream(stream) \
> > +	for (stream  = SNDRV_PCM_STREAM_PLAYBACK;	\
> > +	     stream <= SNDRV_PCM_STREAM_LAST;		\
> > +	     stream++)

I see.
Will do in v2


Thank you for your help !!
Best regards
---
Kuninori Morimoto
Pierre-Louis Bossart Feb. 13, 2020, 4:14 p.m. UTC | #3
On 2/12/20 10:26 PM, Kuninori Morimoto wrote:
> 
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> ALSA SoC has SNDRV_PCM_STREAM_PLAYBACK/CAPTURE everywhere.
> Having for_each_xxxx macro is useful.
> This patch adds for_each_pcm_stream() for it.

Indeed, we also have ugly code in SOF for this:

for (dir = 0; dir <= SNDRV_PCM_STREAM_CAPTURE; dir++) {

a macro would be much nicer, good suggestion.
Kuninori Morimoto Feb. 14, 2020, 12:05 a.m. UTC | #4
Hi Pierre-Louis

> > From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > 
> > ALSA SoC has SNDRV_PCM_STREAM_PLAYBACK/CAPTURE everywhere.
> > Having for_each_xxxx macro is useful.
> > This patch adds for_each_pcm_stream() for it.
> 
> Indeed, we also have ugly code in SOF for this:
> 
> for (dir = 0; dir <= SNDRV_PCM_STREAM_CAPTURE; dir++) {
> 
> a macro would be much nicer, good suggestion.

Thank you for pointing it.
I will care it in v2 :)

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

Patch
diff mbox series

diff --git a/include/sound/soc.h b/include/sound/soc.h
index f0e4f36f83bf..58af52efa07d 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -419,6 +419,11 @@  enum snd_soc_card_subclass {
 	SND_SOC_CARD_CLASS_RUNTIME	= 1,
 };
 
+#define for_each_pcm_stream(stream) \
+	for (stream  = SNDRV_PCM_STREAM_PLAYBACK;	\
+	     stream <= SNDRV_PCM_STREAM_LAST;		\
+	     stream++)
+
 int snd_soc_register_card(struct snd_soc_card *card);
 int snd_soc_unregister_card(struct snd_soc_card *card);
 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c
index ece130f59d15..2f5a62381f94 100644
--- a/sound/soc/fsl/fsl_asrc_dma.c
+++ b/sound/soc/fsl/fsl_asrc_dma.c
@@ -400,7 +400,7 @@  static int fsl_asrc_dma_pcm_new(struct snd_soc_component *component,
 		return ret;
 	}
 
-	for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_LAST; i++) {
+	for_each_pcm_stream(i) {
 		substream = pcm->streams[i].substream;
 		if (!substream)
 			continue;
@@ -428,7 +428,7 @@  static void fsl_asrc_dma_pcm_free(struct snd_soc_component *component,
 	struct snd_pcm_substream *substream;
 	int i;
 
-	for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_LAST; i++) {
+	for_each_pcm_stream(i) {
 		substream = pcm->streams[i].substream;
 		if (!substream)
 			continue;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 068d809c349a..dc58ce766f3b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -431,6 +431,7 @@  static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_component *component;
 	struct device *dev;
 	int ret;
+	int stream;
 
 	/*
 	 * for rtd->dev
@@ -465,10 +466,10 @@  static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 
 	rtd->dev = dev;
 	INIT_LIST_HEAD(&rtd->list);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
-	INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
+	for_each_pcm_stream(stream) {
+		INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients);
+		INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients);
+	}
 	dev_set_drvdata(dev, rtd);
 	INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
 
@@ -558,17 +559,14 @@  int snd_soc_suspend(struct device *dev)
 	snd_soc_flush_all_delayed_work(card);
 
 	for_each_card_rtds(card, rtd) {
+		int stream;
 
 		if (rtd->dai_link->ignore_suspend)
 			continue;
 
-		snd_soc_dapm_stream_event(rtd,
-					  SNDRV_PCM_STREAM_PLAYBACK,
-					  SND_SOC_DAPM_STREAM_SUSPEND);
-
-		snd_soc_dapm_stream_event(rtd,
-					  SNDRV_PCM_STREAM_CAPTURE,
-					  SND_SOC_DAPM_STREAM_SUSPEND);
+		for_each_pcm_stream(stream)
+			snd_soc_dapm_stream_event(rtd, stream,
+						  SND_SOC_DAPM_STREAM_SUSPEND);
 	}
 
 	/* Recheck all endpoints too, their state is affected by suspend */
@@ -664,17 +662,14 @@  static void soc_resume_deferred(struct work_struct *work)
 	}
 
 	for_each_card_rtds(card, rtd) {
+		int stream;
 
 		if (rtd->dai_link->ignore_suspend)
 			continue;
 
-		snd_soc_dapm_stream_event(rtd,
-					  SNDRV_PCM_STREAM_PLAYBACK,
-					  SND_SOC_DAPM_STREAM_RESUME);
-
-		snd_soc_dapm_stream_event(rtd,
-					  SNDRV_PCM_STREAM_CAPTURE,
-					  SND_SOC_DAPM_STREAM_RESUME);
+		for_each_pcm_stream(stream)
+			snd_soc_dapm_stream_event(rtd, stream,
+						  SND_SOC_DAPM_STREAM_RESUME);
 	}
 
 	/* unmute any active DACs */