blob: d024ea02e639cf55f6a4040826d6e469fff72a52 [file] [log] [blame]
Thomas Renningerc3d6de62008-08-01 17:37:55 +02001/*
Hans de Goede87521e12015-06-16 16:27:48 +02002 * Copyright (C) 2015 Red Hat Inc.
3 * Hans de Goede <hdegoede@redhat.com>
Thomas Renningerc3d6de62008-08-01 17:37:55 +02004 * 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:
Thomas Renningerc3d6de62008-08-01 17:37:55 +020010 * After PCI devices are glued with ACPI devices
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000011 * acpi_get_pci_dev() can be called to identify ACPI graphics
Thomas Renningerc3d6de62008-08-01 17:37:55 +020012 * devices for which a real graphics card is plugged in
13 *
Thomas Renningerc3d6de62008-08-01 17:37:55 +020014 * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
15 * are available, video.ko should be used to handle the device.
16 *
Corentin Chary7ec48ce2011-12-15 08:27:37 +010017 * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
Zhang Rui677bd812010-12-06 15:04:21 +080018 * sony_acpi,... can take care about backlight brightness.
Thomas Renningerc3d6de62008-08-01 17:37:55 +020019 *
Hans de Goede87521e12015-06-16 16:27:48 +020020 * Backlight drivers can use acpi_video_get_backlight_type() to determine
21 * which driver should handle the backlight.
Thomas Renningerc3d6de62008-08-01 17:37:55 +020022 *
Hans de Goede87521e12015-06-16 16:27:48 +020023 * 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.
Thomas Renningerc3d6de62008-08-01 17:37:55 +020026 */
27
Paul Gortmaker214f2c92011-10-26 16:22:14 -040028#include <linux/export.h>
Thomas Renningerc3d6de62008-08-01 17:37:55 +020029#include <linux/acpi.h>
Hans de Goede87521e12015-06-16 16:27:48 +020030#include <linux/backlight.h>
Thomas Renningerc3d6de62008-08-01 17:37:55 +020031#include <linux/dmi.h>
Hans de Goede14ca7a472015-06-16 16:27:47 +020032#include <linux/module.h>
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000033#include <linux/pci.h>
Hans de Goede87521e12015-06-16 16:27:48 +020034#include <linux/types.h>
35#include <acpi/video.h>
Thomas Renningerc3d6de62008-08-01 17:37:55 +020036
37ACPI_MODULE_NAME("video");
Thomas Renningerc3d6de62008-08-01 17:37:55 +020038#define _COMPONENT ACPI_VIDEO_COMPONENT
39
Hans de Goede87521e12015-06-16 16:27:48 +020040static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
41static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
Thomas Renningerc3d6de62008-08-01 17:37:55 +020042
Hans de Goede14ca7a472015-06-16 16:27:47 +020043static void acpi_video_parse_cmdline(void)
44{
45 if (!strcmp("vendor", acpi_video_backlight_string))
Hans de Goede87521e12015-06-16 16:27:48 +020046 acpi_backlight_cmdline = acpi_backlight_vendor;
Hans de Goede14ca7a472015-06-16 16:27:47 +020047 if (!strcmp("video", acpi_video_backlight_string))
Hans de Goede87521e12015-06-16 16:27:48 +020048 acpi_backlight_cmdline = acpi_backlight_video;
49 if (!strcmp("native", acpi_video_backlight_string))
50 acpi_backlight_cmdline = acpi_backlight_native;
51 if (!strcmp("none", acpi_video_backlight_string))
52 acpi_backlight_cmdline = acpi_backlight_none;
Hans de Goede14ca7a472015-06-16 16:27:47 +020053}
54
Thomas Renningerc3d6de62008-08-01 17:37:55 +020055static acpi_status
Thomas Renningerc3d6de62008-08-01 17:37:55 +020056find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
57{
58 long *cap = context;
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000059 struct pci_dev *dev;
Thomas Renningerc3d6de62008-08-01 17:37:55 +020060 struct acpi_device *acpi_dev;
61
Mathias Krause4a4f01a2015-06-13 14:26:59 +020062 static const struct acpi_device_id video_ids[] = {
Thomas Renningerc3d6de62008-08-01 17:37:55 +020063 {ACPI_VIDEO_HID, 0},
64 {"", 0},
65 };
66 if (acpi_bus_get_device(handle, &acpi_dev))
67 return AE_OK;
68
69 if (!acpi_match_device_ids(acpi_dev, video_ids)) {
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000070 dev = acpi_get_pci_dev(handle);
Thomas Renningerc3d6de62008-08-01 17:37:55 +020071 if (!dev)
72 return AE_OK;
Alexander Chiang1e4cffe2009-06-10 19:56:00 +000073 pci_dev_put(dev);
Toshi Kanid4e1a692013-03-04 21:30:41 +000074 *cap |= acpi_is_video_device(handle);
Thomas Renningerc3d6de62008-08-01 17:37:55 +020075 }
76 return AE_OK;
77}
78
Corentin Chary084940d2012-06-13 09:32:04 +020079/* Force to use vendor driver when the ACPI device is known to be
80 * buggy */
81static int video_detect_force_vendor(const struct dmi_system_id *d)
82{
Hans de Goede87521e12015-06-16 16:27:48 +020083 acpi_backlight_dmi = acpi_backlight_vendor;
Corentin Chary084940d2012-06-13 09:32:04 +020084 return 0;
85}
86
Hans de Goede3bd6bce2015-06-16 16:27:51 +020087static int video_detect_force_video(const struct dmi_system_id *d)
88{
89 acpi_backlight_dmi = acpi_backlight_video;
90 return 0;
91}
92
93static int video_detect_force_native(const struct dmi_system_id *d)
94{
95 acpi_backlight_dmi = acpi_backlight_native;
96 return 0;
97}
98
Mathias Krause4a4f01a2015-06-13 14:26:59 +020099static const struct dmi_system_id video_detect_dmi_table[] = {
Corentin Chary084940d2012-06-13 09:32:04 +0200100 /* On Samsung X360, the BIOS will set a flag (VDRV) if generic
101 * ACPI backlight device is used. This flag will definitively break
102 * the backlight interface (even the vendor interface) untill next
103 * reboot. It's why we should prevent video.ko from being used here
104 * and we can't rely on a later call to acpi_video_unregister().
105 */
106 {
107 .callback = video_detect_force_vendor,
108 .ident = "X360",
109 .matches = {
110 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
111 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
112 DMI_MATCH(DMI_BOARD_NAME, "X360"),
113 },
114 },
Lan Tianyud0c2ce12012-11-30 13:02:50 +0100115 {
116 .callback = video_detect_force_vendor,
117 .ident = "Asus UL30VT",
118 .matches = {
119 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
120 DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
121 },
122 },
Bastian Trillerc8f6d832013-05-19 11:52:33 +0000123 {
124 .callback = video_detect_force_vendor,
125 .ident = "Asus UL30A",
126 .matches = {
127 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
128 DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
129 },
130 },
Edward Lin08a56222014-06-20 16:13:42 +0800131 {
132 .callback = video_detect_force_vendor,
133 .ident = "Dell Inspiron 5737",
134 .matches = {
135 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
136 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5737"),
137 },
138 },
Hans de Goede3bd6bce2015-06-16 16:27:51 +0200139
140 /*
141 * These models have a working acpi_video backlight control, and using
142 * native backlight causes a regression where backlight does not work
143 * when userspace is not handling brightness key events. Disable
144 * native_backlight on these to fix this:
145 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
146 */
147 {
148 .callback = video_detect_force_video,
149 .ident = "ThinkPad T420",
150 .matches = {
151 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
152 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
153 },
154 },
155 {
156 .callback = video_detect_force_video,
157 .ident = "ThinkPad T520",
158 .matches = {
159 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
160 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
161 },
162 },
163 {
164 .callback = video_detect_force_video,
165 .ident = "ThinkPad X201s",
166 .matches = {
167 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
168 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
169 },
170 },
171
172 /* The native backlight controls do not work on some older machines */
173 {
174 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
175 .callback = video_detect_force_video,
176 .ident = "HP ENVY 15 Notebook",
177 .matches = {
178 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
179 DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
180 },
181 },
182 {
183 .callback = video_detect_force_video,
184 .ident = "SAMSUNG 870Z5E/880Z5E/680Z5E",
185 .matches = {
186 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
187 DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
188 },
189 },
190 {
191 .callback = video_detect_force_video,
192 .ident = "SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V",
193 .matches = {
194 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
195 DMI_MATCH(DMI_PRODUCT_NAME,
196 "370R4E/370R4V/370R5E/3570RE/370R5V"),
197 },
198 },
199 {
200 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
201 .callback = video_detect_force_video,
202 .ident = "SAMSUNG 3570R/370R/470R/450R/510R/4450RV",
203 .matches = {
204 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
205 DMI_MATCH(DMI_PRODUCT_NAME,
206 "3570R/370R/470R/450R/510R/4450RV"),
207 },
208 },
209 {
210 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
211 .callback = video_detect_force_video,
212 .ident = "SAMSUNG 730U3E/740U3E",
213 .matches = {
214 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
215 DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
216 },
217 },
218 {
219 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
220 .callback = video_detect_force_video,
221 .ident = "SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D",
222 .matches = {
223 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
224 DMI_MATCH(DMI_PRODUCT_NAME,
225 "900X3C/900X3D/900X3E/900X4C/900X4D"),
226 },
227 },
228 {
229 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
230 .callback = video_detect_force_video,
231 .ident = "Dell XPS15 L521X",
232 .matches = {
233 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
234 DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
235 },
236 },
237
238 /* Non win8 machines which need native backlight nevertheless */
239 {
240 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
241 .callback = video_detect_force_native,
242 .ident = "Lenovo Ideapad Z570",
243 .matches = {
244 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
245 DMI_MATCH(DMI_PRODUCT_NAME, "102434U"),
246 },
247 },
248 {
249 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
250 .callback = video_detect_force_native,
251 .ident = "Apple MacBook Pro 12,1",
252 .matches = {
253 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
254 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
255 },
256 },
Corentin Chary084940d2012-06-13 09:32:04 +0200257 { },
258};
259
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200260/*
Hans de Goede87521e12015-06-16 16:27:48 +0200261 * Determine which type of backlight interface to use on this system,
262 * First check cmdline, then dmi quirks, then do autodetect.
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200263 *
Hans de Goede87521e12015-06-16 16:27:48 +0200264 * The autodetect order is:
265 * 1) Is the acpi-video backlight interface supported ->
266 * no, use a vendor interface
267 * 2) Is this a win8 "ready" BIOS and do we have a native interface ->
268 * yes, use a native interface
269 * 3) Else use the acpi-video interface
270 *
271 * Arguably the native on win8 check should be done first, but that would
272 * be a behavior change, which may causes issues.
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200273 */
Hans de Goede87521e12015-06-16 16:27:48 +0200274enum acpi_backlight_type acpi_video_get_backlight_type(void)
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200275{
Hans de Goede87521e12015-06-16 16:27:48 +0200276 static DEFINE_MUTEX(init_mutex);
277 static bool init_done;
278 static long video_caps;
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200279
Hans de Goede87521e12015-06-16 16:27:48 +0200280 /* Parse cmdline, dmi and acpi only once */
281 mutex_lock(&init_mutex);
282 if (!init_done) {
283 acpi_video_parse_cmdline();
284 dmi_check_system(video_detect_dmi_table);
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200285 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Lin Ming22635762009-11-13 10:06:08 +0800286 ACPI_UINT32_MAX, find_video, NULL,
Hans de Goede87521e12015-06-16 16:27:48 +0200287 &video_caps, NULL);
288 init_done = true;
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200289 }
Hans de Goede87521e12015-06-16 16:27:48 +0200290 mutex_unlock(&init_mutex);
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200291
Hans de Goede87521e12015-06-16 16:27:48 +0200292 if (acpi_backlight_cmdline != acpi_backlight_undef)
293 return acpi_backlight_cmdline;
Corentin Charyf838eb52012-06-13 09:32:01 +0200294
Hans de Goede87521e12015-06-16 16:27:48 +0200295 if (acpi_backlight_dmi != acpi_backlight_undef)
296 return acpi_backlight_dmi;
297
298 if (!(video_caps & ACPI_VIDEO_BACKLIGHT))
299 return acpi_backlight_vendor;
300
301 if (acpi_osi_is_win8() && backlight_device_registered(BACKLIGHT_RAW))
302 return acpi_backlight_native;
303
304 return acpi_backlight_video;
305}
306EXPORT_SYMBOL(acpi_video_get_backlight_type);
307
308/*
309 * Set the preferred backlight interface type based on DMI info.
310 * This function allows DMI blacklists to be implemented by external
Corentin Charyf838eb52012-06-13 09:32:01 +0200311 * platform drivers instead of putting a big blacklist in video_detect.c
Hans de Goede87521e12015-06-16 16:27:48 +0200312 */
313void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
314{
315 acpi_backlight_dmi = type;
Hans de Goede5fd677b2015-06-16 16:27:49 +0200316 /* Remove acpi-video backlight interface if it is no longer desired */
317 if (acpi_video_get_backlight_type() != acpi_backlight_video)
318 acpi_video_unregister_backlight();
Hans de Goede87521e12015-06-16 16:27:48 +0200319}
320EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type);
321
322/*
323 * Compatiblity function, this is going away as soon as all drivers are
324 * converted to acpi_video_set_dmi_backlight_type().
325 *
326 * Promote the vendor interface instead of the generic video module.
Corentin Charyf838eb52012-06-13 09:32:01 +0200327 * After calling this function you will probably want to call
328 * acpi_video_unregister() to make sure the video module is not loaded
329 */
330void acpi_video_dmi_promote_vendor(void)
331{
Hans de Goede87521e12015-06-16 16:27:48 +0200332 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Corentin Charyf838eb52012-06-13 09:32:01 +0200333}
334EXPORT_SYMBOL(acpi_video_dmi_promote_vendor);
335
Hans de Goede87521e12015-06-16 16:27:48 +0200336/*
337 * Compatiblity function, this is going away as soon as all drivers are
338 * converted to acpi_video_get_backlight_type().
339 *
340 * Returns true if video.ko can do backlight switching.
341 */
Corentin Charyf838eb52012-06-13 09:32:01 +0200342int acpi_video_backlight_support(void)
343{
Hans de Goede87521e12015-06-16 16:27:48 +0200344 /*
345 * This is done this way since vendor drivers call this to see
346 * if they should load, and we do not want them to load for both
347 * the acpi_backlight_video and acpi_backlight_native cases.
348 */
349 return acpi_video_get_backlight_type() != acpi_backlight_vendor;
Thomas Renningerc3d6de62008-08-01 17:37:55 +0200350}
351EXPORT_SYMBOL(acpi_video_backlight_support);