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