blob: bb6133c60175dcd929a426dc819a3fdc76dc08de [file] [log] [blame]
Thomas Renningerc3d6de62008-08-01 17:37:55 +02001/*
2 * Copyright (C) 2008 SuSE Linux Products GmbH
3 * Thomas Renninger <trenn@suse.de>
4 *
5 * May be copied or modified under the terms of the GNU General Public License
6 *
7 * video_detect.c:
Thomas Renningerc3d6de62008-08-01 17:37:55 +02008 * After PCI devices are glued with ACPI devices
Alexander Chiang1e4cffe2009-06-10 19:56:00 +00009 * acpi_get_pci_dev() can be called to identify ACPI graphics
Thomas Renningerc3d6de62008-08-01 17:37:55 +020010 * devices for which a real graphics card is plugged in
11 *
12 * Now acpi_video_get_capabilities() can be called to check which
13 * capabilities the graphics cards plugged in support. The check for general
14 * video capabilities will be triggered by the first caller of
15 * acpi_video_get_capabilities(NULL); which will happen when the first
Zhang Rui677bd812010-12-06 15:04:21 +080016 * backlight switching supporting driver calls:
Thomas Renningerc3d6de62008-08-01 17:37:55 +020017 * acpi_video_backlight_support();
18 *
19 * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
20 * are available, video.ko should be used to handle the device.
21 *
Corentin Chary7ec48ce2011-12-15 08:27:37 +010022 * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
Zhang Rui677bd812010-12-06 15:04:21 +080023 * sony_acpi,... can take care about backlight brightness.
Thomas Renningerc3d6de62008-08-01 17:37:55 +020024 *
25 * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
26 * this file will not be compiled, acpi_video_get_capabilities() and
27 * acpi_video_backlight_support() will always return 0 and vendor specific
28 * drivers always can handle backlight.
29 *
30 */
31
Paul Gortmaker214f2c92011-10-26 16:22:14 -040032#include <linux/export.h>
Thomas Renningerc3d6de62008-08-01 17:37:55 +020033#include <linux/acpi.h>
34#include <linux/dmi.h>
Hans de Goede14ca7a472015-06-16 16:27:47 +020035#include <linux/module.h>
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000036#include <linux/pci.h>
Thomas Renningerc3d6de62008-08-01 17:37:55 +020037
38ACPI_MODULE_NAME("video");
Thomas Renningerc3d6de62008-08-01 17:37:55 +020039#define _COMPONENT ACPI_VIDEO_COMPONENT
40
41static long acpi_video_support;
42static bool acpi_video_caps_checked;
43
Hans de Goede14ca7a472015-06-16 16:27:47 +020044static void acpi_video_parse_cmdline(void)
45{
46 if (!strcmp("vendor", acpi_video_backlight_string))
47 acpi_video_support |= ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR;
48 if (!strcmp("video", acpi_video_backlight_string))
49 acpi_video_support |= ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO;
50}
51
Thomas Renningerc3d6de62008-08-01 17:37:55 +020052static acpi_status
Thomas Renningerc3d6de62008-08-01 17:37:55 +020053find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
54{
55 long *cap = context;
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000056 struct pci_dev *dev;
Thomas Renningerc3d6de62008-08-01 17:37:55 +020057 struct acpi_device *acpi_dev;
58
Mathias Krause4a4f01a2015-06-13 14:26:59 +020059 static const struct acpi_device_id video_ids[] = {
Thomas Renningerc3d6de62008-08-01 17:37:55 +020060 {ACPI_VIDEO_HID, 0},
61 {"", 0},
62 };
63 if (acpi_bus_get_device(handle, &acpi_dev))
64 return AE_OK;
65
66 if (!acpi_match_device_ids(acpi_dev, video_ids)) {
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000067 dev = acpi_get_pci_dev(handle);
Thomas Renningerc3d6de62008-08-01 17:37:55 +020068 if (!dev)
69 return AE_OK;
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000070 pci_dev_put(dev);
Toshi Kanid4e1a692013-03-04 21:30:41 +000071 *cap |= acpi_is_video_device(handle);
Thomas Renningerc3d6de62008-08-01 17:37:55 +020072 }
73 return AE_OK;
74}
75
Corentin Chary084940d2012-06-13 09:32:04 +020076/* Force to use vendor driver when the ACPI device is known to be
77 * buggy */
78static int video_detect_force_vendor(const struct dmi_system_id *d)
79{
80 acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
81 return 0;
82}
83
Mathias Krause4a4f01a2015-06-13 14:26:59 +020084static const struct dmi_system_id video_detect_dmi_table[] = {
Corentin Chary084940d2012-06-13 09:32:04 +020085 /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
86 * ACPI backlight device is used. This flag will definitively break
87 * the backlight interface (even the vendor interface) untill next
88 * reboot. It's why we should prevent video.ko from being used here
89 * and we can't rely on a later call to acpi_video_unregister().
90 */
91 {
92 .callback = video_detect_force_vendor,
93 .ident = "X360",
94 .matches = {
95 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
96 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
97 DMI_MATCH(DMI_BOARD_NAME, "X360"),
98 },
99 },
Lan Tianyud0c2ce12012-11-30 13:02:50 +0100100 {
101 .callback = video_detect_force_vendor,
102 .ident = "Asus UL30VT",
103 .matches = {
104 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
105 DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
106 },
107 },
Bastian Trillerc8f6d832013-05-19 11:52:33 +0000108 {
109 .callback = video_detect_force_vendor,
110 .ident = "Asus UL30A",
111 .matches = {
112 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
113 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
114 },
115 },
Edward Lin08a56222014-06-20 16:13:42 +0800116 {
117 .callback = video_detect_force_vendor,
118 .ident = "Dell Inspiron 5737",
119 .matches = {
120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
121 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5737"),
122 },
123 },
Corentin Chary084940d2012-06-13 09:32:04 +0200124 { },
125};
126
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200127/*
128 * Returns the video capabilities of a specific ACPI graphics device
129 *
130 * if NULL is passed as argument all ACPI devices are enumerated and
131 * all graphics capabilities of physically present devices are
Thadeu Lima de Souza Cascardo94e2bd62009-10-16 15:20:49 +0200132 * summarized and returned. This is cached and done only once.
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200133 */
Hans de Goedefb105d92015-06-16 16:27:44 +0200134static long acpi_video_get_capabilities(acpi_handle graphics_handle)
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200135{
136 long caps = 0;
137 struct acpi_device *tmp_dev;
138 acpi_status status;
139
140 if (acpi_video_caps_checked && graphics_handle == NULL)
141 return acpi_video_support;
142
143 if (!graphics_handle) {
144 /* Only do the global walk through all graphics devices once */
145 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Lin Ming22635762009-11-13 10:06:08 +0800146 ACPI_UINT32_MAX, find_video, NULL,
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200147 &caps, NULL);
148 /* There might be boot param flags set already... */
149 acpi_video_support |= caps;
150 acpi_video_caps_checked = 1;
151 /* Add blacklists here. Be careful to use the right *DMI* bits
152 * to still be able to override logic via boot params, e.g.:
153 *
154 * if (dmi_name_in_vendors("XY")) {
155 * acpi_video_support |=
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200156 * ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
157 *}
158 */
Corentin Chary084940d2012-06-13 09:32:04 +0200159
160 dmi_check_system(video_detect_dmi_table);
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200161 } else {
162 status = acpi_bus_get_device(graphics_handle, &tmp_dev);
163 if (ACPI_FAILURE(status)) {
164 ACPI_EXCEPTION((AE_INFO, status, "Invalid device"));
165 return 0;
166 }
167 acpi_walk_namespace(ACPI_TYPE_DEVICE, graphics_handle,
Lin Ming22635762009-11-13 10:06:08 +0800168 ACPI_UINT32_MAX, find_video, NULL,
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200169 &caps, NULL);
170 }
171 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "We have 0x%lX video support %s %s\n",
172 graphics_handle ? caps : acpi_video_support,
173 graphics_handle ? "on device " : "in general",
174 graphics_handle ? acpi_device_bid(tmp_dev) : ""));
175 return caps;
176}
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200177
Corentin Charyf838eb52012-06-13 09:32:01 +0200178static void acpi_video_caps_check(void)
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200179{
180 /*
181 * We must check whether the ACPI graphics device is physically plugged
182 * in. Therefore this must be called after binding PCI and ACPI devices
183 */
Hans de Goede14ca7a472015-06-16 16:27:47 +0200184 if (!acpi_video_caps_checked) {
185 acpi_video_parse_cmdline();
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200186 acpi_video_get_capabilities(NULL);
Hans de Goede14ca7a472015-06-16 16:27:47 +0200187 }
Corentin Charyf838eb52012-06-13 09:32:01 +0200188}
189
190/* Promote the vendor interface instead of the generic video module.
191 * This function allow DMI blacklists to be implemented by externals
192 * platform drivers instead of putting a big blacklist in video_detect.c
193 * After calling this function you will probably want to call
194 * acpi_video_unregister() to make sure the video module is not loaded
195 */
196void acpi_video_dmi_promote_vendor(void)
197{
198 acpi_video_caps_check();
199 acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR;
200}
201EXPORT_SYMBOL(acpi_video_dmi_promote_vendor);
202
Corentin Charyf838eb52012-06-13 09:32:01 +0200203/* Returns true if video.ko can do backlight switching */
204int acpi_video_backlight_support(void)
205{
206 acpi_video_caps_check();
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200207
208 /* First check for boot param -> highest prio */
209 if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR)
210 return 0;
211 else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO)
212 return 1;
213
214 /* Then check for DMI blacklist -> second highest prio */
215 if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VENDOR)
216 return 0;
217 else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VIDEO)
218 return 1;
219
220 /* Then go the default way */
221 return acpi_video_support & ACPI_VIDEO_BACKLIGHT;
222}
223EXPORT_SYMBOL(acpi_video_backlight_support);