xref: /linux/sound/soc/amd/acp-config.c (revision 4e273bca232ec71bbf072f10f7d395a28e85e4e1)
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) 2021, 2023 Advanced Micro Devices, Inc.
7 //
8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
9 //
10 
11 /* ACP machine configuration module */
12 
13 #include <linux/acpi.h>
14 #include <linux/bits.h>
15 #include <linux/dmi.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 
19 #include "../sof/amd/acp.h"
20 #include "mach-config.h"
21 
22 #define ACP_7_0_REV	0x70
23 
24 static int acp_quirk_data;
25 
26 static const struct dmi_system_id acp70_acpi_flag_override_table[] = {
27 	{
28 		.matches = {
29 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
30 			DMI_MATCH(DMI_PRODUCT_NAME, "HN7306EA"),
31 		},
32 	},
33 	{
34 		/* ASUS Zenbook S16 UM5606GA (Strix Point, ACP 7.0) */
35 		.matches = {
36 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
37 			DMI_MATCH(DMI_PRODUCT_NAME, "Zenbook S16 UM5606GA"),
38 		},
39 	},
40 	{}
41 };
42 
43 static const struct config_entry config_table[] = {
44 	{
45 		.flags = FLAG_AMD_SOF,
46 		.device = ACP_PCI_DEV_ID,
47 		.dmi_table = (const struct dmi_system_id []) {
48 			{
49 				.matches = {
50 					DMI_MATCH(DMI_SYS_VENDOR, "AMD"),
51 					DMI_MATCH(DMI_PRODUCT_NAME, "Majolica-CZN"),
52 				},
53 			},
54 			{}
55 		},
56 	},
57 	{
58 		.flags = FLAG_AMD_SOF,
59 		.device = ACP_PCI_DEV_ID,
60 		.dmi_table = (const struct dmi_system_id []) {
61 			{
62 				.matches = {
63 					DMI_MATCH(DMI_SYS_VENDOR, "Google"),
64 				},
65 			},
66 			{}
67 		},
68 	},
69 	{
70 		.flags = FLAG_AMD_LEGACY,
71 		.device = ACP_PCI_DEV_ID,
72 		.dmi_table = (const struct dmi_system_id []) {
73 			{
74 				.matches = {
75 					DMI_MATCH(DMI_SYS_VENDOR, "Valve"),
76 					DMI_MATCH(DMI_PRODUCT_NAME, "Jupiter"),
77 				},
78 			},
79 			{}
80 		},
81 	},
82 	{
83 		.flags = FLAG_AMD_SOF,
84 		.device = ACP_PCI_DEV_ID,
85 		.dmi_table = (const struct dmi_system_id []) {
86 			{
87 				.matches = {
88 					DMI_MATCH(DMI_SYS_VENDOR, "Valve"),
89 					DMI_MATCH(DMI_PRODUCT_NAME, "Galileo"),
90 				},
91 			},
92 			{}
93 		},
94 	},
95 	{
96 		.flags = FLAG_AMD_LEGACY,
97 		.device = ACP_PCI_DEV_ID,
98 		.dmi_table = (const struct dmi_system_id []) {
99 			{
100 				.matches = {
101 					DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
102 					DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXXW"),
103 					DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
104 				},
105 			},
106 			{}
107 		},
108 	},
109 	{
110 		.flags = FLAG_AMD_LEGACY,
111 		.device = ACP_PCI_DEV_ID,
112 		.dmi_table = (const struct dmi_system_id []) {
113 			{
114 				.matches = {
115 					DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
116 					DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXX9"),
117 					DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
118 				},
119 			},
120 			{}
121 		},
122 	},
123 	{
124 		.flags = FLAG_AMD_LEGACY,
125 		.device = ACP_PCI_DEV_ID,
126 		.dmi_table = (const struct dmi_system_id []) {
127 			{
128 				.matches = {
129 					DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
130 					DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "BOM-WXX9"),
131 					DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
132 				},
133 			},
134 			{}
135 		},
136 	},
137 	{
138 		.flags = FLAG_AMD_LEGACY,
139 		.device = ACP_PCI_DEV_ID,
140 		.dmi_table = (const struct dmi_system_id []) {
141 			{
142 				.matches = {
143 					DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
144 					DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"),
145 					DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
146 				},
147 			},
148 			{}
149 		},
150 	},
151 	{
152 		.flags = FLAG_AMD_LEGACY,
153 		.device = ACP_PCI_DEV_ID,
154 		.dmi_table = (const struct dmi_system_id []) {
155 			{
156 				.matches = {
157 					DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
158 					DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"),
159 					DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1020"),
160 				},
161 			},
162 			{}
163 		},
164 	},
165 	{
166 		.flags = FLAG_AMD_LEGACY,
167 		.device = ACP_PCI_DEV_ID,
168 		.dmi_table = (const struct dmi_system_id []) {
169 			{
170 				.matches = {
171 					DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
172 					DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"),
173 					DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1040"),
174 				},
175 			},
176 			{}
177 		},
178 	},
179 };
180 
181 static int snd_amd_acp_acpi_find_config(struct pci_dev *pci)
182 {
183 	const union acpi_object *obj;
184 	int acp_flag = FLAG_AMD_LEGACY_ONLY_DMIC;
185 
186 	if (!acpi_dev_get_property(ACPI_COMPANION(&pci->dev), "acp-audio-config-flag",
187 				   ACPI_TYPE_INTEGER, &obj))
188 		acp_flag = obj->integer.value;
189 
190 	return acp_flag;
191 }
192 
193 int snd_amd_acp_find_config(struct pci_dev *pci)
194 {
195 	const struct config_entry *table = config_table;
196 	u16 device = pci->device;
197 	int i;
198 
199 	/* Do not enable FLAGS on older platforms with Rev Id zero
200 	 * For platforms which has ACP 7.0 or higher, read the acp
201 	 * config flag from BIOS ACPI table and for older platforms
202 	 * read it from DMI tables.
203 	 */
204 	if (!pci->revision)
205 		return 0;
206 	else if (pci->revision >= ACP_7_0_REV) {
207 		if (dmi_check_system(acp70_acpi_flag_override_table))
208 			return 0;
209 		return snd_amd_acp_acpi_find_config(pci);
210 	}
211 
212 	for (i = 0; i < ARRAY_SIZE(config_table); i++, table++) {
213 		if (table->device != device)
214 			continue;
215 		if (table->dmi_table && !dmi_check_system(table->dmi_table))
216 			continue;
217 		acp_quirk_data = table->flags;
218 		return table->flags;
219 	}
220 
221 	return 0;
222 }
223 EXPORT_SYMBOL(snd_amd_acp_find_config);
224 
225 static struct snd_soc_acpi_codecs amp_rt1019 = {
226 	.num_codecs = 1,
227 	.codecs = {"10EC1019"}
228 };
229 
230 static struct snd_soc_acpi_codecs amp_max = {
231 	.num_codecs = 1,
232 	.codecs = {"MX98360A"}
233 };
234 
235 static struct snd_soc_acpi_codecs amp_max98388 = {
236 	.num_codecs = 1,
237 	.codecs = {"ADS8388"}
238 };
239 
240 struct snd_soc_acpi_mach snd_soc_acpi_amd_sof_machines[] = {
241 	{
242 		.id = "10EC5682",
243 		.drv_name = "rt5682-rt1019",
244 		.pdata = (void *)&acp_quirk_data,
245 		.machine_quirk = snd_soc_acpi_codec_list,
246 		.quirk_data = &amp_rt1019,
247 		.fw_filename = "sof-rn.ri",
248 		.sof_tplg_filename = "sof-rn-rt5682-rt1019.tplg",
249 	},
250 	{
251 		.id = "10EC5682",
252 		.drv_name = "rt5682-max",
253 		.pdata = (void *)&acp_quirk_data,
254 		.machine_quirk = snd_soc_acpi_codec_list,
255 		.quirk_data = &amp_max,
256 		.fw_filename = "sof-rn.ri",
257 		.sof_tplg_filename = "sof-rn-rt5682-max98360.tplg",
258 	},
259 	{
260 		.id = "RTL5682",
261 		.drv_name = "rt5682s-max",
262 		.pdata = (void *)&acp_quirk_data,
263 		.machine_quirk = snd_soc_acpi_codec_list,
264 		.quirk_data = &amp_max,
265 		.fw_filename = "sof-rn.ri",
266 		.sof_tplg_filename = "sof-rn-rt5682-max98360.tplg",
267 	},
268 	{
269 		.id = "RTL5682",
270 		.drv_name = "rt5682s-rt1019",
271 		.pdata = (void *)&acp_quirk_data,
272 		.machine_quirk = snd_soc_acpi_codec_list,
273 		.quirk_data = &amp_rt1019,
274 		.fw_filename = "sof-rn.ri",
275 		.sof_tplg_filename = "sof-rn-rt5682-rt1019.tplg",
276 	},
277 	{
278 		.id = "AMDI1019",
279 		.drv_name = "renoir-dsp",
280 		.pdata = (void *)&acp_quirk_data,
281 		.fw_filename = "sof-rn.ri",
282 		.sof_tplg_filename = "sof-acp.tplg",
283 	},
284 	{},
285 };
286 EXPORT_SYMBOL(snd_soc_acpi_amd_sof_machines);
287 
288 struct snd_soc_acpi_mach snd_soc_acpi_amd_vangogh_sof_machines[] = {
289 	{
290 		.id = "NVTN2020",
291 		.drv_name = "nau8821-max",
292 		.pdata = &acp_quirk_data,
293 		.machine_quirk = snd_soc_acpi_codec_list,
294 		.quirk_data = &amp_max98388,
295 		.fw_filename = "sof-vangogh.ri",
296 		.sof_tplg_filename = "sof-vangogh-nau8821-max.tplg",
297 	},
298 	{},
299 };
300 EXPORT_SYMBOL(snd_soc_acpi_amd_vangogh_sof_machines);
301 
302 struct snd_soc_acpi_mach snd_soc_acpi_amd_rmb_sof_machines[] = {
303 	{
304 		.id = "AMDI1019",
305 		.drv_name = "rmb-dsp",
306 		.pdata = &acp_quirk_data,
307 		.fw_filename = "sof-rmb.ri",
308 		.sof_tplg_filename = "sof-acp-rmb.tplg",
309 	},
310 	{
311 		.id = "10508825",
312 		.drv_name = "nau8825-max",
313 		.pdata = &acp_quirk_data,
314 		.machine_quirk = snd_soc_acpi_codec_list,
315 		.quirk_data = &amp_max,
316 		.fw_filename = "sof-rmb.ri",
317 		.sof_tplg_filename = "sof-rmb-nau8825-max98360.tplg",
318 	},
319 	{
320 		.id = "RTL5682",
321 		.drv_name = "rt5682s-hs-rt1019",
322 		.pdata = &acp_quirk_data,
323 		.machine_quirk = snd_soc_acpi_codec_list,
324 		.quirk_data = &amp_rt1019,
325 		.fw_filename = "sof-rmb.ri",
326 		.sof_tplg_filename = "sof-rmb-rt5682s-rt1019.tplg",
327 	},
328 	{},
329 };
330 EXPORT_SYMBOL(snd_soc_acpi_amd_rmb_sof_machines);
331 
332 struct snd_soc_acpi_mach snd_soc_acpi_amd_acp63_sof_machines[] = {
333 	{
334 		.id = "AMDI1019",
335 		.drv_name = "acp63-dsp",
336 		.pdata = &acp_quirk_data,
337 		.fw_filename = "sof-acp_6_3.ri",
338 		.sof_tplg_filename = "sof-acp_6_3.tplg",
339 	},
340 	{},
341 };
342 EXPORT_SYMBOL(snd_soc_acpi_amd_acp63_sof_machines);
343 
344 struct snd_soc_acpi_mach snd_soc_acpi_amd_acp70_sof_machines[] = {
345 	{
346 		.id = "AMDI1010",
347 		.drv_name = "acp70-dsp",
348 		.pdata = &acp_quirk_data,
349 		.fw_filename = "sof-acp_7_0.ri",
350 		.sof_tplg_filename = "sof-acp_7_0.tplg",
351 	},
352 	{},
353 };
354 EXPORT_SYMBOL(snd_soc_acpi_amd_acp70_sof_machines);
355 
356 MODULE_DESCRIPTION("AMD ACP Machine Configuration Module");
357 MODULE_LICENSE("Dual BSD/GPL");
358