ASoC: intel: sof_sdw: Factor out SoundWire DAI creation
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Tue, 26 Mar 2024 16:04:18 +0000 (11:04 -0500)
committerMark Brown <broonie@kernel.org>
Tue, 26 Mar 2024 16:13:40 +0000 (16:13 +0000)
Factor out the creation of the SoundWire DAI links into a helper
function. No functional change.

Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://msgid.link/r/20240326160429.13560-24-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/sof_sdw.c

index 9f1c49df9cd2b690d257462179915b39a78445e4..3e6a758c98ab494c77636416655ee7f460b5f509 100644 (file)
@@ -1559,6 +1559,34 @@ static int create_sdw_dailink(struct snd_soc_card *card,
        return 0;
 }
 
+static int create_sdw_dailinks(struct snd_soc_card *card,
+                              struct snd_soc_dai_link **dai_links, int *be_id,
+                              struct sof_sdw_dailink *sof_dais)
+{
+       struct mc_private *ctx = snd_soc_card_get_drvdata(card);
+       int ret, i;
+
+       for (i = 0; i < SDW_MAX_LINKS; i++)
+               ctx->sdw_pin_index[i] = SDW_INTEL_BIDIR_PDI_BASE;
+
+       /* generate DAI links by each sdw link */
+       while (sof_dais->initialised) {
+               int current_be_id;
+
+               ret = create_sdw_dailink(card, sof_dais, dai_links, &current_be_id);
+               if (ret)
+                       return ret;
+
+               /* Update the be_id to match the highest ID used for SDW link */
+               if (*be_id < current_be_id)
+                       *be_id = current_be_id;
+
+               sof_dais++;
+       }
+
+       return 0;
+}
+
 static int create_ssp_dailinks(struct snd_soc_card *card,
                               struct snd_soc_dai_link **dai_links, int *be_id,
                               struct sof_sdw_codec_info *ssp_info,
@@ -1692,7 +1720,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
        int num_ends = 0;
        struct snd_soc_dai_link *dai_links;
        int num_links;
-       int i, be_id = 0;
+       int be_id = 0;
        int hdmi_num;
        unsigned long ssp_mask;
        int ret;
@@ -1774,28 +1802,12 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
        card->num_links = num_links;
 
        /* SDW */
-       if (!sdw_be_num)
-               goto SSP;
-
-       for (i = 0; i < SDW_MAX_LINKS; i++)
-               ctx->sdw_pin_index[i] = SDW_INTEL_BIDIR_PDI_BASE;
-
-       /* generate DAI links by each sdw link */
-       while (sof_dais->initialised) {
-               int current_be_id;
-
-               ret = create_sdw_dailink(card, sof_dais, &dai_links, &current_be_id);
+       if (sdw_be_num) {
+               ret = create_sdw_dailinks(card, &dai_links, &be_id, sof_dais);
                if (ret)
                        goto err_end;
-
-               /* Update the be_id to match the highest ID used for SDW link */
-               if (be_id < current_be_id)
-                       be_id = current_be_id;
-
-               sof_dais++;
        }
 
-SSP:
        /* SSP */
        if (ssp_num) {
                ret = create_ssp_dailinks(card, &dai_links, &be_id,