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 acpi_video_bus_add(struct acpi_device *device);
76 static int acpi_video_bus_remove(struct acpi_device *device, int type);
78 static const struct acpi_device_id video_device_ids[] = {
82 MODULE_DEVICE_TABLE(acpi, video_device_ids);
84 static struct acpi_driver acpi_video_bus = {
86 .class = ACPI_VIDEO_CLASS,
87 .ids = video_device_ids,
89 .add = acpi_video_bus_add,
90 .remove = acpi_video_bus_remove,
94 struct acpi_video_bus_flags {
95 u8 multihead:1; /* can switch video heads */
96 u8 rom:1; /* can retrieve a video rom */
97 u8 post:1; /* can configure the head to */
101 struct acpi_video_bus_cap {
102 u8 _DOS:1; /*Enable/Disable output switching */
103 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
104 u8 _ROM:1; /*Get ROM Data */
105 u8 _GPD:1; /*Get POST Device */
106 u8 _SPD:1; /*Set POST Device */
107 u8 _VPO:1; /*Video POST Options */
111 struct acpi_video_device_attrib {
112 u32 display_index:4; /* A zero-based instance of the Display */
113 u32 display_port_attachment:4; /*This field differentiates the display type */
114 u32 display_type:4; /*Describe the specific type in use */
115 u32 vendor_specific:4; /*Chipset Vendor Specific */
116 u32 bios_can_detect:1; /*BIOS can detect the device */
117 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
119 u32 pipe_id:3; /*For VGA multiple-head devices. */
120 u32 reserved:10; /*Must be 0 */
121 u32 device_id_scheme:1; /*Device ID Scheme */
124 struct acpi_video_enumerated_device {
127 struct acpi_video_device_attrib attrib;
129 struct acpi_video_device *bind_info;
132 struct acpi_video_bus {
133 struct acpi_device *device;
135 struct acpi_video_enumerated_device *attached_array;
137 struct acpi_video_bus_cap cap;
138 struct acpi_video_bus_flags flags;
139 struct list_head video_device_list;
140 struct mutex device_list_lock; /* protects video_device_list */
141 struct proc_dir_entry *dir;
142 struct input_dev *input;
143 char phys[32]; /* for input device */
146 struct acpi_video_device_flags {
156 struct acpi_video_device_cap {
157 u8 _ADR:1; /*Return the unique ID */
158 u8 _BCL:1; /*Query list of brightness control levels supported */
159 u8 _BCM:1; /*Set the brightness level */
160 u8 _BQC:1; /* Get current brightness level */
161 u8 _DDC:1; /*Return the EDID for this device */
162 u8 _DCS:1; /*Return status of output device */
163 u8 _DGS:1; /*Query graphics state */
164 u8 _DSS:1; /*Device state set */
167 struct acpi_video_device_brightness {
173 struct acpi_video_device {
174 unsigned long device_id;
175 struct acpi_video_device_flags flags;
176 struct acpi_video_device_cap cap;
177 struct list_head entry;
178 struct acpi_video_bus *video;
179 struct acpi_device *dev;
180 struct acpi_video_device_brightness *brightness;
181 struct backlight_device *backlight;
182 struct output_device *output_dev;
186 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
187 static struct file_operations acpi_video_bus_info_fops = {
188 .open = acpi_video_bus_info_open_fs,
191 .release = single_release,
194 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
195 static struct file_operations acpi_video_bus_ROM_fops = {
196 .open = acpi_video_bus_ROM_open_fs,
199 .release = single_release,
202 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
204 static struct file_operations acpi_video_bus_POST_info_fops = {
205 .open = acpi_video_bus_POST_info_open_fs,
208 .release = single_release,
211 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
212 static struct file_operations acpi_video_bus_POST_fops = {
213 .open = acpi_video_bus_POST_open_fs,
216 .release = single_release,
219 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
220 static struct file_operations acpi_video_bus_DOS_fops = {
221 .open = acpi_video_bus_DOS_open_fs,
224 .release = single_release,
228 static int acpi_video_device_info_open_fs(struct inode *inode,
230 static struct file_operations acpi_video_device_info_fops = {
231 .open = acpi_video_device_info_open_fs,
234 .release = single_release,
237 static int acpi_video_device_state_open_fs(struct inode *inode,
239 static struct file_operations acpi_video_device_state_fops = {
240 .open = acpi_video_device_state_open_fs,
243 .release = single_release,
246 static int acpi_video_device_brightness_open_fs(struct inode *inode,
248 static struct file_operations acpi_video_device_brightness_fops = {
249 .open = acpi_video_device_brightness_open_fs,
252 .release = single_release,
255 static int acpi_video_device_EDID_open_fs(struct inode *inode,
257 static struct file_operations acpi_video_device_EDID_fops = {
258 .open = acpi_video_device_EDID_open_fs,
261 .release = single_release,
264 static char device_decode[][30] = {
265 "motherboard VGA device",
271 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
272 static void acpi_video_device_rebind(struct acpi_video_bus *video);
273 static void acpi_video_device_bind(struct acpi_video_bus *video,
274 struct acpi_video_device *device);
275 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
276 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
277 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
279 static int acpi_video_device_lcd_get_level_current(
280 struct acpi_video_device *device,
281 unsigned long *level);
282 static int acpi_video_get_next_level(struct acpi_video_device *device,
283 u32 level_current, u32 event);
284 static void acpi_video_switch_brightness(struct acpi_video_device *device,
286 static int acpi_video_device_get_state(struct acpi_video_device *device,
287 unsigned long *state);
288 static int acpi_video_output_get(struct output_device *od);
289 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
291 /*backlight device sysfs support*/
292 static int acpi_video_get_brightness(struct backlight_device *bd)
294 unsigned long cur_level;
295 struct acpi_video_device *vd =
296 (struct acpi_video_device *)bl_get_data(bd);
297 acpi_video_device_lcd_get_level_current(vd, &cur_level);
298 return (int) cur_level;
301 static int acpi_video_set_brightness(struct backlight_device *bd)
303 int request_level = bd->props.brightness;
304 struct acpi_video_device *vd =
305 (struct acpi_video_device *)bl_get_data(bd);
306 acpi_video_device_lcd_set_level(vd, request_level);
310 static struct backlight_ops acpi_backlight_ops = {
311 .get_brightness = acpi_video_get_brightness,
312 .update_status = acpi_video_set_brightness,
315 /*video output device sysfs support*/
316 static int acpi_video_output_get(struct output_device *od)
319 struct acpi_video_device *vd =
320 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
321 acpi_video_device_get_state(vd, &state);
325 static int acpi_video_output_set(struct output_device *od)
327 unsigned long state = od->request_state;
328 struct acpi_video_device *vd=
329 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
330 return acpi_video_device_set_state(vd, state);
333 static struct output_properties acpi_output_properties = {
334 .set_state = acpi_video_output_set,
335 .get_status = acpi_video_output_get,
337 /* --------------------------------------------------------------------------
339 -------------------------------------------------------------------------- */
344 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
348 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
354 acpi_video_device_get_state(struct acpi_video_device *device,
355 unsigned long *state)
359 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
365 acpi_video_device_set_state(struct acpi_video_device *device, int state)
368 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
369 struct acpi_object_list args = { 1, &arg0 };
373 arg0.integer.value = state;
374 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
380 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
381 union acpi_object **levels)
384 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
385 union acpi_object *obj;
390 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
391 if (!ACPI_SUCCESS(status))
393 obj = (union acpi_object *)buffer.pointer;
394 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
395 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
405 kfree(buffer.pointer);
411 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
414 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
415 struct acpi_object_list args = { 1, &arg0 };
418 arg0.integer.value = level;
420 if (device->cap._BCM)
421 status = acpi_evaluate_object(device->dev->handle, "_BCM",
423 device->brightness->curr = level;
428 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
429 unsigned long *level)
431 if (device->cap._BQC)
432 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
434 *level = device->brightness->curr;
439 acpi_video_device_EDID(struct acpi_video_device *device,
440 union acpi_object **edid, ssize_t length)
443 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
444 union acpi_object *obj;
445 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
446 struct acpi_object_list args = { 1, &arg0 };
454 arg0.integer.value = 1;
455 else if (length == 256)
456 arg0.integer.value = 2;
460 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
461 if (ACPI_FAILURE(status))
464 obj = buffer.pointer;
466 if (obj && obj->type == ACPI_TYPE_BUFFER)
469 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
480 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
484 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
485 struct acpi_object_list args = { 1, &arg0 };
488 arg0.integer.value = option;
490 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
491 if (ACPI_SUCCESS(status))
492 status = tmp ? (-EINVAL) : (AE_OK);
498 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
502 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
508 acpi_video_bus_POST_options(struct acpi_video_bus *video,
509 unsigned long *options)
513 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
521 * video : video bus device pointer
523 * 0. The system BIOS should NOT automatically switch(toggle)
524 * the active display output.
525 * 1. The system BIOS should automatically switch (toggle) the
526 * active display output. No switch event.
527 * 2. The _DGS value should be locked.
528 * 3. The system BIOS should not automatically switch (toggle) the
529 * active display output, but instead generate the display switch
532 * 0. The system BIOS should automatically control the brightness level
533 * of the LCD when the power changes from AC to DC
534 * 1. The system BIOS should NOT automatically control the brightness
535 * level of the LCD when the power changes from AC to DC.
541 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
543 acpi_integer status = 0;
544 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
545 struct acpi_object_list args = { 1, &arg0 };
548 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
552 arg0.integer.value = (lcd_flag << 2) | bios_flag;
553 video->dos_setting = arg0.integer.value;
554 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
562 * device : video output device (LCD, CRT, ..)
567 * Find out all required AML methods defined under the output
571 static void acpi_video_device_find_cap(struct acpi_video_device *device)
573 acpi_handle h_dummy1;
576 union acpi_object *obj = NULL;
577 struct acpi_video_device_brightness *br = NULL;
580 memset(&device->cap, 0, sizeof(device->cap));
582 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
583 device->cap._ADR = 1;
585 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
586 device->cap._BCL = 1;
588 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
589 device->cap._BCM = 1;
591 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
592 device->cap._BQC = 1;
593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
594 device->cap._DDC = 1;
596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
597 device->cap._DCS = 1;
599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
600 device->cap._DGS = 1;
602 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
603 device->cap._DSS = 1;
606 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
608 if (obj->package.count >= 2) {
610 union acpi_object *o;
612 br = kzalloc(sizeof(*br), GFP_KERNEL);
614 printk(KERN_ERR "can't allocate memory\n");
616 br->levels = kmalloc(obj->package.count *
617 sizeof *(br->levels), GFP_KERNEL);
621 for (i = 0; i < obj->package.count; i++) {
622 o = (union acpi_object *)&obj->package.
624 if (o->type != ACPI_TYPE_INTEGER) {
625 printk(KERN_ERR PREFIX "Invalid data\n");
628 br->levels[count] = (u32) o->integer.value;
630 if (br->levels[count] > max_level)
631 max_level = br->levels[count];
640 device->brightness = br;
641 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
642 "found %d brightness levels\n",
649 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
654 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
656 static int count = 0;
658 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
662 sprintf(name, "acpi_video%d", count++);
663 acpi_video_device_lcd_get_level_current(device, &tmp);
664 device->backlight = backlight_device_register(name,
665 NULL, device, &acpi_backlight_ops);
666 device->backlight->props.max_brightness = max_level;
667 device->backlight->props.brightness = (int)tmp;
668 backlight_update_status(device->backlight);
672 if (device->cap._DCS && device->cap._DSS){
673 static int count = 0;
675 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
678 sprintf(name, "acpi_video%d", count++);
679 device->output_dev = video_output_register(name,
680 NULL, device, &acpi_output_properties);
688 * device : video output device (VGA)
693 * Find out all required AML methods defined under the video bus device.
696 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
698 acpi_handle h_dummy1;
700 memset(&video->cap, 0, sizeof(video->cap));
701 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
704 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
716 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
722 * Check whether the video bus device has required AML method to
723 * support the desired features
726 static int acpi_video_bus_check(struct acpi_video_bus *video)
728 acpi_status status = -ENOENT;
734 /* Since there is no HID, CID and so on for VGA driver, we have
735 * to check well known required nodes.
738 /* Does this device support video switching? */
739 if (video->cap._DOS) {
740 video->flags.multihead = 1;
744 /* Does this device support retrieving a video ROM? */
745 if (video->cap._ROM) {
746 video->flags.rom = 1;
750 /* Does this device support configuring which video device to POST? */
751 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
752 video->flags.post = 1;
759 /* --------------------------------------------------------------------------
761 -------------------------------------------------------------------------- */
763 static struct proc_dir_entry *acpi_video_dir;
767 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
769 struct acpi_video_device *dev = seq->private;
775 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
776 seq_printf(seq, "type: ");
778 seq_printf(seq, "CRT\n");
779 else if (dev->flags.lcd)
780 seq_printf(seq, "LCD\n");
781 else if (dev->flags.tvout)
782 seq_printf(seq, "TVOUT\n");
783 else if (dev->flags.dvi)
784 seq_printf(seq, "DVI\n");
786 seq_printf(seq, "UNKNOWN\n");
788 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
795 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
797 return single_open(file, acpi_video_device_info_seq_show,
801 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
804 struct acpi_video_device *dev = seq->private;
811 status = acpi_video_device_get_state(dev, &state);
812 seq_printf(seq, "state: ");
813 if (ACPI_SUCCESS(status))
814 seq_printf(seq, "0x%02lx\n", state);
816 seq_printf(seq, "<not supported>\n");
818 status = acpi_video_device_query(dev, &state);
819 seq_printf(seq, "query: ");
820 if (ACPI_SUCCESS(status))
821 seq_printf(seq, "0x%02lx\n", state);
823 seq_printf(seq, "<not supported>\n");
830 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
832 return single_open(file, acpi_video_device_state_seq_show,
837 acpi_video_device_write_state(struct file *file,
838 const char __user * buffer,
839 size_t count, loff_t * data)
842 struct seq_file *m = file->private_data;
843 struct acpi_video_device *dev = m->private;
844 char str[12] = { 0 };
848 if (!dev || count + 1 > sizeof str)
851 if (copy_from_user(str, buffer, count))
855 state = simple_strtoul(str, NULL, 0);
856 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
858 status = acpi_video_device_set_state(dev, state);
867 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
869 struct acpi_video_device *dev = seq->private;
873 if (!dev || !dev->brightness) {
874 seq_printf(seq, "<not supported>\n");
878 seq_printf(seq, "levels: ");
879 for (i = 0; i < dev->brightness->count; i++)
880 seq_printf(seq, " %d", dev->brightness->levels[i]);
881 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
887 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
889 return single_open(file, acpi_video_device_brightness_seq_show,
894 acpi_video_device_write_brightness(struct file *file,
895 const char __user * buffer,
896 size_t count, loff_t * data)
898 struct seq_file *m = file->private_data;
899 struct acpi_video_device *dev = m->private;
901 unsigned int level = 0;
905 if (!dev || !dev->brightness || count + 1 > sizeof str)
908 if (copy_from_user(str, buffer, count))
912 level = simple_strtoul(str, NULL, 0);
917 /* validate through the list of available levels */
918 for (i = 0; i < dev->brightness->count; i++)
919 if (level == dev->brightness->levels[i]) {
921 (acpi_video_device_lcd_set_level(dev, level)))
922 dev->brightness->curr = level;
929 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
931 struct acpi_video_device *dev = seq->private;
934 union acpi_object *edid = NULL;
940 status = acpi_video_device_EDID(dev, &edid, 128);
941 if (ACPI_FAILURE(status)) {
942 status = acpi_video_device_EDID(dev, &edid, 256);
945 if (ACPI_FAILURE(status)) {
949 if (edid && edid->type == ACPI_TYPE_BUFFER) {
950 for (i = 0; i < edid->buffer.length; i++)
951 seq_putc(seq, edid->buffer.pointer[i]);
956 seq_printf(seq, "<not supported>\n");
964 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
966 return single_open(file, acpi_video_device_EDID_seq_show,
970 static int acpi_video_device_add_fs(struct acpi_device *device)
972 struct proc_dir_entry *entry = NULL;
973 struct acpi_video_device *vid_dev;
979 vid_dev = acpi_driver_data(device);
983 if (!acpi_device_dir(device)) {
984 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
985 vid_dev->video->dir);
986 if (!acpi_device_dir(device))
988 acpi_device_dir(device)->owner = THIS_MODULE;
992 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
996 entry->proc_fops = &acpi_video_device_info_fops;
997 entry->data = acpi_driver_data(device);
998 entry->owner = THIS_MODULE;
1003 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1004 acpi_device_dir(device));
1008 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1009 entry->proc_fops = &acpi_video_device_state_fops;
1010 entry->data = acpi_driver_data(device);
1011 entry->owner = THIS_MODULE;
1014 /* 'brightness' [R/W] */
1016 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1017 acpi_device_dir(device));
1021 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1022 entry->proc_fops = &acpi_video_device_brightness_fops;
1023 entry->data = acpi_driver_data(device);
1024 entry->owner = THIS_MODULE;
1028 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1032 entry->proc_fops = &acpi_video_device_EDID_fops;
1033 entry->data = acpi_driver_data(device);
1034 entry->owner = THIS_MODULE;
1040 static int acpi_video_device_remove_fs(struct acpi_device *device)
1042 struct acpi_video_device *vid_dev;
1044 vid_dev = acpi_driver_data(device);
1045 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1048 if (acpi_device_dir(device)) {
1049 remove_proc_entry("info", acpi_device_dir(device));
1050 remove_proc_entry("state", acpi_device_dir(device));
1051 remove_proc_entry("brightness", acpi_device_dir(device));
1052 remove_proc_entry("EDID", acpi_device_dir(device));
1053 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1054 acpi_device_dir(device) = NULL;
1061 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1063 struct acpi_video_bus *video = seq->private;
1069 seq_printf(seq, "Switching heads: %s\n",
1070 video->flags.multihead ? "yes" : "no");
1071 seq_printf(seq, "Video ROM: %s\n",
1072 video->flags.rom ? "yes" : "no");
1073 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1074 video->flags.post ? "yes" : "no");
1080 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1082 return single_open(file, acpi_video_bus_info_seq_show,
1086 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1088 struct acpi_video_bus *video = seq->private;
1094 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1095 seq_printf(seq, "<TODO>\n");
1101 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1103 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1106 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1108 struct acpi_video_bus *video = seq->private;
1109 unsigned long options;
1116 status = acpi_video_bus_POST_options(video, &options);
1117 if (ACPI_SUCCESS(status)) {
1118 if (!(options & 1)) {
1119 printk(KERN_WARNING PREFIX
1120 "The motherboard VGA device is not listed as a possible POST device.\n");
1121 printk(KERN_WARNING PREFIX
1122 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1124 printk("%lx\n", options);
1125 seq_printf(seq, "can POST: <integrated video>");
1127 seq_printf(seq, " <PCI video>");
1129 seq_printf(seq, " <AGP video>");
1130 seq_putc(seq, '\n');
1132 seq_printf(seq, "<not supported>\n");
1138 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1140 return single_open(file, acpi_video_bus_POST_info_seq_show,
1144 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1146 struct acpi_video_bus *video = seq->private;
1154 status = acpi_video_bus_get_POST(video, &id);
1155 if (!ACPI_SUCCESS(status)) {
1156 seq_printf(seq, "<not supported>\n");
1159 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1165 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1167 struct acpi_video_bus *video = seq->private;
1170 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1175 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1177 return single_open(file, acpi_video_bus_POST_seq_show,
1181 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1183 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1187 acpi_video_bus_write_POST(struct file *file,
1188 const char __user * buffer,
1189 size_t count, loff_t * data)
1192 struct seq_file *m = file->private_data;
1193 struct acpi_video_bus *video = m->private;
1194 char str[12] = { 0 };
1195 unsigned long opt, options;
1198 if (!video || count + 1 > sizeof str)
1201 status = acpi_video_bus_POST_options(video, &options);
1202 if (!ACPI_SUCCESS(status))
1205 if (copy_from_user(str, buffer, count))
1209 opt = strtoul(str, NULL, 0);
1213 /* just in case an OEM 'forgot' the motherboard... */
1216 if (options & (1ul << opt)) {
1217 status = acpi_video_bus_set_POST(video, opt);
1218 if (!ACPI_SUCCESS(status))
1227 acpi_video_bus_write_DOS(struct file *file,
1228 const char __user * buffer,
1229 size_t count, loff_t * data)
1232 struct seq_file *m = file->private_data;
1233 struct acpi_video_bus *video = m->private;
1234 char str[12] = { 0 };
1238 if (!video || count + 1 > sizeof str)
1241 if (copy_from_user(str, buffer, count))
1245 opt = strtoul(str, NULL, 0);
1249 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1251 if (!ACPI_SUCCESS(status))
1257 static int acpi_video_bus_add_fs(struct acpi_device *device)
1261 struct proc_dir_entry *entry = NULL;
1262 struct acpi_video_bus *video;
1266 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1268 if (!ACPI_SUCCESS(status))
1271 /* We need to attempt to determine whether the _ADR refers to a
1272 PCI device or not. There's no terribly good way to do this,
1273 so the best we can hope for is to assume that there'll never
1274 be a video device in the host bridge */
1275 if (device_id >= 0x10000) {
1276 /* It looks like a PCI device. Does it exist? */
1277 dev = acpi_get_physical_device(device->handle);
1279 /* It doesn't look like a PCI device. Does its parent
1281 acpi_handle phandle;
1282 if (acpi_get_parent(device->handle, &phandle))
1284 dev = acpi_get_physical_device(phandle);
1292 video = acpi_driver_data(device);
1294 if (!acpi_device_dir(device)) {
1295 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1297 if (!acpi_device_dir(device))
1299 video->dir = acpi_device_dir(device);
1300 acpi_device_dir(device)->owner = THIS_MODULE;
1304 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1308 entry->proc_fops = &acpi_video_bus_info_fops;
1309 entry->data = acpi_driver_data(device);
1310 entry->owner = THIS_MODULE;
1314 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1318 entry->proc_fops = &acpi_video_bus_ROM_fops;
1319 entry->data = acpi_driver_data(device);
1320 entry->owner = THIS_MODULE;
1323 /* 'POST_info' [R] */
1325 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1329 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1330 entry->data = acpi_driver_data(device);
1331 entry->owner = THIS_MODULE;
1336 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1337 acpi_device_dir(device));
1341 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1342 entry->proc_fops = &acpi_video_bus_POST_fops;
1343 entry->data = acpi_driver_data(device);
1344 entry->owner = THIS_MODULE;
1349 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1350 acpi_device_dir(device));
1354 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1355 entry->proc_fops = &acpi_video_bus_DOS_fops;
1356 entry->data = acpi_driver_data(device);
1357 entry->owner = THIS_MODULE;
1363 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1365 struct acpi_video_bus *video;
1368 video = acpi_driver_data(device);
1370 if (acpi_device_dir(device)) {
1371 remove_proc_entry("info", acpi_device_dir(device));
1372 remove_proc_entry("ROM", acpi_device_dir(device));
1373 remove_proc_entry("POST_info", acpi_device_dir(device));
1374 remove_proc_entry("POST", acpi_device_dir(device));
1375 remove_proc_entry("DOS", acpi_device_dir(device));
1376 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1377 acpi_device_dir(device) = NULL;
1383 /* --------------------------------------------------------------------------
1385 -------------------------------------------------------------------------- */
1387 /* device interface */
1388 static struct acpi_video_device_attrib*
1389 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1393 for(count = 0; count < video->attached_count; count++)
1394 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1395 return &(video->attached_array[count].value.attrib);
1400 acpi_video_bus_get_one_device(struct acpi_device *device,
1401 struct acpi_video_bus *video)
1403 unsigned long device_id;
1405 struct acpi_video_device *data;
1406 struct acpi_video_device_attrib* attribute;
1408 if (!device || !video)
1412 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1413 if (ACPI_SUCCESS(status)) {
1415 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1419 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1420 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1421 acpi_driver_data(device) = data;
1423 data->device_id = device_id;
1424 data->video = video;
1427 attribute = acpi_video_get_device_attr(video, device_id);
1429 if((attribute != NULL) && attribute->device_id_scheme) {
1430 switch (attribute->display_type) {
1431 case ACPI_VIDEO_DISPLAY_CRT:
1432 data->flags.crt = 1;
1434 case ACPI_VIDEO_DISPLAY_TV:
1435 data->flags.tvout = 1;
1437 case ACPI_VIDEO_DISPLAY_DVI:
1438 data->flags.dvi = 1;
1440 case ACPI_VIDEO_DISPLAY_LCD:
1441 data->flags.lcd = 1;
1444 data->flags.unknown = 1;
1447 if(attribute->bios_can_detect)
1448 data->flags.bios = 1;
1450 data->flags.unknown = 1;
1452 acpi_video_device_bind(video, data);
1453 acpi_video_device_find_cap(data);
1455 status = acpi_install_notify_handler(device->handle,
1457 acpi_video_device_notify,
1459 if (ACPI_FAILURE(status)) {
1460 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1461 "Error installing notify handler\n"));
1462 if(data->brightness)
1463 kfree(data->brightness->levels);
1464 kfree(data->brightness);
1469 mutex_lock(&video->device_list_lock);
1470 list_add_tail(&data->entry, &video->video_device_list);
1471 mutex_unlock(&video->device_list_lock);
1473 acpi_video_device_add_fs(device);
1483 * video : video bus device
1488 * Enumerate the video device list of the video bus,
1489 * bind the ids with the corresponding video devices
1490 * under the video bus.
1493 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1495 struct acpi_video_device *dev;
1497 mutex_lock(&video->device_list_lock);
1499 list_for_each_entry(dev, &video->video_device_list, entry)
1500 acpi_video_device_bind(video, dev);
1502 mutex_unlock(&video->device_list_lock);
1507 * video : video bus device
1508 * device : video output device under the video
1514 * Bind the ids with the corresponding video devices
1515 * under the video bus.
1519 acpi_video_device_bind(struct acpi_video_bus *video,
1520 struct acpi_video_device *device)
1524 #define IDS_VAL(i) video->attached_array[i].value.int_val
1525 #define IDS_BIND(i) video->attached_array[i].bind_info
1527 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1528 i < video->attached_count; i++) {
1529 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1530 IDS_BIND(i) = device;
1531 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1540 * video : video bus device
1545 * Call _DOD to enumerate all devices attached to display adapter
1549 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1554 struct acpi_video_enumerated_device *active_device_list;
1555 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1556 union acpi_object *dod = NULL;
1557 union acpi_object *obj;
1559 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1560 if (!ACPI_SUCCESS(status)) {
1561 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1565 dod = buffer.pointer;
1566 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1567 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1572 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1573 dod->package.count));
1575 active_device_list = kmalloc((1 +
1576 dod->package.count) *
1578 acpi_video_enumerated_device),
1581 if (!active_device_list) {
1587 for (i = 0; i < dod->package.count; i++) {
1588 obj = &dod->package.elements[i];
1590 if (obj->type != ACPI_TYPE_INTEGER) {
1591 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1592 active_device_list[i].value.int_val =
1593 ACPI_VIDEO_HEAD_INVALID;
1595 active_device_list[i].value.int_val = obj->integer.value;
1596 active_device_list[i].bind_info = NULL;
1597 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1598 (int)obj->integer.value));
1601 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1603 kfree(video->attached_array);
1605 video->attached_array = active_device_list;
1606 video->attached_count = count;
1608 kfree(buffer.pointer);
1614 * video : video bus device
1615 * event : notify event
1620 * 1. Find out the current active output device.
1621 * 2. Identify the next output device to switch to.
1622 * 3. call _DSS to do actual switch.
1625 static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1627 struct list_head *node;
1628 struct acpi_video_device *dev = NULL;
1629 struct acpi_video_device *dev_next = NULL;
1630 struct acpi_video_device *dev_prev = NULL;
1631 unsigned long state;
1634 mutex_lock(&video->device_list_lock);
1636 list_for_each(node, &video->video_device_list) {
1637 dev = container_of(node, struct acpi_video_device, entry);
1638 status = acpi_video_device_get_state(dev, &state);
1640 dev_next = container_of(node->next,
1641 struct acpi_video_device, entry);
1642 dev_prev = container_of(node->prev,
1643 struct acpi_video_device, entry);
1648 dev_next = container_of(node->next, struct acpi_video_device, entry);
1649 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1652 mutex_unlock(&video->device_list_lock);
1655 case ACPI_VIDEO_NOTIFY_CYCLE:
1656 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1657 acpi_video_device_set_state(dev, 0);
1658 acpi_video_device_set_state(dev_next, 0x80000001);
1660 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1661 acpi_video_device_set_state(dev, 0);
1662 acpi_video_device_set_state(dev_prev, 0x80000001);
1671 acpi_video_get_next_level(struct acpi_video_device *device,
1672 u32 level_current, u32 event)
1674 int min, max, min_above, max_below, i, l, delta = 255;
1675 max = max_below = 0;
1676 min = min_above = 255;
1677 /* Find closest level to level_current */
1678 for (i = 0; i < device->brightness->count; i++) {
1679 l = device->brightness->levels[i];
1680 if (abs(l - level_current) < abs(delta)) {
1681 delta = l - level_current;
1686 /* Ajust level_current to closest available level */
1687 level_current += delta;
1688 for (i = 0; i < device->brightness->count; i++) {
1689 l = device->brightness->levels[i];
1694 if (l < min_above && l > level_current)
1696 if (l > max_below && l < level_current)
1701 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1702 return (level_current < max) ? min_above : min;
1703 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1704 return (level_current < max) ? min_above : max;
1705 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1706 return (level_current > min) ? max_below : min;
1707 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1708 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1711 return level_current;
1716 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1718 unsigned long level_current, level_next;
1719 acpi_video_device_lcd_get_level_current(device, &level_current);
1720 level_next = acpi_video_get_next_level(device, level_current, event);
1721 acpi_video_device_lcd_set_level(device, level_next);
1725 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1726 struct acpi_device *device)
1729 struct acpi_device *dev;
1731 acpi_video_device_enumerate(video);
1733 list_for_each_entry(dev, &device->children, node) {
1735 status = acpi_video_bus_get_one_device(dev, video);
1736 if (ACPI_FAILURE(status)) {
1737 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1744 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1747 struct acpi_video_bus *video;
1750 if (!device || !device->video)
1753 video = device->video;
1755 acpi_video_device_remove_fs(device->dev);
1757 status = acpi_remove_notify_handler(device->dev->handle,
1759 acpi_video_device_notify);
1760 backlight_device_unregister(device->backlight);
1761 video_output_unregister(device->output_dev);
1766 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1769 struct acpi_video_device *dev, *next;
1771 mutex_lock(&video->device_list_lock);
1773 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1775 status = acpi_video_bus_put_one_device(dev);
1776 if (ACPI_FAILURE(status))
1777 printk(KERN_WARNING PREFIX
1778 "hhuuhhuu bug in acpi video driver.\n");
1780 if (dev->brightness) {
1781 kfree(dev->brightness->levels);
1782 kfree(dev->brightness);
1784 list_del(&dev->entry);
1788 mutex_unlock(&video->device_list_lock);
1793 /* acpi_video interface */
1795 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1797 return acpi_video_bus_DOS(video, 0, 0);
1800 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1802 return acpi_video_bus_DOS(video, 0, 1);
1805 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1807 struct acpi_video_bus *video = data;
1808 struct acpi_device *device = NULL;
1809 struct input_dev *input;
1815 device = video->device;
1816 input = video->input;
1819 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1820 * most likely via hotkey. */
1821 acpi_bus_generate_proc_event(device, event, 0);
1822 keycode = KEY_SWITCHVIDEOMODE;
1825 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1827 acpi_video_device_enumerate(video);
1828 acpi_video_device_rebind(video);
1829 acpi_video_switch_output(video, event);
1830 acpi_bus_generate_proc_event(device, event, 0);
1831 keycode = KEY_SWITCHVIDEOMODE;
1834 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1835 acpi_video_switch_output(video, event);
1836 acpi_bus_generate_proc_event(device, event, 0);
1837 keycode = KEY_SWITCHVIDEOMODE;
1839 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1840 acpi_video_switch_output(video, event);
1841 acpi_bus_generate_proc_event(device, event, 0);
1842 keycode = KEY_VIDEO_NEXT;
1844 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1845 acpi_video_switch_output(video, event);
1846 acpi_bus_generate_proc_event(device, event, 0);
1847 keycode = KEY_VIDEO_PREV;
1851 keycode = KEY_UNKNOWN;
1852 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1853 "Unsupported event [0x%x]\n", event));
1857 input_report_key(input, keycode, 1);
1859 input_report_key(input, keycode, 0);
1865 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1867 struct acpi_video_device *video_device = data;
1868 struct acpi_device *device = NULL;
1869 struct acpi_video_bus *bus;
1870 struct input_dev *input;
1876 device = video_device->dev;
1877 bus = video_device->video;
1881 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1882 acpi_video_switch_brightness(video_device, event);
1883 acpi_bus_generate_proc_event(device, event, 0);
1884 keycode = KEY_BRIGHTNESS_CYCLE;
1886 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1887 acpi_video_switch_brightness(video_device, event);
1888 acpi_bus_generate_proc_event(device, event, 0);
1889 keycode = KEY_BRIGHTNESSUP;
1891 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1892 acpi_video_switch_brightness(video_device, event);
1893 acpi_bus_generate_proc_event(device, event, 0);
1894 keycode = KEY_BRIGHTNESSDOWN;
1896 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1897 acpi_video_switch_brightness(video_device, event);
1898 acpi_bus_generate_proc_event(device, event, 0);
1899 keycode = KEY_BRIGHTNESS_ZERO;
1901 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1902 acpi_video_switch_brightness(video_device, event);
1903 acpi_bus_generate_proc_event(device, event, 0);
1904 keycode = KEY_DISPLAY_OFF;
1907 keycode = KEY_UNKNOWN;
1908 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1909 "Unsupported event [0x%x]\n", event));
1913 input_report_key(input, keycode, 1);
1915 input_report_key(input, keycode, 0);
1921 static int instance;
1922 static int acpi_video_bus_add(struct acpi_device *device)
1925 struct acpi_video_bus *video;
1926 struct input_dev *input;
1929 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1933 /* a hack to fix the duplicate name "VID" problem on T61 */
1934 if (!strcmp(device->pnp.bus_id, "VID")) {
1936 device->pnp.bus_id[3] = '0' + instance;
1940 video->device = device;
1941 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1942 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1943 acpi_driver_data(device) = video;
1945 acpi_video_bus_find_cap(video);
1946 error = acpi_video_bus_check(video);
1948 goto err_free_video;
1950 error = acpi_video_bus_add_fs(device);
1952 goto err_free_video;
1954 mutex_init(&video->device_list_lock);
1955 INIT_LIST_HEAD(&video->video_device_list);
1957 acpi_video_bus_get_devices(video, device);
1958 acpi_video_bus_start_devices(video);
1960 status = acpi_install_notify_handler(device->handle,
1962 acpi_video_bus_notify, video);
1963 if (ACPI_FAILURE(status)) {
1964 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1965 "Error installing notify handler\n"));
1967 goto err_stop_video;
1970 video->input = input = input_allocate_device();
1973 goto err_uninstall_notify;
1976 snprintf(video->phys, sizeof(video->phys),
1977 "%s/video/input0", acpi_device_hid(video->device));
1979 input->name = acpi_device_name(video->device);
1980 input->phys = video->phys;
1981 input->id.bustype = BUS_HOST;
1982 input->id.product = 0x06;
1983 input->dev.parent = &device->dev;
1984 input->evbit[0] = BIT(EV_KEY);
1985 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1986 set_bit(KEY_VIDEO_NEXT, input->keybit);
1987 set_bit(KEY_VIDEO_PREV, input->keybit);
1988 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1989 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1990 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1991 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1992 set_bit(KEY_DISPLAY_OFF, input->keybit);
1993 set_bit(KEY_UNKNOWN, input->keybit);
1995 error = input_register_device(input);
1997 goto err_free_input_dev;
1999 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2000 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2001 video->flags.multihead ? "yes" : "no",
2002 video->flags.rom ? "yes" : "no",
2003 video->flags.post ? "yes" : "no");
2008 input_free_device(input);
2009 err_uninstall_notify:
2010 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2011 acpi_video_bus_notify);
2013 acpi_video_bus_stop_devices(video);
2014 acpi_video_bus_put_devices(video);
2015 kfree(video->attached_array);
2016 acpi_video_bus_remove_fs(device);
2019 acpi_driver_data(device) = NULL;
2024 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2026 acpi_status status = 0;
2027 struct acpi_video_bus *video = NULL;
2030 if (!device || !acpi_driver_data(device))
2033 video = acpi_driver_data(device);
2035 acpi_video_bus_stop_devices(video);
2037 status = acpi_remove_notify_handler(video->device->handle,
2039 acpi_video_bus_notify);
2041 acpi_video_bus_put_devices(video);
2042 acpi_video_bus_remove_fs(device);
2044 input_unregister_device(video->input);
2045 kfree(video->attached_array);
2051 static int __init acpi_video_init(void)
2057 acpi_dbg_level = 0xFFFFFFFF;
2058 acpi_dbg_layer = 0x08000000;
2061 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2062 if (!acpi_video_dir)
2064 acpi_video_dir->owner = THIS_MODULE;
2066 result = acpi_bus_register_driver(&acpi_video_bus);
2068 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2075 static void __exit acpi_video_exit(void)
2078 acpi_bus_unregister_driver(&acpi_video_bus);
2080 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2085 module_init(acpi_video_init);
2086 module_exit(acpi_video_exit);