Skip to content

Commit e359f89

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 34e06c9 commit e359f89

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