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/video_output.h>
38 #include <asm/uaccess.h>
40 #include <acpi/acpi_bus.h>
41 #include <acpi/acpi_drivers.h>
43 #define ACPI_VIDEO_COMPONENT 0x08000000
44 #define ACPI_VIDEO_CLASS "video"
45 #define ACPI_VIDEO_BUS_NAME "Video Bus"
46 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
47 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
49 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
59 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60 #define ACPI_VIDEO_HEAD_END (~0u)
61 #define MAX_NAME_LEN 20
63 #define ACPI_VIDEO_DISPLAY_CRT 1
64 #define ACPI_VIDEO_DISPLAY_TV 2
65 #define ACPI_VIDEO_DISPLAY_DVI 3
66 #define ACPI_VIDEO_DISPLAY_LCD 4
68 #define _COMPONENT ACPI_VIDEO_COMPONENT
69 ACPI_MODULE_NAME("video");
71 MODULE_AUTHOR("Bruno Ducrot");
72 MODULE_DESCRIPTION("ACPI Video Driver");
73 MODULE_LICENSE("GPL");
75 static int acpi_video_bus_add(struct acpi_device
*device
);
76 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
78 static const struct acpi_device_id video_device_ids
[] = {
82 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
84 static struct acpi_driver acpi_video_bus
= {
86 .class = ACPI_VIDEO_CLASS
,
87 .ids
= video_device_ids
,
89 .add
= acpi_video_bus_add
,
90 .remove
= acpi_video_bus_remove
,
94 struct acpi_video_bus_flags
{
95 u8 multihead
:1; /* can switch video heads */
96 u8 rom
:1; /* can retrieve a video rom */
97 u8 post
:1; /* can configure the head to */
101 struct acpi_video_bus_cap
{
102 u8 _DOS
:1; /*Enable/Disable output switching */
103 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
104 u8 _ROM
:1; /*Get ROM Data */
105 u8 _GPD
:1; /*Get POST Device */
106 u8 _SPD
:1; /*Set POST Device */
107 u8 _VPO
:1; /*Video POST Options */
111 struct acpi_video_device_attrib
{
112 u32 display_index
:4; /* A zero-based instance of the Display */
113 u32 display_port_attachment
:4; /*This field differentiates the display type */
114 u32 display_type
:4; /*Describe the specific type in use */
115 u32 vendor_specific
:4; /*Chipset Vendor Specific */
116 u32 bios_can_detect
:1; /*BIOS can detect the device */
117 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
119 u32 pipe_id
:3; /*For VGA multiple-head devices. */
120 u32 reserved
:10; /*Must be 0 */
121 u32 device_id_scheme
:1; /*Device ID Scheme */
124 struct acpi_video_enumerated_device
{
127 struct acpi_video_device_attrib attrib
;
129 struct acpi_video_device
*bind_info
;
132 struct acpi_video_bus
{
133 struct acpi_device
*device
;
135 struct acpi_video_enumerated_device
*attached_array
;
137 struct acpi_video_bus_cap cap
;
138 struct acpi_video_bus_flags flags
;
139 struct list_head video_device_list
;
140 struct mutex device_list_lock
; /* protects video_device_list */
141 struct proc_dir_entry
*dir
;
142 struct input_dev
*input
;
143 char phys
[32]; /* for input device */
146 struct acpi_video_device_flags
{
156 struct acpi_video_device_cap
{
157 u8 _ADR
:1; /*Return the unique ID */
158 u8 _BCL
:1; /*Query list of brightness control levels supported */
159 u8 _BCM
:1; /*Set the brightness level */
160 u8 _BQC
:1; /* Get current brightness level */
161 u8 _DDC
:1; /*Return the EDID for this device */
162 u8 _DCS
:1; /*Return status of output device */
163 u8 _DGS
:1; /*Query graphics state */
164 u8 _DSS
:1; /*Device state set */
167 struct acpi_video_device_brightness
{
173 struct acpi_video_device
{
174 unsigned long device_id
;
175 struct acpi_video_device_flags flags
;
176 struct acpi_video_device_cap cap
;
177 struct list_head entry
;
178 struct acpi_video_bus
*video
;
179 struct acpi_device
*dev
;
180 struct acpi_video_device_brightness
*brightness
;
181 struct backlight_device
*backlight
;
182 struct output_device
*output_dev
;
186 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
187 static struct file_operations acpi_video_bus_info_fops
= {
188 .open
= acpi_video_bus_info_open_fs
,
191 .release
= single_release
,
194 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
195 static struct file_operations acpi_video_bus_ROM_fops
= {
196 .open
= acpi_video_bus_ROM_open_fs
,
199 .release
= single_release
,
202 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
204 static struct file_operations acpi_video_bus_POST_info_fops
= {
205 .open
= acpi_video_bus_POST_info_open_fs
,
208 .release
= single_release
,
211 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
212 static struct file_operations acpi_video_bus_POST_fops
= {
213 .open
= acpi_video_bus_POST_open_fs
,
216 .release
= single_release
,
219 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
220 static struct file_operations acpi_video_bus_DOS_fops
= {
221 .open
= acpi_video_bus_DOS_open_fs
,
224 .release
= single_release
,
228 static int acpi_video_device_info_open_fs(struct inode
*inode
,
230 static struct file_operations acpi_video_device_info_fops
= {
231 .open
= acpi_video_device_info_open_fs
,
234 .release
= single_release
,
237 static int acpi_video_device_state_open_fs(struct inode
*inode
,
239 static struct file_operations acpi_video_device_state_fops
= {
240 .open
= acpi_video_device_state_open_fs
,
243 .release
= single_release
,
246 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
248 static struct file_operations acpi_video_device_brightness_fops
= {
249 .open
= acpi_video_device_brightness_open_fs
,
252 .release
= single_release
,
255 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
257 static struct file_operations acpi_video_device_EDID_fops
= {
258 .open
= acpi_video_device_EDID_open_fs
,
261 .release
= single_release
,
264 static char device_decode
[][30] = {
265 "motherboard VGA device",
271 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
272 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
273 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
274 struct acpi_video_device
*device
);
275 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
276 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
);
277 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
279 static int acpi_video_device_lcd_get_level_current(
280 struct acpi_video_device
*device
,
281 unsigned long *level
);
282 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
283 u32 level_current
, u32 event
);
284 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
286 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
287 unsigned long *state
);
288 static int acpi_video_output_get(struct output_device
*od
);
289 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
291 /*backlight device sysfs support*/
292 static int acpi_video_get_brightness(struct backlight_device
*bd
)
294 unsigned long cur_level
;
296 struct acpi_video_device
*vd
=
297 (struct acpi_video_device
*)bl_get_data(bd
);
298 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
299 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
300 if (vd
->brightness
->levels
[i
] == cur_level
)
301 /* The first two entries are special - see page 575
302 of the ACPI spec 3.0 */
308 static int acpi_video_set_brightness(struct backlight_device
*bd
)
310 int request_level
= bd
->props
.brightness
+2;
311 struct acpi_video_device
*vd
=
312 (struct acpi_video_device
*)bl_get_data(bd
);
313 acpi_video_device_lcd_set_level(vd
,
314 vd
->brightness
->levels
[request_level
]);
318 static struct backlight_ops acpi_backlight_ops
= {
319 .get_brightness
= acpi_video_get_brightness
,
320 .update_status
= acpi_video_set_brightness
,
323 /*video output device sysfs support*/
324 static int acpi_video_output_get(struct output_device
*od
)
327 struct acpi_video_device
*vd
=
328 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
329 acpi_video_device_get_state(vd
, &state
);
333 static int acpi_video_output_set(struct output_device
*od
)
335 unsigned long state
= od
->request_state
;
336 struct acpi_video_device
*vd
=
337 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
338 return acpi_video_device_set_state(vd
, state
);
341 static struct output_properties acpi_output_properties
= {
342 .set_state
= acpi_video_output_set
,
343 .get_status
= acpi_video_output_get
,
345 /* --------------------------------------------------------------------------
347 -------------------------------------------------------------------------- */
352 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
356 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
362 acpi_video_device_get_state(struct acpi_video_device
*device
,
363 unsigned long *state
)
367 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
373 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
376 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
377 struct acpi_object_list args
= { 1, &arg0
};
381 arg0
.integer
.value
= state
;
382 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
388 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
389 union acpi_object
**levels
)
392 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
393 union acpi_object
*obj
;
398 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
399 if (!ACPI_SUCCESS(status
))
401 obj
= (union acpi_object
*)buffer
.pointer
;
402 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
403 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
413 kfree(buffer
.pointer
);
419 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
422 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
423 struct acpi_object_list args
= { 1, &arg0
};
426 arg0
.integer
.value
= level
;
428 if (device
->cap
._BCM
)
429 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
431 device
->brightness
->curr
= level
;
436 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
437 unsigned long *level
)
439 if (device
->cap
._BQC
)
440 return acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
,
442 *level
= device
->brightness
->curr
;
447 acpi_video_device_EDID(struct acpi_video_device
*device
,
448 union acpi_object
**edid
, ssize_t length
)
451 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
452 union acpi_object
*obj
;
453 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
454 struct acpi_object_list args
= { 1, &arg0
};
462 arg0
.integer
.value
= 1;
463 else if (length
== 256)
464 arg0
.integer
.value
= 2;
468 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
469 if (ACPI_FAILURE(status
))
472 obj
= buffer
.pointer
;
474 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
477 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
488 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
492 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
493 struct acpi_object_list args
= { 1, &arg0
};
496 arg0
.integer
.value
= option
;
498 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
499 if (ACPI_SUCCESS(status
))
500 status
= tmp
? (-EINVAL
) : (AE_OK
);
506 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
510 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
516 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
517 unsigned long *options
)
521 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
529 * video : video bus device pointer
531 * 0. The system BIOS should NOT automatically switch(toggle)
532 * the active display output.
533 * 1. The system BIOS should automatically switch (toggle) the
534 * active display output. No switch event.
535 * 2. The _DGS value should be locked.
536 * 3. The system BIOS should not automatically switch (toggle) the
537 * active display output, but instead generate the display switch
540 * 0. The system BIOS should automatically control the brightness level
541 * of the LCD when the power changes from AC to DC
542 * 1. The system BIOS should NOT automatically control the brightness
543 * level of the LCD when the power changes from AC to DC.
549 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
551 acpi_integer status
= 0;
552 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
553 struct acpi_object_list args
= { 1, &arg0
};
556 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
560 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
561 video
->dos_setting
= arg0
.integer
.value
;
562 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
570 * device : video output device (LCD, CRT, ..)
575 * Find out all required AML methods defined under the output
579 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
581 acpi_handle h_dummy1
;
584 union acpi_object
*obj
= NULL
;
585 struct acpi_video_device_brightness
*br
= NULL
;
588 memset(&device
->cap
, 0, sizeof(device
->cap
));
590 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
591 device
->cap
._ADR
= 1;
593 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
594 device
->cap
._BCL
= 1;
596 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
597 device
->cap
._BCM
= 1;
599 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
600 device
->cap
._BQC
= 1;
601 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
602 device
->cap
._DDC
= 1;
604 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
605 device
->cap
._DCS
= 1;
607 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
608 device
->cap
._DGS
= 1;
610 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
611 device
->cap
._DSS
= 1;
614 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
616 if (obj
->package
.count
>= 2) {
618 union acpi_object
*o
;
620 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
622 printk(KERN_ERR
"can't allocate memory\n");
624 br
->levels
= kmalloc(obj
->package
.count
*
625 sizeof *(br
->levels
), GFP_KERNEL
);
629 for (i
= 0; i
< obj
->package
.count
; i
++) {
630 o
= (union acpi_object
*)&obj
->package
.
632 if (o
->type
!= ACPI_TYPE_INTEGER
) {
633 printk(KERN_ERR PREFIX
"Invalid data\n");
636 br
->levels
[count
] = (u32
) o
->integer
.value
;
638 if (br
->levels
[count
] > max_level
)
639 max_level
= br
->levels
[count
];
648 device
->brightness
= br
;
649 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
650 "found %d brightness levels\n",
657 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available LCD brightness level\n"));
662 if (device
->cap
._BCL
&& device
->cap
._BCM
&& device
->cap
._BQC
&& max_level
> 0){
663 static int count
= 0;
665 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
669 sprintf(name
, "acpi_video%d", count
++);
670 device
->backlight
= backlight_device_register(name
,
671 NULL
, device
, &acpi_backlight_ops
);
672 device
->backlight
->props
.max_brightness
= device
->brightness
->count
-3;
673 device
->backlight
->props
.brightness
= acpi_video_get_brightness(device
->backlight
);
674 backlight_update_status(device
->backlight
);
678 if (device
->cap
._DCS
&& device
->cap
._DSS
){
679 static int count
= 0;
681 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
684 sprintf(name
, "acpi_video%d", count
++);
685 device
->output_dev
= video_output_register(name
,
686 NULL
, device
, &acpi_output_properties
);
694 * device : video output device (VGA)
699 * Find out all required AML methods defined under the video bus device.
702 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
704 acpi_handle h_dummy1
;
706 memset(&video
->cap
, 0, sizeof(video
->cap
));
707 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
710 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
713 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
716 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
719 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
722 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
728 * Check whether the video bus device has required AML method to
729 * support the desired features
732 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
734 acpi_status status
= -ENOENT
;
740 /* Since there is no HID, CID and so on for VGA driver, we have
741 * to check well known required nodes.
744 /* Does this device support video switching? */
745 if (video
->cap
._DOS
) {
746 video
->flags
.multihead
= 1;
750 /* Does this device support retrieving a video ROM? */
751 if (video
->cap
._ROM
) {
752 video
->flags
.rom
= 1;
756 /* Does this device support configuring which video device to POST? */
757 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
758 video
->flags
.post
= 1;
765 /* --------------------------------------------------------------------------
767 -------------------------------------------------------------------------- */
769 static struct proc_dir_entry
*acpi_video_dir
;
773 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
775 struct acpi_video_device
*dev
= seq
->private;
781 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
782 seq_printf(seq
, "type: ");
784 seq_printf(seq
, "CRT\n");
785 else if (dev
->flags
.lcd
)
786 seq_printf(seq
, "LCD\n");
787 else if (dev
->flags
.tvout
)
788 seq_printf(seq
, "TVOUT\n");
789 else if (dev
->flags
.dvi
)
790 seq_printf(seq
, "DVI\n");
792 seq_printf(seq
, "UNKNOWN\n");
794 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
801 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
803 return single_open(file
, acpi_video_device_info_seq_show
,
807 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
810 struct acpi_video_device
*dev
= seq
->private;
817 status
= acpi_video_device_get_state(dev
, &state
);
818 seq_printf(seq
, "state: ");
819 if (ACPI_SUCCESS(status
))
820 seq_printf(seq
, "0x%02lx\n", state
);
822 seq_printf(seq
, "<not supported>\n");
824 status
= acpi_video_device_query(dev
, &state
);
825 seq_printf(seq
, "query: ");
826 if (ACPI_SUCCESS(status
))
827 seq_printf(seq
, "0x%02lx\n", state
);
829 seq_printf(seq
, "<not supported>\n");
836 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
838 return single_open(file
, acpi_video_device_state_seq_show
,
843 acpi_video_device_write_state(struct file
*file
,
844 const char __user
* buffer
,
845 size_t count
, loff_t
* data
)
848 struct seq_file
*m
= file
->private_data
;
849 struct acpi_video_device
*dev
= m
->private;
850 char str
[12] = { 0 };
854 if (!dev
|| count
+ 1 > sizeof str
)
857 if (copy_from_user(str
, buffer
, count
))
861 state
= simple_strtoul(str
, NULL
, 0);
862 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
864 status
= acpi_video_device_set_state(dev
, state
);
873 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
875 struct acpi_video_device
*dev
= seq
->private;
879 if (!dev
|| !dev
->brightness
) {
880 seq_printf(seq
, "<not supported>\n");
884 seq_printf(seq
, "levels: ");
885 for (i
= 0; i
< dev
->brightness
->count
; i
++)
886 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
887 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
893 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
895 return single_open(file
, acpi_video_device_brightness_seq_show
,
900 acpi_video_device_write_brightness(struct file
*file
,
901 const char __user
* buffer
,
902 size_t count
, loff_t
* data
)
904 struct seq_file
*m
= file
->private_data
;
905 struct acpi_video_device
*dev
= m
->private;
907 unsigned int level
= 0;
911 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
914 if (copy_from_user(str
, buffer
, count
))
918 level
= simple_strtoul(str
, NULL
, 0);
923 /* validate through the list of available levels */
924 for (i
= 0; i
< dev
->brightness
->count
; i
++)
925 if (level
== dev
->brightness
->levels
[i
]) {
927 (acpi_video_device_lcd_set_level(dev
, level
)))
928 dev
->brightness
->curr
= level
;
935 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
937 struct acpi_video_device
*dev
= seq
->private;
940 union acpi_object
*edid
= NULL
;
946 status
= acpi_video_device_EDID(dev
, &edid
, 128);
947 if (ACPI_FAILURE(status
)) {
948 status
= acpi_video_device_EDID(dev
, &edid
, 256);
951 if (ACPI_FAILURE(status
)) {
955 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
956 for (i
= 0; i
< edid
->buffer
.length
; i
++)
957 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
962 seq_printf(seq
, "<not supported>\n");
970 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
972 return single_open(file
, acpi_video_device_EDID_seq_show
,
976 static int acpi_video_device_add_fs(struct acpi_device
*device
)
978 struct proc_dir_entry
*entry
= NULL
;
979 struct acpi_video_device
*vid_dev
;
985 vid_dev
= acpi_driver_data(device
);
989 if (!acpi_device_dir(device
)) {
990 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
991 vid_dev
->video
->dir
);
992 if (!acpi_device_dir(device
))
994 acpi_device_dir(device
)->owner
= THIS_MODULE
;
998 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1002 entry
->proc_fops
= &acpi_video_device_info_fops
;
1003 entry
->data
= acpi_driver_data(device
);
1004 entry
->owner
= THIS_MODULE
;
1009 create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1010 acpi_device_dir(device
));
1014 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1015 entry
->proc_fops
= &acpi_video_device_state_fops
;
1016 entry
->data
= acpi_driver_data(device
);
1017 entry
->owner
= THIS_MODULE
;
1020 /* 'brightness' [R/W] */
1022 create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1023 acpi_device_dir(device
));
1027 acpi_video_device_brightness_fops
.write
= acpi_video_device_write_brightness
;
1028 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
1029 entry
->data
= acpi_driver_data(device
);
1030 entry
->owner
= THIS_MODULE
;
1034 entry
= create_proc_entry("EDID", S_IRUGO
, acpi_device_dir(device
));
1038 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
1039 entry
->data
= acpi_driver_data(device
);
1040 entry
->owner
= THIS_MODULE
;
1046 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1048 struct acpi_video_device
*vid_dev
;
1050 vid_dev
= acpi_driver_data(device
);
1051 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1054 if (acpi_device_dir(device
)) {
1055 remove_proc_entry("info", acpi_device_dir(device
));
1056 remove_proc_entry("state", acpi_device_dir(device
));
1057 remove_proc_entry("brightness", acpi_device_dir(device
));
1058 remove_proc_entry("EDID", acpi_device_dir(device
));
1059 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1060 acpi_device_dir(device
) = NULL
;
1067 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1069 struct acpi_video_bus
*video
= seq
->private;
1075 seq_printf(seq
, "Switching heads: %s\n",
1076 video
->flags
.multihead
? "yes" : "no");
1077 seq_printf(seq
, "Video ROM: %s\n",
1078 video
->flags
.rom
? "yes" : "no");
1079 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1080 video
->flags
.post
? "yes" : "no");
1086 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1088 return single_open(file
, acpi_video_bus_info_seq_show
,
1092 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1094 struct acpi_video_bus
*video
= seq
->private;
1100 printk(KERN_INFO PREFIX
"Please implement %s\n", __FUNCTION__
);
1101 seq_printf(seq
, "<TODO>\n");
1107 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1109 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1112 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1114 struct acpi_video_bus
*video
= seq
->private;
1115 unsigned long options
;
1122 status
= acpi_video_bus_POST_options(video
, &options
);
1123 if (ACPI_SUCCESS(status
)) {
1124 if (!(options
& 1)) {
1125 printk(KERN_WARNING PREFIX
1126 "The motherboard VGA device is not listed as a possible POST device.\n");
1127 printk(KERN_WARNING PREFIX
1128 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1130 printk("%lx\n", options
);
1131 seq_printf(seq
, "can POST: <integrated video>");
1133 seq_printf(seq
, " <PCI video>");
1135 seq_printf(seq
, " <AGP video>");
1136 seq_putc(seq
, '\n');
1138 seq_printf(seq
, "<not supported>\n");
1144 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1146 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1150 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1152 struct acpi_video_bus
*video
= seq
->private;
1160 status
= acpi_video_bus_get_POST(video
, &id
);
1161 if (!ACPI_SUCCESS(status
)) {
1162 seq_printf(seq
, "<not supported>\n");
1165 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1171 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1173 struct acpi_video_bus
*video
= seq
->private;
1176 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1181 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1183 return single_open(file
, acpi_video_bus_POST_seq_show
,
1187 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1189 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1193 acpi_video_bus_write_POST(struct file
*file
,
1194 const char __user
* buffer
,
1195 size_t count
, loff_t
* data
)
1198 struct seq_file
*m
= file
->private_data
;
1199 struct acpi_video_bus
*video
= m
->private;
1200 char str
[12] = { 0 };
1201 unsigned long opt
, options
;
1204 if (!video
|| count
+ 1 > sizeof str
)
1207 status
= acpi_video_bus_POST_options(video
, &options
);
1208 if (!ACPI_SUCCESS(status
))
1211 if (copy_from_user(str
, buffer
, count
))
1215 opt
= strtoul(str
, NULL
, 0);
1219 /* just in case an OEM 'forgot' the motherboard... */
1222 if (options
& (1ul << opt
)) {
1223 status
= acpi_video_bus_set_POST(video
, opt
);
1224 if (!ACPI_SUCCESS(status
))
1233 acpi_video_bus_write_DOS(struct file
*file
,
1234 const char __user
* buffer
,
1235 size_t count
, loff_t
* data
)
1238 struct seq_file
*m
= file
->private_data
;
1239 struct acpi_video_bus
*video
= m
->private;
1240 char str
[12] = { 0 };
1244 if (!video
|| count
+ 1 > sizeof str
)
1247 if (copy_from_user(str
, buffer
, count
))
1251 opt
= strtoul(str
, NULL
, 0);
1255 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1257 if (!ACPI_SUCCESS(status
))
1263 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1265 struct proc_dir_entry
*entry
= NULL
;
1266 struct acpi_video_bus
*video
;
1269 video
= acpi_driver_data(device
);
1271 if (!acpi_device_dir(device
)) {
1272 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1274 if (!acpi_device_dir(device
))
1276 video
->dir
= acpi_device_dir(device
);
1277 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1281 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1285 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1286 entry
->data
= acpi_driver_data(device
);
1287 entry
->owner
= THIS_MODULE
;
1291 entry
= create_proc_entry("ROM", S_IRUGO
, acpi_device_dir(device
));
1295 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1296 entry
->data
= acpi_driver_data(device
);
1297 entry
->owner
= THIS_MODULE
;
1300 /* 'POST_info' [R] */
1302 create_proc_entry("POST_info", S_IRUGO
, acpi_device_dir(device
));
1306 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1307 entry
->data
= acpi_driver_data(device
);
1308 entry
->owner
= THIS_MODULE
;
1313 create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IRUSR
,
1314 acpi_device_dir(device
));
1318 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1319 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1320 entry
->data
= acpi_driver_data(device
);
1321 entry
->owner
= THIS_MODULE
;
1326 create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IRUSR
,
1327 acpi_device_dir(device
));
1331 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1332 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1333 entry
->data
= acpi_driver_data(device
);
1334 entry
->owner
= THIS_MODULE
;
1340 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1342 struct acpi_video_bus
*video
;
1345 video
= acpi_driver_data(device
);
1347 if (acpi_device_dir(device
)) {
1348 remove_proc_entry("info", acpi_device_dir(device
));
1349 remove_proc_entry("ROM", acpi_device_dir(device
));
1350 remove_proc_entry("POST_info", acpi_device_dir(device
));
1351 remove_proc_entry("POST", acpi_device_dir(device
));
1352 remove_proc_entry("DOS", acpi_device_dir(device
));
1353 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1354 acpi_device_dir(device
) = NULL
;
1360 /* --------------------------------------------------------------------------
1362 -------------------------------------------------------------------------- */
1364 /* device interface */
1365 static struct acpi_video_device_attrib
*
1366 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1370 for(count
= 0; count
< video
->attached_count
; count
++)
1371 if((video
->attached_array
[count
].value
.int_val
& 0xffff) == device_id
)
1372 return &(video
->attached_array
[count
].value
.attrib
);
1377 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1378 struct acpi_video_bus
*video
)
1380 unsigned long device_id
;
1382 struct acpi_video_device
*data
;
1383 struct acpi_video_device_attrib
* attribute
;
1385 if (!device
|| !video
)
1389 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1390 if (ACPI_SUCCESS(status
)) {
1392 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1396 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1397 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1398 acpi_driver_data(device
) = data
;
1400 data
->device_id
= device_id
;
1401 data
->video
= video
;
1404 attribute
= acpi_video_get_device_attr(video
, device_id
);
1406 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1407 switch (attribute
->display_type
) {
1408 case ACPI_VIDEO_DISPLAY_CRT
:
1409 data
->flags
.crt
= 1;
1411 case ACPI_VIDEO_DISPLAY_TV
:
1412 data
->flags
.tvout
= 1;
1414 case ACPI_VIDEO_DISPLAY_DVI
:
1415 data
->flags
.dvi
= 1;
1417 case ACPI_VIDEO_DISPLAY_LCD
:
1418 data
->flags
.lcd
= 1;
1421 data
->flags
.unknown
= 1;
1424 if(attribute
->bios_can_detect
)
1425 data
->flags
.bios
= 1;
1427 data
->flags
.unknown
= 1;
1429 acpi_video_device_bind(video
, data
);
1430 acpi_video_device_find_cap(data
);
1432 status
= acpi_install_notify_handler(device
->handle
,
1434 acpi_video_device_notify
,
1436 if (ACPI_FAILURE(status
)) {
1437 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1438 "Error installing notify handler\n"));
1439 if(data
->brightness
)
1440 kfree(data
->brightness
->levels
);
1441 kfree(data
->brightness
);
1446 mutex_lock(&video
->device_list_lock
);
1447 list_add_tail(&data
->entry
, &video
->video_device_list
);
1448 mutex_unlock(&video
->device_list_lock
);
1450 acpi_video_device_add_fs(device
);
1460 * video : video bus device
1465 * Enumerate the video device list of the video bus,
1466 * bind the ids with the corresponding video devices
1467 * under the video bus.
1470 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1472 struct acpi_video_device
*dev
;
1474 mutex_lock(&video
->device_list_lock
);
1476 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1477 acpi_video_device_bind(video
, dev
);
1479 mutex_unlock(&video
->device_list_lock
);
1484 * video : video bus device
1485 * device : video output device under the video
1491 * Bind the ids with the corresponding video devices
1492 * under the video bus.
1496 acpi_video_device_bind(struct acpi_video_bus
*video
,
1497 struct acpi_video_device
*device
)
1501 #define IDS_VAL(i) video->attached_array[i].value.int_val
1502 #define IDS_BIND(i) video->attached_array[i].bind_info
1504 for (i
= 0; IDS_VAL(i
) != ACPI_VIDEO_HEAD_INVALID
&&
1505 i
< video
->attached_count
; i
++) {
1506 if (device
->device_id
== (IDS_VAL(i
) & 0xffff)) {
1507 IDS_BIND(i
) = device
;
1508 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1517 * video : video bus device
1522 * Call _DOD to enumerate all devices attached to display adapter
1526 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1531 struct acpi_video_enumerated_device
*active_device_list
;
1532 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1533 union acpi_object
*dod
= NULL
;
1534 union acpi_object
*obj
;
1536 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1537 if (!ACPI_SUCCESS(status
)) {
1538 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1542 dod
= buffer
.pointer
;
1543 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1544 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1549 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1550 dod
->package
.count
));
1552 active_device_list
= kmalloc((1 +
1553 dod
->package
.count
) *
1555 acpi_video_enumerated_device
),
1558 if (!active_device_list
) {
1564 for (i
= 0; i
< dod
->package
.count
; i
++) {
1565 obj
= &dod
->package
.elements
[i
];
1567 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1568 printk(KERN_ERR PREFIX
"Invalid _DOD data\n");
1569 active_device_list
[i
].value
.int_val
=
1570 ACPI_VIDEO_HEAD_INVALID
;
1572 active_device_list
[i
].value
.int_val
= obj
->integer
.value
;
1573 active_device_list
[i
].bind_info
= NULL
;
1574 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1575 (int)obj
->integer
.value
));
1578 active_device_list
[count
].value
.int_val
= ACPI_VIDEO_HEAD_END
;
1580 kfree(video
->attached_array
);
1582 video
->attached_array
= active_device_list
;
1583 video
->attached_count
= count
;
1585 kfree(buffer
.pointer
);
1591 * video : video bus device
1592 * event : notify event
1597 * 1. Find out the current active output device.
1598 * 2. Identify the next output device to switch to.
1599 * 3. call _DSS to do actual switch.
1602 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
)
1604 struct list_head
*node
;
1605 struct acpi_video_device
*dev
= NULL
;
1606 struct acpi_video_device
*dev_next
= NULL
;
1607 struct acpi_video_device
*dev_prev
= NULL
;
1608 unsigned long state
;
1611 mutex_lock(&video
->device_list_lock
);
1613 list_for_each(node
, &video
->video_device_list
) {
1614 dev
= container_of(node
, struct acpi_video_device
, entry
);
1615 status
= acpi_video_device_get_state(dev
, &state
);
1617 dev_next
= container_of(node
->next
,
1618 struct acpi_video_device
, entry
);
1619 dev_prev
= container_of(node
->prev
,
1620 struct acpi_video_device
, entry
);
1625 dev_next
= container_of(node
->next
, struct acpi_video_device
, entry
);
1626 dev_prev
= container_of(node
->prev
, struct acpi_video_device
, entry
);
1629 mutex_unlock(&video
->device_list_lock
);
1632 case ACPI_VIDEO_NOTIFY_CYCLE
:
1633 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
:
1634 acpi_video_device_set_state(dev
, 0);
1635 acpi_video_device_set_state(dev_next
, 0x80000001);
1637 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
:
1638 acpi_video_device_set_state(dev
, 0);
1639 acpi_video_device_set_state(dev_prev
, 0x80000001);
1648 acpi_video_get_next_level(struct acpi_video_device
*device
,
1649 u32 level_current
, u32 event
)
1651 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1652 max
= max_below
= 0;
1653 min
= min_above
= 255;
1654 /* Find closest level to level_current */
1655 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1656 l
= device
->brightness
->levels
[i
];
1657 if (abs(l
- level_current
) < abs(delta
)) {
1658 delta
= l
- level_current
;
1663 /* Ajust level_current to closest available level */
1664 level_current
+= delta
;
1665 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1666 l
= device
->brightness
->levels
[i
];
1671 if (l
< min_above
&& l
> level_current
)
1673 if (l
> max_below
&& l
< level_current
)
1678 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1679 return (level_current
< max
) ? min_above
: min
;
1680 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1681 return (level_current
< max
) ? min_above
: max
;
1682 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1683 return (level_current
> min
) ? max_below
: min
;
1684 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1685 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1688 return level_current
;
1693 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1695 unsigned long level_current
, level_next
;
1696 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1697 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1698 acpi_video_device_lcd_set_level(device
, level_next
);
1702 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1703 struct acpi_device
*device
)
1706 struct acpi_device
*dev
;
1708 acpi_video_device_enumerate(video
);
1710 list_for_each_entry(dev
, &device
->children
, node
) {
1712 status
= acpi_video_bus_get_one_device(dev
, video
);
1713 if (ACPI_FAILURE(status
)) {
1714 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1721 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1724 struct acpi_video_bus
*video
;
1727 if (!device
|| !device
->video
)
1730 video
= device
->video
;
1732 acpi_video_device_remove_fs(device
->dev
);
1734 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1736 acpi_video_device_notify
);
1737 backlight_device_unregister(device
->backlight
);
1738 video_output_unregister(device
->output_dev
);
1743 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1746 struct acpi_video_device
*dev
, *next
;
1748 mutex_lock(&video
->device_list_lock
);
1750 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1752 status
= acpi_video_bus_put_one_device(dev
);
1753 if (ACPI_FAILURE(status
))
1754 printk(KERN_WARNING PREFIX
1755 "hhuuhhuu bug in acpi video driver.\n");
1757 if (dev
->brightness
) {
1758 kfree(dev
->brightness
->levels
);
1759 kfree(dev
->brightness
);
1761 list_del(&dev
->entry
);
1765 mutex_unlock(&video
->device_list_lock
);
1770 /* acpi_video interface */
1772 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1774 return acpi_video_bus_DOS(video
, 0, 0);
1777 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1779 return acpi_video_bus_DOS(video
, 0, 1);
1782 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1784 struct acpi_video_bus
*video
= data
;
1785 struct acpi_device
*device
= NULL
;
1786 struct input_dev
*input
;
1792 device
= video
->device
;
1793 input
= video
->input
;
1796 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1797 * most likely via hotkey. */
1798 acpi_bus_generate_proc_event(device
, event
, 0);
1799 keycode
= KEY_SWITCHVIDEOMODE
;
1802 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1804 acpi_video_device_enumerate(video
);
1805 acpi_video_device_rebind(video
);
1806 acpi_video_switch_output(video
, event
);
1807 acpi_bus_generate_proc_event(device
, event
, 0);
1808 keycode
= KEY_SWITCHVIDEOMODE
;
1811 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1812 acpi_video_switch_output(video
, event
);
1813 acpi_bus_generate_proc_event(device
, event
, 0);
1814 keycode
= KEY_SWITCHVIDEOMODE
;
1816 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1817 acpi_video_switch_output(video
, event
);
1818 acpi_bus_generate_proc_event(device
, event
, 0);
1819 keycode
= KEY_VIDEO_NEXT
;
1821 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1822 acpi_video_switch_output(video
, event
);
1823 acpi_bus_generate_proc_event(device
, event
, 0);
1824 keycode
= KEY_VIDEO_PREV
;
1828 keycode
= KEY_UNKNOWN
;
1829 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1830 "Unsupported event [0x%x]\n", event
));
1834 input_report_key(input
, keycode
, 1);
1836 input_report_key(input
, keycode
, 0);
1842 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1844 struct acpi_video_device
*video_device
= data
;
1845 struct acpi_device
*device
= NULL
;
1846 struct acpi_video_bus
*bus
;
1847 struct input_dev
*input
;
1853 device
= video_device
->dev
;
1854 bus
= video_device
->video
;
1858 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1859 acpi_video_switch_brightness(video_device
, event
);
1860 acpi_bus_generate_proc_event(device
, event
, 0);
1861 keycode
= KEY_BRIGHTNESS_CYCLE
;
1863 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1864 acpi_video_switch_brightness(video_device
, event
);
1865 acpi_bus_generate_proc_event(device
, event
, 0);
1866 keycode
= KEY_BRIGHTNESSUP
;
1868 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1869 acpi_video_switch_brightness(video_device
, event
);
1870 acpi_bus_generate_proc_event(device
, event
, 0);
1871 keycode
= KEY_BRIGHTNESSDOWN
;
1873 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1874 acpi_video_switch_brightness(video_device
, event
);
1875 acpi_bus_generate_proc_event(device
, event
, 0);
1876 keycode
= KEY_BRIGHTNESS_ZERO
;
1878 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1879 acpi_video_switch_brightness(video_device
, event
);
1880 acpi_bus_generate_proc_event(device
, event
, 0);
1881 keycode
= KEY_DISPLAY_OFF
;
1884 keycode
= KEY_UNKNOWN
;
1885 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1886 "Unsupported event [0x%x]\n", event
));
1890 input_report_key(input
, keycode
, 1);
1892 input_report_key(input
, keycode
, 0);
1898 static int instance
;
1899 static int acpi_video_bus_add(struct acpi_device
*device
)
1902 struct acpi_video_bus
*video
;
1903 struct input_dev
*input
;
1906 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1910 /* a hack to fix the duplicate name "VID" problem on T61 */
1911 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
1913 device
->pnp
.bus_id
[3] = '0' + instance
;
1917 video
->device
= device
;
1918 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1919 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1920 acpi_driver_data(device
) = video
;
1922 acpi_video_bus_find_cap(video
);
1923 error
= acpi_video_bus_check(video
);
1925 goto err_free_video
;
1927 error
= acpi_video_bus_add_fs(device
);
1929 goto err_free_video
;
1931 mutex_init(&video
->device_list_lock
);
1932 INIT_LIST_HEAD(&video
->video_device_list
);
1934 acpi_video_bus_get_devices(video
, device
);
1935 acpi_video_bus_start_devices(video
);
1937 status
= acpi_install_notify_handler(device
->handle
,
1939 acpi_video_bus_notify
, video
);
1940 if (ACPI_FAILURE(status
)) {
1941 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1942 "Error installing notify handler\n"));
1944 goto err_stop_video
;
1947 video
->input
= input
= input_allocate_device();
1950 goto err_uninstall_notify
;
1953 snprintf(video
->phys
, sizeof(video
->phys
),
1954 "%s/video/input0", acpi_device_hid(video
->device
));
1956 input
->name
= acpi_device_name(video
->device
);
1957 input
->phys
= video
->phys
;
1958 input
->id
.bustype
= BUS_HOST
;
1959 input
->id
.product
= 0x06;
1960 input
->dev
.parent
= &device
->dev
;
1961 input
->evbit
[0] = BIT(EV_KEY
);
1962 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
1963 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
1964 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
1965 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
1966 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
1967 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
1968 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
1969 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
1970 set_bit(KEY_UNKNOWN
, input
->keybit
);
1972 error
= input_register_device(input
);
1974 goto err_free_input_dev
;
1976 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1977 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1978 video
->flags
.multihead
? "yes" : "no",
1979 video
->flags
.rom
? "yes" : "no",
1980 video
->flags
.post
? "yes" : "no");
1985 input_free_device(input
);
1986 err_uninstall_notify
:
1987 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
1988 acpi_video_bus_notify
);
1990 acpi_video_bus_stop_devices(video
);
1991 acpi_video_bus_put_devices(video
);
1992 kfree(video
->attached_array
);
1993 acpi_video_bus_remove_fs(device
);
1996 acpi_driver_data(device
) = NULL
;
2001 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2003 acpi_status status
= 0;
2004 struct acpi_video_bus
*video
= NULL
;
2007 if (!device
|| !acpi_driver_data(device
))
2010 video
= acpi_driver_data(device
);
2012 acpi_video_bus_stop_devices(video
);
2014 status
= acpi_remove_notify_handler(video
->device
->handle
,
2016 acpi_video_bus_notify
);
2018 acpi_video_bus_put_devices(video
);
2019 acpi_video_bus_remove_fs(device
);
2021 input_unregister_device(video
->input
);
2022 kfree(video
->attached_array
);
2028 static int __init
acpi_video_init(void)
2034 acpi_dbg_level = 0xFFFFFFFF;
2035 acpi_dbg_layer = 0x08000000;
2038 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2039 if (!acpi_video_dir
)
2041 acpi_video_dir
->owner
= THIS_MODULE
;
2043 result
= acpi_bus_register_driver(&acpi_video_bus
);
2045 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2052 static void __exit
acpi_video_exit(void)
2055 acpi_bus_unregister_driver(&acpi_video_bus
);
2057 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2062 module_init(acpi_video_init
);
2063 module_exit(acpi_video_exit
);