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>
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
;
143 struct acpi_video_device_flags
{
153 struct acpi_video_device_cap
{
154 u8 _ADR
:1; /*Return the unique ID */
155 u8 _BCL
:1; /*Query list of brightness control levels supported */
156 u8 _BCM
:1; /*Set the brightness level */
157 u8 _BQC
:1; /* Get current brightness level */
158 u8 _DDC
:1; /*Return the EDID for this device */
159 u8 _DCS
:1; /*Return status of output device */
160 u8 _DGS
:1; /*Query graphics state */
161 u8 _DSS
:1; /*Device state set */
164 struct acpi_video_device_brightness
{
170 struct acpi_video_device
{
171 unsigned long device_id
;
172 struct acpi_video_device_flags flags
;
173 struct acpi_video_device_cap cap
;
174 struct list_head entry
;
175 struct acpi_video_bus
*video
;
176 struct acpi_device
*dev
;
177 struct acpi_video_device_brightness
*brightness
;
178 struct backlight_device
*backlight
;
179 struct output_device
*output_dev
;
183 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
184 static struct file_operations acpi_video_bus_info_fops
= {
185 .open
= acpi_video_bus_info_open_fs
,
188 .release
= single_release
,
191 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
192 static struct file_operations acpi_video_bus_ROM_fops
= {
193 .open
= acpi_video_bus_ROM_open_fs
,
196 .release
= single_release
,
199 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
201 static struct file_operations acpi_video_bus_POST_info_fops
= {
202 .open
= acpi_video_bus_POST_info_open_fs
,
205 .release
= single_release
,
208 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
209 static struct file_operations acpi_video_bus_POST_fops
= {
210 .open
= acpi_video_bus_POST_open_fs
,
213 .release
= single_release
,
216 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
217 static struct file_operations acpi_video_bus_DOS_fops
= {
218 .open
= acpi_video_bus_DOS_open_fs
,
221 .release
= single_release
,
225 static int acpi_video_device_info_open_fs(struct inode
*inode
,
227 static struct file_operations acpi_video_device_info_fops
= {
228 .open
= acpi_video_device_info_open_fs
,
231 .release
= single_release
,
234 static int acpi_video_device_state_open_fs(struct inode
*inode
,
236 static struct file_operations acpi_video_device_state_fops
= {
237 .open
= acpi_video_device_state_open_fs
,
240 .release
= single_release
,
243 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
245 static struct file_operations acpi_video_device_brightness_fops
= {
246 .open
= acpi_video_device_brightness_open_fs
,
249 .release
= single_release
,
252 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
254 static struct file_operations acpi_video_device_EDID_fops
= {
255 .open
= acpi_video_device_EDID_open_fs
,
258 .release
= single_release
,
261 static char device_decode
[][30] = {
262 "motherboard VGA device",
268 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
269 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
270 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
271 struct acpi_video_device
*device
);
272 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
273 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
);
274 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
276 static int acpi_video_device_lcd_get_level_current(
277 struct acpi_video_device
*device
,
278 unsigned long *level
);
279 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
280 u32 level_current
, u32 event
);
281 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
283 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
284 unsigned long *state
);
285 static int acpi_video_output_get(struct output_device
*od
);
286 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
288 /*backlight device sysfs support*/
289 static int acpi_video_get_brightness(struct backlight_device
*bd
)
291 unsigned long cur_level
;
292 struct acpi_video_device
*vd
=
293 (struct acpi_video_device
*)bl_get_data(bd
);
294 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
295 return (int) cur_level
;
298 static int acpi_video_set_brightness(struct backlight_device
*bd
)
300 int request_level
= bd
->props
.brightness
;
301 struct acpi_video_device
*vd
=
302 (struct acpi_video_device
*)bl_get_data(bd
);
303 acpi_video_device_lcd_set_level(vd
, request_level
);
307 static struct backlight_ops acpi_backlight_ops
= {
308 .get_brightness
= acpi_video_get_brightness
,
309 .update_status
= acpi_video_set_brightness
,
312 /*video output device sysfs support*/
313 static int acpi_video_output_get(struct output_device
*od
)
316 struct acpi_video_device
*vd
=
317 (struct acpi_video_device
*)class_get_devdata(&od
->class_dev
);
318 acpi_video_device_get_state(vd
, &state
);
322 static int acpi_video_output_set(struct output_device
*od
)
324 unsigned long state
= od
->request_state
;
325 struct acpi_video_device
*vd
=
326 (struct acpi_video_device
*)class_get_devdata(&od
->class_dev
);
327 return acpi_video_device_set_state(vd
, state
);
330 static struct output_properties acpi_output_properties
= {
331 .set_state
= acpi_video_output_set
,
332 .get_status
= acpi_video_output_get
,
334 /* --------------------------------------------------------------------------
336 -------------------------------------------------------------------------- */
341 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
345 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
351 acpi_video_device_get_state(struct acpi_video_device
*device
,
352 unsigned long *state
)
356 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
362 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
365 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
366 struct acpi_object_list args
= { 1, &arg0
};
370 arg0
.integer
.value
= state
;
371 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
377 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
378 union acpi_object
**levels
)
381 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
382 union acpi_object
*obj
;
387 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
388 if (!ACPI_SUCCESS(status
))
390 obj
= (union acpi_object
*)buffer
.pointer
;
391 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
392 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
402 kfree(buffer
.pointer
);
408 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
411 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
412 struct acpi_object_list args
= { 1, &arg0
};
415 arg0
.integer
.value
= level
;
416 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM", &args
, NULL
);
418 printk(KERN_DEBUG
"set_level status: %x\n", status
);
423 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
424 unsigned long *level
)
428 status
= acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
, level
);
434 acpi_video_device_EDID(struct acpi_video_device
*device
,
435 union acpi_object
**edid
, ssize_t length
)
438 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
439 union acpi_object
*obj
;
440 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
441 struct acpi_object_list args
= { 1, &arg0
};
449 arg0
.integer
.value
= 1;
450 else if (length
== 256)
451 arg0
.integer
.value
= 2;
455 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
456 if (ACPI_FAILURE(status
))
459 obj
= buffer
.pointer
;
461 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
464 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
475 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
479 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
480 struct acpi_object_list args
= { 1, &arg0
};
483 arg0
.integer
.value
= option
;
485 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
486 if (ACPI_SUCCESS(status
))
487 status
= tmp
? (-EINVAL
) : (AE_OK
);
493 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
497 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
503 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
504 unsigned long *options
)
508 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
516 * video : video bus device pointer
518 * 0. The system BIOS should NOT automatically switch(toggle)
519 * the active display output.
520 * 1. The system BIOS should automatically switch (toggle) the
521 * active display output. No switch event.
522 * 2. The _DGS value should be locked.
523 * 3. The system BIOS should not automatically switch (toggle) the
524 * active display output, but instead generate the display switch
527 * 0. The system BIOS should automatically control the brightness level
528 * of the LCD when the power changes from AC to DC
529 * 1. The system BIOS should NOT automatically control the brightness
530 * level of the LCD when the power changes from AC to DC.
536 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
538 acpi_integer status
= 0;
539 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
540 struct acpi_object_list args
= { 1, &arg0
};
543 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
547 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
548 video
->dos_setting
= arg0
.integer
.value
;
549 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
557 * device : video output device (LCD, CRT, ..)
562 * Find out all required AML methods defined under the output
566 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
568 acpi_handle h_dummy1
;
571 union acpi_object
*obj
= NULL
;
572 struct acpi_video_device_brightness
*br
= NULL
;
575 memset(&device
->cap
, 0, 4);
577 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
578 device
->cap
._ADR
= 1;
580 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
581 device
->cap
._BCL
= 1;
583 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
584 device
->cap
._BCM
= 1;
586 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
587 device
->cap
._BQC
= 1;
588 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
589 device
->cap
._DDC
= 1;
591 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
592 device
->cap
._DCS
= 1;
594 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
595 device
->cap
._DGS
= 1;
597 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
598 device
->cap
._DSS
= 1;
601 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
603 if (obj
->package
.count
>= 2) {
605 union acpi_object
*o
;
607 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
609 printk(KERN_ERR
"can't allocate memory\n");
611 br
->levels
= kmalloc(obj
->package
.count
*
612 sizeof *(br
->levels
), GFP_KERNEL
);
616 for (i
= 0; i
< obj
->package
.count
; i
++) {
617 o
= (union acpi_object
*)&obj
->package
.
619 if (o
->type
!= ACPI_TYPE_INTEGER
) {
620 printk(KERN_ERR PREFIX
"Invalid data\n");
623 br
->levels
[count
] = (u32
) o
->integer
.value
;
625 if (br
->levels
[count
] > max_level
)
626 max_level
= br
->levels
[count
];
635 device
->brightness
= br
;
636 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
637 "found %d brightness levels\n",
644 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available LCD brightness level\n"));
649 if (device
->cap
._BCL
&& device
->cap
._BCM
&& device
->cap
._BQC
&& max_level
> 0){
651 static int count
= 0;
653 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
657 sprintf(name
, "acpi_video%d", count
++);
658 acpi_video_device_lcd_get_level_current(device
, &tmp
);
659 device
->backlight
= backlight_device_register(name
,
660 NULL
, device
, &acpi_backlight_ops
);
661 device
->backlight
->props
.max_brightness
= max_level
;
662 device
->backlight
->props
.brightness
= (int)tmp
;
663 backlight_update_status(device
->backlight
);
667 if (device
->cap
._DCS
&& device
->cap
._DSS
){
668 static int count
= 0;
670 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
673 sprintf(name
, "acpi_video%d", count
++);
674 device
->output_dev
= video_output_register(name
,
675 NULL
, device
, &acpi_output_properties
);
683 * device : video output device (VGA)
688 * Find out all required AML methods defined under the video bus device.
691 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
693 acpi_handle h_dummy1
;
695 memset(&video
->cap
, 0, 4);
696 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
699 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
702 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
705 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
708 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
711 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
717 * Check whether the video bus device has required AML method to
718 * support the desired features
721 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
723 acpi_status status
= -ENOENT
;
729 /* Since there is no HID, CID and so on for VGA driver, we have
730 * to check well known required nodes.
733 /* Does this device support video switching? */
734 if (video
->cap
._DOS
) {
735 video
->flags
.multihead
= 1;
739 /* Does this device support retrieving a video ROM? */
740 if (video
->cap
._ROM
) {
741 video
->flags
.rom
= 1;
745 /* Does this device support configuring which video device to POST? */
746 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
747 video
->flags
.post
= 1;
754 /* --------------------------------------------------------------------------
756 -------------------------------------------------------------------------- */
758 static struct proc_dir_entry
*acpi_video_dir
;
762 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
764 struct acpi_video_device
*dev
= seq
->private;
770 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
771 seq_printf(seq
, "type: ");
773 seq_printf(seq
, "CRT\n");
774 else if (dev
->flags
.lcd
)
775 seq_printf(seq
, "LCD\n");
776 else if (dev
->flags
.tvout
)
777 seq_printf(seq
, "TVOUT\n");
778 else if (dev
->flags
.dvi
)
779 seq_printf(seq
, "DVI\n");
781 seq_printf(seq
, "UNKNOWN\n");
783 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
790 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
792 return single_open(file
, acpi_video_device_info_seq_show
,
796 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
799 struct acpi_video_device
*dev
= seq
->private;
806 status
= acpi_video_device_get_state(dev
, &state
);
807 seq_printf(seq
, "state: ");
808 if (ACPI_SUCCESS(status
))
809 seq_printf(seq
, "0x%02lx\n", state
);
811 seq_printf(seq
, "<not supported>\n");
813 status
= acpi_video_device_query(dev
, &state
);
814 seq_printf(seq
, "query: ");
815 if (ACPI_SUCCESS(status
))
816 seq_printf(seq
, "0x%02lx\n", state
);
818 seq_printf(seq
, "<not supported>\n");
825 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
827 return single_open(file
, acpi_video_device_state_seq_show
,
832 acpi_video_device_write_state(struct file
*file
,
833 const char __user
* buffer
,
834 size_t count
, loff_t
* data
)
837 struct seq_file
*m
= file
->private_data
;
838 struct acpi_video_device
*dev
= m
->private;
839 char str
[12] = { 0 };
843 if (!dev
|| count
+ 1 > sizeof str
)
846 if (copy_from_user(str
, buffer
, count
))
850 state
= simple_strtoul(str
, NULL
, 0);
851 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
853 status
= acpi_video_device_set_state(dev
, state
);
862 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
864 struct acpi_video_device
*dev
= seq
->private;
868 if (!dev
|| !dev
->brightness
) {
869 seq_printf(seq
, "<not supported>\n");
873 seq_printf(seq
, "levels: ");
874 for (i
= 0; i
< dev
->brightness
->count
; i
++)
875 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
876 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
882 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
884 return single_open(file
, acpi_video_device_brightness_seq_show
,
889 acpi_video_device_write_brightness(struct file
*file
,
890 const char __user
* buffer
,
891 size_t count
, loff_t
* data
)
893 struct seq_file
*m
= file
->private_data
;
894 struct acpi_video_device
*dev
= m
->private;
896 unsigned int level
= 0;
900 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
903 if (copy_from_user(str
, buffer
, count
))
907 level
= simple_strtoul(str
, NULL
, 0);
912 /* validate through the list of available levels */
913 for (i
= 0; i
< dev
->brightness
->count
; i
++)
914 if (level
== dev
->brightness
->levels
[i
]) {
916 (acpi_video_device_lcd_set_level(dev
, level
)))
917 dev
->brightness
->curr
= level
;
924 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
926 struct acpi_video_device
*dev
= seq
->private;
929 union acpi_object
*edid
= NULL
;
935 status
= acpi_video_device_EDID(dev
, &edid
, 128);
936 if (ACPI_FAILURE(status
)) {
937 status
= acpi_video_device_EDID(dev
, &edid
, 256);
940 if (ACPI_FAILURE(status
)) {
944 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
945 for (i
= 0; i
< edid
->buffer
.length
; i
++)
946 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
951 seq_printf(seq
, "<not supported>\n");
959 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
961 return single_open(file
, acpi_video_device_EDID_seq_show
,
965 static int acpi_video_device_add_fs(struct acpi_device
*device
)
967 struct proc_dir_entry
*entry
= NULL
;
968 struct acpi_video_device
*vid_dev
;
974 vid_dev
= acpi_driver_data(device
);
978 if (!acpi_device_dir(device
)) {
979 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
980 vid_dev
->video
->dir
);
981 if (!acpi_device_dir(device
))
983 acpi_device_dir(device
)->owner
= THIS_MODULE
;
987 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
991 entry
->proc_fops
= &acpi_video_device_info_fops
;
992 entry
->data
= acpi_driver_data(device
);
993 entry
->owner
= THIS_MODULE
;
998 create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
999 acpi_device_dir(device
));
1003 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1004 entry
->proc_fops
= &acpi_video_device_state_fops
;
1005 entry
->data
= acpi_driver_data(device
);
1006 entry
->owner
= THIS_MODULE
;
1009 /* 'brightness' [R/W] */
1011 create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1012 acpi_device_dir(device
));
1016 acpi_video_device_brightness_fops
.write
= acpi_video_device_write_brightness
;
1017 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
1018 entry
->data
= acpi_driver_data(device
);
1019 entry
->owner
= THIS_MODULE
;
1023 entry
= create_proc_entry("EDID", S_IRUGO
, acpi_device_dir(device
));
1027 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
1028 entry
->data
= acpi_driver_data(device
);
1029 entry
->owner
= THIS_MODULE
;
1035 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1037 struct acpi_video_device
*vid_dev
;
1039 vid_dev
= acpi_driver_data(device
);
1040 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1043 if (acpi_device_dir(device
)) {
1044 remove_proc_entry("info", acpi_device_dir(device
));
1045 remove_proc_entry("state", acpi_device_dir(device
));
1046 remove_proc_entry("brightness", acpi_device_dir(device
));
1047 remove_proc_entry("EDID", acpi_device_dir(device
));
1048 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1049 acpi_device_dir(device
) = NULL
;
1056 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1058 struct acpi_video_bus
*video
= seq
->private;
1064 seq_printf(seq
, "Switching heads: %s\n",
1065 video
->flags
.multihead
? "yes" : "no");
1066 seq_printf(seq
, "Video ROM: %s\n",
1067 video
->flags
.rom
? "yes" : "no");
1068 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1069 video
->flags
.post
? "yes" : "no");
1075 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1077 return single_open(file
, acpi_video_bus_info_seq_show
,
1081 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1083 struct acpi_video_bus
*video
= seq
->private;
1089 printk(KERN_INFO PREFIX
"Please implement %s\n", __FUNCTION__
);
1090 seq_printf(seq
, "<TODO>\n");
1096 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1098 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1101 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1103 struct acpi_video_bus
*video
= seq
->private;
1104 unsigned long options
;
1111 status
= acpi_video_bus_POST_options(video
, &options
);
1112 if (ACPI_SUCCESS(status
)) {
1113 if (!(options
& 1)) {
1114 printk(KERN_WARNING PREFIX
1115 "The motherboard VGA device is not listed as a possible POST device.\n");
1116 printk(KERN_WARNING PREFIX
1117 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1119 printk("%lx\n", options
);
1120 seq_printf(seq
, "can POST: <integrated video>");
1122 seq_printf(seq
, " <PCI video>");
1124 seq_printf(seq
, " <AGP video>");
1125 seq_putc(seq
, '\n');
1127 seq_printf(seq
, "<not supported>\n");
1133 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1135 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1139 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1141 struct acpi_video_bus
*video
= seq
->private;
1149 status
= acpi_video_bus_get_POST(video
, &id
);
1150 if (!ACPI_SUCCESS(status
)) {
1151 seq_printf(seq
, "<not supported>\n");
1154 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1160 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1162 struct acpi_video_bus
*video
= seq
->private;
1165 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1170 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1172 return single_open(file
, acpi_video_bus_POST_seq_show
,
1176 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1178 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1182 acpi_video_bus_write_POST(struct file
*file
,
1183 const char __user
* buffer
,
1184 size_t count
, loff_t
* data
)
1187 struct seq_file
*m
= file
->private_data
;
1188 struct acpi_video_bus
*video
= m
->private;
1189 char str
[12] = { 0 };
1190 unsigned long opt
, options
;
1193 if (!video
|| count
+ 1 > sizeof str
)
1196 status
= acpi_video_bus_POST_options(video
, &options
);
1197 if (!ACPI_SUCCESS(status
))
1200 if (copy_from_user(str
, buffer
, count
))
1204 opt
= strtoul(str
, NULL
, 0);
1208 /* just in case an OEM 'forgot' the motherboard... */
1211 if (options
& (1ul << opt
)) {
1212 status
= acpi_video_bus_set_POST(video
, opt
);
1213 if (!ACPI_SUCCESS(status
))
1222 acpi_video_bus_write_DOS(struct file
*file
,
1223 const char __user
* buffer
,
1224 size_t count
, loff_t
* data
)
1227 struct seq_file
*m
= file
->private_data
;
1228 struct acpi_video_bus
*video
= m
->private;
1229 char str
[12] = { 0 };
1233 if (!video
|| count
+ 1 > sizeof str
)
1236 if (copy_from_user(str
, buffer
, count
))
1240 opt
= strtoul(str
, NULL
, 0);
1244 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1246 if (!ACPI_SUCCESS(status
))
1252 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1254 struct proc_dir_entry
*entry
= NULL
;
1255 struct acpi_video_bus
*video
;
1258 video
= acpi_driver_data(device
);
1260 if (!acpi_device_dir(device
)) {
1261 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1263 if (!acpi_device_dir(device
))
1265 video
->dir
= acpi_device_dir(device
);
1266 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1270 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1274 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1275 entry
->data
= acpi_driver_data(device
);
1276 entry
->owner
= THIS_MODULE
;
1280 entry
= create_proc_entry("ROM", S_IRUGO
, acpi_device_dir(device
));
1284 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1285 entry
->data
= acpi_driver_data(device
);
1286 entry
->owner
= THIS_MODULE
;
1289 /* 'POST_info' [R] */
1291 create_proc_entry("POST_info", S_IRUGO
, acpi_device_dir(device
));
1295 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1296 entry
->data
= acpi_driver_data(device
);
1297 entry
->owner
= THIS_MODULE
;
1302 create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IRUSR
,
1303 acpi_device_dir(device
));
1307 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1308 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1309 entry
->data
= acpi_driver_data(device
);
1310 entry
->owner
= THIS_MODULE
;
1315 create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IRUSR
,
1316 acpi_device_dir(device
));
1320 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1321 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1322 entry
->data
= acpi_driver_data(device
);
1323 entry
->owner
= THIS_MODULE
;
1329 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1331 struct acpi_video_bus
*video
;
1334 video
= acpi_driver_data(device
);
1336 if (acpi_device_dir(device
)) {
1337 remove_proc_entry("info", acpi_device_dir(device
));
1338 remove_proc_entry("ROM", acpi_device_dir(device
));
1339 remove_proc_entry("POST_info", acpi_device_dir(device
));
1340 remove_proc_entry("POST", acpi_device_dir(device
));
1341 remove_proc_entry("DOS", acpi_device_dir(device
));
1342 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1343 acpi_device_dir(device
) = NULL
;
1349 /* --------------------------------------------------------------------------
1351 -------------------------------------------------------------------------- */
1353 /* device interface */
1354 static struct acpi_video_device_attrib
*
1355 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1359 for(count
= 0; count
< video
->attached_count
; count
++)
1360 if((video
->attached_array
[count
].value
.int_val
& 0xffff) == device_id
)
1361 return &(video
->attached_array
[count
].value
.attrib
);
1366 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1367 struct acpi_video_bus
*video
)
1369 unsigned long device_id
;
1371 struct acpi_video_device
*data
;
1372 struct acpi_video_device_attrib
* attribute
;
1374 if (!device
|| !video
)
1378 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1379 if (ACPI_SUCCESS(status
)) {
1381 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1385 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1386 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1387 acpi_driver_data(device
) = data
;
1389 data
->device_id
= device_id
;
1390 data
->video
= video
;
1393 attribute
= acpi_video_get_device_attr(video
, device_id
);
1395 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1396 switch (attribute
->display_type
) {
1397 case ACPI_VIDEO_DISPLAY_CRT
:
1398 data
->flags
.crt
= 1;
1400 case ACPI_VIDEO_DISPLAY_TV
:
1401 data
->flags
.tvout
= 1;
1403 case ACPI_VIDEO_DISPLAY_DVI
:
1404 data
->flags
.dvi
= 1;
1406 case ACPI_VIDEO_DISPLAY_LCD
:
1407 data
->flags
.lcd
= 1;
1410 data
->flags
.unknown
= 1;
1413 if(attribute
->bios_can_detect
)
1414 data
->flags
.bios
= 1;
1416 data
->flags
.unknown
= 1;
1418 acpi_video_device_bind(video
, data
);
1419 acpi_video_device_find_cap(data
);
1421 status
= acpi_install_notify_handler(device
->handle
,
1423 acpi_video_device_notify
,
1425 if (ACPI_FAILURE(status
)) {
1426 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1427 "Error installing notify handler\n"));
1428 if(data
->brightness
)
1429 kfree(data
->brightness
->levels
);
1430 kfree(data
->brightness
);
1436 list_add_tail(&data
->entry
, &video
->video_device_list
);
1439 acpi_video_device_add_fs(device
);
1449 * video : video bus device
1454 * Enumerate the video device list of the video bus,
1455 * bind the ids with the corresponding video devices
1456 * under the video bus.
1459 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1461 struct list_head
*node
, *next
;
1462 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1463 struct acpi_video_device
*dev
=
1464 container_of(node
, struct acpi_video_device
, entry
);
1465 acpi_video_device_bind(video
, dev
);
1471 * video : video bus device
1472 * device : video output device under the video
1478 * Bind the ids with the corresponding video devices
1479 * under the video bus.
1483 acpi_video_device_bind(struct acpi_video_bus
*video
,
1484 struct acpi_video_device
*device
)
1488 #define IDS_VAL(i) video->attached_array[i].value.int_val
1489 #define IDS_BIND(i) video->attached_array[i].bind_info
1491 for (i
= 0; IDS_VAL(i
) != ACPI_VIDEO_HEAD_INVALID
&&
1492 i
< video
->attached_count
; i
++) {
1493 if (device
->device_id
== (IDS_VAL(i
) & 0xffff)) {
1494 IDS_BIND(i
) = device
;
1495 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1504 * video : video bus device
1509 * Call _DOD to enumerate all devices attached to display adapter
1513 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1518 struct acpi_video_enumerated_device
*active_device_list
;
1519 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1520 union acpi_object
*dod
= NULL
;
1521 union acpi_object
*obj
;
1523 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1524 if (!ACPI_SUCCESS(status
)) {
1525 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1529 dod
= buffer
.pointer
;
1530 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1531 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1536 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1537 dod
->package
.count
));
1539 active_device_list
= kmalloc((1 +
1540 dod
->package
.count
) *
1542 acpi_video_enumerated_device
),
1545 if (!active_device_list
) {
1551 for (i
= 0; i
< dod
->package
.count
; i
++) {
1552 obj
= &dod
->package
.elements
[i
];
1554 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1555 printk(KERN_ERR PREFIX
"Invalid _DOD data\n");
1556 active_device_list
[i
].value
.int_val
=
1557 ACPI_VIDEO_HEAD_INVALID
;
1559 active_device_list
[i
].value
.int_val
= obj
->integer
.value
;
1560 active_device_list
[i
].bind_info
= NULL
;
1561 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1562 (int)obj
->integer
.value
));
1565 active_device_list
[count
].value
.int_val
= ACPI_VIDEO_HEAD_END
;
1567 kfree(video
->attached_array
);
1569 video
->attached_array
= active_device_list
;
1570 video
->attached_count
= count
;
1572 kfree(buffer
.pointer
);
1578 * video : video bus device
1579 * event : notify event
1584 * 1. Find out the current active output device.
1585 * 2. Identify the next output device to switch to.
1586 * 3. call _DSS to do actual switch.
1589 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
)
1591 struct list_head
*node
, *next
;
1592 struct acpi_video_device
*dev
= NULL
;
1593 struct acpi_video_device
*dev_next
= NULL
;
1594 struct acpi_video_device
*dev_prev
= NULL
;
1595 unsigned long state
;
1599 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1600 dev
= container_of(node
, struct acpi_video_device
, entry
);
1601 status
= acpi_video_device_get_state(dev
, &state
);
1604 container_of(node
->next
, struct acpi_video_device
,
1607 container_of(node
->prev
, struct acpi_video_device
,
1612 dev_next
= container_of(node
->next
, struct acpi_video_device
, entry
);
1613 dev_prev
= container_of(node
->prev
, struct acpi_video_device
, entry
);
1616 case ACPI_VIDEO_NOTIFY_CYCLE
:
1617 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
:
1618 acpi_video_device_set_state(dev
, 0);
1619 acpi_video_device_set_state(dev_next
, 0x80000001);
1621 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
:
1622 acpi_video_device_set_state(dev
, 0);
1623 acpi_video_device_set_state(dev_prev
, 0x80000001);
1632 acpi_video_get_next_level(struct acpi_video_device
*device
,
1633 u32 level_current
, u32 event
)
1635 int min
, max
, min_above
, max_below
, i
, l
;
1636 max
= max_below
= 0;
1637 min
= min_above
= 255;
1638 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1639 l
= device
->brightness
->levels
[i
];
1644 if (l
< min_above
&& l
> level_current
)
1646 if (l
> max_below
&& l
< level_current
)
1651 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1652 return (level_current
< max
) ? min_above
: min
;
1653 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1654 return (level_current
< max
) ? min_above
: max
;
1655 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1656 return (level_current
> min
) ? max_below
: min
;
1657 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1658 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1661 return level_current
;
1666 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1668 unsigned long level_current
, level_next
;
1669 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1670 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1671 acpi_video_device_lcd_set_level(device
, level_next
);
1675 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1676 struct acpi_device
*device
)
1679 struct list_head
*node
, *next
;
1682 acpi_video_device_enumerate(video
);
1684 list_for_each_safe(node
, next
, &device
->children
) {
1685 struct acpi_device
*dev
=
1686 list_entry(node
, struct acpi_device
, node
);
1691 status
= acpi_video_bus_get_one_device(dev
, video
);
1692 if (ACPI_FAILURE(status
)) {
1693 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1701 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1704 struct acpi_video_bus
*video
;
1707 if (!device
|| !device
->video
)
1710 video
= device
->video
;
1713 list_del(&device
->entry
);
1715 acpi_video_device_remove_fs(device
->dev
);
1717 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1719 acpi_video_device_notify
);
1720 backlight_device_unregister(device
->backlight
);
1721 video_output_unregister(device
->output_dev
);
1725 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1728 struct list_head
*node
, *next
;
1731 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1732 struct acpi_video_device
*data
=
1733 list_entry(node
, struct acpi_video_device
, entry
);
1737 status
= acpi_video_bus_put_one_device(data
);
1738 if (ACPI_FAILURE(status
))
1739 printk(KERN_WARNING PREFIX
1740 "hhuuhhuu bug in acpi video driver.\n");
1742 if (data
->brightness
)
1743 kfree(data
->brightness
->levels
);
1744 kfree(data
->brightness
);
1751 /* acpi_video interface */
1753 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1755 return acpi_video_bus_DOS(video
, 1, 0);
1758 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1760 return acpi_video_bus_DOS(video
, 0, 1);
1763 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1765 struct acpi_video_bus
*video
= data
;
1766 struct acpi_device
*device
= NULL
;
1768 printk("video bus notify\n");
1773 device
= video
->device
;
1776 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1777 * most likely via hotkey. */
1778 acpi_bus_generate_event(device
, event
, 0);
1781 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1783 acpi_video_device_enumerate(video
);
1784 acpi_video_device_rebind(video
);
1785 acpi_video_switch_output(video
, event
);
1786 acpi_bus_generate_event(device
, event
, 0);
1789 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1790 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1791 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1792 acpi_video_switch_output(video
, event
);
1793 acpi_bus_generate_event(device
, event
, 0);
1797 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1798 "Unsupported event [0x%x]\n", event
));
1805 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1807 struct acpi_video_device
*video_device
= data
;
1808 struct acpi_device
*device
= NULL
;
1813 device
= video_device
->dev
;
1816 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1817 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1818 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1819 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1820 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1821 acpi_video_switch_brightness(video_device
, event
);
1822 acpi_bus_generate_event(device
, event
, 0);
1825 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1826 "Unsupported event [0x%x]\n", event
));
1832 static int acpi_video_bus_add(struct acpi_device
*device
)
1835 acpi_status status
= 0;
1836 struct acpi_video_bus
*video
= NULL
;
1842 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1846 video
->device
= device
;
1847 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1848 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1849 acpi_driver_data(device
) = video
;
1851 acpi_video_bus_find_cap(video
);
1852 result
= acpi_video_bus_check(video
);
1856 result
= acpi_video_bus_add_fs(device
);
1860 init_MUTEX(&video
->sem
);
1861 INIT_LIST_HEAD(&video
->video_device_list
);
1863 acpi_video_bus_get_devices(video
, device
);
1864 acpi_video_bus_start_devices(video
);
1866 status
= acpi_install_notify_handler(device
->handle
,
1868 acpi_video_bus_notify
, video
);
1869 if (ACPI_FAILURE(status
)) {
1870 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1871 "Error installing notify handler\n"));
1872 acpi_video_bus_stop_devices(video
);
1873 acpi_video_bus_put_devices(video
);
1874 kfree(video
->attached_array
);
1875 acpi_video_bus_remove_fs(device
);
1880 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1881 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1882 video
->flags
.multihead
? "yes" : "no",
1883 video
->flags
.rom
? "yes" : "no",
1884 video
->flags
.post
? "yes" : "no");
1893 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
1895 acpi_status status
= 0;
1896 struct acpi_video_bus
*video
= NULL
;
1899 if (!device
|| !acpi_driver_data(device
))
1902 video
= acpi_driver_data(device
);
1904 acpi_video_bus_stop_devices(video
);
1906 status
= acpi_remove_notify_handler(video
->device
->handle
,
1908 acpi_video_bus_notify
);
1910 acpi_video_bus_put_devices(video
);
1911 acpi_video_bus_remove_fs(device
);
1913 kfree(video
->attached_array
);
1919 static int __init
acpi_video_init(void)
1925 acpi_dbg_level = 0xFFFFFFFF;
1926 acpi_dbg_layer = 0x08000000;
1929 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1930 if (!acpi_video_dir
)
1932 acpi_video_dir
->owner
= THIS_MODULE
;
1934 result
= acpi_bus_register_driver(&acpi_video_bus
);
1936 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1943 static void __exit
acpi_video_exit(void)
1946 acpi_bus_unregister_driver(&acpi_video_bus
);
1948 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1953 module_init(acpi_video_init
);
1954 module_exit(acpi_video_exit
);