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