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/proc_fs.h>
33 #include <linux/seq_file.h>
34 #include <linux/input.h>
35 #include <linux/backlight.h>
36 #include <linux/video_output.h>
37 #include <asm/uaccess.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/acpi_drivers.h>
42 #define ACPI_VIDEO_COMPONENT 0x08000000
43 #define ACPI_VIDEO_CLASS "video"
44 #define ACPI_VIDEO_BUS_NAME "Video Bus"
45 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
46 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
47 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
48 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
49 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
50 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
52 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
53 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
54 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
55 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
56 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
58 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
59 #define ACPI_VIDEO_HEAD_END (~0u)
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 acpi_video_bus_add(struct acpi_device
*device
);
75 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
77 static const struct acpi_device_id video_device_ids
[] = {
81 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
83 static struct acpi_driver acpi_video_bus
= {
85 .class = ACPI_VIDEO_CLASS
,
86 .ids
= video_device_ids
,
88 .add
= acpi_video_bus_add
,
89 .remove
= acpi_video_bus_remove
,
93 struct acpi_video_bus_flags
{
94 u8 multihead
:1; /* can switch video heads */
95 u8 rom
:1; /* can retrieve a video rom */
96 u8 post
:1; /* can configure the head to */
100 struct acpi_video_bus_cap
{
101 u8 _DOS
:1; /*Enable/Disable output switching */
102 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
103 u8 _ROM
:1; /*Get ROM Data */
104 u8 _GPD
:1; /*Get POST Device */
105 u8 _SPD
:1; /*Set POST Device */
106 u8 _VPO
:1; /*Video POST Options */
110 struct acpi_video_device_attrib
{
111 u32 display_index
:4; /* A zero-based instance of the Display */
112 u32 display_port_attachment
:4; /*This field differentiates the display type */
113 u32 display_type
:4; /*Describe the specific type in use */
114 u32 vendor_specific
:4; /*Chipset Vendor Specific */
115 u32 bios_can_detect
:1; /*BIOS can detect the device */
116 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
118 u32 pipe_id
:3; /*For VGA multiple-head devices. */
119 u32 reserved
:10; /*Must be 0 */
120 u32 device_id_scheme
:1; /*Device ID Scheme */
123 struct acpi_video_enumerated_device
{
126 struct acpi_video_device_attrib attrib
;
128 struct acpi_video_device
*bind_info
;
131 struct acpi_video_bus
{
132 struct acpi_device
*device
;
134 struct acpi_video_enumerated_device
*attached_array
;
136 struct acpi_video_bus_cap cap
;
137 struct acpi_video_bus_flags flags
;
138 struct semaphore sem
;
139 struct list_head video_device_list
;
140 struct proc_dir_entry
*dir
;
141 struct input_dev
*input
;
142 char phys
[32]; /* for input device */
145 struct acpi_video_device_flags
{
155 struct acpi_video_device_cap
{
156 u8 _ADR
:1; /*Return the unique ID */
157 u8 _BCL
:1; /*Query list of brightness control levels supported */
158 u8 _BCM
:1; /*Set the brightness level */
159 u8 _BQC
:1; /* Get current brightness level */
160 u8 _DDC
:1; /*Return the EDID for this device */
161 u8 _DCS
:1; /*Return status of output device */
162 u8 _DGS
:1; /*Query graphics state */
163 u8 _DSS
:1; /*Device state set */
166 struct acpi_video_device_brightness
{
172 struct acpi_video_device
{
173 unsigned long device_id
;
174 struct acpi_video_device_flags flags
;
175 struct acpi_video_device_cap cap
;
176 struct list_head entry
;
177 struct acpi_video_bus
*video
;
178 struct acpi_device
*dev
;
179 struct acpi_video_device_brightness
*brightness
;
180 struct backlight_device
*backlight
;
181 struct output_device
*output_dev
;
185 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
186 static struct file_operations acpi_video_bus_info_fops
= {
187 .open
= acpi_video_bus_info_open_fs
,
190 .release
= single_release
,
193 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
194 static struct file_operations acpi_video_bus_ROM_fops
= {
195 .open
= acpi_video_bus_ROM_open_fs
,
198 .release
= single_release
,
201 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
203 static struct file_operations acpi_video_bus_POST_info_fops
= {
204 .open
= acpi_video_bus_POST_info_open_fs
,
207 .release
= single_release
,
210 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
211 static struct file_operations acpi_video_bus_POST_fops
= {
212 .open
= acpi_video_bus_POST_open_fs
,
215 .release
= single_release
,
218 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
219 static struct file_operations acpi_video_bus_DOS_fops
= {
220 .open
= acpi_video_bus_DOS_open_fs
,
223 .release
= single_release
,
227 static int acpi_video_device_info_open_fs(struct inode
*inode
,
229 static struct file_operations acpi_video_device_info_fops
= {
230 .open
= acpi_video_device_info_open_fs
,
233 .release
= single_release
,
236 static int acpi_video_device_state_open_fs(struct inode
*inode
,
238 static struct file_operations acpi_video_device_state_fops
= {
239 .open
= acpi_video_device_state_open_fs
,
242 .release
= single_release
,
245 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
247 static struct file_operations acpi_video_device_brightness_fops
= {
248 .open
= acpi_video_device_brightness_open_fs
,
251 .release
= single_release
,
254 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
256 static struct file_operations acpi_video_device_EDID_fops
= {
257 .open
= acpi_video_device_EDID_open_fs
,
260 .release
= single_release
,
263 static char device_decode
[][30] = {
264 "motherboard VGA device",
270 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
271 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
272 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
273 struct acpi_video_device
*device
);
274 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
275 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
);
276 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
278 static int acpi_video_device_lcd_get_level_current(
279 struct acpi_video_device
*device
,
280 unsigned long *level
);
281 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
282 u32 level_current
, u32 event
);
283 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
285 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
286 unsigned long *state
);
287 static int acpi_video_output_get(struct output_device
*od
);
288 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
290 /*backlight device sysfs support*/
291 static int acpi_video_get_brightness(struct backlight_device
*bd
)
293 unsigned long cur_level
;
294 struct acpi_video_device
*vd
=
295 (struct acpi_video_device
*)bl_get_data(bd
);
296 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
297 return (int) cur_level
;
300 static int acpi_video_set_brightness(struct backlight_device
*bd
)
302 int request_level
= bd
->props
.brightness
;
303 struct acpi_video_device
*vd
=
304 (struct acpi_video_device
*)bl_get_data(bd
);
305 acpi_video_device_lcd_set_level(vd
, request_level
);
309 static struct backlight_ops acpi_backlight_ops
= {
310 .get_brightness
= acpi_video_get_brightness
,
311 .update_status
= acpi_video_set_brightness
,
314 /*video output device sysfs support*/
315 static int acpi_video_output_get(struct output_device
*od
)
318 struct acpi_video_device
*vd
=
319 (struct acpi_video_device
*)class_get_devdata(&od
->class_dev
);
320 acpi_video_device_get_state(vd
, &state
);
324 static int acpi_video_output_set(struct output_device
*od
)
326 unsigned long state
= od
->request_state
;
327 struct acpi_video_device
*vd
=
328 (struct acpi_video_device
*)class_get_devdata(&od
->class_dev
);
329 return acpi_video_device_set_state(vd
, state
);
332 static struct output_properties acpi_output_properties
= {
333 .set_state
= acpi_video_output_set
,
334 .get_status
= acpi_video_output_get
,
336 /* --------------------------------------------------------------------------
338 -------------------------------------------------------------------------- */
343 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
347 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
353 acpi_video_device_get_state(struct acpi_video_device
*device
,
354 unsigned long *state
)
358 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
364 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
367 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
368 struct acpi_object_list args
= { 1, &arg0
};
372 arg0
.integer
.value
= state
;
373 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
379 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
380 union acpi_object
**levels
)
383 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
384 union acpi_object
*obj
;
389 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
390 if (!ACPI_SUCCESS(status
))
392 obj
= (union acpi_object
*)buffer
.pointer
;
393 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
394 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
404 kfree(buffer
.pointer
);
410 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
413 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
414 struct acpi_object_list args
= { 1, &arg0
};
417 arg0
.integer
.value
= level
;
418 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM", &args
, NULL
);
420 printk(KERN_DEBUG
"set_level status: %x\n", status
);
425 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
426 unsigned long *level
)
430 status
= acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
, level
);
436 acpi_video_device_EDID(struct acpi_video_device
*device
,
437 union acpi_object
**edid
, ssize_t length
)
440 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
441 union acpi_object
*obj
;
442 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
443 struct acpi_object_list args
= { 1, &arg0
};
451 arg0
.integer
.value
= 1;
452 else if (length
== 256)
453 arg0
.integer
.value
= 2;
457 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
458 if (ACPI_FAILURE(status
))
461 obj
= buffer
.pointer
;
463 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
466 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
477 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
481 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
482 struct acpi_object_list args
= { 1, &arg0
};
485 arg0
.integer
.value
= option
;
487 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
488 if (ACPI_SUCCESS(status
))
489 status
= tmp
? (-EINVAL
) : (AE_OK
);
495 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
499 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
505 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
506 unsigned long *options
)
510 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
518 * video : video bus device pointer
520 * 0. The system BIOS should NOT automatically switch(toggle)
521 * the active display output.
522 * 1. The system BIOS should automatically switch (toggle) the
523 * active display output. No switch event.
524 * 2. The _DGS value should be locked.
525 * 3. The system BIOS should not automatically switch (toggle) the
526 * active display output, but instead generate the display switch
529 * 0. The system BIOS should automatically control the brightness level
530 * of the LCD when the power changes from AC to DC
531 * 1. The system BIOS should NOT automatically control the brightness
532 * level of the LCD when the power changes from AC to DC.
538 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
540 acpi_integer status
= 0;
541 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
542 struct acpi_object_list args
= { 1, &arg0
};
545 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
549 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
550 video
->dos_setting
= arg0
.integer
.value
;
551 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
559 * device : video output device (LCD, CRT, ..)
564 * Find out all required AML methods defined under the output
568 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
570 acpi_handle h_dummy1
;
573 union acpi_object
*obj
= NULL
;
574 struct acpi_video_device_brightness
*br
= NULL
;
577 memset(&device
->cap
, 0, 4);
579 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
580 device
->cap
._ADR
= 1;
582 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
583 device
->cap
._BCL
= 1;
585 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
586 device
->cap
._BCM
= 1;
588 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
589 device
->cap
._BQC
= 1;
590 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
591 device
->cap
._DDC
= 1;
593 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
594 device
->cap
._DCS
= 1;
596 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
597 device
->cap
._DGS
= 1;
599 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
600 device
->cap
._DSS
= 1;
603 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
605 if (obj
->package
.count
>= 2) {
607 union acpi_object
*o
;
609 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
611 printk(KERN_ERR
"can't allocate memory\n");
613 br
->levels
= kmalloc(obj
->package
.count
*
614 sizeof *(br
->levels
), GFP_KERNEL
);
618 for (i
= 0; i
< obj
->package
.count
; i
++) {
619 o
= (union acpi_object
*)&obj
->package
.
621 if (o
->type
!= ACPI_TYPE_INTEGER
) {
622 printk(KERN_ERR PREFIX
"Invalid data\n");
625 br
->levels
[count
] = (u32
) o
->integer
.value
;
627 if (br
->levels
[count
] > max_level
)
628 max_level
= br
->levels
[count
];
637 device
->brightness
= br
;
638 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
639 "found %d brightness levels\n",
646 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available LCD brightness level\n"));
651 if (device
->cap
._BCL
&& device
->cap
._BCM
&& device
->cap
._BQC
&& max_level
> 0){
653 static int count
= 0;
655 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
659 sprintf(name
, "acpi_video%d", count
++);
660 acpi_video_device_lcd_get_level_current(device
, &tmp
);
661 device
->backlight
= backlight_device_register(name
,
662 NULL
, device
, &acpi_backlight_ops
);
663 device
->backlight
->props
.max_brightness
= max_level
;
664 device
->backlight
->props
.brightness
= (int)tmp
;
665 backlight_update_status(device
->backlight
);
669 if (device
->cap
._DCS
&& device
->cap
._DSS
){
670 static int count
= 0;
672 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
675 sprintf(name
, "acpi_video%d", count
++);
676 device
->output_dev
= video_output_register(name
,
677 NULL
, device
, &acpi_output_properties
);
685 * device : video output device (VGA)
690 * Find out all required AML methods defined under the video bus device.
693 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
695 acpi_handle h_dummy1
;
697 memset(&video
->cap
, 0, 4);
698 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
701 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
704 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
707 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
710 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
713 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
719 * Check whether the video bus device has required AML method to
720 * support the desired features
723 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
725 acpi_status status
= -ENOENT
;
731 /* Since there is no HID, CID and so on for VGA driver, we have
732 * to check well known required nodes.
735 /* Does this device support video switching? */
736 if (video
->cap
._DOS
) {
737 video
->flags
.multihead
= 1;
741 /* Does this device support retrieving a video ROM? */
742 if (video
->cap
._ROM
) {
743 video
->flags
.rom
= 1;
747 /* Does this device support configuring which video device to POST? */
748 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
749 video
->flags
.post
= 1;
756 /* --------------------------------------------------------------------------
758 -------------------------------------------------------------------------- */
760 static struct proc_dir_entry
*acpi_video_dir
;
764 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
766 struct acpi_video_device
*dev
= seq
->private;
772 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
773 seq_printf(seq
, "type: ");
775 seq_printf(seq
, "CRT\n");
776 else if (dev
->flags
.lcd
)
777 seq_printf(seq
, "LCD\n");
778 else if (dev
->flags
.tvout
)
779 seq_printf(seq
, "TVOUT\n");
780 else if (dev
->flags
.dvi
)
781 seq_printf(seq
, "DVI\n");
783 seq_printf(seq
, "UNKNOWN\n");
785 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
792 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
794 return single_open(file
, acpi_video_device_info_seq_show
,
798 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
801 struct acpi_video_device
*dev
= seq
->private;
808 status
= acpi_video_device_get_state(dev
, &state
);
809 seq_printf(seq
, "state: ");
810 if (ACPI_SUCCESS(status
))
811 seq_printf(seq
, "0x%02lx\n", state
);
813 seq_printf(seq
, "<not supported>\n");
815 status
= acpi_video_device_query(dev
, &state
);
816 seq_printf(seq
, "query: ");
817 if (ACPI_SUCCESS(status
))
818 seq_printf(seq
, "0x%02lx\n", state
);
820 seq_printf(seq
, "<not supported>\n");
827 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
829 return single_open(file
, acpi_video_device_state_seq_show
,
834 acpi_video_device_write_state(struct file
*file
,
835 const char __user
* buffer
,
836 size_t count
, loff_t
* data
)
839 struct seq_file
*m
= file
->private_data
;
840 struct acpi_video_device
*dev
= m
->private;
841 char str
[12] = { 0 };
845 if (!dev
|| count
+ 1 > sizeof str
)
848 if (copy_from_user(str
, buffer
, count
))
852 state
= simple_strtoul(str
, NULL
, 0);
853 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
855 status
= acpi_video_device_set_state(dev
, state
);
864 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
866 struct acpi_video_device
*dev
= seq
->private;
870 if (!dev
|| !dev
->brightness
) {
871 seq_printf(seq
, "<not supported>\n");
875 seq_printf(seq
, "levels: ");
876 for (i
= 0; i
< dev
->brightness
->count
; i
++)
877 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
878 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
884 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
886 return single_open(file
, acpi_video_device_brightness_seq_show
,
891 acpi_video_device_write_brightness(struct file
*file
,
892 const char __user
* buffer
,
893 size_t count
, loff_t
* data
)
895 struct seq_file
*m
= file
->private_data
;
896 struct acpi_video_device
*dev
= m
->private;
898 unsigned int level
= 0;
902 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
905 if (copy_from_user(str
, buffer
, count
))
909 level
= simple_strtoul(str
, NULL
, 0);
914 /* validate through the list of available levels */
915 for (i
= 0; i
< dev
->brightness
->count
; i
++)
916 if (level
== dev
->brightness
->levels
[i
]) {
918 (acpi_video_device_lcd_set_level(dev
, level
)))
919 dev
->brightness
->curr
= level
;
926 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
928 struct acpi_video_device
*dev
= seq
->private;
931 union acpi_object
*edid
= NULL
;
937 status
= acpi_video_device_EDID(dev
, &edid
, 128);
938 if (ACPI_FAILURE(status
)) {
939 status
= acpi_video_device_EDID(dev
, &edid
, 256);
942 if (ACPI_FAILURE(status
)) {
946 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
947 for (i
= 0; i
< edid
->buffer
.length
; i
++)
948 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
953 seq_printf(seq
, "<not supported>\n");
961 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
963 return single_open(file
, acpi_video_device_EDID_seq_show
,
967 static int acpi_video_device_add_fs(struct acpi_device
*device
)
969 struct proc_dir_entry
*entry
= NULL
;
970 struct acpi_video_device
*vid_dev
;
976 vid_dev
= acpi_driver_data(device
);
980 if (!acpi_device_dir(device
)) {
981 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
982 vid_dev
->video
->dir
);
983 if (!acpi_device_dir(device
))
985 acpi_device_dir(device
)->owner
= THIS_MODULE
;
989 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
993 entry
->proc_fops
= &acpi_video_device_info_fops
;
994 entry
->data
= acpi_driver_data(device
);
995 entry
->owner
= THIS_MODULE
;
1000 create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1001 acpi_device_dir(device
));
1005 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1006 entry
->proc_fops
= &acpi_video_device_state_fops
;
1007 entry
->data
= acpi_driver_data(device
);
1008 entry
->owner
= THIS_MODULE
;
1011 /* 'brightness' [R/W] */
1013 create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1014 acpi_device_dir(device
));
1018 acpi_video_device_brightness_fops
.write
= acpi_video_device_write_brightness
;
1019 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
1020 entry
->data
= acpi_driver_data(device
);
1021 entry
->owner
= THIS_MODULE
;
1025 entry
= create_proc_entry("EDID", S_IRUGO
, acpi_device_dir(device
));
1029 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
1030 entry
->data
= acpi_driver_data(device
);
1031 entry
->owner
= THIS_MODULE
;
1037 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1039 struct acpi_video_device
*vid_dev
;
1041 vid_dev
= acpi_driver_data(device
);
1042 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1045 if (acpi_device_dir(device
)) {
1046 remove_proc_entry("info", acpi_device_dir(device
));
1047 remove_proc_entry("state", acpi_device_dir(device
));
1048 remove_proc_entry("brightness", acpi_device_dir(device
));
1049 remove_proc_entry("EDID", acpi_device_dir(device
));
1050 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1051 acpi_device_dir(device
) = NULL
;
1058 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1060 struct acpi_video_bus
*video
= seq
->private;
1066 seq_printf(seq
, "Switching heads: %s\n",
1067 video
->flags
.multihead
? "yes" : "no");
1068 seq_printf(seq
, "Video ROM: %s\n",
1069 video
->flags
.rom
? "yes" : "no");
1070 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1071 video
->flags
.post
? "yes" : "no");
1077 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1079 return single_open(file
, acpi_video_bus_info_seq_show
,
1083 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1085 struct acpi_video_bus
*video
= seq
->private;
1091 printk(KERN_INFO PREFIX
"Please implement %s\n", __FUNCTION__
);
1092 seq_printf(seq
, "<TODO>\n");
1098 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1100 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1103 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1105 struct acpi_video_bus
*video
= seq
->private;
1106 unsigned long options
;
1113 status
= acpi_video_bus_POST_options(video
, &options
);
1114 if (ACPI_SUCCESS(status
)) {
1115 if (!(options
& 1)) {
1116 printk(KERN_WARNING PREFIX
1117 "The motherboard VGA device is not listed as a possible POST device.\n");
1118 printk(KERN_WARNING PREFIX
1119 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1121 printk("%lx\n", options
);
1122 seq_printf(seq
, "can POST: <integrated video>");
1124 seq_printf(seq
, " <PCI video>");
1126 seq_printf(seq
, " <AGP video>");
1127 seq_putc(seq
, '\n');
1129 seq_printf(seq
, "<not supported>\n");
1135 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1137 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1141 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1143 struct acpi_video_bus
*video
= seq
->private;
1151 status
= acpi_video_bus_get_POST(video
, &id
);
1152 if (!ACPI_SUCCESS(status
)) {
1153 seq_printf(seq
, "<not supported>\n");
1156 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1162 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1164 struct acpi_video_bus
*video
= seq
->private;
1167 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1172 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1174 return single_open(file
, acpi_video_bus_POST_seq_show
,
1178 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1180 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1184 acpi_video_bus_write_POST(struct file
*file
,
1185 const char __user
* buffer
,
1186 size_t count
, loff_t
* data
)
1189 struct seq_file
*m
= file
->private_data
;
1190 struct acpi_video_bus
*video
= m
->private;
1191 char str
[12] = { 0 };
1192 unsigned long opt
, options
;
1195 if (!video
|| count
+ 1 > sizeof str
)
1198 status
= acpi_video_bus_POST_options(video
, &options
);
1199 if (!ACPI_SUCCESS(status
))
1202 if (copy_from_user(str
, buffer
, count
))
1206 opt
= strtoul(str
, NULL
, 0);
1210 /* just in case an OEM 'forgot' the motherboard... */
1213 if (options
& (1ul << opt
)) {
1214 status
= acpi_video_bus_set_POST(video
, opt
);
1215 if (!ACPI_SUCCESS(status
))
1224 acpi_video_bus_write_DOS(struct file
*file
,
1225 const char __user
* buffer
,
1226 size_t count
, loff_t
* data
)
1229 struct seq_file
*m
= file
->private_data
;
1230 struct acpi_video_bus
*video
= m
->private;
1231 char str
[12] = { 0 };
1235 if (!video
|| count
+ 1 > sizeof str
)
1238 if (copy_from_user(str
, buffer
, count
))
1242 opt
= strtoul(str
, NULL
, 0);
1246 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1248 if (!ACPI_SUCCESS(status
))
1254 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1256 struct proc_dir_entry
*entry
= NULL
;
1257 struct acpi_video_bus
*video
;
1260 video
= acpi_driver_data(device
);
1262 if (!acpi_device_dir(device
)) {
1263 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1265 if (!acpi_device_dir(device
))
1267 video
->dir
= acpi_device_dir(device
);
1268 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1272 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1276 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1277 entry
->data
= acpi_driver_data(device
);
1278 entry
->owner
= THIS_MODULE
;
1282 entry
= create_proc_entry("ROM", S_IRUGO
, acpi_device_dir(device
));
1286 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1287 entry
->data
= acpi_driver_data(device
);
1288 entry
->owner
= THIS_MODULE
;
1291 /* 'POST_info' [R] */
1293 create_proc_entry("POST_info", S_IRUGO
, acpi_device_dir(device
));
1297 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1298 entry
->data
= acpi_driver_data(device
);
1299 entry
->owner
= THIS_MODULE
;
1304 create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IRUSR
,
1305 acpi_device_dir(device
));
1309 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1310 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1311 entry
->data
= acpi_driver_data(device
);
1312 entry
->owner
= THIS_MODULE
;
1317 create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IRUSR
,
1318 acpi_device_dir(device
));
1322 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1323 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1324 entry
->data
= acpi_driver_data(device
);
1325 entry
->owner
= THIS_MODULE
;
1331 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1333 struct acpi_video_bus
*video
;
1336 video
= acpi_driver_data(device
);
1338 if (acpi_device_dir(device
)) {
1339 remove_proc_entry("info", acpi_device_dir(device
));
1340 remove_proc_entry("ROM", acpi_device_dir(device
));
1341 remove_proc_entry("POST_info", acpi_device_dir(device
));
1342 remove_proc_entry("POST", acpi_device_dir(device
));
1343 remove_proc_entry("DOS", acpi_device_dir(device
));
1344 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1345 acpi_device_dir(device
) = NULL
;
1351 /* --------------------------------------------------------------------------
1353 -------------------------------------------------------------------------- */
1355 /* device interface */
1356 static struct acpi_video_device_attrib
*
1357 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1361 for(count
= 0; count
< video
->attached_count
; count
++)
1362 if((video
->attached_array
[count
].value
.int_val
& 0xffff) == device_id
)
1363 return &(video
->attached_array
[count
].value
.attrib
);
1368 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1369 struct acpi_video_bus
*video
)
1371 unsigned long device_id
;
1373 struct acpi_video_device
*data
;
1374 struct acpi_video_device_attrib
* attribute
;
1376 if (!device
|| !video
)
1380 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1381 if (ACPI_SUCCESS(status
)) {
1383 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1387 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1388 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1389 acpi_driver_data(device
) = data
;
1391 data
->device_id
= device_id
;
1392 data
->video
= video
;
1395 attribute
= acpi_video_get_device_attr(video
, device_id
);
1397 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1398 switch (attribute
->display_type
) {
1399 case ACPI_VIDEO_DISPLAY_CRT
:
1400 data
->flags
.crt
= 1;
1402 case ACPI_VIDEO_DISPLAY_TV
:
1403 data
->flags
.tvout
= 1;
1405 case ACPI_VIDEO_DISPLAY_DVI
:
1406 data
->flags
.dvi
= 1;
1408 case ACPI_VIDEO_DISPLAY_LCD
:
1409 data
->flags
.lcd
= 1;
1412 data
->flags
.unknown
= 1;
1415 if(attribute
->bios_can_detect
)
1416 data
->flags
.bios
= 1;
1418 data
->flags
.unknown
= 1;
1420 acpi_video_device_bind(video
, data
);
1421 acpi_video_device_find_cap(data
);
1423 status
= acpi_install_notify_handler(device
->handle
,
1425 acpi_video_device_notify
,
1427 if (ACPI_FAILURE(status
)) {
1428 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1429 "Error installing notify handler\n"));
1430 if(data
->brightness
)
1431 kfree(data
->brightness
->levels
);
1432 kfree(data
->brightness
);
1438 list_add_tail(&data
->entry
, &video
->video_device_list
);
1441 acpi_video_device_add_fs(device
);
1451 * video : video bus device
1456 * Enumerate the video device list of the video bus,
1457 * bind the ids with the corresponding video devices
1458 * under the video bus.
1461 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1463 struct list_head
*node
, *next
;
1464 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1465 struct acpi_video_device
*dev
=
1466 container_of(node
, struct acpi_video_device
, entry
);
1467 acpi_video_device_bind(video
, dev
);
1473 * video : video bus device
1474 * device : video output device under the video
1480 * Bind the ids with the corresponding video devices
1481 * under the video bus.
1485 acpi_video_device_bind(struct acpi_video_bus
*video
,
1486 struct acpi_video_device
*device
)
1490 #define IDS_VAL(i) video->attached_array[i].value.int_val
1491 #define IDS_BIND(i) video->attached_array[i].bind_info
1493 for (i
= 0; IDS_VAL(i
) != ACPI_VIDEO_HEAD_INVALID
&&
1494 i
< video
->attached_count
; i
++) {
1495 if (device
->device_id
== (IDS_VAL(i
) & 0xffff)) {
1496 IDS_BIND(i
) = device
;
1497 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1506 * video : video bus device
1511 * Call _DOD to enumerate all devices attached to display adapter
1515 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1520 struct acpi_video_enumerated_device
*active_device_list
;
1521 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1522 union acpi_object
*dod
= NULL
;
1523 union acpi_object
*obj
;
1525 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1526 if (!ACPI_SUCCESS(status
)) {
1527 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1531 dod
= buffer
.pointer
;
1532 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1533 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1538 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1539 dod
->package
.count
));
1541 active_device_list
= kmalloc((1 +
1542 dod
->package
.count
) *
1544 acpi_video_enumerated_device
),
1547 if (!active_device_list
) {
1553 for (i
= 0; i
< dod
->package
.count
; i
++) {
1554 obj
= &dod
->package
.elements
[i
];
1556 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1557 printk(KERN_ERR PREFIX
"Invalid _DOD data\n");
1558 active_device_list
[i
].value
.int_val
=
1559 ACPI_VIDEO_HEAD_INVALID
;
1561 active_device_list
[i
].value
.int_val
= obj
->integer
.value
;
1562 active_device_list
[i
].bind_info
= NULL
;
1563 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1564 (int)obj
->integer
.value
));
1567 active_device_list
[count
].value
.int_val
= ACPI_VIDEO_HEAD_END
;
1569 kfree(video
->attached_array
);
1571 video
->attached_array
= active_device_list
;
1572 video
->attached_count
= count
;
1574 kfree(buffer
.pointer
);
1580 * video : video bus device
1581 * event : notify event
1586 * 1. Find out the current active output device.
1587 * 2. Identify the next output device to switch to.
1588 * 3. call _DSS to do actual switch.
1591 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
)
1593 struct list_head
*node
, *next
;
1594 struct acpi_video_device
*dev
= NULL
;
1595 struct acpi_video_device
*dev_next
= NULL
;
1596 struct acpi_video_device
*dev_prev
= NULL
;
1597 unsigned long state
;
1601 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1602 dev
= container_of(node
, struct acpi_video_device
, entry
);
1603 status
= acpi_video_device_get_state(dev
, &state
);
1606 container_of(node
->next
, struct acpi_video_device
,
1609 container_of(node
->prev
, struct acpi_video_device
,
1614 dev_next
= container_of(node
->next
, struct acpi_video_device
, entry
);
1615 dev_prev
= container_of(node
->prev
, struct acpi_video_device
, entry
);
1618 case ACPI_VIDEO_NOTIFY_CYCLE
:
1619 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
:
1620 acpi_video_device_set_state(dev
, 0);
1621 acpi_video_device_set_state(dev_next
, 0x80000001);
1623 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
:
1624 acpi_video_device_set_state(dev
, 0);
1625 acpi_video_device_set_state(dev_prev
, 0x80000001);
1634 acpi_video_get_next_level(struct acpi_video_device
*device
,
1635 u32 level_current
, u32 event
)
1637 int min
, max
, min_above
, max_below
, i
, l
;
1638 max
= max_below
= 0;
1639 min
= min_above
= 255;
1640 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1641 l
= device
->brightness
->levels
[i
];
1646 if (l
< min_above
&& l
> level_current
)
1648 if (l
> max_below
&& l
< level_current
)
1653 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1654 return (level_current
< max
) ? min_above
: min
;
1655 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1656 return (level_current
< max
) ? min_above
: max
;
1657 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1658 return (level_current
> min
) ? max_below
: min
;
1659 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1660 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1663 return level_current
;
1668 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1670 unsigned long level_current
, level_next
;
1671 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1672 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1673 acpi_video_device_lcd_set_level(device
, level_next
);
1677 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1678 struct acpi_device
*device
)
1681 struct list_head
*node
, *next
;
1684 acpi_video_device_enumerate(video
);
1686 list_for_each_safe(node
, next
, &device
->children
) {
1687 struct acpi_device
*dev
=
1688 list_entry(node
, struct acpi_device
, node
);
1693 status
= acpi_video_bus_get_one_device(dev
, video
);
1694 if (ACPI_FAILURE(status
)) {
1695 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1703 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1706 struct acpi_video_bus
*video
;
1709 if (!device
|| !device
->video
)
1712 video
= device
->video
;
1715 list_del(&device
->entry
);
1717 acpi_video_device_remove_fs(device
->dev
);
1719 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1721 acpi_video_device_notify
);
1722 backlight_device_unregister(device
->backlight
);
1723 video_output_unregister(device
->output_dev
);
1727 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1730 struct list_head
*node
, *next
;
1733 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1734 struct acpi_video_device
*data
=
1735 list_entry(node
, struct acpi_video_device
, entry
);
1739 status
= acpi_video_bus_put_one_device(data
);
1740 if (ACPI_FAILURE(status
))
1741 printk(KERN_WARNING PREFIX
1742 "hhuuhhuu bug in acpi video driver.\n");
1744 if (data
->brightness
)
1745 kfree(data
->brightness
->levels
);
1746 kfree(data
->brightness
);
1753 /* acpi_video interface */
1755 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1757 return acpi_video_bus_DOS(video
, 1, 0);
1760 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1762 return acpi_video_bus_DOS(video
, 0, 1);
1765 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1767 struct acpi_video_bus
*video
= data
;
1768 struct acpi_device
*device
= NULL
;
1769 struct input_dev
*input
;
1773 printk("video bus notify\n");
1778 device
= video
->device
;
1779 input
= video
->input
;
1782 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1783 * most likely via hotkey. */
1784 acpi_bus_generate_proc_event(device
, event
, 0);
1785 keycode
= KEY_SWITCHVIDEOMODE
;
1788 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1790 acpi_video_device_enumerate(video
);
1791 acpi_video_device_rebind(video
);
1792 acpi_video_switch_output(video
, event
);
1793 acpi_bus_generate_proc_event(device
, event
, 0);
1794 keycode
= KEY_SWITCHVIDEOMODE
;
1797 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1798 acpi_video_switch_output(video
, event
);
1799 acpi_bus_generate_proc_event(device
, event
, 0);
1800 keycode
= KEY_SWITCHVIDEOMODE
;
1802 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1803 acpi_video_switch_output(video
, event
);
1804 acpi_bus_generate_proc_event(device
, event
, 0);
1805 keycode
= KEY_VIDEO_NEXT
;
1807 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1808 acpi_video_switch_output(video
, event
);
1809 acpi_bus_generate_proc_event(device
, event
, 0);
1810 keycode
= KEY_VIDEO_PREV
;
1814 keycode
= KEY_UNKNOWN
;
1815 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1816 "Unsupported event [0x%x]\n", event
));
1820 input_report_key(input
, keycode
, 1);
1822 input_report_key(input
, keycode
, 0);
1828 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1830 struct acpi_video_device
*video_device
= data
;
1831 struct acpi_device
*device
= NULL
;
1832 struct acpi_video_bus
*bus
;
1833 struct input_dev
*input
;
1839 device
= video_device
->dev
;
1840 bus
= video_device
->video
;
1844 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1845 acpi_video_switch_brightness(video_device
, event
);
1846 acpi_bus_generate_proc_event(device
, event
, 0);
1847 keycode
= KEY_BRIGHTNESS_CYCLE
;
1849 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1850 acpi_video_switch_brightness(video_device
, event
);
1851 acpi_bus_generate_proc_event(device
, event
, 0);
1852 keycode
= KEY_BRIGHTNESSUP
;
1854 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1855 acpi_video_switch_brightness(video_device
, event
);
1856 acpi_bus_generate_proc_event(device
, event
, 0);
1857 keycode
= KEY_BRIGHTNESSDOWN
;
1859 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1860 acpi_video_switch_brightness(video_device
, event
);
1861 acpi_bus_generate_proc_event(device
, event
, 0);
1862 keycode
= KEY_BRIGHTNESS_ZERO
;
1864 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1865 acpi_video_switch_brightness(video_device
, event
);
1866 acpi_bus_generate_proc_event(device
, event
, 0);
1867 keycode
= KEY_DISPLAY_OFF
;
1870 keycode
= KEY_UNKNOWN
;
1871 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1872 "Unsupported event [0x%x]\n", event
));
1876 input_report_key(input
, keycode
, 1);
1878 input_report_key(input
, keycode
, 0);
1884 static int instance
;
1885 static int acpi_video_bus_add(struct acpi_device
*device
)
1888 acpi_status status
= 0;
1889 struct acpi_video_bus
*video
= NULL
;
1890 struct input_dev
*input
;
1896 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1900 /* a hack to fix the duplicate name "VID" problem on T61 */
1901 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
1903 device
->pnp
.bus_id
[3] = '0' + instance
;
1907 video
->device
= device
;
1908 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1909 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1910 acpi_driver_data(device
) = video
;
1912 acpi_video_bus_find_cap(video
);
1913 result
= acpi_video_bus_check(video
);
1917 result
= acpi_video_bus_add_fs(device
);
1921 init_MUTEX(&video
->sem
);
1922 INIT_LIST_HEAD(&video
->video_device_list
);
1924 acpi_video_bus_get_devices(video
, device
);
1925 acpi_video_bus_start_devices(video
);
1927 status
= acpi_install_notify_handler(device
->handle
,
1929 acpi_video_bus_notify
, video
);
1930 if (ACPI_FAILURE(status
)) {
1931 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1932 "Error installing notify handler\n"));
1933 acpi_video_bus_stop_devices(video
);
1934 acpi_video_bus_put_devices(video
);
1935 kfree(video
->attached_array
);
1936 acpi_video_bus_remove_fs(device
);
1942 video
->input
= input
= input_allocate_device();
1944 snprintf(video
->phys
, sizeof(video
->phys
),
1945 "%s/video/input0", acpi_device_hid(video
->device
));
1947 input
->name
= acpi_device_name(video
->device
);
1948 input
->phys
= video
->phys
;
1949 input
->id
.bustype
= BUS_HOST
;
1950 input
->id
.product
= 0x06;
1951 input
->evbit
[0] = BIT(EV_KEY
);
1952 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
1953 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
1954 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
1955 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
1956 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
1957 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
1958 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
1959 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
1960 set_bit(KEY_UNKNOWN
, input
->keybit
);
1961 result
= input_register_device(input
);
1963 acpi_remove_notify_handler(video
->device
->handle
,
1965 acpi_video_bus_notify
);
1966 acpi_video_bus_stop_devices(video
);
1967 acpi_video_bus_put_devices(video
);
1968 kfree(video
->attached_array
);
1969 acpi_video_bus_remove_fs(device
);
1974 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1975 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1976 video
->flags
.multihead
? "yes" : "no",
1977 video
->flags
.rom
? "yes" : "no",
1978 video
->flags
.post
? "yes" : "no");
1987 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
1989 acpi_status status
= 0;
1990 struct acpi_video_bus
*video
= NULL
;
1993 if (!device
|| !acpi_driver_data(device
))
1996 video
= acpi_driver_data(device
);
1998 acpi_video_bus_stop_devices(video
);
2000 status
= acpi_remove_notify_handler(video
->device
->handle
,
2002 acpi_video_bus_notify
);
2004 acpi_video_bus_put_devices(video
);
2005 acpi_video_bus_remove_fs(device
);
2007 input_unregister_device(video
->input
);
2008 kfree(video
->attached_array
);
2014 static int __init
acpi_video_init(void)
2020 acpi_dbg_level = 0xFFFFFFFF;
2021 acpi_dbg_layer = 0x08000000;
2024 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2025 if (!acpi_video_dir
)
2027 acpi_video_dir
->owner
= THIS_MODULE
;
2029 result
= acpi_bus_register_driver(&acpi_video_bus
);
2031 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2038 static void __exit
acpi_video_exit(void)
2041 acpi_bus_unregister_driver(&acpi_video_bus
);
2043 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2048 module_init(acpi_video_init
);
2049 module_exit(acpi_video_exit
);