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>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/list.h>
31 #include <linux/proc_fs.h>
32 #include <linux/seq_file.h>
34 #include <asm/uaccess.h>
36 #include <acpi/acpi_bus.h>
37 #include <acpi/acpi_drivers.h>
39 #define ACPI_VIDEO_COMPONENT 0x08000000
40 #define ACPI_VIDEO_CLASS "video"
41 #define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver"
42 #define ACPI_VIDEO_BUS_NAME "Video Bus"
43 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
44 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
45 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
46 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
47 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
48 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
50 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82
51 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83
52 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84
53 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85
54 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86
56 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
57 #define ACPI_VIDEO_HEAD_END (~0u)
59 #define _COMPONENT ACPI_VIDEO_COMPONENT
60 ACPI_MODULE_NAME("acpi_video")
62 MODULE_AUTHOR("Bruno Ducrot");
63 MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME
);
64 MODULE_LICENSE("GPL");
66 static int acpi_video_bus_add(struct acpi_device
*device
);
67 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
68 static int acpi_video_bus_match(struct acpi_device
*device
,
69 struct acpi_driver
*driver
);
71 static struct acpi_driver acpi_video_bus
= {
72 .name
= ACPI_VIDEO_DRIVER_NAME
,
73 .class = ACPI_VIDEO_CLASS
,
75 .add
= acpi_video_bus_add
,
76 .remove
= acpi_video_bus_remove
,
77 .match
= acpi_video_bus_match
,
81 struct acpi_video_bus_flags
{
82 u8 multihead
:1; /* can switch video heads */
83 u8 rom
:1; /* can retrieve a video rom */
84 u8 post
:1; /* can configure the head to */
88 struct acpi_video_bus_cap
{
89 u8 _DOS
:1; /*Enable/Disable output switching */
90 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
91 u8 _ROM
:1; /*Get ROM Data */
92 u8 _GPD
:1; /*Get POST Device */
93 u8 _SPD
:1; /*Set POST Device */
94 u8 _VPO
:1; /*Video POST Options */
98 struct acpi_video_device_attrib
{
99 u32 display_index
:4; /* A zero-based instance of the Display */
100 u32 display_port_attachment
:4; /*This field differenates displays type */
101 u32 display_type
:4; /*Describe the specific type in use */
102 u32 vendor_specific
:4; /*Chipset Vendor Specifi */
103 u32 bios_can_detect
:1; /*BIOS can detect the device */
104 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
106 u32 pipe_id
:3; /*For VGA multiple-head devices. */
107 u32 reserved
:10; /*Must be 0 */
108 u32 device_id_scheme
:1; /*Device ID Scheme */
111 struct acpi_video_enumerated_device
{
114 struct acpi_video_device_attrib attrib
;
116 struct acpi_video_device
*bind_info
;
119 struct acpi_video_bus
{
122 struct acpi_video_enumerated_device
*attached_array
;
124 struct acpi_video_bus_cap cap
;
125 struct acpi_video_bus_flags flags
;
126 struct semaphore sem
;
127 struct list_head video_device_list
;
128 struct proc_dir_entry
*dir
;
131 struct acpi_video_device_flags
{
140 struct acpi_video_device_cap
{
141 u8 _ADR
:1; /*Return the unique ID */
142 u8 _BCL
:1; /*Query list of brightness control levels supported */
143 u8 _BCM
:1; /*Set the brightness level */
144 u8 _DDC
:1; /*Return the EDID for this device */
145 u8 _DCS
:1; /*Return status of output device */
146 u8 _DGS
:1; /*Query graphics state */
147 u8 _DSS
:1; /*Device state set */
151 struct acpi_video_device_brightness
{
157 struct acpi_video_device
{
159 unsigned long device_id
;
160 struct acpi_video_device_flags flags
;
161 struct acpi_video_device_cap cap
;
162 struct list_head entry
;
163 struct acpi_video_bus
*video
;
164 struct acpi_device
*dev
;
165 struct acpi_video_device_brightness
*brightness
;
169 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
170 static struct file_operations acpi_video_bus_info_fops
= {
171 .open
= acpi_video_bus_info_open_fs
,
174 .release
= single_release
,
177 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
178 static struct file_operations acpi_video_bus_ROM_fops
= {
179 .open
= acpi_video_bus_ROM_open_fs
,
182 .release
= single_release
,
185 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
187 static struct file_operations acpi_video_bus_POST_info_fops
= {
188 .open
= acpi_video_bus_POST_info_open_fs
,
191 .release
= single_release
,
194 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
195 static struct file_operations acpi_video_bus_POST_fops
= {
196 .open
= acpi_video_bus_POST_open_fs
,
199 .release
= single_release
,
202 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
203 static struct file_operations acpi_video_bus_DOS_fops
= {
204 .open
= acpi_video_bus_DOS_open_fs
,
207 .release
= single_release
,
211 static int acpi_video_device_info_open_fs(struct inode
*inode
,
213 static struct file_operations acpi_video_device_info_fops
= {
214 .open
= acpi_video_device_info_open_fs
,
217 .release
= single_release
,
220 static int acpi_video_device_state_open_fs(struct inode
*inode
,
222 static struct file_operations acpi_video_device_state_fops
= {
223 .open
= acpi_video_device_state_open_fs
,
226 .release
= single_release
,
229 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
231 static struct file_operations acpi_video_device_brightness_fops
= {
232 .open
= acpi_video_device_brightness_open_fs
,
235 .release
= single_release
,
238 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
240 static struct file_operations acpi_video_device_EDID_fops
= {
241 .open
= acpi_video_device_EDID_open_fs
,
244 .release
= single_release
,
247 static char device_decode
[][30] = {
248 "motherboard VGA device",
254 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
255 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
256 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
257 struct acpi_video_device
*device
);
258 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
259 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
);
260 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
261 u32 level_current
, u32 event
);
262 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
265 /* --------------------------------------------------------------------------
267 -------------------------------------------------------------------------- */
272 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
275 ACPI_FUNCTION_TRACE("acpi_video_device_query");
276 status
= acpi_evaluate_integer(device
->handle
, "_DGS", NULL
, state
);
278 return_VALUE(status
);
282 acpi_video_device_get_state(struct acpi_video_device
*device
,
283 unsigned long *state
)
287 ACPI_FUNCTION_TRACE("acpi_video_device_get_state");
289 status
= acpi_evaluate_integer(device
->handle
, "_DCS", NULL
, state
);
291 return_VALUE(status
);
295 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
298 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
299 struct acpi_object_list args
= { 1, &arg0
};
302 ACPI_FUNCTION_TRACE("acpi_video_device_set_state");
304 arg0
.integer
.value
= state
;
305 status
= acpi_evaluate_integer(device
->handle
, "_DSS", &args
, &ret
);
307 return_VALUE(status
);
311 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
312 union acpi_object
**levels
)
315 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
316 union acpi_object
*obj
;
318 ACPI_FUNCTION_TRACE("acpi_video_device_lcd_query_levels");
322 status
= acpi_evaluate_object(device
->handle
, "_BCL", NULL
, &buffer
);
323 if (!ACPI_SUCCESS(status
))
324 return_VALUE(status
);
325 obj
= (union acpi_object
*)buffer
.pointer
;
326 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
327 ACPI_ERROR((AE_INFO
, "Invalid _BCL data"));
337 kfree(buffer
.pointer
);
339 return_VALUE(status
);
343 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
346 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
347 struct acpi_object_list args
= { 1, &arg0
};
349 ACPI_FUNCTION_TRACE("acpi_video_device_lcd_set_level");
351 arg0
.integer
.value
= level
;
352 status
= acpi_evaluate_object(device
->handle
, "_BCM", &args
, NULL
);
354 printk(KERN_DEBUG
"set_level status: %x\n", status
);
355 return_VALUE(status
);
359 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
360 unsigned long *level
)
363 ACPI_FUNCTION_TRACE("acpi_video_device_lcd_get_level_current");
365 status
= acpi_evaluate_integer(device
->handle
, "_BQC", NULL
, level
);
367 return_VALUE(status
);
371 acpi_video_device_EDID(struct acpi_video_device
*device
,
372 union acpi_object
**edid
, ssize_t length
)
375 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
376 union acpi_object
*obj
;
377 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
378 struct acpi_object_list args
= { 1, &arg0
};
380 ACPI_FUNCTION_TRACE("acpi_video_device_get_EDID");
385 return_VALUE(-ENODEV
);
387 arg0
.integer
.value
= 1;
388 else if (length
== 256)
389 arg0
.integer
.value
= 2;
391 return_VALUE(-EINVAL
);
393 status
= acpi_evaluate_object(device
->handle
, "_DDC", &args
, &buffer
);
394 if (ACPI_FAILURE(status
))
395 return_VALUE(-ENODEV
);
397 obj
= (union acpi_object
*)buffer
.pointer
;
399 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
402 ACPI_ERROR((AE_INFO
, "Invalid _DDC data"));
407 return_VALUE(status
);
413 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
417 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
418 struct acpi_object_list args
= { 1, &arg0
};
420 ACPI_FUNCTION_TRACE("acpi_video_bus_set_POST");
422 arg0
.integer
.value
= option
;
424 status
= acpi_evaluate_integer(video
->handle
, "_SPD", &args
, &tmp
);
425 if (ACPI_SUCCESS(status
))
426 status
= tmp
? (-EINVAL
) : (AE_OK
);
428 return_VALUE(status
);
432 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
436 ACPI_FUNCTION_TRACE("acpi_video_bus_get_POST");
438 status
= acpi_evaluate_integer(video
->handle
, "_GPD", NULL
, id
);
440 return_VALUE(status
);
444 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
445 unsigned long *options
)
448 ACPI_FUNCTION_TRACE("acpi_video_bus_POST_options");
450 status
= acpi_evaluate_integer(video
->handle
, "_VPO", NULL
, options
);
453 return_VALUE(status
);
458 * video : video bus device pointer
460 * 0. The system BIOS should NOT automatically switch(toggle)
461 * the active display output.
462 * 1. The system BIOS should automatically switch (toggle) the
463 * active display output. No swich event.
464 * 2. The _DGS value should be locked.
465 * 3. The system BIOS should not automatically switch (toggle) the
466 * active display output, but instead generate the display switch
469 * 0. The system BIOS should automatically control the brightness level
470 * of the LCD, when the power changes from AC to DC
471 * 1. The system BIOS should NOT automatically control the brightness
472 * level of the LCD, when the power changes from AC to DC.
478 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
480 acpi_integer status
= 0;
481 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
482 struct acpi_object_list args
= { 1, &arg0
};
484 ACPI_FUNCTION_TRACE("acpi_video_bus_DOS");
486 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
490 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
491 video
->dos_setting
= arg0
.integer
.value
;
492 acpi_evaluate_object(video
->handle
, "_DOS", &args
, NULL
);
495 return_VALUE(status
);
500 * device : video output device (LCD, CRT, ..)
505 * Find out all required AML method defined under the output
509 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
512 acpi_handle h_dummy1
;
514 union acpi_object
*obj
= NULL
;
515 struct acpi_video_device_brightness
*br
= NULL
;
517 ACPI_FUNCTION_TRACE("acpi_video_device_find_cap");
519 memset(&device
->cap
, 0, 4);
521 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_ADR", &h_dummy1
))) {
522 device
->cap
._ADR
= 1;
524 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_BCL", &h_dummy1
))) {
525 device
->cap
._BCL
= 1;
527 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_BCM", &h_dummy1
))) {
528 device
->cap
._BCM
= 1;
530 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DDC", &h_dummy1
))) {
531 device
->cap
._DDC
= 1;
533 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DCS", &h_dummy1
))) {
534 device
->cap
._DCS
= 1;
536 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DGS", &h_dummy1
))) {
537 device
->cap
._DGS
= 1;
539 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DSS", &h_dummy1
))) {
540 device
->cap
._DSS
= 1;
543 status
= acpi_video_device_lcd_query_levels(device
, &obj
);
545 if (obj
&& obj
->type
== ACPI_TYPE_PACKAGE
&& obj
->package
.count
>= 2) {
547 union acpi_object
*o
;
549 br
= kmalloc(sizeof(*br
), GFP_KERNEL
);
551 printk(KERN_ERR
"can't allocate memory\n");
553 memset(br
, 0, sizeof(*br
));
554 br
->levels
= kmalloc(obj
->package
.count
*
555 sizeof *(br
->levels
), GFP_KERNEL
);
559 for (i
= 0; i
< obj
->package
.count
; i
++) {
560 o
= (union acpi_object
*)&obj
->package
.
562 if (o
->type
!= ACPI_TYPE_INTEGER
) {
563 ACPI_ERROR((AE_INFO
, "Invalid data"));
566 br
->levels
[count
] = (u32
) o
->integer
.value
;
575 device
->brightness
= br
;
576 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
577 "found %d brightness levels\n",
590 * device : video output device (VGA)
595 * Find out all required AML method defined under the video bus device.
598 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
600 acpi_handle h_dummy1
;
602 memset(&video
->cap
, 0, 4);
603 if (ACPI_SUCCESS(acpi_get_handle(video
->handle
, "_DOS", &h_dummy1
))) {
606 if (ACPI_SUCCESS(acpi_get_handle(video
->handle
, "_DOD", &h_dummy1
))) {
609 if (ACPI_SUCCESS(acpi_get_handle(video
->handle
, "_ROM", &h_dummy1
))) {
612 if (ACPI_SUCCESS(acpi_get_handle(video
->handle
, "_GPD", &h_dummy1
))) {
615 if (ACPI_SUCCESS(acpi_get_handle(video
->handle
, "_SPD", &h_dummy1
))) {
618 if (ACPI_SUCCESS(acpi_get_handle(video
->handle
, "_VPO", &h_dummy1
))) {
624 * Check whether the video bus device has required AML method to
625 * support the desired features
628 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
630 acpi_status status
= -ENOENT
;
632 ACPI_FUNCTION_TRACE("acpi_video_bus_check");
635 return_VALUE(-EINVAL
);
637 /* Since there is no HID, CID and so on for VGA driver, we have
638 * to check well known required nodes.
641 /* Does this device able to support video switching ? */
642 if (video
->cap
._DOS
) {
643 video
->flags
.multihead
= 1;
647 /* Does this device able to retrieve a retrieve a video ROM ? */
648 if (video
->cap
._ROM
) {
649 video
->flags
.rom
= 1;
653 /* Does this device able to configure which video device to POST ? */
654 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
655 video
->flags
.post
= 1;
659 return_VALUE(status
);
662 /* --------------------------------------------------------------------------
664 -------------------------------------------------------------------------- */
666 static struct proc_dir_entry
*acpi_video_dir
;
670 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
672 struct acpi_video_device
*dev
=
673 (struct acpi_video_device
*)seq
->private;
675 ACPI_FUNCTION_TRACE("acpi_video_device_info_seq_show");
680 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
681 seq_printf(seq
, "type: ");
683 seq_printf(seq
, "CRT\n");
684 else if (dev
->flags
.lcd
)
685 seq_printf(seq
, "LCD\n");
686 else if (dev
->flags
.tvout
)
687 seq_printf(seq
, "TVOUT\n");
689 seq_printf(seq
, "UNKNOWN\n");
691 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
698 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
700 return single_open(file
, acpi_video_device_info_seq_show
,
704 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
707 struct acpi_video_device
*dev
=
708 (struct acpi_video_device
*)seq
->private;
711 ACPI_FUNCTION_TRACE("acpi_video_device_state_seq_show");
716 status
= acpi_video_device_get_state(dev
, &state
);
717 seq_printf(seq
, "state: ");
718 if (ACPI_SUCCESS(status
))
719 seq_printf(seq
, "0x%02lx\n", state
);
721 seq_printf(seq
, "<not supported>\n");
723 status
= acpi_video_device_query(dev
, &state
);
724 seq_printf(seq
, "query: ");
725 if (ACPI_SUCCESS(status
))
726 seq_printf(seq
, "0x%02lx\n", state
);
728 seq_printf(seq
, "<not supported>\n");
735 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
737 return single_open(file
, acpi_video_device_state_seq_show
,
742 acpi_video_device_write_state(struct file
*file
,
743 const char __user
* buffer
,
744 size_t count
, loff_t
* data
)
747 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
748 struct acpi_video_device
*dev
= (struct acpi_video_device
*)m
->private;
749 char str
[12] = { 0 };
752 ACPI_FUNCTION_TRACE("acpi_video_device_write_state");
754 if (!dev
|| count
+ 1 > sizeof str
)
755 return_VALUE(-EINVAL
);
757 if (copy_from_user(str
, buffer
, count
))
758 return_VALUE(-EFAULT
);
761 state
= simple_strtoul(str
, NULL
, 0);
762 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
764 status
= acpi_video_device_set_state(dev
, state
);
767 return_VALUE(-EFAULT
);
773 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
775 struct acpi_video_device
*dev
=
776 (struct acpi_video_device
*)seq
->private;
779 ACPI_FUNCTION_TRACE("acpi_video_device_brightness_seq_show");
781 if (!dev
|| !dev
->brightness
) {
782 seq_printf(seq
, "<not supported>\n");
786 seq_printf(seq
, "levels: ");
787 for (i
= 0; i
< dev
->brightness
->count
; i
++)
788 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
789 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
795 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
797 return single_open(file
, acpi_video_device_brightness_seq_show
,
802 acpi_video_device_write_brightness(struct file
*file
,
803 const char __user
* buffer
,
804 size_t count
, loff_t
* data
)
806 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
807 struct acpi_video_device
*dev
= (struct acpi_video_device
*)m
->private;
809 unsigned int level
= 0;
812 ACPI_FUNCTION_TRACE("acpi_video_device_write_brightness");
814 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
815 return_VALUE(-EINVAL
);
817 if (copy_from_user(str
, buffer
, count
))
818 return_VALUE(-EFAULT
);
821 level
= simple_strtoul(str
, NULL
, 0);
824 return_VALUE(-EFAULT
);
826 /* validate though the list of available levels */
827 for (i
= 0; i
< dev
->brightness
->count
; i
++)
828 if (level
== dev
->brightness
->levels
[i
]) {
830 (acpi_video_device_lcd_set_level(dev
, level
)))
831 dev
->brightness
->curr
= level
;
838 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
840 struct acpi_video_device
*dev
=
841 (struct acpi_video_device
*)seq
->private;
844 union acpi_object
*edid
= NULL
;
846 ACPI_FUNCTION_TRACE("acpi_video_device_EDID_seq_show");
851 status
= acpi_video_device_EDID(dev
, &edid
, 128);
852 if (ACPI_FAILURE(status
)) {
853 status
= acpi_video_device_EDID(dev
, &edid
, 256);
856 if (ACPI_FAILURE(status
)) {
860 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
861 for (i
= 0; i
< edid
->buffer
.length
; i
++)
862 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
867 seq_printf(seq
, "<not supported>\n");
875 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
877 return single_open(file
, acpi_video_device_EDID_seq_show
,
881 static int acpi_video_device_add_fs(struct acpi_device
*device
)
883 struct proc_dir_entry
*entry
= NULL
;
884 struct acpi_video_device
*vid_dev
;
886 ACPI_FUNCTION_TRACE("acpi_video_device_add_fs");
889 return_VALUE(-ENODEV
);
891 vid_dev
= (struct acpi_video_device
*)acpi_driver_data(device
);
893 return_VALUE(-ENODEV
);
895 if (!acpi_device_dir(device
)) {
896 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
897 vid_dev
->video
->dir
);
898 if (!acpi_device_dir(device
))
899 return_VALUE(-ENODEV
);
900 acpi_device_dir(device
)->owner
= THIS_MODULE
;
904 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
906 return_VALUE(-ENODEV
);
908 entry
->proc_fops
= &acpi_video_device_info_fops
;
909 entry
->data
= acpi_driver_data(device
);
910 entry
->owner
= THIS_MODULE
;
915 create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
916 acpi_device_dir(device
));
918 return_VALUE(-ENODEV
);
920 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
921 entry
->proc_fops
= &acpi_video_device_state_fops
;
922 entry
->data
= acpi_driver_data(device
);
923 entry
->owner
= THIS_MODULE
;
926 /* 'brightness' [R/W] */
928 create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
929 acpi_device_dir(device
));
931 return_VALUE(-ENODEV
);
933 acpi_video_device_brightness_fops
.write
= acpi_video_device_write_brightness
;
934 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
935 entry
->data
= acpi_driver_data(device
);
936 entry
->owner
= THIS_MODULE
;
940 entry
= create_proc_entry("EDID", S_IRUGO
, acpi_device_dir(device
));
942 return_VALUE(-ENODEV
);
944 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
945 entry
->data
= acpi_driver_data(device
);
946 entry
->owner
= THIS_MODULE
;
952 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
954 struct acpi_video_device
*vid_dev
;
955 ACPI_FUNCTION_TRACE("acpi_video_device_remove_fs");
957 vid_dev
= (struct acpi_video_device
*)acpi_driver_data(device
);
958 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
959 return_VALUE(-ENODEV
);
961 if (acpi_device_dir(device
)) {
962 remove_proc_entry("info", acpi_device_dir(device
));
963 remove_proc_entry("state", acpi_device_dir(device
));
964 remove_proc_entry("brightness", acpi_device_dir(device
));
965 remove_proc_entry("EDID", acpi_device_dir(device
));
966 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
967 acpi_device_dir(device
) = NULL
;
974 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
976 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)seq
->private;
978 ACPI_FUNCTION_TRACE("acpi_video_bus_info_seq_show");
983 seq_printf(seq
, "Switching heads: %s\n",
984 video
->flags
.multihead
? "yes" : "no");
985 seq_printf(seq
, "Video ROM: %s\n",
986 video
->flags
.rom
? "yes" : "no");
987 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
988 video
->flags
.post
? "yes" : "no");
994 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
996 return single_open(file
, acpi_video_bus_info_seq_show
,
1000 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1002 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)seq
->private;
1004 ACPI_FUNCTION_TRACE("acpi_video_bus_ROM_seq_show");
1009 printk(KERN_INFO PREFIX
"Please implement %s\n", __FUNCTION__
);
1010 seq_printf(seq
, "<TODO>\n");
1016 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1018 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1021 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1023 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)seq
->private;
1024 unsigned long options
;
1027 ACPI_FUNCTION_TRACE("acpi_video_bus_POST_info_seq_show");
1032 status
= acpi_video_bus_POST_options(video
, &options
);
1033 if (ACPI_SUCCESS(status
)) {
1034 if (!(options
& 1)) {
1035 printk(KERN_WARNING PREFIX
1036 "The motherboard VGA device is not listed as a possible POST device.\n");
1037 printk(KERN_WARNING PREFIX
1038 "This indicate a BIOS bug. Please contact the manufacturer.\n");
1040 printk("%lx\n", options
);
1041 seq_printf(seq
, "can POST: <intgrated video>");
1043 seq_printf(seq
, " <PCI video>");
1045 seq_printf(seq
, " <AGP video>");
1046 seq_putc(seq
, '\n');
1048 seq_printf(seq
, "<not supported>\n");
1054 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1056 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1060 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1062 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)seq
->private;
1066 ACPI_FUNCTION_TRACE("acpi_video_bus_POST_seq_show");
1071 status
= acpi_video_bus_get_POST(video
, &id
);
1072 if (!ACPI_SUCCESS(status
)) {
1073 seq_printf(seq
, "<not supported>\n");
1076 seq_printf(seq
, "device posted is <%s>\n", device_decode
[id
& 3]);
1082 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1084 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)seq
->private;
1086 ACPI_FUNCTION_TRACE("acpi_video_bus_DOS_seq_show");
1088 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1093 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1095 return single_open(file
, acpi_video_bus_POST_seq_show
,
1099 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1101 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1105 acpi_video_bus_write_POST(struct file
*file
,
1106 const char __user
* buffer
,
1107 size_t count
, loff_t
* data
)
1110 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
1111 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)m
->private;
1112 char str
[12] = { 0 };
1113 unsigned long opt
, options
;
1115 ACPI_FUNCTION_TRACE("acpi_video_bus_write_POST");
1117 if (!video
|| count
+ 1 > sizeof str
)
1118 return_VALUE(-EINVAL
);
1120 status
= acpi_video_bus_POST_options(video
, &options
);
1121 if (!ACPI_SUCCESS(status
))
1122 return_VALUE(-EINVAL
);
1124 if (copy_from_user(str
, buffer
, count
))
1125 return_VALUE(-EFAULT
);
1128 opt
= strtoul(str
, NULL
, 0);
1130 return_VALUE(-EFAULT
);
1132 /* just in case an OEM 'forget' the motherboard... */
1135 if (options
& (1ul << opt
)) {
1136 status
= acpi_video_bus_set_POST(video
, opt
);
1137 if (!ACPI_SUCCESS(status
))
1138 return_VALUE(-EFAULT
);
1142 return_VALUE(count
);
1146 acpi_video_bus_write_DOS(struct file
*file
,
1147 const char __user
* buffer
,
1148 size_t count
, loff_t
* data
)
1151 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
1152 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)m
->private;
1153 char str
[12] = { 0 };
1156 ACPI_FUNCTION_TRACE("acpi_video_bus_write_DOS");
1158 if (!video
|| count
+ 1 > sizeof str
)
1159 return_VALUE(-EINVAL
);
1161 if (copy_from_user(str
, buffer
, count
))
1162 return_VALUE(-EFAULT
);
1165 opt
= strtoul(str
, NULL
, 0);
1167 return_VALUE(-EFAULT
);
1169 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1171 if (!ACPI_SUCCESS(status
))
1172 return_VALUE(-EFAULT
);
1174 return_VALUE(count
);
1177 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1179 struct proc_dir_entry
*entry
= NULL
;
1180 struct acpi_video_bus
*video
;
1182 ACPI_FUNCTION_TRACE("acpi_video_bus_add_fs");
1184 video
= (struct acpi_video_bus
*)acpi_driver_data(device
);
1186 if (!acpi_device_dir(device
)) {
1187 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1189 if (!acpi_device_dir(device
))
1190 return_VALUE(-ENODEV
);
1191 video
->dir
= acpi_device_dir(device
);
1192 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1196 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1198 return_VALUE(-ENODEV
);
1200 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1201 entry
->data
= acpi_driver_data(device
);
1202 entry
->owner
= THIS_MODULE
;
1206 entry
= create_proc_entry("ROM", S_IRUGO
, acpi_device_dir(device
));
1208 return_VALUE(-ENODEV
);
1210 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1211 entry
->data
= acpi_driver_data(device
);
1212 entry
->owner
= THIS_MODULE
;
1215 /* 'POST_info' [R] */
1217 create_proc_entry("POST_info", S_IRUGO
, acpi_device_dir(device
));
1219 return_VALUE(-ENODEV
);
1221 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1222 entry
->data
= acpi_driver_data(device
);
1223 entry
->owner
= THIS_MODULE
;
1228 create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IRUSR
,
1229 acpi_device_dir(device
));
1231 return_VALUE(-ENODEV
);
1233 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1234 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1235 entry
->data
= acpi_driver_data(device
);
1236 entry
->owner
= THIS_MODULE
;
1241 create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IRUSR
,
1242 acpi_device_dir(device
));
1244 return_VALUE(-ENODEV
);
1246 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1247 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1248 entry
->data
= acpi_driver_data(device
);
1249 entry
->owner
= THIS_MODULE
;
1255 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1257 struct acpi_video_bus
*video
;
1259 ACPI_FUNCTION_TRACE("acpi_video_bus_remove_fs");
1261 video
= (struct acpi_video_bus
*)acpi_driver_data(device
);
1263 if (acpi_device_dir(device
)) {
1264 remove_proc_entry("info", acpi_device_dir(device
));
1265 remove_proc_entry("ROM", acpi_device_dir(device
));
1266 remove_proc_entry("POST_info", acpi_device_dir(device
));
1267 remove_proc_entry("POST", acpi_device_dir(device
));
1268 remove_proc_entry("DOS", acpi_device_dir(device
));
1269 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1270 acpi_device_dir(device
) = NULL
;
1276 /* --------------------------------------------------------------------------
1278 -------------------------------------------------------------------------- */
1280 /* device interface */
1283 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1284 struct acpi_video_bus
*video
)
1286 unsigned long device_id
;
1288 struct acpi_video_device
*data
;
1290 ACPI_FUNCTION_TRACE("acpi_video_bus_get_one_device");
1292 if (!device
|| !video
)
1293 return_VALUE(-EINVAL
);
1296 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1297 if (ACPI_SUCCESS(status
)) {
1299 data
= kmalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1301 return_VALUE(-ENOMEM
);
1303 memset(data
, 0, sizeof(struct acpi_video_device
));
1305 data
->handle
= device
->handle
;
1306 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1307 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1308 acpi_driver_data(device
) = data
;
1310 data
->device_id
= device_id
;
1311 data
->video
= video
;
1314 switch (device_id
& 0xffff) {
1316 data
->flags
.crt
= 1;
1319 data
->flags
.lcd
= 1;
1322 data
->flags
.tvout
= 1;
1325 data
->flags
.unknown
= 1;
1329 acpi_video_device_bind(video
, data
);
1330 acpi_video_device_find_cap(data
);
1332 status
= acpi_install_notify_handler(data
->handle
,
1334 acpi_video_device_notify
,
1336 if (ACPI_FAILURE(status
)) {
1337 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1338 "Error installing notify handler\n"));
1339 if(data
->brightness
)
1340 kfree(data
->brightness
->levels
);
1341 kfree(data
->brightness
);
1347 list_add_tail(&data
->entry
, &video
->video_device_list
);
1350 acpi_video_device_add_fs(device
);
1355 return_VALUE(-ENOENT
);
1360 * video : video bus device
1365 * Enumerate the video device list of the video bus,
1366 * bind the ids with the corresponding video devices
1367 * under the video bus.
1370 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1372 struct list_head
*node
, *next
;
1373 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1374 struct acpi_video_device
*dev
=
1375 container_of(node
, struct acpi_video_device
, entry
);
1376 acpi_video_device_bind(video
, dev
);
1382 * video : video bus device
1383 * device : video output device under the video
1389 * Bind the ids with the corresponding video devices
1390 * under the video bus.
1394 acpi_video_device_bind(struct acpi_video_bus
*video
,
1395 struct acpi_video_device
*device
)
1398 ACPI_FUNCTION_TRACE("acpi_video_device_bind");
1400 #define IDS_VAL(i) video->attached_array[i].value.int_val
1401 #define IDS_BIND(i) video->attached_array[i].bind_info
1403 for (i
= 0; IDS_VAL(i
) != ACPI_VIDEO_HEAD_INVALID
&&
1404 i
< video
->attached_count
; i
++) {
1405 if (device
->device_id
== (IDS_VAL(i
) & 0xffff)) {
1406 IDS_BIND(i
) = device
;
1407 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1416 * video : video bus device
1421 * Call _DOD to enumerate all devices attached to display adapter
1425 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1430 struct acpi_video_enumerated_device
*active_device_list
;
1431 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1432 union acpi_object
*dod
= NULL
;
1433 union acpi_object
*obj
;
1435 ACPI_FUNCTION_TRACE("acpi_video_device_enumerate");
1437 status
= acpi_evaluate_object(video
->handle
, "_DOD", NULL
, &buffer
);
1438 if (!ACPI_SUCCESS(status
)) {
1439 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1440 return_VALUE(status
);
1443 dod
= (union acpi_object
*)buffer
.pointer
;
1444 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1445 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1450 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1451 dod
->package
.count
));
1453 active_device_list
= kmalloc((1 +
1454 dod
->package
.count
) *
1456 acpi_video_enumerated_device
),
1459 if (!active_device_list
) {
1465 for (i
= 0; i
< dod
->package
.count
; i
++) {
1466 obj
= (union acpi_object
*)&dod
->package
.elements
[i
];
1468 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1469 ACPI_ERROR((AE_INFO
, "Invalid _DOD data"));
1470 active_device_list
[i
].value
.int_val
=
1471 ACPI_VIDEO_HEAD_INVALID
;
1473 active_device_list
[i
].value
.int_val
= obj
->integer
.value
;
1474 active_device_list
[i
].bind_info
= NULL
;
1475 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1476 (int)obj
->integer
.value
));
1479 active_device_list
[count
].value
.int_val
= ACPI_VIDEO_HEAD_END
;
1481 kfree(video
->attached_array
);
1483 video
->attached_array
= active_device_list
;
1484 video
->attached_count
= count
;
1486 acpi_os_free(buffer
.pointer
);
1487 return_VALUE(status
);
1492 * video : video bus device
1493 * event : Nontify Event
1498 * 1. Find out the current active output device.
1499 * 2. Identify the next output device to switch
1500 * 3. call _DSS to do actual switch.
1503 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
)
1505 struct list_head
*node
, *next
;
1506 struct acpi_video_device
*dev
= NULL
;
1507 struct acpi_video_device
*dev_next
= NULL
;
1508 struct acpi_video_device
*dev_prev
= NULL
;
1509 unsigned long state
;
1512 ACPI_FUNCTION_TRACE("acpi_video_switch_output");
1514 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1515 dev
= container_of(node
, struct acpi_video_device
, entry
);
1516 status
= acpi_video_device_get_state(dev
, &state
);
1519 container_of(node
->next
, struct acpi_video_device
,
1522 container_of(node
->prev
, struct acpi_video_device
,
1527 dev_next
= container_of(node
->next
, struct acpi_video_device
, entry
);
1528 dev_prev
= container_of(node
->prev
, struct acpi_video_device
, entry
);
1531 case ACPI_VIDEO_NOTIFY_CYCLE
:
1532 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
:
1533 acpi_video_device_set_state(dev
, 0);
1534 acpi_video_device_set_state(dev_next
, 0x80000001);
1536 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
:
1537 acpi_video_device_set_state(dev
, 0);
1538 acpi_video_device_set_state(dev_prev
, 0x80000001);
1543 return_VALUE(status
);
1547 acpi_video_get_next_level(struct acpi_video_device
*device
,
1548 u32 level_current
, u32 event
)
1551 return level_current
;
1555 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1557 unsigned long level_current
, level_next
;
1558 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1559 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1560 acpi_video_device_lcd_set_level(device
, level_next
);
1564 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1565 struct acpi_device
*device
)
1568 struct list_head
*node
, *next
;
1570 ACPI_FUNCTION_TRACE("acpi_video_get_devices");
1572 acpi_video_device_enumerate(video
);
1574 list_for_each_safe(node
, next
, &device
->children
) {
1575 struct acpi_device
*dev
=
1576 list_entry(node
, struct acpi_device
, node
);
1581 status
= acpi_video_bus_get_one_device(dev
, video
);
1582 if (ACPI_FAILURE(status
)) {
1583 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1588 return_VALUE(status
);
1591 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1594 struct acpi_video_bus
*video
;
1596 ACPI_FUNCTION_TRACE("acpi_video_bus_put_one_device");
1598 if (!device
|| !device
->video
)
1599 return_VALUE(-ENOENT
);
1601 video
= device
->video
;
1604 list_del(&device
->entry
);
1606 acpi_video_device_remove_fs(device
->dev
);
1608 status
= acpi_remove_notify_handler(device
->handle
,
1610 acpi_video_device_notify
);
1615 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1618 struct list_head
*node
, *next
;
1620 ACPI_FUNCTION_TRACE("acpi_video_bus_put_devices");
1622 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1623 struct acpi_video_device
*data
=
1624 list_entry(node
, struct acpi_video_device
, entry
);
1628 status
= acpi_video_bus_put_one_device(data
);
1629 if (ACPI_FAILURE(status
))
1630 printk(KERN_WARNING PREFIX
1631 "hhuuhhuu bug in acpi video driver.\n");
1633 if (data
->brightness
)
1634 kfree(data
->brightness
->levels
);
1635 kfree(data
->brightness
);
1642 /* acpi_video interface */
1644 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1646 return acpi_video_bus_DOS(video
, 1, 0);
1649 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1651 return acpi_video_bus_DOS(video
, 0, 1);
1654 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1656 struct acpi_video_bus
*video
= (struct acpi_video_bus
*)data
;
1657 struct acpi_device
*device
= NULL
;
1659 ACPI_FUNCTION_TRACE("acpi_video_bus_notify");
1660 printk("video bus notify\n");
1665 if (acpi_bus_get_device(handle
, &device
))
1669 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User request that a switch occur,
1670 * most likely via hotkey. */
1671 acpi_bus_generate_event(device
, event
, 0);
1674 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plug or remove a video
1676 acpi_video_device_enumerate(video
);
1677 acpi_video_device_rebind(video
);
1678 acpi_video_switch_output(video
, event
);
1679 acpi_bus_generate_event(device
, event
, 0);
1682 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1683 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1684 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1685 acpi_video_switch_output(video
, event
);
1686 acpi_bus_generate_event(device
, event
, 0);
1690 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1691 "Unsupported event [0x%x]\n", event
));
1698 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1700 struct acpi_video_device
*video_device
=
1701 (struct acpi_video_device
*)data
;
1702 struct acpi_device
*device
= NULL
;
1704 ACPI_FUNCTION_TRACE("acpi_video_device_notify");
1706 printk("video device notify\n");
1710 if (acpi_bus_get_device(handle
, &device
))
1714 case ACPI_VIDEO_NOTIFY_SWITCH
: /* change in status (cycle output device) */
1715 case ACPI_VIDEO_NOTIFY_PROBE
: /* change in status (output device status) */
1716 acpi_bus_generate_event(device
, event
, 0);
1718 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1719 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1720 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1721 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1722 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1723 acpi_video_switch_brightness(video_device
, event
);
1724 acpi_bus_generate_event(device
, event
, 0);
1727 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1728 "Unsupported event [0x%x]\n", event
));
1734 static int acpi_video_bus_add(struct acpi_device
*device
)
1737 acpi_status status
= 0;
1738 struct acpi_video_bus
*video
= NULL
;
1740 ACPI_FUNCTION_TRACE("acpi_video_bus_add");
1743 return_VALUE(-EINVAL
);
1745 video
= kmalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1747 return_VALUE(-ENOMEM
);
1748 memset(video
, 0, sizeof(struct acpi_video_bus
));
1750 video
->handle
= device
->handle
;
1751 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1752 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1753 acpi_driver_data(device
) = video
;
1755 acpi_video_bus_find_cap(video
);
1756 result
= acpi_video_bus_check(video
);
1760 result
= acpi_video_bus_add_fs(device
);
1764 init_MUTEX(&video
->sem
);
1765 INIT_LIST_HEAD(&video
->video_device_list
);
1767 acpi_video_bus_get_devices(video
, device
);
1768 acpi_video_bus_start_devices(video
);
1770 status
= acpi_install_notify_handler(video
->handle
,
1772 acpi_video_bus_notify
, video
);
1773 if (ACPI_FAILURE(status
)) {
1774 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1775 "Error installing notify handler\n"));
1776 acpi_video_bus_stop_devices(video
);
1777 acpi_video_bus_put_devices(video
);
1778 kfree(video
->attached_array
);
1779 acpi_video_bus_remove_fs(device
);
1784 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1785 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1786 video
->flags
.multihead
? "yes" : "no",
1787 video
->flags
.rom
? "yes" : "no",
1788 video
->flags
.post
? "yes" : "no");
1794 return_VALUE(result
);
1797 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
1799 acpi_status status
= 0;
1800 struct acpi_video_bus
*video
= NULL
;
1802 ACPI_FUNCTION_TRACE("acpi_video_bus_remove");
1804 if (!device
|| !acpi_driver_data(device
))
1805 return_VALUE(-EINVAL
);
1807 video
= (struct acpi_video_bus
*)acpi_driver_data(device
);
1809 acpi_video_bus_stop_devices(video
);
1811 status
= acpi_remove_notify_handler(video
->handle
,
1813 acpi_video_bus_notify
);
1815 acpi_video_bus_put_devices(video
);
1816 acpi_video_bus_remove_fs(device
);
1818 kfree(video
->attached_array
);
1825 acpi_video_bus_match(struct acpi_device
*device
, struct acpi_driver
*driver
)
1827 acpi_handle h_dummy1
;
1828 acpi_handle h_dummy2
;
1829 acpi_handle h_dummy3
;
1831 ACPI_FUNCTION_TRACE("acpi_video_bus_match");
1833 if (!device
|| !driver
)
1834 return_VALUE(-EINVAL
);
1836 /* Since there is no HID, CID for ACPI Video drivers, we have
1837 * to check well known required nodes for each feature we support.
1840 /* Does this device able to support video switching ? */
1841 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DOD", &h_dummy1
)) &&
1842 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DOS", &h_dummy2
)))
1845 /* Does this device able to retrieve a video ROM ? */
1846 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_ROM", &h_dummy1
)))
1849 /* Does this device able to configure which video head to be POSTed ? */
1850 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_VPO", &h_dummy1
)) &&
1851 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_GPD", &h_dummy2
)) &&
1852 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_SPD", &h_dummy3
)))
1855 return_VALUE(-ENODEV
);
1858 static int __init
acpi_video_init(void)
1862 ACPI_FUNCTION_TRACE("acpi_video_init");
1865 acpi_dbg_level = 0xFFFFFFFF;
1866 acpi_dbg_layer = 0x08000000;
1869 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1870 if (!acpi_video_dir
)
1871 return_VALUE(-ENODEV
);
1872 acpi_video_dir
->owner
= THIS_MODULE
;
1874 result
= acpi_bus_register_driver(&acpi_video_bus
);
1876 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1877 return_VALUE(-ENODEV
);
1883 static void __exit
acpi_video_exit(void)
1885 ACPI_FUNCTION_TRACE("acpi_video_exit");
1887 acpi_bus_unregister_driver(&acpi_video_bus
);
1889 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1894 module_init(acpi_video_init
);
1895 module_exit(acpi_video_exit
);