xref: /linux/drivers/acpi/video_detect.c (revision 20bed0d6ff62d985fe8222958825504b8aad4e88)
1 /*
2  *  Copyright (C) 2015       Red Hat Inc.
3  *                           Hans de Goede <hdegoede@redhat.com>
4  *  Copyright (C) 2008       SuSE Linux Products GmbH
5  *                           Thomas Renninger <trenn@suse.de>
6  *
7  *  May be copied or modified under the terms of the GNU General Public License
8  *
9  * video_detect.c:
10  * After PCI devices are glued with ACPI devices
11  * acpi_get_pci_dev() can be called to identify ACPI graphics
12  * devices for which a real graphics card is plugged in
13  *
14  * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
15  * are available, video.ko should be used to handle the device.
16  *
17  * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
18  * sony_acpi,... can take care about backlight brightness.
19  *
20  * Backlight drivers can use acpi_video_get_backlight_type() to determine which
21  * driver should handle the backlight. RAW/GPU-driver backlight drivers must
22  * use the acpi_video_backlight_use_native() helper for this.
23  *
24  * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
25  * this file will not be compiled and acpi_video_get_backlight_type() will
26  * always return acpi_backlight_vendor.
27  */
28 
29 #include <linux/export.h>
30 #include <linux/acpi.h>
31 #include <linux/apple-gmux.h>
32 #include <linux/backlight.h>
33 #include <linux/dmi.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/platform_data/x86/nvidia-wmi-ec-backlight.h>
37 #include <linux/pnp.h>
38 #include <linux/types.h>
39 #include <linux/workqueue.h>
40 #include <acpi/video.h>
41 
42 static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
43 static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
44 
45 static void acpi_video_parse_cmdline(void)
46 {
47 	if (!strcmp("vendor", acpi_video_backlight_string))
48 		acpi_backlight_cmdline = acpi_backlight_vendor;
49 	if (!strcmp("video", acpi_video_backlight_string))
50 		acpi_backlight_cmdline = acpi_backlight_video;
51 	if (!strcmp("native", acpi_video_backlight_string))
52 		acpi_backlight_cmdline = acpi_backlight_native;
53 	if (!strcmp("nvidia_wmi_ec", acpi_video_backlight_string))
54 		acpi_backlight_cmdline = acpi_backlight_nvidia_wmi_ec;
55 	if (!strcmp("apple_gmux", acpi_video_backlight_string))
56 		acpi_backlight_cmdline = acpi_backlight_apple_gmux;
57 	if (!strcmp("dell_uart", acpi_video_backlight_string))
58 		acpi_backlight_cmdline = acpi_backlight_dell_uart;
59 	if (!strcmp("none", acpi_video_backlight_string))
60 		acpi_backlight_cmdline = acpi_backlight_none;
61 }
62 
63 static acpi_status
64 find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
65 {
66 	struct acpi_device *acpi_dev = acpi_fetch_acpi_dev(handle);
67 	long *cap = context;
68 	struct pci_dev *dev;
69 
70 	if (acpi_dev_is_video_device(acpi_dev)) {
71 		dev = acpi_dev_get_pci_dev(acpi_dev);
72 		if (!dev)
73 			return AE_OK;
74 		pci_dev_put(dev);
75 		*cap |= acpi_is_video_device(handle);
76 	}
77 	return AE_OK;
78 }
79 
80 static bool nvidia_wmi_ec_supported(void)
81 {
82 	struct wmi_brightness_args args = {
83 		.mode = WMI_BRIGHTNESS_MODE_GET,
84 		.val = 0,
85 		.ret = 0,
86 	};
87 	struct acpi_buffer buf = { (acpi_size)sizeof(args), &args };
88 	acpi_status status;
89 
90 	status = wmi_evaluate_method(WMI_BRIGHTNESS_GUID, 0,
91 				     WMI_BRIGHTNESS_METHOD_SOURCE, &buf, &buf);
92 	if (ACPI_FAILURE(status))
93 		return false;
94 
95 	/*
96 	 * If brightness is handled by the EC then nvidia-wmi-ec-backlight
97 	 * should be used, else the GPU driver(s) should be used.
98 	 */
99 	return args.ret == WMI_BRIGHTNESS_SOURCE_EC;
100 }
101 
102 /* Force to use vendor driver when the ACPI device is known to be
103  * buggy */
104 static int video_detect_force_vendor(const struct dmi_system_id *d)
105 {
106 	acpi_backlight_dmi = acpi_backlight_vendor;
107 	return 0;
108 }
109 
110 static int video_detect_force_video(const struct dmi_system_id *d)
111 {
112 	acpi_backlight_dmi = acpi_backlight_video;
113 	return 0;
114 }
115 
116 static int video_detect_force_native(const struct dmi_system_id *d)
117 {
118 	acpi_backlight_dmi = acpi_backlight_native;
119 	return 0;
120 }
121 
122 static int video_detect_portege_r100(const struct dmi_system_id *d)
123 {
124 	struct pci_dev *dev;
125 	/* Search for Trident CyberBlade XP4m32 to confirm Portégé R100 */
126 	dev = pci_get_device(PCI_VENDOR_ID_TRIDENT, 0x2100, NULL);
127 	if (dev) {
128 		acpi_backlight_dmi = acpi_backlight_vendor;
129 		pci_dev_put(dev);
130 	}
131 	return 0;
132 }
133 
134 static const struct dmi_system_id video_detect_dmi_table[] = {
135 	/*
136 	 * Models which should use the vendor backlight interface,
137 	 * because of broken ACPI video backlight control.
138 	 */
139 	{
140 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1128309 */
141 	 .callback = video_detect_force_vendor,
142 	 /* Acer KAV80 */
143 	 .matches = {
144 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
145 		DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
146 		},
147 	},
148 	{
149 	 .callback = video_detect_force_vendor,
150 	 /* Asus UL30VT */
151 	 .matches = {
152 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
153 		DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
154 		},
155 	},
156 	{
157 	 .callback = video_detect_force_vendor,
158 	 /* Asus UL30A */
159 	 .matches = {
160 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
161 		DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
162 		},
163 	},
164 	{
165 	 .callback = video_detect_force_vendor,
166 	 /* Asus X55U */
167 	 .matches = {
168 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
169 		DMI_MATCH(DMI_PRODUCT_NAME, "X55U"),
170 		},
171 	},
172 	{
173 	 /* https://bugs.launchpad.net/bugs/1000146 */
174 	 .callback = video_detect_force_vendor,
175 	 /* Asus X101CH */
176 	 .matches = {
177 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
178 		DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
179 		},
180 	},
181 	{
182 	 .callback = video_detect_force_vendor,
183 	 /* Asus X401U */
184 	 .matches = {
185 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
186 		DMI_MATCH(DMI_PRODUCT_NAME, "X401U"),
187 		},
188 	},
189 	{
190 	 .callback = video_detect_force_vendor,
191 	 /* Asus X501U */
192 	 .matches = {
193 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
194 		DMI_MATCH(DMI_PRODUCT_NAME, "X501U"),
195 		},
196 	},
197 	{
198 	 /* https://bugs.launchpad.net/bugs/1000146 */
199 	 .callback = video_detect_force_vendor,
200 	 /* Asus 1015CX */
201 	 .matches = {
202 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
203 		DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
204 		},
205 	},
206 	{
207 	 .callback = video_detect_force_vendor,
208 	 /* Samsung N150/N210/N220 */
209 	 .matches = {
210 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
211 		DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
212 		DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
213 		},
214 	},
215 	{
216 	 .callback = video_detect_force_vendor,
217 	 /* Samsung NF110/NF210/NF310 */
218 	 .matches = {
219 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
220 		DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
221 		DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
222 		},
223 	},
224 	{
225 	 .callback = video_detect_force_vendor,
226 	 /* Samsung NC210 */
227 	 .matches = {
228 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
229 		DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
230 		DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
231 		},
232 	},
233 
234 	/*
235 	 * Models which should use the vendor backlight interface,
236 	 * because of broken native backlight control.
237 	 */
238 	{
239 	 .callback = video_detect_force_vendor,
240 	 /* Sony Vaio PCG-FRV35 */
241 	 .matches = {
242 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
243 		DMI_MATCH(DMI_PRODUCT_NAME, "PCG-FRV35"),
244 		},
245 	},
246 	{
247 	 .callback = video_detect_force_vendor,
248 	 /* Panasonic Toughbook CF-18 */
249 	 .matches = {
250 		DMI_MATCH(DMI_SYS_VENDOR, "Matsushita Electric Industrial"),
251 		DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
252 		},
253 	},
254 
255 	/*
256 	 * Toshiba models with Transflective display, these need to use
257 	 * the toshiba_acpi vendor driver for proper Transflective handling.
258 	 */
259 	{
260 	 .callback = video_detect_force_vendor,
261 	 .matches = {
262 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
263 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R500"),
264 		},
265 	},
266 	{
267 	 .callback = video_detect_force_vendor,
268 	 .matches = {
269 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
270 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R600"),
271 		},
272 	},
273 
274 	/*
275 	 * Toshiba Portégé R100 has working both acpi_video and toshiba_acpi
276 	 * vendor driver. But none of them gets activated as it has a VGA with
277 	 * no kernel driver (Trident CyberBlade XP4m32).
278 	 * The DMI strings are generic so check for the VGA chip in callback.
279 	 */
280 	{
281 	 .callback = video_detect_portege_r100,
282 	 .matches = {
283 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
284 		DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
285 		DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
286 		DMI_MATCH(DMI_BOARD_NAME, "Portable PC")
287 		},
288 	},
289 
290 	/*
291 	 * Models which need acpi_video backlight control where the GPU drivers
292 	 * do not call acpi_video_register_backlight() because no internal panel
293 	 * is detected. Typically these are all-in-ones (monitors with builtin
294 	 * PC) where the panel connection shows up as regular DP instead of eDP.
295 	 */
296 	{
297 	 .callback = video_detect_force_video,
298 	 /* Apple iMac14,1 */
299 	 .matches = {
300 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
301 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,1"),
302 		},
303 	},
304 	{
305 	 .callback = video_detect_force_video,
306 	 /* Apple iMac14,2 */
307 	 .matches = {
308 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
309 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,2"),
310 		},
311 	},
312 
313 	/*
314 	 * These models have a working acpi_video backlight control, and using
315 	 * native backlight causes a regression where backlight does not work
316 	 * when userspace is not handling brightness key events. Disable
317 	 * native_backlight on these to fix this:
318 	 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
319 	 */
320 	{
321 	 .callback = video_detect_force_video,
322 	 /* ThinkPad T420 */
323 	 .matches = {
324 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
325 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
326 		},
327 	},
328 	{
329 	 .callback = video_detect_force_video,
330 	 /* ThinkPad T520 */
331 	 .matches = {
332 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
333 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
334 		},
335 	},
336 	{
337 	 .callback = video_detect_force_video,
338 	 /* ThinkPad X201s */
339 	 .matches = {
340 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
341 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
342 		},
343 	},
344 	{
345 	 .callback = video_detect_force_video,
346 	 /* ThinkPad X201T */
347 	 .matches = {
348 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
349 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
350 		},
351 	},
352 
353 	/* The native backlight controls do not work on some older machines */
354 	{
355 	 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
356 	 .callback = video_detect_force_video,
357 	 /* HP ENVY 15 Notebook */
358 	 .matches = {
359 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
360 		DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
361 		},
362 	},
363 	{
364 	 .callback = video_detect_force_video,
365 	 /* SAMSUNG 870Z5E/880Z5E/680Z5E */
366 	 .matches = {
367 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
368 		DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
369 		},
370 	},
371 	{
372 	 .callback = video_detect_force_video,
373 	 /* SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V */
374 	 .matches = {
375 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
376 		DMI_MATCH(DMI_PRODUCT_NAME,
377 			  "370R4E/370R4V/370R5E/3570RE/370R5V"),
378 		},
379 	},
380 	{
381 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
382 	 .callback = video_detect_force_video,
383 	 /* SAMSUNG 3570R/370R/470R/450R/510R/4450RV */
384 	 .matches = {
385 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
386 		DMI_MATCH(DMI_PRODUCT_NAME,
387 			  "3570R/370R/470R/450R/510R/4450RV"),
388 		},
389 	},
390 	{
391 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
392 	 .callback = video_detect_force_video,
393 	 /* SAMSUNG 670Z5E */
394 	 .matches = {
395 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
396 		DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
397 		},
398 	},
399 	{
400 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
401 	 .callback = video_detect_force_video,
402 	 /* SAMSUNG 730U3E/740U3E */
403 	 .matches = {
404 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
405 		DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
406 		},
407 	},
408 	{
409 	 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
410 	 .callback = video_detect_force_video,
411 	 /* SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D */
412 	 .matches = {
413 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
414 		DMI_MATCH(DMI_PRODUCT_NAME,
415 			  "900X3C/900X3D/900X3E/900X4C/900X4D"),
416 		},
417 	},
418 	{
419 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
420 	 .callback = video_detect_force_video,
421 	 /* Dell XPS14 L421X */
422 	 .matches = {
423 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
424 		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
425 		},
426 	},
427 	{
428 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
429 	 .callback = video_detect_force_video,
430 	 /* Dell XPS15 L521X */
431 	 .matches = {
432 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
433 		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
434 		},
435 	},
436 	{
437 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
438 	 .callback = video_detect_force_video,
439 	 /* SAMSUNG 530U4E/540U4E */
440 	 .matches = {
441 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
442 		DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
443 		},
444 	},
445 	{
446 	 /* https://bugs.launchpad.net/bugs/1894667 */
447 	 .callback = video_detect_force_video,
448 	 /* HP 635 Notebook */
449 	 .matches = {
450 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
451 		DMI_MATCH(DMI_PRODUCT_NAME, "HP 635 Notebook PC"),
452 		},
453 	},
454 
455 	/* Non win8 machines which need native backlight nevertheless */
456 	{
457 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
458 	 .callback = video_detect_force_native,
459 	 /* Lenovo Ideapad S405 */
460 	 .matches = {
461 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
462 		DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
463 		},
464 	},
465 	{
466 	 /* https://bugzilla.suse.com/show_bug.cgi?id=1208724 */
467 	 .callback = video_detect_force_native,
468 	 /* Lenovo Ideapad Z470 */
469 	 .matches = {
470 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
471 		DMI_MATCH(DMI_PRODUCT_VERSION, "IdeaPad Z470"),
472 		},
473 	},
474 	{
475 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
476 	 .callback = video_detect_force_native,
477 	 /* Lenovo Ideapad Z570 */
478 	 .matches = {
479 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
480 		DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
481 		},
482 	},
483 	{
484 	 .callback = video_detect_force_native,
485 	 /* Lenovo E41-25 */
486 	 .matches = {
487 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
488 		DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
489 		},
490 	},
491 	{
492 	 .callback = video_detect_force_native,
493 	 /* Lenovo E41-45 */
494 	 .matches = {
495 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
496 		DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
497 		},
498 	},
499 	{
500 	 .callback = video_detect_force_native,
501 	 /* Lenovo Slim 7 16ARH7 */
502 	 .matches = {
503 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
504 		DMI_MATCH(DMI_PRODUCT_NAME, "82UX"),
505 		},
506 	},
507 	{
508 	 .callback = video_detect_force_native,
509 	 /* Lenovo ThinkPad X131e (3371 AMD version) */
510 	 .matches = {
511 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
512 		DMI_MATCH(DMI_PRODUCT_NAME, "3371"),
513 		},
514 	},
515 	{
516 	 .callback = video_detect_force_native,
517 	 /* Apple iMac11,3 */
518 	 .matches = {
519 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
520 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac11,3"),
521 		},
522 	},
523 	{
524 	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/1838 */
525 	 .callback = video_detect_force_native,
526 	 /* Apple iMac12,1 */
527 	 .matches = {
528 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
529 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,1"),
530 		},
531 	},
532 	{
533 	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/2753 */
534 	 .callback = video_detect_force_native,
535 	 /* Apple iMac12,2 */
536 	 .matches = {
537 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
538 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,2"),
539 		},
540 	},
541 	{
542 	 .callback = video_detect_force_native,
543 	 /* Apple MacBook Air 7,2 */
544 	 .matches = {
545 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
546 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir7,2"),
547 		},
548 	},
549 	{
550 	 .callback = video_detect_force_native,
551 	 /* Apple MacBook Air 9,1 */
552 	 .matches = {
553 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
554 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir9,1"),
555 		},
556 	},
557 	{
558 	 .callback = video_detect_force_native,
559 	 /* Apple MacBook Pro 9,2 */
560 	 .matches = {
561 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
562 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,2"),
563 		},
564 	},
565 	{
566 	 .callback = video_detect_force_native,
567 	 /* Apple MacBook Pro 11,2 */
568 	 .matches = {
569 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
570 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro11,2"),
571 		},
572 	},
573 	{
574 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
575 	 .callback = video_detect_force_native,
576 	 /* Apple MacBook Pro 12,1 */
577 	 .matches = {
578 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
579 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
580 		},
581 	},
582 	{
583 	 .callback = video_detect_force_native,
584 	 /* Apple MacBook Pro 16,2 */
585 	 .matches = {
586 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
587 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro16,2"),
588 		},
589 	},
590 	{
591 	 .callback = video_detect_force_native,
592 	 /* Dell Inspiron N4010 */
593 	 .matches = {
594 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
595 		DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N4010"),
596 		},
597 	},
598 	{
599 	 .callback = video_detect_force_native,
600 	 /* Dell Vostro V131 */
601 	 .matches = {
602 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
603 		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
604 		},
605 	},
606 	{
607 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
608 	 .callback = video_detect_force_native,
609 	 /* Dell XPS 17 L702X */
610 	 .matches = {
611 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
612 		DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
613 		},
614 	},
615 	{
616 	 .callback = video_detect_force_native,
617 	 /* Dell Precision 7510 */
618 	 .matches = {
619 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
620 		DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
621 		},
622 	},
623 	{
624 	 .callback = video_detect_force_native,
625 	 /* Dell Studio 1569 */
626 	 .matches = {
627 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
628 		DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1569"),
629 		},
630 	},
631 	{
632 	 .callback = video_detect_force_native,
633 	 /* Acer Aspire 3830TG */
634 	 .matches = {
635 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
636 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3830TG"),
637 		},
638 	},
639 	{
640 	 .callback = video_detect_force_native,
641 	 /* Acer Aspire 4810T */
642 	 .matches = {
643 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
644 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 4810T"),
645 		},
646 	},
647 	{
648 	 .callback = video_detect_force_native,
649 	 /* Acer Aspire 5738z */
650 	 .matches = {
651 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
652 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
653 		DMI_MATCH(DMI_BOARD_NAME, "JV50"),
654 		},
655 	},
656 	{
657 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1012674 */
658 	 .callback = video_detect_force_native,
659 	 /* Acer Aspire 5741 */
660 	 .matches = {
661 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
662 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
663 		},
664 	},
665 	{
666 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42993 */
667 	 .callback = video_detect_force_native,
668 	 /* Acer Aspire 5750 */
669 	 .matches = {
670 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
671 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
672 		},
673 	},
674 	{
675 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42833 */
676 	 .callback = video_detect_force_native,
677 	 /* Acer Extensa 5235 */
678 	 .matches = {
679 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
680 		DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
681 		},
682 	},
683 	{
684 	 .callback = video_detect_force_native,
685 	 /* Acer TravelMate 4750 */
686 	 .matches = {
687 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
688 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
689 		},
690 	},
691 	{
692 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
693 	 .callback = video_detect_force_native,
694 	 /* Acer TravelMate 5735Z */
695 	 .matches = {
696 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
697 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
698 		DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
699 		},
700 	},
701 	{
702 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=36322 */
703 	 .callback = video_detect_force_native,
704 	 /* Acer TravelMate 5760 */
705 	 .matches = {
706 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
707 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
708 		},
709 	},
710 	{
711 	 .callback = video_detect_force_native,
712 	 /* ASUSTeK COMPUTER INC. GA401 */
713 	 .matches = {
714 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
715 		DMI_MATCH(DMI_PRODUCT_NAME, "GA401"),
716 		},
717 	},
718 	{
719 	 .callback = video_detect_force_native,
720 	 /* ASUSTeK COMPUTER INC. GA502 */
721 	 .matches = {
722 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
723 		DMI_MATCH(DMI_PRODUCT_NAME, "GA502"),
724 		},
725 	},
726 	{
727 	 .callback = video_detect_force_native,
728 	 /* ASUSTeK COMPUTER INC. GA503 */
729 	 .matches = {
730 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
731 		DMI_MATCH(DMI_PRODUCT_NAME, "GA503"),
732 		},
733 	},
734 	{
735 	 .callback = video_detect_force_native,
736 	 /* Asus U46E */
737 	 .matches = {
738 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
739 		DMI_MATCH(DMI_PRODUCT_NAME, "U46E"),
740 		},
741 	},
742 	{
743 	 .callback = video_detect_force_native,
744 	 /* Asus UX303UB */
745 	 .matches = {
746 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
747 		DMI_MATCH(DMI_PRODUCT_NAME, "UX303UB"),
748 		},
749 	},
750 	{
751 	 .callback = video_detect_force_native,
752 	 /* HP EliteBook 8460p */
753 	 .matches = {
754 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
755 		DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook 8460p"),
756 		},
757 	},
758 	{
759 	 .callback = video_detect_force_native,
760 	 /* HP Pavilion g6-1d80nr / B4U19UA */
761 	 .matches = {
762 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
763 		DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion g6 Notebook PC"),
764 		DMI_MATCH(DMI_PRODUCT_SKU, "B4U19UA"),
765 		},
766 	},
767 	{
768 	 .callback = video_detect_force_native,
769 	 /* Samsung N150P */
770 	 .matches = {
771 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
772 		DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
773 		DMI_MATCH(DMI_BOARD_NAME, "N150P"),
774 		},
775 	},
776 	{
777 	 .callback = video_detect_force_native,
778 	 /* Samsung N145P/N250P/N260P */
779 	 .matches = {
780 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
781 		DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
782 		DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
783 		},
784 	},
785 	{
786 	 .callback = video_detect_force_native,
787 	 /* Samsung N250P */
788 	 .matches = {
789 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
790 		DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
791 		DMI_MATCH(DMI_BOARD_NAME, "N250P"),
792 		},
793 	},
794 	{
795 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=202401 */
796 	 .callback = video_detect_force_native,
797 	 /* Sony Vaio VPCEH3U1E */
798 	 .matches = {
799 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
800 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
801 		},
802 	},
803 	{
804 	 .callback = video_detect_force_native,
805 	 /* Sony Vaio VPCY11S1E */
806 	 .matches = {
807 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
808 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCY11S1E"),
809 		},
810 	},
811 
812 	/*
813 	 * These Toshibas have a broken acpi-video interface for brightness
814 	 * control. They also have an issue where the panel is off after
815 	 * suspend until a special firmware call is made to turn it back
816 	 * on. This is handled by the toshiba_acpi kernel module, so that
817 	 * module must be enabled for these models to work correctly.
818 	 */
819 	{
820 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
821 	 .callback = video_detect_force_native,
822 	 /* Toshiba Portégé R700 */
823 	 .matches = {
824 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
825 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R700"),
826 		},
827 	},
828 	{
829 	 /* Portégé: https://bugs.freedesktop.org/show_bug.cgi?id=82634 */
830 	 /* Satellite: https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
831 	 .callback = video_detect_force_native,
832 	 /* Toshiba Satellite/Portégé R830 */
833 	 .matches = {
834 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
835 		DMI_MATCH(DMI_PRODUCT_NAME, "R830"),
836 		},
837 	},
838 	{
839 	 .callback = video_detect_force_native,
840 	 /* Toshiba Satellite/Portégé Z830 */
841 	 .matches = {
842 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
843 		DMI_MATCH(DMI_PRODUCT_NAME, "Z830"),
844 		},
845 	},
846 
847 	/*
848 	 * Dell AIO (All in Ones) which advertise an UART attached backlight
849 	 * controller board in their ACPI tables (and may even have one), but
850 	 * which need native backlight control nevertheless.
851 	 */
852 	{
853 	 /* https://github.com/zabbly/linux/issues/26 */
854 	 .callback = video_detect_force_native,
855 	 /* Dell OptiPlex 5480 AIO */
856 	 .matches = {
857 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
858 		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 5480 AIO"),
859 		},
860 	},
861 	{
862 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=2303936 */
863 	 .callback = video_detect_force_native,
864 	 /* Dell OptiPlex 7760 AIO */
865 	 .matches = {
866 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
867 		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 7760 AIO"),
868 		},
869 	},
870 	{
871 	 .callback = video_detect_force_native,
872 	 /* Dell OptiPlex 7770 AIO */
873 	 .matches = {
874 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
875 		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 7770 AIO"),
876 		},
877 	},
878 	{
879 	 .callback = video_detect_force_native,
880 	 /* Dell OptiPlex AIO 7410 35W */
881 	 .matches = {
882 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
883 		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex AIO 7410 35W"),
884 		},
885 	},
886 
887 	/*
888 	 * Models which have nvidia-ec-wmi support, but should not use it.
889 	 * Note this indicates a likely firmware bug on these models and should
890 	 * be revisited if/when Linux gets support for dynamic mux mode.
891 	 */
892 	{
893 	 .callback = video_detect_force_native,
894 	 /* Dell G15 5515 */
895 	 .matches = {
896 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
897 		DMI_MATCH(DMI_PRODUCT_NAME, "Dell G15 5515"),
898 		},
899 	},
900 	{
901 	 .callback = video_detect_force_native,
902 	 .matches = {
903 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
904 		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15 3535"),
905 		},
906 	},
907 	{
908 	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/4512 */
909 	 .callback = video_detect_force_native,
910 	 /* Lenovo Legion S7 15ACH6 */
911 	 .matches = {
912 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
913 		DMI_MATCH(DMI_PRODUCT_NAME, "82K8"),
914 		},
915 	},
916 	{
917 	 .callback = video_detect_force_native,
918 	 /* HP OMEN Gaming Laptop 16-n0xxx */
919 	 .matches = {
920 		DMI_MATCH(DMI_SYS_VENDOR, "HP"),
921 		DMI_MATCH(DMI_PRODUCT_NAME, "OMEN by HP Gaming Laptop 16-n0xxx"),
922 		},
923 	},
924 	{
925 	 .callback = video_detect_force_native,
926 	 /* Acer Nitro AN515-46 */
927 	 .matches = {
928 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
929 		DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN515-46"),
930 		},
931 	},
932 	{
933 	 .callback = video_detect_force_native,
934 	 /* Acer Nitro AN515-58 */
935 	 .matches = {
936 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
937 		DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN515-58"),
938 		},
939 	},
940 
941 	/*
942 	 * x86 android tablets which directly control the backlight through
943 	 * an external backlight controller, typically TI's LP8557.
944 	 * The backlight is directly controlled by the lp855x driver on these.
945 	 * This setup means that neither i915's native nor acpi_video backlight
946 	 * control works. Add a "vendor" quirk to disable both. Note these
947 	 * devices do not use vendor control in the typical meaning of
948 	 * vendor specific SMBIOS or ACPI calls being used.
949 	 */
950 	{
951 	 .callback = video_detect_force_vendor,
952 	 /* Lenovo Yoga Book X90F / X90L */
953 	 .matches = {
954 		DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
955 		DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
956 		DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
957 		},
958 	},
959 	{
960 	 .callback = video_detect_force_vendor,
961 	 /*
962 	  * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
963 	  * Lenovo Yoga Tablet 2 use the same mainboard)
964 	  */
965 	 .matches = {
966 		DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
967 		DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
968 		DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
969 		/* Partial match on beginning of BIOS version */
970 		DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
971 		},
972 	},
973 	{
974 	 .callback = video_detect_force_vendor,
975 	 /* Lenovo Yoga Tab 3 Pro YT3-X90F */
976 	 .matches = {
977 		DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
978 		DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
979 		},
980 	},
981 	{
982 	 .callback = video_detect_force_vendor,
983 	 /* Xiaomi Mi Pad 2 */
984 	 .matches = {
985 		DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
986 		DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
987 		},
988 	},
989 	{ },
990 };
991 
992 static bool google_cros_ec_present(void)
993 {
994 	return acpi_dev_found("GOOG0004") || acpi_dev_found("GOOG000C");
995 }
996 
997 /*
998  * Windows 8 and newer no longer use the ACPI video interface, so it often
999  * does not work. So on win8+ systems prefer native brightness control.
1000  * Chromebooks should always prefer native backlight control.
1001  */
1002 static bool prefer_native_over_acpi_video(void)
1003 {
1004 	return acpi_osi_is_win8() || google_cros_ec_present();
1005 }
1006 
1007 /*
1008  * Determine which type of backlight interface to use on this system,
1009  * First check cmdline, then dmi quirks, then do autodetect.
1010  */
1011 enum acpi_backlight_type __acpi_video_get_backlight_type(bool native, bool *auto_detect)
1012 {
1013 	static DEFINE_MUTEX(init_mutex);
1014 	static bool nvidia_wmi_ec_present;
1015 	static bool apple_gmux_present;
1016 	static bool dell_uart_present;
1017 	static bool native_available;
1018 	static bool init_done;
1019 	static long video_caps;
1020 
1021 	/* Parse cmdline, dmi and acpi only once */
1022 	mutex_lock(&init_mutex);
1023 	if (!init_done) {
1024 		acpi_video_parse_cmdline();
1025 		dmi_check_system(video_detect_dmi_table);
1026 		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1027 				    ACPI_UINT32_MAX, find_video, NULL,
1028 				    &video_caps, NULL);
1029 		nvidia_wmi_ec_present = nvidia_wmi_ec_supported();
1030 		apple_gmux_present = apple_gmux_detect(NULL, NULL);
1031 		dell_uart_present = acpi_dev_present("DELL0501", NULL, -1);
1032 		init_done = true;
1033 	}
1034 	if (native)
1035 		native_available = true;
1036 	mutex_unlock(&init_mutex);
1037 
1038 	if (auto_detect)
1039 		*auto_detect = false;
1040 
1041 	/*
1042 	 * The below heuristics / detection steps are in order of descending
1043 	 * presedence. The commandline takes presedence over anything else.
1044 	 */
1045 	if (acpi_backlight_cmdline != acpi_backlight_undef)
1046 		return acpi_backlight_cmdline;
1047 
1048 	/* DMI quirks override any autodetection. */
1049 	if (acpi_backlight_dmi != acpi_backlight_undef)
1050 		return acpi_backlight_dmi;
1051 
1052 	if (auto_detect)
1053 		*auto_detect = true;
1054 
1055 	/* Special cases such as nvidia_wmi_ec and apple gmux. */
1056 	if (nvidia_wmi_ec_present)
1057 		return acpi_backlight_nvidia_wmi_ec;
1058 
1059 	if (apple_gmux_present)
1060 		return acpi_backlight_apple_gmux;
1061 
1062 	if (dell_uart_present)
1063 		return acpi_backlight_dell_uart;
1064 
1065 	/* Use ACPI video if available, except when native should be preferred. */
1066 	if ((video_caps & ACPI_VIDEO_BACKLIGHT) &&
1067 	     !(native_available && prefer_native_over_acpi_video()))
1068 		return acpi_backlight_video;
1069 
1070 	/* Use native if available */
1071 	if (native_available)
1072 		return acpi_backlight_native;
1073 
1074 	/*
1075 	 * The vendor specific BIOS interfaces are only necessary for
1076 	 * laptops from before ~2008.
1077 	 *
1078 	 * For laptops from ~2008 till ~2023 this point is never reached
1079 	 * because on those (video_caps & ACPI_VIDEO_BACKLIGHT) above is true.
1080 	 *
1081 	 * Laptops from after ~2023 no longer support ACPI_VIDEO_BACKLIGHT,
1082 	 * if this point is reached on those, this likely means that
1083 	 * the GPU kms driver which sets native_available has not loaded yet.
1084 	 *
1085 	 * Returning acpi_backlight_vendor in this case is known to sometimes
1086 	 * cause a non working vendor specific /sys/class/backlight device to
1087 	 * get registered.
1088 	 *
1089 	 * Return acpi_backlight_none on laptops with ACPI tables written
1090 	 * for Windows 8 (laptops from after ~2012) to avoid this problem.
1091 	 */
1092 	if (acpi_osi_is_win8())
1093 		return acpi_backlight_none;
1094 
1095 	/* No ACPI video/native (old hw), use vendor specific fw methods. */
1096 	return acpi_backlight_vendor;
1097 }
1098 EXPORT_SYMBOL(__acpi_video_get_backlight_type);
1099