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

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87d0hx5rnm.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 8dacac9538849a8da0b4d637514af80a1ab7b3ad..ff8233014444ec474f5ccec031df914ece749e02 100644 (file)
@@ -343,5 +343,7 @@ int snd_soc_component_open(struct snd_soc_component *component,
                           struct snd_pcm_substream *substream);
 int snd_soc_component_close(struct snd_soc_component *component,
                            struct snd_pcm_substream *substream);
+int snd_soc_component_prepare(struct snd_soc_component *component,
+                             struct snd_pcm_substream *substream);
 
 #endif /* __SOC_COMPONENT_H */
index cee66183470d861d94246ee390c2a132165cacd9..733d7139d87535e84be701b6d2b836dfda87f7ea 100644 (file)
@@ -305,3 +305,13 @@ int snd_soc_component_close(struct snd_soc_component *component,
 
        return 0;
 }
+
+int snd_soc_component_prepare(struct snd_soc_component *component,
+                             struct snd_pcm_substream *substream)
+{
+       if (component->driver->ops &&
+           component->driver->ops->prepare)
+               return component->driver->ops->prepare(substream);
+
+       return 0;
+}
index 4848642ef159bbd5f1509d0cc80889fa5a365797..c7fee67bc0dcb68fe6f37373ff172bbda6418fc8 100644 (file)
@@ -785,11 +785,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
        for_each_rtdcom(rtd, rtdcom) {
                component = rtdcom->component;
 
-               if (!component->driver->ops ||
-                   !component->driver->ops->prepare)
-                       continue;
-
-               ret = component->driver->ops->prepare(substream);
+               ret = snd_soc_component_prepare(component, substream);
                if (ret < 0) {
                        dev_err(component->dev,
                                "ASoC: platform prepare error: %d\n", ret);