2 * video.c - ACPI Video Driver ($Revision:$)
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/video_output.h>
37 #include <linux/sort.h>
38 #include <linux/pci.h>
39 #include <linux/pci_ids.h>
40 #include <linux/slab.h>
41 #include <asm/uaccess.h>
42 #include <linux/dmi.h>
43 #include <acpi/acpi_bus.h>
44 #include <acpi/acpi_drivers.h>
45 #include <linux/suspend.h>
46 #include <acpi/video.h>
48 #define PREFIX "ACPI: "
50 #define ACPI_VIDEO_CLASS "video"
51 #define ACPI_VIDEO_BUS_NAME "Video Bus"
52 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
53 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
54 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
55 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
56 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
57 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
59 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
60 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
61 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
62 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
63 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
65 #define MAX_NAME_LEN 20
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
78 * By default, we don't allow duplicate ACPI video bus devices
79 * under the same VGA controller
81 static int allow_duplicates;
82 module_param(allow_duplicates, bool, 0644);
85 * Some BIOSes claim they use minimum backlight at boot,
86 * and this may bring dimming screen after boot
88 static int use_bios_initial_backlight = 1;
89 module_param(use_bios_initial_backlight, bool, 0644);
91 static int register_count = 0;
92 static int acpi_video_bus_add(struct acpi_device *device);
93 static int acpi_video_bus_remove(struct acpi_device *device, int type);
94 static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
96 static const struct acpi_device_id video_device_ids[] = {
100 MODULE_DEVICE_TABLE(acpi, video_device_ids);
102 static struct acpi_driver acpi_video_bus = {
104 .class = ACPI_VIDEO_CLASS,
105 .ids = video_device_ids,
107 .add = acpi_video_bus_add,
108 .remove = acpi_video_bus_remove,
109 .notify = acpi_video_bus_notify,
113 struct acpi_video_bus_flags {
114 u8 multihead:1; /* can switch video heads */
115 u8 rom:1; /* can retrieve a video rom */
116 u8 post:1; /* can configure the head to */
120 struct acpi_video_bus_cap {
121 u8 _DOS:1; /*Enable/Disable output switching */
122 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
123 u8 _ROM:1; /*Get ROM Data */
124 u8 _GPD:1; /*Get POST Device */
125 u8 _SPD:1; /*Set POST Device */
126 u8 _VPO:1; /*Video POST Options */
130 struct acpi_video_device_attrib {
131 u32 display_index:4; /* A zero-based instance of the Display */
132 u32 display_port_attachment:4; /*This field differentiates the display type */
133 u32 display_type:4; /*Describe the specific type in use */
134 u32 vendor_specific:4; /*Chipset Vendor Specific */
135 u32 bios_can_detect:1; /*BIOS can detect the device */
136 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
138 u32 pipe_id:3; /*For VGA multiple-head devices. */
139 u32 reserved:10; /*Must be 0 */
140 u32 device_id_scheme:1; /*Device ID Scheme */
143 struct acpi_video_enumerated_device {
146 struct acpi_video_device_attrib attrib;
148 struct acpi_video_device *bind_info;
151 struct acpi_video_bus {
152 struct acpi_device *device;
154 struct acpi_video_enumerated_device *attached_array;
156 struct acpi_video_bus_cap cap;
157 struct acpi_video_bus_flags flags;
158 struct list_head video_device_list;
159 struct mutex device_list_lock; /* protects video_device_list */
160 struct input_dev *input;
161 char phys[32]; /* for input device */
162 struct notifier_block pm_nb;
165 struct acpi_video_device_flags {
175 struct acpi_video_device_cap {
176 u8 _ADR:1; /*Return the unique ID */
177 u8 _BCL:1; /*Query list of brightness control levels supported */
178 u8 _BCM:1; /*Set the brightness level */
179 u8 _BQC:1; /* Get current brightness level */
180 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
181 u8 _DDC:1; /*Return the EDID for this device */
182 u8 _DCS:1; /*Return status of output device */
183 u8 _DGS:1; /*Query graphics state */
184 u8 _DSS:1; /*Device state set */
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 _BCL_use_index:1; /* levels in _BCL are index values */
191 u8 _BCM_use_index:1; /* input of _BCM is an index value */
192 u8 _BQC_use_index:1; /* _BQC returns an index value */
195 struct acpi_video_device_brightness {
199 struct acpi_video_brightness_flags flags;
202 struct acpi_video_device {
203 unsigned long device_id;
204 struct acpi_video_device_flags flags;
205 struct acpi_video_device_cap cap;
206 struct list_head entry;
207 struct acpi_video_bus *video;
208 struct acpi_device *dev;
209 struct acpi_video_device_brightness *brightness;
210 struct backlight_device *backlight;
211 struct thermal_cooling_device *cooling_dev;
212 struct output_device *output_dev;
215 static const char device_decode[][30] = {
216 "motherboard VGA device",
222 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
223 static void acpi_video_device_rebind(struct acpi_video_bus *video);
224 static void acpi_video_device_bind(struct acpi_video_bus *video,
225 struct acpi_video_device *device);
226 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
227 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
229 static int acpi_video_device_lcd_get_level_current(
230 struct acpi_video_device *device,
231 unsigned long long *level, int init);
232 static int acpi_video_get_next_level(struct acpi_video_device *device,
233 u32 level_current, u32 event);
234 static int acpi_video_switch_brightness(struct acpi_video_device *device,
236 static int acpi_video_device_get_state(struct acpi_video_device *device,
237 unsigned long long *state);
238 static int acpi_video_output_get(struct output_device *od);
239 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
241 /*backlight device sysfs support*/
242 static int acpi_video_get_brightness(struct backlight_device *bd)
244 unsigned long long cur_level;
246 struct acpi_video_device *vd =
247 (struct acpi_video_device *)bl_get_data(bd);
249 if (acpi_video_device_lcd_get_level_current(vd, &cur_level, 0))
251 for (i = 2; i < vd->brightness->count; i++) {
252 if (vd->brightness->levels[i] == cur_level)
253 /* The first two entries are special - see page 575
254 of the ACPI spec 3.0 */
260 static int acpi_video_set_brightness(struct backlight_device *bd)
262 int request_level = bd->props.brightness + 2;
263 struct acpi_video_device *vd =
264 (struct acpi_video_device *)bl_get_data(bd);
266 return acpi_video_device_lcd_set_level(vd,
267 vd->brightness->levels[request_level]);
270 static struct backlight_ops acpi_backlight_ops = {
271 .get_brightness = acpi_video_get_brightness,
272 .update_status = acpi_video_set_brightness,
275 /*video output device sysfs support*/
276 static int acpi_video_output_get(struct output_device *od)
278 unsigned long long state;
279 struct acpi_video_device *vd =
280 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
281 acpi_video_device_get_state(vd, &state);
285 static int acpi_video_output_set(struct output_device *od)
287 unsigned long state = od->request_state;
288 struct acpi_video_device *vd=
289 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
290 return acpi_video_device_set_state(vd, state);
293 static struct output_properties acpi_output_properties = {
294 .set_state = acpi_video_output_set,
295 .get_status = acpi_video_output_get,
299 /* thermal cooling device callbacks */
300 static int video_get_max_state(struct thermal_cooling_device *cooling_dev, unsigned
303 struct acpi_device *device = cooling_dev->devdata;
304 struct acpi_video_device *video = acpi_driver_data(device);
306 *state = video->brightness->count - 3;
310 static int video_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned
313 struct acpi_device *device = cooling_dev->devdata;
314 struct acpi_video_device *video = acpi_driver_data(device);
315 unsigned long long level;
318 if (acpi_video_device_lcd_get_level_current(video, &level, 0))
320 for (offset = 2; offset < video->brightness->count; offset++)
321 if (level == video->brightness->levels[offset]) {
322 *state = video->brightness->count - offset - 1;
330 video_set_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long state)
332 struct acpi_device *device = cooling_dev->devdata;
333 struct acpi_video_device *video = acpi_driver_data(device);
336 if ( state >= video->brightness->count - 2)
339 state = video->brightness->count - state;
340 level = video->brightness->levels[state -1];
341 return acpi_video_device_lcd_set_level(video, level);
344 static struct thermal_cooling_device_ops video_cooling_ops = {
345 .get_max_state = video_get_max_state,
346 .get_cur_state = video_get_cur_state,
347 .set_cur_state = video_set_cur_state,
350 /* --------------------------------------------------------------------------
352 -------------------------------------------------------------------------- */
357 acpi_video_device_get_state(struct acpi_video_device *device,
358 unsigned long long *state)
362 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
368 acpi_video_device_set_state(struct acpi_video_device *device, int state)
371 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
372 struct acpi_object_list args = { 1, &arg0 };
373 unsigned long long ret;
376 arg0.integer.value = state;
377 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
383 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
384 union acpi_object **levels)
387 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
388 union acpi_object *obj;
393 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
394 if (!ACPI_SUCCESS(status))
396 obj = (union acpi_object *)buffer.pointer;
397 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
398 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
408 kfree(buffer.pointer);
414 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
417 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
418 struct acpi_object_list args = { 1, &arg0 };
421 arg0.integer.value = level;
423 status = acpi_evaluate_object(device->dev->handle, "_BCM",
425 if (ACPI_FAILURE(status)) {
426 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
430 device->brightness->curr = level;
431 for (state = 2; state < device->brightness->count; state++)
432 if (level == device->brightness->levels[state]) {
433 if (device->backlight)
434 device->backlight->props.brightness = state - 2;
438 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
443 * For some buggy _BQC methods, we need to add a constant value to
444 * the _BQC return value to get the actual current brightness level
447 static int bqc_offset_aml_bug_workaround;
448 static int __init video_set_bqc_offset(const struct dmi_system_id *d)
450 bqc_offset_aml_bug_workaround = 9;
454 static struct dmi_system_id video_dmi_table[] __initdata = {
456 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
459 .callback = video_set_bqc_offset,
460 .ident = "Acer Aspire 5720",
462 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
463 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"),
467 .callback = video_set_bqc_offset,
468 .ident = "Acer Aspire 5710Z",
470 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
471 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"),
475 .callback = video_set_bqc_offset,
476 .ident = "eMachines E510",
478 DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"),
479 DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"),
483 .callback = video_set_bqc_offset,
484 .ident = "Acer Aspire 5315",
486 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
487 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"),
491 .callback = video_set_bqc_offset,
492 .ident = "Acer Aspire 7720",
494 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
495 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"),
502 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
503 unsigned long long *level, int init)
505 acpi_status status = AE_OK;
508 if (device->cap._BQC || device->cap._BCQ) {
509 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
511 status = acpi_evaluate_integer(device->dev->handle, buf,
513 if (ACPI_SUCCESS(status)) {
514 if (device->brightness->flags._BQC_use_index) {
515 if (device->brightness->flags._BCL_reversed)
516 *level = device->brightness->count
518 *level = device->brightness->levels[*level + 2];
521 *level += bqc_offset_aml_bug_workaround;
522 for (i = 2; i < device->brightness->count; i++)
523 if (device->brightness->levels[i] == *level) {
524 device->brightness->curr = *level;
529 * BQC returned an invalid level.
532 ACPI_WARNING((AE_INFO,
533 "%s returned an invalid level",
535 device->cap._BQC = device->cap._BCQ = 0;
539 * should we return an error or ignore this failure?
540 * dev->brightness->curr is a cached value which stores
541 * the correct current backlight level in most cases.
542 * ACPI video backlight still works w/ buggy _BQC.
543 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
545 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
546 device->cap._BQC = device->cap._BCQ = 0;
550 *level = device->brightness->curr;
555 acpi_video_device_EDID(struct acpi_video_device *device,
556 union acpi_object **edid, ssize_t length)
559 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
560 union acpi_object *obj;
561 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
562 struct acpi_object_list args = { 1, &arg0 };
570 arg0.integer.value = 1;
571 else if (length == 256)
572 arg0.integer.value = 2;
576 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
577 if (ACPI_FAILURE(status))
580 obj = buffer.pointer;
582 if (obj && obj->type == ACPI_TYPE_BUFFER)
585 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
597 * video : video bus device pointer
599 * 0. The system BIOS should NOT automatically switch(toggle)
600 * the active display output.
601 * 1. The system BIOS should automatically switch (toggle) the
602 * active display output. No switch event.
603 * 2. The _DGS value should be locked.
604 * 3. The system BIOS should not automatically switch (toggle) the
605 * active display output, but instead generate the display switch
608 * 0. The system BIOS should automatically control the brightness level
609 * of the LCD when the power changes from AC to DC
610 * 1. The system BIOS should NOT automatically control the brightness
611 * level of the LCD when the power changes from AC to DC.
617 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
620 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
621 struct acpi_object_list args = { 1, &arg0 };
624 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
628 arg0.integer.value = (lcd_flag << 2) | bios_flag;
629 video->dos_setting = arg0.integer.value;
630 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
637 * Simple comparison function used to sort backlight levels.
641 acpi_video_cmp_level(const void *a, const void *b)
643 return *(int *)a - *(int *)b;
648 * device : video output device (LCD, CRT, ..)
651 * Maximum brightness level
653 * Allocate and initialize device->brightness.
657 acpi_video_init_brightness(struct acpi_video_device *device)
659 union acpi_object *obj = NULL;
660 int i, max_level = 0, count = 0, level_ac_battery = 0;
661 unsigned long long level, level_old;
662 union acpi_object *o;
663 struct acpi_video_device_brightness *br = NULL;
664 int result = -EINVAL;
666 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
667 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
668 "LCD brightness level\n"));
672 if (obj->package.count < 2)
675 br = kzalloc(sizeof(*br), GFP_KERNEL);
677 printk(KERN_ERR "can't allocate memory\n");
682 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
689 for (i = 0; i < obj->package.count; i++) {
690 o = (union acpi_object *)&obj->package.elements[i];
691 if (o->type != ACPI_TYPE_INTEGER) {
692 printk(KERN_ERR PREFIX "Invalid data\n");
695 br->levels[count] = (u32) o->integer.value;
697 if (br->levels[count] > max_level)
698 max_level = br->levels[count];
703 * some buggy BIOS don't export the levels
704 * when machine is on AC/Battery in _BCL package.
705 * In this case, the first two elements in _BCL packages
706 * are also supported brightness levels that OS should take care of.
708 for (i = 2; i < count; i++) {
709 if (br->levels[i] == br->levels[0])
711 if (br->levels[i] == br->levels[1])
715 if (level_ac_battery < 2) {
716 level_ac_battery = 2 - level_ac_battery;
717 br->flags._BCL_no_ac_battery_levels = 1;
718 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
719 br->levels[i] = br->levels[i - level_ac_battery];
720 count += level_ac_battery;
721 } else if (level_ac_battery > 2)
722 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
724 /* Check if the _BCL package is in a reversed order */
725 if (max_level == br->levels[2]) {
726 br->flags._BCL_reversed = 1;
727 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
728 acpi_video_cmp_level, NULL);
729 } else if (max_level != br->levels[count - 1])
731 "Found unordered _BCL package\n"));
734 device->brightness = br;
736 /* Check the input/output of _BQC/_BCL/_BCM */
737 if ((max_level < 100) && (max_level <= (count - 2)))
738 br->flags._BCL_use_index = 1;
741 * _BCM is always consistent with _BCL,
742 * at least for all the laptops we have ever seen.
744 br->flags._BCM_use_index = br->flags._BCL_use_index;
746 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
747 br->curr = level = max_level;
749 if (!device->cap._BQC)
752 result = acpi_video_device_lcd_get_level_current(device, &level_old, 1);
754 goto out_free_levels;
757 * Set the level to maximum and check if _BQC uses indexed value
759 result = acpi_video_device_lcd_set_level(device, max_level);
761 goto out_free_levels;
763 result = acpi_video_device_lcd_get_level_current(device, &level, 0);
765 goto out_free_levels;
767 br->flags._BQC_use_index = (level == max_level ? 0 : 1);
769 if (!br->flags._BQC_use_index) {
771 * Set the backlight to the initial state.
772 * On some buggy laptops, _BQC returns an uninitialized value
773 * when invoked for the first time, i.e. level_old is invalid.
774 * set the backlight to max_level in this case
776 if (use_bios_initial_backlight) {
777 for (i = 2; i < br->count; i++)
778 if (level_old == br->levels[i])
784 if (br->flags._BCL_reversed)
785 level_old = (br->count - 1) - level_old;
786 level = br->levels[level_old];
789 result = acpi_video_device_lcd_set_level(device, level);
791 goto out_free_levels;
793 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
794 "found %d brightness levels\n", count - 2));
803 device->brightness = NULL;
810 * device : video output device (LCD, CRT, ..)
815 * Find out all required AML methods defined under the output
819 static void acpi_video_device_find_cap(struct acpi_video_device *device)
821 acpi_handle h_dummy1;
823 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
824 device->cap._ADR = 1;
826 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
827 device->cap._BCL = 1;
829 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
830 device->cap._BCM = 1;
832 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
833 device->cap._BQC = 1;
834 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
836 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
837 device->cap._BCQ = 1;
840 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
841 device->cap._DDC = 1;
843 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
844 device->cap._DCS = 1;
846 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
847 device->cap._DGS = 1;
849 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
850 device->cap._DSS = 1;
853 if (acpi_video_backlight_support()) {
854 struct backlight_properties props;
856 static int count = 0;
859 result = acpi_video_init_brightness(device);
862 name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
867 memset(&props, 0, sizeof(struct backlight_properties));
868 props.max_brightness = device->brightness->count - 3;
869 device->backlight = backlight_device_register(name, NULL, device,
873 if (IS_ERR(device->backlight))
877 * Save current brightness level in case we have to restore it
878 * before acpi_video_device_lcd_set_level() is called next time.
880 device->backlight->props.brightness =
881 acpi_video_get_brightness(device->backlight);
883 result = sysfs_create_link(&device->backlight->dev.kobj,
884 &device->dev->dev.kobj, "device");
886 printk(KERN_ERR PREFIX "Create sysfs link\n");
888 device->cooling_dev = thermal_cooling_device_register("LCD",
889 device->dev, &video_cooling_ops);
890 if (IS_ERR(device->cooling_dev)) {
892 * Set cooling_dev to NULL so we don't crash trying to
894 * Also, why the hell we are returning early and
895 * not attempt to register video output if cooling
896 * device registration failed?
899 device->cooling_dev = NULL;
903 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
904 device->cooling_dev->id);
905 result = sysfs_create_link(&device->dev->dev.kobj,
906 &device->cooling_dev->device.kobj,
909 printk(KERN_ERR PREFIX "Create sysfs link\n");
910 result = sysfs_create_link(&device->cooling_dev->device.kobj,
911 &device->dev->dev.kobj, "device");
913 printk(KERN_ERR PREFIX "Create sysfs link\n");
917 if (acpi_video_display_switch_support()) {
919 if (device->cap._DCS && device->cap._DSS) {
922 name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
926 device->output_dev = video_output_register(name,
927 NULL, device, &acpi_output_properties);
935 * device : video output device (VGA)
940 * Find out all required AML methods defined under the video bus device.
943 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
945 acpi_handle h_dummy1;
947 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
950 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
953 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
956 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
959 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
962 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
968 * Check whether the video bus device has required AML method to
969 * support the desired features
972 static int acpi_video_bus_check(struct acpi_video_bus *video)
974 acpi_status status = -ENOENT;
980 dev = acpi_get_pci_dev(video->device->handle);
985 /* Since there is no HID, CID and so on for VGA driver, we have
986 * to check well known required nodes.
989 /* Does this device support video switching? */
990 if (video->cap._DOS || video->cap._DOD) {
991 if (!video->cap._DOS) {
992 printk(KERN_WARNING FW_BUG
993 "ACPI(%s) defines _DOD but not _DOS\n",
994 acpi_device_bid(video->device));
996 video->flags.multihead = 1;
1000 /* Does this device support retrieving a video ROM? */
1001 if (video->cap._ROM) {
1002 video->flags.rom = 1;
1006 /* Does this device support configuring which video device to POST? */
1007 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
1008 video->flags.post = 1;
1015 /* --------------------------------------------------------------------------
1017 -------------------------------------------------------------------------- */
1019 /* device interface */
1020 static struct acpi_video_device_attrib*
1021 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1023 struct acpi_video_enumerated_device *ids;
1026 for (i = 0; i < video->attached_count; i++) {
1027 ids = &video->attached_array[i];
1028 if ((ids->value.int_val & 0xffff) == device_id)
1029 return &ids->value.attrib;
1036 acpi_video_get_device_type(struct acpi_video_bus *video,
1037 unsigned long device_id)
1039 struct acpi_video_enumerated_device *ids;
1042 for (i = 0; i < video->attached_count; i++) {
1043 ids = &video->attached_array[i];
1044 if ((ids->value.int_val & 0xffff) == device_id)
1045 return ids->value.int_val;
1052 acpi_video_bus_get_one_device(struct acpi_device *device,
1053 struct acpi_video_bus *video)
1055 unsigned long long device_id;
1056 int status, device_type;
1057 struct acpi_video_device *data;
1058 struct acpi_video_device_attrib* attribute;
1060 if (!device || !video)
1064 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1065 if (ACPI_SUCCESS(status)) {
1067 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1071 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1072 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1073 device->driver_data = data;
1075 data->device_id = device_id;
1076 data->video = video;
1079 attribute = acpi_video_get_device_attr(video, device_id);
1081 if((attribute != NULL) && attribute->device_id_scheme) {
1082 switch (attribute->display_type) {
1083 case ACPI_VIDEO_DISPLAY_CRT:
1084 data->flags.crt = 1;
1086 case ACPI_VIDEO_DISPLAY_TV:
1087 data->flags.tvout = 1;
1089 case ACPI_VIDEO_DISPLAY_DVI:
1090 data->flags.dvi = 1;
1092 case ACPI_VIDEO_DISPLAY_LCD:
1093 data->flags.lcd = 1;
1096 data->flags.unknown = 1;
1099 if(attribute->bios_can_detect)
1100 data->flags.bios = 1;
1102 /* Check for legacy IDs */
1103 device_type = acpi_video_get_device_type(video,
1105 /* Ignore bits 16 and 18-20 */
1106 switch (device_type & 0xffe2ffff) {
1107 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR:
1108 data->flags.crt = 1;
1110 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL:
1111 data->flags.lcd = 1;
1113 case ACPI_VIDEO_DISPLAY_LEGACY_TV:
1114 data->flags.tvout = 1;
1117 data->flags.unknown = 1;
1121 acpi_video_device_bind(video, data);
1122 acpi_video_device_find_cap(data);
1124 status = acpi_install_notify_handler(device->handle,
1126 acpi_video_device_notify,
1128 if (ACPI_FAILURE(status)) {
1129 printk(KERN_ERR PREFIX
1130 "Error installing notify handler\n");
1131 if(data->brightness)
1132 kfree(data->brightness->levels);
1133 kfree(data->brightness);
1138 mutex_lock(&video->device_list_lock);
1139 list_add_tail(&data->entry, &video->video_device_list);
1140 mutex_unlock(&video->device_list_lock);
1150 * video : video bus device
1155 * Enumerate the video device list of the video bus,
1156 * bind the ids with the corresponding video devices
1157 * under the video bus.
1160 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1162 struct acpi_video_device *dev;
1164 mutex_lock(&video->device_list_lock);
1166 list_for_each_entry(dev, &video->video_device_list, entry)
1167 acpi_video_device_bind(video, dev);
1169 mutex_unlock(&video->device_list_lock);
1174 * video : video bus device
1175 * device : video output device under the video
1181 * Bind the ids with the corresponding video devices
1182 * under the video bus.
1186 acpi_video_device_bind(struct acpi_video_bus *video,
1187 struct acpi_video_device *device)
1189 struct acpi_video_enumerated_device *ids;
1192 for (i = 0; i < video->attached_count; i++) {
1193 ids = &video->attached_array[i];
1194 if (device->device_id == (ids->value.int_val & 0xffff)) {
1195 ids->bind_info = device;
1196 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1203 * video : video bus device
1208 * Call _DOD to enumerate all devices attached to display adapter
1212 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1217 struct acpi_video_enumerated_device *active_list;
1218 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1219 union acpi_object *dod = NULL;
1220 union acpi_object *obj;
1222 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1223 if (!ACPI_SUCCESS(status)) {
1224 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1228 dod = buffer.pointer;
1229 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1230 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1235 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1236 dod->package.count));
1238 active_list = kcalloc(1 + dod->package.count,
1239 sizeof(struct acpi_video_enumerated_device),
1247 for (i = 0; i < dod->package.count; i++) {
1248 obj = &dod->package.elements[i];
1250 if (obj->type != ACPI_TYPE_INTEGER) {
1251 printk(KERN_ERR PREFIX
1252 "Invalid _DOD data in element %d\n", i);
1256 active_list[count].value.int_val = obj->integer.value;
1257 active_list[count].bind_info = NULL;
1258 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1259 (int)obj->integer.value));
1263 kfree(video->attached_array);
1265 video->attached_array = active_list;
1266 video->attached_count = count;
1269 kfree(buffer.pointer);
1274 acpi_video_get_next_level(struct acpi_video_device *device,
1275 u32 level_current, u32 event)
1277 int min, max, min_above, max_below, i, l, delta = 255;
1278 max = max_below = 0;
1279 min = min_above = 255;
1280 /* Find closest level to level_current */
1281 for (i = 2; i < device->brightness->count; i++) {
1282 l = device->brightness->levels[i];
1283 if (abs(l - level_current) < abs(delta)) {
1284 delta = l - level_current;
1289 /* Ajust level_current to closest available level */
1290 level_current += delta;
1291 for (i = 2; i < device->brightness->count; i++) {
1292 l = device->brightness->levels[i];
1297 if (l < min_above && l > level_current)
1299 if (l > max_below && l < level_current)
1304 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1305 return (level_current < max) ? min_above : min;
1306 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1307 return (level_current < max) ? min_above : max;
1308 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1309 return (level_current > min) ? max_below : min;
1310 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1311 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1314 return level_current;
1319 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1321 unsigned long long level_current, level_next;
1322 int result = -EINVAL;
1324 /* no warning message if acpi_backlight=vendor is used */
1325 if (!acpi_video_backlight_support())
1328 if (!device->brightness)
1331 result = acpi_video_device_lcd_get_level_current(device,
1336 level_next = acpi_video_get_next_level(device, level_current, event);
1338 result = acpi_video_device_lcd_set_level(device, level_next);
1341 backlight_force_update(device->backlight,
1342 BACKLIGHT_UPDATE_HOTKEY);
1346 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1351 int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
1354 struct acpi_video_bus *video;
1355 struct acpi_video_device *video_device;
1356 union acpi_object *buffer = NULL;
1360 if (!device || !acpi_driver_data(device))
1363 video = acpi_driver_data(device);
1365 for (i = 0; i < video->attached_count; i++) {
1366 video_device = video->attached_array[i].bind_info;
1374 case ACPI_VIDEO_DISPLAY_CRT:
1375 if (!video_device->flags.crt)
1378 case ACPI_VIDEO_DISPLAY_TV:
1379 if (!video_device->flags.tvout)
1382 case ACPI_VIDEO_DISPLAY_DVI:
1383 if (!video_device->flags.dvi)
1386 case ACPI_VIDEO_DISPLAY_LCD:
1387 if (!video_device->flags.lcd)
1391 } else if (video_device->device_id != device_id) {
1395 status = acpi_video_device_EDID(video_device, &buffer, length);
1397 if (ACPI_FAILURE(status) || !buffer ||
1398 buffer->type != ACPI_TYPE_BUFFER) {
1400 status = acpi_video_device_EDID(video_device, &buffer,
1402 if (ACPI_FAILURE(status) || !buffer ||
1403 buffer->type != ACPI_TYPE_BUFFER) {
1408 *edid = buffer->buffer.pointer;
1414 EXPORT_SYMBOL(acpi_video_get_edid);
1417 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1418 struct acpi_device *device)
1421 struct acpi_device *dev;
1423 acpi_video_device_enumerate(video);
1425 list_for_each_entry(dev, &device->children, node) {
1427 status = acpi_video_bus_get_one_device(dev, video);
1428 if (ACPI_FAILURE(status)) {
1429 printk(KERN_WARNING PREFIX
1430 "Cant attach device\n");
1437 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1441 if (!device || !device->video)
1444 status = acpi_remove_notify_handler(device->dev->handle,
1446 acpi_video_device_notify);
1447 if (ACPI_FAILURE(status)) {
1448 printk(KERN_WARNING PREFIX
1449 "Cant remove video notify handler\n");
1451 if (device->backlight) {
1452 sysfs_remove_link(&device->backlight->dev.kobj, "device");
1453 backlight_device_unregister(device->backlight);
1454 device->backlight = NULL;
1456 if (device->cooling_dev) {
1457 sysfs_remove_link(&device->dev->dev.kobj,
1459 sysfs_remove_link(&device->cooling_dev->device.kobj,
1461 thermal_cooling_device_unregister(device->cooling_dev);
1462 device->cooling_dev = NULL;
1464 video_output_unregister(device->output_dev);
1469 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1472 struct acpi_video_device *dev, *next;
1474 mutex_lock(&video->device_list_lock);
1476 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1478 status = acpi_video_bus_put_one_device(dev);
1479 if (ACPI_FAILURE(status))
1480 printk(KERN_WARNING PREFIX
1481 "hhuuhhuu bug in acpi video driver.\n");
1483 if (dev->brightness) {
1484 kfree(dev->brightness->levels);
1485 kfree(dev->brightness);
1487 list_del(&dev->entry);
1491 mutex_unlock(&video->device_list_lock);
1496 /* acpi_video interface */
1498 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1500 return acpi_video_bus_DOS(video, 0, 0);
1503 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1505 return acpi_video_bus_DOS(video, 0, 1);
1508 static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1510 struct acpi_video_bus *video = acpi_driver_data(device);
1511 struct input_dev *input;
1517 input = video->input;
1520 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1521 * most likely via hotkey. */
1522 acpi_bus_generate_proc_event(device, event, 0);
1523 keycode = KEY_SWITCHVIDEOMODE;
1526 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1528 acpi_video_device_enumerate(video);
1529 acpi_video_device_rebind(video);
1530 acpi_bus_generate_proc_event(device, event, 0);
1531 keycode = KEY_SWITCHVIDEOMODE;
1534 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1535 acpi_bus_generate_proc_event(device, event, 0);
1536 keycode = KEY_SWITCHVIDEOMODE;
1538 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1539 acpi_bus_generate_proc_event(device, event, 0);
1540 keycode = KEY_VIDEO_NEXT;
1542 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1543 acpi_bus_generate_proc_event(device, event, 0);
1544 keycode = KEY_VIDEO_PREV;
1548 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1549 "Unsupported event [0x%x]\n", event));
1553 acpi_notifier_call_chain(device, event, 0);
1556 input_report_key(input, keycode, 1);
1558 input_report_key(input, keycode, 0);
1565 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1567 struct acpi_video_device *video_device = data;
1568 struct acpi_device *device = NULL;
1569 struct acpi_video_bus *bus;
1570 struct input_dev *input;
1576 device = video_device->dev;
1577 bus = video_device->video;
1581 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1582 if (brightness_switch_enabled)
1583 acpi_video_switch_brightness(video_device, event);
1584 acpi_bus_generate_proc_event(device, event, 0);
1585 keycode = KEY_BRIGHTNESS_CYCLE;
1587 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1588 if (brightness_switch_enabled)
1589 acpi_video_switch_brightness(video_device, event);
1590 acpi_bus_generate_proc_event(device, event, 0);
1591 keycode = KEY_BRIGHTNESSUP;
1593 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1594 if (brightness_switch_enabled)
1595 acpi_video_switch_brightness(video_device, event);
1596 acpi_bus_generate_proc_event(device, event, 0);
1597 keycode = KEY_BRIGHTNESSDOWN;
1599 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1600 if (brightness_switch_enabled)
1601 acpi_video_switch_brightness(video_device, event);
1602 acpi_bus_generate_proc_event(device, event, 0);
1603 keycode = KEY_BRIGHTNESS_ZERO;
1605 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1606 if (brightness_switch_enabled)
1607 acpi_video_switch_brightness(video_device, event);
1608 acpi_bus_generate_proc_event(device, event, 0);
1609 keycode = KEY_DISPLAY_OFF;
1612 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1613 "Unsupported event [0x%x]\n", event));
1617 acpi_notifier_call_chain(device, event, 0);
1620 input_report_key(input, keycode, 1);
1622 input_report_key(input, keycode, 0);
1629 static int acpi_video_resume(struct notifier_block *nb,
1630 unsigned long val, void *ign)
1632 struct acpi_video_bus *video;
1633 struct acpi_video_device *video_device;
1637 case PM_HIBERNATION_PREPARE:
1638 case PM_SUSPEND_PREPARE:
1639 case PM_RESTORE_PREPARE:
1643 video = container_of(nb, struct acpi_video_bus, pm_nb);
1645 dev_info(&video->device->dev, "Restoring backlight state\n");
1647 for (i = 0; i < video->attached_count; i++) {
1648 video_device = video->attached_array[i].bind_info;
1649 if (video_device && video_device->backlight)
1650 acpi_video_set_brightness(video_device->backlight);
1657 acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
1658 void **return_value)
1660 struct acpi_device *device = context;
1661 struct acpi_device *sibling;
1664 if (handle == device->handle)
1665 return AE_CTRL_TERMINATE;
1667 result = acpi_bus_get_device(handle, &sibling);
1671 if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME))
1672 return AE_ALREADY_EXISTS;
1677 static int instance;
1679 static int acpi_video_bus_add(struct acpi_device *device)
1681 struct acpi_video_bus *video;
1682 struct input_dev *input;
1686 status = acpi_walk_namespace(ACPI_TYPE_DEVICE,
1687 device->parent->handle, 1,
1688 acpi_video_bus_match, NULL,
1690 if (status == AE_ALREADY_EXISTS) {
1691 printk(KERN_WARNING FW_BUG
1692 "Duplicate ACPI video bus devices for the"
1693 " same VGA controller, please try module "
1694 "parameter \"video.allow_duplicates=1\""
1695 "if the current driver doesn't work.\n");
1696 if (!allow_duplicates)
1700 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1704 /* a hack to fix the duplicate name "VID" problem on T61 */
1705 if (!strcmp(device->pnp.bus_id, "VID")) {
1707 device->pnp.bus_id[3] = '0' + instance;
1710 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
1711 if (!strcmp(device->pnp.bus_id, "VGA")) {
1713 device->pnp.bus_id[3] = '0' + instance;
1717 video->device = device;
1718 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1719 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1720 device->driver_data = video;
1722 acpi_video_bus_find_cap(video);
1723 error = acpi_video_bus_check(video);
1725 goto err_free_video;
1727 mutex_init(&video->device_list_lock);
1728 INIT_LIST_HEAD(&video->video_device_list);
1730 acpi_video_bus_get_devices(video, device);
1731 acpi_video_bus_start_devices(video);
1733 video->input = input = input_allocate_device();
1736 goto err_stop_video;
1739 snprintf(video->phys, sizeof(video->phys),
1740 "%s/video/input0", acpi_device_hid(video->device));
1742 input->name = acpi_device_name(video->device);
1743 input->phys = video->phys;
1744 input->id.bustype = BUS_HOST;
1745 input->id.product = 0x06;
1746 input->dev.parent = &device->dev;
1747 input->evbit[0] = BIT(EV_KEY);
1748 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1749 set_bit(KEY_VIDEO_NEXT, input->keybit);
1750 set_bit(KEY_VIDEO_PREV, input->keybit);
1751 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1752 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1753 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1754 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1755 set_bit(KEY_DISPLAY_OFF, input->keybit);
1757 error = input_register_device(input);
1759 goto err_free_input_dev;
1761 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1762 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1763 video->flags.multihead ? "yes" : "no",
1764 video->flags.rom ? "yes" : "no",
1765 video->flags.post ? "yes" : "no");
1767 video->pm_nb.notifier_call = acpi_video_resume;
1768 video->pm_nb.priority = 0;
1769 register_pm_notifier(&video->pm_nb);
1774 input_free_device(input);
1776 acpi_video_bus_stop_devices(video);
1777 acpi_video_bus_put_devices(video);
1778 kfree(video->attached_array);
1781 device->driver_data = NULL;
1786 static int acpi_video_bus_remove(struct acpi_device *device, int type)
1788 struct acpi_video_bus *video = NULL;
1791 if (!device || !acpi_driver_data(device))
1794 video = acpi_driver_data(device);
1796 unregister_pm_notifier(&video->pm_nb);
1798 acpi_video_bus_stop_devices(video);
1799 acpi_video_bus_put_devices(video);
1801 input_unregister_device(video->input);
1802 kfree(video->attached_array);
1808 static int __init intel_opregion_present(void)
1810 #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
1811 struct pci_dev *dev = NULL;
1814 for_each_pci_dev(dev) {
1815 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1817 if (dev->vendor != PCI_VENDOR_ID_INTEL)
1819 pci_read_config_dword(dev, 0xfc, &address);
1828 int acpi_video_register(void)
1831 if (register_count) {
1833 * if the function of acpi_video_register is already called,
1834 * don't register the acpi_vide_bus again and return no error.
1839 result = acpi_bus_register_driver(&acpi_video_bus);
1844 * When the acpi_video_bus is loaded successfully, increase
1845 * the counter reference.
1851 EXPORT_SYMBOL(acpi_video_register);
1853 void acpi_video_unregister(void)
1855 if (!register_count) {
1857 * If the acpi video bus is already unloaded, don't
1858 * unload it again and return directly.
1862 acpi_bus_unregister_driver(&acpi_video_bus);
1868 EXPORT_SYMBOL(acpi_video_unregister);
1871 * This is kind of nasty. Hardware using Intel chipsets may require
1872 * the video opregion code to be run first in order to initialise
1873 * state before any ACPI video calls are made. To handle this we defer
1874 * registration of the video class until the opregion code has run.
1877 static int __init acpi_video_init(void)
1879 dmi_check_system(video_dmi_table);
1881 if (intel_opregion_present())
1884 return acpi_video_register();
1887 static void __exit acpi_video_exit(void)
1889 acpi_video_unregister();
1894 module_init(acpi_video_init);
1895 module_exit(acpi_video_exit);