xref: /linux/sound/soc/amd/acp-config.c (revision c2dfe29f30d8850af324449f416491b171af19aa)
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, "M1020"),
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, "M1040"),
143 				},
144 			},
145 			{}
146 		},
147 	},
148 };
149 
150 static int snd_amd_acp_acpi_find_config(struct pci_dev *pci)
151 {
152 	const union acpi_object *obj;
153 	int acp_flag = FLAG_AMD_LEGACY_ONLY_DMIC;
154 
155 	if (!acpi_dev_get_property(ACPI_COMPANION(&pci->dev), "acp-audio-config-flag",
156 				   ACPI_TYPE_INTEGER, &obj))
157 		acp_flag = obj->integer.value;
158 
159 	return acp_flag;
160 }
161 
162 int snd_amd_acp_find_config(struct pci_dev *pci)
163 {
164 	const struct config_entry *table = config_table;
165 	u16 device = pci->device;
166 	int i;
167 
168 	/* Do not enable FLAGS on older platforms with Rev Id zero
169 	 * For platforms which has ACP 7.0 or higher, read the acp
170 	 * config flag from BIOS ACPI table and for older platforms
171 	 * read it from DMI tables.
172 	 */
173 	if (!pci->revision)
174 		return 0;
175 	else if (pci->revision >= ACP_7_0_REV)
176 		return snd_amd_acp_acpi_find_config(pci);
177 
178 	for (i = 0; i < ARRAY_SIZE(config_table); i++, table++) {
179 		if (table->device != device)
180 			continue;
181 		if (table->dmi_table && !dmi_check_system(table->dmi_table))
182 			continue;
183 		acp_quirk_data = table->flags;
184 		return table->flags;
185 	}
186 
187 	return 0;
188 }
189 EXPORT_SYMBOL(snd_amd_acp_find_config);
190 
191 static struct snd_soc_acpi_codecs amp_rt1019 = {
192 	.num_codecs = 1,
193 	.codecs = {"10EC1019"}
194 };
195 
196 static struct snd_soc_acpi_codecs amp_max = {
197 	.num_codecs = 1,
198 	.codecs = {"MX98360A"}
199 };
200 
201 static struct snd_soc_acpi_codecs amp_max98388 = {
202 	.num_codecs = 1,
203 	.codecs = {"ADS8388"}
204 };
205 
206 struct snd_soc_acpi_mach snd_soc_acpi_amd_sof_machines[] = {
207 	{
208 		.id = "10EC5682",
209 		.drv_name = "rt5682-rt1019",
210 		.pdata = (void *)&acp_quirk_data,
211 		.machine_quirk = snd_soc_acpi_codec_list,
212 		.quirk_data = &amp_rt1019,
213 		.fw_filename = "sof-rn.ri",
214 		.sof_tplg_filename = "sof-rn-rt5682-rt1019.tplg",
215 	},
216 	{
217 		.id = "10EC5682",
218 		.drv_name = "rt5682-max",
219 		.pdata = (void *)&acp_quirk_data,
220 		.machine_quirk = snd_soc_acpi_codec_list,
221 		.quirk_data = &amp_max,
222 		.fw_filename = "sof-rn.ri",
223 		.sof_tplg_filename = "sof-rn-rt5682-max98360.tplg",
224 	},
225 	{
226 		.id = "RTL5682",
227 		.drv_name = "rt5682s-max",
228 		.pdata = (void *)&acp_quirk_data,
229 		.machine_quirk = snd_soc_acpi_codec_list,
230 		.quirk_data = &amp_max,
231 		.fw_filename = "sof-rn.ri",
232 		.sof_tplg_filename = "sof-rn-rt5682-max98360.tplg",
233 	},
234 	{
235 		.id = "RTL5682",
236 		.drv_name = "rt5682s-rt1019",
237 		.pdata = (void *)&acp_quirk_data,
238 		.machine_quirk = snd_soc_acpi_codec_list,
239 		.quirk_data = &amp_rt1019,
240 		.fw_filename = "sof-rn.ri",
241 		.sof_tplg_filename = "sof-rn-rt5682-rt1019.tplg",
242 	},
243 	{
244 		.id = "AMDI1019",
245 		.drv_name = "renoir-dsp",
246 		.pdata = (void *)&acp_quirk_data,
247 		.fw_filename = "sof-rn.ri",
248 		.sof_tplg_filename = "sof-acp.tplg",
249 	},
250 	{},
251 };
252 EXPORT_SYMBOL(snd_soc_acpi_amd_sof_machines);
253 
254 struct snd_soc_acpi_mach snd_soc_acpi_amd_vangogh_sof_machines[] = {
255 	{
256 		.id = "NVTN2020",
257 		.drv_name = "nau8821-max",
258 		.pdata = &acp_quirk_data,
259 		.machine_quirk = snd_soc_acpi_codec_list,
260 		.quirk_data = &amp_max98388,
261 		.fw_filename = "sof-vangogh.ri",
262 		.sof_tplg_filename = "sof-vangogh-nau8821-max.tplg",
263 	},
264 	{},
265 };
266 EXPORT_SYMBOL(snd_soc_acpi_amd_vangogh_sof_machines);
267 
268 struct snd_soc_acpi_mach snd_soc_acpi_amd_rmb_sof_machines[] = {
269 	{
270 		.id = "AMDI1019",
271 		.drv_name = "rmb-dsp",
272 		.pdata = &acp_quirk_data,
273 		.fw_filename = "sof-rmb.ri",
274 		.sof_tplg_filename = "sof-acp-rmb.tplg",
275 	},
276 	{
277 		.id = "10508825",
278 		.drv_name = "nau8825-max",
279 		.pdata = &acp_quirk_data,
280 		.machine_quirk = snd_soc_acpi_codec_list,
281 		.quirk_data = &amp_max,
282 		.fw_filename = "sof-rmb.ri",
283 		.sof_tplg_filename = "sof-rmb-nau8825-max98360.tplg",
284 	},
285 	{
286 		.id = "RTL5682",
287 		.drv_name = "rt5682s-hs-rt1019",
288 		.pdata = &acp_quirk_data,
289 		.machine_quirk = snd_soc_acpi_codec_list,
290 		.quirk_data = &amp_rt1019,
291 		.fw_filename = "sof-rmb.ri",
292 		.sof_tplg_filename = "sof-rmb-rt5682s-rt1019.tplg",
293 	},
294 	{},
295 };
296 EXPORT_SYMBOL(snd_soc_acpi_amd_rmb_sof_machines);
297 
298 struct snd_soc_acpi_mach snd_soc_acpi_amd_acp63_sof_machines[] = {
299 	{
300 		.id = "AMDI1019",
301 		.drv_name = "acp63-dsp",
302 		.pdata = &acp_quirk_data,
303 		.fw_filename = "sof-acp_6_3.ri",
304 		.sof_tplg_filename = "sof-acp_6_3.tplg",
305 	},
306 	{},
307 };
308 EXPORT_SYMBOL(snd_soc_acpi_amd_acp63_sof_machines);
309 
310 MODULE_LICENSE("Dual BSD/GPL");
311