diff --git a/include/sound/soc-acpi.h b/include/sound/soc-acpi.h index 2ee303b791dc84..2950364d1dd87e 100644 --- a/include/sound/soc-acpi.h +++ b/include/sound/soc-acpi.h @@ -74,6 +74,8 @@ static inline struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg) * @subsystem_id_set: true if a value has been written to * subsystem_vendor and subsystem_device. * @bt_link_mask: BT offload link enabled on the board + * @tplg_platform: platform name used in the function topology file names, + * when it can't be taken from the topology file name */ struct snd_soc_acpi_mach_params { u32 acpi_ipc_irq_index; @@ -90,6 +92,7 @@ struct snd_soc_acpi_mach_params { unsigned short subsystem_rev; bool subsystem_id_set; u32 bt_link_mask; + const char *tplg_platform; }; /** diff --git a/sound/soc/intel/common/soc-acpi-intel-hda-match.c b/sound/soc/intel/common/soc-acpi-intel-hda-match.c index e93336e27bebd7..cd43ea8222a8b2 100644 --- a/sound/soc/intel/common/soc-acpi-intel-hda-match.c +++ b/sound/soc/intel/common/soc-acpi-intel-hda-match.c @@ -8,6 +8,7 @@ #include #include +#include "sof-function-topology-lib.h" struct snd_soc_acpi_mach snd_soc_acpi_intel_hda_machines[] = { { @@ -15,6 +16,7 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_hda_machines[] = { .drv_name = "skl_hda_dsp_generic", .sof_tplg_filename = "sof-hda-generic", /* the tplg suffix is added at run time */ .tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER, + .get_function_tplg_files = sof_hda_get_tplg_files, }, {}, }; diff --git a/sound/soc/intel/common/sof-function-topology-lib.c b/sound/soc/intel/common/sof-function-topology-lib.c index 57e089f8e721dc..15e7308badeee6 100644 --- a/sound/soc/intel/common/sof-function-topology-lib.c +++ b/sound/soc/intel/common/sof-function-topology-lib.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "sof-function-topology-lib.h" @@ -24,6 +25,7 @@ enum tplg_device_id { TPLG_DEVICE_SSP_BT, TPLG_DEVICE_SSP_HDMI_IN, TPLG_DEVICE_LOOPBACK_VIRTUAL, + TPLG_DEVICE_HDA, TPLG_DEVICE_MAX }; @@ -37,6 +39,12 @@ static int get_platform_name(struct snd_soc_card *card, { int ret; + if (mach->mach_params.tplg_platform) { + strscpy(platform, mach->mach_params.tplg_platform, + SOF_INTEL_PLATFORM_NAME_MAX); + return 0; + } + ret = sscanf(mach->sof_tplg_filename, "sof-%3s-*.tplg", platform); if (ret != 1) { dev_err(card->dev, "Invalid platform name of tplg %s\n", @@ -332,3 +340,104 @@ int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ return tplg_num; } EXPORT_SYMBOL_GPL(sof_i2s_get_tplg_files); + +/* + * The dai links are created by the skl_hda_dsp_generic machine driver: + * iDisp - HDMI + * Analog Playback and Capture - HDA analog codec + * Digital Playback and Capture - HDA digital codec + * dmic01/dmic16k - PCH DMIC + * SSP-BT - BT offload + * SSP-HDMI - HDMI IN, two links in one tplg + */ +int sof_hda_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach, + const char *prefix, const char ***tplg_files, bool best_effort) +{ + struct snd_soc_acpi_mach_params mach_params = mach->mach_params; + struct snd_soc_dai_link *dai_link; + char platform[SOF_INTEL_PLATFORM_NAME_MAX]; + unsigned long tplg_mask = 0; + u16 hdmi_in_mask = 0; + int tplg_num = 0; + char *tplg_file; + int tplg_dev; + int ret; + int i; + + ret = get_platform_name(card, mach, platform); + if (ret < 0) + return ret; + + for_each_card_prelinks(card, i, dai_link) { + char *tplg_dev_name; + + dev_dbg(card->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id); + if (strstr(dai_link->name, "iDisp")) { + tplg_dev = TPLG_DEVICE_HDMI; + tplg_dev_name = "hdmi-pcm3"; + } else if (!strcmp(dai_link->name, "Analog Playback and Capture") || + !strcmp(dai_link->name, "Digital Playback and Capture")) { + /* + * The analog and digital dai links share one tplg, named + * after the id of the first one, the analog dai link. + */ + tplg_dev = TPLG_DEVICE_HDA; + tplg_dev_name = "hda"; + } else if (strstr(dai_link->name, "dmic")) { + /* + * The machine driver creates the DMIC dai links even + * if there is no DMIC, no tplg is needed for them. + */ + if (!mach_params.dmic_num) + continue; + + if (get_dmic_tplg_dev(card->dev, mach_params.dmic_num, + &tplg_dev, &tplg_dev_name) < 0) { + /* no function topology for this number of dmics */ + if (best_effort) + continue; + + return 0; + } + } else if (strstr(dai_link->name, "SSP")) { + if (get_ssp_tplg_dev(card->dev, dai_link, &hdmi_in_mask, + &tplg_dev, &tplg_dev_name) < 0) + continue; + } else { + /* The dai link is not supported by separated tplg yet */ + dev_dbg(card->dev, + "dai_link %s is not supported by separated tplg yet\n", + dai_link->name); + if (best_effort) + continue; + + return 0; + } + if (tplg_mask & BIT(tplg_dev)) + continue; + + tplg_file = get_tplg_filename(card->dev, prefix, platform, tplg_dev_name, + dai_link->id, tplg_dev); + if (!tplg_file) + return -ENOMEM; + + /* Check presence of sub-topologies */ + if (!tplg_files_exist(card->dev, tplg_file)) { + devm_kfree(card->dev, tplg_file); + if (best_effort) + continue; + + return 0; + } + + tplg_mask |= BIT(tplg_dev); + + (*tplg_files)[tplg_num] = tplg_file; + tplg_num++; + } + + dev_dbg(card->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num); + + return tplg_num; +} +EXPORT_SYMBOL_GPL(sof_hda_get_tplg_files); diff --git a/sound/soc/intel/common/sof-function-topology-lib.h b/sound/soc/intel/common/sof-function-topology-lib.h index 9755e97709685e..74af7f71414b6b 100644 --- a/sound/soc/intel/common/sof-function-topology-lib.h +++ b/sound/soc/intel/common/sof-function-topology-lib.h @@ -15,4 +15,7 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_ int sof_i2s_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach, const char *prefix, const char ***tplg_files, bool best_effort); +int sof_hda_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach, + const char *prefix, const char ***tplg_files, bool best_effort); + #endif diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index 45e968fb19104b..fa4b84aa435b02 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -1047,6 +1047,7 @@ static void hda_generic_machine_select(struct snd_sof_dev *sdev, struct snd_soc_acpi_mach_params *mach_params; struct snd_soc_acpi_mach *hda_mach; struct snd_sof_pdata *pdata = sdev->pdata; + const struct sof_intel_dsp_desc *chip = get_chip_info(pdata); const char *tplg_filename; int codec_num = 0; int i; @@ -1092,6 +1093,14 @@ static void hda_generic_machine_select(struct snd_sof_dev *sdev, dev_info(bus->dev, "using HDA machine driver %s now\n", hda_mach->drv_name); + /* + * The platform name is needed to form the function topology + * file names, but sof_tplg_filename of the match table is + * platform independent and is kept for the monolithic + * topology fallback. + */ + hda_mach->mach_params.tplg_platform = chip->platform; + /* * topology: use the info from hda_machines since tplg file name * is not overwritten