2 * video.c - ACPI Video Driver
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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/types.h>
27 #include <linux/list.h>
28 #include <linux/mutex.h>
29 #include <linux/input.h>
30 #include <linux/backlight.h>
31 #include <linux/thermal.h>
32 #include <linux/sort.h>
33 #include <linux/pci.h>
34 #include <linux/pci_ids.h>
35 #include <linux/slab.h>
36 #include <linux/dmi.h>
37 #include <linux/suspend.h>
38 #include <linux/acpi.h>
39 #include <acpi/video.h>
40 #include <asm/uaccess.h>
42 #define PREFIX "ACPI: "
44 #define ACPI_VIDEO_BUS_NAME "Video Bus"
45 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
46 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
47 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
48 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
49 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
50 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
52 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
53 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
54 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
55 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
56 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
58 #define MAX_NAME_LEN 20
60 #define _COMPONENT ACPI_VIDEO_COMPONENT
61 ACPI_MODULE_NAME("video");
63 MODULE_AUTHOR("Bruno Ducrot");
64 MODULE_DESCRIPTION("ACPI Video Driver");
65 MODULE_LICENSE("GPL");
67 static bool brightness_switch_enabled = 1;
68 module_param(brightness_switch_enabled, bool, 0644);
71 * By default, we don't allow duplicate ACPI video bus devices
72 * under the same VGA controller
74 static bool allow_duplicates;
75 module_param(allow_duplicates, bool, 0644);
77 static int disable_backlight_sysfs_if = -1;
78 module_param(disable_backlight_sysfs_if, int, 0444);
80 static int register_count;
81 static DEFINE_MUTEX(register_count_mutex);
82 static struct mutex video_list_lock;
83 static struct list_head video_bus_head;
84 static int acpi_video_bus_add(struct acpi_device *device);
85 static int acpi_video_bus_remove(struct acpi_device *device);
86 static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
87 void acpi_video_detect_exit(void);
89 static const struct acpi_device_id video_device_ids[] = {
93 MODULE_DEVICE_TABLE(acpi, video_device_ids);
95 static struct acpi_driver acpi_video_bus = {
97 .class = ACPI_VIDEO_CLASS,
98 .ids = video_device_ids,
100 .add = acpi_video_bus_add,
101 .remove = acpi_video_bus_remove,
102 .notify = acpi_video_bus_notify,
106 struct acpi_video_bus_flags {
107 u8 multihead:1; /* can switch video heads */
108 u8 rom:1; /* can retrieve a video rom */
109 u8 post:1; /* can configure the head to */
113 struct acpi_video_bus_cap {
114 u8 _DOS:1; /* Enable/Disable output switching */
115 u8 _DOD:1; /* Enumerate all devices attached to display adapter */
116 u8 _ROM:1; /* Get ROM Data */
117 u8 _GPD:1; /* Get POST Device */
118 u8 _SPD:1; /* Set POST Device */
119 u8 _VPO:1; /* Video POST Options */
123 struct acpi_video_device_attrib {
124 u32 display_index:4; /* A zero-based instance of the Display */
125 u32 display_port_attachment:4; /* This field differentiates the display type */
126 u32 display_type:4; /* Describe the specific type in use */
127 u32 vendor_specific:4; /* Chipset Vendor Specific */
128 u32 bios_can_detect:1; /* BIOS can detect the device */
129 u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
131 u32 pipe_id:3; /* For VGA multiple-head devices. */
132 u32 reserved:10; /* Must be 0 */
133 u32 device_id_scheme:1; /* Device ID Scheme */
136 struct acpi_video_enumerated_device {
139 struct acpi_video_device_attrib attrib;
141 struct acpi_video_device *bind_info;
144 struct acpi_video_bus {
145 struct acpi_device *device;
146 bool backlight_registered;
148 struct acpi_video_enumerated_device *attached_array;
151 struct acpi_video_bus_cap cap;
152 struct acpi_video_bus_flags flags;
153 struct list_head video_device_list;
154 struct mutex device_list_lock; /* protects video_device_list */
155 struct list_head entry;
156 struct input_dev *input;
157 char phys[32]; /* for input device */
158 struct notifier_block pm_nb;
161 struct acpi_video_device_flags {
172 struct acpi_video_device_cap {
173 u8 _ADR:1; /* Return the unique ID */
174 u8 _BCL:1; /* Query list of brightness control levels supported */
175 u8 _BCM:1; /* Set the brightness level */
176 u8 _BQC:1; /* Get current brightness level */
177 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
178 u8 _DDC:1; /* Return the EDID for this device */
181 struct acpi_video_brightness_flags {
182 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
183 u8 _BCL_reversed:1; /* _BCL package is in a reversed order */
184 u8 _BQC_use_index:1; /* _BQC returns an index value */
187 struct acpi_video_device_brightness {
191 struct acpi_video_brightness_flags flags;
194 struct acpi_video_device {
195 unsigned long device_id;
196 struct acpi_video_device_flags flags;
197 struct acpi_video_device_cap cap;
198 struct list_head entry;
199 struct delayed_work switch_brightness_work;
200 int switch_brightness_event;
201 struct acpi_video_bus *video;
202 struct acpi_device *dev;
203 struct acpi_video_device_brightness *brightness;
204 struct backlight_device *backlight;
205 struct thermal_cooling_device *cooling_dev;
208 static const char device_decode[][30] = {
209 "motherboard VGA device",
215 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
216 static void acpi_video_device_rebind(struct acpi_video_bus *video);
217 static void acpi_video_device_bind(struct acpi_video_bus *video,
218 struct acpi_video_device *device);
219 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
220 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
222 static int acpi_video_device_lcd_get_level_current(
223 struct acpi_video_device *device,
224 unsigned long long *level, bool raw);
225 static int acpi_video_get_next_level(struct acpi_video_device *device,
226 u32 level_current, u32 event);
227 static void acpi_video_switch_brightness(struct work_struct *work);
229 /* backlight device sysfs support */
230 static int acpi_video_get_brightness(struct backlight_device *bd)
232 unsigned long long cur_level;
234 struct acpi_video_device *vd = bl_get_data(bd);
236 if (acpi_video_device_lcd_get_level_current(vd, &cur_level, false))
238 for (i = 2; i < vd->brightness->count; i++) {
239 if (vd->brightness->levels[i] == cur_level)
241 * The first two entries are special - see page 575
242 * of the ACPI spec 3.0
249 static int acpi_video_set_brightness(struct backlight_device *bd)
251 int request_level = bd->props.brightness + 2;
252 struct acpi_video_device *vd = bl_get_data(bd);
254 cancel_delayed_work(&vd->switch_brightness_work);
255 return acpi_video_device_lcd_set_level(vd,
256 vd->brightness->levels[request_level]);
259 static const struct backlight_ops acpi_backlight_ops = {
260 .get_brightness = acpi_video_get_brightness,
261 .update_status = acpi_video_set_brightness,
264 /* thermal cooling device callbacks */
265 static int video_get_max_state(struct thermal_cooling_device *cooling_dev, unsigned
268 struct acpi_device *device = cooling_dev->devdata;
269 struct acpi_video_device *video = acpi_driver_data(device);
271 *state = video->brightness->count - 3;
275 static int video_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned
278 struct acpi_device *device = cooling_dev->devdata;
279 struct acpi_video_device *video = acpi_driver_data(device);
280 unsigned long long level;
283 if (acpi_video_device_lcd_get_level_current(video, &level, false))
285 for (offset = 2; offset < video->brightness->count; offset++)
286 if (level == video->brightness->levels[offset]) {
287 *state = video->brightness->count - offset - 1;
295 video_set_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long state)
297 struct acpi_device *device = cooling_dev->devdata;
298 struct acpi_video_device *video = acpi_driver_data(device);
301 if (state >= video->brightness->count - 2)
304 state = video->brightness->count - state;
305 level = video->brightness->levels[state - 1];
306 return acpi_video_device_lcd_set_level(video, level);
309 static const struct thermal_cooling_device_ops video_cooling_ops = {
310 .get_max_state = video_get_max_state,
311 .get_cur_state = video_get_cur_state,
312 .set_cur_state = video_set_cur_state,
316 * --------------------------------------------------------------------------
318 * --------------------------------------------------------------------------
322 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
323 union acpi_object **levels)
326 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
327 union acpi_object *obj;
332 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
333 if (!ACPI_SUCCESS(status))
335 obj = (union acpi_object *)buffer.pointer;
336 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
337 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
347 kfree(buffer.pointer);
353 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
358 status = acpi_execute_simple_method(device->dev->handle,
360 if (ACPI_FAILURE(status)) {
361 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
365 device->brightness->curr = level;
366 for (state = 2; state < device->brightness->count; state++)
367 if (level == device->brightness->levels[state]) {
368 if (device->backlight)
369 device->backlight->props.brightness = state - 2;
373 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
378 * For some buggy _BQC methods, we need to add a constant value to
379 * the _BQC return value to get the actual current brightness level
382 static int bqc_offset_aml_bug_workaround;
383 static int video_set_bqc_offset(const struct dmi_system_id *d)
385 bqc_offset_aml_bug_workaround = 9;
389 static int video_disable_backlight_sysfs_if(
390 const struct dmi_system_id *d)
392 if (disable_backlight_sysfs_if == -1)
393 disable_backlight_sysfs_if = 1;
397 static struct dmi_system_id video_dmi_table[] = {
399 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
402 .callback = video_set_bqc_offset,
403 .ident = "Acer Aspire 5720",
405 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
406 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"),
410 .callback = video_set_bqc_offset,
411 .ident = "Acer Aspire 5710Z",
413 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
414 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"),
418 .callback = video_set_bqc_offset,
419 .ident = "eMachines E510",
421 DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"),
422 DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"),
426 .callback = video_set_bqc_offset,
427 .ident = "Acer Aspire 5315",
429 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
430 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"),
434 .callback = video_set_bqc_offset,
435 .ident = "Acer Aspire 7720",
437 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"),
443 * Some machines have a broken acpi-video interface for brightness
444 * control, but still need an acpi_video_device_lcd_set_level() call
445 * on resume to turn the backlight power on. We Enable backlight
446 * control on these systems, but do not register a backlight sysfs
447 * as brightness control does not work.
450 /* https://bugs.freedesktop.org/show_bug.cgi?id=82634 */
451 .callback = video_disable_backlight_sysfs_if,
452 .ident = "Toshiba Portege R830",
454 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
455 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R830"),
461 static unsigned long long
462 acpi_video_bqc_value_to_level(struct acpi_video_device *device,
463 unsigned long long bqc_value)
465 unsigned long long level;
467 if (device->brightness->flags._BQC_use_index) {
469 * _BQC returns an index that doesn't account for
470 * the first 2 items with special meaning, so we need
471 * to compensate for that by offsetting ourselves
473 if (device->brightness->flags._BCL_reversed)
474 bqc_value = device->brightness->count - 3 - bqc_value;
476 level = device->brightness->levels[bqc_value + 2];
481 level += bqc_offset_aml_bug_workaround;
487 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
488 unsigned long long *level, bool raw)
490 acpi_status status = AE_OK;
493 if (device->cap._BQC || device->cap._BCQ) {
494 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
496 status = acpi_evaluate_integer(device->dev->handle, buf,
498 if (ACPI_SUCCESS(status)) {
501 * Caller has indicated he wants the raw
502 * value returned by _BQC, so don't furtherly
503 * mess with the value.
508 *level = acpi_video_bqc_value_to_level(device, *level);
510 for (i = 2; i < device->brightness->count; i++)
511 if (device->brightness->levels[i] == *level) {
512 device->brightness->curr = *level;
516 * BQC returned an invalid level.
519 ACPI_WARNING((AE_INFO,
520 "%s returned an invalid level",
522 device->cap._BQC = device->cap._BCQ = 0;
526 * should we return an error or ignore this failure?
527 * dev->brightness->curr is a cached value which stores
528 * the correct current backlight level in most cases.
529 * ACPI video backlight still works w/ buggy _BQC.
530 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
532 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
533 device->cap._BQC = device->cap._BCQ = 0;
537 *level = device->brightness->curr;
542 acpi_video_device_EDID(struct acpi_video_device *device,
543 union acpi_object **edid, ssize_t length)
546 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
547 union acpi_object *obj;
548 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
549 struct acpi_object_list args = { 1, &arg0 };
557 arg0.integer.value = 1;
558 else if (length == 256)
559 arg0.integer.value = 2;
563 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
564 if (ACPI_FAILURE(status))
567 obj = buffer.pointer;
569 if (obj && obj->type == ACPI_TYPE_BUFFER)
572 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
584 * video : video bus device pointer
586 * 0. The system BIOS should NOT automatically switch(toggle)
587 * the active display output.
588 * 1. The system BIOS should automatically switch (toggle) the
589 * active display output. No switch event.
590 * 2. The _DGS value should be locked.
591 * 3. The system BIOS should not automatically switch (toggle) the
592 * active display output, but instead generate the display switch
595 * 0. The system BIOS should automatically control the brightness level
596 * of the LCD when the power changes from AC to DC
597 * 1. The system BIOS should NOT automatically control the brightness
598 * level of the LCD when the power changes from AC to DC.
604 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
608 if (!video->cap._DOS)
611 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1)
613 video->dos_setting = (lcd_flag << 2) | bios_flag;
614 status = acpi_execute_simple_method(video->device->handle, "_DOS",
615 (lcd_flag << 2) | bios_flag);
616 if (ACPI_FAILURE(status))
623 * Simple comparison function used to sort backlight levels.
627 acpi_video_cmp_level(const void *a, const void *b)
629 return *(int *)a - *(int *)b;
633 * Decides if _BQC/_BCQ for this system is usable
635 * We do this by changing the level first and then read out the current
636 * brightness level, if the value does not match, find out if it is using
637 * index. If not, clear the _BQC/_BCQ capability.
639 static int acpi_video_bqc_quirk(struct acpi_video_device *device,
640 int max_level, int current_level)
642 struct acpi_video_device_brightness *br = device->brightness;
644 unsigned long long level;
647 /* don't mess with existing known broken systems */
648 if (bqc_offset_aml_bug_workaround)
652 * Some systems always report current brightness level as maximum
653 * through _BQC, we need to test another value for them.
655 test_level = current_level == max_level ? br->levels[3] : max_level;
657 result = acpi_video_device_lcd_set_level(device, test_level);
661 result = acpi_video_device_lcd_get_level_current(device, &level, true);
665 if (level != test_level) {
666 /* buggy _BQC found, need to find out if it uses index */
667 if (level < br->count) {
668 if (br->flags._BCL_reversed)
669 level = br->count - 3 - level;
670 if (br->levels[level + 2] == test_level)
671 br->flags._BQC_use_index = 1;
674 if (!br->flags._BQC_use_index)
675 device->cap._BQC = device->cap._BCQ = 0;
684 * device : video output device (LCD, CRT, ..)
687 * Maximum brightness level
689 * Allocate and initialize device->brightness.
693 acpi_video_init_brightness(struct acpi_video_device *device)
695 union acpi_object *obj = NULL;
696 int i, max_level = 0, count = 0, level_ac_battery = 0;
697 unsigned long long level, level_old;
698 union acpi_object *o;
699 struct acpi_video_device_brightness *br = NULL;
700 int result = -EINVAL;
703 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
704 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
705 "LCD brightness level\n"));
709 if (obj->package.count < 2)
712 br = kzalloc(sizeof(*br), GFP_KERNEL);
714 printk(KERN_ERR "can't allocate memory\n");
719 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
726 for (i = 0; i < obj->package.count; i++) {
727 o = (union acpi_object *)&obj->package.elements[i];
728 if (o->type != ACPI_TYPE_INTEGER) {
729 printk(KERN_ERR PREFIX "Invalid data\n");
732 value = (u32) o->integer.value;
733 /* Skip duplicate entries */
734 if (count > 2 && br->levels[count - 1] == value)
737 br->levels[count] = value;
739 if (br->levels[count] > max_level)
740 max_level = br->levels[count];
745 * some buggy BIOS don't export the levels
746 * when machine is on AC/Battery in _BCL package.
747 * In this case, the first two elements in _BCL packages
748 * are also supported brightness levels that OS should take care of.
750 for (i = 2; i < count; i++) {
751 if (br->levels[i] == br->levels[0])
753 if (br->levels[i] == br->levels[1])
757 if (level_ac_battery < 2) {
758 level_ac_battery = 2 - level_ac_battery;
759 br->flags._BCL_no_ac_battery_levels = 1;
760 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
761 br->levels[i] = br->levels[i - level_ac_battery];
762 count += level_ac_battery;
763 } else if (level_ac_battery > 2)
764 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package"));
766 /* Check if the _BCL package is in a reversed order */
767 if (max_level == br->levels[2]) {
768 br->flags._BCL_reversed = 1;
769 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
770 acpi_video_cmp_level, NULL);
771 } else if (max_level != br->levels[count - 1])
773 "Found unordered _BCL package"));
776 device->brightness = br;
778 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
779 br->curr = level = max_level;
781 if (!device->cap._BQC)
784 result = acpi_video_device_lcd_get_level_current(device,
787 goto out_free_levels;
789 result = acpi_video_bqc_quirk(device, max_level, level_old);
791 goto out_free_levels;
793 * cap._BQC may get cleared due to _BQC is found to be broken
794 * in acpi_video_bqc_quirk, so check again here.
796 if (!device->cap._BQC)
799 level = acpi_video_bqc_value_to_level(device, level_old);
801 * On some buggy laptops, _BQC returns an uninitialized
802 * value when invoked for the first time, i.e.
803 * level_old is invalid (no matter whether it's a level
804 * or an index). Set the backlight to max_level in this case.
806 for (i = 2; i < br->count; i++)
807 if (level == br->levels[i])
809 if (i == br->count || !level)
813 result = acpi_video_device_lcd_set_level(device, level);
815 goto out_free_levels;
817 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
818 "found %d brightness levels\n", count - 2));
827 device->brightness = NULL;
834 * device : video output device (LCD, CRT, ..)
839 * Find out all required AML methods defined under the output
843 static void acpi_video_device_find_cap(struct acpi_video_device *device)
845 if (acpi_has_method(device->dev->handle, "_ADR"))
846 device->cap._ADR = 1;
847 if (acpi_has_method(device->dev->handle, "_BCL"))
848 device->cap._BCL = 1;
849 if (acpi_has_method(device->dev->handle, "_BCM"))
850 device->cap._BCM = 1;
851 if (acpi_has_method(device->dev->handle, "_BQC")) {
852 device->cap._BQC = 1;
853 } else if (acpi_has_method(device->dev->handle, "_BCQ")) {
854 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
855 device->cap._BCQ = 1;
858 if (acpi_has_method(device->dev->handle, "_DDC"))
859 device->cap._DDC = 1;
864 * device : video output device (VGA)
869 * Find out all required AML methods defined under the video bus device.
872 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
874 if (acpi_has_method(video->device->handle, "_DOS"))
876 if (acpi_has_method(video->device->handle, "_DOD"))
878 if (acpi_has_method(video->device->handle, "_ROM"))
880 if (acpi_has_method(video->device->handle, "_GPD"))
882 if (acpi_has_method(video->device->handle, "_SPD"))
884 if (acpi_has_method(video->device->handle, "_VPO"))
889 * Check whether the video bus device has required AML method to
890 * support the desired features
893 static int acpi_video_bus_check(struct acpi_video_bus *video)
895 acpi_status status = -ENOENT;
901 dev = acpi_get_pci_dev(video->device->handle);
907 * Since there is no HID, CID and so on for VGA driver, we have
908 * to check well known required nodes.
911 /* Does this device support video switching? */
912 if (video->cap._DOS || video->cap._DOD) {
913 if (!video->cap._DOS) {
914 printk(KERN_WARNING FW_BUG
915 "ACPI(%s) defines _DOD but not _DOS\n",
916 acpi_device_bid(video->device));
918 video->flags.multihead = 1;
922 /* Does this device support retrieving a video ROM? */
923 if (video->cap._ROM) {
924 video->flags.rom = 1;
928 /* Does this device support configuring which video device to POST? */
929 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
930 video->flags.post = 1;
938 * --------------------------------------------------------------------------
940 * --------------------------------------------------------------------------
943 /* device interface */
944 static struct acpi_video_device_attrib *
945 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
947 struct acpi_video_enumerated_device *ids;
950 for (i = 0; i < video->attached_count; i++) {
951 ids = &video->attached_array[i];
952 if ((ids->value.int_val & 0xffff) == device_id)
953 return &ids->value.attrib;
960 acpi_video_get_device_type(struct acpi_video_bus *video,
961 unsigned long device_id)
963 struct acpi_video_enumerated_device *ids;
966 for (i = 0; i < video->attached_count; i++) {
967 ids = &video->attached_array[i];
968 if ((ids->value.int_val & 0xffff) == device_id)
969 return ids->value.int_val;
976 acpi_video_bus_get_one_device(struct acpi_device *device,
977 struct acpi_video_bus *video)
979 unsigned long long device_id;
980 int status, device_type;
981 struct acpi_video_device *data;
982 struct acpi_video_device_attrib *attribute;
985 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
986 /* Some device omits _ADR, we skip them instead of fail */
987 if (ACPI_FAILURE(status))
990 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
994 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
995 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
996 device->driver_data = data;
998 data->device_id = device_id;
1001 INIT_DELAYED_WORK(&data->switch_brightness_work,
1002 acpi_video_switch_brightness);
1004 attribute = acpi_video_get_device_attr(video, device_id);
1006 if (attribute && attribute->device_id_scheme) {
1007 switch (attribute->display_type) {
1008 case ACPI_VIDEO_DISPLAY_CRT:
1009 data->flags.crt = 1;
1011 case ACPI_VIDEO_DISPLAY_TV:
1012 data->flags.tvout = 1;
1014 case ACPI_VIDEO_DISPLAY_DVI:
1015 data->flags.dvi = 1;
1017 case ACPI_VIDEO_DISPLAY_LCD:
1018 data->flags.lcd = 1;
1021 data->flags.unknown = 1;
1024 if (attribute->bios_can_detect)
1025 data->flags.bios = 1;
1027 /* Check for legacy IDs */
1028 device_type = acpi_video_get_device_type(video, device_id);
1029 /* Ignore bits 16 and 18-20 */
1030 switch (device_type & 0xffe2ffff) {
1031 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR:
1032 data->flags.crt = 1;
1034 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL:
1035 data->flags.lcd = 1;
1037 case ACPI_VIDEO_DISPLAY_LEGACY_TV:
1038 data->flags.tvout = 1;
1041 data->flags.unknown = 1;
1045 acpi_video_device_bind(video, data);
1046 acpi_video_device_find_cap(data);
1048 mutex_lock(&video->device_list_lock);
1049 list_add_tail(&data->entry, &video->video_device_list);
1050 mutex_unlock(&video->device_list_lock);
1057 * video : video bus device
1062 * Enumerate the video device list of the video bus,
1063 * bind the ids with the corresponding video devices
1064 * under the video bus.
1067 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1069 struct acpi_video_device *dev;
1071 mutex_lock(&video->device_list_lock);
1073 list_for_each_entry(dev, &video->video_device_list, entry)
1074 acpi_video_device_bind(video, dev);
1076 mutex_unlock(&video->device_list_lock);
1081 * video : video bus device
1082 * device : video output device under the video
1088 * Bind the ids with the corresponding video devices
1089 * under the video bus.
1093 acpi_video_device_bind(struct acpi_video_bus *video,
1094 struct acpi_video_device *device)
1096 struct acpi_video_enumerated_device *ids;
1099 for (i = 0; i < video->attached_count; i++) {
1100 ids = &video->attached_array[i];
1101 if (device->device_id == (ids->value.int_val & 0xffff)) {
1102 ids->bind_info = device;
1103 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1108 static bool acpi_video_device_in_dod(struct acpi_video_device *device)
1110 struct acpi_video_bus *video = device->video;
1114 * If we have a broken _DOD or we have more than 8 output devices
1115 * under the graphics controller node that we can't proper deal with
1116 * in the operation region code currently, no need to test.
1118 if (!video->attached_count || video->child_count > 8)
1121 for (i = 0; i < video->attached_count; i++) {
1122 if ((video->attached_array[i].value.int_val & 0xfff) ==
1123 (device->device_id & 0xfff))
1132 * video : video bus device
1137 * Call _DOD to enumerate all devices attached to display adapter
1141 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1146 struct acpi_video_enumerated_device *active_list;
1147 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1148 union acpi_object *dod = NULL;
1149 union acpi_object *obj;
1151 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1152 if (!ACPI_SUCCESS(status)) {
1153 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1157 dod = buffer.pointer;
1158 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1159 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1164 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1165 dod->package.count));
1167 active_list = kcalloc(1 + dod->package.count,
1168 sizeof(struct acpi_video_enumerated_device),
1176 for (i = 0; i < dod->package.count; i++) {
1177 obj = &dod->package.elements[i];
1179 if (obj->type != ACPI_TYPE_INTEGER) {
1180 printk(KERN_ERR PREFIX
1181 "Invalid _DOD data in element %d\n", i);
1185 active_list[count].value.int_val = obj->integer.value;
1186 active_list[count].bind_info = NULL;
1187 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1188 (int)obj->integer.value));
1192 kfree(video->attached_array);
1194 video->attached_array = active_list;
1195 video->attached_count = count;
1198 kfree(buffer.pointer);
1203 acpi_video_get_next_level(struct acpi_video_device *device,
1204 u32 level_current, u32 event)
1206 int min, max, min_above, max_below, i, l, delta = 255;
1207 max = max_below = 0;
1208 min = min_above = 255;
1209 /* Find closest level to level_current */
1210 for (i = 2; i < device->brightness->count; i++) {
1211 l = device->brightness->levels[i];
1212 if (abs(l - level_current) < abs(delta)) {
1213 delta = l - level_current;
1218 /* Ajust level_current to closest available level */
1219 level_current += delta;
1220 for (i = 2; i < device->brightness->count; i++) {
1221 l = device->brightness->levels[i];
1226 if (l < min_above && l > level_current)
1228 if (l > max_below && l < level_current)
1233 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1234 return (level_current < max) ? min_above : min;
1235 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1236 return (level_current < max) ? min_above : max;
1237 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1238 return (level_current > min) ? max_below : min;
1239 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1240 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1243 return level_current;
1248 acpi_video_switch_brightness(struct work_struct *work)
1250 struct acpi_video_device *device = container_of(to_delayed_work(work),
1251 struct acpi_video_device, switch_brightness_work);
1252 unsigned long long level_current, level_next;
1253 int event = device->switch_brightness_event;
1254 int result = -EINVAL;
1256 /* no warning message if acpi_backlight=vendor or a quirk is used */
1257 if (!device->backlight)
1260 if (!device->brightness)
1263 result = acpi_video_device_lcd_get_level_current(device,
1269 level_next = acpi_video_get_next_level(device, level_current, event);
1271 result = acpi_video_device_lcd_set_level(device, level_next);
1274 backlight_force_update(device->backlight,
1275 BACKLIGHT_UPDATE_HOTKEY);
1279 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1282 int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
1285 struct acpi_video_bus *video;
1286 struct acpi_video_device *video_device;
1287 union acpi_object *buffer = NULL;
1291 if (!device || !acpi_driver_data(device))
1294 video = acpi_driver_data(device);
1296 for (i = 0; i < video->attached_count; i++) {
1297 video_device = video->attached_array[i].bind_info;
1303 if (!video_device->cap._DDC)
1308 case ACPI_VIDEO_DISPLAY_CRT:
1309 if (!video_device->flags.crt)
1312 case ACPI_VIDEO_DISPLAY_TV:
1313 if (!video_device->flags.tvout)
1316 case ACPI_VIDEO_DISPLAY_DVI:
1317 if (!video_device->flags.dvi)
1320 case ACPI_VIDEO_DISPLAY_LCD:
1321 if (!video_device->flags.lcd)
1325 } else if (video_device->device_id != device_id) {
1329 status = acpi_video_device_EDID(video_device, &buffer, length);
1331 if (ACPI_FAILURE(status) || !buffer ||
1332 buffer->type != ACPI_TYPE_BUFFER) {
1334 status = acpi_video_device_EDID(video_device, &buffer,
1336 if (ACPI_FAILURE(status) || !buffer ||
1337 buffer->type != ACPI_TYPE_BUFFER) {
1342 *edid = buffer->buffer.pointer;
1348 EXPORT_SYMBOL(acpi_video_get_edid);
1351 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1352 struct acpi_device *device)
1355 struct acpi_device *dev;
1358 * There are systems where video module known to work fine regardless
1359 * of broken _DOD and ignoring returned value here doesn't cause
1362 acpi_video_device_enumerate(video);
1364 list_for_each_entry(dev, &device->children, node) {
1366 status = acpi_video_bus_get_one_device(dev, video);
1368 dev_err(&dev->dev, "Can't attach device\n");
1371 video->child_count++;
1376 /* acpi_video interface */
1379 * Win8 requires setting bit2 of _DOS to let firmware know it shouldn't
1380 * preform any automatic brightness change on receiving a notification.
1382 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1384 return acpi_video_bus_DOS(video, 0,
1385 acpi_osi_is_win8() ? 1 : 0);
1388 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1390 return acpi_video_bus_DOS(video, 0,
1391 acpi_osi_is_win8() ? 0 : 1);
1394 static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1396 struct acpi_video_bus *video = acpi_driver_data(device);
1397 struct input_dev *input;
1400 if (!video || !video->input)
1403 input = video->input;
1406 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1407 * most likely via hotkey. */
1408 keycode = KEY_SWITCHVIDEOMODE;
1411 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1413 acpi_video_device_enumerate(video);
1414 acpi_video_device_rebind(video);
1415 keycode = KEY_SWITCHVIDEOMODE;
1418 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1419 keycode = KEY_SWITCHVIDEOMODE;
1421 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1422 keycode = KEY_VIDEO_NEXT;
1424 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1425 keycode = KEY_VIDEO_PREV;
1429 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1430 "Unsupported event [0x%x]\n", event));
1434 if (acpi_notifier_call_chain(device, event, 0))
1435 /* Something vetoed the keypress. */
1439 input_report_key(input, keycode, 1);
1441 input_report_key(input, keycode, 0);
1448 static void brightness_switch_event(struct acpi_video_device *video_device,
1451 if (!brightness_switch_enabled)
1454 video_device->switch_brightness_event = event;
1455 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10);
1458 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1460 struct acpi_video_device *video_device = data;
1461 struct acpi_device *device = NULL;
1462 struct acpi_video_bus *bus;
1463 struct input_dev *input;
1469 device = video_device->dev;
1470 bus = video_device->video;
1474 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1475 brightness_switch_event(video_device, event);
1476 keycode = KEY_BRIGHTNESS_CYCLE;
1478 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1479 brightness_switch_event(video_device, event);
1480 keycode = KEY_BRIGHTNESSUP;
1482 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1483 brightness_switch_event(video_device, event);
1484 keycode = KEY_BRIGHTNESSDOWN;
1486 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */
1487 brightness_switch_event(video_device, event);
1488 keycode = KEY_BRIGHTNESS_ZERO;
1490 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1491 brightness_switch_event(video_device, event);
1492 keycode = KEY_DISPLAY_OFF;
1495 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1496 "Unsupported event [0x%x]\n", event));
1500 acpi_notifier_call_chain(device, event, 0);
1503 input_report_key(input, keycode, 1);
1505 input_report_key(input, keycode, 0);
1512 static int acpi_video_resume(struct notifier_block *nb,
1513 unsigned long val, void *ign)
1515 struct acpi_video_bus *video;
1516 struct acpi_video_device *video_device;
1520 case PM_HIBERNATION_PREPARE:
1521 case PM_SUSPEND_PREPARE:
1522 case PM_RESTORE_PREPARE:
1526 video = container_of(nb, struct acpi_video_bus, pm_nb);
1528 dev_info(&video->device->dev, "Restoring backlight state\n");
1530 for (i = 0; i < video->attached_count; i++) {
1531 video_device = video->attached_array[i].bind_info;
1532 if (video_device && video_device->brightness)
1533 acpi_video_device_lcd_set_level(video_device,
1534 video_device->brightness->curr);
1541 acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
1542 void **return_value)
1544 struct acpi_device *device = context;
1545 struct acpi_device *sibling;
1548 if (handle == device->handle)
1549 return AE_CTRL_TERMINATE;
1551 result = acpi_bus_get_device(handle, &sibling);
1555 if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME))
1556 return AE_ALREADY_EXISTS;
1561 static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
1563 struct backlight_properties props;
1564 struct pci_dev *pdev;
1565 acpi_handle acpi_parent;
1566 struct device *parent = NULL;
1572 * Do not create backlight device for video output
1573 * device that is not in the enumerated list.
1575 if (!acpi_video_device_in_dod(device)) {
1576 dev_dbg(&device->dev->dev, "not in _DOD list, ignore\n");
1580 result = acpi_video_init_brightness(device);
1584 if (disable_backlight_sysfs_if > 0)
1587 name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
1592 acpi_get_parent(device->dev->handle, &acpi_parent);
1594 pdev = acpi_get_pci_dev(acpi_parent);
1596 parent = &pdev->dev;
1600 memset(&props, 0, sizeof(struct backlight_properties));
1601 props.type = BACKLIGHT_FIRMWARE;
1602 props.max_brightness = device->brightness->count - 3;
1603 device->backlight = backlight_device_register(name,
1606 &acpi_backlight_ops,
1609 if (IS_ERR(device->backlight)) {
1610 device->backlight = NULL;
1615 * Save current brightness level in case we have to restore it
1616 * before acpi_video_device_lcd_set_level() is called next time.
1618 device->backlight->props.brightness =
1619 acpi_video_get_brightness(device->backlight);
1621 device->cooling_dev = thermal_cooling_device_register("LCD",
1622 device->dev, &video_cooling_ops);
1623 if (IS_ERR(device->cooling_dev)) {
1625 * Set cooling_dev to NULL so we don't crash trying to free it.
1626 * Also, why the hell we are returning early and not attempt to
1627 * register video output if cooling device registration failed?
1630 device->cooling_dev = NULL;
1634 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
1635 device->cooling_dev->id);
1636 result = sysfs_create_link(&device->dev->dev.kobj,
1637 &device->cooling_dev->device.kobj,
1640 printk(KERN_ERR PREFIX "Create sysfs link\n");
1641 result = sysfs_create_link(&device->cooling_dev->device.kobj,
1642 &device->dev->dev.kobj, "device");
1644 printk(KERN_ERR PREFIX "Create sysfs link\n");
1647 static void acpi_video_run_bcl_for_osi(struct acpi_video_bus *video)
1649 struct acpi_video_device *dev;
1650 union acpi_object *levels;
1652 mutex_lock(&video->device_list_lock);
1653 list_for_each_entry(dev, &video->video_device_list, entry) {
1654 if (!acpi_video_device_lcd_query_levels(dev, &levels))
1657 mutex_unlock(&video->device_list_lock);
1660 static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
1662 struct acpi_video_device *dev;
1664 if (video->backlight_registered)
1667 acpi_video_run_bcl_for_osi(video);
1669 if (acpi_video_get_backlight_type() != acpi_backlight_video)
1672 mutex_lock(&video->device_list_lock);
1673 list_for_each_entry(dev, &video->video_device_list, entry)
1674 acpi_video_dev_register_backlight(dev);
1675 mutex_unlock(&video->device_list_lock);
1677 video->backlight_registered = true;
1679 video->pm_nb.notifier_call = acpi_video_resume;
1680 video->pm_nb.priority = 0;
1681 return register_pm_notifier(&video->pm_nb);
1684 static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device)
1686 if (device->backlight) {
1687 backlight_device_unregister(device->backlight);
1688 device->backlight = NULL;
1690 if (device->brightness) {
1691 kfree(device->brightness->levels);
1692 kfree(device->brightness);
1693 device->brightness = NULL;
1695 if (device->cooling_dev) {
1696 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling");
1697 sysfs_remove_link(&device->cooling_dev->device.kobj, "device");
1698 thermal_cooling_device_unregister(device->cooling_dev);
1699 device->cooling_dev = NULL;
1703 static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video)
1705 struct acpi_video_device *dev;
1708 if (!video->backlight_registered)
1711 error = unregister_pm_notifier(&video->pm_nb);
1713 mutex_lock(&video->device_list_lock);
1714 list_for_each_entry(dev, &video->video_device_list, entry)
1715 acpi_video_dev_unregister_backlight(dev);
1716 mutex_unlock(&video->device_list_lock);
1718 video->backlight_registered = false;
1723 static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device)
1726 struct acpi_device *adev = device->dev;
1728 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
1729 acpi_video_device_notify, device);
1730 if (ACPI_FAILURE(status))
1731 dev_err(&adev->dev, "Error installing notify handler\n");
1733 device->flags.notify = 1;
1736 static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
1738 struct input_dev *input;
1739 struct acpi_video_device *dev;
1742 video->input = input = input_allocate_device();
1748 error = acpi_video_bus_start_devices(video);
1750 goto err_free_input;
1752 snprintf(video->phys, sizeof(video->phys),
1753 "%s/video/input0", acpi_device_hid(video->device));
1755 input->name = acpi_device_name(video->device);
1756 input->phys = video->phys;
1757 input->id.bustype = BUS_HOST;
1758 input->id.product = 0x06;
1759 input->dev.parent = &video->device->dev;
1760 input->evbit[0] = BIT(EV_KEY);
1761 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1762 set_bit(KEY_VIDEO_NEXT, input->keybit);
1763 set_bit(KEY_VIDEO_PREV, input->keybit);
1764 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1765 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1766 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1767 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1768 set_bit(KEY_DISPLAY_OFF, input->keybit);
1770 error = input_register_device(input);
1774 mutex_lock(&video->device_list_lock);
1775 list_for_each_entry(dev, &video->video_device_list, entry)
1776 acpi_video_dev_add_notify_handler(dev);
1777 mutex_unlock(&video->device_list_lock);
1782 acpi_video_bus_stop_devices(video);
1784 input_free_device(input);
1785 video->input = NULL;
1790 static void acpi_video_dev_remove_notify_handler(struct acpi_video_device *dev)
1792 if (dev->flags.notify) {
1793 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY,
1794 acpi_video_device_notify);
1795 dev->flags.notify = 0;
1799 static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
1801 struct acpi_video_device *dev;
1803 mutex_lock(&video->device_list_lock);
1804 list_for_each_entry(dev, &video->video_device_list, entry)
1805 acpi_video_dev_remove_notify_handler(dev);
1806 mutex_unlock(&video->device_list_lock);
1808 acpi_video_bus_stop_devices(video);
1809 input_unregister_device(video->input);
1810 video->input = NULL;
1813 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1815 struct acpi_video_device *dev, *next;
1817 mutex_lock(&video->device_list_lock);
1818 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1819 list_del(&dev->entry);
1822 mutex_unlock(&video->device_list_lock);
1827 static int instance;
1829 static int acpi_video_bus_add(struct acpi_device *device)
1831 struct acpi_video_bus *video;
1835 status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
1836 device->parent->handle, 1,
1837 acpi_video_bus_match, NULL,
1839 if (status == AE_ALREADY_EXISTS) {
1840 printk(KERN_WARNING FW_BUG
1841 "Duplicate ACPI video bus devices for the"
1842 " same VGA controller, please try module "
1843 "parameter \"video.allow_duplicates=1\""
1844 "if the current driver doesn't work.\n");
1845 if (!allow_duplicates)
1849 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1853 /* a hack to fix the duplicate name "VID" problem on T61 */
1854 if (!strcmp(device->pnp.bus_id, "VID")) {
1856 device->pnp.bus_id[3] = '0' + instance;
1859 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
1860 if (!strcmp(device->pnp.bus_id, "VGA")) {
1862 device->pnp.bus_id[3] = '0' + instance;
1866 video->device = device;
1867 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1868 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1869 device->driver_data = video;
1871 acpi_video_bus_find_cap(video);
1872 error = acpi_video_bus_check(video);
1874 goto err_free_video;
1876 mutex_init(&video->device_list_lock);
1877 INIT_LIST_HEAD(&video->video_device_list);
1879 error = acpi_video_bus_get_devices(video, device);
1883 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1884 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1885 video->flags.multihead ? "yes" : "no",
1886 video->flags.rom ? "yes" : "no",
1887 video->flags.post ? "yes" : "no");
1888 mutex_lock(&video_list_lock);
1889 list_add_tail(&video->entry, &video_bus_head);
1890 mutex_unlock(&video_list_lock);
1892 acpi_video_bus_register_backlight(video);
1893 acpi_video_bus_add_notify_handler(video);
1898 acpi_video_bus_put_devices(video);
1899 kfree(video->attached_array);
1902 device->driver_data = NULL;
1907 static int acpi_video_bus_remove(struct acpi_device *device)
1909 struct acpi_video_bus *video = NULL;
1912 if (!device || !acpi_driver_data(device))
1915 video = acpi_driver_data(device);
1917 acpi_video_bus_remove_notify_handler(video);
1918 acpi_video_bus_unregister_backlight(video);
1919 acpi_video_bus_put_devices(video);
1921 mutex_lock(&video_list_lock);
1922 list_del(&video->entry);
1923 mutex_unlock(&video_list_lock);
1925 kfree(video->attached_array);
1931 static int __init is_i740(struct pci_dev *dev)
1933 if (dev->device == 0x00D1)
1935 if (dev->device == 0x7000)
1940 static int __init intel_opregion_present(void)
1943 struct pci_dev *dev = NULL;
1946 for_each_pci_dev(dev) {
1947 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1949 if (dev->vendor != PCI_VENDOR_ID_INTEL)
1951 /* We don't want to poke around undefined i740 registers */
1954 pci_read_config_dword(dev, 0xfc, &address);
1962 int acpi_video_register(void)
1966 mutex_lock(®ister_count_mutex);
1967 if (register_count) {
1969 * if the function of acpi_video_register is already called,
1970 * don't register the acpi_vide_bus again and return no error.
1975 mutex_init(&video_list_lock);
1976 INIT_LIST_HEAD(&video_bus_head);
1978 dmi_check_system(video_dmi_table);
1980 ret = acpi_bus_register_driver(&acpi_video_bus);
1985 * When the acpi_video_bus is loaded successfully, increase
1986 * the counter reference.
1991 mutex_unlock(®ister_count_mutex);
1994 EXPORT_SYMBOL(acpi_video_register);
1996 void acpi_video_unregister(void)
1998 mutex_lock(®ister_count_mutex);
1999 if (register_count) {
2000 acpi_bus_unregister_driver(&acpi_video_bus);
2003 mutex_unlock(®ister_count_mutex);
2005 EXPORT_SYMBOL(acpi_video_unregister);
2007 void acpi_video_unregister_backlight(void)
2009 struct acpi_video_bus *video;
2011 mutex_lock(®ister_count_mutex);
2012 if (register_count) {
2013 mutex_lock(&video_list_lock);
2014 list_for_each_entry(video, &video_bus_head, entry)
2015 acpi_video_bus_unregister_backlight(video);
2016 mutex_unlock(&video_list_lock);
2018 mutex_unlock(®ister_count_mutex);
2022 * This is kind of nasty. Hardware using Intel chipsets may require
2023 * the video opregion code to be run first in order to initialise
2024 * state before any ACPI video calls are made. To handle this we defer
2025 * registration of the video class until the opregion code has run.
2028 static int __init acpi_video_init(void)
2031 * Let the module load even if ACPI is disabled (e.g. due to
2032 * a broken BIOS) so that i915.ko can still be loaded on such
2033 * old systems without an AcpiOpRegion.
2035 * acpi_video_register() will report -ENODEV later as well due
2036 * to acpi_disabled when i915.ko tries to register itself afterwards.
2041 if (intel_opregion_present())
2044 return acpi_video_register();
2047 static void __exit acpi_video_exit(void)
2049 acpi_video_detect_exit();
2050 acpi_video_unregister();
2055 module_init(acpi_video_init);
2056 module_exit(acpi_video_exit);