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