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