Skip to content

Commit e48da7a

Browse files
committed
ASoC: Intel: sof-function-topology-lib: create common helpers
The existing code supports get_function_tplg_files callback for SoundWire machine driver only. Some common sections can be used to extend the support to other machines. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 7a67ee4 commit e48da7a

1 file changed

Lines changed: 72 additions & 40 deletions

File tree

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

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,83 @@ enum tplg_device_id {
2727

2828
#define SOF_INTEL_PLATFORM_NAME_MAX 4
2929

30+
static int get_platform_name(struct snd_soc_card *card,
31+
const struct snd_soc_acpi_mach *mach, char *platform)
32+
{
33+
int ret;
34+
35+
ret = sscanf(mach->sof_tplg_filename, "sof-%3s-*.tplg", platform);
36+
if (ret != 1) {
37+
dev_err(card->dev, "Invalid platform name %s of tplg %s\n",
38+
platform, mach->sof_tplg_filename);
39+
return -EINVAL;
40+
}
41+
42+
return 0;
43+
}
44+
45+
static bool all_tplg_files_exist(struct device *dev, const char ***tplg_files, int tplg_num)
46+
{
47+
const struct firmware *fw;
48+
int ret;
49+
int i;
50+
51+
for (i = 0; i < tplg_num; i++) {
52+
ret = firmware_request_nowarn(&fw, (*tplg_files)[i], dev);
53+
if (!ret) {
54+
release_firmware(fw);
55+
} else {
56+
dev_warn(dev,
57+
"Failed to open topology file: %s, you might need to\n",
58+
(*tplg_files)[i]);
59+
dev_warn(dev,
60+
"download it from https://github.com/thesofproject/sof-bin/\n");
61+
return false;
62+
}
63+
}
64+
65+
return true;
66+
}
67+
68+
static char *get_tplg_filename(struct device *dev, const char *prefix,
69+
const char *platform, const char *tplg_dev_name,
70+
int dai_link_id, int tplg_dev)
71+
{
72+
char *filename = NULL;
73+
/*
74+
* The tplg file naming rule is sof-<platform>-<function>-id<BE id number>.tplg
75+
* where <platform> is only required for the devices that need NHLT blob like DMIC
76+
* as the nhlt blob is platform dependent.
77+
*/
78+
switch (tplg_dev) {
79+
case TPLG_DEVICE_INTEL_PCH_DMIC:
80+
filename = devm_kasprintf(dev, GFP_KERNEL, "%s/sof-%s-%s-id%d.tplg",
81+
prefix, platform, tplg_dev_name, dai_link_id);
82+
break;
83+
default:
84+
filename = devm_kasprintf(dev, GFP_KERNEL, "%s/sof-%s-id%d.tplg",
85+
prefix, tplg_dev_name, dai_link_id);
86+
break;
87+
}
88+
89+
return filename;
90+
}
91+
3092
int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach,
3193
const char *prefix, const char ***tplg_files, bool best_effort)
3294
{
3395
struct snd_soc_acpi_mach_params mach_params = mach->mach_params;
3496
struct snd_soc_dai_link *dai_link;
35-
const struct firmware *fw;
3697
char platform[SOF_INTEL_PLATFORM_NAME_MAX];
3798
unsigned long tplg_mask = 0;
3899
int tplg_num = 0;
39100
int tplg_dev;
40101
int ret;
41102
int i;
42103

43-
ret = sscanf(mach->sof_tplg_filename, "sof-%3s-*.tplg", platform);
44-
if (ret != 1) {
45-
dev_err(card->dev, "Invalid platform name %s of tplg %s\n",
46-
platform, mach->sof_tplg_filename);
47-
return -EINVAL;
48-
}
104+
ret = get_platform_name(card, mach, platform);
105+
if (ret < 0)
106+
return ret;
49107

50108
for_each_card_prelinks(card, i, dai_link) {
51109
char *tplg_dev_name;
@@ -97,25 +155,9 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_
97155

98156
tplg_mask |= BIT(tplg_dev);
99157

100-
/*
101-
* The tplg file naming rule is sof-<platform>-<function>-id<BE id number>.tplg
102-
* where <platform> is only required for the DMIC function as the nhlt blob
103-
* is platform dependent.
104-
*/
105-
switch (tplg_dev) {
106-
case TPLG_DEVICE_INTEL_PCH_DMIC:
107-
(*tplg_files)[tplg_num] = devm_kasprintf(card->dev, GFP_KERNEL,
108-
"%s/sof-%s-%s-id%d.tplg",
109-
prefix, platform,
110-
tplg_dev_name, dai_link->id);
111-
break;
112-
default:
113-
(*tplg_files)[tplg_num] = devm_kasprintf(card->dev, GFP_KERNEL,
114-
"%s/sof-%s-id%d.tplg",
115-
prefix, tplg_dev_name,
116-
dai_link->id);
117-
break;
118-
}
158+
(*tplg_files)[tplg_num] = get_tplg_filename(card->dev, prefix, platform,
159+
tplg_dev_name, dai_link->id,
160+
tplg_dev);
119161
if (!(*tplg_files)[tplg_num])
120162
return -ENOMEM;
121163
tplg_num++;
@@ -124,20 +166,10 @@ int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_
124166
dev_dbg(card->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num);
125167

126168
/* Check presence of sub-topologies */
127-
for (i = 0; i < tplg_num; i++) {
128-
ret = firmware_request_nowarn(&fw, (*tplg_files)[i], card->dev);
129-
if (!ret) {
130-
release_firmware(fw);
131-
} else {
132-
dev_warn(card->dev,
133-
"Failed to open topology file: %s, you might need to\n",
134-
(*tplg_files)[i]);
135-
dev_warn(card->dev,
136-
"download it from https://github.com/thesofproject/sof-bin/\n");
137-
return 0;
138-
}
139-
}
169+
if (all_tplg_files_exist(card->dev, tplg_files, tplg_num))
170+
return tplg_num;
140171

141-
return tplg_num;
172+
/* return 0 to use monolithic topology */
173+
return 0;
142174
}
143175
EXPORT_SYMBOL_GPL(sof_sdw_get_tplg_files);

0 commit comments

Comments
 (0)