Skip to content

Commit 38e9310

Browse files
committed
ASoC: Intel: add sof_sdw_get_tplg_files ops
Add sof_sdw_get_tplg_files ops to get sub-topology file names for the sof_sdw card. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 1dfef99 commit 38e9310

3 files changed

Lines changed: 152 additions & 1 deletion

File tree

sound/soc/intel/common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ snd-soc-acpi-intel-match-y := soc-acpi-intel-byt-match.o soc-acpi-intel-cht-matc
1212
soc-acpi-intel-lnl-match.o \
1313
soc-acpi-intel-ptl-match.o \
1414
soc-acpi-intel-hda-match.o \
15-
soc-acpi-intel-sdw-mockup-match.o
15+
soc-acpi-intel-sdw-mockup-match.o sof-function-topology-lib.o
1616

1717
snd-soc-acpi-intel-match-y += soc-acpi-intel-ssp-common.o
1818

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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 <linux/firmware.h>
12+
#include <sound/soc.h>
13+
#include <sound/soc-acpi.h>
14+
#include "sof-function-topology-lib.h"
15+
16+
enum tplg_device_id {
17+
TPLG_DEVICE_SDCA_JACK,
18+
TPLG_DEVICE_SDCA_AMP,
19+
TPLG_DEVICE_SDCA_MIC,
20+
TPLG_DEVICE_INTEL_PCH_DMIC,
21+
TPLG_DEVICE_HDMI,
22+
TPLG_DEVICE_MAX
23+
};
24+
25+
#define SDCA_DEVICE_MASK (BIT(TPLG_DEVICE_SDCA_JACK) | BIT(TPLG_DEVICE_SDCA_AMP) | \
26+
BIT(TPLG_DEVICE_SDCA_MIC))
27+
28+
#define SOF_INTEL_PLATFORM_NAME_MAX 4
29+
30+
int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach,
31+
const char *prefix, const char ***tplg_files)
32+
{
33+
struct snd_soc_acpi_mach_params mach_params = mach->mach_params;
34+
struct snd_soc_dai_link *dai_link;
35+
const struct firmware *fw;
36+
char platform[SOF_INTEL_PLATFORM_NAME_MAX];
37+
unsigned long tplg_mask = 0;
38+
int tplg_num = 0;
39+
int tplg_dev;
40+
int ret;
41+
int i;
42+
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+
}
49+
50+
for_each_card_prelinks(card, i, dai_link) {
51+
char *tplg_dev_name;
52+
53+
dev_dbg(card->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id);
54+
if (strstr(dai_link->name, "SimpleJack")) {
55+
tplg_dev = TPLG_DEVICE_SDCA_JACK;
56+
tplg_dev_name = "sdca-jack";
57+
} else if (strstr(dai_link->name, "SmartAmp")) {
58+
tplg_dev = TPLG_DEVICE_SDCA_AMP;
59+
tplg_dev_name = devm_kasprintf(card->dev, GFP_KERNEL,
60+
"sdca-%damp", dai_link->num_cpus);
61+
if (!tplg_dev_name)
62+
return -ENOMEM;
63+
} else if (strstr(dai_link->name, "SmartMic")) {
64+
tplg_dev = TPLG_DEVICE_SDCA_MIC;
65+
tplg_dev_name = "sdca-mic";
66+
} else if (strstr(dai_link->name, "dmic")) {
67+
switch (mach_params.dmic_num) {
68+
case 2:
69+
tplg_dev_name = "dmic-2ch";
70+
break;
71+
case 4:
72+
tplg_dev_name = "dmic-4ch";
73+
break;
74+
default:
75+
dev_warn(card->dev,
76+
"only -2ch and -4ch are supported for dmic\n");
77+
continue;
78+
}
79+
tplg_dev = TPLG_DEVICE_INTEL_PCH_DMIC;
80+
} else if (strstr(dai_link->name, "iDisp")) {
81+
tplg_dev = TPLG_DEVICE_HDMI;
82+
tplg_dev_name = "hdmi-pcm5";
83+
84+
} else {
85+
/* The dai link is not supported by seperated tplg yet */
86+
dev_dbg(card->dev,
87+
"dai_link %s is not supported by seperated tplg yet\n",
88+
dai_link->name);
89+
return 0;
90+
}
91+
if (tplg_mask & BIT(tplg_dev))
92+
continue;
93+
94+
tplg_mask |= BIT(tplg_dev);
95+
96+
/*
97+
* The tplg file naming rule is sof-<platform>-<function>-id<BE id number>.tplg
98+
* where <platform> is only required for the DMIC function as the nhlt blob
99+
* is platform dependent.
100+
*/
101+
switch (tplg_dev) {
102+
case TPLG_DEVICE_INTEL_PCH_DMIC:
103+
(*tplg_files)[tplg_num] = devm_kasprintf(card->dev, GFP_KERNEL,
104+
"%s/sof-%s-%s-id%d.tplg",
105+
prefix, platform,
106+
tplg_dev_name, dai_link->id);
107+
break;
108+
default:
109+
(*tplg_files)[tplg_num] = devm_kasprintf(card->dev, GFP_KERNEL,
110+
"%s/sof-%s-id%d.tplg",
111+
prefix, tplg_dev_name,
112+
dai_link->id);
113+
break;
114+
}
115+
if (!(*tplg_files)[tplg_num])
116+
return -ENOMEM;
117+
tplg_num++;
118+
}
119+
120+
dev_dbg(card->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num);
121+
122+
/* Check presence of sub-topologies */
123+
for (i = 0; i < tplg_num; i++) {
124+
ret = firmware_request_nowarn(&fw, (*tplg_files)[i], card->dev);
125+
if (!ret) {
126+
release_firmware(fw);
127+
} else {
128+
dev_dbg(card->dev, "Failed to open topology file: %s\n", (*tplg_files)[i]);
129+
return 0;
130+
}
131+
}
132+
133+
return tplg_num;
134+
}
135+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
/* SPDX-License-Identifier: GPL-2.0-only */
3+
/*
4+
* soc-acpi-intel-get-tplg.h - get-tplg-files ops
5+
*
6+
* Copyright (c) 2025, Intel Corporation.
7+
*
8+
*/
9+
10+
#ifndef _SND_SOC_ACPI_INTEL_GET_TPLG_H
11+
#define _SND_SOC_ACPI_INTEL_GET_TPLG_H
12+
13+
int sof_sdw_get_tplg_files(struct snd_soc_card *card, const struct snd_soc_acpi_mach *mach,
14+
const char *prefix, const char ***tplg_files);
15+
16+
#endif

0 commit comments

Comments
 (0)