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