ASoC: soc-dai: add snd_soc_dai_prepare()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Mon, 22 Jul 2019 01:33:45 +0000 (10:33 +0900)
committerMark Brown <broonie@kernel.org>
Tue, 23 Jul 2019 17:14:18 +0000 (18:14 +0100)
Current ALSA SoC is directly using dai->driver->ops->xxx,
thus, it has deep nested bracket, and it makes code unreadable.
This patch adds new snd_soc_dai_prepare() and use it.

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

index 32545d457b3d3a9aff2d1907b51c038755caee0e..c7dff6a0b5b9c209820b884a75a06f913628ea91 100644 (file)
@@ -154,6 +154,8 @@ int snd_soc_dai_startup(struct snd_soc_dai *dai,
                        struct snd_pcm_substream *substream);
 void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
                          struct snd_pcm_substream *substream);
+int snd_soc_dai_prepare(struct snd_soc_dai *dai,
+                       struct snd_pcm_substream *substream);
 
 struct snd_soc_dai_ops {
        /*
index 67ff6cc1fe022d059f7002d0d5e98bb98e79707a..cb810888c563620065389dad50b8b240b934ca5d 100644 (file)
@@ -307,3 +307,14 @@ void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
        if (dai->driver->ops->shutdown)
                dai->driver->ops->shutdown(substream, dai);
 }
+
+int snd_soc_dai_prepare(struct snd_soc_dai *dai,
+                       struct snd_pcm_substream *substream)
+{
+       int ret = 0;
+
+       if (dai->driver->ops->prepare)
+               ret = dai->driver->ops->prepare(substream, dai);
+
+       return ret;
+}
index ed5ae23c7104d684c00aaabd74d2e6811aa0ffd9..d7611af90dce7892957a638dd2d529b86fde203c 100644 (file)
@@ -814,27 +814,22 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
        }
 
        for_each_rtd_codec_dai(rtd, i, codec_dai) {
-               if (codec_dai->driver->ops->prepare) {
-                       ret = codec_dai->driver->ops->prepare(substream,
-                                                             codec_dai);
-                       if (ret < 0) {
-                               dev_err(codec_dai->dev,
-                                       "ASoC: codec DAI prepare error: %d\n",
-                                       ret);
-                               goto out;
-                       }
-               }
-       }
-
-       if (cpu_dai->driver->ops->prepare) {
-               ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
+               ret = snd_soc_dai_prepare(codec_dai, substream);
                if (ret < 0) {
-                       dev_err(cpu_dai->dev,
-                               "ASoC: cpu DAI prepare error: %d\n", ret);
+                       dev_err(codec_dai->dev,
+                               "ASoC: codec DAI prepare error: %d\n",
+                               ret);
                        goto out;
                }
        }
 
+       ret = snd_soc_dai_prepare(cpu_dai, substream);
+       if (ret < 0) {
+               dev_err(cpu_dai->dev,
+                       "ASoC: cpu DAI prepare error: %d\n", ret);
+               goto out;
+       }
+
        /* cancel any delayed stream shutdown that is pending */
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
            rtd->pop_wait) {