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/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/thermal.h>
38 #include <linux/video_output.h>
39 #include <linux/sort.h>
40 #include <linux/pci.h>
41 #include <linux/pci_ids.h>
42 #include <linux/slab.h>
43 #include <asm/uaccess.h>
44 #include <linux/dmi.h>
45 #include <acpi/acpi_bus.h>
46 #include <acpi/acpi_drivers.h>
47 #include <linux/suspend.h>
48 #include <acpi/video.h>
50 #define PREFIX "ACPI: "
52 #define ACPI_VIDEO_CLASS "video"
53 #define ACPI_VIDEO_BUS_NAME "Video Bus"
54 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
55 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
56 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
57 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
58 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
59 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
61 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
62 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
63 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
64 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
65 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
67 #define MAX_NAME_LEN 20
69 #define _COMPONENT ACPI_VIDEO_COMPONENT
70 ACPI_MODULE_NAME("video");
72 MODULE_AUTHOR("Bruno Ducrot");
73 MODULE_DESCRIPTION("ACPI Video Driver");
74 MODULE_LICENSE("GPL");
76 static int brightness_switch_enabled
= 1;
77 module_param(brightness_switch_enabled
, bool, 0644);
80 * By default, we don't allow duplicate ACPI video bus devices
81 * under the same VGA controller
83 static int allow_duplicates
;
84 module_param(allow_duplicates
, bool, 0644);
86 static int register_count
= 0;
87 static int acpi_video_bus_add(struct acpi_device
*device
);
88 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
89 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
);
91 static const struct acpi_device_id video_device_ids
[] = {
95 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
97 static struct acpi_driver acpi_video_bus
= {
99 .class = ACPI_VIDEO_CLASS
,
100 .ids
= video_device_ids
,
102 .add
= acpi_video_bus_add
,
103 .remove
= acpi_video_bus_remove
,
104 .notify
= acpi_video_bus_notify
,
108 struct acpi_video_bus_flags
{
109 u8 multihead
:1; /* can switch video heads */
110 u8 rom
:1; /* can retrieve a video rom */
111 u8 post
:1; /* can configure the head to */
115 struct acpi_video_bus_cap
{
116 u8 _DOS
:1; /*Enable/Disable output switching */
117 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
118 u8 _ROM
:1; /*Get ROM Data */
119 u8 _GPD
:1; /*Get POST Device */
120 u8 _SPD
:1; /*Set POST Device */
121 u8 _VPO
:1; /*Video POST Options */
125 struct acpi_video_device_attrib
{
126 u32 display_index
:4; /* A zero-based instance of the Display */
127 u32 display_port_attachment
:4; /*This field differentiates the display type */
128 u32 display_type
:4; /*Describe the specific type in use */
129 u32 vendor_specific
:4; /*Chipset Vendor Specific */
130 u32 bios_can_detect
:1; /*BIOS can detect the device */
131 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
133 u32 pipe_id
:3; /*For VGA multiple-head devices. */
134 u32 reserved
:10; /*Must be 0 */
135 u32 device_id_scheme
:1; /*Device ID Scheme */
138 struct acpi_video_enumerated_device
{
141 struct acpi_video_device_attrib attrib
;
143 struct acpi_video_device
*bind_info
;
146 struct acpi_video_bus
{
147 struct acpi_device
*device
;
149 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 #ifdef CONFIG_ACPI_PROCFS
156 struct proc_dir_entry
*dir
;
158 struct input_dev
*input
;
159 char phys
[32]; /* for input device */
160 struct notifier_block pm_nb
;
163 struct acpi_video_device_flags
{
173 struct acpi_video_device_cap
{
174 u8 _ADR
:1; /*Return the unique ID */
175 u8 _BCL
:1; /*Query list of brightness control levels supported */
176 u8 _BCM
:1; /*Set the brightness level */
177 u8 _BQC
:1; /* Get current brightness level */
178 u8 _BCQ
:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
179 u8 _DDC
:1; /*Return the EDID for this device */
180 u8 _DCS
:1; /*Return status of output device */
181 u8 _DGS
:1; /*Query graphics state */
182 u8 _DSS
:1; /*Device state set */
185 struct acpi_video_brightness_flags
{
186 u8 _BCL_no_ac_battery_levels
:1; /* no AC/Battery levels in _BCL */
187 u8 _BCL_reversed
:1; /* _BCL package is in a reversed order*/
188 u8 _BCL_use_index
:1; /* levels in _BCL are index values */
189 u8 _BCM_use_index
:1; /* input of _BCM is an index value */
190 u8 _BQC_use_index
:1; /* _BQC returns an index value */
193 struct acpi_video_device_brightness
{
197 struct acpi_video_brightness_flags flags
;
200 struct acpi_video_device
{
201 unsigned long device_id
;
202 struct acpi_video_device_flags flags
;
203 struct acpi_video_device_cap cap
;
204 struct list_head entry
;
205 struct acpi_video_bus
*video
;
206 struct acpi_device
*dev
;
207 struct acpi_video_device_brightness
*brightness
;
208 struct backlight_device
*backlight
;
209 struct thermal_cooling_device
*cooling_dev
;
210 struct output_device
*output_dev
;
213 #ifdef CONFIG_ACPI_PROCFS
215 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
216 static const struct file_operations acpi_video_bus_info_fops
= {
217 .owner
= THIS_MODULE
,
218 .open
= acpi_video_bus_info_open_fs
,
221 .release
= single_release
,
224 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
225 static const struct file_operations acpi_video_bus_ROM_fops
= {
226 .owner
= THIS_MODULE
,
227 .open
= acpi_video_bus_ROM_open_fs
,
230 .release
= single_release
,
233 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
235 static const struct file_operations acpi_video_bus_POST_info_fops
= {
236 .owner
= THIS_MODULE
,
237 .open
= acpi_video_bus_POST_info_open_fs
,
240 .release
= single_release
,
243 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
244 static ssize_t
acpi_video_bus_write_POST(struct file
*file
,
245 const char __user
*buffer
, size_t count
, loff_t
*data
);
246 static const struct file_operations acpi_video_bus_POST_fops
= {
247 .owner
= THIS_MODULE
,
248 .open
= acpi_video_bus_POST_open_fs
,
250 .write
= acpi_video_bus_write_POST
,
252 .release
= single_release
,
255 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
256 static ssize_t
acpi_video_bus_write_DOS(struct file
*file
,
257 const char __user
*buffer
, size_t count
, loff_t
*data
);
258 static const struct file_operations acpi_video_bus_DOS_fops
= {
259 .owner
= THIS_MODULE
,
260 .open
= acpi_video_bus_DOS_open_fs
,
262 .write
= acpi_video_bus_write_DOS
,
264 .release
= single_release
,
268 static int acpi_video_device_info_open_fs(struct inode
*inode
,
270 static const struct file_operations acpi_video_device_info_fops
= {
271 .owner
= THIS_MODULE
,
272 .open
= acpi_video_device_info_open_fs
,
275 .release
= single_release
,
278 static int acpi_video_device_state_open_fs(struct inode
*inode
,
280 static ssize_t
acpi_video_device_write_state(struct file
*file
,
281 const char __user
*buffer
, size_t count
, loff_t
*data
);
282 static const struct file_operations acpi_video_device_state_fops
= {
283 .owner
= THIS_MODULE
,
284 .open
= acpi_video_device_state_open_fs
,
286 .write
= acpi_video_device_write_state
,
288 .release
= single_release
,
291 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
293 static ssize_t
acpi_video_device_write_brightness(struct file
*file
,
294 const char __user
*buffer
, size_t count
, loff_t
*data
);
295 static const struct file_operations acpi_video_device_brightness_fops
= {
296 .owner
= THIS_MODULE
,
297 .open
= acpi_video_device_brightness_open_fs
,
299 .write
= acpi_video_device_write_brightness
,
301 .release
= single_release
,
304 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
306 static const struct file_operations acpi_video_device_EDID_fops
= {
307 .owner
= THIS_MODULE
,
308 .open
= acpi_video_device_EDID_open_fs
,
311 .release
= single_release
,
313 #endif /* CONFIG_ACPI_PROCFS */
315 static const char device_decode
[][30] = {
316 "motherboard VGA device",
322 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
323 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
324 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
325 struct acpi_video_device
*device
);
326 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
327 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
329 static int acpi_video_device_lcd_get_level_current(
330 struct acpi_video_device
*device
,
331 unsigned long long *level
, int init
);
332 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
333 u32 level_current
, u32 event
);
334 static int acpi_video_switch_brightness(struct acpi_video_device
*device
,
336 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
337 unsigned long long *state
);
338 static int acpi_video_output_get(struct output_device
*od
);
339 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
341 /*backlight device sysfs support*/
342 static int acpi_video_get_brightness(struct backlight_device
*bd
)
344 unsigned long long cur_level
;
346 struct acpi_video_device
*vd
=
347 (struct acpi_video_device
*)bl_get_data(bd
);
349 if (acpi_video_device_lcd_get_level_current(vd
, &cur_level
, 0))
351 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
352 if (vd
->brightness
->levels
[i
] == cur_level
)
353 /* The first two entries are special - see page 575
354 of the ACPI spec 3.0 */
360 static int acpi_video_set_brightness(struct backlight_device
*bd
)
362 int request_level
= bd
->props
.brightness
+ 2;
363 struct acpi_video_device
*vd
=
364 (struct acpi_video_device
*)bl_get_data(bd
);
366 return acpi_video_device_lcd_set_level(vd
,
367 vd
->brightness
->levels
[request_level
]);
370 static struct backlight_ops acpi_backlight_ops
= {
371 .get_brightness
= acpi_video_get_brightness
,
372 .update_status
= acpi_video_set_brightness
,
375 /*video output device sysfs support*/
376 static int acpi_video_output_get(struct output_device
*od
)
378 unsigned long long state
;
379 struct acpi_video_device
*vd
=
380 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
381 acpi_video_device_get_state(vd
, &state
);
385 static int acpi_video_output_set(struct output_device
*od
)
387 unsigned long state
= od
->request_state
;
388 struct acpi_video_device
*vd
=
389 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
390 return acpi_video_device_set_state(vd
, state
);
393 static struct output_properties acpi_output_properties
= {
394 .set_state
= acpi_video_output_set
,
395 .get_status
= acpi_video_output_get
,
399 /* thermal cooling device callbacks */
400 static int video_get_max_state(struct thermal_cooling_device
*cooling_dev
, unsigned
403 struct acpi_device
*device
= cooling_dev
->devdata
;
404 struct acpi_video_device
*video
= acpi_driver_data(device
);
406 *state
= video
->brightness
->count
- 3;
410 static int video_get_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned
413 struct acpi_device
*device
= cooling_dev
->devdata
;
414 struct acpi_video_device
*video
= acpi_driver_data(device
);
415 unsigned long long level
;
418 if (acpi_video_device_lcd_get_level_current(video
, &level
, 0))
420 for (offset
= 2; offset
< video
->brightness
->count
; offset
++)
421 if (level
== video
->brightness
->levels
[offset
]) {
422 *state
= video
->brightness
->count
- offset
- 1;
430 video_set_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned long state
)
432 struct acpi_device
*device
= cooling_dev
->devdata
;
433 struct acpi_video_device
*video
= acpi_driver_data(device
);
436 if ( state
>= video
->brightness
->count
- 2)
439 state
= video
->brightness
->count
- state
;
440 level
= video
->brightness
->levels
[state
-1];
441 return acpi_video_device_lcd_set_level(video
, level
);
444 static struct thermal_cooling_device_ops video_cooling_ops
= {
445 .get_max_state
= video_get_max_state
,
446 .get_cur_state
= video_get_cur_state
,
447 .set_cur_state
= video_set_cur_state
,
450 /* --------------------------------------------------------------------------
452 -------------------------------------------------------------------------- */
457 acpi_video_device_get_state(struct acpi_video_device
*device
,
458 unsigned long long *state
)
462 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
468 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
471 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
472 struct acpi_object_list args
= { 1, &arg0
};
473 unsigned long long ret
;
476 arg0
.integer
.value
= state
;
477 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
483 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
484 union acpi_object
**levels
)
487 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
488 union acpi_object
*obj
;
493 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
494 if (!ACPI_SUCCESS(status
))
496 obj
= (union acpi_object
*)buffer
.pointer
;
497 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
498 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
508 kfree(buffer
.pointer
);
514 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
517 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
518 struct acpi_object_list args
= { 1, &arg0
};
521 arg0
.integer
.value
= level
;
523 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
525 if (ACPI_FAILURE(status
)) {
526 ACPI_ERROR((AE_INFO
, "Evaluating _BCM failed"));
530 device
->brightness
->curr
= level
;
531 for (state
= 2; state
< device
->brightness
->count
; state
++)
532 if (level
== device
->brightness
->levels
[state
]) {
533 if (device
->backlight
)
534 device
->backlight
->props
.brightness
= state
- 2;
538 ACPI_ERROR((AE_INFO
, "Current brightness invalid"));
543 * For some buggy _BQC methods, we need to add a constant value to
544 * the _BQC return value to get the actual current brightness level
547 static int bqc_offset_aml_bug_workaround
;
548 static int __init
video_set_bqc_offset(const struct dmi_system_id
*d
)
550 bqc_offset_aml_bug_workaround
= 9;
554 static struct dmi_system_id video_dmi_table
[] __initdata
= {
556 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
559 .callback
= video_set_bqc_offset
,
560 .ident
= "Acer Aspire 5720",
562 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
563 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5720"),
567 .callback
= video_set_bqc_offset
,
568 .ident
= "Acer Aspire 5710Z",
570 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
571 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5710Z"),
575 .callback
= video_set_bqc_offset
,
576 .ident
= "eMachines E510",
578 DMI_MATCH(DMI_BOARD_VENDOR
, "EMACHINES"),
579 DMI_MATCH(DMI_PRODUCT_NAME
, "eMachines E510"),
583 .callback
= video_set_bqc_offset
,
584 .ident
= "Acer Aspire 5315",
586 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
587 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5315"),
591 .callback
= video_set_bqc_offset
,
592 .ident
= "Acer Aspire 7720",
594 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
595 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 7720"),
602 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
603 unsigned long long *level
, int init
)
605 acpi_status status
= AE_OK
;
608 if (device
->cap
._BQC
|| device
->cap
._BCQ
) {
609 char *buf
= device
->cap
._BQC
? "_BQC" : "_BCQ";
611 status
= acpi_evaluate_integer(device
->dev
->handle
, buf
,
613 if (ACPI_SUCCESS(status
)) {
614 if (device
->brightness
->flags
._BQC_use_index
) {
615 if (device
->brightness
->flags
._BCL_reversed
)
616 *level
= device
->brightness
->count
618 *level
= device
->brightness
->levels
[*level
+ 2];
621 *level
+= bqc_offset_aml_bug_workaround
;
622 for (i
= 2; i
< device
->brightness
->count
; i
++)
623 if (device
->brightness
->levels
[i
] == *level
) {
624 device
->brightness
->curr
= *level
;
629 * BQC returned an invalid level.
632 ACPI_WARNING((AE_INFO
,
633 "%s returned an invalid level",
635 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
639 * should we return an error or ignore this failure?
640 * dev->brightness->curr is a cached value which stores
641 * the correct current backlight level in most cases.
642 * ACPI video backlight still works w/ buggy _BQC.
643 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
645 ACPI_WARNING((AE_INFO
, "Evaluating %s failed", buf
));
646 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
650 *level
= device
->brightness
->curr
;
655 acpi_video_device_EDID(struct acpi_video_device
*device
,
656 union acpi_object
**edid
, ssize_t length
)
659 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
660 union acpi_object
*obj
;
661 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
662 struct acpi_object_list args
= { 1, &arg0
};
670 arg0
.integer
.value
= 1;
671 else if (length
== 256)
672 arg0
.integer
.value
= 2;
676 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
677 if (ACPI_FAILURE(status
))
680 obj
= buffer
.pointer
;
682 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
685 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
697 * video : video bus device pointer
699 * 0. The system BIOS should NOT automatically switch(toggle)
700 * the active display output.
701 * 1. The system BIOS should automatically switch (toggle) the
702 * active display output. No switch event.
703 * 2. The _DGS value should be locked.
704 * 3. The system BIOS should not automatically switch (toggle) the
705 * active display output, but instead generate the display switch
708 * 0. The system BIOS should automatically control the brightness level
709 * of the LCD when the power changes from AC to DC
710 * 1. The system BIOS should NOT automatically control the brightness
711 * level of the LCD when the power changes from AC to DC.
717 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
720 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
721 struct acpi_object_list args
= { 1, &arg0
};
724 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
728 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
729 video
->dos_setting
= arg0
.integer
.value
;
730 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
737 * Simple comparison function used to sort backlight levels.
741 acpi_video_cmp_level(const void *a
, const void *b
)
743 return *(int *)a
- *(int *)b
;
748 * device : video output device (LCD, CRT, ..)
751 * Maximum brightness level
753 * Allocate and initialize device->brightness.
757 acpi_video_init_brightness(struct acpi_video_device
*device
)
759 union acpi_object
*obj
= NULL
;
760 int i
, max_level
= 0, count
= 0, level_ac_battery
= 0;
761 unsigned long long level
, level_old
;
762 union acpi_object
*o
;
763 struct acpi_video_device_brightness
*br
= NULL
;
764 int result
= -EINVAL
;
766 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
767 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
768 "LCD brightness level\n"));
772 if (obj
->package
.count
< 2)
775 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
777 printk(KERN_ERR
"can't allocate memory\n");
782 br
->levels
= kmalloc((obj
->package
.count
+ 2) * sizeof *(br
->levels
),
789 for (i
= 0; i
< obj
->package
.count
; i
++) {
790 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
791 if (o
->type
!= ACPI_TYPE_INTEGER
) {
792 printk(KERN_ERR PREFIX
"Invalid data\n");
795 br
->levels
[count
] = (u32
) o
->integer
.value
;
797 if (br
->levels
[count
] > max_level
)
798 max_level
= br
->levels
[count
];
803 * some buggy BIOS don't export the levels
804 * when machine is on AC/Battery in _BCL package.
805 * In this case, the first two elements in _BCL packages
806 * are also supported brightness levels that OS should take care of.
808 for (i
= 2; i
< count
; i
++) {
809 if (br
->levels
[i
] == br
->levels
[0])
811 if (br
->levels
[i
] == br
->levels
[1])
815 if (level_ac_battery
< 2) {
816 level_ac_battery
= 2 - level_ac_battery
;
817 br
->flags
._BCL_no_ac_battery_levels
= 1;
818 for (i
= (count
- 1 + level_ac_battery
); i
>= 2; i
--)
819 br
->levels
[i
] = br
->levels
[i
- level_ac_battery
];
820 count
+= level_ac_battery
;
821 } else if (level_ac_battery
> 2)
822 ACPI_ERROR((AE_INFO
, "Too many duplicates in _BCL package\n"));
824 /* Check if the _BCL package is in a reversed order */
825 if (max_level
== br
->levels
[2]) {
826 br
->flags
._BCL_reversed
= 1;
827 sort(&br
->levels
[2], count
- 2, sizeof(br
->levels
[2]),
828 acpi_video_cmp_level
, NULL
);
829 } else if (max_level
!= br
->levels
[count
- 1])
831 "Found unordered _BCL package\n"));
834 device
->brightness
= br
;
836 /* Check the input/output of _BQC/_BCL/_BCM */
837 if ((max_level
< 100) && (max_level
<= (count
- 2)))
838 br
->flags
._BCL_use_index
= 1;
841 * _BCM is always consistent with _BCL,
842 * at least for all the laptops we have ever seen.
844 br
->flags
._BCM_use_index
= br
->flags
._BCL_use_index
;
846 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
847 br
->curr
= level
= max_level
;
849 if (!device
->cap
._BQC
)
852 result
= acpi_video_device_lcd_get_level_current(device
, &level_old
, 1);
854 goto out_free_levels
;
857 * Set the level to maximum and check if _BQC uses indexed value
859 result
= acpi_video_device_lcd_set_level(device
, max_level
);
861 goto out_free_levels
;
863 result
= acpi_video_device_lcd_get_level_current(device
, &level
, 0);
865 goto out_free_levels
;
867 br
->flags
._BQC_use_index
= (level
== max_level
? 0 : 1);
869 if (!br
->flags
._BQC_use_index
) {
871 * Set the backlight to the initial state.
872 * On some buggy laptops, _BQC returns an uninitialized value
873 * when invoked for the first time, i.e. level_old is invalid.
874 * set the backlight to max_level in this case
876 for (i
= 2; i
< br
->count
; i
++)
877 if (level_old
== br
->levels
[i
])
882 if (br
->flags
._BCL_reversed
)
883 level_old
= (br
->count
- 1) - level_old
;
884 level
= br
->levels
[level_old
];
887 result
= acpi_video_device_lcd_set_level(device
, level
);
889 goto out_free_levels
;
891 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
892 "found %d brightness levels\n", count
- 2));
901 device
->brightness
= NULL
;
908 * device : video output device (LCD, CRT, ..)
913 * Find out all required AML methods defined under the output
917 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
919 acpi_handle h_dummy1
;
921 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
922 device
->cap
._ADR
= 1;
924 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
925 device
->cap
._BCL
= 1;
927 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
928 device
->cap
._BCM
= 1;
930 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
931 device
->cap
._BQC
= 1;
932 else if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCQ",
934 printk(KERN_WARNING FW_BUG
"_BCQ is used instead of _BQC\n");
935 device
->cap
._BCQ
= 1;
938 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
939 device
->cap
._DDC
= 1;
941 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
942 device
->cap
._DCS
= 1;
944 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
945 device
->cap
._DGS
= 1;
947 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
948 device
->cap
._DSS
= 1;
951 if (acpi_video_backlight_support()) {
952 struct backlight_properties props
;
954 static int count
= 0;
957 result
= acpi_video_init_brightness(device
);
960 name
= kasprintf(GFP_KERNEL
, "acpi_video%d", count
);
965 memset(&props
, 0, sizeof(struct backlight_properties
));
966 props
.max_brightness
= device
->brightness
->count
- 3;
967 device
->backlight
= backlight_device_register(name
, NULL
, device
,
971 if (IS_ERR(device
->backlight
))
975 * Save current brightness level in case we have to restore it
976 * before acpi_video_device_lcd_set_level() is called next time.
978 device
->backlight
->props
.brightness
=
979 acpi_video_get_brightness(device
->backlight
);
981 result
= sysfs_create_link(&device
->backlight
->dev
.kobj
,
982 &device
->dev
->dev
.kobj
, "device");
984 printk(KERN_ERR PREFIX
"Create sysfs link\n");
986 device
->cooling_dev
= thermal_cooling_device_register("LCD",
987 device
->dev
, &video_cooling_ops
);
988 if (IS_ERR(device
->cooling_dev
)) {
990 * Set cooling_dev to NULL so we don't crash trying to
992 * Also, why the hell we are returning early and
993 * not attempt to register video output if cooling
994 * device registration failed?
997 device
->cooling_dev
= NULL
;
1001 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
1002 device
->cooling_dev
->id
);
1003 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
1004 &device
->cooling_dev
->device
.kobj
,
1007 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1008 result
= sysfs_create_link(&device
->cooling_dev
->device
.kobj
,
1009 &device
->dev
->dev
.kobj
, "device");
1011 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1015 if (acpi_video_display_switch_support()) {
1017 if (device
->cap
._DCS
&& device
->cap
._DSS
) {
1020 name
= kasprintf(GFP_KERNEL
, "acpi_video%d", count
);
1024 device
->output_dev
= video_output_register(name
,
1025 NULL
, device
, &acpi_output_properties
);
1033 * device : video output device (VGA)
1038 * Find out all required AML methods defined under the video bus device.
1041 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
1043 acpi_handle h_dummy1
;
1045 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
1046 video
->cap
._DOS
= 1;
1048 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
1049 video
->cap
._DOD
= 1;
1051 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
1052 video
->cap
._ROM
= 1;
1054 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
1055 video
->cap
._GPD
= 1;
1057 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
1058 video
->cap
._SPD
= 1;
1060 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
1061 video
->cap
._VPO
= 1;
1066 * Check whether the video bus device has required AML method to
1067 * support the desired features
1070 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
1072 acpi_status status
= -ENOENT
;
1073 struct pci_dev
*dev
;
1078 dev
= acpi_get_pci_dev(video
->device
->handle
);
1083 /* Since there is no HID, CID and so on for VGA driver, we have
1084 * to check well known required nodes.
1087 /* Does this device support video switching? */
1088 if (video
->cap
._DOS
|| video
->cap
._DOD
) {
1089 if (!video
->cap
._DOS
) {
1090 printk(KERN_WARNING FW_BUG
1091 "ACPI(%s) defines _DOD but not _DOS\n",
1092 acpi_device_bid(video
->device
));
1094 video
->flags
.multihead
= 1;
1098 /* Does this device support retrieving a video ROM? */
1099 if (video
->cap
._ROM
) {
1100 video
->flags
.rom
= 1;
1104 /* Does this device support configuring which video device to POST? */
1105 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
1106 video
->flags
.post
= 1;
1113 /* --------------------------------------------------------------------------
1114 FS Interface (/proc)
1115 -------------------------------------------------------------------------- */
1116 #ifdef CONFIG_ACPI_PROCFS
1118 static struct proc_dir_entry
*acpi_video_dir
;
1122 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
1124 struct acpi_video_device
*dev
= seq
->private;
1130 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
1131 seq_printf(seq
, "type: ");
1133 seq_printf(seq
, "CRT\n");
1134 else if (dev
->flags
.lcd
)
1135 seq_printf(seq
, "LCD\n");
1136 else if (dev
->flags
.tvout
)
1137 seq_printf(seq
, "TVOUT\n");
1138 else if (dev
->flags
.dvi
)
1139 seq_printf(seq
, "DVI\n");
1141 seq_printf(seq
, "UNKNOWN\n");
1143 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
1150 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
1152 return single_open(file
, acpi_video_device_info_seq_show
,
1157 acpi_video_device_query(struct acpi_video_device
*device
,
1158 unsigned long long *state
)
1162 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS",
1168 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
1171 struct acpi_video_device
*dev
= seq
->private;
1172 unsigned long long state
;
1178 status
= acpi_video_device_get_state(dev
, &state
);
1179 seq_printf(seq
, "state: ");
1180 if (ACPI_SUCCESS(status
))
1181 seq_printf(seq
, "0x%02llx\n", state
);
1183 seq_printf(seq
, "<not supported>\n");
1185 status
= acpi_video_device_query(dev
, &state
);
1186 seq_printf(seq
, "query: ");
1187 if (ACPI_SUCCESS(status
))
1188 seq_printf(seq
, "0x%02llx\n", state
);
1190 seq_printf(seq
, "<not supported>\n");
1197 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
1199 return single_open(file
, acpi_video_device_state_seq_show
,
1204 acpi_video_device_write_state(struct file
*file
,
1205 const char __user
* buffer
,
1206 size_t count
, loff_t
* data
)
1209 struct seq_file
*m
= file
->private_data
;
1210 struct acpi_video_device
*dev
= m
->private;
1211 char str
[12] = { 0 };
1215 if (!dev
|| count
>= sizeof(str
))
1218 if (copy_from_user(str
, buffer
, count
))
1222 state
= simple_strtoul(str
, NULL
, 0);
1223 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1225 status
= acpi_video_device_set_state(dev
, state
);
1234 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
1236 struct acpi_video_device
*dev
= seq
->private;
1240 if (!dev
|| !dev
->brightness
) {
1241 seq_printf(seq
, "<not supported>\n");
1245 seq_printf(seq
, "levels: ");
1246 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1247 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
1248 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
1254 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
1256 return single_open(file
, acpi_video_device_brightness_seq_show
,
1261 acpi_video_device_write_brightness(struct file
*file
,
1262 const char __user
* buffer
,
1263 size_t count
, loff_t
* data
)
1265 struct seq_file
*m
= file
->private_data
;
1266 struct acpi_video_device
*dev
= m
->private;
1267 char str
[5] = { 0 };
1268 unsigned int level
= 0;
1272 if (!dev
|| !dev
->brightness
|| count
>= sizeof(str
))
1275 if (copy_from_user(str
, buffer
, count
))
1279 level
= simple_strtoul(str
, NULL
, 0);
1284 /* validate through the list of available levels */
1285 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1286 if (level
== dev
->brightness
->levels
[i
]) {
1287 if (!acpi_video_device_lcd_set_level(dev
, level
))
1295 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
1297 struct acpi_video_device
*dev
= seq
->private;
1300 union acpi_object
*edid
= NULL
;
1306 status
= acpi_video_device_EDID(dev
, &edid
, 128);
1307 if (ACPI_FAILURE(status
)) {
1308 status
= acpi_video_device_EDID(dev
, &edid
, 256);
1311 if (ACPI_FAILURE(status
)) {
1315 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
1316 for (i
= 0; i
< edid
->buffer
.length
; i
++)
1317 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
1322 seq_printf(seq
, "<not supported>\n");
1330 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
1332 return single_open(file
, acpi_video_device_EDID_seq_show
,
1336 static int acpi_video_device_add_fs(struct acpi_device
*device
)
1338 struct proc_dir_entry
*entry
, *device_dir
;
1339 struct acpi_video_device
*vid_dev
;
1341 vid_dev
= acpi_driver_data(device
);
1345 device_dir
= proc_mkdir(acpi_device_bid(device
),
1346 vid_dev
->video
->dir
);
1351 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1352 &acpi_video_device_info_fops
, acpi_driver_data(device
));
1354 goto err_remove_dir
;
1357 entry
= proc_create_data("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1359 &acpi_video_device_state_fops
,
1360 acpi_driver_data(device
));
1362 goto err_remove_info
;
1364 /* 'brightness' [R/W] */
1365 entry
= proc_create_data("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1367 &acpi_video_device_brightness_fops
,
1368 acpi_driver_data(device
));
1370 goto err_remove_state
;
1373 entry
= proc_create_data("EDID", S_IRUGO
, device_dir
,
1374 &acpi_video_device_EDID_fops
,
1375 acpi_driver_data(device
));
1377 goto err_remove_brightness
;
1379 acpi_device_dir(device
) = device_dir
;
1383 err_remove_brightness
:
1384 remove_proc_entry("brightness", device_dir
);
1386 remove_proc_entry("state", device_dir
);
1388 remove_proc_entry("info", device_dir
);
1390 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1394 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1396 struct acpi_video_device
*vid_dev
;
1397 struct proc_dir_entry
*device_dir
;
1399 vid_dev
= acpi_driver_data(device
);
1400 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1403 device_dir
= acpi_device_dir(device
);
1405 remove_proc_entry("info", device_dir
);
1406 remove_proc_entry("state", device_dir
);
1407 remove_proc_entry("brightness", device_dir
);
1408 remove_proc_entry("EDID", device_dir
);
1409 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1410 acpi_device_dir(device
) = NULL
;
1417 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1419 struct acpi_video_bus
*video
= seq
->private;
1425 seq_printf(seq
, "Switching heads: %s\n",
1426 video
->flags
.multihead
? "yes" : "no");
1427 seq_printf(seq
, "Video ROM: %s\n",
1428 video
->flags
.rom
? "yes" : "no");
1429 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1430 video
->flags
.post
? "yes" : "no");
1436 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1438 return single_open(file
, acpi_video_bus_info_seq_show
,
1442 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1444 struct acpi_video_bus
*video
= seq
->private;
1450 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1451 seq_printf(seq
, "<TODO>\n");
1457 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1459 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1463 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
1464 unsigned long long *options
)
1468 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO",
1475 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1477 struct acpi_video_bus
*video
= seq
->private;
1478 unsigned long long options
;
1485 status
= acpi_video_bus_POST_options(video
, &options
);
1486 if (ACPI_SUCCESS(status
)) {
1487 if (!(options
& 1)) {
1488 printk(KERN_WARNING PREFIX
1489 "The motherboard VGA device is not listed as a possible POST device.\n");
1490 printk(KERN_WARNING PREFIX
1491 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1493 printk(KERN_WARNING
"%llx\n", options
);
1494 seq_printf(seq
, "can POST: <integrated video>");
1496 seq_printf(seq
, " <PCI video>");
1498 seq_printf(seq
, " <AGP video>");
1499 seq_putc(seq
, '\n');
1501 seq_printf(seq
, "<not supported>\n");
1507 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1509 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1514 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long long *id
)
1518 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
1523 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1525 struct acpi_video_bus
*video
= seq
->private;
1527 unsigned long long id
;
1533 status
= acpi_video_bus_get_POST(video
, &id
);
1534 if (!ACPI_SUCCESS(status
)) {
1535 seq_printf(seq
, "<not supported>\n");
1538 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1544 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1546 struct acpi_video_bus
*video
= seq
->private;
1549 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1554 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1556 return single_open(file
, acpi_video_bus_POST_seq_show
,
1560 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1562 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1566 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
1569 unsigned long long tmp
;
1570 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
1571 struct acpi_object_list args
= { 1, &arg0
};
1574 arg0
.integer
.value
= option
;
1576 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD",
1578 if (ACPI_SUCCESS(status
))
1579 status
= tmp
? (-EINVAL
) : (AE_OK
);
1585 acpi_video_bus_write_POST(struct file
*file
,
1586 const char __user
* buffer
,
1587 size_t count
, loff_t
* data
)
1590 struct seq_file
*m
= file
->private_data
;
1591 struct acpi_video_bus
*video
= m
->private;
1592 char str
[12] = { 0 };
1593 unsigned long long opt
, options
;
1596 if (!video
|| count
>= sizeof(str
))
1599 status
= acpi_video_bus_POST_options(video
, &options
);
1600 if (!ACPI_SUCCESS(status
))
1603 if (copy_from_user(str
, buffer
, count
))
1607 opt
= strtoul(str
, NULL
, 0);
1611 /* just in case an OEM 'forgot' the motherboard... */
1614 if (options
& (1ul << opt
)) {
1615 status
= acpi_video_bus_set_POST(video
, opt
);
1616 if (!ACPI_SUCCESS(status
))
1625 acpi_video_bus_write_DOS(struct file
*file
,
1626 const char __user
* buffer
,
1627 size_t count
, loff_t
* data
)
1630 struct seq_file
*m
= file
->private_data
;
1631 struct acpi_video_bus
*video
= m
->private;
1632 char str
[12] = { 0 };
1636 if (!video
|| count
>= sizeof(str
))
1639 if (copy_from_user(str
, buffer
, count
))
1643 opt
= strtoul(str
, NULL
, 0);
1647 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1649 if (!ACPI_SUCCESS(status
))
1655 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1657 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1658 struct proc_dir_entry
*device_dir
;
1659 struct proc_dir_entry
*entry
;
1661 device_dir
= proc_mkdir(acpi_device_bid(device
), acpi_video_dir
);
1666 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1667 &acpi_video_bus_info_fops
,
1668 acpi_driver_data(device
));
1670 goto err_remove_dir
;
1673 entry
= proc_create_data("ROM", S_IRUGO
, device_dir
,
1674 &acpi_video_bus_ROM_fops
,
1675 acpi_driver_data(device
));
1677 goto err_remove_info
;
1679 /* 'POST_info' [R] */
1680 entry
= proc_create_data("POST_info", S_IRUGO
, device_dir
,
1681 &acpi_video_bus_POST_info_fops
,
1682 acpi_driver_data(device
));
1684 goto err_remove_rom
;
1687 entry
= proc_create_data("POST", S_IFREG
| S_IRUGO
| S_IWUSR
,
1689 &acpi_video_bus_POST_fops
,
1690 acpi_driver_data(device
));
1692 goto err_remove_post_info
;
1695 entry
= proc_create_data("DOS", S_IFREG
| S_IRUGO
| S_IWUSR
,
1697 &acpi_video_bus_DOS_fops
,
1698 acpi_driver_data(device
));
1700 goto err_remove_post
;
1702 video
->dir
= acpi_device_dir(device
) = device_dir
;
1706 remove_proc_entry("POST", device_dir
);
1707 err_remove_post_info
:
1708 remove_proc_entry("POST_info", device_dir
);
1710 remove_proc_entry("ROM", device_dir
);
1712 remove_proc_entry("info", device_dir
);
1714 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1718 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1720 struct proc_dir_entry
*device_dir
= acpi_device_dir(device
);
1723 remove_proc_entry("info", device_dir
);
1724 remove_proc_entry("ROM", device_dir
);
1725 remove_proc_entry("POST_info", device_dir
);
1726 remove_proc_entry("POST", device_dir
);
1727 remove_proc_entry("DOS", device_dir
);
1728 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1729 acpi_device_dir(device
) = NULL
;
1735 static inline int acpi_video_device_add_fs(struct acpi_device
*device
)
1739 static inline int acpi_video_device_remove_fs(struct acpi_device
*device
)
1743 static inline int acpi_video_bus_add_fs(struct acpi_device
*device
)
1747 static inline int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1751 #endif /* CONFIG_ACPI_PROCFS */
1753 /* --------------------------------------------------------------------------
1755 -------------------------------------------------------------------------- */
1757 /* device interface */
1758 static struct acpi_video_device_attrib
*
1759 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1761 struct acpi_video_enumerated_device
*ids
;
1764 for (i
= 0; i
< video
->attached_count
; i
++) {
1765 ids
= &video
->attached_array
[i
];
1766 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1767 return &ids
->value
.attrib
;
1774 acpi_video_get_device_type(struct acpi_video_bus
*video
,
1775 unsigned long device_id
)
1777 struct acpi_video_enumerated_device
*ids
;
1780 for (i
= 0; i
< video
->attached_count
; i
++) {
1781 ids
= &video
->attached_array
[i
];
1782 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1783 return ids
->value
.int_val
;
1790 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1791 struct acpi_video_bus
*video
)
1793 unsigned long long device_id
;
1794 int status
, device_type
;
1795 struct acpi_video_device
*data
;
1796 struct acpi_video_device_attrib
* attribute
;
1798 if (!device
|| !video
)
1802 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1803 if (ACPI_SUCCESS(status
)) {
1805 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1809 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1810 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1811 device
->driver_data
= data
;
1813 data
->device_id
= device_id
;
1814 data
->video
= video
;
1817 attribute
= acpi_video_get_device_attr(video
, device_id
);
1819 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1820 switch (attribute
->display_type
) {
1821 case ACPI_VIDEO_DISPLAY_CRT
:
1822 data
->flags
.crt
= 1;
1824 case ACPI_VIDEO_DISPLAY_TV
:
1825 data
->flags
.tvout
= 1;
1827 case ACPI_VIDEO_DISPLAY_DVI
:
1828 data
->flags
.dvi
= 1;
1830 case ACPI_VIDEO_DISPLAY_LCD
:
1831 data
->flags
.lcd
= 1;
1834 data
->flags
.unknown
= 1;
1837 if(attribute
->bios_can_detect
)
1838 data
->flags
.bios
= 1;
1840 /* Check for legacy IDs */
1841 device_type
= acpi_video_get_device_type(video
,
1843 /* Ignore bits 16 and 18-20 */
1844 switch (device_type
& 0xffe2ffff) {
1845 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR
:
1846 data
->flags
.crt
= 1;
1848 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL
:
1849 data
->flags
.lcd
= 1;
1851 case ACPI_VIDEO_DISPLAY_LEGACY_TV
:
1852 data
->flags
.tvout
= 1;
1855 data
->flags
.unknown
= 1;
1859 acpi_video_device_bind(video
, data
);
1860 acpi_video_device_find_cap(data
);
1862 status
= acpi_install_notify_handler(device
->handle
,
1864 acpi_video_device_notify
,
1866 if (ACPI_FAILURE(status
)) {
1867 printk(KERN_ERR PREFIX
1868 "Error installing notify handler\n");
1869 if(data
->brightness
)
1870 kfree(data
->brightness
->levels
);
1871 kfree(data
->brightness
);
1876 mutex_lock(&video
->device_list_lock
);
1877 list_add_tail(&data
->entry
, &video
->video_device_list
);
1878 mutex_unlock(&video
->device_list_lock
);
1880 acpi_video_device_add_fs(device
);
1890 * video : video bus device
1895 * Enumerate the video device list of the video bus,
1896 * bind the ids with the corresponding video devices
1897 * under the video bus.
1900 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1902 struct acpi_video_device
*dev
;
1904 mutex_lock(&video
->device_list_lock
);
1906 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1907 acpi_video_device_bind(video
, dev
);
1909 mutex_unlock(&video
->device_list_lock
);
1914 * video : video bus device
1915 * device : video output device under the video
1921 * Bind the ids with the corresponding video devices
1922 * under the video bus.
1926 acpi_video_device_bind(struct acpi_video_bus
*video
,
1927 struct acpi_video_device
*device
)
1929 struct acpi_video_enumerated_device
*ids
;
1932 for (i
= 0; i
< video
->attached_count
; i
++) {
1933 ids
= &video
->attached_array
[i
];
1934 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1935 ids
->bind_info
= device
;
1936 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1943 * video : video bus device
1948 * Call _DOD to enumerate all devices attached to display adapter
1952 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1957 struct acpi_video_enumerated_device
*active_list
;
1958 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1959 union acpi_object
*dod
= NULL
;
1960 union acpi_object
*obj
;
1962 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1963 if (!ACPI_SUCCESS(status
)) {
1964 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1968 dod
= buffer
.pointer
;
1969 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1970 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1975 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1976 dod
->package
.count
));
1978 active_list
= kcalloc(1 + dod
->package
.count
,
1979 sizeof(struct acpi_video_enumerated_device
),
1987 for (i
= 0; i
< dod
->package
.count
; i
++) {
1988 obj
= &dod
->package
.elements
[i
];
1990 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1991 printk(KERN_ERR PREFIX
1992 "Invalid _DOD data in element %d\n", i
);
1996 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1997 active_list
[count
].bind_info
= NULL
;
1998 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1999 (int)obj
->integer
.value
));
2003 kfree(video
->attached_array
);
2005 video
->attached_array
= active_list
;
2006 video
->attached_count
= count
;
2009 kfree(buffer
.pointer
);
2014 acpi_video_get_next_level(struct acpi_video_device
*device
,
2015 u32 level_current
, u32 event
)
2017 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
2018 max
= max_below
= 0;
2019 min
= min_above
= 255;
2020 /* Find closest level to level_current */
2021 for (i
= 2; i
< device
->brightness
->count
; i
++) {
2022 l
= device
->brightness
->levels
[i
];
2023 if (abs(l
- level_current
) < abs(delta
)) {
2024 delta
= l
- level_current
;
2029 /* Ajust level_current to closest available level */
2030 level_current
+= delta
;
2031 for (i
= 2; i
< device
->brightness
->count
; i
++) {
2032 l
= device
->brightness
->levels
[i
];
2037 if (l
< min_above
&& l
> level_current
)
2039 if (l
> max_below
&& l
< level_current
)
2044 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
2045 return (level_current
< max
) ? min_above
: min
;
2046 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
2047 return (level_current
< max
) ? min_above
: max
;
2048 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
2049 return (level_current
> min
) ? max_below
: min
;
2050 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
2051 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
2054 return level_current
;
2059 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
2061 unsigned long long level_current
, level_next
;
2062 int result
= -EINVAL
;
2064 /* no warning message if acpi_backlight=vendor is used */
2065 if (!acpi_video_backlight_support())
2068 if (!device
->brightness
)
2071 result
= acpi_video_device_lcd_get_level_current(device
,
2076 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
2078 result
= acpi_video_device_lcd_set_level(device
, level_next
);
2081 backlight_force_update(device
->backlight
,
2082 BACKLIGHT_UPDATE_HOTKEY
);
2086 printk(KERN_ERR PREFIX
"Failed to switch the brightness\n");
2091 int acpi_video_get_edid(struct acpi_device
*device
, int type
, int device_id
,
2094 struct acpi_video_bus
*video
;
2095 struct acpi_video_device
*video_device
;
2096 union acpi_object
*buffer
= NULL
;
2100 if (!device
|| !acpi_driver_data(device
))
2103 video
= acpi_driver_data(device
);
2105 for (i
= 0; i
< video
->attached_count
; i
++) {
2106 video_device
= video
->attached_array
[i
].bind_info
;
2114 case ACPI_VIDEO_DISPLAY_CRT
:
2115 if (!video_device
->flags
.crt
)
2118 case ACPI_VIDEO_DISPLAY_TV
:
2119 if (!video_device
->flags
.tvout
)
2122 case ACPI_VIDEO_DISPLAY_DVI
:
2123 if (!video_device
->flags
.dvi
)
2126 case ACPI_VIDEO_DISPLAY_LCD
:
2127 if (!video_device
->flags
.lcd
)
2131 } else if (video_device
->device_id
!= device_id
) {
2135 status
= acpi_video_device_EDID(video_device
, &buffer
, length
);
2137 if (ACPI_FAILURE(status
) || !buffer
||
2138 buffer
->type
!= ACPI_TYPE_BUFFER
) {
2140 status
= acpi_video_device_EDID(video_device
, &buffer
,
2142 if (ACPI_FAILURE(status
) || !buffer
||
2143 buffer
->type
!= ACPI_TYPE_BUFFER
) {
2148 *edid
= buffer
->buffer
.pointer
;
2154 EXPORT_SYMBOL(acpi_video_get_edid
);
2157 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
2158 struct acpi_device
*device
)
2161 struct acpi_device
*dev
;
2163 acpi_video_device_enumerate(video
);
2165 list_for_each_entry(dev
, &device
->children
, node
) {
2167 status
= acpi_video_bus_get_one_device(dev
, video
);
2168 if (ACPI_FAILURE(status
)) {
2169 printk(KERN_WARNING PREFIX
2170 "Cant attach device\n");
2177 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
2181 if (!device
|| !device
->video
)
2184 acpi_video_device_remove_fs(device
->dev
);
2186 status
= acpi_remove_notify_handler(device
->dev
->handle
,
2188 acpi_video_device_notify
);
2189 if (ACPI_FAILURE(status
)) {
2190 printk(KERN_WARNING PREFIX
2191 "Cant remove video notify handler\n");
2193 if (device
->backlight
) {
2194 sysfs_remove_link(&device
->backlight
->dev
.kobj
, "device");
2195 backlight_device_unregister(device
->backlight
);
2196 device
->backlight
= NULL
;
2198 if (device
->cooling_dev
) {
2199 sysfs_remove_link(&device
->dev
->dev
.kobj
,
2201 sysfs_remove_link(&device
->cooling_dev
->device
.kobj
,
2203 thermal_cooling_device_unregister(device
->cooling_dev
);
2204 device
->cooling_dev
= NULL
;
2206 video_output_unregister(device
->output_dev
);
2211 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
2214 struct acpi_video_device
*dev
, *next
;
2216 mutex_lock(&video
->device_list_lock
);
2218 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
2220 status
= acpi_video_bus_put_one_device(dev
);
2221 if (ACPI_FAILURE(status
))
2222 printk(KERN_WARNING PREFIX
2223 "hhuuhhuu bug in acpi video driver.\n");
2225 if (dev
->brightness
) {
2226 kfree(dev
->brightness
->levels
);
2227 kfree(dev
->brightness
);
2229 list_del(&dev
->entry
);
2233 mutex_unlock(&video
->device_list_lock
);
2238 /* acpi_video interface */
2240 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
2242 return acpi_video_bus_DOS(video
, 0, 0);
2245 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
2247 return acpi_video_bus_DOS(video
, 0, 1);
2250 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
)
2252 struct acpi_video_bus
*video
= acpi_driver_data(device
);
2253 struct input_dev
*input
;
2259 input
= video
->input
;
2262 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
2263 * most likely via hotkey. */
2264 acpi_bus_generate_proc_event(device
, event
, 0);
2265 keycode
= KEY_SWITCHVIDEOMODE
;
2268 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
2270 acpi_video_device_enumerate(video
);
2271 acpi_video_device_rebind(video
);
2272 acpi_bus_generate_proc_event(device
, event
, 0);
2273 keycode
= KEY_SWITCHVIDEOMODE
;
2276 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
2277 acpi_bus_generate_proc_event(device
, event
, 0);
2278 keycode
= KEY_SWITCHVIDEOMODE
;
2280 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
2281 acpi_bus_generate_proc_event(device
, event
, 0);
2282 keycode
= KEY_VIDEO_NEXT
;
2284 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
2285 acpi_bus_generate_proc_event(device
, event
, 0);
2286 keycode
= KEY_VIDEO_PREV
;
2290 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
2291 "Unsupported event [0x%x]\n", event
));
2295 acpi_notifier_call_chain(device
, event
, 0);
2298 input_report_key(input
, keycode
, 1);
2300 input_report_key(input
, keycode
, 0);
2307 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
2309 struct acpi_video_device
*video_device
= data
;
2310 struct acpi_device
*device
= NULL
;
2311 struct acpi_video_bus
*bus
;
2312 struct input_dev
*input
;
2318 device
= video_device
->dev
;
2319 bus
= video_device
->video
;
2323 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
2324 if (brightness_switch_enabled
)
2325 acpi_video_switch_brightness(video_device
, event
);
2326 acpi_bus_generate_proc_event(device
, event
, 0);
2327 keycode
= KEY_BRIGHTNESS_CYCLE
;
2329 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
2330 if (brightness_switch_enabled
)
2331 acpi_video_switch_brightness(video_device
, event
);
2332 acpi_bus_generate_proc_event(device
, event
, 0);
2333 keycode
= KEY_BRIGHTNESSUP
;
2335 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
2336 if (brightness_switch_enabled
)
2337 acpi_video_switch_brightness(video_device
, event
);
2338 acpi_bus_generate_proc_event(device
, event
, 0);
2339 keycode
= KEY_BRIGHTNESSDOWN
;
2341 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
2342 if (brightness_switch_enabled
)
2343 acpi_video_switch_brightness(video_device
, event
);
2344 acpi_bus_generate_proc_event(device
, event
, 0);
2345 keycode
= KEY_BRIGHTNESS_ZERO
;
2347 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
2348 if (brightness_switch_enabled
)
2349 acpi_video_switch_brightness(video_device
, event
);
2350 acpi_bus_generate_proc_event(device
, event
, 0);
2351 keycode
= KEY_DISPLAY_OFF
;
2354 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
2355 "Unsupported event [0x%x]\n", event
));
2359 acpi_notifier_call_chain(device
, event
, 0);
2362 input_report_key(input
, keycode
, 1);
2364 input_report_key(input
, keycode
, 0);
2371 static int acpi_video_resume(struct notifier_block
*nb
,
2372 unsigned long val
, void *ign
)
2374 struct acpi_video_bus
*video
;
2375 struct acpi_video_device
*video_device
;
2379 case PM_HIBERNATION_PREPARE
:
2380 case PM_SUSPEND_PREPARE
:
2381 case PM_RESTORE_PREPARE
:
2385 video
= container_of(nb
, struct acpi_video_bus
, pm_nb
);
2387 dev_info(&video
->device
->dev
, "Restoring backlight state\n");
2389 for (i
= 0; i
< video
->attached_count
; i
++) {
2390 video_device
= video
->attached_array
[i
].bind_info
;
2391 if (video_device
&& video_device
->backlight
)
2392 acpi_video_set_brightness(video_device
->backlight
);
2399 acpi_video_bus_match(acpi_handle handle
, u32 level
, void *context
,
2400 void **return_value
)
2402 struct acpi_device
*device
= context
;
2403 struct acpi_device
*sibling
;
2406 if (handle
== device
->handle
)
2407 return AE_CTRL_TERMINATE
;
2409 result
= acpi_bus_get_device(handle
, &sibling
);
2413 if (!strcmp(acpi_device_name(sibling
), ACPI_VIDEO_BUS_NAME
))
2414 return AE_ALREADY_EXISTS
;
2419 static int instance
;
2421 static int acpi_video_bus_add(struct acpi_device
*device
)
2423 struct acpi_video_bus
*video
;
2424 struct input_dev
*input
;
2428 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
,
2429 device
->parent
->handle
, 1,
2430 acpi_video_bus_match
, NULL
,
2432 if (status
== AE_ALREADY_EXISTS
) {
2433 printk(KERN_WARNING FW_BUG
2434 "Duplicate ACPI video bus devices for the"
2435 " same VGA controller, please try module "
2436 "parameter \"video.allow_duplicates=1\""
2437 "if the current driver doesn't work.\n");
2438 if (!allow_duplicates
)
2442 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
2446 /* a hack to fix the duplicate name "VID" problem on T61 */
2447 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
2449 device
->pnp
.bus_id
[3] = '0' + instance
;
2452 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2453 if (!strcmp(device
->pnp
.bus_id
, "VGA")) {
2455 device
->pnp
.bus_id
[3] = '0' + instance
;
2459 video
->device
= device
;
2460 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
2461 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
2462 device
->driver_data
= video
;
2464 acpi_video_bus_find_cap(video
);
2465 error
= acpi_video_bus_check(video
);
2467 goto err_free_video
;
2469 error
= acpi_video_bus_add_fs(device
);
2471 goto err_free_video
;
2473 mutex_init(&video
->device_list_lock
);
2474 INIT_LIST_HEAD(&video
->video_device_list
);
2476 acpi_video_bus_get_devices(video
, device
);
2477 acpi_video_bus_start_devices(video
);
2479 video
->input
= input
= input_allocate_device();
2482 goto err_stop_video
;
2485 snprintf(video
->phys
, sizeof(video
->phys
),
2486 "%s/video/input0", acpi_device_hid(video
->device
));
2488 input
->name
= acpi_device_name(video
->device
);
2489 input
->phys
= video
->phys
;
2490 input
->id
.bustype
= BUS_HOST
;
2491 input
->id
.product
= 0x06;
2492 input
->dev
.parent
= &device
->dev
;
2493 input
->evbit
[0] = BIT(EV_KEY
);
2494 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2495 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2496 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2497 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2498 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2499 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2500 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2501 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2503 error
= input_register_device(input
);
2505 goto err_free_input_dev
;
2507 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2508 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2509 video
->flags
.multihead
? "yes" : "no",
2510 video
->flags
.rom
? "yes" : "no",
2511 video
->flags
.post
? "yes" : "no");
2513 video
->pm_nb
.notifier_call
= acpi_video_resume
;
2514 video
->pm_nb
.priority
= 0;
2515 register_pm_notifier(&video
->pm_nb
);
2520 input_free_device(input
);
2522 acpi_video_bus_stop_devices(video
);
2523 acpi_video_bus_put_devices(video
);
2524 kfree(video
->attached_array
);
2525 acpi_video_bus_remove_fs(device
);
2528 device
->driver_data
= NULL
;
2533 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2535 struct acpi_video_bus
*video
= NULL
;
2538 if (!device
|| !acpi_driver_data(device
))
2541 video
= acpi_driver_data(device
);
2543 unregister_pm_notifier(&video
->pm_nb
);
2545 acpi_video_bus_stop_devices(video
);
2546 acpi_video_bus_put_devices(video
);
2547 acpi_video_bus_remove_fs(device
);
2549 input_unregister_device(video
->input
);
2550 kfree(video
->attached_array
);
2556 static int __init
intel_opregion_present(void)
2558 #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2559 struct pci_dev
*dev
= NULL
;
2562 for_each_pci_dev(dev
) {
2563 if ((dev
->class >> 8) != PCI_CLASS_DISPLAY_VGA
)
2565 if (dev
->vendor
!= PCI_VENDOR_ID_INTEL
)
2567 pci_read_config_dword(dev
, 0xfc, &address
);
2576 int acpi_video_register(void)
2579 if (register_count
) {
2581 * if the function of acpi_video_register is already called,
2582 * don't register the acpi_vide_bus again and return no error.
2587 #ifdef CONFIG_ACPI_PROCFS
2588 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2589 if (!acpi_video_dir
)
2593 result
= acpi_bus_register_driver(&acpi_video_bus
);
2595 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2600 * When the acpi_video_bus is loaded successfully, increase
2601 * the counter reference.
2607 EXPORT_SYMBOL(acpi_video_register
);
2609 void acpi_video_unregister(void)
2611 if (!register_count
) {
2613 * If the acpi video bus is already unloaded, don't
2614 * unload it again and return directly.
2618 acpi_bus_unregister_driver(&acpi_video_bus
);
2620 #ifdef CONFIG_ACPI_PROCFS
2621 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2628 EXPORT_SYMBOL(acpi_video_unregister
);
2631 * This is kind of nasty. Hardware using Intel chipsets may require
2632 * the video opregion code to be run first in order to initialise
2633 * state before any ACPI video calls are made. To handle this we defer
2634 * registration of the video class until the opregion code has run.
2637 static int __init
acpi_video_init(void)
2639 dmi_check_system(video_dmi_table
);
2641 if (intel_opregion_present())
2644 return acpi_video_register();
2647 static void __exit
acpi_video_exit(void)
2649 acpi_video_unregister();
2654 module_init(acpi_video_init
);
2655 module_exit(acpi_video_exit
);