2 * video.c - ACPI Video Driver
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/input.h>
34 #include <linux/backlight.h>
35 #include <linux/thermal.h>
36 #include <linux/sort.h>
37 #include <linux/pci.h>
38 #include <linux/pci_ids.h>
39 #include <linux/slab.h>
40 #include <linux/dmi.h>
41 #include <linux/suspend.h>
42 #include <linux/acpi.h>
43 #include <acpi/video.h>
44 #include <asm/uaccess.h>
48 #define PREFIX "ACPI: "
50 #define ACPI_VIDEO_BUS_NAME "Video Bus"
51 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
52 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
53 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
54 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
55 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
56 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
58 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
59 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
60 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
61 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
62 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
64 #define MAX_NAME_LEN 20
66 #define _COMPONENT ACPI_VIDEO_COMPONENT
67 ACPI_MODULE_NAME("video");
69 MODULE_AUTHOR("Bruno Ducrot");
70 MODULE_DESCRIPTION("ACPI Video Driver");
71 MODULE_LICENSE("GPL");
73 static bool brightness_switch_enabled = 1;
74 module_param(brightness_switch_enabled, bool, 0644);
77 * By default, we don't allow duplicate ACPI video bus devices
78 * under the same VGA controller
80 static bool allow_duplicates;
81 module_param(allow_duplicates, bool, 0644);
84 * For Windows 8 systems: if set ture and the GPU driver has
85 * registered a backlight interface, skip registering ACPI video's.
87 static bool use_native_backlight = false;
88 module_param(use_native_backlight, bool, 0644);
90 static int register_count;
91 static struct mutex video_list_lock;
92 static struct list_head video_bus_head;
93 static int acpi_video_bus_add(struct acpi_device *device);
94 static int acpi_video_bus_remove(struct acpi_device *device);
95 static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
97 static const struct acpi_device_id video_device_ids[] = {
101 MODULE_DEVICE_TABLE(acpi, video_device_ids);
103 static struct acpi_driver acpi_video_bus = {
105 .class = ACPI_VIDEO_CLASS,
106 .ids = video_device_ids,
108 .add = acpi_video_bus_add,
109 .remove = acpi_video_bus_remove,
110 .notify = acpi_video_bus_notify,
114 struct acpi_video_bus_flags {
115 u8 multihead:1; /* can switch video heads */
116 u8 rom:1; /* can retrieve a video rom */
117 u8 post:1; /* can configure the head to */
121 struct acpi_video_bus_cap {
122 u8 _DOS:1; /* Enable/Disable output switching */
123 u8 _DOD:1; /* Enumerate all devices attached to display adapter */
124 u8 _ROM:1; /* Get ROM Data */
125 u8 _GPD:1; /* Get POST Device */
126 u8 _SPD:1; /* Set POST Device */
127 u8 _VPO:1; /* Video POST Options */
131 struct acpi_video_device_attrib {
132 u32 display_index:4; /* A zero-based instance of the Display */
133 u32 display_port_attachment:4; /* This field differentiates the display type */
134 u32 display_type:4; /* Describe the specific type in use */
135 u32 vendor_specific:4; /* Chipset Vendor Specific */
136 u32 bios_can_detect:1; /* BIOS can detect the device */
137 u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
139 u32 pipe_id:3; /* For VGA multiple-head devices. */
140 u32 reserved:10; /* Must be 0 */
141 u32 device_id_scheme:1; /* Device ID Scheme */
144 struct acpi_video_enumerated_device {
147 struct acpi_video_device_attrib attrib;
149 struct acpi_video_device *bind_info;
152 struct acpi_video_bus {
153 struct acpi_device *device;
155 struct acpi_video_enumerated_device *attached_array;
157 struct acpi_video_bus_cap cap;
158 struct acpi_video_bus_flags flags;
159 struct list_head video_device_list;
160 struct mutex device_list_lock; /* protects video_device_list */
161 struct list_head entry;
162 struct input_dev *input;
163 char phys[32]; /* for input device */
164 struct notifier_block pm_nb;
167 struct acpi_video_device_flags {
178 struct acpi_video_device_cap {
179 u8 _ADR:1; /* Return the unique ID */
180 u8 _BCL:1; /* Query list of brightness control levels supported */
181 u8 _BCM:1; /* Set the brightness level */
182 u8 _BQC:1; /* Get current brightness level */
183 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
184 u8 _DDC:1; /* Return the EDID for this device */
187 struct acpi_video_brightness_flags {
188 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
189 u8 _BCL_reversed:1; /* _BCL package is in a reversed order */
190 u8 _BQC_use_index:1; /* _BQC returns an index value */
193 struct acpi_video_device_brightness {
197 struct acpi_video_brightness_flags flags;
200 struct acpi_video_device {
201 unsigned long device_id;
202 struct acpi_video_device_flags flags;
203 struct acpi_video_device_cap cap;
204 struct list_head entry;
205 struct acpi_video_bus *video;
206 struct acpi_device *dev;
207 struct acpi_video_device_brightness *brightness;
208 struct backlight_device *backlight;
209 struct thermal_cooling_device *cooling_dev;
212 static const char device_decode[][30] = {
213 "motherboard VGA device",
219 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
220 static void acpi_video_device_rebind(struct acpi_video_bus *video);
221 static void acpi_video_device_bind(struct acpi_video_bus *video,
222 struct acpi_video_device *device);
223 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
224 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
226 static int acpi_video_device_lcd_get_level_current(
227 struct acpi_video_device *device,
228 unsigned long long *level, bool raw);
229 static int acpi_video_get_next_level(struct acpi_video_device *device,
230 u32 level_current, u32 event);
231 static int acpi_video_switch_brightness(struct acpi_video_device *device,
234 static bool acpi_video_verify_backlight_support(void)
236 if (acpi_osi_is_win8() && use_native_backlight &&
237 backlight_device_registered(BACKLIGHT_RAW))
239 return acpi_video_backlight_support();
242 /* backlight device sysfs support */
243 static int acpi_video_get_brightness(struct backlight_device *bd)
245 unsigned long long cur_level;
247 struct acpi_video_device *vd = bl_get_data(bd);
249 if (acpi_video_device_lcd_get_level_current(vd, &cur_level, false))
251 for (i = 2; i < vd->brightness->count; i++) {
252 if (vd->brightness->levels[i] == cur_level)
254 * The first two entries are special - see page 575
255 * of the ACPI spec 3.0
262 static int acpi_video_set_brightness(struct backlight_device *bd)
264 int request_level = bd->props.brightness + 2;
265 struct acpi_video_device *vd = bl_get_data(bd);
267 return acpi_video_device_lcd_set_level(vd,
268 vd->brightness->levels[request_level]);
271 static const struct backlight_ops acpi_backlight_ops = {
272 .get_brightness = acpi_video_get_brightness,
273 .update_status = acpi_video_set_brightness,
276 /* thermal cooling device callbacks */
277 static int video_get_max_state(struct thermal_cooling_device *cooling_dev, unsigned
280 struct acpi_device *device = cooling_dev->devdata;
281 struct acpi_video_device *video = acpi_driver_data(device);
283 *state = video->brightness->count - 3;
287 static int video_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned
290 struct acpi_device *device = cooling_dev->devdata;
291 struct acpi_video_device *video = acpi_driver_data(device);
292 unsigned long long level;
295 if (acpi_video_device_lcd_get_level_current(video, &level, false))
297 for (offset = 2; offset < video->brightness->count; offset++)
298 if (level == video->brightness->levels[offset]) {
299 *state = video->brightness->count - offset - 1;
307 video_set_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long state)
309 struct acpi_device *device = cooling_dev->devdata;
310 struct acpi_video_device *video = acpi_driver_data(device);
313 if (state >= video->brightness->count - 2)
316 state = video->brightness->count - state;
317 level = video->brightness->levels[state - 1];
318 return acpi_video_device_lcd_set_level(video, level);
321 static const struct thermal_cooling_device_ops video_cooling_ops = {
322 .get_max_state = video_get_max_state,
323 .get_cur_state = video_get_cur_state,
324 .set_cur_state = video_set_cur_state,
328 * --------------------------------------------------------------------------
330 * --------------------------------------------------------------------------
334 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
335 union acpi_object **levels)
338 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
339 union acpi_object *obj;
344 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
345 if (!ACPI_SUCCESS(status))
347 obj = (union acpi_object *)buffer.pointer;
348 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
349 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
359 kfree(buffer.pointer);
365 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
370 status = acpi_execute_simple_method(device->dev->handle,
372 if (ACPI_FAILURE(status)) {
373 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
377 device->brightness->curr = level;
378 for (state = 2; state < device->brightness->count; state++)
379 if (level == device->brightness->levels[state]) {
380 if (device->backlight)
381 device->backlight->props.brightness = state - 2;
385 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
390 * For some buggy _BQC methods, we need to add a constant value to
391 * the _BQC return value to get the actual current brightness level
394 static int bqc_offset_aml_bug_workaround;
395 static int __init video_set_bqc_offset(const struct dmi_system_id *d)
397 bqc_offset_aml_bug_workaround = 9;
401 static struct dmi_system_id video_dmi_table[] __initdata = {
403 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
406 .callback = video_set_bqc_offset,
407 .ident = "Acer Aspire 5720",
409 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
410 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"),
414 .callback = video_set_bqc_offset,
415 .ident = "Acer Aspire 5710Z",
417 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"),
422 .callback = video_set_bqc_offset,
423 .ident = "eMachines E510",
425 DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"),
426 DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"),
430 .callback = video_set_bqc_offset,
431 .ident = "Acer Aspire 5315",
433 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
434 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"),
438 .callback = video_set_bqc_offset,
439 .ident = "Acer Aspire 7720",
441 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
442 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"),
448 static unsigned long long
449 acpi_video_bqc_value_to_level(struct acpi_video_device *device,
450 unsigned long long bqc_value)
452 unsigned long long level;
454 if (device->brightness->flags._BQC_use_index) {
456 * _BQC returns an index that doesn't account for
457 * the first 2 items with special meaning, so we need
458 * to compensate for that by offsetting ourselves
460 if (device->brightness->flags._BCL_reversed)
461 bqc_value = device->brightness->count - 3 - bqc_value;
463 level = device->brightness->levels[bqc_value + 2];
468 level += bqc_offset_aml_bug_workaround;
474 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
475 unsigned long long *level, bool raw)
477 acpi_status status = AE_OK;
480 if (device->cap._BQC || device->cap._BCQ) {
481 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
483 status = acpi_evaluate_integer(device->dev->handle, buf,
485 if (ACPI_SUCCESS(status)) {
488 * Caller has indicated he wants the raw
489 * value returned by _BQC, so don't furtherly
490 * mess with the value.
495 *level = acpi_video_bqc_value_to_level(device, *level);
497 for (i = 2; i < device->brightness->count; i++)
498 if (device->brightness->levels[i] == *level) {
499 device->brightness->curr = *level;
503 * BQC returned an invalid level.
506 ACPI_WARNING((AE_INFO,
507 "%s returned an invalid level",
509 device->cap._BQC = device->cap._BCQ = 0;
513 * should we return an error or ignore this failure?
514 * dev->brightness->curr is a cached value which stores
515 * the correct current backlight level in most cases.
516 * ACPI video backlight still works w/ buggy _BQC.
517 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
519 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
520 device->cap._BQC = device->cap._BCQ = 0;
524 *level = device->brightness->curr;
529 acpi_video_device_EDID(struct acpi_video_device *device,
530 union acpi_object **edid, ssize_t length)
533 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
534 union acpi_object *obj;
535 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
536 struct acpi_object_list args = { 1, &arg0 };
544 arg0.integer.value = 1;
545 else if (length == 256)
546 arg0.integer.value = 2;
550 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
551 if (ACPI_FAILURE(status))
554 obj = buffer.pointer;
556 if (obj && obj->type == ACPI_TYPE_BUFFER)
559 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
571 * video : video bus device pointer
573 * 0. The system BIOS should NOT automatically switch(toggle)
574 * the active display output.
575 * 1. The system BIOS should automatically switch (toggle) the
576 * active display output. No switch event.
577 * 2. The _DGS value should be locked.
578 * 3. The system BIOS should not automatically switch (toggle) the
579 * active display output, but instead generate the display switch
582 * 0. The system BIOS should automatically control the brightness level
583 * of the LCD when the power changes from AC to DC
584 * 1. The system BIOS should NOT automatically control the brightness
585 * level of the LCD when the power changes from AC to DC.
591 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
595 if (!video->cap._DOS)
598 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1)
600 video->dos_setting = (lcd_flag << 2) | bios_flag;
601 status = acpi_execute_simple_method(video->device->handle, "_DOS",
602 (lcd_flag << 2) | bios_flag);
603 if (ACPI_FAILURE(status))
610 * Simple comparison function used to sort backlight levels.
614 acpi_video_cmp_level(const void *a, const void *b)
616 return *(int *)a - *(int *)b;
620 * Decides if _BQC/_BCQ for this system is usable
622 * We do this by changing the level first and then read out the current
623 * brightness level, if the value does not match, find out if it is using
624 * index. If not, clear the _BQC/_BCQ capability.
626 static int acpi_video_bqc_quirk(struct acpi_video_device *device,
627 int max_level, int current_level)
629 struct acpi_video_device_brightness *br = device->brightness;
631 unsigned long long level;
634 /* don't mess with existing known broken systems */
635 if (bqc_offset_aml_bug_workaround)
639 * Some systems always report current brightness level as maximum
640 * through _BQC, we need to test another value for them.
642 test_level = current_level == max_level ? br->levels[3] : max_level;
644 result = acpi_video_device_lcd_set_level(device, test_level);
648 result = acpi_video_device_lcd_get_level_current(device, &level, true);
652 if (level != test_level) {
653 /* buggy _BQC found, need to find out if it uses index */
654 if (level < br->count) {
655 if (br->flags._BCL_reversed)
656 level = br->count - 3 - level;
657 if (br->levels[level + 2] == test_level)
658 br->flags._BQC_use_index = 1;
661 if (!br->flags._BQC_use_index)
662 device->cap._BQC = device->cap._BCQ = 0;
671 * device : video output device (LCD, CRT, ..)
674 * Maximum brightness level
676 * Allocate and initialize device->brightness.
680 acpi_video_init_brightness(struct acpi_video_device *device)
682 union acpi_object *obj = NULL;
683 int i, max_level = 0, count = 0, level_ac_battery = 0;
684 unsigned long long level, level_old;
685 union acpi_object *o;
686 struct acpi_video_device_brightness *br = NULL;
687 int result = -EINVAL;
690 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
691 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
692 "LCD brightness level\n"));
696 if (obj->package.count < 2)
699 br = kzalloc(sizeof(*br), GFP_KERNEL);
701 printk(KERN_ERR "can't allocate memory\n");
706 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
713 for (i = 0; i < obj->package.count; i++) {
714 o = (union acpi_object *)&obj->package.elements[i];
715 if (o->type != ACPI_TYPE_INTEGER) {
716 printk(KERN_ERR PREFIX "Invalid data\n");
719 value = (u32) o->integer.value;
720 /* Skip duplicate entries */
721 if (count > 2 && br->levels[count - 1] == value)
724 br->levels[count] = value;
726 if (br->levels[count] > max_level)
727 max_level = br->levels[count];
732 * some buggy BIOS don't export the levels
733 * when machine is on AC/Battery in _BCL package.
734 * In this case, the first two elements in _BCL packages
735 * are also supported brightness levels that OS should take care of.
737 for (i = 2; i < count; i++) {
738 if (br->levels[i] == br->levels[0])
740 if (br->levels[i] == br->levels[1])
744 if (level_ac_battery < 2) {
745 level_ac_battery = 2 - level_ac_battery;
746 br->flags._BCL_no_ac_battery_levels = 1;
747 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
748 br->levels[i] = br->levels[i - level_ac_battery];
749 count += level_ac_battery;
750 } else if (level_ac_battery > 2)
751 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package"));
753 /* Check if the _BCL package is in a reversed order */
754 if (max_level == br->levels[2]) {
755 br->flags._BCL_reversed = 1;
756 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
757 acpi_video_cmp_level, NULL);
758 } else if (max_level != br->levels[count - 1])
760 "Found unordered _BCL package"));
763 device->brightness = br;
765 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
766 br->curr = level = max_level;
768 if (!device->cap._BQC)
771 result = acpi_video_device_lcd_get_level_current(device,
774 goto out_free_levels;
776 result = acpi_video_bqc_quirk(device, max_level, level_old);
778 goto out_free_levels;
780 * cap._BQC may get cleared due to _BQC is found to be broken
781 * in acpi_video_bqc_quirk, so check again here.
783 if (!device->cap._BQC)
786 level = acpi_video_bqc_value_to_level(device, level_old);
788 * On some buggy laptops, _BQC returns an uninitialized
789 * value when invoked for the first time, i.e.
790 * level_old is invalid (no matter whether it's a level
791 * or an index). Set the backlight to max_level in this case.
793 for (i = 2; i < br->count; i++)
794 if (level == br->levels[i])
796 if (i == br->count || !level)
800 result = acpi_video_device_lcd_set_level(device, level);
802 goto out_free_levels;
804 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
805 "found %d brightness levels\n", count - 2));
814 device->brightness = NULL;
821 * device : video output device (LCD, CRT, ..)
826 * Find out all required AML methods defined under the output
830 static void acpi_video_device_find_cap(struct acpi_video_device *device)
832 if (acpi_has_method(device->dev->handle, "_ADR"))
833 device->cap._ADR = 1;
834 if (acpi_has_method(device->dev->handle, "_BCL"))
835 device->cap._BCL = 1;
836 if (acpi_has_method(device->dev->handle, "_BCM"))
837 device->cap._BCM = 1;
838 if (acpi_has_method(device->dev->handle, "_BQC")) {
839 device->cap._BQC = 1;
840 } else if (acpi_has_method(device->dev->handle, "_BCQ")) {
841 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
842 device->cap._BCQ = 1;
845 if (acpi_has_method(device->dev->handle, "_DDC"))
846 device->cap._DDC = 1;
851 * device : video output device (VGA)
856 * Find out all required AML methods defined under the video bus device.
859 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
861 if (acpi_has_method(video->device->handle, "_DOS"))
863 if (acpi_has_method(video->device->handle, "_DOD"))
865 if (acpi_has_method(video->device->handle, "_ROM"))
867 if (acpi_has_method(video->device->handle, "_GPD"))
869 if (acpi_has_method(video->device->handle, "_SPD"))
871 if (acpi_has_method(video->device->handle, "_VPO"))
876 * Check whether the video bus device has required AML method to
877 * support the desired features
880 static int acpi_video_bus_check(struct acpi_video_bus *video)
882 acpi_status status = -ENOENT;
888 dev = acpi_get_pci_dev(video->device->handle);
894 * Since there is no HID, CID and so on for VGA driver, we have
895 * to check well known required nodes.
898 /* Does this device support video switching? */
899 if (video->cap._DOS || video->cap._DOD) {
900 if (!video->cap._DOS) {
901 printk(KERN_WARNING FW_BUG
902 "ACPI(%s) defines _DOD but not _DOS\n",
903 acpi_device_bid(video->device));
905 video->flags.multihead = 1;
909 /* Does this device support retrieving a video ROM? */
910 if (video->cap._ROM) {
911 video->flags.rom = 1;
915 /* Does this device support configuring which video device to POST? */
916 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
917 video->flags.post = 1;
925 * --------------------------------------------------------------------------
927 * --------------------------------------------------------------------------
930 /* device interface */
931 static struct acpi_video_device_attrib *
932 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
934 struct acpi_video_enumerated_device *ids;
937 for (i = 0; i < video->attached_count; i++) {
938 ids = &video->attached_array[i];
939 if ((ids->value.int_val & 0xffff) == device_id)
940 return &ids->value.attrib;
947 acpi_video_get_device_type(struct acpi_video_bus *video,
948 unsigned long device_id)
950 struct acpi_video_enumerated_device *ids;
953 for (i = 0; i < video->attached_count; i++) {
954 ids = &video->attached_array[i];
955 if ((ids->value.int_val & 0xffff) == device_id)
956 return ids->value.int_val;
963 acpi_video_bus_get_one_device(struct acpi_device *device,
964 struct acpi_video_bus *video)
966 unsigned long long device_id;
967 int status, device_type;
968 struct acpi_video_device *data;
969 struct acpi_video_device_attrib *attribute;
972 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
973 /* Some device omits _ADR, we skip them instead of fail */
974 if (ACPI_FAILURE(status))
977 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
981 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
982 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
983 device->driver_data = data;
985 data->device_id = device_id;
989 attribute = acpi_video_get_device_attr(video, device_id);
991 if (attribute && attribute->device_id_scheme) {
992 switch (attribute->display_type) {
993 case ACPI_VIDEO_DISPLAY_CRT:
996 case ACPI_VIDEO_DISPLAY_TV:
997 data->flags.tvout = 1;
999 case ACPI_VIDEO_DISPLAY_DVI:
1000 data->flags.dvi = 1;
1002 case ACPI_VIDEO_DISPLAY_LCD:
1003 data->flags.lcd = 1;
1006 data->flags.unknown = 1;
1009 if (attribute->bios_can_detect)
1010 data->flags.bios = 1;
1012 /* Check for legacy IDs */
1013 device_type = acpi_video_get_device_type(video, device_id);
1014 /* Ignore bits 16 and 18-20 */
1015 switch (device_type & 0xffe2ffff) {
1016 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR:
1017 data->flags.crt = 1;
1019 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL:
1020 data->flags.lcd = 1;
1022 case ACPI_VIDEO_DISPLAY_LEGACY_TV:
1023 data->flags.tvout = 1;
1026 data->flags.unknown = 1;
1030 acpi_video_device_bind(video, data);
1031 acpi_video_device_find_cap(data);
1033 mutex_lock(&video->device_list_lock);
1034 list_add_tail(&data->entry, &video->video_device_list);
1035 mutex_unlock(&video->device_list_lock);
1042 * video : video bus device
1047 * Enumerate the video device list of the video bus,
1048 * bind the ids with the corresponding video devices
1049 * under the video bus.
1052 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1054 struct acpi_video_device *dev;
1056 mutex_lock(&video->device_list_lock);
1058 list_for_each_entry(dev, &video->video_device_list, entry)
1059 acpi_video_device_bind(video, dev);
1061 mutex_unlock(&video->device_list_lock);
1066 * video : video bus device
1067 * device : video output device under the video
1073 * Bind the ids with the corresponding video devices
1074 * under the video bus.
1078 acpi_video_device_bind(struct acpi_video_bus *video,
1079 struct acpi_video_device *device)
1081 struct acpi_video_enumerated_device *ids;
1084 for (i = 0; i < video->attached_count; i++) {
1085 ids = &video->attached_array[i];
1086 if (device->device_id == (ids->value.int_val & 0xffff)) {
1087 ids->bind_info = device;
1088 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1095 * video : video bus device
1100 * Call _DOD to enumerate all devices attached to display adapter
1104 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1109 struct acpi_video_enumerated_device *active_list;
1110 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1111 union acpi_object *dod = NULL;
1112 union acpi_object *obj;
1114 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1115 if (!ACPI_SUCCESS(status)) {
1116 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1120 dod = buffer.pointer;
1121 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1122 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1127 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1128 dod->package.count));
1130 active_list = kcalloc(1 + dod->package.count,
1131 sizeof(struct acpi_video_enumerated_device),
1139 for (i = 0; i < dod->package.count; i++) {
1140 obj = &dod->package.elements[i];
1142 if (obj->type != ACPI_TYPE_INTEGER) {
1143 printk(KERN_ERR PREFIX
1144 "Invalid _DOD data in element %d\n", i);
1148 active_list[count].value.int_val = obj->integer.value;
1149 active_list[count].bind_info = NULL;
1150 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1151 (int)obj->integer.value));
1155 kfree(video->attached_array);
1157 video->attached_array = active_list;
1158 video->attached_count = count;
1161 kfree(buffer.pointer);
1166 acpi_video_get_next_level(struct acpi_video_device *device,
1167 u32 level_current, u32 event)
1169 int min, max, min_above, max_below, i, l, delta = 255;
1170 max = max_below = 0;
1171 min = min_above = 255;
1172 /* Find closest level to level_current */
1173 for (i = 2; i < device->brightness->count; i++) {
1174 l = device->brightness->levels[i];
1175 if (abs(l - level_current) < abs(delta)) {
1176 delta = l - level_current;
1181 /* Ajust level_current to closest available level */
1182 level_current += delta;
1183 for (i = 2; i < device->brightness->count; i++) {
1184 l = device->brightness->levels[i];
1189 if (l < min_above && l > level_current)
1191 if (l > max_below && l < level_current)
1196 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1197 return (level_current < max) ? min_above : min;
1198 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1199 return (level_current < max) ? min_above : max;
1200 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1201 return (level_current > min) ? max_below : min;
1202 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1203 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1206 return level_current;
1211 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1213 unsigned long long level_current, level_next;
1214 int result = -EINVAL;
1216 /* no warning message if acpi_backlight=vendor or a quirk is used */
1217 if (!acpi_video_verify_backlight_support())
1220 if (!device->brightness)
1223 result = acpi_video_device_lcd_get_level_current(device,
1229 level_next = acpi_video_get_next_level(device, level_current, event);
1231 result = acpi_video_device_lcd_set_level(device, level_next);
1234 backlight_force_update(device->backlight,
1235 BACKLIGHT_UPDATE_HOTKEY);
1239 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1244 int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
1247 struct acpi_video_bus *video;
1248 struct acpi_video_device *video_device;
1249 union acpi_object *buffer = NULL;
1253 if (!device || !acpi_driver_data(device))
1256 video = acpi_driver_data(device);
1258 for (i = 0; i < video->attached_count; i++) {
1259 video_device = video->attached_array[i].bind_info;
1265 if (!video_device->cap._DDC)
1270 case ACPI_VIDEO_DISPLAY_CRT:
1271 if (!video_device->flags.crt)
1274 case ACPI_VIDEO_DISPLAY_TV:
1275 if (!video_device->flags.tvout)
1278 case ACPI_VIDEO_DISPLAY_DVI:
1279 if (!video_device->flags.dvi)
1282 case ACPI_VIDEO_DISPLAY_LCD:
1283 if (!video_device->flags.lcd)
1287 } else if (video_device->device_id != device_id) {
1291 status = acpi_video_device_EDID(video_device, &buffer, length);
1293 if (ACPI_FAILURE(status) || !buffer ||
1294 buffer->type != ACPI_TYPE_BUFFER) {
1296 status = acpi_video_device_EDID(video_device, &buffer,
1298 if (ACPI_FAILURE(status) || !buffer ||
1299 buffer->type != ACPI_TYPE_BUFFER) {
1304 *edid = buffer->buffer.pointer;
1310 EXPORT_SYMBOL(acpi_video_get_edid);
1313 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1314 struct acpi_device *device)
1317 struct acpi_device *dev;
1320 * There are systems where video module known to work fine regardless
1321 * of broken _DOD and ignoring returned value here doesn't cause
1324 acpi_video_device_enumerate(video);
1326 list_for_each_entry(dev, &device->children, node) {
1328 status = acpi_video_bus_get_one_device(dev, video);
1330 dev_err(&dev->dev, "Can't attach device\n");
1337 /* acpi_video interface */
1340 * Win8 requires setting bit2 of _DOS to let firmware know it shouldn't
1341 * preform any automatic brightness change on receiving a notification.
1343 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1345 return acpi_video_bus_DOS(video, 0,
1346 acpi_osi_is_win8() ? 1 : 0);
1349 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1351 return acpi_video_bus_DOS(video, 0,
1352 acpi_osi_is_win8() ? 0 : 1);
1355 static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1357 struct acpi_video_bus *video = acpi_driver_data(device);
1358 struct input_dev *input;
1361 if (!video || !video->input)
1364 input = video->input;
1367 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1368 * most likely via hotkey. */
1369 keycode = KEY_SWITCHVIDEOMODE;
1372 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1374 acpi_video_device_enumerate(video);
1375 acpi_video_device_rebind(video);
1376 keycode = KEY_SWITCHVIDEOMODE;
1379 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1380 keycode = KEY_SWITCHVIDEOMODE;
1382 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1383 keycode = KEY_VIDEO_NEXT;
1385 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1386 keycode = KEY_VIDEO_PREV;
1390 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1391 "Unsupported event [0x%x]\n", event));
1395 if (acpi_notifier_call_chain(device, event, 0))
1396 /* Something vetoed the keypress. */
1400 input_report_key(input, keycode, 1);
1402 input_report_key(input, keycode, 0);
1409 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1411 struct acpi_video_device *video_device = data;
1412 struct acpi_device *device = NULL;
1413 struct acpi_video_bus *bus;
1414 struct input_dev *input;
1420 device = video_device->dev;
1421 bus = video_device->video;
1425 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1426 if (brightness_switch_enabled)
1427 acpi_video_switch_brightness(video_device, event);
1428 keycode = KEY_BRIGHTNESS_CYCLE;
1430 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1431 if (brightness_switch_enabled)
1432 acpi_video_switch_brightness(video_device, event);
1433 keycode = KEY_BRIGHTNESSUP;
1435 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1436 if (brightness_switch_enabled)
1437 acpi_video_switch_brightness(video_device, event);
1438 keycode = KEY_BRIGHTNESSDOWN;
1440 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */
1441 if (brightness_switch_enabled)
1442 acpi_video_switch_brightness(video_device, event);
1443 keycode = KEY_BRIGHTNESS_ZERO;
1445 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1446 if (brightness_switch_enabled)
1447 acpi_video_switch_brightness(video_device, event);
1448 keycode = KEY_DISPLAY_OFF;
1451 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1452 "Unsupported event [0x%x]\n", event));
1456 acpi_notifier_call_chain(device, event, 0);
1459 input_report_key(input, keycode, 1);
1461 input_report_key(input, keycode, 0);
1468 static int acpi_video_resume(struct notifier_block *nb,
1469 unsigned long val, void *ign)
1471 struct acpi_video_bus *video;
1472 struct acpi_video_device *video_device;
1476 case PM_HIBERNATION_PREPARE:
1477 case PM_SUSPEND_PREPARE:
1478 case PM_RESTORE_PREPARE:
1482 video = container_of(nb, struct acpi_video_bus, pm_nb);
1484 dev_info(&video->device->dev, "Restoring backlight state\n");
1486 for (i = 0; i < video->attached_count; i++) {
1487 video_device = video->attached_array[i].bind_info;
1488 if (video_device && video_device->backlight)
1489 acpi_video_set_brightness(video_device->backlight);
1496 acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
1497 void **return_value)
1499 struct acpi_device *device = context;
1500 struct acpi_device *sibling;
1503 if (handle == device->handle)
1504 return AE_CTRL_TERMINATE;
1506 result = acpi_bus_get_device(handle, &sibling);
1510 if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME))
1511 return AE_ALREADY_EXISTS;
1516 static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
1518 if (acpi_video_verify_backlight_support()) {
1519 struct backlight_properties props;
1520 struct pci_dev *pdev;
1521 acpi_handle acpi_parent;
1522 struct device *parent = NULL;
1527 result = acpi_video_init_brightness(device);
1530 name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
1535 acpi_get_parent(device->dev->handle, &acpi_parent);
1537 pdev = acpi_get_pci_dev(acpi_parent);
1539 parent = &pdev->dev;
1543 memset(&props, 0, sizeof(struct backlight_properties));
1544 props.type = BACKLIGHT_FIRMWARE;
1545 props.max_brightness = device->brightness->count - 3;
1546 device->backlight = backlight_device_register(name,
1549 &acpi_backlight_ops,
1552 if (IS_ERR(device->backlight))
1556 * Save current brightness level in case we have to restore it
1557 * before acpi_video_device_lcd_set_level() is called next time.
1559 device->backlight->props.brightness =
1560 acpi_video_get_brightness(device->backlight);
1562 device->cooling_dev = thermal_cooling_device_register("LCD",
1563 device->dev, &video_cooling_ops);
1564 if (IS_ERR(device->cooling_dev)) {
1566 * Set cooling_dev to NULL so we don't crash trying to
1568 * Also, why the hell we are returning early and
1569 * not attempt to register video output if cooling
1570 * device registration failed?
1573 device->cooling_dev = NULL;
1577 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
1578 device->cooling_dev->id);
1579 result = sysfs_create_link(&device->dev->dev.kobj,
1580 &device->cooling_dev->device.kobj,
1583 printk(KERN_ERR PREFIX "Create sysfs link\n");
1584 result = sysfs_create_link(&device->cooling_dev->device.kobj,
1585 &device->dev->dev.kobj, "device");
1587 printk(KERN_ERR PREFIX "Create sysfs link\n");
1591 static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
1593 struct acpi_video_device *dev;
1595 mutex_lock(&video->device_list_lock);
1596 list_for_each_entry(dev, &video->video_device_list, entry)
1597 acpi_video_dev_register_backlight(dev);
1598 mutex_unlock(&video->device_list_lock);
1600 video->pm_nb.notifier_call = acpi_video_resume;
1601 video->pm_nb.priority = 0;
1602 return register_pm_notifier(&video->pm_nb);
1605 static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device)
1607 if (device->backlight) {
1608 backlight_device_unregister(device->backlight);
1609 device->backlight = NULL;
1611 if (device->brightness) {
1612 kfree(device->brightness->levels);
1613 kfree(device->brightness);
1614 device->brightness = NULL;
1616 if (device->cooling_dev) {
1617 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling");
1618 sysfs_remove_link(&device->cooling_dev->device.kobj, "device");
1619 thermal_cooling_device_unregister(device->cooling_dev);
1620 device->cooling_dev = NULL;
1624 static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video)
1626 struct acpi_video_device *dev;
1627 int error = unregister_pm_notifier(&video->pm_nb);
1629 mutex_lock(&video->device_list_lock);
1630 list_for_each_entry(dev, &video->video_device_list, entry)
1631 acpi_video_dev_unregister_backlight(dev);
1632 mutex_unlock(&video->device_list_lock);
1637 static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device)
1640 struct acpi_device *adev = device->dev;
1642 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
1643 acpi_video_device_notify, device);
1644 if (ACPI_FAILURE(status))
1645 dev_err(&adev->dev, "Error installing notify handler\n");
1647 device->flags.notify = 1;
1650 static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
1652 struct input_dev *input;
1653 struct acpi_video_device *dev;
1656 video->input = input = input_allocate_device();
1662 error = acpi_video_bus_start_devices(video);
1664 goto err_free_input;
1666 snprintf(video->phys, sizeof(video->phys),
1667 "%s/video/input0", acpi_device_hid(video->device));
1669 input->name = acpi_device_name(video->device);
1670 input->phys = video->phys;
1671 input->id.bustype = BUS_HOST;
1672 input->id.product = 0x06;
1673 input->dev.parent = &video->device->dev;
1674 input->evbit[0] = BIT(EV_KEY);
1675 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1676 set_bit(KEY_VIDEO_NEXT, input->keybit);
1677 set_bit(KEY_VIDEO_PREV, input->keybit);
1678 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1679 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1680 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1681 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1682 set_bit(KEY_DISPLAY_OFF, input->keybit);
1684 error = input_register_device(input);
1688 mutex_lock(&video->device_list_lock);
1689 list_for_each_entry(dev, &video->video_device_list, entry)
1690 acpi_video_dev_add_notify_handler(dev);
1691 mutex_unlock(&video->device_list_lock);
1696 acpi_video_bus_stop_devices(video);
1698 input_free_device(input);
1699 video->input = NULL;
1704 static void acpi_video_dev_remove_notify_handler(struct acpi_video_device *dev)
1706 if (dev->flags.notify) {
1707 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY,
1708 acpi_video_device_notify);
1709 dev->flags.notify = 0;
1713 static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
1715 struct acpi_video_device *dev;
1717 mutex_lock(&video->device_list_lock);
1718 list_for_each_entry(dev, &video->video_device_list, entry)
1719 acpi_video_dev_remove_notify_handler(dev);
1720 mutex_unlock(&video->device_list_lock);
1722 acpi_video_bus_stop_devices(video);
1723 input_unregister_device(video->input);
1724 video->input = NULL;
1727 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1729 struct acpi_video_device *dev, *next;
1731 mutex_lock(&video->device_list_lock);
1732 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1733 list_del(&dev->entry);
1736 mutex_unlock(&video->device_list_lock);
1741 static int instance;
1743 static int acpi_video_bus_add(struct acpi_device *device)
1745 struct acpi_video_bus *video;
1749 status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
1750 device->parent->handle, 1,
1751 acpi_video_bus_match, NULL,
1753 if (status == AE_ALREADY_EXISTS) {
1754 printk(KERN_WARNING FW_BUG
1755 "Duplicate ACPI video bus devices for the"
1756 " same VGA controller, please try module "
1757 "parameter \"video.allow_duplicates=1\""
1758 "if the current driver doesn't work.\n");
1759 if (!allow_duplicates)
1763 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1767 /* a hack to fix the duplicate name "VID" problem on T61 */
1768 if (!strcmp(device->pnp.bus_id, "VID")) {
1770 device->pnp.bus_id[3] = '0' + instance;
1773 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
1774 if (!strcmp(device->pnp.bus_id, "VGA")) {
1776 device->pnp.bus_id[3] = '0' + instance;
1780 video->device = device;
1781 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1782 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1783 device->driver_data = video;
1785 acpi_video_bus_find_cap(video);
1786 error = acpi_video_bus_check(video);
1788 goto err_free_video;
1790 mutex_init(&video->device_list_lock);
1791 INIT_LIST_HEAD(&video->video_device_list);
1793 error = acpi_video_bus_get_devices(video, device);
1797 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1798 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1799 video->flags.multihead ? "yes" : "no",
1800 video->flags.rom ? "yes" : "no",
1801 video->flags.post ? "yes" : "no");
1802 mutex_lock(&video_list_lock);
1803 list_add_tail(&video->entry, &video_bus_head);
1804 mutex_unlock(&video_list_lock);
1806 acpi_video_bus_register_backlight(video);
1807 acpi_video_bus_add_notify_handler(video);
1812 acpi_video_bus_put_devices(video);
1813 kfree(video->attached_array);
1816 device->driver_data = NULL;
1821 static int acpi_video_bus_remove(struct acpi_device *device)
1823 struct acpi_video_bus *video = NULL;
1826 if (!device || !acpi_driver_data(device))
1829 video = acpi_driver_data(device);
1831 acpi_video_bus_remove_notify_handler(video);
1832 acpi_video_bus_unregister_backlight(video);
1833 acpi_video_bus_put_devices(video);
1835 mutex_lock(&video_list_lock);
1836 list_del(&video->entry);
1837 mutex_unlock(&video_list_lock);
1839 kfree(video->attached_array);
1845 static int __init is_i740(struct pci_dev *dev)
1847 if (dev->device == 0x00D1)
1849 if (dev->device == 0x7000)
1854 static int __init intel_opregion_present(void)
1857 struct pci_dev *dev = NULL;
1860 for_each_pci_dev(dev) {
1861 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1863 if (dev->vendor != PCI_VENDOR_ID_INTEL)
1865 /* We don't want to poke around undefined i740 registers */
1868 pci_read_config_dword(dev, 0xfc, &address);
1876 int acpi_video_register(void)
1879 if (register_count) {
1881 * if the function of acpi_video_register is already called,
1882 * don't register the acpi_vide_bus again and return no error.
1887 mutex_init(&video_list_lock);
1888 INIT_LIST_HEAD(&video_bus_head);
1890 result = acpi_bus_register_driver(&acpi_video_bus);
1895 * When the acpi_video_bus is loaded successfully, increase
1896 * the counter reference.
1902 EXPORT_SYMBOL(acpi_video_register);
1904 void acpi_video_unregister(void)
1906 if (!register_count) {
1908 * If the acpi video bus is already unloaded, don't
1909 * unload it again and return directly.
1913 acpi_bus_unregister_driver(&acpi_video_bus);
1919 EXPORT_SYMBOL(acpi_video_unregister);
1922 * This is kind of nasty. Hardware using Intel chipsets may require
1923 * the video opregion code to be run first in order to initialise
1924 * state before any ACPI video calls are made. To handle this we defer
1925 * registration of the video class until the opregion code has run.
1928 static int __init acpi_video_init(void)
1930 dmi_check_system(video_dmi_table);
1932 if (intel_opregion_present())
1935 return acpi_video_register();
1938 static void __exit acpi_video_exit(void)
1940 acpi_video_unregister();
1945 module_init(acpi_video_init);
1946 module_exit(acpi_video_exit);