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 <asm/uaccess.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
44 #define ACPI_VIDEO_COMPONENT 0x08000000
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled
= 1;
75 module_param(brightness_switch_enabled
, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device
*device
);
78 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
79 static int acpi_video_resume(struct acpi_device
*device
);
81 static const struct acpi_device_id video_device_ids
[] = {
85 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
87 static struct acpi_driver acpi_video_bus
= {
89 .class = ACPI_VIDEO_CLASS
,
90 .ids
= video_device_ids
,
92 .add
= acpi_video_bus_add
,
93 .remove
= acpi_video_bus_remove
,
94 .resume
= acpi_video_resume
,
98 struct acpi_video_bus_flags
{
99 u8 multihead
:1; /* can switch video heads */
100 u8 rom
:1; /* can retrieve a video rom */
101 u8 post
:1; /* can configure the head to */
105 struct acpi_video_bus_cap
{
106 u8 _DOS
:1; /*Enable/Disable output switching */
107 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM
:1; /*Get ROM Data */
109 u8 _GPD
:1; /*Get POST Device */
110 u8 _SPD
:1; /*Set POST Device */
111 u8 _VPO
:1; /*Video POST Options */
115 struct acpi_video_device_attrib
{
116 u32 display_index
:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment
:4; /*This field differentiates the display type */
118 u32 display_type
:4; /*Describe the specific type in use */
119 u32 vendor_specific
:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect
:1; /*BIOS can detect the device */
121 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id
:3; /*For VGA multiple-head devices. */
124 u32 reserved
:10; /*Must be 0 */
125 u32 device_id_scheme
:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device
{
131 struct acpi_video_device_attrib attrib
;
133 struct acpi_video_device
*bind_info
;
136 struct acpi_video_bus
{
137 struct acpi_device
*device
;
139 struct acpi_video_enumerated_device
*attached_array
;
141 struct acpi_video_bus_cap cap
;
142 struct acpi_video_bus_flags flags
;
143 struct list_head video_device_list
;
144 struct mutex device_list_lock
; /* protects video_device_list */
145 struct proc_dir_entry
*dir
;
146 struct input_dev
*input
;
147 char phys
[32]; /* for input device */
150 struct acpi_video_device_flags
{
160 struct acpi_video_device_cap
{
161 u8 _ADR
:1; /*Return the unique ID */
162 u8 _BCL
:1; /*Query list of brightness control levels supported */
163 u8 _BCM
:1; /*Set the brightness level */
164 u8 _BQC
:1; /* Get current brightness level */
165 u8 _DDC
:1; /*Return the EDID for this device */
166 u8 _DCS
:1; /*Return status of output device */
167 u8 _DGS
:1; /*Query graphics state */
168 u8 _DSS
:1; /*Device state set */
171 struct acpi_video_device_brightness
{
177 struct acpi_video_device
{
178 unsigned long device_id
;
179 struct acpi_video_device_flags flags
;
180 struct acpi_video_device_cap cap
;
181 struct list_head entry
;
182 struct acpi_video_bus
*video
;
183 struct acpi_device
*dev
;
184 struct acpi_video_device_brightness
*brightness
;
185 struct backlight_device
*backlight
;
186 struct thermal_cooling_device
*cdev
;
187 struct output_device
*output_dev
;
191 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
192 static struct file_operations acpi_video_bus_info_fops
= {
193 .open
= acpi_video_bus_info_open_fs
,
196 .release
= single_release
,
199 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
200 static struct file_operations acpi_video_bus_ROM_fops
= {
201 .open
= acpi_video_bus_ROM_open_fs
,
204 .release
= single_release
,
207 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
209 static struct file_operations acpi_video_bus_POST_info_fops
= {
210 .open
= acpi_video_bus_POST_info_open_fs
,
213 .release
= single_release
,
216 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
217 static struct file_operations acpi_video_bus_POST_fops
= {
218 .open
= acpi_video_bus_POST_open_fs
,
221 .release
= single_release
,
224 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
225 static struct file_operations acpi_video_bus_DOS_fops
= {
226 .open
= acpi_video_bus_DOS_open_fs
,
229 .release
= single_release
,
233 static int acpi_video_device_info_open_fs(struct inode
*inode
,
235 static struct file_operations acpi_video_device_info_fops
= {
236 .open
= acpi_video_device_info_open_fs
,
239 .release
= single_release
,
242 static int acpi_video_device_state_open_fs(struct inode
*inode
,
244 static struct file_operations acpi_video_device_state_fops
= {
245 .open
= acpi_video_device_state_open_fs
,
248 .release
= single_release
,
251 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
253 static struct file_operations acpi_video_device_brightness_fops
= {
254 .open
= acpi_video_device_brightness_open_fs
,
257 .release
= single_release
,
260 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
262 static struct file_operations acpi_video_device_EDID_fops
= {
263 .open
= acpi_video_device_EDID_open_fs
,
266 .release
= single_release
,
269 static char device_decode
[][30] = {
270 "motherboard VGA device",
276 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
277 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
278 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
279 struct acpi_video_device
*device
);
280 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
281 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
283 static int acpi_video_device_lcd_get_level_current(
284 struct acpi_video_device
*device
,
285 unsigned long *level
);
286 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
287 u32 level_current
, u32 event
);
288 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
290 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
291 unsigned long *state
);
292 static int acpi_video_output_get(struct output_device
*od
);
293 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
295 /*backlight device sysfs support*/
296 static int acpi_video_get_brightness(struct backlight_device
*bd
)
298 unsigned long cur_level
;
300 struct acpi_video_device
*vd
=
301 (struct acpi_video_device
*)bl_get_data(bd
);
302 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
303 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
304 if (vd
->brightness
->levels
[i
] == cur_level
)
305 /* The first two entries are special - see page 575
306 of the ACPI spec 3.0 */
312 static int acpi_video_set_brightness(struct backlight_device
*bd
)
314 int request_level
= bd
->props
.brightness
+2;
315 struct acpi_video_device
*vd
=
316 (struct acpi_video_device
*)bl_get_data(bd
);
317 acpi_video_device_lcd_set_level(vd
,
318 vd
->brightness
->levels
[request_level
]);
322 static struct backlight_ops acpi_backlight_ops
= {
323 .get_brightness
= acpi_video_get_brightness
,
324 .update_status
= acpi_video_set_brightness
,
327 /*video output device sysfs support*/
328 static int acpi_video_output_get(struct output_device
*od
)
331 struct acpi_video_device
*vd
=
332 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
333 acpi_video_device_get_state(vd
, &state
);
337 static int acpi_video_output_set(struct output_device
*od
)
339 unsigned long state
= od
->request_state
;
340 struct acpi_video_device
*vd
=
341 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
342 return acpi_video_device_set_state(vd
, state
);
345 static struct output_properties acpi_output_properties
= {
346 .set_state
= acpi_video_output_set
,
347 .get_status
= acpi_video_output_get
,
351 /* thermal cooling device callbacks */
352 static int video_get_max_state(struct thermal_cooling_device
*cdev
, char *buf
)
354 struct acpi_device
*device
= cdev
->devdata
;
355 struct acpi_video_device
*video
= acpi_driver_data(device
);
357 return sprintf(buf
, "%d\n", video
->brightness
->count
- 3);
360 static int video_get_cur_state(struct thermal_cooling_device
*cdev
, char *buf
)
362 struct acpi_device
*device
= cdev
->devdata
;
363 struct acpi_video_device
*video
= acpi_driver_data(device
);
367 acpi_video_device_lcd_get_level_current(video
, &level
);
368 for (state
= 2; state
< video
->brightness
->count
; state
++)
369 if (level
== video
->brightness
->levels
[state
])
370 return sprintf(buf
, "%d\n",
371 video
->brightness
->count
- state
- 1);
377 video_set_cur_state(struct thermal_cooling_device
*cdev
, unsigned int state
)
379 struct acpi_device
*device
= cdev
->devdata
;
380 struct acpi_video_device
*video
= acpi_driver_data(device
);
383 if ( state
>= video
->brightness
->count
- 2)
386 state
= video
->brightness
->count
- state
;
387 level
= video
->brightness
->levels
[state
-1];
388 return acpi_video_device_lcd_set_level(video
, level
);
391 static struct thermal_cooling_device_ops video_cooling_ops
= {
392 .get_max_state
= video_get_max_state
,
393 .get_cur_state
= video_get_cur_state
,
394 .set_cur_state
= video_set_cur_state
,
397 /* --------------------------------------------------------------------------
399 -------------------------------------------------------------------------- */
404 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
408 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
414 acpi_video_device_get_state(struct acpi_video_device
*device
,
415 unsigned long *state
)
419 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
425 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
428 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
429 struct acpi_object_list args
= { 1, &arg0
};
433 arg0
.integer
.value
= state
;
434 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
440 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
441 union acpi_object
**levels
)
444 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
445 union acpi_object
*obj
;
450 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
451 if (!ACPI_SUCCESS(status
))
453 obj
= (union acpi_object
*)buffer
.pointer
;
454 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
455 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
465 kfree(buffer
.pointer
);
471 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
474 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
475 struct acpi_object_list args
= { 1, &arg0
};
478 arg0
.integer
.value
= level
;
480 if (device
->cap
._BCM
)
481 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
483 device
->brightness
->curr
= level
;
488 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
489 unsigned long *level
)
491 if (device
->cap
._BQC
)
492 return acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
,
494 *level
= device
->brightness
->curr
;
499 acpi_video_device_EDID(struct acpi_video_device
*device
,
500 union acpi_object
**edid
, ssize_t length
)
503 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
504 union acpi_object
*obj
;
505 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
506 struct acpi_object_list args
= { 1, &arg0
};
514 arg0
.integer
.value
= 1;
515 else if (length
== 256)
516 arg0
.integer
.value
= 2;
520 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
521 if (ACPI_FAILURE(status
))
524 obj
= buffer
.pointer
;
526 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
529 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
540 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
544 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
545 struct acpi_object_list args
= { 1, &arg0
};
548 arg0
.integer
.value
= option
;
550 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
551 if (ACPI_SUCCESS(status
))
552 status
= tmp
? (-EINVAL
) : (AE_OK
);
558 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
562 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
568 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
569 unsigned long *options
)
573 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
581 * video : video bus device pointer
583 * 0. The system BIOS should NOT automatically switch(toggle)
584 * the active display output.
585 * 1. The system BIOS should automatically switch (toggle) the
586 * active display output. No switch event.
587 * 2. The _DGS value should be locked.
588 * 3. The system BIOS should not automatically switch (toggle) the
589 * active display output, but instead generate the display switch
592 * 0. The system BIOS should automatically control the brightness level
593 * of the LCD when the power changes from AC to DC
594 * 1. The system BIOS should NOT automatically control the brightness
595 * level of the LCD when the power changes from AC to DC.
601 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
603 acpi_integer status
= 0;
604 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
605 struct acpi_object_list args
= { 1, &arg0
};
608 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
612 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
613 video
->dos_setting
= arg0
.integer
.value
;
614 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
622 * device : video output device (LCD, CRT, ..)
627 * Find out all required AML methods defined under the output
631 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
633 acpi_handle h_dummy1
;
636 union acpi_object
*obj
= NULL
;
637 struct acpi_video_device_brightness
*br
= NULL
;
640 memset(&device
->cap
, 0, sizeof(device
->cap
));
642 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
643 device
->cap
._ADR
= 1;
645 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
646 device
->cap
._BCL
= 1;
648 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
649 device
->cap
._BCM
= 1;
651 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
652 device
->cap
._BQC
= 1;
653 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
654 device
->cap
._DDC
= 1;
656 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
657 device
->cap
._DCS
= 1;
659 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
660 device
->cap
._DGS
= 1;
662 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
663 device
->cap
._DSS
= 1;
666 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
668 if (obj
->package
.count
>= 2) {
670 union acpi_object
*o
;
672 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
674 printk(KERN_ERR
"can't allocate memory\n");
676 br
->levels
= kmalloc(obj
->package
.count
*
677 sizeof *(br
->levels
), GFP_KERNEL
);
681 for (i
= 0; i
< obj
->package
.count
; i
++) {
682 o
= (union acpi_object
*)&obj
->package
.
684 if (o
->type
!= ACPI_TYPE_INTEGER
) {
685 printk(KERN_ERR PREFIX
"Invalid data\n");
688 br
->levels
[count
] = (u32
) o
->integer
.value
;
690 if (br
->levels
[count
] > max_level
)
691 max_level
= br
->levels
[count
];
700 device
->brightness
= br
;
701 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
702 "found %d brightness levels\n",
709 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available LCD brightness level\n"));
714 if (device
->cap
._BCL
&& device
->cap
._BCM
&& device
->cap
._BQC
&& max_level
> 0){
716 static int count
= 0;
718 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
722 sprintf(name
, "acpi_video%d", count
++);
723 device
->backlight
= backlight_device_register(name
,
724 NULL
, device
, &acpi_backlight_ops
);
725 device
->backlight
->props
.max_brightness
= device
->brightness
->count
-3;
726 device
->backlight
->props
.brightness
= acpi_video_get_brightness(device
->backlight
);
727 backlight_update_status(device
->backlight
);
730 device
->cdev
= thermal_cooling_device_register("LCD",
731 device
->dev
, &video_cooling_ops
);
732 if (IS_ERR(device
->cdev
))
736 printk(KERN_INFO PREFIX
737 "%s is registered as cooling_device%d\n",
738 device
->dev
->dev
.bus_id
, device
->cdev
->id
);
739 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
740 &device
->cdev
->device
.kobj
,
743 printk(KERN_ERR PREFIX
"Create sysfs link\n");
744 result
= sysfs_create_link(&device
->cdev
->device
.kobj
,
745 &device
->dev
->dev
.kobj
,
748 printk(KERN_ERR PREFIX
"Create sysfs link\n");
751 if (device
->cap
._DCS
&& device
->cap
._DSS
){
752 static int count
= 0;
754 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
757 sprintf(name
, "acpi_video%d", count
++);
758 device
->output_dev
= video_output_register(name
,
759 NULL
, device
, &acpi_output_properties
);
767 * device : video output device (VGA)
772 * Find out all required AML methods defined under the video bus device.
775 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
777 acpi_handle h_dummy1
;
779 memset(&video
->cap
, 0, sizeof(video
->cap
));
780 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
783 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
786 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
789 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
792 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
795 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
801 * Check whether the video bus device has required AML method to
802 * support the desired features
805 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
807 acpi_status status
= -ENOENT
;
813 /* Since there is no HID, CID and so on for VGA driver, we have
814 * to check well known required nodes.
817 /* Does this device support video switching? */
818 if (video
->cap
._DOS
) {
819 video
->flags
.multihead
= 1;
823 /* Does this device support retrieving a video ROM? */
824 if (video
->cap
._ROM
) {
825 video
->flags
.rom
= 1;
829 /* Does this device support configuring which video device to POST? */
830 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
831 video
->flags
.post
= 1;
838 /* --------------------------------------------------------------------------
840 -------------------------------------------------------------------------- */
842 static struct proc_dir_entry
*acpi_video_dir
;
846 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
848 struct acpi_video_device
*dev
= seq
->private;
854 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
855 seq_printf(seq
, "type: ");
857 seq_printf(seq
, "CRT\n");
858 else if (dev
->flags
.lcd
)
859 seq_printf(seq
, "LCD\n");
860 else if (dev
->flags
.tvout
)
861 seq_printf(seq
, "TVOUT\n");
862 else if (dev
->flags
.dvi
)
863 seq_printf(seq
, "DVI\n");
865 seq_printf(seq
, "UNKNOWN\n");
867 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
874 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
876 return single_open(file
, acpi_video_device_info_seq_show
,
880 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
883 struct acpi_video_device
*dev
= seq
->private;
890 status
= acpi_video_device_get_state(dev
, &state
);
891 seq_printf(seq
, "state: ");
892 if (ACPI_SUCCESS(status
))
893 seq_printf(seq
, "0x%02lx\n", state
);
895 seq_printf(seq
, "<not supported>\n");
897 status
= acpi_video_device_query(dev
, &state
);
898 seq_printf(seq
, "query: ");
899 if (ACPI_SUCCESS(status
))
900 seq_printf(seq
, "0x%02lx\n", state
);
902 seq_printf(seq
, "<not supported>\n");
909 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
911 return single_open(file
, acpi_video_device_state_seq_show
,
916 acpi_video_device_write_state(struct file
*file
,
917 const char __user
* buffer
,
918 size_t count
, loff_t
* data
)
921 struct seq_file
*m
= file
->private_data
;
922 struct acpi_video_device
*dev
= m
->private;
923 char str
[12] = { 0 };
927 if (!dev
|| count
+ 1 > sizeof str
)
930 if (copy_from_user(str
, buffer
, count
))
934 state
= simple_strtoul(str
, NULL
, 0);
935 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
937 status
= acpi_video_device_set_state(dev
, state
);
946 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
948 struct acpi_video_device
*dev
= seq
->private;
952 if (!dev
|| !dev
->brightness
) {
953 seq_printf(seq
, "<not supported>\n");
957 seq_printf(seq
, "levels: ");
958 for (i
= 0; i
< dev
->brightness
->count
; i
++)
959 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
960 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
966 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
968 return single_open(file
, acpi_video_device_brightness_seq_show
,
973 acpi_video_device_write_brightness(struct file
*file
,
974 const char __user
* buffer
,
975 size_t count
, loff_t
* data
)
977 struct seq_file
*m
= file
->private_data
;
978 struct acpi_video_device
*dev
= m
->private;
980 unsigned int level
= 0;
984 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
987 if (copy_from_user(str
, buffer
, count
))
991 level
= simple_strtoul(str
, NULL
, 0);
996 /* validate through the list of available levels */
997 for (i
= 0; i
< dev
->brightness
->count
; i
++)
998 if (level
== dev
->brightness
->levels
[i
]) {
1000 (acpi_video_device_lcd_set_level(dev
, level
)))
1001 dev
->brightness
->curr
= level
;
1008 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
1010 struct acpi_video_device
*dev
= seq
->private;
1013 union acpi_object
*edid
= NULL
;
1019 status
= acpi_video_device_EDID(dev
, &edid
, 128);
1020 if (ACPI_FAILURE(status
)) {
1021 status
= acpi_video_device_EDID(dev
, &edid
, 256);
1024 if (ACPI_FAILURE(status
)) {
1028 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
1029 for (i
= 0; i
< edid
->buffer
.length
; i
++)
1030 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
1035 seq_printf(seq
, "<not supported>\n");
1043 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
1045 return single_open(file
, acpi_video_device_EDID_seq_show
,
1049 static int acpi_video_device_add_fs(struct acpi_device
*device
)
1051 struct proc_dir_entry
*entry
, *device_dir
;
1052 struct acpi_video_device
*vid_dev
;
1054 vid_dev
= acpi_driver_data(device
);
1058 device_dir
= proc_mkdir(acpi_device_bid(device
),
1059 vid_dev
->video
->dir
);
1063 device_dir
->owner
= THIS_MODULE
;
1066 entry
= create_proc_entry("info", S_IRUGO
, device_dir
);
1068 goto err_remove_dir
;
1070 entry
->proc_fops
= &acpi_video_device_info_fops
;
1071 entry
->data
= acpi_driver_data(device
);
1072 entry
->owner
= THIS_MODULE
;
1075 entry
= create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1078 goto err_remove_info
;
1080 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1081 entry
->proc_fops
= &acpi_video_device_state_fops
;
1082 entry
->data
= acpi_driver_data(device
);
1083 entry
->owner
= THIS_MODULE
;
1085 /* 'brightness' [R/W] */
1086 entry
= create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1089 goto err_remove_state
;
1091 acpi_video_device_brightness_fops
.write
=
1092 acpi_video_device_write_brightness
;
1093 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
1094 entry
->data
= acpi_driver_data(device
);
1095 entry
->owner
= THIS_MODULE
;
1098 entry
= create_proc_entry("EDID", S_IRUGO
, device_dir
);
1100 goto err_remove_brightness
;
1102 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
1103 entry
->data
= acpi_driver_data(device
);
1104 entry
->owner
= THIS_MODULE
;
1106 acpi_device_dir(device
) = device_dir
;
1109 err_remove_brightness
:
1110 remove_proc_entry("brightness", device_dir
);
1112 remove_proc_entry("state", device_dir
);
1114 remove_proc_entry("info", device_dir
);
1116 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1120 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1122 struct acpi_video_device
*vid_dev
;
1123 struct proc_dir_entry
*device_dir
;
1125 vid_dev
= acpi_driver_data(device
);
1126 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1129 device_dir
= acpi_device_dir(device
);
1131 remove_proc_entry("info", device_dir
);
1132 remove_proc_entry("state", device_dir
);
1133 remove_proc_entry("brightness", device_dir
);
1134 remove_proc_entry("EDID", device_dir
);
1135 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1136 acpi_device_dir(device
) = NULL
;
1143 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1145 struct acpi_video_bus
*video
= seq
->private;
1151 seq_printf(seq
, "Switching heads: %s\n",
1152 video
->flags
.multihead
? "yes" : "no");
1153 seq_printf(seq
, "Video ROM: %s\n",
1154 video
->flags
.rom
? "yes" : "no");
1155 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1156 video
->flags
.post
? "yes" : "no");
1162 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1164 return single_open(file
, acpi_video_bus_info_seq_show
,
1168 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1170 struct acpi_video_bus
*video
= seq
->private;
1176 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1177 seq_printf(seq
, "<TODO>\n");
1183 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1185 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1188 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1190 struct acpi_video_bus
*video
= seq
->private;
1191 unsigned long options
;
1198 status
= acpi_video_bus_POST_options(video
, &options
);
1199 if (ACPI_SUCCESS(status
)) {
1200 if (!(options
& 1)) {
1201 printk(KERN_WARNING PREFIX
1202 "The motherboard VGA device is not listed as a possible POST device.\n");
1203 printk(KERN_WARNING PREFIX
1204 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1206 printk("%lx\n", options
);
1207 seq_printf(seq
, "can POST: <integrated video>");
1209 seq_printf(seq
, " <PCI video>");
1211 seq_printf(seq
, " <AGP video>");
1212 seq_putc(seq
, '\n');
1214 seq_printf(seq
, "<not supported>\n");
1220 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1222 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1226 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1228 struct acpi_video_bus
*video
= seq
->private;
1236 status
= acpi_video_bus_get_POST(video
, &id
);
1237 if (!ACPI_SUCCESS(status
)) {
1238 seq_printf(seq
, "<not supported>\n");
1241 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1247 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1249 struct acpi_video_bus
*video
= seq
->private;
1252 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1257 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1259 return single_open(file
, acpi_video_bus_POST_seq_show
,
1263 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1265 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1269 acpi_video_bus_write_POST(struct file
*file
,
1270 const char __user
* buffer
,
1271 size_t count
, loff_t
* data
)
1274 struct seq_file
*m
= file
->private_data
;
1275 struct acpi_video_bus
*video
= m
->private;
1276 char str
[12] = { 0 };
1277 unsigned long opt
, options
;
1280 if (!video
|| count
+ 1 > sizeof str
)
1283 status
= acpi_video_bus_POST_options(video
, &options
);
1284 if (!ACPI_SUCCESS(status
))
1287 if (copy_from_user(str
, buffer
, count
))
1291 opt
= strtoul(str
, NULL
, 0);
1295 /* just in case an OEM 'forgot' the motherboard... */
1298 if (options
& (1ul << opt
)) {
1299 status
= acpi_video_bus_set_POST(video
, opt
);
1300 if (!ACPI_SUCCESS(status
))
1309 acpi_video_bus_write_DOS(struct file
*file
,
1310 const char __user
* buffer
,
1311 size_t count
, loff_t
* data
)
1314 struct seq_file
*m
= file
->private_data
;
1315 struct acpi_video_bus
*video
= m
->private;
1316 char str
[12] = { 0 };
1320 if (!video
|| count
+ 1 > sizeof str
)
1323 if (copy_from_user(str
, buffer
, count
))
1327 opt
= strtoul(str
, NULL
, 0);
1331 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1333 if (!ACPI_SUCCESS(status
))
1339 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1341 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1342 struct proc_dir_entry
*device_dir
;
1343 struct proc_dir_entry
*entry
;
1345 device_dir
= proc_mkdir(acpi_device_bid(device
), acpi_video_dir
);
1349 device_dir
->owner
= THIS_MODULE
;
1352 entry
= create_proc_entry("info", S_IRUGO
, device_dir
);
1354 goto err_remove_dir
;
1356 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1357 entry
->data
= acpi_driver_data(device
);
1358 entry
->owner
= THIS_MODULE
;
1361 entry
= create_proc_entry("ROM", S_IRUGO
, device_dir
);
1363 goto err_remove_info
;
1365 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1366 entry
->data
= acpi_driver_data(device
);
1367 entry
->owner
= THIS_MODULE
;
1369 /* 'POST_info' [R] */
1370 entry
= create_proc_entry("POST_info", S_IRUGO
, device_dir
);
1372 goto err_remove_rom
;
1374 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1375 entry
->data
= acpi_driver_data(device
);
1376 entry
->owner
= THIS_MODULE
;
1379 entry
= create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IWUSR
,
1382 goto err_remove_post_info
;
1384 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1385 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1386 entry
->data
= acpi_driver_data(device
);
1387 entry
->owner
= THIS_MODULE
;
1390 entry
= create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IWUSR
,
1393 goto err_remove_post
;
1395 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1396 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1397 entry
->data
= acpi_driver_data(device
);
1398 entry
->owner
= THIS_MODULE
;
1400 video
->dir
= acpi_device_dir(device
) = device_dir
;
1404 remove_proc_entry("POST", device_dir
);
1405 err_remove_post_info
:
1406 remove_proc_entry("POST_info", device_dir
);
1408 remove_proc_entry("ROM", device_dir
);
1410 remove_proc_entry("info", device_dir
);
1412 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1416 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1418 struct proc_dir_entry
*device_dir
= acpi_device_dir(device
);
1421 remove_proc_entry("info", device_dir
);
1422 remove_proc_entry("ROM", device_dir
);
1423 remove_proc_entry("POST_info", device_dir
);
1424 remove_proc_entry("POST", device_dir
);
1425 remove_proc_entry("DOS", device_dir
);
1426 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1427 acpi_device_dir(device
) = NULL
;
1433 /* --------------------------------------------------------------------------
1435 -------------------------------------------------------------------------- */
1437 /* device interface */
1438 static struct acpi_video_device_attrib
*
1439 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1441 struct acpi_video_enumerated_device
*ids
;
1444 for (i
= 0; i
< video
->attached_count
; i
++) {
1445 ids
= &video
->attached_array
[i
];
1446 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1447 return &ids
->value
.attrib
;
1454 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1455 struct acpi_video_bus
*video
)
1457 unsigned long device_id
;
1459 struct acpi_video_device
*data
;
1460 struct acpi_video_device_attrib
* attribute
;
1462 if (!device
|| !video
)
1466 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1467 if (ACPI_SUCCESS(status
)) {
1469 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1473 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1474 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1475 acpi_driver_data(device
) = data
;
1477 data
->device_id
= device_id
;
1478 data
->video
= video
;
1481 attribute
= acpi_video_get_device_attr(video
, device_id
);
1483 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1484 switch (attribute
->display_type
) {
1485 case ACPI_VIDEO_DISPLAY_CRT
:
1486 data
->flags
.crt
= 1;
1488 case ACPI_VIDEO_DISPLAY_TV
:
1489 data
->flags
.tvout
= 1;
1491 case ACPI_VIDEO_DISPLAY_DVI
:
1492 data
->flags
.dvi
= 1;
1494 case ACPI_VIDEO_DISPLAY_LCD
:
1495 data
->flags
.lcd
= 1;
1498 data
->flags
.unknown
= 1;
1501 if(attribute
->bios_can_detect
)
1502 data
->flags
.bios
= 1;
1504 data
->flags
.unknown
= 1;
1506 acpi_video_device_bind(video
, data
);
1507 acpi_video_device_find_cap(data
);
1509 status
= acpi_install_notify_handler(device
->handle
,
1511 acpi_video_device_notify
,
1513 if (ACPI_FAILURE(status
)) {
1514 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1515 "Error installing notify handler\n"));
1516 if(data
->brightness
)
1517 kfree(data
->brightness
->levels
);
1518 kfree(data
->brightness
);
1523 mutex_lock(&video
->device_list_lock
);
1524 list_add_tail(&data
->entry
, &video
->video_device_list
);
1525 mutex_unlock(&video
->device_list_lock
);
1527 acpi_video_device_add_fs(device
);
1537 * video : video bus device
1542 * Enumerate the video device list of the video bus,
1543 * bind the ids with the corresponding video devices
1544 * under the video bus.
1547 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1549 struct acpi_video_device
*dev
;
1551 mutex_lock(&video
->device_list_lock
);
1553 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1554 acpi_video_device_bind(video
, dev
);
1556 mutex_unlock(&video
->device_list_lock
);
1561 * video : video bus device
1562 * device : video output device under the video
1568 * Bind the ids with the corresponding video devices
1569 * under the video bus.
1573 acpi_video_device_bind(struct acpi_video_bus
*video
,
1574 struct acpi_video_device
*device
)
1576 struct acpi_video_enumerated_device
*ids
;
1579 for (i
= 0; i
< video
->attached_count
; i
++) {
1580 ids
= &video
->attached_array
[i
];
1581 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1582 ids
->bind_info
= device
;
1583 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1590 * video : video bus device
1595 * Call _DOD to enumerate all devices attached to display adapter
1599 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1604 struct acpi_video_enumerated_device
*active_list
;
1605 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1606 union acpi_object
*dod
= NULL
;
1607 union acpi_object
*obj
;
1609 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1610 if (!ACPI_SUCCESS(status
)) {
1611 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1615 dod
= buffer
.pointer
;
1616 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1617 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1622 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1623 dod
->package
.count
));
1625 active_list
= kcalloc(1 + dod
->package
.count
,
1626 sizeof(struct acpi_video_enumerated_device
),
1634 for (i
= 0; i
< dod
->package
.count
; i
++) {
1635 obj
= &dod
->package
.elements
[i
];
1637 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1638 printk(KERN_ERR PREFIX
1639 "Invalid _DOD data in element %d\n", i
);
1643 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1644 active_list
[count
].bind_info
= NULL
;
1645 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1646 (int)obj
->integer
.value
));
1650 kfree(video
->attached_array
);
1652 video
->attached_array
= active_list
;
1653 video
->attached_count
= count
;
1656 kfree(buffer
.pointer
);
1661 acpi_video_get_next_level(struct acpi_video_device
*device
,
1662 u32 level_current
, u32 event
)
1664 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1665 max
= max_below
= 0;
1666 min
= min_above
= 255;
1667 /* Find closest level to level_current */
1668 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1669 l
= device
->brightness
->levels
[i
];
1670 if (abs(l
- level_current
) < abs(delta
)) {
1671 delta
= l
- level_current
;
1676 /* Ajust level_current to closest available level */
1677 level_current
+= delta
;
1678 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1679 l
= device
->brightness
->levels
[i
];
1684 if (l
< min_above
&& l
> level_current
)
1686 if (l
> max_below
&& l
< level_current
)
1691 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1692 return (level_current
< max
) ? min_above
: min
;
1693 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1694 return (level_current
< max
) ? min_above
: max
;
1695 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1696 return (level_current
> min
) ? max_below
: min
;
1697 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1698 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1701 return level_current
;
1706 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1708 unsigned long level_current
, level_next
;
1709 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1710 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1711 acpi_video_device_lcd_set_level(device
, level_next
);
1715 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1716 struct acpi_device
*device
)
1719 struct acpi_device
*dev
;
1721 acpi_video_device_enumerate(video
);
1723 list_for_each_entry(dev
, &device
->children
, node
) {
1725 status
= acpi_video_bus_get_one_device(dev
, video
);
1726 if (ACPI_FAILURE(status
)) {
1727 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1734 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1737 struct acpi_video_bus
*video
;
1740 if (!device
|| !device
->video
)
1743 video
= device
->video
;
1745 acpi_video_device_remove_fs(device
->dev
);
1747 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1749 acpi_video_device_notify
);
1750 backlight_device_unregister(device
->backlight
);
1752 sysfs_remove_link(&device
->dev
->dev
.kobj
,
1754 sysfs_remove_link(&device
->cdev
->device
.kobj
,
1756 thermal_cooling_device_unregister(device
->cdev
);
1757 device
->cdev
= NULL
;
1759 video_output_unregister(device
->output_dev
);
1764 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1767 struct acpi_video_device
*dev
, *next
;
1769 mutex_lock(&video
->device_list_lock
);
1771 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1773 status
= acpi_video_bus_put_one_device(dev
);
1774 if (ACPI_FAILURE(status
))
1775 printk(KERN_WARNING PREFIX
1776 "hhuuhhuu bug in acpi video driver.\n");
1778 if (dev
->brightness
) {
1779 kfree(dev
->brightness
->levels
);
1780 kfree(dev
->brightness
);
1782 list_del(&dev
->entry
);
1786 mutex_unlock(&video
->device_list_lock
);
1791 /* acpi_video interface */
1793 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1795 return acpi_video_bus_DOS(video
, 0, 0);
1798 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1800 return acpi_video_bus_DOS(video
, 0, 1);
1803 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1805 struct acpi_video_bus
*video
= data
;
1806 struct acpi_device
*device
= NULL
;
1807 struct input_dev
*input
;
1813 device
= video
->device
;
1814 input
= video
->input
;
1817 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1818 * most likely via hotkey. */
1819 acpi_bus_generate_proc_event(device
, event
, 0);
1820 keycode
= KEY_SWITCHVIDEOMODE
;
1823 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1825 acpi_video_device_enumerate(video
);
1826 acpi_video_device_rebind(video
);
1827 acpi_bus_generate_proc_event(device
, event
, 0);
1828 keycode
= KEY_SWITCHVIDEOMODE
;
1831 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1832 acpi_bus_generate_proc_event(device
, event
, 0);
1833 keycode
= KEY_SWITCHVIDEOMODE
;
1835 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1836 acpi_bus_generate_proc_event(device
, event
, 0);
1837 keycode
= KEY_VIDEO_NEXT
;
1839 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1840 acpi_bus_generate_proc_event(device
, event
, 0);
1841 keycode
= KEY_VIDEO_PREV
;
1845 keycode
= KEY_UNKNOWN
;
1846 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1847 "Unsupported event [0x%x]\n", event
));
1851 acpi_notifier_call_chain(device
, event
, 0);
1852 input_report_key(input
, keycode
, 1);
1854 input_report_key(input
, keycode
, 0);
1860 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1862 struct acpi_video_device
*video_device
= data
;
1863 struct acpi_device
*device
= NULL
;
1864 struct acpi_video_bus
*bus
;
1865 struct input_dev
*input
;
1871 device
= video_device
->dev
;
1872 bus
= video_device
->video
;
1876 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1877 if (brightness_switch_enabled
)
1878 acpi_video_switch_brightness(video_device
, event
);
1879 acpi_bus_generate_proc_event(device
, event
, 0);
1880 keycode
= KEY_BRIGHTNESS_CYCLE
;
1882 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1883 if (brightness_switch_enabled
)
1884 acpi_video_switch_brightness(video_device
, event
);
1885 acpi_bus_generate_proc_event(device
, event
, 0);
1886 keycode
= KEY_BRIGHTNESSUP
;
1888 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1889 if (brightness_switch_enabled
)
1890 acpi_video_switch_brightness(video_device
, event
);
1891 acpi_bus_generate_proc_event(device
, event
, 0);
1892 keycode
= KEY_BRIGHTNESSDOWN
;
1894 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1895 if (brightness_switch_enabled
)
1896 acpi_video_switch_brightness(video_device
, event
);
1897 acpi_bus_generate_proc_event(device
, event
, 0);
1898 keycode
= KEY_BRIGHTNESS_ZERO
;
1900 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1901 if (brightness_switch_enabled
)
1902 acpi_video_switch_brightness(video_device
, event
);
1903 acpi_bus_generate_proc_event(device
, event
, 0);
1904 keycode
= KEY_DISPLAY_OFF
;
1907 keycode
= KEY_UNKNOWN
;
1908 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1909 "Unsupported event [0x%x]\n", event
));
1913 acpi_notifier_call_chain(device
, event
, 0);
1914 input_report_key(input
, keycode
, 1);
1916 input_report_key(input
, keycode
, 0);
1922 static int instance
;
1923 static int acpi_video_resume(struct acpi_device
*device
)
1925 struct acpi_video_bus
*video
;
1926 struct acpi_video_device
*video_device
;
1929 if (!device
|| !acpi_driver_data(device
))
1932 video
= acpi_driver_data(device
);
1934 for (i
= 0; i
< video
->attached_count
; i
++) {
1935 video_device
= video
->attached_array
[i
].bind_info
;
1936 if (video_device
&& video_device
->backlight
)
1937 acpi_video_set_brightness(video_device
->backlight
);
1942 static int acpi_video_bus_add(struct acpi_device
*device
)
1945 struct acpi_video_bus
*video
;
1946 struct input_dev
*input
;
1949 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1953 /* a hack to fix the duplicate name "VID" problem on T61 */
1954 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
1956 device
->pnp
.bus_id
[3] = '0' + instance
;
1960 video
->device
= device
;
1961 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1962 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1963 acpi_driver_data(device
) = video
;
1965 acpi_video_bus_find_cap(video
);
1966 error
= acpi_video_bus_check(video
);
1968 goto err_free_video
;
1970 error
= acpi_video_bus_add_fs(device
);
1972 goto err_free_video
;
1974 mutex_init(&video
->device_list_lock
);
1975 INIT_LIST_HEAD(&video
->video_device_list
);
1977 acpi_video_bus_get_devices(video
, device
);
1978 acpi_video_bus_start_devices(video
);
1980 status
= acpi_install_notify_handler(device
->handle
,
1982 acpi_video_bus_notify
, video
);
1983 if (ACPI_FAILURE(status
)) {
1984 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1985 "Error installing notify handler\n"));
1987 goto err_stop_video
;
1990 video
->input
= input
= input_allocate_device();
1993 goto err_uninstall_notify
;
1996 snprintf(video
->phys
, sizeof(video
->phys
),
1997 "%s/video/input0", acpi_device_hid(video
->device
));
1999 input
->name
= acpi_device_name(video
->device
);
2000 input
->phys
= video
->phys
;
2001 input
->id
.bustype
= BUS_HOST
;
2002 input
->id
.product
= 0x06;
2003 input
->dev
.parent
= &device
->dev
;
2004 input
->evbit
[0] = BIT(EV_KEY
);
2005 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2006 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2007 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2008 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2009 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2010 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2011 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2012 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2013 set_bit(KEY_UNKNOWN
, input
->keybit
);
2015 error
= input_register_device(input
);
2017 goto err_free_input_dev
;
2019 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2020 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2021 video
->flags
.multihead
? "yes" : "no",
2022 video
->flags
.rom
? "yes" : "no",
2023 video
->flags
.post
? "yes" : "no");
2028 input_free_device(input
);
2029 err_uninstall_notify
:
2030 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
2031 acpi_video_bus_notify
);
2033 acpi_video_bus_stop_devices(video
);
2034 acpi_video_bus_put_devices(video
);
2035 kfree(video
->attached_array
);
2036 acpi_video_bus_remove_fs(device
);
2039 acpi_driver_data(device
) = NULL
;
2044 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2046 acpi_status status
= 0;
2047 struct acpi_video_bus
*video
= NULL
;
2050 if (!device
|| !acpi_driver_data(device
))
2053 video
= acpi_driver_data(device
);
2055 acpi_video_bus_stop_devices(video
);
2057 status
= acpi_remove_notify_handler(video
->device
->handle
,
2059 acpi_video_bus_notify
);
2061 acpi_video_bus_put_devices(video
);
2062 acpi_video_bus_remove_fs(device
);
2064 input_unregister_device(video
->input
);
2065 kfree(video
->attached_array
);
2071 static int __init
acpi_video_init(void)
2077 acpi_dbg_level = 0xFFFFFFFF;
2078 acpi_dbg_layer = 0x08000000;
2081 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2082 if (!acpi_video_dir
)
2084 acpi_video_dir
->owner
= THIS_MODULE
;
2086 result
= acpi_bus_register_driver(&acpi_video_bus
);
2088 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2095 static void __exit
acpi_video_exit(void)
2098 acpi_bus_unregister_driver(&acpi_video_bus
);
2100 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2105 module_init(acpi_video_init
);
2106 module_exit(acpi_video_exit
);