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 struct proc_dir_entry
*dir
;
156 struct input_dev
*input
;
157 char phys
[32]; /* for input device */
158 struct notifier_block pm_nb
;
161 struct acpi_video_device_flags
{
171 struct acpi_video_device_cap
{
172 u8 _ADR
:1; /*Return the unique ID */
173 u8 _BCL
:1; /*Query list of brightness control levels supported */
174 u8 _BCM
:1; /*Set the brightness level */
175 u8 _BQC
:1; /* Get current brightness level */
176 u8 _BCQ
:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
177 u8 _DDC
:1; /*Return the EDID for this device */
178 u8 _DCS
:1; /*Return status of output device */
179 u8 _DGS
:1; /*Query graphics state */
180 u8 _DSS
:1; /*Device state set */
183 struct acpi_video_brightness_flags
{
184 u8 _BCL_no_ac_battery_levels
:1; /* no AC/Battery levels in _BCL */
185 u8 _BCL_reversed
:1; /* _BCL package is in a reversed order*/
186 u8 _BCL_use_index
:1; /* levels in _BCL are index values */
187 u8 _BCM_use_index
:1; /* input of _BCM is an index value */
188 u8 _BQC_use_index
:1; /* _BQC returns an index value */
191 struct acpi_video_device_brightness
{
195 struct acpi_video_brightness_flags flags
;
198 struct acpi_video_device
{
199 unsigned long device_id
;
200 struct acpi_video_device_flags flags
;
201 struct acpi_video_device_cap cap
;
202 struct list_head entry
;
203 struct acpi_video_bus
*video
;
204 struct acpi_device
*dev
;
205 struct acpi_video_device_brightness
*brightness
;
206 struct backlight_device
*backlight
;
207 struct thermal_cooling_device
*cooling_dev
;
208 struct output_device
*output_dev
;
212 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
213 static const struct file_operations acpi_video_bus_info_fops
= {
214 .owner
= THIS_MODULE
,
215 .open
= acpi_video_bus_info_open_fs
,
218 .release
= single_release
,
221 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
222 static const struct file_operations acpi_video_bus_ROM_fops
= {
223 .owner
= THIS_MODULE
,
224 .open
= acpi_video_bus_ROM_open_fs
,
227 .release
= single_release
,
230 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
232 static const struct file_operations acpi_video_bus_POST_info_fops
= {
233 .owner
= THIS_MODULE
,
234 .open
= acpi_video_bus_POST_info_open_fs
,
237 .release
= single_release
,
240 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
241 static ssize_t
acpi_video_bus_write_POST(struct file
*file
,
242 const char __user
*buffer
, size_t count
, loff_t
*data
);
243 static const struct file_operations acpi_video_bus_POST_fops
= {
244 .owner
= THIS_MODULE
,
245 .open
= acpi_video_bus_POST_open_fs
,
247 .write
= acpi_video_bus_write_POST
,
249 .release
= single_release
,
252 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
253 static ssize_t
acpi_video_bus_write_DOS(struct file
*file
,
254 const char __user
*buffer
, size_t count
, loff_t
*data
);
255 static const struct file_operations acpi_video_bus_DOS_fops
= {
256 .owner
= THIS_MODULE
,
257 .open
= acpi_video_bus_DOS_open_fs
,
259 .write
= acpi_video_bus_write_DOS
,
261 .release
= single_release
,
265 static int acpi_video_device_info_open_fs(struct inode
*inode
,
267 static const struct file_operations acpi_video_device_info_fops
= {
268 .owner
= THIS_MODULE
,
269 .open
= acpi_video_device_info_open_fs
,
272 .release
= single_release
,
275 static int acpi_video_device_state_open_fs(struct inode
*inode
,
277 static ssize_t
acpi_video_device_write_state(struct file
*file
,
278 const char __user
*buffer
, size_t count
, loff_t
*data
);
279 static const struct file_operations acpi_video_device_state_fops
= {
280 .owner
= THIS_MODULE
,
281 .open
= acpi_video_device_state_open_fs
,
283 .write
= acpi_video_device_write_state
,
285 .release
= single_release
,
288 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
290 static ssize_t
acpi_video_device_write_brightness(struct file
*file
,
291 const char __user
*buffer
, size_t count
, loff_t
*data
);
292 static const struct file_operations acpi_video_device_brightness_fops
= {
293 .owner
= THIS_MODULE
,
294 .open
= acpi_video_device_brightness_open_fs
,
296 .write
= acpi_video_device_write_brightness
,
298 .release
= single_release
,
301 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
303 static const struct file_operations acpi_video_device_EDID_fops
= {
304 .owner
= THIS_MODULE
,
305 .open
= acpi_video_device_EDID_open_fs
,
308 .release
= single_release
,
311 static const char device_decode
[][30] = {
312 "motherboard VGA device",
318 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
319 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
320 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
321 struct acpi_video_device
*device
);
322 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
323 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
325 static int acpi_video_device_lcd_get_level_current(
326 struct acpi_video_device
*device
,
327 unsigned long long *level
, int init
);
328 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
329 u32 level_current
, u32 event
);
330 static int acpi_video_switch_brightness(struct acpi_video_device
*device
,
332 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
333 unsigned long long *state
);
334 static int acpi_video_output_get(struct output_device
*od
);
335 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
337 /*backlight device sysfs support*/
338 static int acpi_video_get_brightness(struct backlight_device
*bd
)
340 unsigned long long cur_level
;
342 struct acpi_video_device
*vd
=
343 (struct acpi_video_device
*)bl_get_data(bd
);
345 if (acpi_video_device_lcd_get_level_current(vd
, &cur_level
, 0))
347 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
348 if (vd
->brightness
->levels
[i
] == cur_level
)
349 /* The first two entries are special - see page 575
350 of the ACPI spec 3.0 */
356 static int acpi_video_set_brightness(struct backlight_device
*bd
)
358 int request_level
= bd
->props
.brightness
+ 2;
359 struct acpi_video_device
*vd
=
360 (struct acpi_video_device
*)bl_get_data(bd
);
362 return acpi_video_device_lcd_set_level(vd
,
363 vd
->brightness
->levels
[request_level
]);
366 static struct backlight_ops acpi_backlight_ops
= {
367 .get_brightness
= acpi_video_get_brightness
,
368 .update_status
= acpi_video_set_brightness
,
371 /*video output device sysfs support*/
372 static int acpi_video_output_get(struct output_device
*od
)
374 unsigned long long state
;
375 struct acpi_video_device
*vd
=
376 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
377 acpi_video_device_get_state(vd
, &state
);
381 static int acpi_video_output_set(struct output_device
*od
)
383 unsigned long state
= od
->request_state
;
384 struct acpi_video_device
*vd
=
385 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
386 return acpi_video_device_set_state(vd
, state
);
389 static struct output_properties acpi_output_properties
= {
390 .set_state
= acpi_video_output_set
,
391 .get_status
= acpi_video_output_get
,
395 /* thermal cooling device callbacks */
396 static int video_get_max_state(struct thermal_cooling_device
*cooling_dev
, unsigned
399 struct acpi_device
*device
= cooling_dev
->devdata
;
400 struct acpi_video_device
*video
= acpi_driver_data(device
);
402 *state
= video
->brightness
->count
- 3;
406 static int video_get_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned
409 struct acpi_device
*device
= cooling_dev
->devdata
;
410 struct acpi_video_device
*video
= acpi_driver_data(device
);
411 unsigned long long level
;
414 if (acpi_video_device_lcd_get_level_current(video
, &level
, 0))
416 for (offset
= 2; offset
< video
->brightness
->count
; offset
++)
417 if (level
== video
->brightness
->levels
[offset
]) {
418 *state
= video
->brightness
->count
- offset
- 1;
426 video_set_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned long state
)
428 struct acpi_device
*device
= cooling_dev
->devdata
;
429 struct acpi_video_device
*video
= acpi_driver_data(device
);
432 if ( state
>= video
->brightness
->count
- 2)
435 state
= video
->brightness
->count
- state
;
436 level
= video
->brightness
->levels
[state
-1];
437 return acpi_video_device_lcd_set_level(video
, level
);
440 static struct thermal_cooling_device_ops video_cooling_ops
= {
441 .get_max_state
= video_get_max_state
,
442 .get_cur_state
= video_get_cur_state
,
443 .set_cur_state
= video_set_cur_state
,
446 /* --------------------------------------------------------------------------
448 -------------------------------------------------------------------------- */
453 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long long *state
)
457 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
463 acpi_video_device_get_state(struct acpi_video_device
*device
,
464 unsigned long long *state
)
468 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
474 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
477 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
478 struct acpi_object_list args
= { 1, &arg0
};
479 unsigned long long ret
;
482 arg0
.integer
.value
= state
;
483 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
489 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
490 union acpi_object
**levels
)
493 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
494 union acpi_object
*obj
;
499 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
500 if (!ACPI_SUCCESS(status
))
502 obj
= (union acpi_object
*)buffer
.pointer
;
503 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
504 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
514 kfree(buffer
.pointer
);
520 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
523 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
524 struct acpi_object_list args
= { 1, &arg0
};
527 arg0
.integer
.value
= level
;
529 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
531 if (ACPI_FAILURE(status
)) {
532 ACPI_ERROR((AE_INFO
, "Evaluating _BCM failed"));
536 device
->brightness
->curr
= level
;
537 for (state
= 2; state
< device
->brightness
->count
; state
++)
538 if (level
== device
->brightness
->levels
[state
]) {
539 if (device
->backlight
)
540 device
->backlight
->props
.brightness
= state
- 2;
544 ACPI_ERROR((AE_INFO
, "Current brightness invalid"));
549 * For some buggy _BQC methods, we need to add a constant value to
550 * the _BQC return value to get the actual current brightness level
553 static int bqc_offset_aml_bug_workaround
;
554 static int __init
video_set_bqc_offset(const struct dmi_system_id
*d
)
556 bqc_offset_aml_bug_workaround
= 9;
560 static struct dmi_system_id video_dmi_table
[] __initdata
= {
562 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
565 .callback
= video_set_bqc_offset
,
566 .ident
= "Acer Aspire 5720",
568 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
569 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5720"),
573 .callback
= video_set_bqc_offset
,
574 .ident
= "Acer Aspire 5710Z",
576 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
577 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5710Z"),
581 .callback
= video_set_bqc_offset
,
582 .ident
= "eMachines E510",
584 DMI_MATCH(DMI_BOARD_VENDOR
, "EMACHINES"),
585 DMI_MATCH(DMI_PRODUCT_NAME
, "eMachines E510"),
589 .callback
= video_set_bqc_offset
,
590 .ident
= "Acer Aspire 5315",
592 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
593 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5315"),
597 .callback
= video_set_bqc_offset
,
598 .ident
= "Acer Aspire 7720",
600 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
601 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 7720"),
608 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
609 unsigned long long *level
, int init
)
611 acpi_status status
= AE_OK
;
614 if (device
->cap
._BQC
|| device
->cap
._BCQ
) {
615 char *buf
= device
->cap
._BQC
? "_BQC" : "_BCQ";
617 status
= acpi_evaluate_integer(device
->dev
->handle
, buf
,
619 if (ACPI_SUCCESS(status
)) {
620 if (device
->brightness
->flags
._BQC_use_index
) {
621 if (device
->brightness
->flags
._BCL_reversed
)
622 *level
= device
->brightness
->count
624 *level
= device
->brightness
->levels
[*level
+ 2];
627 *level
+= bqc_offset_aml_bug_workaround
;
628 for (i
= 2; i
< device
->brightness
->count
; i
++)
629 if (device
->brightness
->levels
[i
] == *level
) {
630 device
->brightness
->curr
= *level
;
635 * BQC returned an invalid level.
638 ACPI_WARNING((AE_INFO
,
639 "%s returned an invalid level",
641 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
645 * should we return an error or ignore this failure?
646 * dev->brightness->curr is a cached value which stores
647 * the correct current backlight level in most cases.
648 * ACPI video backlight still works w/ buggy _BQC.
649 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
651 ACPI_WARNING((AE_INFO
, "Evaluating %s failed", buf
));
652 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
656 *level
= device
->brightness
->curr
;
661 acpi_video_device_EDID(struct acpi_video_device
*device
,
662 union acpi_object
**edid
, ssize_t length
)
665 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
666 union acpi_object
*obj
;
667 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
668 struct acpi_object_list args
= { 1, &arg0
};
676 arg0
.integer
.value
= 1;
677 else if (length
== 256)
678 arg0
.integer
.value
= 2;
682 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
683 if (ACPI_FAILURE(status
))
686 obj
= buffer
.pointer
;
688 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
691 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
702 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
705 unsigned long long tmp
;
706 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
707 struct acpi_object_list args
= { 1, &arg0
};
710 arg0
.integer
.value
= option
;
712 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
713 if (ACPI_SUCCESS(status
))
714 status
= tmp
? (-EINVAL
) : (AE_OK
);
720 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long long *id
)
724 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
730 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
731 unsigned long long *options
)
735 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
743 * video : video bus device pointer
745 * 0. The system BIOS should NOT automatically switch(toggle)
746 * the active display output.
747 * 1. The system BIOS should automatically switch (toggle) the
748 * active display output. No switch event.
749 * 2. The _DGS value should be locked.
750 * 3. The system BIOS should not automatically switch (toggle) the
751 * active display output, but instead generate the display switch
754 * 0. The system BIOS should automatically control the brightness level
755 * of the LCD when the power changes from AC to DC
756 * 1. The system BIOS should NOT automatically control the brightness
757 * level of the LCD when the power changes from AC to DC.
763 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
766 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
767 struct acpi_object_list args
= { 1, &arg0
};
770 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
774 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
775 video
->dos_setting
= arg0
.integer
.value
;
776 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
783 * Simple comparison function used to sort backlight levels.
787 acpi_video_cmp_level(const void *a
, const void *b
)
789 return *(int *)a
- *(int *)b
;
794 * device : video output device (LCD, CRT, ..)
797 * Maximum brightness level
799 * Allocate and initialize device->brightness.
803 acpi_video_init_brightness(struct acpi_video_device
*device
)
805 union acpi_object
*obj
= NULL
;
806 int i
, max_level
= 0, count
= 0, level_ac_battery
= 0;
807 unsigned long long level
, level_old
;
808 union acpi_object
*o
;
809 struct acpi_video_device_brightness
*br
= NULL
;
810 int result
= -EINVAL
;
812 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
813 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
814 "LCD brightness level\n"));
818 if (obj
->package
.count
< 2)
821 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
823 printk(KERN_ERR
"can't allocate memory\n");
828 br
->levels
= kmalloc((obj
->package
.count
+ 2) * sizeof *(br
->levels
),
835 for (i
= 0; i
< obj
->package
.count
; i
++) {
836 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
837 if (o
->type
!= ACPI_TYPE_INTEGER
) {
838 printk(KERN_ERR PREFIX
"Invalid data\n");
841 br
->levels
[count
] = (u32
) o
->integer
.value
;
843 if (br
->levels
[count
] > max_level
)
844 max_level
= br
->levels
[count
];
849 * some buggy BIOS don't export the levels
850 * when machine is on AC/Battery in _BCL package.
851 * In this case, the first two elements in _BCL packages
852 * are also supported brightness levels that OS should take care of.
854 for (i
= 2; i
< count
; i
++) {
855 if (br
->levels
[i
] == br
->levels
[0])
857 if (br
->levels
[i
] == br
->levels
[1])
861 if (level_ac_battery
< 2) {
862 level_ac_battery
= 2 - level_ac_battery
;
863 br
->flags
._BCL_no_ac_battery_levels
= 1;
864 for (i
= (count
- 1 + level_ac_battery
); i
>= 2; i
--)
865 br
->levels
[i
] = br
->levels
[i
- level_ac_battery
];
866 count
+= level_ac_battery
;
867 } else if (level_ac_battery
> 2)
868 ACPI_ERROR((AE_INFO
, "Too many duplicates in _BCL package\n"));
870 /* Check if the _BCL package is in a reversed order */
871 if (max_level
== br
->levels
[2]) {
872 br
->flags
._BCL_reversed
= 1;
873 sort(&br
->levels
[2], count
- 2, sizeof(br
->levels
[2]),
874 acpi_video_cmp_level
, NULL
);
875 } else if (max_level
!= br
->levels
[count
- 1])
877 "Found unordered _BCL package\n"));
880 device
->brightness
= br
;
882 /* Check the input/output of _BQC/_BCL/_BCM */
883 if ((max_level
< 100) && (max_level
<= (count
- 2)))
884 br
->flags
._BCL_use_index
= 1;
887 * _BCM is always consistent with _BCL,
888 * at least for all the laptops we have ever seen.
890 br
->flags
._BCM_use_index
= br
->flags
._BCL_use_index
;
892 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
893 br
->curr
= level
= max_level
;
895 if (!device
->cap
._BQC
)
898 result
= acpi_video_device_lcd_get_level_current(device
, &level_old
, 1);
900 goto out_free_levels
;
903 * Set the level to maximum and check if _BQC uses indexed value
905 result
= acpi_video_device_lcd_set_level(device
, max_level
);
907 goto out_free_levels
;
909 result
= acpi_video_device_lcd_get_level_current(device
, &level
, 0);
911 goto out_free_levels
;
913 br
->flags
._BQC_use_index
= (level
== max_level
? 0 : 1);
915 if (!br
->flags
._BQC_use_index
) {
917 * Set the backlight to the initial state.
918 * On some buggy laptops, _BQC returns an uninitialized value
919 * when invoked for the first time, i.e. level_old is invalid.
920 * set the backlight to max_level in this case
922 for (i
= 2; i
< br
->count
; i
++)
923 if (level_old
== br
->levels
[i
])
928 if (br
->flags
._BCL_reversed
)
929 level_old
= (br
->count
- 1) - level_old
;
930 level
= br
->levels
[level_old
];
933 result
= acpi_video_device_lcd_set_level(device
, level
);
935 goto out_free_levels
;
937 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
938 "found %d brightness levels\n", count
- 2));
947 device
->brightness
= NULL
;
954 * device : video output device (LCD, CRT, ..)
959 * Find out all required AML methods defined under the output
963 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
965 acpi_handle h_dummy1
;
967 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
968 device
->cap
._ADR
= 1;
970 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
971 device
->cap
._BCL
= 1;
973 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
974 device
->cap
._BCM
= 1;
976 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
977 device
->cap
._BQC
= 1;
978 else if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCQ",
980 printk(KERN_WARNING FW_BUG
"_BCQ is used instead of _BQC\n");
981 device
->cap
._BCQ
= 1;
984 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
985 device
->cap
._DDC
= 1;
987 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
988 device
->cap
._DCS
= 1;
990 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
991 device
->cap
._DGS
= 1;
993 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
994 device
->cap
._DSS
= 1;
997 if (acpi_video_backlight_support()) {
998 struct backlight_properties props
;
1000 static int count
= 0;
1003 result
= acpi_video_init_brightness(device
);
1006 name
= kasprintf(GFP_KERNEL
, "acpi_video%d", count
);
1011 memset(&props
, 0, sizeof(struct backlight_properties
));
1012 props
.max_brightness
= device
->brightness
->count
- 3;
1013 device
->backlight
= backlight_device_register(name
, NULL
, device
,
1014 &acpi_backlight_ops
,
1017 if (IS_ERR(device
->backlight
))
1021 * Save current brightness level in case we have to restore it
1022 * before acpi_video_device_lcd_set_level() is called next time.
1024 device
->backlight
->props
.brightness
=
1025 acpi_video_get_brightness(device
->backlight
);
1027 result
= sysfs_create_link(&device
->backlight
->dev
.kobj
,
1028 &device
->dev
->dev
.kobj
, "device");
1030 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1032 device
->cooling_dev
= thermal_cooling_device_register("LCD",
1033 device
->dev
, &video_cooling_ops
);
1034 if (IS_ERR(device
->cooling_dev
)) {
1036 * Set cooling_dev to NULL so we don't crash trying to
1038 * Also, why the hell we are returning early and
1039 * not attempt to register video output if cooling
1040 * device registration failed?
1043 device
->cooling_dev
= NULL
;
1047 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
1048 device
->cooling_dev
->id
);
1049 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
1050 &device
->cooling_dev
->device
.kobj
,
1053 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1054 result
= sysfs_create_link(&device
->cooling_dev
->device
.kobj
,
1055 &device
->dev
->dev
.kobj
, "device");
1057 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1061 if (acpi_video_display_switch_support()) {
1063 if (device
->cap
._DCS
&& device
->cap
._DSS
) {
1066 name
= kasprintf(GFP_KERNEL
, "acpi_video%d", count
);
1070 device
->output_dev
= video_output_register(name
,
1071 NULL
, device
, &acpi_output_properties
);
1079 * device : video output device (VGA)
1084 * Find out all required AML methods defined under the video bus device.
1087 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
1089 acpi_handle h_dummy1
;
1091 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
1092 video
->cap
._DOS
= 1;
1094 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
1095 video
->cap
._DOD
= 1;
1097 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
1098 video
->cap
._ROM
= 1;
1100 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
1101 video
->cap
._GPD
= 1;
1103 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
1104 video
->cap
._SPD
= 1;
1106 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
1107 video
->cap
._VPO
= 1;
1112 * Check whether the video bus device has required AML method to
1113 * support the desired features
1116 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
1118 acpi_status status
= -ENOENT
;
1119 struct pci_dev
*dev
;
1124 dev
= acpi_get_pci_dev(video
->device
->handle
);
1129 /* Since there is no HID, CID and so on for VGA driver, we have
1130 * to check well known required nodes.
1133 /* Does this device support video switching? */
1134 if (video
->cap
._DOS
|| video
->cap
._DOD
) {
1135 if (!video
->cap
._DOS
) {
1136 printk(KERN_WARNING FW_BUG
1137 "ACPI(%s) defines _DOD but not _DOS\n",
1138 acpi_device_bid(video
->device
));
1140 video
->flags
.multihead
= 1;
1144 /* Does this device support retrieving a video ROM? */
1145 if (video
->cap
._ROM
) {
1146 video
->flags
.rom
= 1;
1150 /* Does this device support configuring which video device to POST? */
1151 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
1152 video
->flags
.post
= 1;
1159 /* --------------------------------------------------------------------------
1160 FS Interface (/proc)
1161 -------------------------------------------------------------------------- */
1163 static struct proc_dir_entry
*acpi_video_dir
;
1167 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
1169 struct acpi_video_device
*dev
= seq
->private;
1175 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
1176 seq_printf(seq
, "type: ");
1178 seq_printf(seq
, "CRT\n");
1179 else if (dev
->flags
.lcd
)
1180 seq_printf(seq
, "LCD\n");
1181 else if (dev
->flags
.tvout
)
1182 seq_printf(seq
, "TVOUT\n");
1183 else if (dev
->flags
.dvi
)
1184 seq_printf(seq
, "DVI\n");
1186 seq_printf(seq
, "UNKNOWN\n");
1188 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
1195 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
1197 return single_open(file
, acpi_video_device_info_seq_show
,
1201 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
1204 struct acpi_video_device
*dev
= seq
->private;
1205 unsigned long long state
;
1211 status
= acpi_video_device_get_state(dev
, &state
);
1212 seq_printf(seq
, "state: ");
1213 if (ACPI_SUCCESS(status
))
1214 seq_printf(seq
, "0x%02llx\n", state
);
1216 seq_printf(seq
, "<not supported>\n");
1218 status
= acpi_video_device_query(dev
, &state
);
1219 seq_printf(seq
, "query: ");
1220 if (ACPI_SUCCESS(status
))
1221 seq_printf(seq
, "0x%02llx\n", state
);
1223 seq_printf(seq
, "<not supported>\n");
1230 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
1232 return single_open(file
, acpi_video_device_state_seq_show
,
1237 acpi_video_device_write_state(struct file
*file
,
1238 const char __user
* buffer
,
1239 size_t count
, loff_t
* data
)
1242 struct seq_file
*m
= file
->private_data
;
1243 struct acpi_video_device
*dev
= m
->private;
1244 char str
[12] = { 0 };
1248 if (!dev
|| count
>= sizeof(str
))
1251 if (copy_from_user(str
, buffer
, count
))
1255 state
= simple_strtoul(str
, NULL
, 0);
1256 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1258 status
= acpi_video_device_set_state(dev
, state
);
1267 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
1269 struct acpi_video_device
*dev
= seq
->private;
1273 if (!dev
|| !dev
->brightness
) {
1274 seq_printf(seq
, "<not supported>\n");
1278 seq_printf(seq
, "levels: ");
1279 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1280 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
1281 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
1287 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
1289 return single_open(file
, acpi_video_device_brightness_seq_show
,
1294 acpi_video_device_write_brightness(struct file
*file
,
1295 const char __user
* buffer
,
1296 size_t count
, loff_t
* data
)
1298 struct seq_file
*m
= file
->private_data
;
1299 struct acpi_video_device
*dev
= m
->private;
1300 char str
[5] = { 0 };
1301 unsigned int level
= 0;
1305 if (!dev
|| !dev
->brightness
|| count
>= sizeof(str
))
1308 if (copy_from_user(str
, buffer
, count
))
1312 level
= simple_strtoul(str
, NULL
, 0);
1317 /* validate through the list of available levels */
1318 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1319 if (level
== dev
->brightness
->levels
[i
]) {
1320 if (!acpi_video_device_lcd_set_level(dev
, level
))
1328 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
1330 struct acpi_video_device
*dev
= seq
->private;
1333 union acpi_object
*edid
= NULL
;
1339 status
= acpi_video_device_EDID(dev
, &edid
, 128);
1340 if (ACPI_FAILURE(status
)) {
1341 status
= acpi_video_device_EDID(dev
, &edid
, 256);
1344 if (ACPI_FAILURE(status
)) {
1348 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
1349 for (i
= 0; i
< edid
->buffer
.length
; i
++)
1350 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
1355 seq_printf(seq
, "<not supported>\n");
1363 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
1365 return single_open(file
, acpi_video_device_EDID_seq_show
,
1369 static int acpi_video_device_add_fs(struct acpi_device
*device
)
1371 struct proc_dir_entry
*entry
, *device_dir
;
1372 struct acpi_video_device
*vid_dev
;
1374 vid_dev
= acpi_driver_data(device
);
1378 device_dir
= proc_mkdir(acpi_device_bid(device
),
1379 vid_dev
->video
->dir
);
1384 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1385 &acpi_video_device_info_fops
, acpi_driver_data(device
));
1387 goto err_remove_dir
;
1390 entry
= proc_create_data("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1392 &acpi_video_device_state_fops
,
1393 acpi_driver_data(device
));
1395 goto err_remove_info
;
1397 /* 'brightness' [R/W] */
1398 entry
= proc_create_data("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1400 &acpi_video_device_brightness_fops
,
1401 acpi_driver_data(device
));
1403 goto err_remove_state
;
1406 entry
= proc_create_data("EDID", S_IRUGO
, device_dir
,
1407 &acpi_video_device_EDID_fops
,
1408 acpi_driver_data(device
));
1410 goto err_remove_brightness
;
1412 acpi_device_dir(device
) = device_dir
;
1416 err_remove_brightness
:
1417 remove_proc_entry("brightness", device_dir
);
1419 remove_proc_entry("state", device_dir
);
1421 remove_proc_entry("info", device_dir
);
1423 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1427 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1429 struct acpi_video_device
*vid_dev
;
1430 struct proc_dir_entry
*device_dir
;
1432 vid_dev
= acpi_driver_data(device
);
1433 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1436 device_dir
= acpi_device_dir(device
);
1438 remove_proc_entry("info", device_dir
);
1439 remove_proc_entry("state", device_dir
);
1440 remove_proc_entry("brightness", device_dir
);
1441 remove_proc_entry("EDID", device_dir
);
1442 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1443 acpi_device_dir(device
) = NULL
;
1450 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1452 struct acpi_video_bus
*video
= seq
->private;
1458 seq_printf(seq
, "Switching heads: %s\n",
1459 video
->flags
.multihead
? "yes" : "no");
1460 seq_printf(seq
, "Video ROM: %s\n",
1461 video
->flags
.rom
? "yes" : "no");
1462 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1463 video
->flags
.post
? "yes" : "no");
1469 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1471 return single_open(file
, acpi_video_bus_info_seq_show
,
1475 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1477 struct acpi_video_bus
*video
= seq
->private;
1483 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1484 seq_printf(seq
, "<TODO>\n");
1490 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1492 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1495 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1497 struct acpi_video_bus
*video
= seq
->private;
1498 unsigned long long options
;
1505 status
= acpi_video_bus_POST_options(video
, &options
);
1506 if (ACPI_SUCCESS(status
)) {
1507 if (!(options
& 1)) {
1508 printk(KERN_WARNING PREFIX
1509 "The motherboard VGA device is not listed as a possible POST device.\n");
1510 printk(KERN_WARNING PREFIX
1511 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1513 printk(KERN_WARNING
"%llx\n", options
);
1514 seq_printf(seq
, "can POST: <integrated video>");
1516 seq_printf(seq
, " <PCI video>");
1518 seq_printf(seq
, " <AGP video>");
1519 seq_putc(seq
, '\n');
1521 seq_printf(seq
, "<not supported>\n");
1527 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1529 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1533 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1535 struct acpi_video_bus
*video
= seq
->private;
1537 unsigned long long id
;
1543 status
= acpi_video_bus_get_POST(video
, &id
);
1544 if (!ACPI_SUCCESS(status
)) {
1545 seq_printf(seq
, "<not supported>\n");
1548 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1554 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1556 struct acpi_video_bus
*video
= seq
->private;
1559 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1564 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1566 return single_open(file
, acpi_video_bus_POST_seq_show
,
1570 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1572 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1576 acpi_video_bus_write_POST(struct file
*file
,
1577 const char __user
* buffer
,
1578 size_t count
, loff_t
* data
)
1581 struct seq_file
*m
= file
->private_data
;
1582 struct acpi_video_bus
*video
= m
->private;
1583 char str
[12] = { 0 };
1584 unsigned long long opt
, options
;
1587 if (!video
|| count
>= sizeof(str
))
1590 status
= acpi_video_bus_POST_options(video
, &options
);
1591 if (!ACPI_SUCCESS(status
))
1594 if (copy_from_user(str
, buffer
, count
))
1598 opt
= strtoul(str
, NULL
, 0);
1602 /* just in case an OEM 'forgot' the motherboard... */
1605 if (options
& (1ul << opt
)) {
1606 status
= acpi_video_bus_set_POST(video
, opt
);
1607 if (!ACPI_SUCCESS(status
))
1616 acpi_video_bus_write_DOS(struct file
*file
,
1617 const char __user
* buffer
,
1618 size_t count
, loff_t
* data
)
1621 struct seq_file
*m
= file
->private_data
;
1622 struct acpi_video_bus
*video
= m
->private;
1623 char str
[12] = { 0 };
1627 if (!video
|| count
>= sizeof(str
))
1630 if (copy_from_user(str
, buffer
, count
))
1634 opt
= strtoul(str
, NULL
, 0);
1638 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1640 if (!ACPI_SUCCESS(status
))
1646 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1648 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1649 struct proc_dir_entry
*device_dir
;
1650 struct proc_dir_entry
*entry
;
1652 device_dir
= proc_mkdir(acpi_device_bid(device
), acpi_video_dir
);
1657 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1658 &acpi_video_bus_info_fops
,
1659 acpi_driver_data(device
));
1661 goto err_remove_dir
;
1664 entry
= proc_create_data("ROM", S_IRUGO
, device_dir
,
1665 &acpi_video_bus_ROM_fops
,
1666 acpi_driver_data(device
));
1668 goto err_remove_info
;
1670 /* 'POST_info' [R] */
1671 entry
= proc_create_data("POST_info", S_IRUGO
, device_dir
,
1672 &acpi_video_bus_POST_info_fops
,
1673 acpi_driver_data(device
));
1675 goto err_remove_rom
;
1678 entry
= proc_create_data("POST", S_IFREG
| S_IRUGO
| S_IWUSR
,
1680 &acpi_video_bus_POST_fops
,
1681 acpi_driver_data(device
));
1683 goto err_remove_post_info
;
1686 entry
= proc_create_data("DOS", S_IFREG
| S_IRUGO
| S_IWUSR
,
1688 &acpi_video_bus_DOS_fops
,
1689 acpi_driver_data(device
));
1691 goto err_remove_post
;
1693 video
->dir
= acpi_device_dir(device
) = device_dir
;
1697 remove_proc_entry("POST", device_dir
);
1698 err_remove_post_info
:
1699 remove_proc_entry("POST_info", device_dir
);
1701 remove_proc_entry("ROM", device_dir
);
1703 remove_proc_entry("info", device_dir
);
1705 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1709 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1711 struct proc_dir_entry
*device_dir
= acpi_device_dir(device
);
1714 remove_proc_entry("info", device_dir
);
1715 remove_proc_entry("ROM", device_dir
);
1716 remove_proc_entry("POST_info", device_dir
);
1717 remove_proc_entry("POST", device_dir
);
1718 remove_proc_entry("DOS", device_dir
);
1719 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1720 acpi_device_dir(device
) = NULL
;
1726 /* --------------------------------------------------------------------------
1728 -------------------------------------------------------------------------- */
1730 /* device interface */
1731 static struct acpi_video_device_attrib
*
1732 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1734 struct acpi_video_enumerated_device
*ids
;
1737 for (i
= 0; i
< video
->attached_count
; i
++) {
1738 ids
= &video
->attached_array
[i
];
1739 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1740 return &ids
->value
.attrib
;
1747 acpi_video_get_device_type(struct acpi_video_bus
*video
,
1748 unsigned long device_id
)
1750 struct acpi_video_enumerated_device
*ids
;
1753 for (i
= 0; i
< video
->attached_count
; i
++) {
1754 ids
= &video
->attached_array
[i
];
1755 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1756 return ids
->value
.int_val
;
1763 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1764 struct acpi_video_bus
*video
)
1766 unsigned long long device_id
;
1767 int status
, device_type
;
1768 struct acpi_video_device
*data
;
1769 struct acpi_video_device_attrib
* attribute
;
1771 if (!device
|| !video
)
1775 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1776 if (ACPI_SUCCESS(status
)) {
1778 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1782 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1783 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1784 device
->driver_data
= data
;
1786 data
->device_id
= device_id
;
1787 data
->video
= video
;
1790 attribute
= acpi_video_get_device_attr(video
, device_id
);
1792 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1793 switch (attribute
->display_type
) {
1794 case ACPI_VIDEO_DISPLAY_CRT
:
1795 data
->flags
.crt
= 1;
1797 case ACPI_VIDEO_DISPLAY_TV
:
1798 data
->flags
.tvout
= 1;
1800 case ACPI_VIDEO_DISPLAY_DVI
:
1801 data
->flags
.dvi
= 1;
1803 case ACPI_VIDEO_DISPLAY_LCD
:
1804 data
->flags
.lcd
= 1;
1807 data
->flags
.unknown
= 1;
1810 if(attribute
->bios_can_detect
)
1811 data
->flags
.bios
= 1;
1813 /* Check for legacy IDs */
1814 device_type
= acpi_video_get_device_type(video
,
1816 /* Ignore bits 16 and 18-20 */
1817 switch (device_type
& 0xffe2ffff) {
1818 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR
:
1819 data
->flags
.crt
= 1;
1821 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL
:
1822 data
->flags
.lcd
= 1;
1824 case ACPI_VIDEO_DISPLAY_LEGACY_TV
:
1825 data
->flags
.tvout
= 1;
1828 data
->flags
.unknown
= 1;
1832 acpi_video_device_bind(video
, data
);
1833 acpi_video_device_find_cap(data
);
1835 status
= acpi_install_notify_handler(device
->handle
,
1837 acpi_video_device_notify
,
1839 if (ACPI_FAILURE(status
)) {
1840 printk(KERN_ERR PREFIX
1841 "Error installing notify handler\n");
1842 if(data
->brightness
)
1843 kfree(data
->brightness
->levels
);
1844 kfree(data
->brightness
);
1849 mutex_lock(&video
->device_list_lock
);
1850 list_add_tail(&data
->entry
, &video
->video_device_list
);
1851 mutex_unlock(&video
->device_list_lock
);
1853 acpi_video_device_add_fs(device
);
1863 * video : video bus device
1868 * Enumerate the video device list of the video bus,
1869 * bind the ids with the corresponding video devices
1870 * under the video bus.
1873 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1875 struct acpi_video_device
*dev
;
1877 mutex_lock(&video
->device_list_lock
);
1879 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1880 acpi_video_device_bind(video
, dev
);
1882 mutex_unlock(&video
->device_list_lock
);
1887 * video : video bus device
1888 * device : video output device under the video
1894 * Bind the ids with the corresponding video devices
1895 * under the video bus.
1899 acpi_video_device_bind(struct acpi_video_bus
*video
,
1900 struct acpi_video_device
*device
)
1902 struct acpi_video_enumerated_device
*ids
;
1905 for (i
= 0; i
< video
->attached_count
; i
++) {
1906 ids
= &video
->attached_array
[i
];
1907 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1908 ids
->bind_info
= device
;
1909 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1916 * video : video bus device
1921 * Call _DOD to enumerate all devices attached to display adapter
1925 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1930 struct acpi_video_enumerated_device
*active_list
;
1931 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1932 union acpi_object
*dod
= NULL
;
1933 union acpi_object
*obj
;
1935 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1936 if (!ACPI_SUCCESS(status
)) {
1937 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1941 dod
= buffer
.pointer
;
1942 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1943 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1948 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1949 dod
->package
.count
));
1951 active_list
= kcalloc(1 + dod
->package
.count
,
1952 sizeof(struct acpi_video_enumerated_device
),
1960 for (i
= 0; i
< dod
->package
.count
; i
++) {
1961 obj
= &dod
->package
.elements
[i
];
1963 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1964 printk(KERN_ERR PREFIX
1965 "Invalid _DOD data in element %d\n", i
);
1969 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1970 active_list
[count
].bind_info
= NULL
;
1971 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1972 (int)obj
->integer
.value
));
1976 kfree(video
->attached_array
);
1978 video
->attached_array
= active_list
;
1979 video
->attached_count
= count
;
1982 kfree(buffer
.pointer
);
1987 acpi_video_get_next_level(struct acpi_video_device
*device
,
1988 u32 level_current
, u32 event
)
1990 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1991 max
= max_below
= 0;
1992 min
= min_above
= 255;
1993 /* Find closest level to level_current */
1994 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1995 l
= device
->brightness
->levels
[i
];
1996 if (abs(l
- level_current
) < abs(delta
)) {
1997 delta
= l
- level_current
;
2002 /* Ajust level_current to closest available level */
2003 level_current
+= delta
;
2004 for (i
= 2; i
< device
->brightness
->count
; i
++) {
2005 l
= device
->brightness
->levels
[i
];
2010 if (l
< min_above
&& l
> level_current
)
2012 if (l
> max_below
&& l
< level_current
)
2017 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
2018 return (level_current
< max
) ? min_above
: min
;
2019 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
2020 return (level_current
< max
) ? min_above
: max
;
2021 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
2022 return (level_current
> min
) ? max_below
: min
;
2023 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
2024 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
2027 return level_current
;
2032 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
2034 unsigned long long level_current
, level_next
;
2035 int result
= -EINVAL
;
2037 /* no warning message if acpi_backlight=vendor is used */
2038 if (!acpi_video_backlight_support())
2041 if (!device
->brightness
)
2044 result
= acpi_video_device_lcd_get_level_current(device
,
2049 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
2051 result
= acpi_video_device_lcd_set_level(device
, level_next
);
2054 backlight_force_update(device
->backlight
,
2055 BACKLIGHT_UPDATE_HOTKEY
);
2059 printk(KERN_ERR PREFIX
"Failed to switch the brightness\n");
2064 int acpi_video_get_edid(struct acpi_device
*device
, int type
, int device_id
,
2067 struct acpi_video_bus
*video
;
2068 struct acpi_video_device
*video_device
;
2069 union acpi_object
*buffer
= NULL
;
2073 if (!device
|| !acpi_driver_data(device
))
2076 video
= acpi_driver_data(device
);
2078 for (i
= 0; i
< video
->attached_count
; i
++) {
2079 video_device
= video
->attached_array
[i
].bind_info
;
2087 case ACPI_VIDEO_DISPLAY_CRT
:
2088 if (!video_device
->flags
.crt
)
2091 case ACPI_VIDEO_DISPLAY_TV
:
2092 if (!video_device
->flags
.tvout
)
2095 case ACPI_VIDEO_DISPLAY_DVI
:
2096 if (!video_device
->flags
.dvi
)
2099 case ACPI_VIDEO_DISPLAY_LCD
:
2100 if (!video_device
->flags
.lcd
)
2104 } else if (video_device
->device_id
!= device_id
) {
2108 status
= acpi_video_device_EDID(video_device
, &buffer
, length
);
2110 if (ACPI_FAILURE(status
) || !buffer
||
2111 buffer
->type
!= ACPI_TYPE_BUFFER
) {
2113 status
= acpi_video_device_EDID(video_device
, &buffer
,
2115 if (ACPI_FAILURE(status
) || !buffer
||
2116 buffer
->type
!= ACPI_TYPE_BUFFER
) {
2121 *edid
= buffer
->buffer
.pointer
;
2127 EXPORT_SYMBOL(acpi_video_get_edid
);
2130 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
2131 struct acpi_device
*device
)
2134 struct acpi_device
*dev
;
2136 acpi_video_device_enumerate(video
);
2138 list_for_each_entry(dev
, &device
->children
, node
) {
2140 status
= acpi_video_bus_get_one_device(dev
, video
);
2141 if (ACPI_FAILURE(status
)) {
2142 printk(KERN_WARNING PREFIX
2143 "Cant attach device");
2150 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
2153 struct acpi_video_bus
*video
;
2156 if (!device
|| !device
->video
)
2159 video
= device
->video
;
2161 acpi_video_device_remove_fs(device
->dev
);
2163 status
= acpi_remove_notify_handler(device
->dev
->handle
,
2165 acpi_video_device_notify
);
2166 if (device
->backlight
) {
2167 sysfs_remove_link(&device
->backlight
->dev
.kobj
, "device");
2168 backlight_device_unregister(device
->backlight
);
2169 device
->backlight
= NULL
;
2171 if (device
->cooling_dev
) {
2172 sysfs_remove_link(&device
->dev
->dev
.kobj
,
2174 sysfs_remove_link(&device
->cooling_dev
->device
.kobj
,
2176 thermal_cooling_device_unregister(device
->cooling_dev
);
2177 device
->cooling_dev
= NULL
;
2179 video_output_unregister(device
->output_dev
);
2184 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
2187 struct acpi_video_device
*dev
, *next
;
2189 mutex_lock(&video
->device_list_lock
);
2191 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
2193 status
= acpi_video_bus_put_one_device(dev
);
2194 if (ACPI_FAILURE(status
))
2195 printk(KERN_WARNING PREFIX
2196 "hhuuhhuu bug in acpi video driver.\n");
2198 if (dev
->brightness
) {
2199 kfree(dev
->brightness
->levels
);
2200 kfree(dev
->brightness
);
2202 list_del(&dev
->entry
);
2206 mutex_unlock(&video
->device_list_lock
);
2211 /* acpi_video interface */
2213 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
2215 return acpi_video_bus_DOS(video
, 0, 0);
2218 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
2220 return acpi_video_bus_DOS(video
, 0, 1);
2223 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
)
2225 struct acpi_video_bus
*video
= acpi_driver_data(device
);
2226 struct input_dev
*input
;
2232 input
= video
->input
;
2235 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
2236 * most likely via hotkey. */
2237 acpi_bus_generate_proc_event(device
, event
, 0);
2238 keycode
= KEY_SWITCHVIDEOMODE
;
2241 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
2243 acpi_video_device_enumerate(video
);
2244 acpi_video_device_rebind(video
);
2245 acpi_bus_generate_proc_event(device
, event
, 0);
2246 keycode
= KEY_SWITCHVIDEOMODE
;
2249 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
2250 acpi_bus_generate_proc_event(device
, event
, 0);
2251 keycode
= KEY_SWITCHVIDEOMODE
;
2253 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
2254 acpi_bus_generate_proc_event(device
, event
, 0);
2255 keycode
= KEY_VIDEO_NEXT
;
2257 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
2258 acpi_bus_generate_proc_event(device
, event
, 0);
2259 keycode
= KEY_VIDEO_PREV
;
2263 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
2264 "Unsupported event [0x%x]\n", event
));
2268 acpi_notifier_call_chain(device
, event
, 0);
2271 input_report_key(input
, keycode
, 1);
2273 input_report_key(input
, keycode
, 0);
2280 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
2282 struct acpi_video_device
*video_device
= data
;
2283 struct acpi_device
*device
= NULL
;
2284 struct acpi_video_bus
*bus
;
2285 struct input_dev
*input
;
2291 device
= video_device
->dev
;
2292 bus
= video_device
->video
;
2296 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
2297 if (brightness_switch_enabled
)
2298 acpi_video_switch_brightness(video_device
, event
);
2299 acpi_bus_generate_proc_event(device
, event
, 0);
2300 keycode
= KEY_BRIGHTNESS_CYCLE
;
2302 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
2303 if (brightness_switch_enabled
)
2304 acpi_video_switch_brightness(video_device
, event
);
2305 acpi_bus_generate_proc_event(device
, event
, 0);
2306 keycode
= KEY_BRIGHTNESSUP
;
2308 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
2309 if (brightness_switch_enabled
)
2310 acpi_video_switch_brightness(video_device
, event
);
2311 acpi_bus_generate_proc_event(device
, event
, 0);
2312 keycode
= KEY_BRIGHTNESSDOWN
;
2314 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
2315 if (brightness_switch_enabled
)
2316 acpi_video_switch_brightness(video_device
, event
);
2317 acpi_bus_generate_proc_event(device
, event
, 0);
2318 keycode
= KEY_BRIGHTNESS_ZERO
;
2320 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
2321 if (brightness_switch_enabled
)
2322 acpi_video_switch_brightness(video_device
, event
);
2323 acpi_bus_generate_proc_event(device
, event
, 0);
2324 keycode
= KEY_DISPLAY_OFF
;
2327 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
2328 "Unsupported event [0x%x]\n", event
));
2332 acpi_notifier_call_chain(device
, event
, 0);
2335 input_report_key(input
, keycode
, 1);
2337 input_report_key(input
, keycode
, 0);
2344 static int acpi_video_resume(struct notifier_block
*nb
,
2345 unsigned long val
, void *ign
)
2347 struct acpi_video_bus
*video
;
2348 struct acpi_video_device
*video_device
;
2352 case PM_HIBERNATION_PREPARE
:
2353 case PM_SUSPEND_PREPARE
:
2354 case PM_RESTORE_PREPARE
:
2358 video
= container_of(nb
, struct acpi_video_bus
, pm_nb
);
2360 dev_info(&video
->device
->dev
, "Restoring backlight state\n");
2362 for (i
= 0; i
< video
->attached_count
; i
++) {
2363 video_device
= video
->attached_array
[i
].bind_info
;
2364 if (video_device
&& video_device
->backlight
)
2365 acpi_video_set_brightness(video_device
->backlight
);
2372 acpi_video_bus_match(acpi_handle handle
, u32 level
, void *context
,
2373 void **return_value
)
2375 struct acpi_device
*device
= context
;
2376 struct acpi_device
*sibling
;
2379 if (handle
== device
->handle
)
2380 return AE_CTRL_TERMINATE
;
2382 result
= acpi_bus_get_device(handle
, &sibling
);
2386 if (!strcmp(acpi_device_name(sibling
), ACPI_VIDEO_BUS_NAME
))
2387 return AE_ALREADY_EXISTS
;
2392 static int instance
;
2394 static int acpi_video_bus_add(struct acpi_device
*device
)
2396 struct acpi_video_bus
*video
;
2397 struct input_dev
*input
;
2401 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
,
2402 device
->parent
->handle
, 1,
2403 acpi_video_bus_match
, NULL
,
2405 if (status
== AE_ALREADY_EXISTS
) {
2406 printk(KERN_WARNING FW_BUG
2407 "Duplicate ACPI video bus devices for the"
2408 " same VGA controller, please try module "
2409 "parameter \"video.allow_duplicates=1\""
2410 "if the current driver doesn't work.\n");
2411 if (!allow_duplicates
)
2415 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
2419 /* a hack to fix the duplicate name "VID" problem on T61 */
2420 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
2422 device
->pnp
.bus_id
[3] = '0' + instance
;
2425 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2426 if (!strcmp(device
->pnp
.bus_id
, "VGA")) {
2428 device
->pnp
.bus_id
[3] = '0' + instance
;
2432 video
->device
= device
;
2433 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
2434 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
2435 device
->driver_data
= video
;
2437 acpi_video_bus_find_cap(video
);
2438 error
= acpi_video_bus_check(video
);
2440 goto err_free_video
;
2442 error
= acpi_video_bus_add_fs(device
);
2444 goto err_free_video
;
2446 mutex_init(&video
->device_list_lock
);
2447 INIT_LIST_HEAD(&video
->video_device_list
);
2449 acpi_video_bus_get_devices(video
, device
);
2450 acpi_video_bus_start_devices(video
);
2452 video
->input
= input
= input_allocate_device();
2455 goto err_stop_video
;
2458 snprintf(video
->phys
, sizeof(video
->phys
),
2459 "%s/video/input0", acpi_device_hid(video
->device
));
2461 input
->name
= acpi_device_name(video
->device
);
2462 input
->phys
= video
->phys
;
2463 input
->id
.bustype
= BUS_HOST
;
2464 input
->id
.product
= 0x06;
2465 input
->dev
.parent
= &device
->dev
;
2466 input
->evbit
[0] = BIT(EV_KEY
);
2467 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2468 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2469 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2470 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2471 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2472 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2473 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2474 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2476 error
= input_register_device(input
);
2478 goto err_free_input_dev
;
2480 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2481 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2482 video
->flags
.multihead
? "yes" : "no",
2483 video
->flags
.rom
? "yes" : "no",
2484 video
->flags
.post
? "yes" : "no");
2486 video
->pm_nb
.notifier_call
= acpi_video_resume
;
2487 video
->pm_nb
.priority
= 0;
2488 register_pm_notifier(&video
->pm_nb
);
2493 input_free_device(input
);
2495 acpi_video_bus_stop_devices(video
);
2496 acpi_video_bus_put_devices(video
);
2497 kfree(video
->attached_array
);
2498 acpi_video_bus_remove_fs(device
);
2501 device
->driver_data
= NULL
;
2506 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2508 struct acpi_video_bus
*video
= NULL
;
2511 if (!device
|| !acpi_driver_data(device
))
2514 video
= acpi_driver_data(device
);
2516 unregister_pm_notifier(&video
->pm_nb
);
2518 acpi_video_bus_stop_devices(video
);
2519 acpi_video_bus_put_devices(video
);
2520 acpi_video_bus_remove_fs(device
);
2522 input_unregister_device(video
->input
);
2523 kfree(video
->attached_array
);
2529 static int __init
intel_opregion_present(void)
2531 #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2532 struct pci_dev
*dev
= NULL
;
2535 for_each_pci_dev(dev
) {
2536 if ((dev
->class >> 8) != PCI_CLASS_DISPLAY_VGA
)
2538 if (dev
->vendor
!= PCI_VENDOR_ID_INTEL
)
2540 pci_read_config_dword(dev
, 0xfc, &address
);
2549 int acpi_video_register(void)
2552 if (register_count
) {
2554 * if the function of acpi_video_register is already called,
2555 * don't register the acpi_vide_bus again and return no error.
2560 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2561 if (!acpi_video_dir
)
2564 result
= acpi_bus_register_driver(&acpi_video_bus
);
2566 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2571 * When the acpi_video_bus is loaded successfully, increase
2572 * the counter reference.
2578 EXPORT_SYMBOL(acpi_video_register
);
2580 void acpi_video_unregister(void)
2582 if (!register_count
) {
2584 * If the acpi video bus is already unloaded, don't
2585 * unload it again and return directly.
2589 acpi_bus_unregister_driver(&acpi_video_bus
);
2591 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2597 EXPORT_SYMBOL(acpi_video_unregister
);
2600 * This is kind of nasty. Hardware using Intel chipsets may require
2601 * the video opregion code to be run first in order to initialise
2602 * state before any ACPI video calls are made. To handle this we defer
2603 * registration of the video class until the opregion code has run.
2606 static int __init
acpi_video_init(void)
2608 dmi_check_system(video_dmi_table
);
2610 if (intel_opregion_present())
2613 return acpi_video_register();
2616 static void __exit
acpi_video_exit(void)
2618 acpi_video_unregister();
2623 module_init(acpi_video_init
);
2624 module_exit(acpi_video_exit
);