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 {
121 struct acpi_device *device;
123 struct acpi_video_enumerated_device *attached_array;
125 struct acpi_video_bus_cap cap;
126 struct acpi_video_bus_flags flags;
127 struct semaphore sem;
128 struct list_head video_device_list;
129 struct proc_dir_entry *dir;
132 struct acpi_video_device_flags {
141 struct acpi_video_device_cap {
142 u8 _ADR:1; /*Return the unique ID */
143 u8 _BCL:1; /*Query list of brightness control levels supported */
144 u8 _BCM:1; /*Set the brightness level */
145 u8 _DDC:1; /*Return the EDID for this device */
146 u8 _DCS:1; /*Return status of output device */
147 u8 _DGS:1; /*Query graphics state */
148 u8 _DSS:1; /*Device state set */
152 struct acpi_video_device_brightness {
158 struct acpi_video_device {
160 unsigned long device_id;
161 struct acpi_video_device_flags flags;
162 struct acpi_video_device_cap cap;
163 struct list_head entry;
164 struct acpi_video_bus *video;
165 struct acpi_device *dev;
166 struct acpi_video_device_brightness *brightness;
170 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
171 static struct file_operations acpi_video_bus_info_fops = {
172 .open = acpi_video_bus_info_open_fs,
175 .release = single_release,
178 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
179 static struct file_operations acpi_video_bus_ROM_fops = {
180 .open = acpi_video_bus_ROM_open_fs,
183 .release = single_release,
186 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
188 static struct file_operations acpi_video_bus_POST_info_fops = {
189 .open = acpi_video_bus_POST_info_open_fs,
192 .release = single_release,
195 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
196 static struct file_operations acpi_video_bus_POST_fops = {
197 .open = acpi_video_bus_POST_open_fs,
200 .release = single_release,
203 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
204 static struct file_operations acpi_video_bus_DOS_fops = {
205 .open = acpi_video_bus_DOS_open_fs,
208 .release = single_release,
212 static int acpi_video_device_info_open_fs(struct inode *inode,
214 static struct file_operations acpi_video_device_info_fops = {
215 .open = acpi_video_device_info_open_fs,
218 .release = single_release,
221 static int acpi_video_device_state_open_fs(struct inode *inode,
223 static struct file_operations acpi_video_device_state_fops = {
224 .open = acpi_video_device_state_open_fs,
227 .release = single_release,
230 static int acpi_video_device_brightness_open_fs(struct inode *inode,
232 static struct file_operations acpi_video_device_brightness_fops = {
233 .open = acpi_video_device_brightness_open_fs,
236 .release = single_release,
239 static int acpi_video_device_EDID_open_fs(struct inode *inode,
241 static struct file_operations acpi_video_device_EDID_fops = {
242 .open = acpi_video_device_EDID_open_fs,
245 .release = single_release,
248 static char device_decode[][30] = {
249 "motherboard VGA device",
255 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
256 static void acpi_video_device_rebind(struct acpi_video_bus *video);
257 static void acpi_video_device_bind(struct acpi_video_bus *video,
258 struct acpi_video_device *device);
259 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
260 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
261 static int acpi_video_get_next_level(struct acpi_video_device *device,
262 u32 level_current, u32 event);
263 static void acpi_video_switch_brightness(struct acpi_video_device *device,
266 /* --------------------------------------------------------------------------
268 -------------------------------------------------------------------------- */
273 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
276 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state);
282 acpi_video_device_get_state(struct acpi_video_device *device,
283 unsigned long *state)
288 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
294 acpi_video_device_set_state(struct acpi_video_device *device, int state)
297 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
298 struct acpi_object_list args = { 1, &arg0 };
302 arg0.integer.value = state;
303 status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret);
309 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
310 union acpi_object **levels)
313 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
314 union acpi_object *obj;
319 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer);
320 if (!ACPI_SUCCESS(status))
322 obj = (union acpi_object *)buffer.pointer;
323 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
324 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
334 kfree(buffer.pointer);
340 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
343 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
344 struct acpi_object_list args = { 1, &arg0 };
347 arg0.integer.value = level;
348 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL);
350 printk(KERN_DEBUG "set_level status: %x\n", status);
355 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
356 unsigned long *level)
360 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level);
366 acpi_video_device_EDID(struct acpi_video_device *device,
367 union acpi_object **edid, ssize_t length)
370 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
371 union acpi_object *obj;
372 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
373 struct acpi_object_list args = { 1, &arg0 };
381 arg0.integer.value = 1;
382 else if (length == 256)
383 arg0.integer.value = 2;
387 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer);
388 if (ACPI_FAILURE(status))
391 obj = (union acpi_object *)buffer.pointer;
393 if (obj && obj->type == ACPI_TYPE_BUFFER)
396 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
407 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
411 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
412 struct acpi_object_list args = { 1, &arg0 };
415 arg0.integer.value = option;
417 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp);
418 if (ACPI_SUCCESS(status))
419 status = tmp ? (-EINVAL) : (AE_OK);
425 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
430 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
436 acpi_video_bus_POST_options(struct acpi_video_bus *video,
437 unsigned long *options)
441 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options);
449 * video : video bus device pointer
451 * 0. The system BIOS should NOT automatically switch(toggle)
452 * the active display output.
453 * 1. The system BIOS should automatically switch (toggle) the
454 * active display output. No swich event.
455 * 2. The _DGS value should be locked.
456 * 3. The system BIOS should not automatically switch (toggle) the
457 * active display output, but instead generate the display switch
460 * 0. The system BIOS should automatically control the brightness level
461 * of the LCD, when the power changes from AC to DC
462 * 1. The system BIOS should NOT automatically control the brightness
463 * level of the LCD, when the power changes from AC to DC.
469 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
471 acpi_integer status = 0;
472 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
473 struct acpi_object_list args = { 1, &arg0 };
476 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
480 arg0.integer.value = (lcd_flag << 2) | bios_flag;
481 video->dos_setting = arg0.integer.value;
482 acpi_evaluate_object(video->handle, "_DOS", &args, NULL);
490 * device : video output device (LCD, CRT, ..)
495 * Find out all required AML method defined under the output
499 static void acpi_video_device_find_cap(struct acpi_video_device *device)
502 acpi_handle h_dummy1;
504 union acpi_object *obj = NULL;
505 struct acpi_video_device_brightness *br = NULL;
508 memset(&device->cap, 0, 4);
510 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) {
511 device->cap._ADR = 1;
513 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) {
514 device->cap._BCL = 1;
516 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) {
517 device->cap._BCM = 1;
519 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) {
520 device->cap._DDC = 1;
522 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) {
523 device->cap._DCS = 1;
525 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) {
526 device->cap._DGS = 1;
528 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) {
529 device->cap._DSS = 1;
532 status = acpi_video_device_lcd_query_levels(device, &obj);
534 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
536 union acpi_object *o;
538 br = kmalloc(sizeof(*br), GFP_KERNEL);
540 printk(KERN_ERR "can't allocate memory\n");
542 memset(br, 0, sizeof(*br));
543 br->levels = kmalloc(obj->package.count *
544 sizeof *(br->levels), GFP_KERNEL);
548 for (i = 0; i < obj->package.count; i++) {
549 o = (union acpi_object *)&obj->package.
551 if (o->type != ACPI_TYPE_INTEGER) {
552 printk(KERN_ERR PREFIX "Invalid data\n");
555 br->levels[count] = (u32) o->integer.value;
564 device->brightness = br;
565 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
566 "found %d brightness levels\n",
579 * device : video output device (VGA)
584 * Find out all required AML method defined under the video bus device.
587 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
589 acpi_handle h_dummy1;
591 memset(&video->cap, 0, 4);
592 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) {
595 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) {
598 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) {
601 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) {
604 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) {
607 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) {
613 * Check whether the video bus device has required AML method to
614 * support the desired features
617 static int acpi_video_bus_check(struct acpi_video_bus *video)
619 acpi_status status = -ENOENT;
625 /* Since there is no HID, CID and so on for VGA driver, we have
626 * to check well known required nodes.
629 /* Does this device able to support video switching ? */
630 if (video->cap._DOS) {
631 video->flags.multihead = 1;
635 /* Does this device able to retrieve a retrieve a video ROM ? */
636 if (video->cap._ROM) {
637 video->flags.rom = 1;
641 /* Does this device able to configure which video device to POST ? */
642 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
643 video->flags.post = 1;
650 /* --------------------------------------------------------------------------
652 -------------------------------------------------------------------------- */
654 static struct proc_dir_entry *acpi_video_dir;
658 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
660 struct acpi_video_device *dev =
661 (struct acpi_video_device *)seq->private;
667 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
668 seq_printf(seq, "type: ");
670 seq_printf(seq, "CRT\n");
671 else if (dev->flags.lcd)
672 seq_printf(seq, "LCD\n");
673 else if (dev->flags.tvout)
674 seq_printf(seq, "TVOUT\n");
676 seq_printf(seq, "UNKNOWN\n");
678 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
685 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
687 return single_open(file, acpi_video_device_info_seq_show,
691 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
694 struct acpi_video_device *dev =
695 (struct acpi_video_device *)seq->private;
702 status = acpi_video_device_get_state(dev, &state);
703 seq_printf(seq, "state: ");
704 if (ACPI_SUCCESS(status))
705 seq_printf(seq, "0x%02lx\n", state);
707 seq_printf(seq, "<not supported>\n");
709 status = acpi_video_device_query(dev, &state);
710 seq_printf(seq, "query: ");
711 if (ACPI_SUCCESS(status))
712 seq_printf(seq, "0x%02lx\n", state);
714 seq_printf(seq, "<not supported>\n");
721 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
723 return single_open(file, acpi_video_device_state_seq_show,
728 acpi_video_device_write_state(struct file *file,
729 const char __user * buffer,
730 size_t count, loff_t * data)
733 struct seq_file *m = (struct seq_file *)file->private_data;
734 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
735 char str[12] = { 0 };
739 if (!dev || count + 1 > sizeof str)
742 if (copy_from_user(str, buffer, count))
746 state = simple_strtoul(str, NULL, 0);
747 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
749 status = acpi_video_device_set_state(dev, state);
758 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
760 struct acpi_video_device *dev =
761 (struct acpi_video_device *)seq->private;
765 if (!dev || !dev->brightness) {
766 seq_printf(seq, "<not supported>\n");
770 seq_printf(seq, "levels: ");
771 for (i = 0; i < dev->brightness->count; i++)
772 seq_printf(seq, " %d", dev->brightness->levels[i]);
773 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
779 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
781 return single_open(file, acpi_video_device_brightness_seq_show,
786 acpi_video_device_write_brightness(struct file *file,
787 const char __user * buffer,
788 size_t count, loff_t * data)
790 struct seq_file *m = (struct seq_file *)file->private_data;
791 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
793 unsigned int level = 0;
797 if (!dev || !dev->brightness || count + 1 > sizeof str)
800 if (copy_from_user(str, buffer, count))
804 level = simple_strtoul(str, NULL, 0);
809 /* validate though the list of available levels */
810 for (i = 0; i < dev->brightness->count; i++)
811 if (level == dev->brightness->levels[i]) {
813 (acpi_video_device_lcd_set_level(dev, level)))
814 dev->brightness->curr = level;
821 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
823 struct acpi_video_device *dev =
824 (struct acpi_video_device *)seq->private;
827 union acpi_object *edid = NULL;
833 status = acpi_video_device_EDID(dev, &edid, 128);
834 if (ACPI_FAILURE(status)) {
835 status = acpi_video_device_EDID(dev, &edid, 256);
838 if (ACPI_FAILURE(status)) {
842 if (edid && edid->type == ACPI_TYPE_BUFFER) {
843 for (i = 0; i < edid->buffer.length; i++)
844 seq_putc(seq, edid->buffer.pointer[i]);
849 seq_printf(seq, "<not supported>\n");
857 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
859 return single_open(file, acpi_video_device_EDID_seq_show,
863 static int acpi_video_device_add_fs(struct acpi_device *device)
865 struct proc_dir_entry *entry = NULL;
866 struct acpi_video_device *vid_dev;
872 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
876 if (!acpi_device_dir(device)) {
877 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
878 vid_dev->video->dir);
879 if (!acpi_device_dir(device))
881 acpi_device_dir(device)->owner = THIS_MODULE;
885 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
889 entry->proc_fops = &acpi_video_device_info_fops;
890 entry->data = acpi_driver_data(device);
891 entry->owner = THIS_MODULE;
896 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
897 acpi_device_dir(device));
901 acpi_video_device_state_fops.write = acpi_video_device_write_state;
902 entry->proc_fops = &acpi_video_device_state_fops;
903 entry->data = acpi_driver_data(device);
904 entry->owner = THIS_MODULE;
907 /* 'brightness' [R/W] */
909 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
910 acpi_device_dir(device));
914 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
915 entry->proc_fops = &acpi_video_device_brightness_fops;
916 entry->data = acpi_driver_data(device);
917 entry->owner = THIS_MODULE;
921 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
925 entry->proc_fops = &acpi_video_device_EDID_fops;
926 entry->data = acpi_driver_data(device);
927 entry->owner = THIS_MODULE;
933 static int acpi_video_device_remove_fs(struct acpi_device *device)
935 struct acpi_video_device *vid_dev;
937 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
938 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
941 if (acpi_device_dir(device)) {
942 remove_proc_entry("info", acpi_device_dir(device));
943 remove_proc_entry("state", acpi_device_dir(device));
944 remove_proc_entry("brightness", acpi_device_dir(device));
945 remove_proc_entry("EDID", acpi_device_dir(device));
946 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
947 acpi_device_dir(device) = NULL;
954 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
956 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
962 seq_printf(seq, "Switching heads: %s\n",
963 video->flags.multihead ? "yes" : "no");
964 seq_printf(seq, "Video ROM: %s\n",
965 video->flags.rom ? "yes" : "no");
966 seq_printf(seq, "Device to be POSTed on boot: %s\n",
967 video->flags.post ? "yes" : "no");
973 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
975 return single_open(file, acpi_video_bus_info_seq_show,
979 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
981 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
987 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
988 seq_printf(seq, "<TODO>\n");
994 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
996 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
999 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1001 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1002 unsigned long options;
1009 status = acpi_video_bus_POST_options(video, &options);
1010 if (ACPI_SUCCESS(status)) {
1011 if (!(options & 1)) {
1012 printk(KERN_WARNING PREFIX
1013 "The motherboard VGA device is not listed as a possible POST device.\n");
1014 printk(KERN_WARNING PREFIX
1015 "This indicate a BIOS bug. Please contact the manufacturer.\n");
1017 printk("%lx\n", options);
1018 seq_printf(seq, "can POST: <intgrated video>");
1020 seq_printf(seq, " <PCI video>");
1022 seq_printf(seq, " <AGP video>");
1023 seq_putc(seq, '\n');
1025 seq_printf(seq, "<not supported>\n");
1031 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1033 return single_open(file, acpi_video_bus_POST_info_seq_show,
1037 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1039 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1047 status = acpi_video_bus_get_POST(video, &id);
1048 if (!ACPI_SUCCESS(status)) {
1049 seq_printf(seq, "<not supported>\n");
1052 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
1058 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1060 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1063 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1068 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1070 return single_open(file, acpi_video_bus_POST_seq_show,
1074 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1076 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1080 acpi_video_bus_write_POST(struct file *file,
1081 const char __user * buffer,
1082 size_t count, loff_t * data)
1085 struct seq_file *m = (struct seq_file *)file->private_data;
1086 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1087 char str[12] = { 0 };
1088 unsigned long opt, options;
1091 if (!video || count + 1 > sizeof str)
1094 status = acpi_video_bus_POST_options(video, &options);
1095 if (!ACPI_SUCCESS(status))
1098 if (copy_from_user(str, buffer, count))
1102 opt = strtoul(str, NULL, 0);
1106 /* just in case an OEM 'forget' the motherboard... */
1109 if (options & (1ul << opt)) {
1110 status = acpi_video_bus_set_POST(video, opt);
1111 if (!ACPI_SUCCESS(status))
1120 acpi_video_bus_write_DOS(struct file *file,
1121 const char __user * buffer,
1122 size_t count, loff_t * data)
1125 struct seq_file *m = (struct seq_file *)file->private_data;
1126 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1127 char str[12] = { 0 };
1131 if (!video || count + 1 > sizeof str)
1134 if (copy_from_user(str, buffer, count))
1138 opt = strtoul(str, NULL, 0);
1142 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1144 if (!ACPI_SUCCESS(status))
1150 static int acpi_video_bus_add_fs(struct acpi_device *device)
1152 struct proc_dir_entry *entry = NULL;
1153 struct acpi_video_bus *video;
1156 video = (struct acpi_video_bus *)acpi_driver_data(device);
1158 if (!acpi_device_dir(device)) {
1159 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1161 if (!acpi_device_dir(device))
1163 video->dir = acpi_device_dir(device);
1164 acpi_device_dir(device)->owner = THIS_MODULE;
1168 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1172 entry->proc_fops = &acpi_video_bus_info_fops;
1173 entry->data = acpi_driver_data(device);
1174 entry->owner = THIS_MODULE;
1178 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1182 entry->proc_fops = &acpi_video_bus_ROM_fops;
1183 entry->data = acpi_driver_data(device);
1184 entry->owner = THIS_MODULE;
1187 /* 'POST_info' [R] */
1189 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1193 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1194 entry->data = acpi_driver_data(device);
1195 entry->owner = THIS_MODULE;
1200 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1201 acpi_device_dir(device));
1205 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1206 entry->proc_fops = &acpi_video_bus_POST_fops;
1207 entry->data = acpi_driver_data(device);
1208 entry->owner = THIS_MODULE;
1213 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1214 acpi_device_dir(device));
1218 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1219 entry->proc_fops = &acpi_video_bus_DOS_fops;
1220 entry->data = acpi_driver_data(device);
1221 entry->owner = THIS_MODULE;
1227 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1229 struct acpi_video_bus *video;
1232 video = (struct acpi_video_bus *)acpi_driver_data(device);
1234 if (acpi_device_dir(device)) {
1235 remove_proc_entry("info", acpi_device_dir(device));
1236 remove_proc_entry("ROM", acpi_device_dir(device));
1237 remove_proc_entry("POST_info", acpi_device_dir(device));
1238 remove_proc_entry("POST", acpi_device_dir(device));
1239 remove_proc_entry("DOS", acpi_device_dir(device));
1240 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1241 acpi_device_dir(device) = NULL;
1247 /* --------------------------------------------------------------------------
1249 -------------------------------------------------------------------------- */
1251 /* device interface */
1254 acpi_video_bus_get_one_device(struct acpi_device *device,
1255 struct acpi_video_bus *video)
1257 unsigned long device_id;
1259 struct acpi_video_device *data;
1262 if (!device || !video)
1266 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1267 if (ACPI_SUCCESS(status)) {
1269 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1273 memset(data, 0, sizeof(struct acpi_video_device));
1275 data->handle = device->handle;
1276 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1277 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1278 acpi_driver_data(device) = data;
1280 data->device_id = device_id;
1281 data->video = video;
1284 switch (device_id & 0xffff) {
1286 data->flags.crt = 1;
1289 data->flags.lcd = 1;
1292 data->flags.tvout = 1;
1295 data->flags.unknown = 1;
1299 acpi_video_device_bind(video, data);
1300 acpi_video_device_find_cap(data);
1302 status = acpi_install_notify_handler(data->handle,
1304 acpi_video_device_notify,
1306 if (ACPI_FAILURE(status)) {
1307 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1308 "Error installing notify handler\n"));
1309 if(data->brightness)
1310 kfree(data->brightness->levels);
1311 kfree(data->brightness);
1317 list_add_tail(&data->entry, &video->video_device_list);
1320 acpi_video_device_add_fs(device);
1330 * video : video bus device
1335 * Enumerate the video device list of the video bus,
1336 * bind the ids with the corresponding video devices
1337 * under the video bus.
1340 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1342 struct list_head *node, *next;
1343 list_for_each_safe(node, next, &video->video_device_list) {
1344 struct acpi_video_device *dev =
1345 container_of(node, struct acpi_video_device, entry);
1346 acpi_video_device_bind(video, dev);
1352 * video : video bus device
1353 * device : video output device under the video
1359 * Bind the ids with the corresponding video devices
1360 * under the video bus.
1364 acpi_video_device_bind(struct acpi_video_bus *video,
1365 struct acpi_video_device *device)
1369 #define IDS_VAL(i) video->attached_array[i].value.int_val
1370 #define IDS_BIND(i) video->attached_array[i].bind_info
1372 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1373 i < video->attached_count; i++) {
1374 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1375 IDS_BIND(i) = device;
1376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1385 * video : video bus device
1390 * Call _DOD to enumerate all devices attached to display adapter
1394 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1399 struct acpi_video_enumerated_device *active_device_list;
1400 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1401 union acpi_object *dod = NULL;
1402 union acpi_object *obj;
1405 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1406 if (!ACPI_SUCCESS(status)) {
1407 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1411 dod = (union acpi_object *)buffer.pointer;
1412 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1413 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1418 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1419 dod->package.count));
1421 active_device_list = kmalloc((1 +
1422 dod->package.count) *
1424 acpi_video_enumerated_device),
1427 if (!active_device_list) {
1433 for (i = 0; i < dod->package.count; i++) {
1434 obj = (union acpi_object *)&dod->package.elements[i];
1436 if (obj->type != ACPI_TYPE_INTEGER) {
1437 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1438 active_device_list[i].value.int_val =
1439 ACPI_VIDEO_HEAD_INVALID;
1441 active_device_list[i].value.int_val = obj->integer.value;
1442 active_device_list[i].bind_info = NULL;
1443 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1444 (int)obj->integer.value));
1447 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1449 kfree(video->attached_array);
1451 video->attached_array = active_device_list;
1452 video->attached_count = count;
1454 acpi_os_free(buffer.pointer);
1460 * video : video bus device
1461 * event : Nontify Event
1466 * 1. Find out the current active output device.
1467 * 2. Identify the next output device to switch
1468 * 3. call _DSS to do actual switch.
1471 static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1473 struct list_head *node, *next;
1474 struct acpi_video_device *dev = NULL;
1475 struct acpi_video_device *dev_next = NULL;
1476 struct acpi_video_device *dev_prev = NULL;
1477 unsigned long state;
1481 list_for_each_safe(node, next, &video->video_device_list) {
1482 dev = container_of(node, struct acpi_video_device, entry);
1483 status = acpi_video_device_get_state(dev, &state);
1486 container_of(node->next, struct acpi_video_device,
1489 container_of(node->prev, struct acpi_video_device,
1494 dev_next = container_of(node->next, struct acpi_video_device, entry);
1495 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1498 case ACPI_VIDEO_NOTIFY_CYCLE:
1499 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1500 acpi_video_device_set_state(dev, 0);
1501 acpi_video_device_set_state(dev_next, 0x80000001);
1503 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1504 acpi_video_device_set_state(dev, 0);
1505 acpi_video_device_set_state(dev_prev, 0x80000001);
1514 acpi_video_get_next_level(struct acpi_video_device *device,
1515 u32 level_current, u32 event)
1518 return level_current;
1522 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1524 unsigned long level_current, level_next;
1525 acpi_video_device_lcd_get_level_current(device, &level_current);
1526 level_next = acpi_video_get_next_level(device, level_current, event);
1527 acpi_video_device_lcd_set_level(device, level_next);
1531 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1532 struct acpi_device *device)
1535 struct list_head *node, *next;
1538 acpi_video_device_enumerate(video);
1540 list_for_each_safe(node, next, &device->children) {
1541 struct acpi_device *dev =
1542 list_entry(node, struct acpi_device, node);
1547 status = acpi_video_bus_get_one_device(dev, video);
1548 if (ACPI_FAILURE(status)) {
1549 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1557 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1560 struct acpi_video_bus *video;
1563 if (!device || !device->video)
1566 video = device->video;
1569 list_del(&device->entry);
1571 acpi_video_device_remove_fs(device->dev);
1573 status = acpi_remove_notify_handler(device->handle,
1575 acpi_video_device_notify);
1580 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1583 struct list_head *node, *next;
1586 list_for_each_safe(node, next, &video->video_device_list) {
1587 struct acpi_video_device *data =
1588 list_entry(node, struct acpi_video_device, entry);
1592 status = acpi_video_bus_put_one_device(data);
1593 if (ACPI_FAILURE(status))
1594 printk(KERN_WARNING PREFIX
1595 "hhuuhhuu bug in acpi video driver.\n");
1597 if (data->brightness)
1598 kfree(data->brightness->levels);
1599 kfree(data->brightness);
1606 /* acpi_video interface */
1608 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1610 return acpi_video_bus_DOS(video, 1, 0);
1613 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1615 return acpi_video_bus_DOS(video, 0, 1);
1618 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1620 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1621 struct acpi_device *device = NULL;
1623 printk("video bus notify\n");
1628 device = video->device;
1631 case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur,
1632 * most likely via hotkey. */
1633 acpi_bus_generate_event(device, event, 0);
1636 case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video
1638 acpi_video_device_enumerate(video);
1639 acpi_video_device_rebind(video);
1640 acpi_video_switch_output(video, event);
1641 acpi_bus_generate_event(device, event, 0);
1644 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1645 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1646 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1647 acpi_video_switch_output(video, event);
1648 acpi_bus_generate_event(device, event, 0);
1652 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1653 "Unsupported event [0x%x]\n", event));
1660 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1662 struct acpi_video_device *video_device =
1663 (struct acpi_video_device *)data;
1664 struct acpi_device *device = NULL;
1667 printk("video device notify\n");
1671 device = video_device->dev;
1674 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1675 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
1676 acpi_bus_generate_event(device, event, 0);
1678 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1679 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1680 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1681 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1682 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1683 acpi_video_switch_brightness(video_device, event);
1684 acpi_bus_generate_event(device, event, 0);
1687 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1688 "Unsupported event [0x%x]\n", event));
1694 static int acpi_video_bus_add(struct acpi_device *device)
1697 acpi_status status = 0;
1698 struct acpi_video_bus *video = NULL;
1704 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1707 memset(video, 0, sizeof(struct acpi_video_bus));
1709 video->handle = device->handle;
1710 video->device = device;
1711 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1712 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1713 acpi_driver_data(device) = video;
1715 acpi_video_bus_find_cap(video);
1716 result = acpi_video_bus_check(video);
1720 result = acpi_video_bus_add_fs(device);
1724 init_MUTEX(&video->sem);
1725 INIT_LIST_HEAD(&video->video_device_list);
1727 acpi_video_bus_get_devices(video, device);
1728 acpi_video_bus_start_devices(video);
1730 status = acpi_install_notify_handler(video->handle,
1732 acpi_video_bus_notify, video);
1733 if (ACPI_FAILURE(status)) {
1734 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1735 "Error installing notify handler\n"));
1736 acpi_video_bus_stop_devices(video);
1737 acpi_video_bus_put_devices(video);
1738 kfree(video->attached_array);
1739 acpi_video_bus_remove_fs(device);
1744 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1745 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1746 video->flags.multihead ? "yes" : "no",
1747 video->flags.rom ? "yes" : "no",
1748 video->flags.post ? "yes" : "no");
1757 static int acpi_video_bus_remove(struct acpi_device *device, int type)
1759 acpi_status status = 0;
1760 struct acpi_video_bus *video = NULL;
1763 if (!device || !acpi_driver_data(device))
1766 video = (struct acpi_video_bus *)acpi_driver_data(device);
1768 acpi_video_bus_stop_devices(video);
1770 status = acpi_remove_notify_handler(video->handle,
1772 acpi_video_bus_notify);
1774 acpi_video_bus_put_devices(video);
1775 acpi_video_bus_remove_fs(device);
1777 kfree(video->attached_array);
1784 acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver)
1786 acpi_handle h_dummy1;
1787 acpi_handle h_dummy2;
1788 acpi_handle h_dummy3;
1791 if (!device || !driver)
1794 /* Since there is no HID, CID for ACPI Video drivers, we have
1795 * to check well known required nodes for each feature we support.
1798 /* Does this device able to support video switching ? */
1799 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
1800 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
1803 /* Does this device able to retrieve a video ROM ? */
1804 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
1807 /* Does this device able to configure which video head to be POSTed ? */
1808 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
1809 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
1810 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
1816 static int __init acpi_video_init(void)
1822 acpi_dbg_level = 0xFFFFFFFF;
1823 acpi_dbg_layer = 0x08000000;
1826 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1827 if (!acpi_video_dir)
1829 acpi_video_dir->owner = THIS_MODULE;
1831 result = acpi_bus_register_driver(&acpi_video_bus);
1833 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1840 static void __exit acpi_video_exit(void)
1843 acpi_bus_unregister_driver(&acpi_video_bus);
1845 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1850 module_init(acpi_video_init);
1851 module_exit(acpi_video_exit);