Skip to content

Commit b6f4b09

Browse files
committed
ASoC: Intel: sof-function-topology-lib: add get_function_topology for I2S machines
Add sof_i2s_get_tplg_files() callback for Intel SOF I2S machines. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 4d665f0 commit b6f4b09

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

sound/soc/intel/common/sof-function-topology-lib.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,115 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_
241241
return 0;
242242
}
243243
EXPORT_SYMBOL_GPL(sof_sdw_get_tplg_files);
244+
245+
int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach,
246+
const char *prefix, const char ***tplg_files, bool best_effort)
247+
{
248+
struct snd_soc_acpi_mach_params mach_params = mach->mach_params;
249+
struct snd_soc_dai_link *dai_link;
250+
char platform[SOF_INTEL_PLATFORM_NAME_MAX];
251+
unsigned long tplg_mask = 0;
252+
u16 hdmi_in_mask = 0;
253+
int tplg_num = 0;
254+
int tplg_dev;
255+
int ret;
256+
int i;
257+
258+
ret = get_platform_name(card, mach, platform);
259+
if (ret < 0)
260+
return ret;
261+
262+
for_each_card_prelinks(card, i, dai_link) {
263+
char *tplg_dev_name;
264+
265+
dev_dbg(card->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id);
266+
if (strstr(dai_link->name, "SSP")) {
267+
unsigned int ssp_port;
268+
269+
if (sscanf(dai_link->name, "SSP%d", &ssp_port) != 1) {
270+
dev_err(card->dev, "Invalid SSP port %d\n", ssp_port);
271+
return -EINVAL;
272+
}
273+
if (strstr(dai_link->name, "Codec")) {
274+
/*
275+
* Assume DAI link 0 is jack which is true in all existing
276+
* machine driver
277+
*/
278+
if (dai_link->id == 0) {
279+
tplg_dev = TPLG_DEVICE_SSP_JACK;
280+
tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL,
281+
"ssp%d-jack", ssp_port);
282+
} else {
283+
tplg_dev = TPLG_DEVICE_SSP_AMP;
284+
tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL,
285+
"ssp%d-amp", ssp_port);
286+
}
287+
} else if (strstr(dai_link->name, "BT")) {
288+
tplg_dev = TPLG_DEVICE_SSP_BT;
289+
tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL,
290+
"ssp%d-bt", ssp_port);
291+
} else if (strstr(dai_link->name, "HDMI")) {
292+
hdmi_in_mask |= BIT(ssp_port);
293+
/* The number of HDMI in dai link is always 2 right now */
294+
if (hweight16(hdmi_in_mask) != 2)
295+
continue;
296+
297+
tplg_dev = TPLG_DEVICE_SSP_HDMI_IN;
298+
tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL,
299+
"ssp%x-hdmiin", hdmi_in_mask);
300+
} else {
301+
dev_warn(card->dev,
302+
"unsupported SSP link %s\n", dai_link->name);
303+
continue;
304+
}
305+
} else if (strstr(dai_link->name, "dmic")) {
306+
switch (mach_params.dmic_num) {
307+
case 2:
308+
tplg_dev_name = "dmic-2ch";
309+
break;
310+
case 4:
311+
tplg_dev_name = "dmic-4ch";
312+
break;
313+
default:
314+
dev_warn(card->dev,
315+
"unsupported number of dmics: %d\n",
316+
mach_params.dmic_num);
317+
continue;
318+
}
319+
tplg_dev = TPLG_DEVICE_INTEL_PCH_DMIC;
320+
} else if (strstr(dai_link->name, "iDisp")) {
321+
tplg_dev = TPLG_DEVICE_HDMI;
322+
tplg_dev_name = "hdmi-pcm5";
323+
} else {
324+
/* The dai link is not supported by separated tplg yet */
325+
dev_dbg(card->dev,
326+
"dai_link %s is not supported by separated tplg yet\n",
327+
dai_link->name);
328+
if (best_effort)
329+
continue;
330+
331+
return 0;
332+
}
333+
if (tplg_mask & BIT(tplg_dev))
334+
continue;
335+
336+
tplg_mask |= BIT(tplg_dev);
337+
338+
(*tplg_files)[tplg_num] = get_tplg_filename(card->dev, prefix, platform,
339+
tplg_dev_name, dai_link->id,
340+
tplg_dev);
341+
if (!(*tplg_files)[tplg_num])
342+
return -ENOMEM;
343+
tplg_num++;
344+
}
345+
346+
dev_dbg(card->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num);
347+
348+
/* Check presence of sub-topologies */
349+
if (all_tplg_files_exist(card->dev, tplg_files, tplg_num))
350+
return tplg_num;
351+
352+
/* return 0 to use monolithic topology */
353+
return 0;
354+
}
355+
EXPORT_SYMBOL_GPL(sof_i2s_get_tplg_files);

sound/soc/intel/common/sof-function-topology-lib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach,
1313
const char *prefix, const char ***tplg_files, bool best_effort);
1414

15+
int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach,
16+
const char *prefix, const char ***tplg_files, bool best_effort);
17+
1518
#endif

0 commit comments

Comments
 (0)