Skip to content

Commit 448deb3

Browse files
committed
ASoC: SOF: topology: add get_sof_sdw_tplg_files ops
Add get_sof_sdw_tplg_files ops to generate the topology file names for the "sof-soundwire" card. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent bc6e0a0 commit 448deb3

File tree

4 files changed

+127
-1
lines changed

4 files changed

+127
-1
lines changed

sound/soc/sof/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
snd-sof-y := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
44
control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
5-
fw-file-profile.o debug-dsp-ops.o
5+
fw-file-profile.o debug-dsp-ops.o card-tplg-ops.o
66

77
# IPC implementations
88
ifneq ($(CONFIG_SND_SOC_SOF_IPC3),)

sound/soc/sof/card-tplg-ops.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
//
3+
// This file is provided under a dual BSD/GPLv2 license. When using or
4+
// redistributing this file, you may do so under either license.
5+
//
6+
// Copyright(c) 2025 Intel Corporation.
7+
//
8+
9+
#include <linux/device.h>
10+
#include <linux/errno.h>
11+
#include "sof-priv.h"
12+
#include "topology.h"
13+
14+
enum tplg_device_id {
15+
TPLG_DEVICE_SDCA_JACK,
16+
TPLG_DEVICE_SDCA_AMP,
17+
TPLG_DEVICE_SDCA_MIC,
18+
TPLG_DEVICE_PCH_DMIC,
19+
TPLG_DEVICE_HDMI,
20+
TPLG_DEVICE_MAX
21+
};
22+
23+
#define SDCA_DEVICE_MASK (BIT(TPLG_DEVICE_SDCA_JACK) | BIT(TPLG_DEVICE_SDCA_AMP) | \
24+
BIT(TPLG_DEVICE_SDCA_MIC))
25+
26+
#define SOF_INTEL_PLATFORM_NAME_MAX 4
27+
28+
int get_sof_sdw_tplg_files(struct snd_soc_component *scomp, const char *file, char ***tplg_files)
29+
{
30+
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
31+
struct snd_sof_pdata *sof_pdata = sdev->pdata;
32+
struct snd_soc_dai_link *dai_link;
33+
char platform[SOF_INTEL_PLATFORM_NAME_MAX];
34+
unsigned long tplg_mask = 0;
35+
int tplg_num = 0;
36+
int tplg_dev;
37+
int ret;
38+
int i;
39+
40+
if (sdev->pdata->ipc_type == SOF_IPC_TYPE_3)
41+
return 0;
42+
43+
ret = sscanf(sof_pdata->tplg_filename, "sof-%3s-*.tplg", platform);
44+
if (ret != 1)
45+
return 0;
46+
47+
/* tplg_num is always less or equal to dai_link numbers */
48+
*tplg_files = kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL);
49+
if (!(*tplg_files))
50+
return -ENOMEM;
51+
52+
for_each_card_prelinks(scomp->card, i, dai_link) {
53+
char *tplg_device;
54+
55+
dev_dbg(scomp->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id);
56+
if (strstr(dai_link->name, "SimpleJack")) {
57+
tplg_dev = TPLG_DEVICE_SDCA_JACK;
58+
tplg_device = "sdca-jack";
59+
} else if (strstr(dai_link->name, "SmartAmp")) {
60+
tplg_dev = TPLG_DEVICE_SDCA_AMP;
61+
tplg_device = devm_kasprintf(sdev->dev, GFP_KERNEL,
62+
"sdca-%damp", dai_link->num_cpus);
63+
if (!tplg_device)
64+
return -ENOMEM;
65+
} else if (strstr(dai_link->name, "SmartMic")) {
66+
tplg_dev = TPLG_DEVICE_SDCA_MIC;
67+
tplg_device = "sdca-mic";
68+
} else if (strstr(dai_link->name, "dmic")) {
69+
if (strstr(file, "-2ch")) {
70+
tplg_device = "dmic-2ch";
71+
} else if (strstr(file, "-4ch")) {
72+
tplg_device = "dmic-4ch";
73+
} else {
74+
dev_warn(scomp->dev,
75+
"only -2ch and -4ch are supported for dmic\n");
76+
continue;
77+
}
78+
tplg_dev = TPLG_DEVICE_PCH_DMIC;
79+
} else if (strstr(dai_link->name, "iDisp")) {
80+
tplg_dev = TPLG_DEVICE_HDMI;
81+
tplg_device = "hdmi-pcm5";
82+
83+
} else {
84+
/* The dai link is not supported by sperated tplg yet */
85+
dev_dbg(scomp->dev,
86+
"dai_link %s is not supported by sperated tplg yet, Fail back to %s\n",
87+
dai_link->name, file);
88+
return 0;
89+
}
90+
if (tplg_mask & BIT(tplg_dev))
91+
continue;
92+
93+
tplg_mask |= BIT(tplg_dev);
94+
95+
/*
96+
* The tplg file naming rule is sof-<platform>-<function>-id<BE id number>.tplg
97+
* where <platform> is only required for the DMIC function as the nhlt blob
98+
* is platform depentent.
99+
*/
100+
switch (tplg_dev) {
101+
case TPLG_DEVICE_PCH_DMIC:
102+
(*tplg_files)[tplg_num] = kasprintf(GFP_KERNEL, "%s/sof-%s-%s-id%d.tplg",
103+
sof_pdata->tplg_filename_prefix,
104+
platform, tplg_device, dai_link->id);
105+
break;
106+
default:
107+
(*tplg_files)[tplg_num] = kasprintf(GFP_KERNEL, "%s/sof-%s-id%d.tplg",
108+
sof_pdata->tplg_filename_prefix,
109+
tplg_device, dai_link->id);
110+
break;
111+
}
112+
if (!(*tplg_files)[tplg_num])
113+
return -ENOMEM;
114+
tplg_num++;
115+
}
116+
117+
dev_dbg(scomp->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num);
118+
return tplg_num;
119+
}
120+

sound/soc/sof/topology.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,10 @@ static const struct snd_soc_tplg_ops sof_dspless_tplg_ops = {
24762476
};
24772477

24782478
static const struct card_tplg_ops card_ops[] = {
2479+
{
2480+
.card_name = "sof-soundwire",
2481+
.get_tplg_files = get_sof_sdw_tplg_files,
2482+
},
24792483
};
24802484

24812485
int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)

sound/soc/sof/topology.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ struct card_tplg_ops {
1515
char ***tplg_files);
1616
};
1717

18+
int get_sof_sdw_tplg_files(struct snd_soc_component *scomp, const char *file, char ***tplg_files);
19+
1820
#endif

0 commit comments

Comments
 (0)