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