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