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 status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state);
281 acpi_video_device_get_state(struct acpi_video_device *device,
282 unsigned long *state)
287 status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state);
293 acpi_video_device_set_state(struct acpi_video_device *device, int state)
296 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
297 struct acpi_object_list args = { 1, &arg0 };
301 arg0.integer.value = state;
302 status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret);
308 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
309 union acpi_object **levels)
312 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
313 union acpi_object *obj;
318 status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer);
319 if (!ACPI_SUCCESS(status))
321 obj = (union acpi_object *)buffer.pointer;
322 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
323 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
333 kfree(buffer.pointer);
339 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
342 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
343 struct acpi_object_list args = { 1, &arg0 };
346 arg0.integer.value = level;
347 status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL);
349 printk(KERN_DEBUG "set_level status: %x\n", status);
354 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
355 unsigned long *level)
359 status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level);
365 acpi_video_device_EDID(struct acpi_video_device *device,
366 union acpi_object **edid, ssize_t length)
369 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
370 union acpi_object *obj;
371 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
372 struct acpi_object_list args = { 1, &arg0 };
380 arg0.integer.value = 1;
381 else if (length == 256)
382 arg0.integer.value = 2;
386 status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer);
387 if (ACPI_FAILURE(status))
390 obj = (union acpi_object *)buffer.pointer;
392 if (obj && obj->type == ACPI_TYPE_BUFFER)
395 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
406 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
410 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
411 struct acpi_object_list args = { 1, &arg0 };
414 arg0.integer.value = option;
416 status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp);
417 if (ACPI_SUCCESS(status))
418 status = tmp ? (-EINVAL) : (AE_OK);
424 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
429 status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id);
435 acpi_video_bus_POST_options(struct acpi_video_bus *video,
436 unsigned long *options)
440 status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options);
448 * video : video bus device pointer
450 * 0. The system BIOS should NOT automatically switch(toggle)
451 * the active display output.
452 * 1. The system BIOS should automatically switch (toggle) the
453 * active display output. No swich event.
454 * 2. The _DGS value should be locked.
455 * 3. The system BIOS should not automatically switch (toggle) the
456 * active display output, but instead generate the display switch
459 * 0. The system BIOS should automatically control the brightness level
460 * of the LCD, when the power changes from AC to DC
461 * 1. The system BIOS should NOT automatically control the brightness
462 * level of the LCD, when the power changes from AC to DC.
468 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
470 acpi_integer status = 0;
471 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
472 struct acpi_object_list args = { 1, &arg0 };
475 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
479 arg0.integer.value = (lcd_flag << 2) | bios_flag;
480 video->dos_setting = arg0.integer.value;
481 acpi_evaluate_object(video->handle, "_DOS", &args, NULL);
489 * device : video output device (LCD, CRT, ..)
494 * Find out all required AML method defined under the output
498 static void acpi_video_device_find_cap(struct acpi_video_device *device)
501 acpi_handle h_dummy1;
503 union acpi_object *obj = NULL;
504 struct acpi_video_device_brightness *br = NULL;
507 memset(&device->cap, 0, 4);
509 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) {
510 device->cap._ADR = 1;
512 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) {
513 device->cap._BCL = 1;
515 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) {
516 device->cap._BCM = 1;
518 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) {
519 device->cap._DDC = 1;
521 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) {
522 device->cap._DCS = 1;
524 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) {
525 device->cap._DGS = 1;
527 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) {
528 device->cap._DSS = 1;
531 status = acpi_video_device_lcd_query_levels(device, &obj);
533 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
535 union acpi_object *o;
537 br = kmalloc(sizeof(*br), GFP_KERNEL);
539 printk(KERN_ERR "can't allocate memory\n");
541 memset(br, 0, sizeof(*br));
542 br->levels = kmalloc(obj->package.count *
543 sizeof *(br->levels), GFP_KERNEL);
547 for (i = 0; i < obj->package.count; i++) {
548 o = (union acpi_object *)&obj->package.
550 if (o->type != ACPI_TYPE_INTEGER) {
551 printk(KERN_ERR PREFIX "Invalid data\n");
554 br->levels[count] = (u32) o->integer.value;
563 device->brightness = br;
564 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
565 "found %d brightness levels\n",
578 * device : video output device (VGA)
583 * Find out all required AML method defined under the video bus device.
586 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
588 acpi_handle h_dummy1;
590 memset(&video->cap, 0, 4);
591 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) {
594 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) {
597 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) {
600 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) {
603 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) {
606 if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) {
612 * Check whether the video bus device has required AML method to
613 * support the desired features
616 static int acpi_video_bus_check(struct acpi_video_bus *video)
618 acpi_status status = -ENOENT;
624 /* Since there is no HID, CID and so on for VGA driver, we have
625 * to check well known required nodes.
628 /* Does this device able to support video switching ? */
629 if (video->cap._DOS) {
630 video->flags.multihead = 1;
634 /* Does this device able to retrieve a retrieve a video ROM ? */
635 if (video->cap._ROM) {
636 video->flags.rom = 1;
640 /* Does this device able to configure which video device to POST ? */
641 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
642 video->flags.post = 1;
649 /* --------------------------------------------------------------------------
651 -------------------------------------------------------------------------- */
653 static struct proc_dir_entry *acpi_video_dir;
657 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
659 struct acpi_video_device *dev =
660 (struct acpi_video_device *)seq->private;
666 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
667 seq_printf(seq, "type: ");
669 seq_printf(seq, "CRT\n");
670 else if (dev->flags.lcd)
671 seq_printf(seq, "LCD\n");
672 else if (dev->flags.tvout)
673 seq_printf(seq, "TVOUT\n");
675 seq_printf(seq, "UNKNOWN\n");
677 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
684 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
686 return single_open(file, acpi_video_device_info_seq_show,
690 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
693 struct acpi_video_device *dev =
694 (struct acpi_video_device *)seq->private;
701 status = acpi_video_device_get_state(dev, &state);
702 seq_printf(seq, "state: ");
703 if (ACPI_SUCCESS(status))
704 seq_printf(seq, "0x%02lx\n", state);
706 seq_printf(seq, "<not supported>\n");
708 status = acpi_video_device_query(dev, &state);
709 seq_printf(seq, "query: ");
710 if (ACPI_SUCCESS(status))
711 seq_printf(seq, "0x%02lx\n", state);
713 seq_printf(seq, "<not supported>\n");
720 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
722 return single_open(file, acpi_video_device_state_seq_show,
727 acpi_video_device_write_state(struct file *file,
728 const char __user * buffer,
729 size_t count, loff_t * data)
732 struct seq_file *m = (struct seq_file *)file->private_data;
733 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
734 char str[12] = { 0 };
738 if (!dev || count + 1 > sizeof str)
741 if (copy_from_user(str, buffer, count))
745 state = simple_strtoul(str, NULL, 0);
746 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
748 status = acpi_video_device_set_state(dev, state);
757 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
759 struct acpi_video_device *dev =
760 (struct acpi_video_device *)seq->private;
764 if (!dev || !dev->brightness) {
765 seq_printf(seq, "<not supported>\n");
769 seq_printf(seq, "levels: ");
770 for (i = 0; i < dev->brightness->count; i++)
771 seq_printf(seq, " %d", dev->brightness->levels[i]);
772 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
778 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
780 return single_open(file, acpi_video_device_brightness_seq_show,
785 acpi_video_device_write_brightness(struct file *file,
786 const char __user * buffer,
787 size_t count, loff_t * data)
789 struct seq_file *m = (struct seq_file *)file->private_data;
790 struct acpi_video_device *dev = (struct acpi_video_device *)m->private;
792 unsigned int level = 0;
796 if (!dev || !dev->brightness || count + 1 > sizeof str)
799 if (copy_from_user(str, buffer, count))
803 level = simple_strtoul(str, NULL, 0);
808 /* validate though the list of available levels */
809 for (i = 0; i < dev->brightness->count; i++)
810 if (level == dev->brightness->levels[i]) {
812 (acpi_video_device_lcd_set_level(dev, level)))
813 dev->brightness->curr = level;
820 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
822 struct acpi_video_device *dev =
823 (struct acpi_video_device *)seq->private;
826 union acpi_object *edid = NULL;
832 status = acpi_video_device_EDID(dev, &edid, 128);
833 if (ACPI_FAILURE(status)) {
834 status = acpi_video_device_EDID(dev, &edid, 256);
837 if (ACPI_FAILURE(status)) {
841 if (edid && edid->type == ACPI_TYPE_BUFFER) {
842 for (i = 0; i < edid->buffer.length; i++)
843 seq_putc(seq, edid->buffer.pointer[i]);
848 seq_printf(seq, "<not supported>\n");
856 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
858 return single_open(file, acpi_video_device_EDID_seq_show,
862 static int acpi_video_device_add_fs(struct acpi_device *device)
864 struct proc_dir_entry *entry = NULL;
865 struct acpi_video_device *vid_dev;
871 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
875 if (!acpi_device_dir(device)) {
876 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
877 vid_dev->video->dir);
878 if (!acpi_device_dir(device))
880 acpi_device_dir(device)->owner = THIS_MODULE;
884 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
888 entry->proc_fops = &acpi_video_device_info_fops;
889 entry->data = acpi_driver_data(device);
890 entry->owner = THIS_MODULE;
895 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
896 acpi_device_dir(device));
900 acpi_video_device_state_fops.write = acpi_video_device_write_state;
901 entry->proc_fops = &acpi_video_device_state_fops;
902 entry->data = acpi_driver_data(device);
903 entry->owner = THIS_MODULE;
906 /* 'brightness' [R/W] */
908 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
909 acpi_device_dir(device));
913 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
914 entry->proc_fops = &acpi_video_device_brightness_fops;
915 entry->data = acpi_driver_data(device);
916 entry->owner = THIS_MODULE;
920 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
924 entry->proc_fops = &acpi_video_device_EDID_fops;
925 entry->data = acpi_driver_data(device);
926 entry->owner = THIS_MODULE;
932 static int acpi_video_device_remove_fs(struct acpi_device *device)
934 struct acpi_video_device *vid_dev;
936 vid_dev = (struct acpi_video_device *)acpi_driver_data(device);
937 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
940 if (acpi_device_dir(device)) {
941 remove_proc_entry("info", acpi_device_dir(device));
942 remove_proc_entry("state", acpi_device_dir(device));
943 remove_proc_entry("brightness", acpi_device_dir(device));
944 remove_proc_entry("EDID", acpi_device_dir(device));
945 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
946 acpi_device_dir(device) = NULL;
953 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
955 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
961 seq_printf(seq, "Switching heads: %s\n",
962 video->flags.multihead ? "yes" : "no");
963 seq_printf(seq, "Video ROM: %s\n",
964 video->flags.rom ? "yes" : "no");
965 seq_printf(seq, "Device to be POSTed on boot: %s\n",
966 video->flags.post ? "yes" : "no");
972 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
974 return single_open(file, acpi_video_bus_info_seq_show,
978 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
980 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
986 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
987 seq_printf(seq, "<TODO>\n");
993 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
995 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
998 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1000 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1001 unsigned long options;
1008 status = acpi_video_bus_POST_options(video, &options);
1009 if (ACPI_SUCCESS(status)) {
1010 if (!(options & 1)) {
1011 printk(KERN_WARNING PREFIX
1012 "The motherboard VGA device is not listed as a possible POST device.\n");
1013 printk(KERN_WARNING PREFIX
1014 "This indicate a BIOS bug. Please contact the manufacturer.\n");
1016 printk("%lx\n", options);
1017 seq_printf(seq, "can POST: <intgrated video>");
1019 seq_printf(seq, " <PCI video>");
1021 seq_printf(seq, " <AGP video>");
1022 seq_putc(seq, '\n');
1024 seq_printf(seq, "<not supported>\n");
1030 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1032 return single_open(file, acpi_video_bus_POST_info_seq_show,
1036 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1038 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1046 status = acpi_video_bus_get_POST(video, &id);
1047 if (!ACPI_SUCCESS(status)) {
1048 seq_printf(seq, "<not supported>\n");
1051 seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]);
1057 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1059 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private;
1062 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1067 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1069 return single_open(file, acpi_video_bus_POST_seq_show,
1073 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1075 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1079 acpi_video_bus_write_POST(struct file *file,
1080 const char __user * buffer,
1081 size_t count, loff_t * data)
1084 struct seq_file *m = (struct seq_file *)file->private_data;
1085 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1086 char str[12] = { 0 };
1087 unsigned long opt, options;
1090 if (!video || count + 1 > sizeof str)
1093 status = acpi_video_bus_POST_options(video, &options);
1094 if (!ACPI_SUCCESS(status))
1097 if (copy_from_user(str, buffer, count))
1101 opt = strtoul(str, NULL, 0);
1105 /* just in case an OEM 'forget' the motherboard... */
1108 if (options & (1ul << opt)) {
1109 status = acpi_video_bus_set_POST(video, opt);
1110 if (!ACPI_SUCCESS(status))
1119 acpi_video_bus_write_DOS(struct file *file,
1120 const char __user * buffer,
1121 size_t count, loff_t * data)
1124 struct seq_file *m = (struct seq_file *)file->private_data;
1125 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private;
1126 char str[12] = { 0 };
1130 if (!video || count + 1 > sizeof str)
1133 if (copy_from_user(str, buffer, count))
1137 opt = strtoul(str, NULL, 0);
1141 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1143 if (!ACPI_SUCCESS(status))
1149 static int acpi_video_bus_add_fs(struct acpi_device *device)
1151 struct proc_dir_entry *entry = NULL;
1152 struct acpi_video_bus *video;
1155 video = (struct acpi_video_bus *)acpi_driver_data(device);
1157 if (!acpi_device_dir(device)) {
1158 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1160 if (!acpi_device_dir(device))
1162 video->dir = acpi_device_dir(device);
1163 acpi_device_dir(device)->owner = THIS_MODULE;
1167 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1171 entry->proc_fops = &acpi_video_bus_info_fops;
1172 entry->data = acpi_driver_data(device);
1173 entry->owner = THIS_MODULE;
1177 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1181 entry->proc_fops = &acpi_video_bus_ROM_fops;
1182 entry->data = acpi_driver_data(device);
1183 entry->owner = THIS_MODULE;
1186 /* 'POST_info' [R] */
1188 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1192 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1193 entry->data = acpi_driver_data(device);
1194 entry->owner = THIS_MODULE;
1199 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1200 acpi_device_dir(device));
1204 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1205 entry->proc_fops = &acpi_video_bus_POST_fops;
1206 entry->data = acpi_driver_data(device);
1207 entry->owner = THIS_MODULE;
1212 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1213 acpi_device_dir(device));
1217 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1218 entry->proc_fops = &acpi_video_bus_DOS_fops;
1219 entry->data = acpi_driver_data(device);
1220 entry->owner = THIS_MODULE;
1226 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1228 struct acpi_video_bus *video;
1231 video = (struct acpi_video_bus *)acpi_driver_data(device);
1233 if (acpi_device_dir(device)) {
1234 remove_proc_entry("info", acpi_device_dir(device));
1235 remove_proc_entry("ROM", acpi_device_dir(device));
1236 remove_proc_entry("POST_info", acpi_device_dir(device));
1237 remove_proc_entry("POST", acpi_device_dir(device));
1238 remove_proc_entry("DOS", acpi_device_dir(device));
1239 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1240 acpi_device_dir(device) = NULL;
1246 /* --------------------------------------------------------------------------
1248 -------------------------------------------------------------------------- */
1250 /* device interface */
1253 acpi_video_bus_get_one_device(struct acpi_device *device,
1254 struct acpi_video_bus *video)
1256 unsigned long device_id;
1258 struct acpi_video_device *data;
1261 if (!device || !video)
1265 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1266 if (ACPI_SUCCESS(status)) {
1268 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1272 memset(data, 0, sizeof(struct acpi_video_device));
1274 data->handle = device->handle;
1275 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1276 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1277 acpi_driver_data(device) = data;
1279 data->device_id = device_id;
1280 data->video = video;
1283 switch (device_id & 0xffff) {
1285 data->flags.crt = 1;
1288 data->flags.lcd = 1;
1291 data->flags.tvout = 1;
1294 data->flags.unknown = 1;
1298 acpi_video_device_bind(video, data);
1299 acpi_video_device_find_cap(data);
1301 status = acpi_install_notify_handler(data->handle,
1303 acpi_video_device_notify,
1305 if (ACPI_FAILURE(status)) {
1306 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1307 "Error installing notify handler\n"));
1308 if(data->brightness)
1309 kfree(data->brightness->levels);
1310 kfree(data->brightness);
1316 list_add_tail(&data->entry, &video->video_device_list);
1319 acpi_video_device_add_fs(device);
1329 * video : video bus device
1334 * Enumerate the video device list of the video bus,
1335 * bind the ids with the corresponding video devices
1336 * under the video bus.
1339 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1341 struct list_head *node, *next;
1342 list_for_each_safe(node, next, &video->video_device_list) {
1343 struct acpi_video_device *dev =
1344 container_of(node, struct acpi_video_device, entry);
1345 acpi_video_device_bind(video, dev);
1351 * video : video bus device
1352 * device : video output device under the video
1358 * Bind the ids with the corresponding video devices
1359 * under the video bus.
1363 acpi_video_device_bind(struct acpi_video_bus *video,
1364 struct acpi_video_device *device)
1368 #define IDS_VAL(i) video->attached_array[i].value.int_val
1369 #define IDS_BIND(i) video->attached_array[i].bind_info
1371 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1372 i < video->attached_count; i++) {
1373 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1374 IDS_BIND(i) = device;
1375 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1384 * video : video bus device
1389 * Call _DOD to enumerate all devices attached to display adapter
1393 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1398 struct acpi_video_enumerated_device *active_device_list;
1399 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1400 union acpi_object *dod = NULL;
1401 union acpi_object *obj;
1404 status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer);
1405 if (!ACPI_SUCCESS(status)) {
1406 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1410 dod = (union acpi_object *)buffer.pointer;
1411 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1412 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1417 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1418 dod->package.count));
1420 active_device_list = kmalloc((1 +
1421 dod->package.count) *
1423 acpi_video_enumerated_device),
1426 if (!active_device_list) {
1432 for (i = 0; i < dod->package.count; i++) {
1433 obj = (union acpi_object *)&dod->package.elements[i];
1435 if (obj->type != ACPI_TYPE_INTEGER) {
1436 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1437 active_device_list[i].value.int_val =
1438 ACPI_VIDEO_HEAD_INVALID;
1440 active_device_list[i].value.int_val = obj->integer.value;
1441 active_device_list[i].bind_info = NULL;
1442 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1443 (int)obj->integer.value));
1446 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1448 kfree(video->attached_array);
1450 video->attached_array = active_device_list;
1451 video->attached_count = count;
1453 kfree(buffer.pointer);
1459 * video : video bus device
1460 * event : Nontify Event
1465 * 1. Find out the current active output device.
1466 * 2. Identify the next output device to switch
1467 * 3. call _DSS to do actual switch.
1470 static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1472 struct list_head *node, *next;
1473 struct acpi_video_device *dev = NULL;
1474 struct acpi_video_device *dev_next = NULL;
1475 struct acpi_video_device *dev_prev = NULL;
1476 unsigned long state;
1480 list_for_each_safe(node, next, &video->video_device_list) {
1481 dev = container_of(node, struct acpi_video_device, entry);
1482 status = acpi_video_device_get_state(dev, &state);
1485 container_of(node->next, struct acpi_video_device,
1488 container_of(node->prev, struct acpi_video_device,
1493 dev_next = container_of(node->next, struct acpi_video_device, entry);
1494 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1497 case ACPI_VIDEO_NOTIFY_CYCLE:
1498 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1499 acpi_video_device_set_state(dev, 0);
1500 acpi_video_device_set_state(dev_next, 0x80000001);
1502 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1503 acpi_video_device_set_state(dev, 0);
1504 acpi_video_device_set_state(dev_prev, 0x80000001);
1513 acpi_video_get_next_level(struct acpi_video_device *device,
1514 u32 level_current, u32 event)
1517 return level_current;
1521 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1523 unsigned long level_current, level_next;
1524 acpi_video_device_lcd_get_level_current(device, &level_current);
1525 level_next = acpi_video_get_next_level(device, level_current, event);
1526 acpi_video_device_lcd_set_level(device, level_next);
1530 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1531 struct acpi_device *device)
1534 struct list_head *node, *next;
1537 acpi_video_device_enumerate(video);
1539 list_for_each_safe(node, next, &device->children) {
1540 struct acpi_device *dev =
1541 list_entry(node, struct acpi_device, node);
1546 status = acpi_video_bus_get_one_device(dev, video);
1547 if (ACPI_FAILURE(status)) {
1548 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1556 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1559 struct acpi_video_bus *video;
1562 if (!device || !device->video)
1565 video = device->video;
1568 list_del(&device->entry);
1570 acpi_video_device_remove_fs(device->dev);
1572 status = acpi_remove_notify_handler(device->handle,
1574 acpi_video_device_notify);
1579 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1582 struct list_head *node, *next;
1585 list_for_each_safe(node, next, &video->video_device_list) {
1586 struct acpi_video_device *data =
1587 list_entry(node, struct acpi_video_device, entry);
1591 status = acpi_video_bus_put_one_device(data);
1592 if (ACPI_FAILURE(status))
1593 printk(KERN_WARNING PREFIX
1594 "hhuuhhuu bug in acpi video driver.\n");
1596 if (data->brightness)
1597 kfree(data->brightness->levels);
1598 kfree(data->brightness);
1605 /* acpi_video interface */
1607 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1609 return acpi_video_bus_DOS(video, 1, 0);
1612 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1614 return acpi_video_bus_DOS(video, 0, 1);
1617 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1619 struct acpi_video_bus *video = (struct acpi_video_bus *)data;
1620 struct acpi_device *device = NULL;
1622 printk("video bus notify\n");
1627 if (acpi_bus_get_device(handle, &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 if (acpi_bus_get_device(handle, &device))
1675 case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */
1676 case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */
1677 acpi_bus_generate_event(device, event, 0);
1679 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1680 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1681 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1682 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1683 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1684 acpi_video_switch_brightness(video_device, event);
1685 acpi_bus_generate_event(device, event, 0);
1688 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1689 "Unsupported event [0x%x]\n", event));
1695 static int acpi_video_bus_add(struct acpi_device *device)
1698 acpi_status status = 0;
1699 struct acpi_video_bus *video = NULL;
1705 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1708 memset(video, 0, sizeof(struct acpi_video_bus));
1710 video->handle = device->handle;
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);