2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/video_output.h>
38 #include <asm/uaccess.h>
40 #include <acpi/acpi_bus.h>
41 #include <acpi/acpi_drivers.h>
43 #define ACPI_VIDEO_COMPONENT 0x08000000
44 #define ACPI_VIDEO_CLASS "video"
45 #define ACPI_VIDEO_BUS_NAME "Video Bus"
46 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
47 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
49 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
59 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60 #define ACPI_VIDEO_HEAD_END (~0u)
61 #define MAX_NAME_LEN 20
63 #define ACPI_VIDEO_DISPLAY_CRT 1
64 #define ACPI_VIDEO_DISPLAY_TV 2
65 #define ACPI_VIDEO_DISPLAY_DVI 3
66 #define ACPI_VIDEO_DISPLAY_LCD 4
68 #define _COMPONENT ACPI_VIDEO_COMPONENT
69 ACPI_MODULE_NAME("video");
71 MODULE_AUTHOR("Bruno Ducrot");
72 MODULE_DESCRIPTION("ACPI Video Driver");
73 MODULE_LICENSE("GPL");
75 static int brightness_switch_enabled = 1;
76 module_param(brightness_switch_enabled, bool, 0644);
78 static int acpi_video_bus_add(struct acpi_device *device);
79 static int acpi_video_bus_remove(struct acpi_device *device, int type);
80 static int acpi_video_resume(struct acpi_device *device);
82 static const struct acpi_device_id video_device_ids[] = {
86 MODULE_DEVICE_TABLE(acpi, video_device_ids);
88 static struct acpi_driver acpi_video_bus = {
90 .class = ACPI_VIDEO_CLASS,
91 .ids = video_device_ids,
93 .add = acpi_video_bus_add,
94 .remove = acpi_video_bus_remove,
95 .resume = acpi_video_resume,
99 struct acpi_video_bus_flags {
100 u8 multihead:1; /* can switch video heads */
101 u8 rom:1; /* can retrieve a video rom */
102 u8 post:1; /* can configure the head to */
106 struct acpi_video_bus_cap {
107 u8 _DOS:1; /*Enable/Disable output switching */
108 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
109 u8 _ROM:1; /*Get ROM Data */
110 u8 _GPD:1; /*Get POST Device */
111 u8 _SPD:1; /*Set POST Device */
112 u8 _VPO:1; /*Video POST Options */
116 struct acpi_video_device_attrib {
117 u32 display_index:4; /* A zero-based instance of the Display */
118 u32 display_port_attachment:4; /*This field differentiates the display type */
119 u32 display_type:4; /*Describe the specific type in use */
120 u32 vendor_specific:4; /*Chipset Vendor Specific */
121 u32 bios_can_detect:1; /*BIOS can detect the device */
122 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
124 u32 pipe_id:3; /*For VGA multiple-head devices. */
125 u32 reserved:10; /*Must be 0 */
126 u32 device_id_scheme:1; /*Device ID Scheme */
129 struct acpi_video_enumerated_device {
132 struct acpi_video_device_attrib attrib;
134 struct acpi_video_device *bind_info;
137 struct acpi_video_bus {
138 struct acpi_device *device;
140 struct acpi_video_enumerated_device *attached_array;
142 struct acpi_video_bus_cap cap;
143 struct acpi_video_bus_flags flags;
144 struct list_head video_device_list;
145 struct mutex device_list_lock; /* protects video_device_list */
146 struct proc_dir_entry *dir;
147 struct input_dev *input;
148 char phys[32]; /* for input device */
151 struct acpi_video_device_flags {
161 struct acpi_video_device_cap {
162 u8 _ADR:1; /*Return the unique ID */
163 u8 _BCL:1; /*Query list of brightness control levels supported */
164 u8 _BCM:1; /*Set the brightness level */
165 u8 _BQC:1; /* Get current brightness level */
166 u8 _DDC:1; /*Return the EDID for this device */
167 u8 _DCS:1; /*Return status of output device */
168 u8 _DGS:1; /*Query graphics state */
169 u8 _DSS:1; /*Device state set */
172 struct acpi_video_device_brightness {
178 struct acpi_video_device {
179 unsigned long device_id;
180 struct acpi_video_device_flags flags;
181 struct acpi_video_device_cap cap;
182 struct list_head entry;
183 struct acpi_video_bus *video;
184 struct acpi_device *dev;
185 struct acpi_video_device_brightness *brightness;
186 struct backlight_device *backlight;
187 struct output_device *output_dev;
191 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192 static struct file_operations acpi_video_bus_info_fops = {
193 .open = acpi_video_bus_info_open_fs,
196 .release = single_release,
199 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
200 static struct file_operations acpi_video_bus_ROM_fops = {
201 .open = acpi_video_bus_ROM_open_fs,
204 .release = single_release,
207 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
209 static struct file_operations acpi_video_bus_POST_info_fops = {
210 .open = acpi_video_bus_POST_info_open_fs,
213 .release = single_release,
216 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
217 static struct file_operations acpi_video_bus_POST_fops = {
218 .open = acpi_video_bus_POST_open_fs,
221 .release = single_release,
224 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
225 static struct file_operations acpi_video_bus_DOS_fops = {
226 .open = acpi_video_bus_DOS_open_fs,
229 .release = single_release,
233 static int acpi_video_device_info_open_fs(struct inode *inode,
235 static struct file_operations acpi_video_device_info_fops = {
236 .open = acpi_video_device_info_open_fs,
239 .release = single_release,
242 static int acpi_video_device_state_open_fs(struct inode *inode,
244 static struct file_operations acpi_video_device_state_fops = {
245 .open = acpi_video_device_state_open_fs,
248 .release = single_release,
251 static int acpi_video_device_brightness_open_fs(struct inode *inode,
253 static struct file_operations acpi_video_device_brightness_fops = {
254 .open = acpi_video_device_brightness_open_fs,
257 .release = single_release,
260 static int acpi_video_device_EDID_open_fs(struct inode *inode,
262 static struct file_operations acpi_video_device_EDID_fops = {
263 .open = acpi_video_device_EDID_open_fs,
266 .release = single_release,
269 static char device_decode[][30] = {
270 "motherboard VGA device",
276 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
277 static void acpi_video_device_rebind(struct acpi_video_bus *video);
278 static void acpi_video_device_bind(struct acpi_video_bus *video,
279 struct acpi_video_device *device);
280 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
281 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
283 static int acpi_video_device_lcd_get_level_current(
284 struct acpi_video_device *device,
285 unsigned long *level);
286 static int acpi_video_get_next_level(struct acpi_video_device *device,
287 u32 level_current, u32 event);
288 static void acpi_video_switch_brightness(struct acpi_video_device *device,
290 static int acpi_video_device_get_state(struct acpi_video_device *device,
291 unsigned long *state);
292 static int acpi_video_output_get(struct output_device *od);
293 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
295 /*backlight device sysfs support*/
296 static int acpi_video_get_brightness(struct backlight_device *bd)
298 unsigned long cur_level;
299 struct acpi_video_device *vd =
300 (struct acpi_video_device *)bl_get_data(bd);
301 acpi_video_device_lcd_get_level_current(vd, &cur_level);
302 return (int) cur_level;
305 static int acpi_video_set_brightness(struct backlight_device *bd)
307 int request_level = bd->props.brightness;
308 struct acpi_video_device *vd =
309 (struct acpi_video_device *)bl_get_data(bd);
310 acpi_video_device_lcd_set_level(vd, request_level);
314 static struct backlight_ops acpi_backlight_ops = {
315 .get_brightness = acpi_video_get_brightness,
316 .update_status = acpi_video_set_brightness,
319 /*video output device sysfs support*/
320 static int acpi_video_output_get(struct output_device *od)
323 struct acpi_video_device *vd =
324 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
325 acpi_video_device_get_state(vd, &state);
329 static int acpi_video_output_set(struct output_device *od)
331 unsigned long state = od->request_state;
332 struct acpi_video_device *vd=
333 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
334 return acpi_video_device_set_state(vd, state);
337 static struct output_properties acpi_output_properties = {
338 .set_state = acpi_video_output_set,
339 .get_status = acpi_video_output_get,
341 /* --------------------------------------------------------------------------
343 -------------------------------------------------------------------------- */
348 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
352 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
358 acpi_video_device_get_state(struct acpi_video_device *device,
359 unsigned long *state)
363 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
369 acpi_video_device_set_state(struct acpi_video_device *device, int state)
372 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
373 struct acpi_object_list args = { 1, &arg0 };
377 arg0.integer.value = state;
378 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
384 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
385 union acpi_object **levels)
388 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
389 union acpi_object *obj;
394 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
395 if (!ACPI_SUCCESS(status))
397 obj = (union acpi_object *)buffer.pointer;
398 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
399 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
409 kfree(buffer.pointer);
415 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
418 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
419 struct acpi_object_list args = { 1, &arg0 };
422 arg0.integer.value = level;
424 if (device->cap._BCM)
425 status = acpi_evaluate_object(device->dev->handle, "_BCM",
427 device->brightness->curr = level;
432 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
433 unsigned long *level)
435 if (device->cap._BQC)
436 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
438 *level = device->brightness->curr;
443 acpi_video_device_EDID(struct acpi_video_device *device,
444 union acpi_object **edid, ssize_t length)
447 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
448 union acpi_object *obj;
449 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
450 struct acpi_object_list args = { 1, &arg0 };
458 arg0.integer.value = 1;
459 else if (length == 256)
460 arg0.integer.value = 2;
464 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
465 if (ACPI_FAILURE(status))
468 obj = buffer.pointer;
470 if (obj && obj->type == ACPI_TYPE_BUFFER)
473 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
484 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
488 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
489 struct acpi_object_list args = { 1, &arg0 };
492 arg0.integer.value = option;
494 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
495 if (ACPI_SUCCESS(status))
496 status = tmp ? (-EINVAL) : (AE_OK);
502 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
506 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
512 acpi_video_bus_POST_options(struct acpi_video_bus *video,
513 unsigned long *options)
517 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
525 * video : video bus device pointer
527 * 0. The system BIOS should NOT automatically switch(toggle)
528 * the active display output.
529 * 1. The system BIOS should automatically switch (toggle) the
530 * active display output. No switch event.
531 * 2. The _DGS value should be locked.
532 * 3. The system BIOS should not automatically switch (toggle) the
533 * active display output, but instead generate the display switch
536 * 0. The system BIOS should automatically control the brightness level
537 * of the LCD when the power changes from AC to DC
538 * 1. The system BIOS should NOT automatically control the brightness
539 * level of the LCD when the power changes from AC to DC.
545 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
547 acpi_integer status = 0;
548 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
549 struct acpi_object_list args = { 1, &arg0 };
552 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
556 arg0.integer.value = (lcd_flag << 2) | bios_flag;
557 video->dos_setting = arg0.integer.value;
558 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
566 * device : video output device (LCD, CRT, ..)
571 * Find out all required AML methods defined under the output
575 static void acpi_video_device_find_cap(struct acpi_video_device *device)
577 acpi_handle h_dummy1;
580 union acpi_object *obj = NULL;
581 struct acpi_video_device_brightness *br = NULL;
584 memset(&device->cap, 0, sizeof(device->cap));
586 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
587 device->cap._ADR = 1;
589 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
590 device->cap._BCL = 1;
592 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
593 device->cap._BCM = 1;
595 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
596 device->cap._BQC = 1;
597 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
598 device->cap._DDC = 1;
600 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
601 device->cap._DCS = 1;
603 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
604 device->cap._DGS = 1;
606 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
607 device->cap._DSS = 1;
610 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
612 if (obj->package.count >= 2) {
614 union acpi_object *o;
616 br = kzalloc(sizeof(*br), GFP_KERNEL);
618 printk(KERN_ERR "can't allocate memory\n");
620 br->levels = kmalloc(obj->package.count *
621 sizeof *(br->levels), GFP_KERNEL);
625 for (i = 0; i < obj->package.count; i++) {
626 o = (union acpi_object *)&obj->package.
628 if (o->type != ACPI_TYPE_INTEGER) {
629 printk(KERN_ERR PREFIX "Invalid data\n");
632 br->levels[count] = (u32) o->integer.value;
634 if (br->levels[count] > max_level)
635 max_level = br->levels[count];
644 device->brightness = br;
645 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
646 "found %d brightness levels\n",
653 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
658 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
660 static int count = 0;
662 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
666 sprintf(name, "acpi_video%d", count++);
667 acpi_video_device_lcd_get_level_current(device, &tmp);
668 device->backlight = backlight_device_register(name,
669 NULL, device, &acpi_backlight_ops);
670 device->backlight->props.max_brightness = max_level;
671 device->backlight->props.brightness = (int)tmp;
672 backlight_update_status(device->backlight);
676 if (device->cap._DCS && device->cap._DSS){
677 static int count = 0;
679 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
682 sprintf(name, "acpi_video%d", count++);
683 device->output_dev = video_output_register(name,
684 NULL, device, &acpi_output_properties);
692 * device : video output device (VGA)
697 * Find out all required AML methods defined under the video bus device.
700 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
702 acpi_handle h_dummy1;
704 memset(&video->cap, 0, sizeof(video->cap));
705 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
708 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
711 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
714 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
717 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
720 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
726 * Check whether the video bus device has required AML method to
727 * support the desired features
730 static int acpi_video_bus_check(struct acpi_video_bus *video)
732 acpi_status status = -ENOENT;
735 struct acpi_device *device;
740 device = video->device;
743 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
745 if (!ACPI_SUCCESS(status))
748 /* We need to attempt to determine whether the _ADR refers to a
749 PCI device or not. There's no terribly good way to do this,
750 so the best we can hope for is to assume that there'll never
751 be a video device in the host bridge */
752 if (device_id >= 0x10000) {
753 /* It looks like a PCI device. Does it exist? */
754 dev = acpi_get_physical_device(device->handle);
756 /* It doesn't look like a PCI device. Does its parent
759 if (acpi_get_parent(device->handle, &phandle))
761 dev = acpi_get_physical_device(phandle);
767 /* Since there is no HID, CID and so on for VGA driver, we have
768 * to check well known required nodes.
771 /* Does this device support video switching? */
772 if (video->cap._DOS) {
773 video->flags.multihead = 1;
777 /* Does this device support retrieving a video ROM? */
778 if (video->cap._ROM) {
779 video->flags.rom = 1;
783 /* Does this device support configuring which video device to POST? */
784 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
785 video->flags.post = 1;
792 /* --------------------------------------------------------------------------
794 -------------------------------------------------------------------------- */
796 static struct proc_dir_entry *acpi_video_dir;
800 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
802 struct acpi_video_device *dev = seq->private;
808 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
809 seq_printf(seq, "type: ");
811 seq_printf(seq, "CRT\n");
812 else if (dev->flags.lcd)
813 seq_printf(seq, "LCD\n");
814 else if (dev->flags.tvout)
815 seq_printf(seq, "TVOUT\n");
816 else if (dev->flags.dvi)
817 seq_printf(seq, "DVI\n");
819 seq_printf(seq, "UNKNOWN\n");
821 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
828 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
830 return single_open(file, acpi_video_device_info_seq_show,
834 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
837 struct acpi_video_device *dev = seq->private;
844 status = acpi_video_device_get_state(dev, &state);
845 seq_printf(seq, "state: ");
846 if (ACPI_SUCCESS(status))
847 seq_printf(seq, "0x%02lx\n", state);
849 seq_printf(seq, "<not supported>\n");
851 status = acpi_video_device_query(dev, &state);
852 seq_printf(seq, "query: ");
853 if (ACPI_SUCCESS(status))
854 seq_printf(seq, "0x%02lx\n", state);
856 seq_printf(seq, "<not supported>\n");
863 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
865 return single_open(file, acpi_video_device_state_seq_show,
870 acpi_video_device_write_state(struct file *file,
871 const char __user * buffer,
872 size_t count, loff_t * data)
875 struct seq_file *m = file->private_data;
876 struct acpi_video_device *dev = m->private;
877 char str[12] = { 0 };
881 if (!dev || count + 1 > sizeof str)
884 if (copy_from_user(str, buffer, count))
888 state = simple_strtoul(str, NULL, 0);
889 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
891 status = acpi_video_device_set_state(dev, state);
900 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
902 struct acpi_video_device *dev = seq->private;
906 if (!dev || !dev->brightness) {
907 seq_printf(seq, "<not supported>\n");
911 seq_printf(seq, "levels: ");
912 for (i = 0; i < dev->brightness->count; i++)
913 seq_printf(seq, " %d", dev->brightness->levels[i]);
914 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
920 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
922 return single_open(file, acpi_video_device_brightness_seq_show,
927 acpi_video_device_write_brightness(struct file *file,
928 const char __user * buffer,
929 size_t count, loff_t * data)
931 struct seq_file *m = file->private_data;
932 struct acpi_video_device *dev = m->private;
934 unsigned int level = 0;
938 if (!dev || !dev->brightness || count + 1 > sizeof str)
941 if (copy_from_user(str, buffer, count))
945 level = simple_strtoul(str, NULL, 0);
950 /* validate through the list of available levels */
951 for (i = 0; i < dev->brightness->count; i++)
952 if (level == dev->brightness->levels[i]) {
954 (acpi_video_device_lcd_set_level(dev, level)))
955 dev->brightness->curr = level;
962 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
964 struct acpi_video_device *dev = seq->private;
967 union acpi_object *edid = NULL;
973 status = acpi_video_device_EDID(dev, &edid, 128);
974 if (ACPI_FAILURE(status)) {
975 status = acpi_video_device_EDID(dev, &edid, 256);
978 if (ACPI_FAILURE(status)) {
982 if (edid && edid->type == ACPI_TYPE_BUFFER) {
983 for (i = 0; i < edid->buffer.length; i++)
984 seq_putc(seq, edid->buffer.pointer[i]);
989 seq_printf(seq, "<not supported>\n");
997 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
999 return single_open(file, acpi_video_device_EDID_seq_show,
1003 static int acpi_video_device_add_fs(struct acpi_device *device)
1005 struct proc_dir_entry *entry = NULL;
1006 struct acpi_video_device *vid_dev;
1012 vid_dev = acpi_driver_data(device);
1016 if (!acpi_device_dir(device)) {
1017 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1018 vid_dev->video->dir);
1019 if (!acpi_device_dir(device))
1021 acpi_device_dir(device)->owner = THIS_MODULE;
1025 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1029 entry->proc_fops = &acpi_video_device_info_fops;
1030 entry->data = acpi_driver_data(device);
1031 entry->owner = THIS_MODULE;
1036 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1037 acpi_device_dir(device));
1041 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1042 entry->proc_fops = &acpi_video_device_state_fops;
1043 entry->data = acpi_driver_data(device);
1044 entry->owner = THIS_MODULE;
1047 /* 'brightness' [R/W] */
1049 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1050 acpi_device_dir(device));
1054 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1055 entry->proc_fops = &acpi_video_device_brightness_fops;
1056 entry->data = acpi_driver_data(device);
1057 entry->owner = THIS_MODULE;
1061 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1065 entry->proc_fops = &acpi_video_device_EDID_fops;
1066 entry->data = acpi_driver_data(device);
1067 entry->owner = THIS_MODULE;
1073 static int acpi_video_device_remove_fs(struct acpi_device *device)
1075 struct acpi_video_device *vid_dev;
1077 vid_dev = acpi_driver_data(device);
1078 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1081 if (acpi_device_dir(device)) {
1082 remove_proc_entry("info", acpi_device_dir(device));
1083 remove_proc_entry("state", acpi_device_dir(device));
1084 remove_proc_entry("brightness", acpi_device_dir(device));
1085 remove_proc_entry("EDID", acpi_device_dir(device));
1086 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1087 acpi_device_dir(device) = NULL;
1094 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1096 struct acpi_video_bus *video = seq->private;
1102 seq_printf(seq, "Switching heads: %s\n",
1103 video->flags.multihead ? "yes" : "no");
1104 seq_printf(seq, "Video ROM: %s\n",
1105 video->flags.rom ? "yes" : "no");
1106 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1107 video->flags.post ? "yes" : "no");
1113 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1115 return single_open(file, acpi_video_bus_info_seq_show,
1119 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1121 struct acpi_video_bus *video = seq->private;
1127 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1128 seq_printf(seq, "<TODO>\n");
1134 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1136 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1139 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1141 struct acpi_video_bus *video = seq->private;
1142 unsigned long options;
1149 status = acpi_video_bus_POST_options(video, &options);
1150 if (ACPI_SUCCESS(status)) {
1151 if (!(options & 1)) {
1152 printk(KERN_WARNING PREFIX
1153 "The motherboard VGA device is not listed as a possible POST device.\n");
1154 printk(KERN_WARNING PREFIX
1155 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1157 printk("%lx\n", options);
1158 seq_printf(seq, "can POST: <integrated video>");
1160 seq_printf(seq, " <PCI video>");
1162 seq_printf(seq, " <AGP video>");
1163 seq_putc(seq, '\n');
1165 seq_printf(seq, "<not supported>\n");
1171 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1173 return single_open(file, acpi_video_bus_POST_info_seq_show,
1177 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1179 struct acpi_video_bus *video = seq->private;
1187 status = acpi_video_bus_get_POST(video, &id);
1188 if (!ACPI_SUCCESS(status)) {
1189 seq_printf(seq, "<not supported>\n");
1192 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1198 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1200 struct acpi_video_bus *video = seq->private;
1203 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1208 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1210 return single_open(file, acpi_video_bus_POST_seq_show,
1214 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1216 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1220 acpi_video_bus_write_POST(struct file *file,
1221 const char __user * buffer,
1222 size_t count, loff_t * data)
1225 struct seq_file *m = file->private_data;
1226 struct acpi_video_bus *video = m->private;
1227 char str[12] = { 0 };
1228 unsigned long opt, options;
1231 if (!video || count + 1 > sizeof str)
1234 status = acpi_video_bus_POST_options(video, &options);
1235 if (!ACPI_SUCCESS(status))
1238 if (copy_from_user(str, buffer, count))
1242 opt = strtoul(str, NULL, 0);
1246 /* just in case an OEM 'forgot' the motherboard... */
1249 if (options & (1ul << opt)) {
1250 status = acpi_video_bus_set_POST(video, opt);
1251 if (!ACPI_SUCCESS(status))
1260 acpi_video_bus_write_DOS(struct file *file,
1261 const char __user * buffer,
1262 size_t count, loff_t * data)
1265 struct seq_file *m = file->private_data;
1266 struct acpi_video_bus *video = m->private;
1267 char str[12] = { 0 };
1271 if (!video || count + 1 > sizeof str)
1274 if (copy_from_user(str, buffer, count))
1278 opt = strtoul(str, NULL, 0);
1282 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1284 if (!ACPI_SUCCESS(status))
1290 static int acpi_video_bus_add_fs(struct acpi_device *device)
1292 struct proc_dir_entry *entry = NULL;
1293 struct acpi_video_bus *video;
1296 video = acpi_driver_data(device);
1298 if (!acpi_device_dir(device)) {
1299 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1301 if (!acpi_device_dir(device))
1303 video->dir = acpi_device_dir(device);
1304 acpi_device_dir(device)->owner = THIS_MODULE;
1308 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1312 entry->proc_fops = &acpi_video_bus_info_fops;
1313 entry->data = acpi_driver_data(device);
1314 entry->owner = THIS_MODULE;
1318 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1322 entry->proc_fops = &acpi_video_bus_ROM_fops;
1323 entry->data = acpi_driver_data(device);
1324 entry->owner = THIS_MODULE;
1327 /* 'POST_info' [R] */
1329 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1333 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1334 entry->data = acpi_driver_data(device);
1335 entry->owner = THIS_MODULE;
1340 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1341 acpi_device_dir(device));
1345 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1346 entry->proc_fops = &acpi_video_bus_POST_fops;
1347 entry->data = acpi_driver_data(device);
1348 entry->owner = THIS_MODULE;
1353 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1354 acpi_device_dir(device));
1358 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1359 entry->proc_fops = &acpi_video_bus_DOS_fops;
1360 entry->data = acpi_driver_data(device);
1361 entry->owner = THIS_MODULE;
1367 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1369 struct acpi_video_bus *video;
1372 video = acpi_driver_data(device);
1374 if (acpi_device_dir(device)) {
1375 remove_proc_entry("info", acpi_device_dir(device));
1376 remove_proc_entry("ROM", acpi_device_dir(device));
1377 remove_proc_entry("POST_info", acpi_device_dir(device));
1378 remove_proc_entry("POST", acpi_device_dir(device));
1379 remove_proc_entry("DOS", acpi_device_dir(device));
1380 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1381 acpi_device_dir(device) = NULL;
1387 /* --------------------------------------------------------------------------
1389 -------------------------------------------------------------------------- */
1391 /* device interface */
1392 static struct acpi_video_device_attrib*
1393 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1397 for(count = 0; count < video->attached_count; count++)
1398 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1399 return &(video->attached_array[count].value.attrib);
1404 acpi_video_bus_get_one_device(struct acpi_device *device,
1405 struct acpi_video_bus *video)
1407 unsigned long device_id;
1409 struct acpi_video_device *data;
1410 struct acpi_video_device_attrib* attribute;
1412 if (!device || !video)
1416 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1417 if (ACPI_SUCCESS(status)) {
1419 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1423 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1424 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1425 acpi_driver_data(device) = data;
1427 data->device_id = device_id;
1428 data->video = video;
1431 attribute = acpi_video_get_device_attr(video, device_id);
1433 if((attribute != NULL) && attribute->device_id_scheme) {
1434 switch (attribute->display_type) {
1435 case ACPI_VIDEO_DISPLAY_CRT:
1436 data->flags.crt = 1;
1438 case ACPI_VIDEO_DISPLAY_TV:
1439 data->flags.tvout = 1;
1441 case ACPI_VIDEO_DISPLAY_DVI:
1442 data->flags.dvi = 1;
1444 case ACPI_VIDEO_DISPLAY_LCD:
1445 data->flags.lcd = 1;
1448 data->flags.unknown = 1;
1451 if(attribute->bios_can_detect)
1452 data->flags.bios = 1;
1454 data->flags.unknown = 1;
1456 acpi_video_device_bind(video, data);
1457 acpi_video_device_find_cap(data);
1459 status = acpi_install_notify_handler(device->handle,
1461 acpi_video_device_notify,
1463 if (ACPI_FAILURE(status)) {
1464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1465 "Error installing notify handler\n"));
1466 if(data->brightness)
1467 kfree(data->brightness->levels);
1468 kfree(data->brightness);
1473 mutex_lock(&video->device_list_lock);
1474 list_add_tail(&data->entry, &video->video_device_list);
1475 mutex_unlock(&video->device_list_lock);
1477 acpi_video_device_add_fs(device);
1487 * video : video bus device
1492 * Enumerate the video device list of the video bus,
1493 * bind the ids with the corresponding video devices
1494 * under the video bus.
1497 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1499 struct acpi_video_device *dev;
1501 mutex_lock(&video->device_list_lock);
1503 list_for_each_entry(dev, &video->video_device_list, entry)
1504 acpi_video_device_bind(video, dev);
1506 mutex_unlock(&video->device_list_lock);
1511 * video : video bus device
1512 * device : video output device under the video
1518 * Bind the ids with the corresponding video devices
1519 * under the video bus.
1523 acpi_video_device_bind(struct acpi_video_bus *video,
1524 struct acpi_video_device *device)
1528 #define IDS_VAL(i) video->attached_array[i].value.int_val
1529 #define IDS_BIND(i) video->attached_array[i].bind_info
1531 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1532 i < video->attached_count; i++) {
1533 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1534 IDS_BIND(i) = device;
1535 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1544 * video : video bus device
1549 * Call _DOD to enumerate all devices attached to display adapter
1553 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1558 struct acpi_video_enumerated_device *active_device_list;
1559 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1560 union acpi_object *dod = NULL;
1561 union acpi_object *obj;
1563 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1564 if (!ACPI_SUCCESS(status)) {
1565 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1569 dod = buffer.pointer;
1570 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1571 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1576 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1577 dod->package.count));
1579 active_device_list = kmalloc((1 +
1580 dod->package.count) *
1582 acpi_video_enumerated_device),
1585 if (!active_device_list) {
1591 for (i = 0; i < dod->package.count; i++) {
1592 obj = &dod->package.elements[i];
1594 if (obj->type != ACPI_TYPE_INTEGER) {
1595 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1596 active_device_list[i].value.int_val =
1597 ACPI_VIDEO_HEAD_INVALID;
1599 active_device_list[i].value.int_val = obj->integer.value;
1600 active_device_list[i].bind_info = NULL;
1601 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1602 (int)obj->integer.value));
1605 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1607 kfree(video->attached_array);
1609 video->attached_array = active_device_list;
1610 video->attached_count = count;
1612 kfree(buffer.pointer);
1617 acpi_video_get_next_level(struct acpi_video_device *device,
1618 u32 level_current, u32 event)
1620 int min, max, min_above, max_below, i, l, delta = 255;
1621 max = max_below = 0;
1622 min = min_above = 255;
1623 /* Find closest level to level_current */
1624 for (i = 0; i < device->brightness->count; i++) {
1625 l = device->brightness->levels[i];
1626 if (abs(l - level_current) < abs(delta)) {
1627 delta = l - level_current;
1632 /* Ajust level_current to closest available level */
1633 level_current += delta;
1634 for (i = 0; i < device->brightness->count; i++) {
1635 l = device->brightness->levels[i];
1640 if (l < min_above && l > level_current)
1642 if (l > max_below && l < level_current)
1647 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1648 return (level_current < max) ? min_above : min;
1649 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1650 return (level_current < max) ? min_above : max;
1651 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1652 return (level_current > min) ? max_below : min;
1653 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1654 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1657 return level_current;
1662 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1664 unsigned long level_current, level_next;
1665 acpi_video_device_lcd_get_level_current(device, &level_current);
1666 level_next = acpi_video_get_next_level(device, level_current, event);
1667 acpi_video_device_lcd_set_level(device, level_next);
1671 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1672 struct acpi_device *device)
1675 struct acpi_device *dev;
1677 acpi_video_device_enumerate(video);
1679 list_for_each_entry(dev, &device->children, node) {
1681 status = acpi_video_bus_get_one_device(dev, video);
1682 if (ACPI_FAILURE(status)) {
1683 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1690 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1693 struct acpi_video_bus *video;
1696 if (!device || !device->video)
1699 video = device->video;
1701 acpi_video_device_remove_fs(device->dev);
1703 status = acpi_remove_notify_handler(device->dev->handle,
1705 acpi_video_device_notify);
1706 backlight_device_unregister(device->backlight);
1707 video_output_unregister(device->output_dev);
1712 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1715 struct acpi_video_device *dev, *next;
1717 mutex_lock(&video->device_list_lock);
1719 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1721 status = acpi_video_bus_put_one_device(dev);
1722 if (ACPI_FAILURE(status))
1723 printk(KERN_WARNING PREFIX
1724 "hhuuhhuu bug in acpi video driver.\n");
1726 if (dev->brightness) {
1727 kfree(dev->brightness->levels);
1728 kfree(dev->brightness);
1730 list_del(&dev->entry);
1734 mutex_unlock(&video->device_list_lock);
1739 /* acpi_video interface */
1741 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1743 return acpi_video_bus_DOS(video, 0, 0);
1746 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1748 return acpi_video_bus_DOS(video, 0, 1);
1751 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1753 struct acpi_video_bus *video = data;
1754 struct acpi_device *device = NULL;
1755 struct input_dev *input;
1761 device = video->device;
1762 input = video->input;
1765 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1766 * most likely via hotkey. */
1767 acpi_bus_generate_proc_event(device, event, 0);
1768 keycode = KEY_SWITCHVIDEOMODE;
1771 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1773 acpi_video_device_enumerate(video);
1774 acpi_video_device_rebind(video);
1775 acpi_bus_generate_proc_event(device, event, 0);
1776 keycode = KEY_SWITCHVIDEOMODE;
1779 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1780 acpi_bus_generate_proc_event(device, event, 0);
1781 keycode = KEY_SWITCHVIDEOMODE;
1783 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1784 acpi_bus_generate_proc_event(device, event, 0);
1785 keycode = KEY_VIDEO_NEXT;
1787 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1788 acpi_bus_generate_proc_event(device, event, 0);
1789 keycode = KEY_VIDEO_PREV;
1793 keycode = KEY_UNKNOWN;
1794 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1795 "Unsupported event [0x%x]\n", event));
1799 acpi_notifier_call_chain(device, event, 0);
1800 input_report_key(input, keycode, 1);
1802 input_report_key(input, keycode, 0);
1808 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1810 struct acpi_video_device *video_device = data;
1811 struct acpi_device *device = NULL;
1812 struct acpi_video_bus *bus;
1813 struct input_dev *input;
1819 device = video_device->dev;
1820 bus = video_device->video;
1824 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1825 if (brightness_switch_enabled)
1826 acpi_video_switch_brightness(video_device, event);
1827 acpi_bus_generate_proc_event(device, event, 0);
1828 keycode = KEY_BRIGHTNESS_CYCLE;
1830 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1831 if (brightness_switch_enabled)
1832 acpi_video_switch_brightness(video_device, event);
1833 acpi_bus_generate_proc_event(device, event, 0);
1834 keycode = KEY_BRIGHTNESSUP;
1836 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1837 if (brightness_switch_enabled)
1838 acpi_video_switch_brightness(video_device, event);
1839 acpi_bus_generate_proc_event(device, event, 0);
1840 keycode = KEY_BRIGHTNESSDOWN;
1842 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1843 if (brightness_switch_enabled)
1844 acpi_video_switch_brightness(video_device, event);
1845 acpi_bus_generate_proc_event(device, event, 0);
1846 keycode = KEY_BRIGHTNESS_ZERO;
1848 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1849 if (brightness_switch_enabled)
1850 acpi_video_switch_brightness(video_device, event);
1851 acpi_bus_generate_proc_event(device, event, 0);
1852 keycode = KEY_DISPLAY_OFF;
1855 keycode = KEY_UNKNOWN;
1856 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1857 "Unsupported event [0x%x]\n", event));
1861 acpi_notifier_call_chain(device, event, 0);
1862 input_report_key(input, keycode, 1);
1864 input_report_key(input, keycode, 0);
1870 static int instance;
1871 static int acpi_video_resume(struct acpi_device *device)
1873 struct acpi_video_bus *video;
1874 struct acpi_video_device *video_device;
1877 if (!device || !acpi_driver_data(device))
1880 video = acpi_driver_data(device);
1882 for (i = 0; i < video->attached_count; i++) {
1883 video_device = video->attached_array[i].bind_info;
1884 if (video_device && video_device->backlight)
1885 acpi_video_set_brightness(video_device->backlight);
1890 static int acpi_video_bus_add(struct acpi_device *device)
1893 struct acpi_video_bus *video;
1894 struct input_dev *input;
1897 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1901 /* a hack to fix the duplicate name "VID" problem on T61 */
1902 if (!strcmp(device->pnp.bus_id, "VID")) {
1904 device->pnp.bus_id[3] = '0' + instance;
1908 video->device = device;
1909 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1910 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1911 acpi_driver_data(device) = video;
1913 acpi_video_bus_find_cap(video);
1914 error = acpi_video_bus_check(video);
1916 goto err_free_video;
1918 error = acpi_video_bus_add_fs(device);
1920 goto err_free_video;
1922 mutex_init(&video->device_list_lock);
1923 INIT_LIST_HEAD(&video->video_device_list);
1925 acpi_video_bus_get_devices(video, device);
1926 acpi_video_bus_start_devices(video);
1928 status = acpi_install_notify_handler(device->handle,
1930 acpi_video_bus_notify, video);
1931 if (ACPI_FAILURE(status)) {
1932 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1933 "Error installing notify handler\n"));
1935 goto err_stop_video;
1938 video->input = input = input_allocate_device();
1941 goto err_uninstall_notify;
1944 snprintf(video->phys, sizeof(video->phys),
1945 "%s/video/input0", acpi_device_hid(video->device));
1947 input->name = acpi_device_name(video->device);
1948 input->phys = video->phys;
1949 input->id.bustype = BUS_HOST;
1950 input->id.product = 0x06;
1951 input->dev.parent = &device->dev;
1952 input->evbit[0] = BIT(EV_KEY);
1953 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1954 set_bit(KEY_VIDEO_NEXT, input->keybit);
1955 set_bit(KEY_VIDEO_PREV, input->keybit);
1956 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1957 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1958 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1959 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1960 set_bit(KEY_DISPLAY_OFF, input->keybit);
1961 set_bit(KEY_UNKNOWN, input->keybit);
1963 error = input_register_device(input);
1965 goto err_free_input_dev;
1967 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1968 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1969 video->flags.multihead ? "yes" : "no",
1970 video->flags.rom ? "yes" : "no",
1971 video->flags.post ? "yes" : "no");
1976 input_free_device(input);
1977 err_uninstall_notify:
1978 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1979 acpi_video_bus_notify);
1981 acpi_video_bus_stop_devices(video);
1982 acpi_video_bus_put_devices(video);
1983 kfree(video->attached_array);
1984 acpi_video_bus_remove_fs(device);
1987 acpi_driver_data(device) = NULL;
1992 static int acpi_video_bus_remove(struct acpi_device *device, int type)
1994 acpi_status status = 0;
1995 struct acpi_video_bus *video = NULL;
1998 if (!device || !acpi_driver_data(device))
2001 video = acpi_driver_data(device);
2003 acpi_video_bus_stop_devices(video);
2005 status = acpi_remove_notify_handler(video->device->handle,
2007 acpi_video_bus_notify);
2009 acpi_video_bus_put_devices(video);
2010 acpi_video_bus_remove_fs(device);
2012 input_unregister_device(video->input);
2013 kfree(video->attached_array);
2019 static int __init acpi_video_init(void)
2025 acpi_dbg_level = 0xFFFFFFFF;
2026 acpi_dbg_layer = 0x08000000;
2029 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2030 if (!acpi_video_dir)
2032 acpi_video_dir->owner = THIS_MODULE;
2034 result = acpi_bus_register_driver(&acpi_video_bus);
2036 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2043 static void __exit acpi_video_exit(void)
2046 acpi_bus_unregister_driver(&acpi_video_bus);
2048 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2053 module_init(acpi_video_init);
2054 module_exit(acpi_video_exit);