blob: 02d8724a21b8c6ba0c8cf5637411b6761f171dff [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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
21 * which driver should handle the backlight.
22 *
23 * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
24 * this file will not be compiled and acpi_video_get_backlight_type() will
25 * always return acpi_backlight_vendor.
26 */
27
28#include <linux/export.h>
29#include <linux/acpi.h>
30#include <linux/backlight.h>
31#include <linux/dmi.h>
32#include <linux/module.h>
33#include <linux/pci.h>
34#include <linux/types.h>
35#include <linux/workqueue.h>
36#include <acpi/video.h>
37
38void acpi_video_unregister_backlight(void);
39
40static bool backlight_notifier_registered;
41static struct notifier_block backlight_nb;
42static struct work_struct backlight_notify_work;
43
44static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
45static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
46
47static void acpi_video_parse_cmdline(void)
48{
49 if (!strcmp("vendor", acpi_video_backlight_string))
50 acpi_backlight_cmdline = acpi_backlight_vendor;
51 if (!strcmp("video", acpi_video_backlight_string))
52 acpi_backlight_cmdline = acpi_backlight_video;
53 if (!strcmp("native", acpi_video_backlight_string))
54 acpi_backlight_cmdline = acpi_backlight_native;
55 if (!strcmp("none", acpi_video_backlight_string))
56 acpi_backlight_cmdline = acpi_backlight_none;
57}
58
59static acpi_status
60find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
61{
62 struct acpi_device *acpi_dev = acpi_fetch_acpi_dev(handle);
63 long *cap = context;
64 struct pci_dev *dev;
65
66 static const struct acpi_device_id video_ids[] = {
67 {ACPI_VIDEO_HID, 0},
68 {"", 0},
69 };
70
71 if (acpi_dev && !acpi_match_device_ids(acpi_dev, video_ids)) {
72 dev = acpi_get_pci_dev(handle);
73 if (!dev)
74 return AE_OK;
75 pci_dev_put(dev);
76 *cap |= acpi_is_video_device(handle);
77 }
78 return AE_OK;
79}
80
81/* Force to use vendor driver when the ACPI device is known to be
82 * buggy */
83static int video_detect_force_vendor(const struct dmi_system_id *d)
84{
85 acpi_backlight_dmi = acpi_backlight_vendor;
86 return 0;
87}
88
89static int video_detect_force_video(const struct dmi_system_id *d)
90{
91 acpi_backlight_dmi = acpi_backlight_video;
92 return 0;
93}
94
95static int video_detect_force_native(const struct dmi_system_id *d)
96{
97 acpi_backlight_dmi = acpi_backlight_native;
98 return 0;
99}
100
101static int video_detect_force_none(const struct dmi_system_id *d)
102{
103 acpi_backlight_dmi = acpi_backlight_none;
104 return 0;
105}
106
107static const struct dmi_system_id video_detect_dmi_table[] = {
108 /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
109 * ACPI backlight device is used. This flag will definitively break
110 * the backlight interface (even the vendor interface) until next
111 * reboot. It's why we should prevent video.ko from being used here
112 * and we can't rely on a later call to acpi_video_unregister().
113 */
114 {
115 .callback = video_detect_force_vendor,
116 /* X360 */
117 .matches = {
118 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
119 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
120 DMI_MATCH(DMI_BOARD_NAME, "X360"),
121 },
122 },
123 {
124 .callback = video_detect_force_vendor,
125 /* Asus UL30VT */
126 .matches = {
127 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
128 DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
129 },
130 },
131 {
132 .callback = video_detect_force_vendor,
133 /* Asus UL30A */
134 .matches = {
135 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
136 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
137 },
138 },
139 {
140 .callback = video_detect_force_vendor,
141 /* GIGABYTE GB-BXBT-2807 */
142 .matches = {
143 DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
144 DMI_MATCH(DMI_PRODUCT_NAME, "GB-BXBT-2807"),
145 },
146 },
147 {
148 .callback = video_detect_force_vendor,
149 /* Sony VPCEH3U1E */
150 .matches = {
151 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
152 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
153 },
154 },
155 {
156 .callback = video_detect_force_vendor,
157 /* Xiaomi Mi Pad 2 */
158 .matches = {
159 DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
160 DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
161 },
162 },
163
164 /*
165 * These models have a working acpi_video backlight control, and using
166 * native backlight causes a regression where backlight does not work
167 * when userspace is not handling brightness key events. Disable
168 * native_backlight on these to fix this:
169 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
170 */
171 {
172 .callback = video_detect_force_video,
173 /* ThinkPad T420 */
174 .matches = {
175 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
176 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
177 },
178 },
179 {
180 .callback = video_detect_force_video,
181 /* ThinkPad T520 */
182 .matches = {
183 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
184 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
185 },
186 },
187 {
188 .callback = video_detect_force_video,
189 /* ThinkPad X201s */
190 .matches = {
191 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
192 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
193 },
194 },
195 {
196 .callback = video_detect_force_video,
197 /* ThinkPad X201T */
198 .matches = {
199 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
200 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
201 },
202 },
203
204 /* The native backlight controls do not work on some older machines */
205 {
206 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
207 .callback = video_detect_force_video,
208 /* HP ENVY 15 Notebook */
209 .matches = {
210 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
211 DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
212 },
213 },
214 {
215 .callback = video_detect_force_video,
216 /* SAMSUNG 870Z5E/880Z5E/680Z5E */
217 .matches = {
218 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
219 DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
220 },
221 },
222 {
223 .callback = video_detect_force_video,
224 /* SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V */
225 .matches = {
226 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
227 DMI_MATCH(DMI_PRODUCT_NAME,
228 "370R4E/370R4V/370R5E/3570RE/370R5V"),
229 },
230 },
231 {
232 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
233 .callback = video_detect_force_video,
234 /* SAMSUNG 3570R/370R/470R/450R/510R/4450RV */
235 .matches = {
236 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
237 DMI_MATCH(DMI_PRODUCT_NAME,
238 "3570R/370R/470R/450R/510R/4450RV"),
239 },
240 },
241 {
242 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
243 .callback = video_detect_force_video,
244 /* SAMSUNG 670Z5E */
245 .matches = {
246 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
247 DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
248 },
249 },
250 {
251 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
252 .callback = video_detect_force_video,
253 /* SAMSUNG 730U3E/740U3E */
254 .matches = {
255 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
256 DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
257 },
258 },
259 {
260 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
261 .callback = video_detect_force_video,
262 /* SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D */
263 .matches = {
264 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
265 DMI_MATCH(DMI_PRODUCT_NAME,
266 "900X3C/900X3D/900X3E/900X4C/900X4D"),
267 },
268 },
269 {
270 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
271 .callback = video_detect_force_video,
272 /* Dell XPS14 L421X */
273 .matches = {
274 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
275 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
276 },
277 },
278 {
279 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
280 .callback = video_detect_force_video,
281 /* Dell XPS15 L521X */
282 .matches = {
283 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
284 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
285 },
286 },
287 {
288 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
289 .callback = video_detect_force_video,
290 /* SAMSUNG 530U4E/540U4E */
291 .matches = {
292 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
293 DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
294 },
295 },
296 /* https://bugs.launchpad.net/bugs/1894667 */
297 {
298 .callback = video_detect_force_video,
299 /* HP 635 Notebook */
300 .matches = {
301 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
302 DMI_MATCH(DMI_PRODUCT_NAME, "HP 635 Notebook PC"),
303 },
304 },
305
306 /* Non win8 machines which need native backlight nevertheless */
307 {
308 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
309 .callback = video_detect_force_native,
310 /* Lenovo Ideapad S405 */
311 .matches = {
312 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
313 DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
314 },
315 },
316 {
317 /* https://bugzilla.suse.com/show_bug.cgi?id=1208724 */
318 .callback = video_detect_force_native,
319 /* Lenovo Ideapad Z470 */
320 .matches = {
321 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
322 DMI_MATCH(DMI_PRODUCT_VERSION, "IdeaPad Z470"),
323 },
324 },
325 {
326 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
327 .callback = video_detect_force_native,
328 /* Lenovo Ideapad Z570 */
329 .matches = {
330 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
331 DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
332 },
333 },
334 {
335 .callback = video_detect_force_native,
336 /* Lenovo E41-25 */
337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
340 },
341 },
342 {
343 .callback = video_detect_force_native,
344 /* Lenovo E41-45 */
345 .matches = {
346 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
347 DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
348 },
349 },
350 {
351 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
352 .callback = video_detect_force_native,
353 /* Apple MacBook Pro 12,1 */
354 .matches = {
355 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
356 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
357 },
358 },
359 {
360 .callback = video_detect_force_native,
361 /* Dell Vostro V131 */
362 .matches = {
363 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
364 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
365 },
366 },
367 {
368 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
369 .callback = video_detect_force_native,
370 /* Dell XPS 17 L702X */
371 .matches = {
372 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
373 DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
374 },
375 },
376 {
377 .callback = video_detect_force_native,
378 /* Dell Precision 7510 */
379 .matches = {
380 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
381 DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
382 },
383 },
384 {
385 .callback = video_detect_force_native,
386 /* Acer Aspire 5738z */
387 .matches = {
388 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
389 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
390 DMI_MATCH(DMI_BOARD_NAME, "JV50"),
391 },
392 },
393 {
394 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
395 .callback = video_detect_force_native,
396 /* Acer TravelMate 5735Z */
397 .matches = {
398 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
399 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
400 DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
401 },
402 },
403 {
404 .callback = video_detect_force_native,
405 /* ASUSTeK COMPUTER INC. GA401 */
406 .matches = {
407 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
408 DMI_MATCH(DMI_PRODUCT_NAME, "GA401"),
409 },
410 },
411 {
412 .callback = video_detect_force_native,
413 /* ASUSTeK COMPUTER INC. GA502 */
414 .matches = {
415 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
416 DMI_MATCH(DMI_PRODUCT_NAME, "GA502"),
417 },
418 },
419 {
420 .callback = video_detect_force_native,
421 /* ASUSTeK COMPUTER INC. GA503 */
422 .matches = {
423 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
424 DMI_MATCH(DMI_PRODUCT_NAME, "GA503"),
425 },
426 },
427 /*
428 * Clevo NL5xRU and NL5xNU/TUXEDO Aura 15 Gen1 and Gen2 have both a
429 * working native and video interface. However the default detection
430 * mechanism first registers the video interface before unregistering
431 * it again and switching to the native interface during boot. This
432 * results in a dangling SBIOS request for backlight change for some
433 * reason, causing the backlight to switch to ~2% once per boot on the
434 * first power cord connect or disconnect event. Setting the native
435 * interface explicitly circumvents this buggy behaviour, by avoiding
436 * the unregistering process.
437 */
438 {
439 .callback = video_detect_force_native,
440 .ident = "Clevo NL5xRU",
441 .matches = {
442 DMI_MATCH(DMI_BOARD_NAME, "NL5xRU"),
443 },
444 },
445 {
446 .callback = video_detect_force_native,
447 .ident = "Clevo NL5xRU",
448 .matches = {
449 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
450 DMI_MATCH(DMI_BOARD_NAME, "AURA1501"),
451 },
452 },
453 {
454 .callback = video_detect_force_native,
455 .ident = "Clevo NL5xRU",
456 .matches = {
457 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
458 DMI_MATCH(DMI_BOARD_NAME, "EDUBOOK1502"),
459 },
460 },
461 {
462 .callback = video_detect_force_native,
463 .ident = "Clevo NL5xNU",
464 .matches = {
465 DMI_MATCH(DMI_BOARD_NAME, "NL5xNU"),
466 },
467 },
468 /*
469 * The TongFang PF5PU1G, PF4NU1F, PF5NU1G, and PF5LUXG/TUXEDO BA15 Gen10,
470 * Pulse 14/15 Gen1, and Pulse 15 Gen2 have the same problem as the Clevo
471 * NL5xRU and NL5xNU/TUXEDO Aura 15 Gen1 and Gen2. See the description
472 * above.
473 */
474 {
475 .callback = video_detect_force_native,
476 .ident = "TongFang PF5PU1G",
477 .matches = {
478 DMI_MATCH(DMI_BOARD_NAME, "PF5PU1G"),
479 },
480 },
481 {
482 .callback = video_detect_force_native,
483 .ident = "TongFang PF4NU1F",
484 .matches = {
485 DMI_MATCH(DMI_BOARD_NAME, "PF4NU1F"),
486 },
487 },
488 {
489 .callback = video_detect_force_native,
490 .ident = "TongFang PF4NU1F",
491 .matches = {
492 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
493 DMI_MATCH(DMI_BOARD_NAME, "PULSE1401"),
494 },
495 },
496 {
497 .callback = video_detect_force_native,
498 .ident = "TongFang PF5NU1G",
499 .matches = {
500 DMI_MATCH(DMI_BOARD_NAME, "PF5NU1G"),
501 },
502 },
503 {
504 .callback = video_detect_force_native,
505 .ident = "TongFang PF5NU1G",
506 .matches = {
507 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
508 DMI_MATCH(DMI_BOARD_NAME, "PULSE1501"),
509 },
510 },
511 {
512 .callback = video_detect_force_native,
513 .ident = "TongFang PF5LUXG",
514 .matches = {
515 DMI_MATCH(DMI_BOARD_NAME, "PF5LUXG"),
516 },
517 },
518 /*
519 * More Tongfang devices with the same issue as the Clevo NL5xRU and
520 * NL5xNU/TUXEDO Aura 15 Gen1 and Gen2. See the description above.
521 */
522 {
523 .callback = video_detect_force_native,
524 .ident = "TongFang GKxNRxx",
525 .matches = {
526 DMI_MATCH(DMI_BOARD_NAME, "GKxNRxx"),
527 },
528 },
529 {
530 .callback = video_detect_force_native,
531 .ident = "TongFang GKxNRxx",
532 .matches = {
533 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
534 DMI_MATCH(DMI_BOARD_NAME, "POLARIS1501A1650TI"),
535 },
536 },
537 {
538 .callback = video_detect_force_native,
539 .ident = "TongFang GKxNRxx",
540 .matches = {
541 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
542 DMI_MATCH(DMI_BOARD_NAME, "POLARIS1501A2060"),
543 },
544 },
545 {
546 .callback = video_detect_force_native,
547 .ident = "TongFang GKxNRxx",
548 .matches = {
549 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
550 DMI_MATCH(DMI_BOARD_NAME, "POLARIS1701A1650TI"),
551 },
552 },
553 {
554 .callback = video_detect_force_native,
555 .ident = "TongFang GKxNRxx",
556 .matches = {
557 DMI_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
558 DMI_MATCH(DMI_BOARD_NAME, "POLARIS1701A2060"),
559 },
560 },
561 {
562 .callback = video_detect_force_native,
563 .ident = "TongFang GMxNGxx",
564 .matches = {
565 DMI_MATCH(DMI_BOARD_NAME, "GMxNGxx"),
566 },
567 },
568 {
569 .callback = video_detect_force_native,
570 .ident = "TongFang GMxZGxx",
571 .matches = {
572 DMI_MATCH(DMI_BOARD_NAME, "GMxZGxx"),
573 },
574 },
575 {
576 .callback = video_detect_force_native,
577 .ident = "TongFang GMxRGxx",
578 .matches = {
579 DMI_MATCH(DMI_BOARD_NAME, "GMxRGxx"),
580 },
581 },
582 /*
583 * Desktops which falsely report a backlight and which our heuristics
584 * for this do not catch.
585 */
586 {
587 .callback = video_detect_force_none,
588 /* Dell OptiPlex 9020M */
589 .matches = {
590 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
591 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020M"),
592 },
593 },
594 {
595 .callback = video_detect_force_none,
596 /* MSI MS-7721 */
597 .matches = {
598 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
599 DMI_MATCH(DMI_PRODUCT_NAME, "MS-7721"),
600 },
601 },
602 { },
603};
604
605/* This uses a workqueue to avoid various locking ordering issues */
606static void acpi_video_backlight_notify_work(struct work_struct *work)
607{
608 if (acpi_video_get_backlight_type() != acpi_backlight_video)
609 acpi_video_unregister_backlight();
610}
611
612static int acpi_video_backlight_notify(struct notifier_block *nb,
613 unsigned long val, void *bd)
614{
615 struct backlight_device *backlight = bd;
616
617 /* A raw bl registering may change video -> native */
618 if (backlight->props.type == BACKLIGHT_RAW &&
619 val == BACKLIGHT_REGISTERED)
620 schedule_work(&backlight_notify_work);
621
622 return NOTIFY_OK;
623}
624
625/*
626 * Determine which type of backlight interface to use on this system,
627 * First check cmdline, then dmi quirks, then do autodetect.
628 *
629 * The autodetect order is:
630 * 1) Is the acpi-video backlight interface supported ->
631 * no, use a vendor interface
632 * 2) Is this a win8 "ready" BIOS and do we have a native interface ->
633 * yes, use a native interface
634 * 3) Else use the acpi-video interface
635 *
636 * Arguably the native on win8 check should be done first, but that would
637 * be a behavior change, which may causes issues.
638 */
639enum acpi_backlight_type acpi_video_get_backlight_type(void)
640{
641 static DEFINE_MUTEX(init_mutex);
642 static bool init_done;
643 static long video_caps;
644
645 /* Parse cmdline, dmi and acpi only once */
646 mutex_lock(&init_mutex);
647 if (!init_done) {
648 acpi_video_parse_cmdline();
649 dmi_check_system(video_detect_dmi_table);
650 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
651 ACPI_UINT32_MAX, find_video, NULL,
652 &video_caps, NULL);
653 INIT_WORK(&backlight_notify_work,
654 acpi_video_backlight_notify_work);
655 backlight_nb.notifier_call = acpi_video_backlight_notify;
656 backlight_nb.priority = 0;
657 if (backlight_register_notifier(&backlight_nb) == 0)
658 backlight_notifier_registered = true;
659 init_done = true;
660 }
661 mutex_unlock(&init_mutex);
662
663 if (acpi_backlight_cmdline != acpi_backlight_undef)
664 return acpi_backlight_cmdline;
665
666 if (acpi_backlight_dmi != acpi_backlight_undef)
667 return acpi_backlight_dmi;
668
669 if (!(video_caps & ACPI_VIDEO_BACKLIGHT))
670 return acpi_backlight_vendor;
671
672 if (acpi_osi_is_win8() && backlight_device_get_by_type(BACKLIGHT_RAW))
673 return acpi_backlight_native;
674
675 return acpi_backlight_video;
676}
677EXPORT_SYMBOL(acpi_video_get_backlight_type);
678
679/*
680 * Set the preferred backlight interface type based on DMI info.
681 * This function allows DMI blacklists to be implemented by external
682 * platform drivers instead of putting a big blacklist in video_detect.c
683 */
684void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
685{
686 acpi_backlight_dmi = type;
687 /* Remove acpi-video backlight interface if it is no longer desired */
688 if (acpi_video_get_backlight_type() != acpi_backlight_video)
689 acpi_video_unregister_backlight();
690}
691EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type);
692
693void __exit acpi_video_detect_exit(void)
694{
695 if (backlight_notifier_registered)
696 backlight_unregister_notifier(&backlight_nb);
697}