ASoC: soc-core.c: add snd_soc_add_pcm_runtimes()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Mon, 27 Mar 2023 00:34:26 +0000 (00:34 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 28 Mar 2023 00:26:03 +0000 (01:26 +0100)
Current ASoC supports snd_soc_add_pcm_runtime(), but user need to
call it one-by-one if it has multi dai_links.
This patch adds snd_soc_add_pcm_runtimes() which supports multi
dai_links.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87h6u76nhq.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc.h
sound/soc/intel/avs/boards/hdaudio.c
sound/soc/soc-core.c
sound/soc/soc-topology.c

index e58b43b5da7c05f5114424c5510baa2bf41e1d0f..57c5786a625b2f532c83385d52b56a154d3ee214 100644 (file)
@@ -1302,8 +1302,9 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev,
                                 struct snd_soc_dai_link *dai_link);
 void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link);
 
-int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
-                           struct snd_soc_dai_link *dai_link);
+int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
+                            struct snd_soc_dai_link *dai_link,
+                            int num_dai_link);
 void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
                                struct snd_soc_pcm_runtime *rtd);
 
index e68c4c7aa2bad5d9840d3f4f62eefb0fe594fa39..a542a67e21d07759e40e192fe948e518fc20f136 100644 (file)
@@ -194,12 +194,10 @@ static int avs_probing_link_init(struct snd_soc_pcm_runtime *rtm)
                return ret;
        }
 
-       for (n = 0; n < pcm_count; n++) {
-               ret = snd_soc_add_pcm_runtime(card, &links[n]);
-               if (ret < 0) {
-                       dev_err(card->dev, "add links failed: %d\n", ret);
-                       return ret;
-               }
+       ret = snd_soc_add_pcm_runtimes(card, links, pcm_count);
+       if (ret < 0) {
+               dev_err(card->dev, "add links failed: %d\n", ret);
+               return ret;
        }
 
        ret = avs_create_dapm_routes(card->dev, codec, pcm_count, &routes, &n);
index 2faa0d8d0d8e8d8dcb9931f7d04f6dcb36d5a417..9bbcff492c1e2fd2c92f67f82967554fd5a459fc 100644 (file)
@@ -959,8 +959,8 @@ EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
  * topology component. And machine drivers can still define static
  * DAI links in dai_link array.
  */
-int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
-                           struct snd_soc_dai_link *dai_link)
+static int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
+                                  struct snd_soc_dai_link *dai_link)
 {
        struct snd_soc_pcm_runtime *rtd;
        struct snd_soc_dai_link_component *codec, *platform, *cpu;
@@ -1027,7 +1027,21 @@ _err_defer:
        snd_soc_remove_pcm_runtime(card, rtd);
        return -EPROBE_DEFER;
 }
-EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtime);
+
+int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
+                            struct snd_soc_dai_link *dai_link,
+                            int num_dai_link)
+{
+       for (int i = 0; i < num_dai_link; i++) {
+               int ret = snd_soc_add_pcm_runtime(card, dai_link + i);
+
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtimes);
 
 static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
 {
@@ -1921,8 +1935,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 {
        struct snd_soc_pcm_runtime *rtd;
        struct snd_soc_component *component;
-       struct snd_soc_dai_link *dai_link;
-       int ret, i;
+       int ret;
 
        mutex_lock(&client_mutex);
        mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
@@ -1939,11 +1952,9 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 
        /* add predefined DAI links to the list */
        card->num_rtd = 0;
-       for_each_card_prelinks(card, i, dai_link) {
-               ret = snd_soc_add_pcm_runtime(card, dai_link);
-               if (ret < 0)
-                       goto probe_end;
-       }
+       ret = snd_soc_add_pcm_runtimes(card, card->dai_link, card->num_links);
+       if (ret < 0)
+               goto probe_end;
 
        /* card bind complete so register a sound card */
        ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
index 7f6424fa59abea55b78af4531784ab185f3b6e85..be9849749713c5db44c16aea9d5d9f2d3b9788e6 100644 (file)
@@ -1741,7 +1741,7 @@ static int soc_tplg_fe_link_create(struct soc_tplg *tplg,
                goto err;
        }
 
-       ret = snd_soc_add_pcm_runtime(tplg->comp->card, link);
+       ret = snd_soc_add_pcm_runtimes(tplg->comp->card, link, 1);
        if (ret < 0) {
                dev_err(tplg->dev, "ASoC: adding FE link failed\n");
                goto err;