xref: /openbmc/linux/drivers/acpi/video_detect.c (revision 5abbeebd)
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("none", acpi_video_backlight_string))
58 		acpi_backlight_cmdline = acpi_backlight_none;
59 }
60 
61 static acpi_status
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
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
107 static bool nvidia_wmi_ec_supported(void)
108 {
109 	return false;
110 }
111 #endif
112 
113 static bool apple_gmux_backlight_present(void)
114 {
115 	struct acpi_device *adev;
116 	struct device *dev;
117 
118 	adev = acpi_dev_get_first_match_dev(GMUX_ACPI_HID, NULL, -1);
119 	if (!adev)
120 		return false;
121 
122 	dev = acpi_get_first_physical_node(adev);
123 	if (!dev)
124 		return false;
125 
126 	/*
127 	 * drivers/platform/x86/apple-gmux.c only supports old style
128 	 * Apple GMUX with an IO-resource.
129 	 */
130 	return pnp_get_resource(to_pnp_dev(dev), IORESOURCE_IO, 0) != NULL;
131 }
132 
133 /* Force to use vendor driver when the ACPI device is known to be
134  * buggy */
135 static int video_detect_force_vendor(const struct dmi_system_id *d)
136 {
137 	acpi_backlight_dmi = acpi_backlight_vendor;
138 	return 0;
139 }
140 
141 static int video_detect_force_video(const struct dmi_system_id *d)
142 {
143 	acpi_backlight_dmi = acpi_backlight_video;
144 	return 0;
145 }
146 
147 static int video_detect_force_native(const struct dmi_system_id *d)
148 {
149 	acpi_backlight_dmi = acpi_backlight_native;
150 	return 0;
151 }
152 
153 static int video_detect_force_none(const struct dmi_system_id *d)
154 {
155 	acpi_backlight_dmi = acpi_backlight_none;
156 	return 0;
157 }
158 
159 static const struct dmi_system_id video_detect_dmi_table[] = {
160 	/*
161 	 * Models which should use the vendor backlight interface,
162 	 * because of broken ACPI video backlight control.
163 	 */
164 	{
165 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1128309 */
166 	 .callback = video_detect_force_vendor,
167 	 /* Acer KAV80 */
168 	 .matches = {
169 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
170 		DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
171 		},
172 	},
173 	{
174 	 .callback = video_detect_force_vendor,
175 	 /* Asus UL30VT */
176 	 .matches = {
177 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
178 		DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
179 		},
180 	},
181 	{
182 	 .callback = video_detect_force_vendor,
183 	 /* Asus UL30A */
184 	 .matches = {
185 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
186 		DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
187 		},
188 	},
189 	{
190 	 .callback = video_detect_force_vendor,
191 	 /* Asus X55U */
192 	 .matches = {
193 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
194 		DMI_MATCH(DMI_PRODUCT_NAME, "X55U"),
195 		},
196 	},
197 	{
198 	 /* https://bugs.launchpad.net/bugs/1000146 */
199 	 .callback = video_detect_force_vendor,
200 	 /* Asus X101CH */
201 	 .matches = {
202 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
203 		DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
204 		},
205 	},
206 	{
207 	 .callback = video_detect_force_vendor,
208 	 /* Asus X401U */
209 	 .matches = {
210 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
211 		DMI_MATCH(DMI_PRODUCT_NAME, "X401U"),
212 		},
213 	},
214 	{
215 	 .callback = video_detect_force_vendor,
216 	 /* Asus X501U */
217 	 .matches = {
218 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
219 		DMI_MATCH(DMI_PRODUCT_NAME, "X501U"),
220 		},
221 	},
222 	{
223 	 /* https://bugs.launchpad.net/bugs/1000146 */
224 	 .callback = video_detect_force_vendor,
225 	 /* Asus 1015CX */
226 	 .matches = {
227 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
228 		DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
229 		},
230 	},
231 	{
232 	 .callback = video_detect_force_vendor,
233 	 /* Samsung N150/N210/N220 */
234 	 .matches = {
235 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
236 		DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
237 		DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
238 		},
239 	},
240 	{
241 	 .callback = video_detect_force_vendor,
242 	 /* Samsung NF110/NF210/NF310 */
243 	 .matches = {
244 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
245 		DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
246 		DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
247 		},
248 	},
249 	{
250 	 .callback = video_detect_force_vendor,
251 	 /* Samsung NC210 */
252 	 .matches = {
253 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
254 		DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
255 		DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
256 		},
257 	},
258 	{
259 	 .callback = video_detect_force_vendor,
260 	 /* Xiaomi Mi Pad 2 */
261 	 .matches = {
262 			DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
263 			DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
264 		},
265 	},
266 
267 	/*
268 	 * Models which should use the vendor backlight interface,
269 	 * because of broken native backlight control.
270 	 */
271 	{
272 	 .callback = video_detect_force_vendor,
273 	 /* Sony Vaio PCG-FRV35 */
274 	 .matches = {
275 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
276 		DMI_MATCH(DMI_PRODUCT_NAME, "PCG-FRV35"),
277 		},
278 	},
279 
280 	/*
281 	 * Toshiba models with Transflective display, these need to use
282 	 * the toshiba_acpi vendor driver for proper Transflective handling.
283 	 */
284 	{
285 	 .callback = video_detect_force_vendor,
286 	 .matches = {
287 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
288 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R500"),
289 		},
290 	},
291 	{
292 	 .callback = video_detect_force_vendor,
293 	 .matches = {
294 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
295 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R600"),
296 		},
297 	},
298 
299 	/*
300 	 * These models have a working acpi_video backlight control, and using
301 	 * native backlight causes a regression where backlight does not work
302 	 * when userspace is not handling brightness key events. Disable
303 	 * native_backlight on these to fix this:
304 	 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
305 	 */
306 	{
307 	 .callback = video_detect_force_video,
308 	 /* ThinkPad T420 */
309 	 .matches = {
310 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
311 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
312 		},
313 	},
314 	{
315 	 .callback = video_detect_force_video,
316 	 /* ThinkPad T520 */
317 	 .matches = {
318 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
319 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
320 		},
321 	},
322 	{
323 	 .callback = video_detect_force_video,
324 	 /* ThinkPad X201s */
325 	 .matches = {
326 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
327 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
328 		},
329 	},
330 	{
331 	 .callback = video_detect_force_video,
332 	 /* ThinkPad X201T */
333 	 .matches = {
334 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
335 		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
336 		},
337 	},
338 
339 	/* The native backlight controls do not work on some older machines */
340 	{
341 	 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
342 	 .callback = video_detect_force_video,
343 	 /* HP ENVY 15 Notebook */
344 	 .matches = {
345 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
346 		DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
347 		},
348 	},
349 	{
350 	 .callback = video_detect_force_video,
351 	 /* SAMSUNG 870Z5E/880Z5E/680Z5E */
352 	 .matches = {
353 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
354 		DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
355 		},
356 	},
357 	{
358 	 .callback = video_detect_force_video,
359 	 /* SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V */
360 	 .matches = {
361 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
362 		DMI_MATCH(DMI_PRODUCT_NAME,
363 			  "370R4E/370R4V/370R5E/3570RE/370R5V"),
364 		},
365 	},
366 	{
367 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
368 	 .callback = video_detect_force_video,
369 	 /* SAMSUNG 3570R/370R/470R/450R/510R/4450RV */
370 	 .matches = {
371 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
372 		DMI_MATCH(DMI_PRODUCT_NAME,
373 			  "3570R/370R/470R/450R/510R/4450RV"),
374 		},
375 	},
376 	{
377 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
378 	 .callback = video_detect_force_video,
379 	 /* SAMSUNG 670Z5E */
380 	 .matches = {
381 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
382 		DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
383 		},
384 	},
385 	{
386 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
387 	 .callback = video_detect_force_video,
388 	 /* SAMSUNG 730U3E/740U3E */
389 	 .matches = {
390 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
391 		DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
392 		},
393 	},
394 	{
395 	 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
396 	 .callback = video_detect_force_video,
397 	 /* SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D */
398 	 .matches = {
399 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
400 		DMI_MATCH(DMI_PRODUCT_NAME,
401 			  "900X3C/900X3D/900X3E/900X4C/900X4D"),
402 		},
403 	},
404 	{
405 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
406 	 .callback = video_detect_force_video,
407 	 /* Dell XPS14 L421X */
408 	 .matches = {
409 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
410 		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
411 		},
412 	},
413 	{
414 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
415 	 .callback = video_detect_force_video,
416 	 /* Dell XPS15 L521X */
417 	 .matches = {
418 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
419 		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
420 		},
421 	},
422 	{
423 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
424 	 .callback = video_detect_force_video,
425 	 /* SAMSUNG 530U4E/540U4E */
426 	 .matches = {
427 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
428 		DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
429 		},
430 	},
431 	{
432 	 /* https://bugs.launchpad.net/bugs/1894667 */
433 	 .callback = video_detect_force_video,
434 	 /* HP 635 Notebook */
435 	 .matches = {
436 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
437 		DMI_MATCH(DMI_PRODUCT_NAME, "HP 635 Notebook PC"),
438 		},
439 	},
440 
441 	/* Non win8 machines which need native backlight nevertheless */
442 	{
443 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
444 	 .callback = video_detect_force_native,
445 	 /* Lenovo Ideapad S405 */
446 	 .matches = {
447 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
448 		DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
449 		},
450 	},
451 	{
452 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
453 	 .callback = video_detect_force_native,
454 	 /* Lenovo Ideapad Z570 */
455 	 .matches = {
456 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
457 		DMI_MATCH(DMI_PRODUCT_NAME, "102434U"),
458 		},
459 	},
460 	{
461 	 .callback = video_detect_force_native,
462 	 /* Lenovo E41-25 */
463 	 .matches = {
464 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
465 		DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
466 		},
467 	},
468 	{
469 	 .callback = video_detect_force_native,
470 	 /* Lenovo E41-45 */
471 	 .matches = {
472 		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
473 		DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
474 		},
475 	},
476 	{
477 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
478 	 .callback = video_detect_force_native,
479 	 /* Apple MacBook Pro 12,1 */
480 	 .matches = {
481 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
482 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
483 		},
484 	},
485 	{
486 	 .callback = video_detect_force_native,
487 	 /* Dell Inspiron N4010 */
488 	 .matches = {
489 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
490 		DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N4010"),
491 		},
492 	},
493 	{
494 	 .callback = video_detect_force_native,
495 	 /* Dell Vostro V131 */
496 	 .matches = {
497 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
498 		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
499 		},
500 	},
501 	{
502 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
503 	 .callback = video_detect_force_native,
504 	 /* Dell XPS 17 L702X */
505 	 .matches = {
506 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
507 		DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
508 		},
509 	},
510 	{
511 	 .callback = video_detect_force_native,
512 	 /* Dell Precision 7510 */
513 	 .matches = {
514 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
515 		DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
516 		},
517 	},
518 	{
519 	 .callback = video_detect_force_native,
520 	 /* Acer Aspire 5738z */
521 	 .matches = {
522 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
523 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
524 		DMI_MATCH(DMI_BOARD_NAME, "JV50"),
525 		},
526 	},
527 	{
528 	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1012674 */
529 	 .callback = video_detect_force_native,
530 	 /* Acer Aspire 5741 */
531 	 .matches = {
532 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
533 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
534 		},
535 	},
536 	{
537 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42993 */
538 	 .callback = video_detect_force_native,
539 	 /* Acer Aspire 5750 */
540 	 .matches = {
541 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
542 		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
543 		},
544 	},
545 	{
546 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42833 */
547 	 .callback = video_detect_force_native,
548 	 /* Acer Extensa 5235 */
549 	 .matches = {
550 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
551 		DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
552 		},
553 	},
554 	{
555 	 .callback = video_detect_force_native,
556 	 /* Acer TravelMate 4750 */
557 	 .matches = {
558 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
559 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
560 		},
561 	},
562 	{
563 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
564 	 .callback = video_detect_force_native,
565 	 /* Acer TravelMate 5735Z */
566 	 .matches = {
567 		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
568 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
569 		DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
570 		},
571 	},
572 	{
573 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=36322 */
574 	 .callback = video_detect_force_native,
575 	 /* Acer TravelMate 5760 */
576 	 .matches = {
577 		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
578 		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
579 		},
580 	},
581 	{
582 	 .callback = video_detect_force_native,
583 	 /* ASUSTeK COMPUTER INC. GA401 */
584 	 .matches = {
585 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
586 		DMI_MATCH(DMI_PRODUCT_NAME, "GA401"),
587 		},
588 	},
589 	{
590 	 .callback = video_detect_force_native,
591 	 /* ASUSTeK COMPUTER INC. GA502 */
592 	 .matches = {
593 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
594 		DMI_MATCH(DMI_PRODUCT_NAME, "GA502"),
595 		},
596 	},
597 	{
598 	 .callback = video_detect_force_native,
599 	 /* ASUSTeK COMPUTER INC. GA503 */
600 	 .matches = {
601 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
602 		DMI_MATCH(DMI_PRODUCT_NAME, "GA503"),
603 		},
604 	},
605 	{
606 	 .callback = video_detect_force_native,
607 	 /* Asus UX303UB */
608 	 .matches = {
609 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
610 		DMI_MATCH(DMI_PRODUCT_NAME, "UX303UB"),
611 		},
612 	},
613 	{
614 	 .callback = video_detect_force_native,
615 	 /* Samsung N150P */
616 	 .matches = {
617 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
618 		DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
619 		DMI_MATCH(DMI_BOARD_NAME, "N150P"),
620 		},
621 	},
622 	{
623 	 .callback = video_detect_force_native,
624 	 /* Samsung N145P/N250P/N260P */
625 	 .matches = {
626 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
627 		DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
628 		DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
629 		},
630 	},
631 	{
632 	 .callback = video_detect_force_native,
633 	 /* Samsung N250P */
634 	 .matches = {
635 		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
636 		DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
637 		DMI_MATCH(DMI_BOARD_NAME, "N250P"),
638 		},
639 	},
640 	{
641 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=202401 */
642 	 .callback = video_detect_force_native,
643 	 /* Sony Vaio VPCEH3U1E */
644 	 .matches = {
645 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
646 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
647 		},
648 	},
649 	{
650 	 .callback = video_detect_force_native,
651 	 /* Sony Vaio VPCY11S1E */
652 	 .matches = {
653 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
654 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCY11S1E"),
655 		},
656 	},
657 
658 	/*
659 	 * These Toshibas have a broken acpi-video interface for brightness
660 	 * control. They also have an issue where the panel is off after
661 	 * suspend until a special firmware call is made to turn it back
662 	 * on. This is handled by the toshiba_acpi kernel module, so that
663 	 * module must be enabled for these models to work correctly.
664 	 */
665 	{
666 	 /* https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
667 	 .callback = video_detect_force_native,
668 	 /* Toshiba Portégé R700 */
669 	 .matches = {
670 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
671 		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R700"),
672 		},
673 	},
674 	{
675 	 /* Portégé: https://bugs.freedesktop.org/show_bug.cgi?id=82634 */
676 	 /* Satellite: https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
677 	 .callback = video_detect_force_native,
678 	 /* Toshiba Satellite/Portégé R830 */
679 	 .matches = {
680 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
681 		DMI_MATCH(DMI_PRODUCT_NAME, "R830"),
682 		},
683 	},
684 	{
685 	 .callback = video_detect_force_native,
686 	 /* Toshiba Satellite/Portégé Z830 */
687 	 .matches = {
688 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
689 		DMI_MATCH(DMI_PRODUCT_NAME, "Z830"),
690 		},
691 	},
692 
693 	/*
694 	 * Models which have nvidia-ec-wmi support, but should not use it.
695 	 * Note this indicates a likely firmware bug on these models and should
696 	 * be revisited if/when Linux gets support for dynamic mux mode.
697 	 */
698 	{
699 	 .callback = video_detect_force_native,
700 	 /* Dell G15 5515 */
701 	 .matches = {
702 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
703 		DMI_MATCH(DMI_PRODUCT_NAME, "Dell G15 5515"),
704 		},
705 	},
706 
707 	/*
708 	 * Desktops which falsely report a backlight and which our heuristics
709 	 * for this do not catch.
710 	 */
711 	{
712 	 .callback = video_detect_force_none,
713 	 /* Dell OptiPlex 9020M */
714 	 .matches = {
715 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
716 		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020M"),
717 		},
718 	},
719 	{
720 	 .callback = video_detect_force_none,
721 	 /* GIGABYTE GB-BXBT-2807 */
722 	 .matches = {
723 		DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
724 		DMI_MATCH(DMI_PRODUCT_NAME, "GB-BXBT-2807"),
725 		},
726 	},
727 	{
728 	 .callback = video_detect_force_none,
729 	 /* MSI MS-7721 */
730 	 .matches = {
731 		DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
732 		DMI_MATCH(DMI_PRODUCT_NAME, "MS-7721"),
733 		},
734 	},
735 	{ },
736 };
737 
738 static bool google_cros_ec_present(void)
739 {
740 	return acpi_dev_found("GOOG0004") || acpi_dev_found("GOOG000C");
741 }
742 
743 /*
744  * Windows 8 and newer no longer use the ACPI video interface, so it often
745  * does not work. So on win8+ systems prefer native brightness control.
746  * Chromebooks should always prefer native backlight control.
747  */
748 static bool prefer_native_over_acpi_video(void)
749 {
750 	return acpi_osi_is_win8() || google_cros_ec_present();
751 }
752 
753 /*
754  * Determine which type of backlight interface to use on this system,
755  * First check cmdline, then dmi quirks, then do autodetect.
756  */
757 static enum acpi_backlight_type __acpi_video_get_backlight_type(bool native)
758 {
759 	static DEFINE_MUTEX(init_mutex);
760 	static bool nvidia_wmi_ec_present;
761 	static bool native_available;
762 	static bool init_done;
763 	static long video_caps;
764 
765 	/* Parse cmdline, dmi and acpi only once */
766 	mutex_lock(&init_mutex);
767 	if (!init_done) {
768 		acpi_video_parse_cmdline();
769 		dmi_check_system(video_detect_dmi_table);
770 		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
771 				    ACPI_UINT32_MAX, find_video, NULL,
772 				    &video_caps, NULL);
773 		nvidia_wmi_ec_present = nvidia_wmi_ec_supported();
774 		init_done = true;
775 	}
776 	if (native)
777 		native_available = true;
778 	mutex_unlock(&init_mutex);
779 
780 	/*
781 	 * The below heuristics / detection steps are in order of descending
782 	 * presedence. The commandline takes presedence over anything else.
783 	 */
784 	if (acpi_backlight_cmdline != acpi_backlight_undef)
785 		return acpi_backlight_cmdline;
786 
787 	/* DMI quirks override any autodetection. */
788 	if (acpi_backlight_dmi != acpi_backlight_undef)
789 		return acpi_backlight_dmi;
790 
791 	/* Special cases such as nvidia_wmi_ec and apple gmux. */
792 	if (nvidia_wmi_ec_present)
793 		return acpi_backlight_nvidia_wmi_ec;
794 
795 	if (apple_gmux_backlight_present())
796 		return acpi_backlight_apple_gmux;
797 
798 	/* Use ACPI video if available, except when native should be preferred. */
799 	if ((video_caps & ACPI_VIDEO_BACKLIGHT) &&
800 	     !(native_available && prefer_native_over_acpi_video()))
801 		return acpi_backlight_video;
802 
803 	/* Use native if available */
804 	if (native_available)
805 		return acpi_backlight_native;
806 
807 	/* No ACPI video/native (old hw), use vendor specific fw methods. */
808 	return acpi_backlight_vendor;
809 }
810 
811 enum acpi_backlight_type acpi_video_get_backlight_type(void)
812 {
813 	return __acpi_video_get_backlight_type(false);
814 }
815 EXPORT_SYMBOL(acpi_video_get_backlight_type);
816 
817 bool acpi_video_backlight_use_native(void)
818 {
819 	return __acpi_video_get_backlight_type(true) == acpi_backlight_native;
820 }
821 EXPORT_SYMBOL(acpi_video_backlight_use_native);
822