ASoC: soc-component: add snd_soc_pcm_component_pcm_new()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Fri, 26 Jul 2019 04:52:08 +0000 (13:52 +0900)
committerMark Brown <broonie@kernel.org>
Mon, 5 Aug 2019 15:26:50 +0000 (16:26 +0100)
Current ALSA SoC is directly using component->driver->xxx,
thus, the code nested deeply, and it makes code difficult to read,
and is not good for encapsulation.

We want to implement component related function at soc-component.c,
but, some of them need to care whole snd_soc_pcm_runtime (= rtd)
connected component.

Let's call component related function which need to care with
for_each_rtdcom() loop as snd_soc_pcm_component_xxx().
This patch adds new snd_soc_pcm_component_pcm() and use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87lfwl4czy.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc-component.h
sound/soc/soc-component.c
sound/soc/soc-pcm.c

index dd1ea5d71998bb65052e3add3cdc03b868e47940..d3048ad0658289a95f8355277e97264771ec237e 100644 (file)
@@ -381,5 +381,6 @@ struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
                                        unsigned long offset);
 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
                               struct vm_area_struct *vma);
+int snd_soc_pcm_component_new(struct snd_pcm *pcm);
 
 #endif /* __SOC_COMPONENT_H */
index 2aff1b087522cb974f3164cd5f800df235bfbfda..ff13d901bbab460e34694d4e36001f0439ff3f67 100644 (file)
@@ -525,3 +525,23 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
 
        return -EINVAL;
 }
+
+int snd_soc_pcm_component_new(struct snd_pcm *pcm)
+{
+       struct snd_soc_pcm_runtime *rtd = pcm->private_data;
+       struct snd_soc_rtdcom_list *rtdcom;
+       struct snd_soc_component *component;
+       int ret;
+
+       for_each_rtdcom(rtd, rtdcom) {
+               component = rtdcom->component;
+
+               if (component->driver->pcm_new) {
+                       ret = component->driver->pcm_new(rtd);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
index 7bbee0d719426cc7a83058592f025e3f748daa60..955c49fd3bda5c1448f2c7b098db70b3d64dc0b9 100644 (file)
@@ -2823,7 +2823,6 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 {
        struct snd_soc_dai *codec_dai;
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_component *component;
        struct snd_soc_rtdcom_list *rtdcom;
        struct snd_pcm *pcm;
        char new_name[64];
@@ -2956,19 +2955,10 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
        if (capture)
                snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
 
-       for_each_rtdcom(rtd, rtdcom) {
-               component = rtdcom->component;
-
-               if (!component->driver->pcm_new)
-                       continue;
-
-               ret = component->driver->pcm_new(rtd);
-               if (ret < 0) {
-                       dev_err(component->dev,
-                               "ASoC: pcm constructor failed: %d\n",
-                               ret);
-                       return ret;
-               }
+       ret = snd_soc_pcm_component_new(pcm);
+       if (ret < 0) {
+               dev_err(rtd->dev, "ASoC: pcm constructor failed: %d\n", ret);
+               return ret;
        }
 
        pcm->private_free = soc_pcm_private_free;