1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * soc-acpi-intel-cht-match.c - tables and support for CHT ACPI enumeration.
4  *
5  * Copyright (c) 2017, Intel Corporation.
6  */
7 
8 #include <linux/dmi.h>
9 #include <sound/soc-acpi.h>
10 #include <sound/soc-acpi-intel-match.h>
11 
12 static unsigned long cht_machine_id;
13 
14 #define CHT_SURFACE_MACH 1
15 
16 static int cht_surface_quirk_cb(const struct dmi_system_id *id)
17 {
18 	cht_machine_id = CHT_SURFACE_MACH;
19 	return 1;
20 }
21 
22 static const struct dmi_system_id cht_table[] = {
23 	{
24 		.callback = cht_surface_quirk_cb,
25 		.matches = {
26 			DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
27 			DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
28 		},
29 	},
30 	{ }
31 };
32 
33 static struct snd_soc_acpi_mach cht_surface_mach = {
34 	.id = "10EC5640",
35 	.drv_name = "cht-bsw-rt5645",
36 	.fw_filename = "intel/fw_sst_22a8.bin",
37 	.board = "cht-bsw",
38 	.sof_tplg_filename = "sof-cht-rt5645.tplg",
39 };
40 
41 static struct snd_soc_acpi_mach *cht_quirk(void *arg)
42 {
43 	struct snd_soc_acpi_mach *mach = arg;
44 
45 	dmi_check_system(cht_table);
46 
47 	if (cht_machine_id == CHT_SURFACE_MACH)
48 		return &cht_surface_mach;
49 	else
50 		return mach;
51 }
52 
53 /*
54  * Some tablets with Android factory OS have buggy DSDTs with an ESSX8316 device
55  * in the ACPI tables. While they are not using an ESS8316 codec. These DSDTs
56  * also have an ACPI device for the correct codec, ignore the ESSX8316.
57  */
58 static const struct dmi_system_id cht_ess8316_not_present_table[] = {
59 	{
60 		/* Nextbook Ares 8A */
61 		.matches = {
62 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
63 			DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
64 			DMI_MATCH(DMI_BIOS_VERSION, "M882"),
65 		},
66 	},
67 	{ }
68 };
69 
70 static struct snd_soc_acpi_mach *cht_ess8316_quirk(void *arg)
71 {
72 	if (dmi_check_system(cht_ess8316_not_present_table))
73 		return NULL;
74 
75 	return arg;
76 }
77 
78 /*
79  * The Lenovo Yoga Tab 3 Pro YT3-X90, with Android factory OS has a buggy DSDT
80  * with the coded not being listed at all.
81  */
82 static const struct dmi_system_id lenovo_yoga_tab3_x90[] = {
83 	{
84 		/* Lenovo Yoga Tab 3 Pro YT3-X90, codec missing from DSDT */
85 		.matches = {
86 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
87 			DMI_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
88 			DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
89 		},
90 	},
91 	{ }
92 };
93 
94 static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = {
95 	.id = "10WM5102",
96 	.drv_name = "bytcr_wm5102",
97 	.fw_filename = "intel/fw_sst_22a8.bin",
98 	.board = "bytcr_wm5102",
99 	.sof_tplg_filename = "sof-cht-wm5102.tplg",
100 };
101 
102 static struct snd_soc_acpi_mach *lenovo_yt3_x90_quirk(void *arg)
103 {
104 	if (dmi_check_system(lenovo_yoga_tab3_x90))
105 		return &cht_lenovo_yoga_tab3_x90_mach;
106 
107 	/* Skip wildcard match snd_soc_acpi_intel_cherrytrail_machines[] entry */
108 	return NULL;
109 }
110 
111 static const struct snd_soc_acpi_codecs rt5640_comp_ids = {
112 	.num_codecs = 2,
113 	.codecs = { "10EC5640", "10EC3276" },
114 };
115 
116 static const struct snd_soc_acpi_codecs rt5670_comp_ids = {
117 	.num_codecs = 2,
118 	.codecs = { "10EC5670", "10EC5672" },
119 };
120 
121 static const struct snd_soc_acpi_codecs rt5645_comp_ids = {
122 	.num_codecs = 3,
123 	.codecs = { "10EC5645", "10EC5650", "10EC3270" },
124 };
125 
126 static const struct snd_soc_acpi_codecs da7213_comp_ids = {
127 	.num_codecs = 2,
128 	.codecs = { "DGLS7212", "DGLS7213"},
129 
130 };
131 
132 /* Cherryview-based platforms: CherryTrail and Braswell */
133 struct snd_soc_acpi_mach  snd_soc_acpi_intel_cherrytrail_machines[] = {
134 	{
135 		.comp_ids = &rt5670_comp_ids,
136 		.drv_name = "cht-bsw-rt5672",
137 		.fw_filename = "intel/fw_sst_22a8.bin",
138 		.board = "cht-bsw",
139 		.sof_tplg_filename = "sof-cht-rt5670.tplg",
140 	},
141 	{
142 		.comp_ids = &rt5645_comp_ids,
143 		.drv_name = "cht-bsw-rt5645",
144 		.fw_filename = "intel/fw_sst_22a8.bin",
145 		.board = "cht-bsw",
146 		.sof_tplg_filename = "sof-cht-rt5645.tplg",
147 	},
148 	{
149 		.id = "193C9890",
150 		.drv_name = "cht-bsw-max98090",
151 		.fw_filename = "intel/fw_sst_22a8.bin",
152 		.board = "cht-bsw",
153 		.sof_tplg_filename = "sof-cht-max98090.tplg",
154 	},
155 	{
156 		.id = "10508824",
157 		.drv_name = "cht-bsw-nau8824",
158 		.fw_filename = "intel/fw_sst_22a8.bin",
159 		.board = "cht-bsw",
160 		.sof_tplg_filename = "sof-cht-nau8824.tplg",
161 	},
162 	{
163 		.comp_ids = &da7213_comp_ids,
164 		.drv_name = "bytcht_da7213",
165 		.fw_filename = "intel/fw_sst_22a8.bin",
166 		.board = "bytcht_da7213",
167 		.sof_tplg_filename = "sof-cht-da7213.tplg",
168 	},
169 	{
170 		.id = "ESSX8316",
171 		.drv_name = "bytcht_es8316",
172 		.fw_filename = "intel/fw_sst_22a8.bin",
173 		.board = "bytcht_es8316",
174 		.machine_quirk = cht_ess8316_quirk,
175 		.sof_tplg_filename = "sof-cht-es8316.tplg",
176 	},
177 	/* some CHT-T platforms rely on RT5640, use Baytrail machine driver */
178 	{
179 		.comp_ids = &rt5640_comp_ids,
180 		.drv_name = "bytcr_rt5640",
181 		.fw_filename = "intel/fw_sst_22a8.bin",
182 		.board = "bytcr_rt5640",
183 		.machine_quirk = cht_quirk,
184 		.sof_tplg_filename = "sof-cht-rt5640.tplg",
185 	},
186 	{
187 		.id = "10EC5682",
188 		.drv_name = "sof_rt5682",
189 		.sof_tplg_filename = "sof-cht-rt5682.tplg",
190 	},
191 	/* some CHT-T platforms rely on RT5651, use Baytrail machine driver */
192 	{
193 		.id = "10EC5651",
194 		.drv_name = "bytcr_rt5651",
195 		.fw_filename = "intel/fw_sst_22a8.bin",
196 		.board = "bytcr_rt5651",
197 		.sof_tplg_filename = "sof-cht-rt5651.tplg",
198 	},
199 	{
200 		.id = "14F10720",
201 		.drv_name = "bytcht_cx2072x",
202 		.fw_filename = "intel/fw_sst_22a8.bin",
203 		.board = "bytcht_cx2072x",
204 		.sof_tplg_filename = "sof-cht-cx2072x.tplg",
205 	},
206 	{
207 		.id = "104C5122",
208 		.drv_name = "sof_pcm512x",
209 		.sof_tplg_filename = "sof-cht-src-50khz-pcm512x.tplg",
210 	},
211 	/*
212 	 * Special case for the Lenovo Yoga Tab 3 Pro YT3-X90 where the DSDT
213 	 * misses the codec. Match on the SST id instead, lenovo_yt3_x90_quirk()
214 	 * will return a YT3 specific mach or NULL when called on other hw,
215 	 * skipping this entry.
216 	 */
217 	{
218 		.id = "808622A8",
219 		.machine_quirk = lenovo_yt3_x90_quirk,
220 	},
221 
222 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
223 	/*
224 	 * This is always last in the table so that it is selected only when
225 	 * enabled explicitly and there is no codec-related information in SSDT
226 	 */
227 	{
228 		.id = "808622A8",
229 		.drv_name = "bytcht_nocodec",
230 		.fw_filename = "intel/fw_sst_22a8.bin",
231 		.board = "bytcht_nocodec",
232 	},
233 #endif
234 	{},
235 };
236 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_cherrytrail_machines);
237