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 <asm/uaccess.h>
41 #include <linux/dmi.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
44 #include <linux/suspend.h>
45 #include <acpi/video.h>
49 #define PREFIX "ACPI: "
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 bool 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 bool allow_duplicates
;
82 module_param(allow_duplicates
, bool, 0644);
84 static int register_count
;
85 static int acpi_video_bus_add(struct acpi_device
*device
);
86 static int acpi_video_bus_remove(struct acpi_device
*device
);
87 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
);
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
;
147 struct acpi_video_enumerated_device
*attached_array
;
149 struct acpi_video_bus_cap cap
;
150 struct acpi_video_bus_flags flags
;
151 struct list_head video_device_list
;
152 struct mutex device_list_lock
; /* protects video_device_list */
153 struct input_dev
*input
;
154 char phys
[32]; /* for input device */
155 struct notifier_block pm_nb
;
158 struct acpi_video_device_flags
{
169 struct acpi_video_device_cap
{
170 u8 _ADR
:1; /* Return the unique ID */
171 u8 _BCL
:1; /* Query list of brightness control levels supported */
172 u8 _BCM
:1; /* Set the brightness level */
173 u8 _BQC
:1; /* Get current brightness level */
174 u8 _BCQ
:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
175 u8 _DDC
:1; /* Return the EDID for this device */
178 struct acpi_video_brightness_flags
{
179 u8 _BCL_no_ac_battery_levels
:1; /* no AC/Battery levels in _BCL */
180 u8 _BCL_reversed
:1; /* _BCL package is in a reversed order */
181 u8 _BQC_use_index
:1; /* _BQC returns an index value */
184 struct acpi_video_device_brightness
{
188 struct acpi_video_brightness_flags flags
;
191 struct acpi_video_device
{
192 unsigned long device_id
;
193 struct acpi_video_device_flags flags
;
194 struct acpi_video_device_cap cap
;
195 struct list_head entry
;
196 struct acpi_video_bus
*video
;
197 struct acpi_device
*dev
;
198 struct acpi_video_device_brightness
*brightness
;
199 struct backlight_device
*backlight
;
200 struct thermal_cooling_device
*cooling_dev
;
203 static const char device_decode
[][30] = {
204 "motherboard VGA device",
210 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
211 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
212 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
213 struct acpi_video_device
*device
);
214 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
215 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
217 static int acpi_video_device_lcd_get_level_current(
218 struct acpi_video_device
*device
,
219 unsigned long long *level
, bool raw
);
220 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
221 u32 level_current
, u32 event
);
222 static int acpi_video_switch_brightness(struct acpi_video_device
*device
,
225 /* backlight device sysfs support */
226 static int acpi_video_get_brightness(struct backlight_device
*bd
)
228 unsigned long long cur_level
;
230 struct acpi_video_device
*vd
= bl_get_data(bd
);
232 if (acpi_video_device_lcd_get_level_current(vd
, &cur_level
, false))
234 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
235 if (vd
->brightness
->levels
[i
] == cur_level
)
237 * The first two entries are special - see page 575
238 * of the ACPI spec 3.0
245 static int acpi_video_set_brightness(struct backlight_device
*bd
)
247 int request_level
= bd
->props
.brightness
+ 2;
248 struct acpi_video_device
*vd
= bl_get_data(bd
);
250 return acpi_video_device_lcd_set_level(vd
,
251 vd
->brightness
->levels
[request_level
]);
254 static const struct backlight_ops acpi_backlight_ops
= {
255 .get_brightness
= acpi_video_get_brightness
,
256 .update_status
= acpi_video_set_brightness
,
259 /* thermal cooling device callbacks */
260 static int video_get_max_state(struct thermal_cooling_device
*cooling_dev
, unsigned
263 struct acpi_device
*device
= cooling_dev
->devdata
;
264 struct acpi_video_device
*video
= acpi_driver_data(device
);
266 *state
= video
->brightness
->count
- 3;
270 static int video_get_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned
273 struct acpi_device
*device
= cooling_dev
->devdata
;
274 struct acpi_video_device
*video
= acpi_driver_data(device
);
275 unsigned long long level
;
278 if (acpi_video_device_lcd_get_level_current(video
, &level
, false))
280 for (offset
= 2; offset
< video
->brightness
->count
; offset
++)
281 if (level
== video
->brightness
->levels
[offset
]) {
282 *state
= video
->brightness
->count
- offset
- 1;
290 video_set_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned long state
)
292 struct acpi_device
*device
= cooling_dev
->devdata
;
293 struct acpi_video_device
*video
= acpi_driver_data(device
);
296 if (state
>= video
->brightness
->count
- 2)
299 state
= video
->brightness
->count
- state
;
300 level
= video
->brightness
->levels
[state
- 1];
301 return acpi_video_device_lcd_set_level(video
, level
);
304 static const struct thermal_cooling_device_ops video_cooling_ops
= {
305 .get_max_state
= video_get_max_state
,
306 .get_cur_state
= video_get_cur_state
,
307 .set_cur_state
= video_set_cur_state
,
311 * --------------------------------------------------------------------------
313 * --------------------------------------------------------------------------
317 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
318 union acpi_object
**levels
)
321 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
322 union acpi_object
*obj
;
327 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
328 if (!ACPI_SUCCESS(status
))
330 obj
= (union acpi_object
*)buffer
.pointer
;
331 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
332 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
342 kfree(buffer
.pointer
);
348 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
353 status
= acpi_execute_simple_method(device
->dev
->handle
,
355 if (ACPI_FAILURE(status
)) {
356 ACPI_ERROR((AE_INFO
, "Evaluating _BCM failed"));
360 device
->brightness
->curr
= level
;
361 for (state
= 2; state
< device
->brightness
->count
; state
++)
362 if (level
== device
->brightness
->levels
[state
]) {
363 if (device
->backlight
)
364 device
->backlight
->props
.brightness
= state
- 2;
368 ACPI_ERROR((AE_INFO
, "Current brightness invalid"));
373 * For some buggy _BQC methods, we need to add a constant value to
374 * the _BQC return value to get the actual current brightness level
377 static int bqc_offset_aml_bug_workaround
;
378 static int __init
video_set_bqc_offset(const struct dmi_system_id
*d
)
380 bqc_offset_aml_bug_workaround
= 9;
384 static struct dmi_system_id video_dmi_table
[] __initdata
= {
386 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
389 .callback
= video_set_bqc_offset
,
390 .ident
= "Acer Aspire 5720",
392 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
393 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5720"),
397 .callback
= video_set_bqc_offset
,
398 .ident
= "Acer Aspire 5710Z",
400 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
401 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5710Z"),
405 .callback
= video_set_bqc_offset
,
406 .ident
= "eMachines E510",
408 DMI_MATCH(DMI_BOARD_VENDOR
, "EMACHINES"),
409 DMI_MATCH(DMI_PRODUCT_NAME
, "eMachines E510"),
413 .callback
= video_set_bqc_offset
,
414 .ident
= "Acer Aspire 5315",
416 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
417 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5315"),
421 .callback
= video_set_bqc_offset
,
422 .ident
= "Acer Aspire 7720",
424 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
425 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 7720"),
431 static unsigned long long
432 acpi_video_bqc_value_to_level(struct acpi_video_device
*device
,
433 unsigned long long bqc_value
)
435 unsigned long long level
;
437 if (device
->brightness
->flags
._BQC_use_index
) {
439 * _BQC returns an index that doesn't account for
440 * the first 2 items with special meaning, so we need
441 * to compensate for that by offsetting ourselves
443 if (device
->brightness
->flags
._BCL_reversed
)
444 bqc_value
= device
->brightness
->count
- 3 - bqc_value
;
446 level
= device
->brightness
->levels
[bqc_value
+ 2];
451 level
+= bqc_offset_aml_bug_workaround
;
457 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
458 unsigned long long *level
, bool raw
)
460 acpi_status status
= AE_OK
;
463 if (device
->cap
._BQC
|| device
->cap
._BCQ
) {
464 char *buf
= device
->cap
._BQC
? "_BQC" : "_BCQ";
466 status
= acpi_evaluate_integer(device
->dev
->handle
, buf
,
468 if (ACPI_SUCCESS(status
)) {
471 * Caller has indicated he wants the raw
472 * value returned by _BQC, so don't furtherly
473 * mess with the value.
478 *level
= acpi_video_bqc_value_to_level(device
, *level
);
480 for (i
= 2; i
< device
->brightness
->count
; i
++)
481 if (device
->brightness
->levels
[i
] == *level
) {
482 device
->brightness
->curr
= *level
;
486 * BQC returned an invalid level.
489 ACPI_WARNING((AE_INFO
,
490 "%s returned an invalid level",
492 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
496 * should we return an error or ignore this failure?
497 * dev->brightness->curr is a cached value which stores
498 * the correct current backlight level in most cases.
499 * ACPI video backlight still works w/ buggy _BQC.
500 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
502 ACPI_WARNING((AE_INFO
, "Evaluating %s failed", buf
));
503 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
507 *level
= device
->brightness
->curr
;
512 acpi_video_device_EDID(struct acpi_video_device
*device
,
513 union acpi_object
**edid
, ssize_t length
)
516 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
517 union acpi_object
*obj
;
518 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
519 struct acpi_object_list args
= { 1, &arg0
};
527 arg0
.integer
.value
= 1;
528 else if (length
== 256)
529 arg0
.integer
.value
= 2;
533 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
534 if (ACPI_FAILURE(status
))
537 obj
= buffer
.pointer
;
539 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
542 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
554 * video : video bus device pointer
556 * 0. The system BIOS should NOT automatically switch(toggle)
557 * the active display output.
558 * 1. The system BIOS should automatically switch (toggle) the
559 * active display output. No switch event.
560 * 2. The _DGS value should be locked.
561 * 3. The system BIOS should not automatically switch (toggle) the
562 * active display output, but instead generate the display switch
565 * 0. The system BIOS should automatically control the brightness level
566 * of the LCD when the power changes from AC to DC
567 * 1. The system BIOS should NOT automatically control the brightness
568 * level of the LCD when the power changes from AC to DC.
574 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
578 if (!video
->cap
._DOS
)
581 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1)
583 video
->dos_setting
= (lcd_flag
<< 2) | bios_flag
;
584 status
= acpi_execute_simple_method(video
->device
->handle
, "_DOS",
585 (lcd_flag
<< 2) | bios_flag
);
586 if (ACPI_FAILURE(status
))
593 * Simple comparison function used to sort backlight levels.
597 acpi_video_cmp_level(const void *a
, const void *b
)
599 return *(int *)a
- *(int *)b
;
603 * Decides if _BQC/_BCQ for this system is usable
605 * We do this by changing the level first and then read out the current
606 * brightness level, if the value does not match, find out if it is using
607 * index. If not, clear the _BQC/_BCQ capability.
609 static int acpi_video_bqc_quirk(struct acpi_video_device
*device
,
610 int max_level
, int current_level
)
612 struct acpi_video_device_brightness
*br
= device
->brightness
;
614 unsigned long long level
;
617 /* don't mess with existing known broken systems */
618 if (bqc_offset_aml_bug_workaround
)
622 * Some systems always report current brightness level as maximum
623 * through _BQC, we need to test another value for them.
625 test_level
= current_level
== max_level
? br
->levels
[3] : max_level
;
627 result
= acpi_video_device_lcd_set_level(device
, test_level
);
631 result
= acpi_video_device_lcd_get_level_current(device
, &level
, true);
635 if (level
!= test_level
) {
636 /* buggy _BQC found, need to find out if it uses index */
637 if (level
< br
->count
) {
638 if (br
->flags
._BCL_reversed
)
639 level
= br
->count
- 3 - level
;
640 if (br
->levels
[level
+ 2] == test_level
)
641 br
->flags
._BQC_use_index
= 1;
644 if (!br
->flags
._BQC_use_index
)
645 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
654 * device : video output device (LCD, CRT, ..)
657 * Maximum brightness level
659 * Allocate and initialize device->brightness.
663 acpi_video_init_brightness(struct acpi_video_device
*device
)
665 union acpi_object
*obj
= NULL
;
666 int i
, max_level
= 0, count
= 0, level_ac_battery
= 0;
667 unsigned long long level
, level_old
;
668 union acpi_object
*o
;
669 struct acpi_video_device_brightness
*br
= NULL
;
670 int result
= -EINVAL
;
673 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
674 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
675 "LCD brightness level\n"));
679 if (obj
->package
.count
< 2)
682 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
684 printk(KERN_ERR
"can't allocate memory\n");
689 br
->levels
= kmalloc((obj
->package
.count
+ 2) * sizeof *(br
->levels
),
696 for (i
= 0; i
< obj
->package
.count
; i
++) {
697 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
698 if (o
->type
!= ACPI_TYPE_INTEGER
) {
699 printk(KERN_ERR PREFIX
"Invalid data\n");
702 value
= (u32
) o
->integer
.value
;
703 /* Skip duplicate entries */
704 if (count
> 2 && br
->levels
[count
- 1] == value
)
707 br
->levels
[count
] = value
;
709 if (br
->levels
[count
] > max_level
)
710 max_level
= br
->levels
[count
];
715 * some buggy BIOS don't export the levels
716 * when machine is on AC/Battery in _BCL package.
717 * In this case, the first two elements in _BCL packages
718 * are also supported brightness levels that OS should take care of.
720 for (i
= 2; i
< count
; i
++) {
721 if (br
->levels
[i
] == br
->levels
[0])
723 if (br
->levels
[i
] == br
->levels
[1])
727 if (level_ac_battery
< 2) {
728 level_ac_battery
= 2 - level_ac_battery
;
729 br
->flags
._BCL_no_ac_battery_levels
= 1;
730 for (i
= (count
- 1 + level_ac_battery
); i
>= 2; i
--)
731 br
->levels
[i
] = br
->levels
[i
- level_ac_battery
];
732 count
+= level_ac_battery
;
733 } else if (level_ac_battery
> 2)
734 ACPI_ERROR((AE_INFO
, "Too many duplicates in _BCL package"));
736 /* Check if the _BCL package is in a reversed order */
737 if (max_level
== br
->levels
[2]) {
738 br
->flags
._BCL_reversed
= 1;
739 sort(&br
->levels
[2], count
- 2, sizeof(br
->levels
[2]),
740 acpi_video_cmp_level
, NULL
);
741 } else if (max_level
!= br
->levels
[count
- 1])
743 "Found unordered _BCL package"));
746 device
->brightness
= br
;
748 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
749 br
->curr
= level
= max_level
;
751 if (!device
->cap
._BQC
)
754 result
= acpi_video_device_lcd_get_level_current(device
,
757 goto out_free_levels
;
759 result
= acpi_video_bqc_quirk(device
, max_level
, level_old
);
761 goto out_free_levels
;
763 * cap._BQC may get cleared due to _BQC is found to be broken
764 * in acpi_video_bqc_quirk, so check again here.
766 if (!device
->cap
._BQC
)
769 level
= acpi_video_bqc_value_to_level(device
, level_old
);
771 * On some buggy laptops, _BQC returns an uninitialized
772 * value when invoked for the first time, i.e.
773 * level_old is invalid (no matter whether it's a level
774 * or an index). Set the backlight to max_level in this case.
776 for (i
= 2; i
< br
->count
; i
++)
777 if (level
== br
->levels
[i
])
779 if (i
== br
->count
|| !level
)
783 result
= acpi_video_device_lcd_set_level(device
, level
);
785 goto out_free_levels
;
787 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
788 "found %d brightness levels\n", count
- 2));
797 device
->brightness
= NULL
;
804 * device : video output device (LCD, CRT, ..)
809 * Find out all required AML methods defined under the output
813 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
815 if (acpi_has_method(device
->dev
->handle
, "_ADR"))
816 device
->cap
._ADR
= 1;
817 if (acpi_has_method(device
->dev
->handle
, "_BCL"))
818 device
->cap
._BCL
= 1;
819 if (acpi_has_method(device
->dev
->handle
, "_BCM"))
820 device
->cap
._BCM
= 1;
821 if (acpi_has_method(device
->dev
->handle
, "_BQC")) {
822 device
->cap
._BQC
= 1;
823 } else if (acpi_has_method(device
->dev
->handle
, "_BCQ")) {
824 printk(KERN_WARNING FW_BUG
"_BCQ is used instead of _BQC\n");
825 device
->cap
._BCQ
= 1;
828 if (acpi_has_method(device
->dev
->handle
, "_DDC"))
829 device
->cap
._DDC
= 1;
831 if (acpi_video_backlight_support()) {
832 struct backlight_properties props
;
833 struct pci_dev
*pdev
;
834 acpi_handle acpi_parent
;
835 struct device
*parent
= NULL
;
840 result
= acpi_video_init_brightness(device
);
843 name
= kasprintf(GFP_KERNEL
, "acpi_video%d", count
);
848 acpi_get_parent(device
->dev
->handle
, &acpi_parent
);
850 pdev
= acpi_get_pci_dev(acpi_parent
);
856 memset(&props
, 0, sizeof(struct backlight_properties
));
857 props
.type
= BACKLIGHT_FIRMWARE
;
858 props
.max_brightness
= device
->brightness
->count
- 3;
859 device
->backlight
= backlight_device_register(name
,
865 if (IS_ERR(device
->backlight
))
869 * Save current brightness level in case we have to restore it
870 * before acpi_video_device_lcd_set_level() is called next time.
872 device
->backlight
->props
.brightness
=
873 acpi_video_get_brightness(device
->backlight
);
875 device
->cooling_dev
= thermal_cooling_device_register("LCD",
876 device
->dev
, &video_cooling_ops
);
877 if (IS_ERR(device
->cooling_dev
)) {
879 * Set cooling_dev to NULL so we don't crash trying to
881 * Also, why the hell we are returning early and
882 * not attempt to register video output if cooling
883 * device registration failed?
886 device
->cooling_dev
= NULL
;
890 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
891 device
->cooling_dev
->id
);
892 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
893 &device
->cooling_dev
->device
.kobj
,
896 printk(KERN_ERR PREFIX
"Create sysfs link\n");
897 result
= sysfs_create_link(&device
->cooling_dev
->device
.kobj
,
898 &device
->dev
->dev
.kobj
, "device");
900 printk(KERN_ERR PREFIX
"Create sysfs link\n");
907 * device : video output device (VGA)
912 * Find out all required AML methods defined under the video bus device.
915 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
917 if (acpi_has_method(video
->device
->handle
, "_DOS"))
919 if (acpi_has_method(video
->device
->handle
, "_DOD"))
921 if (acpi_has_method(video
->device
->handle
, "_ROM"))
923 if (acpi_has_method(video
->device
->handle
, "_GPD"))
925 if (acpi_has_method(video
->device
->handle
, "_SPD"))
927 if (acpi_has_method(video
->device
->handle
, "_VPO"))
932 * Check whether the video bus device has required AML method to
933 * support the desired features
936 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
938 acpi_status status
= -ENOENT
;
944 dev
= acpi_get_pci_dev(video
->device
->handle
);
950 * Since there is no HID, CID and so on for VGA driver, we have
951 * to check well known required nodes.
954 /* Does this device support video switching? */
955 if (video
->cap
._DOS
|| video
->cap
._DOD
) {
956 if (!video
->cap
._DOS
) {
957 printk(KERN_WARNING FW_BUG
958 "ACPI(%s) defines _DOD but not _DOS\n",
959 acpi_device_bid(video
->device
));
961 video
->flags
.multihead
= 1;
965 /* Does this device support retrieving a video ROM? */
966 if (video
->cap
._ROM
) {
967 video
->flags
.rom
= 1;
971 /* Does this device support configuring which video device to POST? */
972 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
973 video
->flags
.post
= 1;
981 * --------------------------------------------------------------------------
983 * --------------------------------------------------------------------------
986 /* device interface */
987 static struct acpi_video_device_attrib
*
988 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
990 struct acpi_video_enumerated_device
*ids
;
993 for (i
= 0; i
< video
->attached_count
; i
++) {
994 ids
= &video
->attached_array
[i
];
995 if ((ids
->value
.int_val
& 0xffff) == device_id
)
996 return &ids
->value
.attrib
;
1003 acpi_video_get_device_type(struct acpi_video_bus
*video
,
1004 unsigned long device_id
)
1006 struct acpi_video_enumerated_device
*ids
;
1009 for (i
= 0; i
< video
->attached_count
; i
++) {
1010 ids
= &video
->attached_array
[i
];
1011 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1012 return ids
->value
.int_val
;
1019 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1020 struct acpi_video_bus
*video
)
1022 unsigned long long device_id
;
1023 int status
, device_type
;
1024 struct acpi_video_device
*data
;
1025 struct acpi_video_device_attrib
*attribute
;
1028 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1029 /* Some device omits _ADR, we skip them instead of fail */
1030 if (ACPI_FAILURE(status
))
1033 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1037 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1038 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1039 device
->driver_data
= data
;
1041 data
->device_id
= device_id
;
1042 data
->video
= video
;
1045 attribute
= acpi_video_get_device_attr(video
, device_id
);
1047 if (attribute
&& attribute
->device_id_scheme
) {
1048 switch (attribute
->display_type
) {
1049 case ACPI_VIDEO_DISPLAY_CRT
:
1050 data
->flags
.crt
= 1;
1052 case ACPI_VIDEO_DISPLAY_TV
:
1053 data
->flags
.tvout
= 1;
1055 case ACPI_VIDEO_DISPLAY_DVI
:
1056 data
->flags
.dvi
= 1;
1058 case ACPI_VIDEO_DISPLAY_LCD
:
1059 data
->flags
.lcd
= 1;
1062 data
->flags
.unknown
= 1;
1065 if (attribute
->bios_can_detect
)
1066 data
->flags
.bios
= 1;
1068 /* Check for legacy IDs */
1069 device_type
= acpi_video_get_device_type(video
, device_id
);
1070 /* Ignore bits 16 and 18-20 */
1071 switch (device_type
& 0xffe2ffff) {
1072 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR
:
1073 data
->flags
.crt
= 1;
1075 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL
:
1076 data
->flags
.lcd
= 1;
1078 case ACPI_VIDEO_DISPLAY_LEGACY_TV
:
1079 data
->flags
.tvout
= 1;
1082 data
->flags
.unknown
= 1;
1086 acpi_video_device_bind(video
, data
);
1087 acpi_video_device_find_cap(data
);
1089 status
= acpi_install_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
1090 acpi_video_device_notify
, data
);
1091 if (ACPI_FAILURE(status
))
1092 dev_err(&device
->dev
, "Error installing notify handler\n");
1094 data
->flags
.notify
= 1;
1096 mutex_lock(&video
->device_list_lock
);
1097 list_add_tail(&data
->entry
, &video
->video_device_list
);
1098 mutex_unlock(&video
->device_list_lock
);
1105 * video : video bus device
1110 * Enumerate the video device list of the video bus,
1111 * bind the ids with the corresponding video devices
1112 * under the video bus.
1115 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1117 struct acpi_video_device
*dev
;
1119 mutex_lock(&video
->device_list_lock
);
1121 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1122 acpi_video_device_bind(video
, dev
);
1124 mutex_unlock(&video
->device_list_lock
);
1129 * video : video bus device
1130 * device : video output device under the video
1136 * Bind the ids with the corresponding video devices
1137 * under the video bus.
1141 acpi_video_device_bind(struct acpi_video_bus
*video
,
1142 struct acpi_video_device
*device
)
1144 struct acpi_video_enumerated_device
*ids
;
1147 for (i
= 0; i
< video
->attached_count
; i
++) {
1148 ids
= &video
->attached_array
[i
];
1149 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1150 ids
->bind_info
= device
;
1151 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1158 * video : video bus device
1163 * Call _DOD to enumerate all devices attached to display adapter
1167 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1172 struct acpi_video_enumerated_device
*active_list
;
1173 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1174 union acpi_object
*dod
= NULL
;
1175 union acpi_object
*obj
;
1177 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1178 if (!ACPI_SUCCESS(status
)) {
1179 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1183 dod
= buffer
.pointer
;
1184 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1185 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1190 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1191 dod
->package
.count
));
1193 active_list
= kcalloc(1 + dod
->package
.count
,
1194 sizeof(struct acpi_video_enumerated_device
),
1202 for (i
= 0; i
< dod
->package
.count
; i
++) {
1203 obj
= &dod
->package
.elements
[i
];
1205 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1206 printk(KERN_ERR PREFIX
1207 "Invalid _DOD data in element %d\n", i
);
1211 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1212 active_list
[count
].bind_info
= NULL
;
1213 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1214 (int)obj
->integer
.value
));
1218 kfree(video
->attached_array
);
1220 video
->attached_array
= active_list
;
1221 video
->attached_count
= count
;
1224 kfree(buffer
.pointer
);
1229 acpi_video_get_next_level(struct acpi_video_device
*device
,
1230 u32 level_current
, u32 event
)
1232 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1233 max
= max_below
= 0;
1234 min
= min_above
= 255;
1235 /* Find closest level to level_current */
1236 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1237 l
= device
->brightness
->levels
[i
];
1238 if (abs(l
- level_current
) < abs(delta
)) {
1239 delta
= l
- level_current
;
1244 /* Ajust level_current to closest available level */
1245 level_current
+= delta
;
1246 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1247 l
= device
->brightness
->levels
[i
];
1252 if (l
< min_above
&& l
> level_current
)
1254 if (l
> max_below
&& l
< level_current
)
1259 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1260 return (level_current
< max
) ? min_above
: min
;
1261 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1262 return (level_current
< max
) ? min_above
: max
;
1263 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1264 return (level_current
> min
) ? max_below
: min
;
1265 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1266 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1269 return level_current
;
1274 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1276 unsigned long long level_current
, level_next
;
1277 int result
= -EINVAL
;
1279 /* no warning message if acpi_backlight=vendor is used */
1280 if (!acpi_video_backlight_support())
1283 if (!device
->brightness
)
1286 result
= acpi_video_device_lcd_get_level_current(device
,
1292 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1294 result
= acpi_video_device_lcd_set_level(device
, level_next
);
1297 backlight_force_update(device
->backlight
,
1298 BACKLIGHT_UPDATE_HOTKEY
);
1302 printk(KERN_ERR PREFIX
"Failed to switch the brightness\n");
1307 int acpi_video_get_edid(struct acpi_device
*device
, int type
, int device_id
,
1310 struct acpi_video_bus
*video
;
1311 struct acpi_video_device
*video_device
;
1312 union acpi_object
*buffer
= NULL
;
1316 if (!device
|| !acpi_driver_data(device
))
1319 video
= acpi_driver_data(device
);
1321 for (i
= 0; i
< video
->attached_count
; i
++) {
1322 video_device
= video
->attached_array
[i
].bind_info
;
1328 if (!video_device
->cap
._DDC
)
1333 case ACPI_VIDEO_DISPLAY_CRT
:
1334 if (!video_device
->flags
.crt
)
1337 case ACPI_VIDEO_DISPLAY_TV
:
1338 if (!video_device
->flags
.tvout
)
1341 case ACPI_VIDEO_DISPLAY_DVI
:
1342 if (!video_device
->flags
.dvi
)
1345 case ACPI_VIDEO_DISPLAY_LCD
:
1346 if (!video_device
->flags
.lcd
)
1350 } else if (video_device
->device_id
!= device_id
) {
1354 status
= acpi_video_device_EDID(video_device
, &buffer
, length
);
1356 if (ACPI_FAILURE(status
) || !buffer
||
1357 buffer
->type
!= ACPI_TYPE_BUFFER
) {
1359 status
= acpi_video_device_EDID(video_device
, &buffer
,
1361 if (ACPI_FAILURE(status
) || !buffer
||
1362 buffer
->type
!= ACPI_TYPE_BUFFER
) {
1367 *edid
= buffer
->buffer
.pointer
;
1373 EXPORT_SYMBOL(acpi_video_get_edid
);
1376 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1377 struct acpi_device
*device
)
1380 struct acpi_device
*dev
;
1383 * There are systems where video module known to work fine regardless
1384 * of broken _DOD and ignoring returned value here doesn't cause
1387 acpi_video_device_enumerate(video
);
1389 list_for_each_entry(dev
, &device
->children
, node
) {
1391 status
= acpi_video_bus_get_one_device(dev
, video
);
1393 dev_err(&dev
->dev
, "Can't attach device\n");
1400 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1404 if (!device
|| !device
->video
)
1407 if (device
->flags
.notify
) {
1408 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1409 ACPI_DEVICE_NOTIFY
, acpi_video_device_notify
);
1410 if (ACPI_FAILURE(status
))
1411 dev_err(&device
->dev
->dev
,
1412 "Can't remove video notify handler\n");
1415 if (device
->backlight
) {
1416 backlight_device_unregister(device
->backlight
);
1417 device
->backlight
= NULL
;
1419 if (device
->cooling_dev
) {
1420 sysfs_remove_link(&device
->dev
->dev
.kobj
,
1422 sysfs_remove_link(&device
->cooling_dev
->device
.kobj
,
1424 thermal_cooling_device_unregister(device
->cooling_dev
);
1425 device
->cooling_dev
= NULL
;
1431 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1434 struct acpi_video_device
*dev
, *next
;
1436 mutex_lock(&video
->device_list_lock
);
1438 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1440 status
= acpi_video_bus_put_one_device(dev
);
1441 if (ACPI_FAILURE(status
))
1442 printk(KERN_WARNING PREFIX
1443 "hhuuhhuu bug in acpi video driver.\n");
1445 if (dev
->brightness
) {
1446 kfree(dev
->brightness
->levels
);
1447 kfree(dev
->brightness
);
1449 list_del(&dev
->entry
);
1453 mutex_unlock(&video
->device_list_lock
);
1458 /* acpi_video interface */
1461 * Win8 requires setting bit2 of _DOS to let firmware know it shouldn't
1462 * preform any automatic brightness change on receiving a notification.
1464 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1466 return acpi_video_bus_DOS(video
, 0,
1467 acpi_video_backlight_quirks() ? 1 : 0);
1470 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1472 return acpi_video_bus_DOS(video
, 0,
1473 acpi_video_backlight_quirks() ? 0 : 1);
1476 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
)
1478 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1479 struct input_dev
*input
;
1485 input
= video
->input
;
1488 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1489 * most likely via hotkey. */
1490 keycode
= KEY_SWITCHVIDEOMODE
;
1493 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1495 acpi_video_device_enumerate(video
);
1496 acpi_video_device_rebind(video
);
1497 keycode
= KEY_SWITCHVIDEOMODE
;
1500 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1501 keycode
= KEY_SWITCHVIDEOMODE
;
1503 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1504 keycode
= KEY_VIDEO_NEXT
;
1506 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1507 keycode
= KEY_VIDEO_PREV
;
1511 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1512 "Unsupported event [0x%x]\n", event
));
1516 if (acpi_notifier_call_chain(device
, event
, 0))
1517 /* Something vetoed the keypress. */
1521 input_report_key(input
, keycode
, 1);
1523 input_report_key(input
, keycode
, 0);
1530 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1532 struct acpi_video_device
*video_device
= data
;
1533 struct acpi_device
*device
= NULL
;
1534 struct acpi_video_bus
*bus
;
1535 struct input_dev
*input
;
1541 device
= video_device
->dev
;
1542 bus
= video_device
->video
;
1546 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1547 if (brightness_switch_enabled
)
1548 acpi_video_switch_brightness(video_device
, event
);
1549 keycode
= KEY_BRIGHTNESS_CYCLE
;
1551 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1552 if (brightness_switch_enabled
)
1553 acpi_video_switch_brightness(video_device
, event
);
1554 keycode
= KEY_BRIGHTNESSUP
;
1556 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1557 if (brightness_switch_enabled
)
1558 acpi_video_switch_brightness(video_device
, event
);
1559 keycode
= KEY_BRIGHTNESSDOWN
;
1561 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightness */
1562 if (brightness_switch_enabled
)
1563 acpi_video_switch_brightness(video_device
, event
);
1564 keycode
= KEY_BRIGHTNESS_ZERO
;
1566 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1567 if (brightness_switch_enabled
)
1568 acpi_video_switch_brightness(video_device
, event
);
1569 keycode
= KEY_DISPLAY_OFF
;
1572 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1573 "Unsupported event [0x%x]\n", event
));
1577 acpi_notifier_call_chain(device
, event
, 0);
1580 input_report_key(input
, keycode
, 1);
1582 input_report_key(input
, keycode
, 0);
1589 static int acpi_video_resume(struct notifier_block
*nb
,
1590 unsigned long val
, void *ign
)
1592 struct acpi_video_bus
*video
;
1593 struct acpi_video_device
*video_device
;
1597 case PM_HIBERNATION_PREPARE
:
1598 case PM_SUSPEND_PREPARE
:
1599 case PM_RESTORE_PREPARE
:
1603 video
= container_of(nb
, struct acpi_video_bus
, pm_nb
);
1605 dev_info(&video
->device
->dev
, "Restoring backlight state\n");
1607 for (i
= 0; i
< video
->attached_count
; i
++) {
1608 video_device
= video
->attached_array
[i
].bind_info
;
1609 if (video_device
&& video_device
->backlight
)
1610 acpi_video_set_brightness(video_device
->backlight
);
1617 acpi_video_bus_match(acpi_handle handle
, u32 level
, void *context
,
1618 void **return_value
)
1620 struct acpi_device
*device
= context
;
1621 struct acpi_device
*sibling
;
1624 if (handle
== device
->handle
)
1625 return AE_CTRL_TERMINATE
;
1627 result
= acpi_bus_get_device(handle
, &sibling
);
1631 if (!strcmp(acpi_device_name(sibling
), ACPI_VIDEO_BUS_NAME
))
1632 return AE_ALREADY_EXISTS
;
1637 static int instance
;
1639 static int acpi_video_bus_add(struct acpi_device
*device
)
1641 struct acpi_video_bus
*video
;
1642 struct input_dev
*input
;
1646 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
,
1647 device
->parent
->handle
, 1,
1648 acpi_video_bus_match
, NULL
,
1650 if (status
== AE_ALREADY_EXISTS
) {
1651 printk(KERN_WARNING FW_BUG
1652 "Duplicate ACPI video bus devices for the"
1653 " same VGA controller, please try module "
1654 "parameter \"video.allow_duplicates=1\""
1655 "if the current driver doesn't work.\n");
1656 if (!allow_duplicates
)
1660 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1664 /* a hack to fix the duplicate name "VID" problem on T61 */
1665 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
1667 device
->pnp
.bus_id
[3] = '0' + instance
;
1670 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
1671 if (!strcmp(device
->pnp
.bus_id
, "VGA")) {
1673 device
->pnp
.bus_id
[3] = '0' + instance
;
1677 video
->device
= device
;
1678 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1679 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1680 device
->driver_data
= video
;
1682 acpi_video_bus_find_cap(video
);
1683 error
= acpi_video_bus_check(video
);
1685 goto err_free_video
;
1687 mutex_init(&video
->device_list_lock
);
1688 INIT_LIST_HEAD(&video
->video_device_list
);
1690 error
= acpi_video_bus_get_devices(video
, device
);
1694 video
->input
= input
= input_allocate_device();
1700 error
= acpi_video_bus_start_devices(video
);
1702 goto err_free_input_dev
;
1704 snprintf(video
->phys
, sizeof(video
->phys
),
1705 "%s/video/input0", acpi_device_hid(video
->device
));
1707 input
->name
= acpi_device_name(video
->device
);
1708 input
->phys
= video
->phys
;
1709 input
->id
.bustype
= BUS_HOST
;
1710 input
->id
.product
= 0x06;
1711 input
->dev
.parent
= &device
->dev
;
1712 input
->evbit
[0] = BIT(EV_KEY
);
1713 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
1714 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
1715 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
1716 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
1717 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
1718 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
1719 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
1720 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
1722 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1723 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1724 video
->flags
.multihead
? "yes" : "no",
1725 video
->flags
.rom
? "yes" : "no",
1726 video
->flags
.post
? "yes" : "no");
1728 video
->pm_nb
.notifier_call
= acpi_video_resume
;
1729 video
->pm_nb
.priority
= 0;
1730 error
= register_pm_notifier(&video
->pm_nb
);
1732 goto err_stop_video
;
1734 error
= input_register_device(input
);
1736 goto err_unregister_pm_notifier
;
1740 err_unregister_pm_notifier
:
1741 unregister_pm_notifier(&video
->pm_nb
);
1743 acpi_video_bus_stop_devices(video
);
1745 input_free_device(input
);
1747 acpi_video_bus_put_devices(video
);
1748 kfree(video
->attached_array
);
1751 device
->driver_data
= NULL
;
1756 static int acpi_video_bus_remove(struct acpi_device
*device
)
1758 struct acpi_video_bus
*video
= NULL
;
1761 if (!device
|| !acpi_driver_data(device
))
1764 video
= acpi_driver_data(device
);
1766 unregister_pm_notifier(&video
->pm_nb
);
1768 acpi_video_bus_stop_devices(video
);
1769 acpi_video_bus_put_devices(video
);
1771 input_unregister_device(video
->input
);
1772 kfree(video
->attached_array
);
1778 static int __init
is_i740(struct pci_dev
*dev
)
1780 if (dev
->device
== 0x00D1)
1782 if (dev
->device
== 0x7000)
1787 static int __init
intel_opregion_present(void)
1790 struct pci_dev
*dev
= NULL
;
1793 for_each_pci_dev(dev
) {
1794 if ((dev
->class >> 8) != PCI_CLASS_DISPLAY_VGA
)
1796 if (dev
->vendor
!= PCI_VENDOR_ID_INTEL
)
1798 /* We don't want to poke around undefined i740 registers */
1801 pci_read_config_dword(dev
, 0xfc, &address
);
1809 int acpi_video_register(void)
1812 if (register_count
) {
1814 * if the function of acpi_video_register is already called,
1815 * don't register the acpi_vide_bus again and return no error.
1820 result
= acpi_bus_register_driver(&acpi_video_bus
);
1825 * When the acpi_video_bus is loaded successfully, increase
1826 * the counter reference.
1832 EXPORT_SYMBOL(acpi_video_register
);
1834 void acpi_video_unregister(void)
1836 if (!register_count
) {
1838 * If the acpi video bus is already unloaded, don't
1839 * unload it again and return directly.
1843 acpi_bus_unregister_driver(&acpi_video_bus
);
1849 EXPORT_SYMBOL(acpi_video_unregister
);
1852 * This is kind of nasty. Hardware using Intel chipsets may require
1853 * the video opregion code to be run first in order to initialise
1854 * state before any ACPI video calls are made. To handle this we defer
1855 * registration of the video class until the opregion code has run.
1858 static int __init
acpi_video_init(void)
1861 * Let the module load even if ACPI is disabled (e.g. due to
1862 * a broken BIOS) so that i915.ko can still be loaded on such
1863 * old systems without an AcpiOpRegion.
1865 * acpi_video_register() will report -ENODEV later as well due
1866 * to acpi_disabled when i915.ko tries to register itself afterwards.
1871 dmi_check_system(video_dmi_table
);
1873 if (intel_opregion_present())
1876 return acpi_video_register();
1879 static void __exit
acpi_video_exit(void)
1881 acpi_video_unregister();
1886 module_init(acpi_video_init
);
1887 module_exit(acpi_video_exit
);