All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: linux-sound@vger.kernel.org
Cc: alsa-devel@alsa-project.org, tiwai@suse.de, broonie@kernel.org,
	Charles Keepax <ckeepax@opensource.cirrus.com>,
	Richard Fitzgerald <rf@opensource.cirrus.com>,
	Shuming Fan <shumingf@realtek.com>, Jack Yu <jack.yu@realtek.com>,
	Oder Chiou <oder_chiou@realtek.com>,
	Bard liao <yung-chuan.liao@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: [PATCH 19/34] ASoC: Intel: sof_sdw: Move counting and codec_conf to new parsing
Date: Tue, 26 Mar 2024 11:04:14 -0500	[thread overview]
Message-ID: <20240326160429.13560-20-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20240326160429.13560-1-pierre-louis.bossart@linux.intel.com>

From: Charles Keepax <ckeepax@opensource.cirrus.com>

Use the output of the new snd_soc_acpi struct parsing for the purposes
of counting the number of SoundWire DAI links and physical devices
attached to the SoundWire. These counts are already returned by the
parser so those can just be used directly. But the population of the
codec_conf structures, is moved from the old parsing code over to the
new. As the two parsers currently co-exist it is better to not have
them both attempt to modify the same structures.

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>
---
 sound/soc/intel/boards/sof_sdw.c | 124 ++++++-------------------------
 1 file changed, 22 insertions(+), 102 deletions(-)

diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c
index 15bf8fbb3be9..0566ab843c2e 100644
--- a/sound/soc/intel/boards/sof_sdw.c
+++ b/sound/soc/intel/boards/sof_sdw.c
@@ -1126,79 +1126,6 @@ static struct sof_sdw_codec_info *find_codec_info_dai(const char *dai_name,
 	return NULL;
 }
 
-/*
- * get BE dailink number and CPU DAI number based on sdw link adr.
- * Since some sdw slaves may be aggregated, the CPU DAI number
- * may be larger than the number of BE dailinks.
- */
-static int get_dailink_info(struct device *dev,
-			    const struct snd_soc_acpi_link_adr *adr_link,
-			    int *sdw_be_num, int *codecs_num)
-{
-	bool group_visited[SDW_MAX_GROUPS];
-	int i;
-	int j;
-
-	*sdw_be_num  = 0;
-
-	if (!adr_link)
-		return -EINVAL;
-
-	for (i = 0; i < SDW_MAX_GROUPS; i++)
-		group_visited[i] = false;
-
-	for (; adr_link->num_adr; adr_link++) {
-		const struct snd_soc_acpi_endpoint *endpoint;
-		struct sof_sdw_codec_info *codec_info;
-		int stream;
-		u64 adr;
-
-		/* make sure the link mask has a single bit set */
-		if (!is_power_of_2(adr_link->mask))
-			return -EINVAL;
-
-		for (i = 0; i < adr_link->num_adr; i++) {
-			adr = adr_link->adr_d[i].adr;
-			codec_info = find_codec_info_part(adr);
-			if (!codec_info)
-				return -EINVAL;
-
-			*codecs_num += codec_info->dai_num;
-
-			if (!adr_link->adr_d[i].name_prefix) {
-				dev_err(dev, "codec 0x%llx does not have a name prefix\n",
-					adr_link->adr_d[i].adr);
-				return -EINVAL;
-			}
-
-			endpoint = adr_link->adr_d[i].endpoints;
-			if (endpoint->aggregated && !endpoint->group_id) {
-				dev_err(dev, "invalid group id on link %x\n",
-					adr_link->mask);
-				return -EINVAL;
-			}
-
-			for (j = 0; j < codec_info->dai_num; j++) {
-				/* count DAI number for playback and capture */
-				for_each_pcm_streams(stream) {
-					if (!codec_info->dais[j].direction[stream])
-						continue;
-
-					/* count BE for each non-aggregated slave or group */
-					if (!endpoint->aggregated ||
-					    !group_visited[endpoint->group_id])
-						(*sdw_be_num)++;
-				}
-			}
-
-			if (endpoint->aggregated)
-				group_visited[endpoint->group_id] = true;
-		}
-	}
-
-	return 0;
-}
-
 static void init_dai_link(struct device *dev, struct snd_soc_dai_link *dai_links,
 			  int *be_id, char *name, int playback, int capture,
 			  struct snd_soc_dai_link_component *cpus, int cpus_num,
@@ -1528,6 +1455,7 @@ static int parse_sdw_endpoints(struct snd_soc_card *card,
 	struct device *dev = card->dev;
 	struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);
 	struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params;
+	struct snd_soc_codec_conf *codec_conf = card->codec_conf;
 	const struct snd_soc_acpi_link_adr *adr_link;
 	struct sof_sdw_endpoint *sof_end = sof_ends;
 	int num_dais = 0;
@@ -1559,6 +1487,13 @@ static int parse_sdw_endpoints(struct snd_soc_card *card,
 			if (!codec_name)
 				return -ENOMEM;
 
+			codec_conf->dlc.name = codec_name;
+			codec_conf->name_prefix = adr_dev->name_prefix;
+			codec_conf++;
+
+			dev_dbg(dev, "Adding prefix %s for %s\n",
+				adr_dev->name_prefix, codec_name);
+
 			for (j = 0; j < adr_dev->num_endpoints; j++) {
 				const struct snd_soc_acpi_endpoint *adr_end;
 				const struct sof_sdw_dai_info *dai_info;
@@ -1614,13 +1549,14 @@ static int parse_sdw_endpoints(struct snd_soc_card *card,
 		}
 	}
 
+	WARN_ON(codec_conf != card->codec_conf + card->num_configs);
+
 	return num_dais;
 }
 
 static int create_sdw_dailink(struct snd_soc_card *card,
 			      struct snd_soc_dai_link **dai_links,
 			      const struct snd_soc_acpi_link_adr *adr_link,
-			      struct snd_soc_codec_conf **codec_conf,
 			      int *be_id, int adr_index, int dai_index)
 {
 	struct mc_private *ctx = snd_soc_card_get_drvdata(card);
@@ -1672,26 +1608,16 @@ static int create_sdw_dailink(struct snd_soc_card *card,
 					 endpoints->group_id != group_id))
 				continue;
 
-			/* sanity check */
-			if (*codec_conf >= card->codec_conf + card->num_configs) {
-				dev_err(dev, "codec_conf array overflowed\n");
-				return -EINVAL;
-			}
-
 			ret = fill_sdw_codec_dlc(dev, adr_link_next,
 						 &codecs[codec_dlc_index],
 						 j, dai_index);
 			if (ret)
 				return ret;
 
-			(*codec_conf)->dlc = codecs[codec_dlc_index];
-			(*codec_conf)->name_prefix = adr_link_next->adr_d[j].name_prefix;
-
 			sdw_codec_ch_maps[codec_dlc_index].cpu = i;
 			sdw_codec_ch_maps[codec_dlc_index].codec = codec_dlc_index;
 
 			codec_dlc_index++;
-			(*codec_conf)++;
 		}
 		j = 0;
 
@@ -1913,7 +1839,6 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 	struct sof_sdw_codec_info *ssp_info;
 	struct sof_sdw_endpoint *sof_ends;
 	struct sof_sdw_dailink *sof_dais;
-	int codec_conf_num = 0;
 	int num_devs = 0;
 	int num_ends = 0;
 	bool group_generated[SDW_MAX_GROUPS] = { };
@@ -1942,15 +1867,21 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 		goto err_dai;
 	}
 
+	/* will be populated when acpi endpoints are parsed */
+	codec_conf = devm_kcalloc(dev, num_devs, sizeof(*codec_conf), GFP_KERNEL);
+	if (!codec_conf) {
+		ret = -ENOMEM;
+		goto err_end;
+	}
+
+	card->codec_conf = codec_conf;
+	card->num_configs = num_devs;
+
 	ret = parse_sdw_endpoints(card, sof_dais, sof_ends);
 	if (ret < 0)
 		goto err_end;
 
-	ret = get_dailink_info(dev, adr_link, &sdw_be_num, &codec_conf_num);
-	if (ret < 0) {
-		dev_err(dev, "failed to get sdw link info %d\n", ret);
-		goto err_end;
-	}
+	sdw_be_num = ret;
 
 	/*
 	 * on generic tgl platform, I2S or sdw mode is supported
@@ -1991,18 +1922,8 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 		goto err_end;
 	}
 
-	/* allocate codec conf, will be populated when dailinks are created */
-	codec_conf = devm_kcalloc(dev, codec_conf_num, sizeof(*codec_conf),
-				  GFP_KERNEL);
-	if (!codec_conf) {
-		ret = -ENOMEM;
-		goto err_end;
-	}
-
 	card->dai_link = dai_links;
 	card->num_links = num_links;
-	card->codec_conf = codec_conf;
-	card->num_configs = codec_conf_num;
 
 	/* SDW */
 	if (!sdw_be_num)
@@ -2065,8 +1986,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
 				int current_be_id;
 
 				ret = create_sdw_dailink(card, &dai_links, adr_link,
-							 &codec_conf, &current_be_id,
-							 i, j);
+							 &current_be_id, i, j);
 				if (ret < 0) {
 					dev_err(dev,
 						"failed to create dai link %d on 0x%x\n",
-- 
2.40.1


  parent reply	other threads:[~2024-03-26 16:05 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 16:03 [PATCH 00/34] ASoC: Intel: boards: updates for 6.10 - part2 Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 01/34] ASoC: intel: sof_sdw: Make find_codec_info_part() return a pointer Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 02/34] ASoC: intel: sof_sdw: Make find_codec_info_acpi() " Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 03/34] ASoC: intel: sof_sdw: Make find_codec_info_dai() " Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 04/34] ASoC: intel: sof_sdw: Only pass codec_conf pointer around Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 05/34] ASoC: intel: sof_sdw: Set channel map directly from endpoints Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 06/34] ASoC: Intel: sof_sdw: Move get_codec_dai_by_name() into sof_sdw itself Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 07/34] ASoC: Intel: sof_sdw: Move flags to private struct Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 08/34] ASoC: Intel: sof_sdw: Only pass dai_link pointer around Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 09/34] ASoC: Intel: sof_sdw: Use for_each_set_bit Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 10/34] ASoC: Intel: sof_sdw: Factor out SSP DAI creation Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 11/34] ASoC: Intel: sof_sdw: Factor out DMIC " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 12/34] ASoC: Intel: sof_sdw: Factor out HDMI " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 13/34] ASoC: Intel: sof_sdw: Factor out BlueTooth " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 14/34] ASoC: Intel: sof_sdw: Factor out codec name generation Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 15/34] ASoC: Intel: soc-acpi-intel-arl-match: Add rt711 sdca codec support Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 16/34] ASoC: Intel: sof_sdw: Remove no longer supported quirk Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 17/34] ASoC: intel: soc-acpi: Add missing cs42l43 endpoints Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 18/34] ASoC: Intel: sof-sdw: Add new code for parsing the snd_soc_acpi structs Pierre-Louis Bossart
2024-03-26 16:04 ` Pierre-Louis Bossart [this message]
2024-03-26 16:04 ` [PATCH 20/34] ASoC: Intel: sof_sdw: Move ignore_pch_dmic to new parsing Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 21/34] ASoC: Intel: sof_sdw: Move append_dai_type " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 22/34] ASoC: Intel: sof_sdw: Move generation of DAI links " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 23/34] ASoC: intel: sof_sdw: Factor out SoundWire DAI creation Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 24/34] ASoC: Intel: sof_sdw: use generic rtd_init function for Realtek SDW DMICs Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 25/34] ASoC: Intel: sof_sdw: remove unused rt dmic rtd_init Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 26/34] ASoC: Intel: sof_sdw_rt722_sdca: set rtd_init in codec_info_list[] Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 27/34] ASoC: Intel: sof_sdw_rt722_sdca: use rt_dmic_rtd_init Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 28/34] ASoC: rt715-sdca: rename dai name with rt715-sdca prefix Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 29/34] ASoC: Intel: sof_sdw: change rt715-sdca dai name Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 30/34] ASoC: Intel: change cs35l56 name_prefix Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 31/34] ASoC: Intel: sof_sdw: Don't pass acpi_link_adr to init functions Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 32/34] ASoC: Intel: sof_sdw: Remove redundant initialisations Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 33/34] ASoC: Intel: sof_sdw: Add quirk for optional codec speakers Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 34/34] ASoC: Intel: sof_sdw: Add support for cs42l43 optional speaker output Pierre-Louis Bossart
2024-03-27 15:10 ` [PATCH 00/34] ASoC: Intel: boards: updates for 6.10 - part2 Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240326160429.13560-20-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=jack.yu@realtek.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=rf@opensource.cirrus.com \
    --cc=shumingf@realtek.com \
    --cc=tiwai@suse.de \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.