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