xref: /openbmc/linux/drivers/acpi/video_detect.c (revision 716dae96)
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 
acpi_video_parse_cmdline(void)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("none", acpi_video_backlight_string))
58 		acpi_backlight_cmdline = acpi_backlight_none;
59 }
60 
61 static acpi_status
find_video(acpi_handle handle,u32 lvl,void * context,void ** rv)62 find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
63 {
64 	struct acpi_device *acpi_dev = acpi_fetch_acpi_dev(handle);
65 	long *cap = context;
66 	struct pci_dev *dev;
67 
68 	static const struct acpi_device_id video_ids[] = {
69 		{ACPI_VIDEO_HID, 0},
70 		{"", 0},
71 	};
72 
73 	if (acpi_dev && !acpi_match_device_ids(acpi_dev, video_ids)) {
74 		dev = acpi_get_pci_dev(handle);
75 		if (!dev)
76 			return AE_OK;
77 		pci_dev_put(dev);
78 		*cap |= acpi_is_video_device(handle);
79 	}
80 	return AE_OK;
81 }
82 
83 /* This depends on ACPI_WMI which is X86 only */
84 #ifdef CONFIG_X86
nvidia_wmi_ec_supported(void)85 static bool nvidia_wmi_ec_supported(void)
86 {
87 	struct wmi_brightness_args args = {
88 		.mode = WMI_BRIGHTNESS_MODE_GET,
89 		.val = 0,
90 		.ret = 0,
91 	};
92 	struct acpi_buffer buf = { (acpi_size)sizeof(args), &args };
93 	acpi_status status;
94 
95 	status = wmi_evaluate_method(WMI_BRIGHTNESS_GUID, 0,
96 				     WMI_BRIGHTNESS_METHOD_SOURCE, &buf, &buf);
97 	if (ACPI_FAILURE(status))
98 		return false;
99 
100 	/*
101 	 * If brightness is handled by the EC then nvidia-wmi-ec-backlight
102 	 * should be used, else the GPU driver(s) should be used.
103 	 */
104 	return args.ret == WMI_BRIGHTNESS_SOURCE_EC;
105 }
106 #else
nvidia_wmi_ec_supported(void)107 static bool nvidia_wmi_ec_supported(void)
108 {
109 	return false;
110 }
111 #endif
112 
113 /* Force to use vendor driver when the ACPI device is known to be
114  * buggy */
video_detect_force_vendor(const struct dmi_system_id * d)115 static int video_detect_force_vendor(const struct dmi_system_id *d)
116 {
117 	acpi_backlight_dmi = acpi_backlight_vendor;
118 	return 0;
119 }
120 
video_detect_force_video(const struct dmi_system_id * d)121 static int video_detect_force_video(const struct dmi_system_id *d)
122 {
123 	acpi_backlight_dmi = acpi_backlight_video;
124 	return 0;
125 }
126 
video_detect_force_native(const struct dmi_system_id * d)127 static int video_detect_force_native(const struct dmi_system_id *d)
128 {
129 	acpi_backlight_dmi = acpi_backlight_native;
130 	return 0;
131 }
132 
video_detect_portege_r100(const struct dmi_system_id * d)133 static int video_detect_portege_r100(const struct dmi_system_id *d)
134 {
135 	struct pci_dev *dev;
136 	/* Search for Trident CyberBlade XP4m32 to confirm Portégé R100 */
137 	dev = pci_get_device(PCI_VENDOR_ID_TRIDENT, 0x2100, NULL);
138 	if (dev)
139 		acpi_backlight_dmi = acpi_backlight_vendor;
140 	return 0;
141 }
142 
143 static const struct dmi_system_id video_detect_dmi_table[] = {
144 	/*
145 	 * Models which should use the vendor backlight interface,
146 	 * because of broken ACPI video backlight control.
147 	 */
148 	{
149 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1128309 */
150 	 .callback = video_detect_force_vendor,
151 	 /* Acer KAV80 */
152 	 .matches = {
153 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
154 		DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
155 		},
156 	},
157 	{
158 	 .callback = video_detect_force_vendor,
159 	 /* Asus UL30VT */
160 	 .matches = {
161 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
162 		DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
163 		},
164 	},
165 	{
166 	 .callback = video_detect_force_vendor,
167 	 /* Asus UL30A */
168 	 .matches = {
169 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
170 		DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
171 		},
172 	},
173 	{
174 	 .callback = video_detect_force_vendor,
175 	 /* Asus X55U */
176 	 .matches = {
177 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
178 		DMI_MATCH(DMI_PRODUCT_NAME, "X55U"),
179 		},
180 	},
181 	{
182 	 /* https://bugs.launchpad.net/bugs/1000146 */
183 	 .callback = video_detect_force_vendor,
184 	 /* Asus X101CH */
185 	 .matches = {
186 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
187 		DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
188 		},
189 	},
190 	{
191 	 .callback = video_detect_force_vendor,
192 	 /* Asus X401U */
193 	 .matches = {
194 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
195 		DMI_MATCH(DMI_PRODUCT_NAME, "X401U"),
196 		},
197 	},
198 	{
199 	 .callback = video_detect_force_vendor,
200 	 /* Asus X501U */
201 	 .matches = {
202 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
203 		DMI_MATCH(DMI_PRODUCT_NAME, "X501U"),
204 		},
205 	},
206 	{
207 	 /* https://bugs.launchpad.net/bugs/1000146 */
208 	 .callback = video_detect_force_vendor,
209 	 /* Asus 1015CX */
210 	 .matches = {
211 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
212 		DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
213 		},
214 	},
215 	{
216 	 .callback = video_detect_force_vendor,
217 	 /* Samsung N150/N210/N220 */
218 	 .matches = {
219 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
220 		DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
221 		DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
222 		},
223 	},
224 	{
225 	 .callback = video_detect_force_vendor,
226 	 /* Samsung NF110/NF210/NF310 */
227 	 .matches = {
228 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
229 		DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
230 		DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
231 		},
232 	},
233 	{
234 	 .callback = video_detect_force_vendor,
235 	 /* Samsung NC210 */
236 	 .matches = {
237 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
238 		DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
239 		DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
240 		},
241 	},
242 	{
243 	 .callback = video_detect_force_vendor,
244 	 /* Xiaomi Mi Pad 2 */
245 	 .matches = {
246 			DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
247 			DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
248 		},
249 	},
250 
251 	/*
252 	 * Models which should use the vendor backlight interface,
253 	 * because of broken native backlight control.
254 	 */
255 	{
256 	 .callback = video_detect_force_vendor,
257 	 /* Sony Vaio PCG-FRV35 */
258 	 .matches = {
259 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
260 		DMI_MATCH(DMI_PRODUCT_NAME, "PCG-FRV35"),
261 		},
262 	},
263 	{
264 	 .callback = video_detect_force_vendor,
265 	 /* Panasonic Toughbook CF-18 */
266 	 .matches = {
267 		DMI_MATCH(DMI_SYS_VENDOR, "Matsushita Electric Industrial"),
268 		DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
269 		},
270 	},
271 
272 	/*
273 	 * Toshiba models with Transflective display, these need to use
274 	 * the toshiba_acpi vendor driver for proper Transflective handling.
275 	 */
276 	{
277 	 .callback = video_detect_force_vendor,
278 	 .matches = {
279 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
280 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R500"),
281 		},
282 	},
283 	{
284 	 .callback = video_detect_force_vendor,
285 	 .matches = {
286 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
287 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R600"),
288 		},
289 	},
290 
291 	/*
292 	 * Toshiba Portégé R100 has working both acpi_video and toshiba_acpi
293 	 * vendor driver. But none of them gets activated as it has a VGA with
294 	 * no kernel driver (Trident CyberBlade XP4m32).
295 	 * The DMI strings are generic so check for the VGA chip in callback.
296 	 */
297 	{
298 	 .callback = video_detect_portege_r100,
299 	 .matches = {
300 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
301 		DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
302 		DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
303 		DMI_MATCH(DMI_BOARD_NAME, "Portable PC")
304 		},
305 	},
306 
307 	/*
308 	 * Models which need acpi_video backlight control where the GPU drivers
309 	 * do not call acpi_video_register_backlight() because no internal panel
310 	 * is detected. Typically these are all-in-ones (monitors with builtin
311 	 * PC) where the panel connection shows up as regular DP instead of eDP.
312 	 */
313 	{
314 	 .callback = video_detect_force_video,
315 	 /* Apple iMac14,1 */
316 	 .matches = {
317 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
318 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,1"),
319 		},
320 	},
321 	{
322 	 .callback = video_detect_force_video,
323 	 /* Apple iMac14,2 */
324 	 .matches = {
325 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
326 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,2"),
327 		},
328 	},
329 
330 	/*
331 	 * These models have a working acpi_video backlight control, and using
332 	 * native backlight causes a regression where backlight does not work
333 	 * when userspace is not handling brightness key events. Disable
334 	 * native_backlight on these to fix this:
335 	 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
336 	 */
337 	{
338 	 .callback = video_detect_force_video,
339 	 /* ThinkPad T420 */
340 	 .matches = {
341 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
342 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
343 		},
344 	},
345 	{
346 	 .callback = video_detect_force_video,
347 	 /* ThinkPad T520 */
348 	 .matches = {
349 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
350 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
351 		},
352 	},
353 	{
354 	 .callback = video_detect_force_video,
355 	 /* ThinkPad X201s */
356 	 .matches = {
357 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
358 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
359 		},
360 	},
361 	{
362 	 .callback = video_detect_force_video,
363 	 /* ThinkPad X201T */
364 	 .matches = {
365 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
366 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
367 		},
368 	},
369 
370 	/* The native backlight controls do not work on some older machines */
371 	{
372 	 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
373 	 .callback = video_detect_force_video,
374 	 /* HP ENVY 15 Notebook */
375 	 .matches = {
376 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
377 		DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
378 		},
379 	},
380 	{
381 	 .callback = video_detect_force_video,
382 	 /* SAMSUNG 870Z5E/880Z5E/680Z5E */
383 	 .matches = {
384 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
385 		DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
386 		},
387 	},
388 	{
389 	 .callback = video_detect_force_video,
390 	 /* SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V */
391 	 .matches = {
392 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
393 		DMI_MATCH(DMI_PRODUCT_NAME,
394 			  "370R4E/370R4V/370R5E/3570RE/370R5V"),
395 		},
396 	},
397 	{
398 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
399 	 .callback = video_detect_force_video,
400 	 /* SAMSUNG 3570R/370R/470R/450R/510R/4450RV */
401 	 .matches = {
402 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
403 		DMI_MATCH(DMI_PRODUCT_NAME,
404 			  "3570R/370R/470R/450R/510R/4450RV"),
405 		},
406 	},
407 	{
408 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
409 	 .callback = video_detect_force_video,
410 	 /* SAMSUNG 670Z5E */
411 	 .matches = {
412 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
413 		DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
414 		},
415 	},
416 	{
417 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
418 	 .callback = video_detect_force_video,
419 	 /* SAMSUNG 730U3E/740U3E */
420 	 .matches = {
421 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
422 		DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
423 		},
424 	},
425 	{
426 	 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
427 	 .callback = video_detect_force_video,
428 	 /* SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D */
429 	 .matches = {
430 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
431 		DMI_MATCH(DMI_PRODUCT_NAME,
432 			  "900X3C/900X3D/900X3E/900X4C/900X4D"),
433 		},
434 	},
435 	{
436 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
437 	 .callback = video_detect_force_video,
438 	 /* Dell XPS14 L421X */
439 	 .matches = {
440 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
441 		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
442 		},
443 	},
444 	{
445 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
446 	 .callback = video_detect_force_video,
447 	 /* Dell XPS15 L521X */
448 	 .matches = {
449 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
450 		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
451 		},
452 	},
453 	{
454 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
455 	 .callback = video_detect_force_video,
456 	 /* SAMSUNG 530U4E/540U4E */
457 	 .matches = {
458 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
459 		DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
460 		},
461 	},
462 	{
463 	 /* https://bugs.launchpad.net/bugs/1894667 */
464 	 .callback = video_detect_force_video,
465 	 /* HP 635 Notebook */
466 	 .matches = {
467 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
468 		DMI_MATCH(DMI_PRODUCT_NAME, "HP 635 Notebook PC"),
469 		},
470 	},
471 
472 	/* Non win8 machines which need native backlight nevertheless */
473 	{
474 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
475 	 .callback = video_detect_force_native,
476 	 /* Lenovo Ideapad S405 */
477 	 .matches = {
478 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
479 		DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
480 		},
481 	},
482 	{
483 	 /* https://bugzilla.suse.com/show_bug.cgi?id=1208724 */
484 	 .callback = video_detect_force_native,
485 	 /* Lenovo Ideapad Z470 */
486 	 .matches = {
487 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
488 		DMI_MATCH(DMI_PRODUCT_VERSION, "IdeaPad Z470"),
489 		},
490 	},
491 	{
492 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
493 	 .callback = video_detect_force_native,
494 	 /* Lenovo Ideapad Z570 */
495 	 .matches = {
496 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
497 		DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
498 		},
499 	},
500 	{
501 	 .callback = video_detect_force_native,
502 	 /* Lenovo E41-25 */
503 	 .matches = {
504 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
505 		DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
506 		},
507 	},
508 	{
509 	 .callback = video_detect_force_native,
510 	 /* Lenovo E41-45 */
511 	 .matches = {
512 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
513 		DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
514 		},
515 	},
516 	{
517 	 .callback = video_detect_force_native,
518 	 /* Lenovo Slim 7 16ARH7 */
519 	 .matches = {
520 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
521 		DMI_MATCH(DMI_PRODUCT_NAME, "82UX"),
522 		},
523 	},
524 	{
525 	 .callback = video_detect_force_native,
526 	 /* Lenovo ThinkPad X131e (3371 AMD version) */
527 	 .matches = {
528 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
529 		DMI_MATCH(DMI_PRODUCT_NAME, "3371"),
530 		},
531 	},
532 	{
533 	 .callback = video_detect_force_native,
534 	 /* Apple iMac11,3 */
535 	 .matches = {
536 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
537 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac11,3"),
538 		},
539 	},
540 	{
541 	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/1838 */
542 	 .callback = video_detect_force_native,
543 	 /* Apple iMac12,1 */
544 	 .matches = {
545 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
546 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,1"),
547 		},
548 	},
549 	{
550 	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/2753 */
551 	 .callback = video_detect_force_native,
552 	 /* Apple iMac12,2 */
553 	 .matches = {
554 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
555 		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,2"),
556 		},
557 	},
558 	{
559 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
560 	 .callback = video_detect_force_native,
561 	 /* Apple MacBook Pro 12,1 */
562 	 .matches = {
563 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
564 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
565 		},
566 	},
567 	{
568 	 .callback = video_detect_force_native,
569 	 /* Dell Inspiron N4010 */
570 	 .matches = {
571 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
572 		DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N4010"),
573 		},
574 	},
575 	{
576 	 .callback = video_detect_force_native,
577 	 /* Dell Vostro V131 */
578 	 .matches = {
579 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
580 		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
581 		},
582 	},
583 	{
584 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
585 	 .callback = video_detect_force_native,
586 	 /* Dell XPS 17 L702X */
587 	 .matches = {
588 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
589 		DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
590 		},
591 	},
592 	{
593 	 .callback = video_detect_force_native,
594 	 /* Dell Precision 7510 */
595 	 .matches = {
596 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
597 		DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
598 		},
599 	},
600 	{
601 	 .callback = video_detect_force_native,
602 	 /* Dell Studio 1569 */
603 	 .matches = {
604 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
605 		DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1569"),
606 		},
607 	},
608 	{
609 	 .callback = video_detect_force_native,
610 	 /* Acer Aspire 3830TG */
611 	 .matches = {
612 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
613 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3830TG"),
614 		},
615 	},
616 	{
617 	 .callback = video_detect_force_native,
618 	 /* Acer Aspire 4810T */
619 	 .matches = {
620 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
621 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 4810T"),
622 		},
623 	},
624 	{
625 	 .callback = video_detect_force_native,
626 	 /* Acer Aspire 5738z */
627 	 .matches = {
628 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
629 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
630 		DMI_MATCH(DMI_BOARD_NAME, "JV50"),
631 		},
632 	},
633 	{
634 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1012674 */
635 	 .callback = video_detect_force_native,
636 	 /* Acer Aspire 5741 */
637 	 .matches = {
638 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
639 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
640 		},
641 	},
642 	{
643 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42993 */
644 	 .callback = video_detect_force_native,
645 	 /* Acer Aspire 5750 */
646 	 .matches = {
647 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
648 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
649 		},
650 	},
651 	{
652 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42833 */
653 	 .callback = video_detect_force_native,
654 	 /* Acer Extensa 5235 */
655 	 .matches = {
656 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
657 		DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
658 		},
659 	},
660 	{
661 	 .callback = video_detect_force_native,
662 	 /* Acer TravelMate 4750 */
663 	 .matches = {
664 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
665 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
666 		},
667 	},
668 	{
669 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
670 	 .callback = video_detect_force_native,
671 	 /* Acer TravelMate 5735Z */
672 	 .matches = {
673 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
674 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
675 		DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
676 		},
677 	},
678 	{
679 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=36322 */
680 	 .callback = video_detect_force_native,
681 	 /* Acer TravelMate 5760 */
682 	 .matches = {
683 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
684 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
685 		},
686 	},
687 	{
688 	 .callback = video_detect_force_native,
689 	 /* ASUSTeK COMPUTER INC. GA401 */
690 	 .matches = {
691 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
692 		DMI_MATCH(DMI_PRODUCT_NAME, "GA401"),
693 		},
694 	},
695 	{
696 	 .callback = video_detect_force_native,
697 	 /* ASUSTeK COMPUTER INC. GA502 */
698 	 .matches = {
699 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
700 		DMI_MATCH(DMI_PRODUCT_NAME, "GA502"),
701 		},
702 	},
703 	{
704 	 .callback = video_detect_force_native,
705 	 /* ASUSTeK COMPUTER INC. GA503 */
706 	 .matches = {
707 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
708 		DMI_MATCH(DMI_PRODUCT_NAME, "GA503"),
709 		},
710 	},
711 	{
712 	 .callback = video_detect_force_native,
713 	 /* Asus U46E */
714 	 .matches = {
715 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
716 		DMI_MATCH(DMI_PRODUCT_NAME, "U46E"),
717 		},
718 	},
719 	{
720 	 .callback = video_detect_force_native,
721 	 /* Asus UX303UB */
722 	 .matches = {
723 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
724 		DMI_MATCH(DMI_PRODUCT_NAME, "UX303UB"),
725 		},
726 	},
727 	{
728 	 .callback = video_detect_force_native,
729 	 /* HP EliteBook 8460p */
730 	 .matches = {
731 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
732 		DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook 8460p"),
733 		},
734 	},
735 	{
736 	 .callback = video_detect_force_native,
737 	 /* HP Pavilion g6-1d80nr / B4U19UA */
738 	 .matches = {
739 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
740 		DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion g6 Notebook PC"),
741 		DMI_MATCH(DMI_PRODUCT_SKU, "B4U19UA"),
742 		},
743 	},
744 	{
745 	 .callback = video_detect_force_native,
746 	 /* Samsung N150P */
747 	 .matches = {
748 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
749 		DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
750 		DMI_MATCH(DMI_BOARD_NAME, "N150P"),
751 		},
752 	},
753 	{
754 	 .callback = video_detect_force_native,
755 	 /* Samsung N145P/N250P/N260P */
756 	 .matches = {
757 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
758 		DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
759 		DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
760 		},
761 	},
762 	{
763 	 .callback = video_detect_force_native,
764 	 /* Samsung N250P */
765 	 .matches = {
766 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
767 		DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
768 		DMI_MATCH(DMI_BOARD_NAME, "N250P"),
769 		},
770 	},
771 	{
772 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=202401 */
773 	 .callback = video_detect_force_native,
774 	 /* Sony Vaio VPCEH3U1E */
775 	 .matches = {
776 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
777 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
778 		},
779 	},
780 	{
781 	 .callback = video_detect_force_native,
782 	 /* Sony Vaio VPCY11S1E */
783 	 .matches = {
784 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
785 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCY11S1E"),
786 		},
787 	},
788 
789 	/*
790 	 * These Toshibas have a broken acpi-video interface for brightness
791 	 * control. They also have an issue where the panel is off after
792 	 * suspend until a special firmware call is made to turn it back
793 	 * on. This is handled by the toshiba_acpi kernel module, so that
794 	 * module must be enabled for these models to work correctly.
795 	 */
796 	{
797 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
798 	 .callback = video_detect_force_native,
799 	 /* Toshiba Portégé R700 */
800 	 .matches = {
801 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
802 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R700"),
803 		},
804 	},
805 	{
806 	 /* Portégé: https://bugs.freedesktop.org/show_bug.cgi?id=82634 */
807 	 /* Satellite: https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
808 	 .callback = video_detect_force_native,
809 	 /* Toshiba Satellite/Portégé R830 */
810 	 .matches = {
811 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
812 		DMI_MATCH(DMI_PRODUCT_NAME, "R830"),
813 		},
814 	},
815 	{
816 	 .callback = video_detect_force_native,
817 	 /* Toshiba Satellite/Portégé Z830 */
818 	 .matches = {
819 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
820 		DMI_MATCH(DMI_PRODUCT_NAME, "Z830"),
821 		},
822 	},
823 
824 	/*
825 	 * Models which have nvidia-ec-wmi support, but should not use it.
826 	 * Note this indicates a likely firmware bug on these models and should
827 	 * be revisited if/when Linux gets support for dynamic mux mode.
828 	 */
829 	{
830 	 .callback = video_detect_force_native,
831 	 /* Dell G15 5515 */
832 	 .matches = {
833 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
834 		DMI_MATCH(DMI_PRODUCT_NAME, "Dell G15 5515"),
835 		},
836 	},
837 	{
838 	 .callback = video_detect_force_native,
839 	 .matches = {
840 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
841 		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15 3535"),
842 		},
843 	},
844 	{ },
845 };
846 
google_cros_ec_present(void)847 static bool google_cros_ec_present(void)
848 {
849 	return acpi_dev_found("GOOG0004") || acpi_dev_found("GOOG000C");
850 }
851 
852 /*
853  * Windows 8 and newer no longer use the ACPI video interface, so it often
854  * does not work. So on win8+ systems prefer native brightness control.
855  * Chromebooks should always prefer native backlight control.
856  */
prefer_native_over_acpi_video(void)857 static bool prefer_native_over_acpi_video(void)
858 {
859 	return acpi_osi_is_win8() || google_cros_ec_present();
860 }
861 
862 /*
863  * Determine which type of backlight interface to use on this system,
864  * First check cmdline, then dmi quirks, then do autodetect.
865  */
__acpi_video_get_backlight_type(bool native,bool * auto_detect)866 enum acpi_backlight_type __acpi_video_get_backlight_type(bool native, bool *auto_detect)
867 {
868 	static DEFINE_MUTEX(init_mutex);
869 	static bool nvidia_wmi_ec_present;
870 	static bool apple_gmux_present;
871 	static bool native_available;
872 	static bool init_done;
873 	static long video_caps;
874 
875 	/* Parse cmdline, dmi and acpi only once */
876 	mutex_lock(&init_mutex);
877 	if (!init_done) {
878 		acpi_video_parse_cmdline();
879 		dmi_check_system(video_detect_dmi_table);
880 		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
881 				    ACPI_UINT32_MAX, find_video, NULL,
882 				    &video_caps, NULL);
883 		nvidia_wmi_ec_present = nvidia_wmi_ec_supported();
884 		apple_gmux_present = apple_gmux_detect(NULL, NULL);
885 		init_done = true;
886 	}
887 	if (native)
888 		native_available = true;
889 	mutex_unlock(&init_mutex);
890 
891 	if (auto_detect)
892 		*auto_detect = false;
893 
894 	/*
895 	 * The below heuristics / detection steps are in order of descending
896 	 * presedence. The commandline takes presedence over anything else.
897 	 */
898 	if (acpi_backlight_cmdline != acpi_backlight_undef)
899 		return acpi_backlight_cmdline;
900 
901 	/* DMI quirks override any autodetection. */
902 	if (acpi_backlight_dmi != acpi_backlight_undef)
903 		return acpi_backlight_dmi;
904 
905 	if (auto_detect)
906 		*auto_detect = true;
907 
908 	/* Special cases such as nvidia_wmi_ec and apple gmux. */
909 	if (nvidia_wmi_ec_present)
910 		return acpi_backlight_nvidia_wmi_ec;
911 
912 	if (apple_gmux_present)
913 		return acpi_backlight_apple_gmux;
914 
915 	/* Use ACPI video if available, except when native should be preferred. */
916 	if ((video_caps & ACPI_VIDEO_BACKLIGHT) &&
917 	     !(native_available && prefer_native_over_acpi_video()))
918 		return acpi_backlight_video;
919 
920 	/* Use native if available */
921 	if (native_available)
922 		return acpi_backlight_native;
923 
924 	/*
925 	 * The vendor specific BIOS interfaces are only necessary for
926 	 * laptops from before ~2008.
927 	 *
928 	 * For laptops from ~2008 till ~2023 this point is never reached
929 	 * because on those (video_caps & ACPI_VIDEO_BACKLIGHT) above is true.
930 	 *
931 	 * Laptops from after ~2023 no longer support ACPI_VIDEO_BACKLIGHT,
932 	 * if this point is reached on those, this likely means that
933 	 * the GPU kms driver which sets native_available has not loaded yet.
934 	 *
935 	 * Returning acpi_backlight_vendor in this case is known to sometimes
936 	 * cause a non working vendor specific /sys/class/backlight device to
937 	 * get registered.
938 	 *
939 	 * Return acpi_backlight_none on laptops with ACPI tables written
940 	 * for Windows 8 (laptops from after ~2012) to avoid this problem.
941 	 */
942 	if (acpi_osi_is_win8())
943 		return acpi_backlight_none;
944 
945 	/* No ACPI video/native (old hw), use vendor specific fw methods. */
946 	return acpi_backlight_vendor;
947 }
948 EXPORT_SYMBOL(__acpi_video_get_backlight_type);
949