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/thermal.h>
38 #include <linux/video_output.h>
39 #include <asm/uaccess.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
44 #define ACPI_VIDEO_COMPONENT 0x08000000
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
61 #define ACPI_VIDEO_HEAD_END (~0u)
62 #define MAX_NAME_LEN 20
64 #define ACPI_VIDEO_DISPLAY_CRT 1
65 #define ACPI_VIDEO_DISPLAY_TV 2
66 #define ACPI_VIDEO_DISPLAY_DVI 3
67 #define ACPI_VIDEO_DISPLAY_LCD 4
69 #define _COMPONENT ACPI_VIDEO_COMPONENT
70 ACPI_MODULE_NAME("video");
72 MODULE_AUTHOR("Bruno Ducrot");
73 MODULE_DESCRIPTION("ACPI Video Driver");
74 MODULE_LICENSE("GPL");
76 static int acpi_video_bus_add(struct acpi_device *device);
77 static int acpi_video_bus_remove(struct acpi_device *device, int type);
79 static const struct acpi_device_id video_device_ids[] = {
83 MODULE_DEVICE_TABLE(acpi, video_device_ids);
85 static struct acpi_driver acpi_video_bus = {
87 .class = ACPI_VIDEO_CLASS,
88 .ids = video_device_ids,
90 .add = acpi_video_bus_add,
91 .remove = acpi_video_bus_remove,
95 struct acpi_video_bus_flags {
96 u8 multihead:1; /* can switch video heads */
97 u8 rom:1; /* can retrieve a video rom */
98 u8 post:1; /* can configure the head to */
102 struct acpi_video_bus_cap {
103 u8 _DOS:1; /*Enable/Disable output switching */
104 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
105 u8 _ROM:1; /*Get ROM Data */
106 u8 _GPD:1; /*Get POST Device */
107 u8 _SPD:1; /*Set POST Device */
108 u8 _VPO:1; /*Video POST Options */
112 struct acpi_video_device_attrib {
113 u32 display_index:4; /* A zero-based instance of the Display */
114 u32 display_port_attachment:4; /*This field differentiates the display type */
115 u32 display_type:4; /*Describe the specific type in use */
116 u32 vendor_specific:4; /*Chipset Vendor Specific */
117 u32 bios_can_detect:1; /*BIOS can detect the device */
118 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
120 u32 pipe_id:3; /*For VGA multiple-head devices. */
121 u32 reserved:10; /*Must be 0 */
122 u32 device_id_scheme:1; /*Device ID Scheme */
125 struct acpi_video_enumerated_device {
128 struct acpi_video_device_attrib attrib;
130 struct acpi_video_device *bind_info;
133 struct acpi_video_bus {
134 struct acpi_device *device;
136 struct acpi_video_enumerated_device *attached_array;
138 struct acpi_video_bus_cap cap;
139 struct acpi_video_bus_flags flags;
140 struct list_head video_device_list;
141 struct mutex device_list_lock; /* protects video_device_list */
142 struct proc_dir_entry *dir;
143 struct input_dev *input;
144 char phys[32]; /* for input device */
147 struct acpi_video_device_flags {
157 struct acpi_video_device_cap {
158 u8 _ADR:1; /*Return the unique ID */
159 u8 _BCL:1; /*Query list of brightness control levels supported */
160 u8 _BCM:1; /*Set the brightness level */
161 u8 _BQC:1; /* Get current brightness level */
162 u8 _DDC:1; /*Return the EDID for this device */
163 u8 _DCS:1; /*Return status of output device */
164 u8 _DGS:1; /*Query graphics state */
165 u8 _DSS:1; /*Device state set */
168 struct acpi_video_device_brightness {
174 struct acpi_video_device {
175 unsigned long device_id;
176 struct acpi_video_device_flags flags;
177 struct acpi_video_device_cap cap;
178 struct list_head entry;
179 struct acpi_video_bus *video;
180 struct acpi_device *dev;
181 struct acpi_video_device_brightness *brightness;
182 struct backlight_device *backlight;
183 struct thermal_cooling_device *cdev;
184 struct output_device *output_dev;
188 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
189 static struct file_operations acpi_video_bus_info_fops = {
190 .open = acpi_video_bus_info_open_fs,
193 .release = single_release,
196 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
197 static struct file_operations acpi_video_bus_ROM_fops = {
198 .open = acpi_video_bus_ROM_open_fs,
201 .release = single_release,
204 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
206 static struct file_operations acpi_video_bus_POST_info_fops = {
207 .open = acpi_video_bus_POST_info_open_fs,
210 .release = single_release,
213 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
214 static struct file_operations acpi_video_bus_POST_fops = {
215 .open = acpi_video_bus_POST_open_fs,
218 .release = single_release,
221 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
222 static struct file_operations acpi_video_bus_DOS_fops = {
223 .open = acpi_video_bus_DOS_open_fs,
226 .release = single_release,
230 static int acpi_video_device_info_open_fs(struct inode *inode,
232 static struct file_operations acpi_video_device_info_fops = {
233 .open = acpi_video_device_info_open_fs,
236 .release = single_release,
239 static int acpi_video_device_state_open_fs(struct inode *inode,
241 static struct file_operations acpi_video_device_state_fops = {
242 .open = acpi_video_device_state_open_fs,
245 .release = single_release,
248 static int acpi_video_device_brightness_open_fs(struct inode *inode,
250 static struct file_operations acpi_video_device_brightness_fops = {
251 .open = acpi_video_device_brightness_open_fs,
254 .release = single_release,
257 static int acpi_video_device_EDID_open_fs(struct inode *inode,
259 static struct file_operations acpi_video_device_EDID_fops = {
260 .open = acpi_video_device_EDID_open_fs,
263 .release = single_release,
266 static char device_decode[][30] = {
267 "motherboard VGA device",
273 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
274 static void acpi_video_device_rebind(struct acpi_video_bus *video);
275 static void acpi_video_device_bind(struct acpi_video_bus *video,
276 struct acpi_video_device *device);
277 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
278 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
279 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
281 static int acpi_video_device_lcd_get_level_current(
282 struct acpi_video_device *device,
283 unsigned long *level);
284 static int acpi_video_get_next_level(struct acpi_video_device *device,
285 u32 level_current, u32 event);
286 static void acpi_video_switch_brightness(struct acpi_video_device *device,
288 static int acpi_video_device_get_state(struct acpi_video_device *device,
289 unsigned long *state);
290 static int acpi_video_output_get(struct output_device *od);
291 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
293 /*backlight device sysfs support*/
294 static int acpi_video_get_brightness(struct backlight_device *bd)
296 unsigned long cur_level;
297 struct acpi_video_device *vd =
298 (struct acpi_video_device *)bl_get_data(bd);
299 acpi_video_device_lcd_get_level_current(vd, &cur_level);
300 return (int) cur_level;
303 static int acpi_video_set_brightness(struct backlight_device *bd)
305 int request_level = bd->props.brightness;
306 struct acpi_video_device *vd =
307 (struct acpi_video_device *)bl_get_data(bd);
308 acpi_video_device_lcd_set_level(vd, request_level);
312 static struct backlight_ops acpi_backlight_ops = {
313 .get_brightness = acpi_video_get_brightness,
314 .update_status = acpi_video_set_brightness,
317 /*video output device sysfs support*/
318 static int acpi_video_output_get(struct output_device *od)
321 struct acpi_video_device *vd =
322 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
323 acpi_video_device_get_state(vd, &state);
327 static int acpi_video_output_set(struct output_device *od)
329 unsigned long state = od->request_state;
330 struct acpi_video_device *vd=
331 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
332 return acpi_video_device_set_state(vd, state);
335 static struct output_properties acpi_output_properties = {
336 .set_state = acpi_video_output_set,
337 .get_status = acpi_video_output_get,
341 /* thermal cooling device callbacks */
342 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
344 struct acpi_device *device = cdev->devdata;
345 struct acpi_video_device *video = acpi_driver_data(device);
347 return sprintf(buf, "%d\n", video->brightness->count - 3);
350 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
352 struct acpi_device *device = cdev->devdata;
353 struct acpi_video_device *video = acpi_driver_data(device);
357 acpi_video_device_lcd_get_level_current(video, &level);
358 for (state = 2; state < video->brightness->count; state++)
359 if (level == video->brightness->levels[state])
360 return sprintf(buf, "%d\n",
361 video->brightness->count - state - 1);
367 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
369 struct acpi_device *device = cdev->devdata;
370 struct acpi_video_device *video = acpi_driver_data(device);
373 if ( state >= video->brightness->count - 2)
376 state = video->brightness->count - state;
377 level = video->brightness->levels[state -1];
378 return acpi_video_device_lcd_set_level(video, level);
381 static struct thermal_cooling_device_ops video_cooling_ops = {
382 .get_max_state = video_get_max_state,
383 .get_cur_state = video_get_cur_state,
384 .set_cur_state = video_set_cur_state,
387 /* --------------------------------------------------------------------------
389 -------------------------------------------------------------------------- */
394 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
398 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
404 acpi_video_device_get_state(struct acpi_video_device *device,
405 unsigned long *state)
409 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
415 acpi_video_device_set_state(struct acpi_video_device *device, int state)
418 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
419 struct acpi_object_list args = { 1, &arg0 };
423 arg0.integer.value = state;
424 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
430 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
431 union acpi_object **levels)
434 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
435 union acpi_object *obj;
440 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
441 if (!ACPI_SUCCESS(status))
443 obj = (union acpi_object *)buffer.pointer;
444 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
445 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
455 kfree(buffer.pointer);
461 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
464 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
465 struct acpi_object_list args = { 1, &arg0 };
468 arg0.integer.value = level;
470 if (device->cap._BCM)
471 status = acpi_evaluate_object(device->dev->handle, "_BCM",
473 device->brightness->curr = level;
478 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
479 unsigned long *level)
481 if (device->cap._BQC)
482 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
484 *level = device->brightness->curr;
489 acpi_video_device_EDID(struct acpi_video_device *device,
490 union acpi_object **edid, ssize_t length)
493 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
494 union acpi_object *obj;
495 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
496 struct acpi_object_list args = { 1, &arg0 };
504 arg0.integer.value = 1;
505 else if (length == 256)
506 arg0.integer.value = 2;
510 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
511 if (ACPI_FAILURE(status))
514 obj = buffer.pointer;
516 if (obj && obj->type == ACPI_TYPE_BUFFER)
519 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
530 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
534 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
535 struct acpi_object_list args = { 1, &arg0 };
538 arg0.integer.value = option;
540 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
541 if (ACPI_SUCCESS(status))
542 status = tmp ? (-EINVAL) : (AE_OK);
548 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
552 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
558 acpi_video_bus_POST_options(struct acpi_video_bus *video,
559 unsigned long *options)
563 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
571 * video : video bus device pointer
573 * 0. The system BIOS should NOT automatically switch(toggle)
574 * the active display output.
575 * 1. The system BIOS should automatically switch (toggle) the
576 * active display output. No switch event.
577 * 2. The _DGS value should be locked.
578 * 3. The system BIOS should not automatically switch (toggle) the
579 * active display output, but instead generate the display switch
582 * 0. The system BIOS should automatically control the brightness level
583 * of the LCD when the power changes from AC to DC
584 * 1. The system BIOS should NOT automatically control the brightness
585 * level of the LCD when the power changes from AC to DC.
591 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
593 acpi_integer status = 0;
594 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
595 struct acpi_object_list args = { 1, &arg0 };
598 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
602 arg0.integer.value = (lcd_flag << 2) | bios_flag;
603 video->dos_setting = arg0.integer.value;
604 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
612 * device : video output device (LCD, CRT, ..)
617 * Find out all required AML methods defined under the output
621 static void acpi_video_device_find_cap(struct acpi_video_device *device)
623 acpi_handle h_dummy1;
626 union acpi_object *obj = NULL;
627 struct acpi_video_device_brightness *br = NULL;
630 memset(&device->cap, 0, sizeof(device->cap));
632 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
633 device->cap._ADR = 1;
635 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
636 device->cap._BCL = 1;
638 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
639 device->cap._BCM = 1;
641 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
642 device->cap._BQC = 1;
643 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
644 device->cap._DDC = 1;
646 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
647 device->cap._DCS = 1;
649 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
650 device->cap._DGS = 1;
652 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
653 device->cap._DSS = 1;
656 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
658 if (obj->package.count >= 2) {
660 union acpi_object *o;
662 br = kzalloc(sizeof(*br), GFP_KERNEL);
664 printk(KERN_ERR "can't allocate memory\n");
666 br->levels = kmalloc(obj->package.count *
667 sizeof *(br->levels), GFP_KERNEL);
671 for (i = 0; i < obj->package.count; i++) {
672 o = (union acpi_object *)&obj->package.
674 if (o->type != ACPI_TYPE_INTEGER) {
675 printk(KERN_ERR PREFIX "Invalid data\n");
678 br->levels[count] = (u32) o->integer.value;
680 if (br->levels[count] > max_level)
681 max_level = br->levels[count];
690 device->brightness = br;
691 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
692 "found %d brightness levels\n",
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
704 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
707 static int count = 0;
709 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
713 sprintf(name, "acpi_video%d", count++);
714 acpi_video_device_lcd_get_level_current(device, &tmp);
715 device->backlight = backlight_device_register(name,
716 NULL, device, &acpi_backlight_ops);
717 device->backlight->props.max_brightness = max_level;
718 device->backlight->props.brightness = (int)tmp;
719 backlight_update_status(device->backlight);
722 device->cdev = thermal_cooling_device_register("LCD",
723 device->dev, &video_cooling_ops);
725 printk(KERN_INFO PREFIX
726 "%s is registered as cooling_device%d\n",
727 device->dev->dev.bus_id, device->cdev->id);
728 result = sysfs_create_link(&device->dev->dev.kobj,
729 &device->cdev->device.kobj,
732 printk(KERN_ERR PREFIX "Create sysfs link\n");
733 result = sysfs_create_link(&device->cdev->device.kobj,
734 &device->dev->dev.kobj,
737 printk(KERN_ERR PREFIX "Create sysfs link\n");
740 if (device->cap._DCS && device->cap._DSS){
741 static int count = 0;
743 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
746 sprintf(name, "acpi_video%d", count++);
747 device->output_dev = video_output_register(name,
748 NULL, device, &acpi_output_properties);
756 * device : video output device (VGA)
761 * Find out all required AML methods defined under the video bus device.
764 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
766 acpi_handle h_dummy1;
768 memset(&video->cap, 0, sizeof(video->cap));
769 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
772 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
775 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
778 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
781 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
784 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
790 * Check whether the video bus device has required AML method to
791 * support the desired features
794 static int acpi_video_bus_check(struct acpi_video_bus *video)
796 acpi_status status = -ENOENT;
802 /* Since there is no HID, CID and so on for VGA driver, we have
803 * to check well known required nodes.
806 /* Does this device support video switching? */
807 if (video->cap._DOS) {
808 video->flags.multihead = 1;
812 /* Does this device support retrieving a video ROM? */
813 if (video->cap._ROM) {
814 video->flags.rom = 1;
818 /* Does this device support configuring which video device to POST? */
819 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
820 video->flags.post = 1;
827 /* --------------------------------------------------------------------------
829 -------------------------------------------------------------------------- */
831 static struct proc_dir_entry *acpi_video_dir;
835 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
837 struct acpi_video_device *dev = seq->private;
843 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
844 seq_printf(seq, "type: ");
846 seq_printf(seq, "CRT\n");
847 else if (dev->flags.lcd)
848 seq_printf(seq, "LCD\n");
849 else if (dev->flags.tvout)
850 seq_printf(seq, "TVOUT\n");
851 else if (dev->flags.dvi)
852 seq_printf(seq, "DVI\n");
854 seq_printf(seq, "UNKNOWN\n");
856 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
863 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
865 return single_open(file, acpi_video_device_info_seq_show,
869 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
872 struct acpi_video_device *dev = seq->private;
879 status = acpi_video_device_get_state(dev, &state);
880 seq_printf(seq, "state: ");
881 if (ACPI_SUCCESS(status))
882 seq_printf(seq, "0x%02lx\n", state);
884 seq_printf(seq, "<not supported>\n");
886 status = acpi_video_device_query(dev, &state);
887 seq_printf(seq, "query: ");
888 if (ACPI_SUCCESS(status))
889 seq_printf(seq, "0x%02lx\n", state);
891 seq_printf(seq, "<not supported>\n");
898 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
900 return single_open(file, acpi_video_device_state_seq_show,
905 acpi_video_device_write_state(struct file *file,
906 const char __user * buffer,
907 size_t count, loff_t * data)
910 struct seq_file *m = file->private_data;
911 struct acpi_video_device *dev = m->private;
912 char str[12] = { 0 };
916 if (!dev || count + 1 > sizeof str)
919 if (copy_from_user(str, buffer, count))
923 state = simple_strtoul(str, NULL, 0);
924 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
926 status = acpi_video_device_set_state(dev, state);
935 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
937 struct acpi_video_device *dev = seq->private;
941 if (!dev || !dev->brightness) {
942 seq_printf(seq, "<not supported>\n");
946 seq_printf(seq, "levels: ");
947 for (i = 0; i < dev->brightness->count; i++)
948 seq_printf(seq, " %d", dev->brightness->levels[i]);
949 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
955 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
957 return single_open(file, acpi_video_device_brightness_seq_show,
962 acpi_video_device_write_brightness(struct file *file,
963 const char __user * buffer,
964 size_t count, loff_t * data)
966 struct seq_file *m = file->private_data;
967 struct acpi_video_device *dev = m->private;
969 unsigned int level = 0;
973 if (!dev || !dev->brightness || count + 1 > sizeof str)
976 if (copy_from_user(str, buffer, count))
980 level = simple_strtoul(str, NULL, 0);
985 /* validate through the list of available levels */
986 for (i = 0; i < dev->brightness->count; i++)
987 if (level == dev->brightness->levels[i]) {
989 (acpi_video_device_lcd_set_level(dev, level)))
990 dev->brightness->curr = level;
997 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
999 struct acpi_video_device *dev = seq->private;
1002 union acpi_object *edid = NULL;
1008 status = acpi_video_device_EDID(dev, &edid, 128);
1009 if (ACPI_FAILURE(status)) {
1010 status = acpi_video_device_EDID(dev, &edid, 256);
1013 if (ACPI_FAILURE(status)) {
1017 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1018 for (i = 0; i < edid->buffer.length; i++)
1019 seq_putc(seq, edid->buffer.pointer[i]);
1024 seq_printf(seq, "<not supported>\n");
1032 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1034 return single_open(file, acpi_video_device_EDID_seq_show,
1038 static int acpi_video_device_add_fs(struct acpi_device *device)
1040 struct proc_dir_entry *entry = NULL;
1041 struct acpi_video_device *vid_dev;
1047 vid_dev = acpi_driver_data(device);
1051 if (!acpi_device_dir(device)) {
1052 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1053 vid_dev->video->dir);
1054 if (!acpi_device_dir(device))
1056 acpi_device_dir(device)->owner = THIS_MODULE;
1060 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1064 entry->proc_fops = &acpi_video_device_info_fops;
1065 entry->data = acpi_driver_data(device);
1066 entry->owner = THIS_MODULE;
1071 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1072 acpi_device_dir(device));
1076 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1077 entry->proc_fops = &acpi_video_device_state_fops;
1078 entry->data = acpi_driver_data(device);
1079 entry->owner = THIS_MODULE;
1082 /* 'brightness' [R/W] */
1084 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1085 acpi_device_dir(device));
1089 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1090 entry->proc_fops = &acpi_video_device_brightness_fops;
1091 entry->data = acpi_driver_data(device);
1092 entry->owner = THIS_MODULE;
1096 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1100 entry->proc_fops = &acpi_video_device_EDID_fops;
1101 entry->data = acpi_driver_data(device);
1102 entry->owner = THIS_MODULE;
1108 static int acpi_video_device_remove_fs(struct acpi_device *device)
1110 struct acpi_video_device *vid_dev;
1112 vid_dev = acpi_driver_data(device);
1113 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1116 if (acpi_device_dir(device)) {
1117 remove_proc_entry("info", acpi_device_dir(device));
1118 remove_proc_entry("state", acpi_device_dir(device));
1119 remove_proc_entry("brightness", acpi_device_dir(device));
1120 remove_proc_entry("EDID", acpi_device_dir(device));
1121 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1122 acpi_device_dir(device) = NULL;
1129 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1131 struct acpi_video_bus *video = seq->private;
1137 seq_printf(seq, "Switching heads: %s\n",
1138 video->flags.multihead ? "yes" : "no");
1139 seq_printf(seq, "Video ROM: %s\n",
1140 video->flags.rom ? "yes" : "no");
1141 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1142 video->flags.post ? "yes" : "no");
1148 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1150 return single_open(file, acpi_video_bus_info_seq_show,
1154 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1156 struct acpi_video_bus *video = seq->private;
1162 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1163 seq_printf(seq, "<TODO>\n");
1169 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1171 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1174 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1176 struct acpi_video_bus *video = seq->private;
1177 unsigned long options;
1184 status = acpi_video_bus_POST_options(video, &options);
1185 if (ACPI_SUCCESS(status)) {
1186 if (!(options & 1)) {
1187 printk(KERN_WARNING PREFIX
1188 "The motherboard VGA device is not listed as a possible POST device.\n");
1189 printk(KERN_WARNING PREFIX
1190 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1192 printk("%lx\n", options);
1193 seq_printf(seq, "can POST: <integrated video>");
1195 seq_printf(seq, " <PCI video>");
1197 seq_printf(seq, " <AGP video>");
1198 seq_putc(seq, '\n');
1200 seq_printf(seq, "<not supported>\n");
1206 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1208 return single_open(file, acpi_video_bus_POST_info_seq_show,
1212 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1214 struct acpi_video_bus *video = seq->private;
1222 status = acpi_video_bus_get_POST(video, &id);
1223 if (!ACPI_SUCCESS(status)) {
1224 seq_printf(seq, "<not supported>\n");
1227 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1233 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1235 struct acpi_video_bus *video = seq->private;
1238 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1243 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1245 return single_open(file, acpi_video_bus_POST_seq_show,
1249 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1251 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1255 acpi_video_bus_write_POST(struct file *file,
1256 const char __user * buffer,
1257 size_t count, loff_t * data)
1260 struct seq_file *m = file->private_data;
1261 struct acpi_video_bus *video = m->private;
1262 char str[12] = { 0 };
1263 unsigned long opt, options;
1266 if (!video || count + 1 > sizeof str)
1269 status = acpi_video_bus_POST_options(video, &options);
1270 if (!ACPI_SUCCESS(status))
1273 if (copy_from_user(str, buffer, count))
1277 opt = strtoul(str, NULL, 0);
1281 /* just in case an OEM 'forgot' the motherboard... */
1284 if (options & (1ul << opt)) {
1285 status = acpi_video_bus_set_POST(video, opt);
1286 if (!ACPI_SUCCESS(status))
1295 acpi_video_bus_write_DOS(struct file *file,
1296 const char __user * buffer,
1297 size_t count, loff_t * data)
1300 struct seq_file *m = file->private_data;
1301 struct acpi_video_bus *video = m->private;
1302 char str[12] = { 0 };
1306 if (!video || count + 1 > sizeof str)
1309 if (copy_from_user(str, buffer, count))
1313 opt = strtoul(str, NULL, 0);
1317 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1319 if (!ACPI_SUCCESS(status))
1325 static int acpi_video_bus_add_fs(struct acpi_device *device)
1327 struct proc_dir_entry *entry = NULL;
1328 struct acpi_video_bus *video;
1331 video = acpi_driver_data(device);
1333 if (!acpi_device_dir(device)) {
1334 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1336 if (!acpi_device_dir(device))
1338 video->dir = acpi_device_dir(device);
1339 acpi_device_dir(device)->owner = THIS_MODULE;
1343 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1347 entry->proc_fops = &acpi_video_bus_info_fops;
1348 entry->data = acpi_driver_data(device);
1349 entry->owner = THIS_MODULE;
1353 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1357 entry->proc_fops = &acpi_video_bus_ROM_fops;
1358 entry->data = acpi_driver_data(device);
1359 entry->owner = THIS_MODULE;
1362 /* 'POST_info' [R] */
1364 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1368 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1369 entry->data = acpi_driver_data(device);
1370 entry->owner = THIS_MODULE;
1375 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1376 acpi_device_dir(device));
1380 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1381 entry->proc_fops = &acpi_video_bus_POST_fops;
1382 entry->data = acpi_driver_data(device);
1383 entry->owner = THIS_MODULE;
1388 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1389 acpi_device_dir(device));
1393 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1394 entry->proc_fops = &acpi_video_bus_DOS_fops;
1395 entry->data = acpi_driver_data(device);
1396 entry->owner = THIS_MODULE;
1402 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1404 struct acpi_video_bus *video;
1407 video = acpi_driver_data(device);
1409 if (acpi_device_dir(device)) {
1410 remove_proc_entry("info", acpi_device_dir(device));
1411 remove_proc_entry("ROM", acpi_device_dir(device));
1412 remove_proc_entry("POST_info", acpi_device_dir(device));
1413 remove_proc_entry("POST", acpi_device_dir(device));
1414 remove_proc_entry("DOS", acpi_device_dir(device));
1415 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1416 acpi_device_dir(device) = NULL;
1422 /* --------------------------------------------------------------------------
1424 -------------------------------------------------------------------------- */
1426 /* device interface */
1427 static struct acpi_video_device_attrib*
1428 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1432 for(count = 0; count < video->attached_count; count++)
1433 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1434 return &(video->attached_array[count].value.attrib);
1439 acpi_video_bus_get_one_device(struct acpi_device *device,
1440 struct acpi_video_bus *video)
1442 unsigned long device_id;
1444 struct acpi_video_device *data;
1445 struct acpi_video_device_attrib* attribute;
1447 if (!device || !video)
1451 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1452 if (ACPI_SUCCESS(status)) {
1454 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1458 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1459 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1460 acpi_driver_data(device) = data;
1462 data->device_id = device_id;
1463 data->video = video;
1466 attribute = acpi_video_get_device_attr(video, device_id);
1468 if((attribute != NULL) && attribute->device_id_scheme) {
1469 switch (attribute->display_type) {
1470 case ACPI_VIDEO_DISPLAY_CRT:
1471 data->flags.crt = 1;
1473 case ACPI_VIDEO_DISPLAY_TV:
1474 data->flags.tvout = 1;
1476 case ACPI_VIDEO_DISPLAY_DVI:
1477 data->flags.dvi = 1;
1479 case ACPI_VIDEO_DISPLAY_LCD:
1480 data->flags.lcd = 1;
1483 data->flags.unknown = 1;
1486 if(attribute->bios_can_detect)
1487 data->flags.bios = 1;
1489 data->flags.unknown = 1;
1491 acpi_video_device_bind(video, data);
1492 acpi_video_device_find_cap(data);
1494 status = acpi_install_notify_handler(device->handle,
1496 acpi_video_device_notify,
1498 if (ACPI_FAILURE(status)) {
1499 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1500 "Error installing notify handler\n"));
1501 if(data->brightness)
1502 kfree(data->brightness->levels);
1503 kfree(data->brightness);
1508 mutex_lock(&video->device_list_lock);
1509 list_add_tail(&data->entry, &video->video_device_list);
1510 mutex_unlock(&video->device_list_lock);
1512 acpi_video_device_add_fs(device);
1522 * video : video bus device
1527 * Enumerate the video device list of the video bus,
1528 * bind the ids with the corresponding video devices
1529 * under the video bus.
1532 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1534 struct acpi_video_device *dev;
1536 mutex_lock(&video->device_list_lock);
1538 list_for_each_entry(dev, &video->video_device_list, entry)
1539 acpi_video_device_bind(video, dev);
1541 mutex_unlock(&video->device_list_lock);
1546 * video : video bus device
1547 * device : video output device under the video
1553 * Bind the ids with the corresponding video devices
1554 * under the video bus.
1558 acpi_video_device_bind(struct acpi_video_bus *video,
1559 struct acpi_video_device *device)
1563 #define IDS_VAL(i) video->attached_array[i].value.int_val
1564 #define IDS_BIND(i) video->attached_array[i].bind_info
1566 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1567 i < video->attached_count; i++) {
1568 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1569 IDS_BIND(i) = device;
1570 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1579 * video : video bus device
1584 * Call _DOD to enumerate all devices attached to display adapter
1588 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1593 struct acpi_video_enumerated_device *active_device_list;
1594 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1595 union acpi_object *dod = NULL;
1596 union acpi_object *obj;
1598 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1599 if (!ACPI_SUCCESS(status)) {
1600 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1604 dod = buffer.pointer;
1605 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1606 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1611 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1612 dod->package.count));
1614 active_device_list = kmalloc((1 +
1615 dod->package.count) *
1617 acpi_video_enumerated_device),
1620 if (!active_device_list) {
1626 for (i = 0; i < dod->package.count; i++) {
1627 obj = &dod->package.elements[i];
1629 if (obj->type != ACPI_TYPE_INTEGER) {
1630 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1631 active_device_list[i].value.int_val =
1632 ACPI_VIDEO_HEAD_INVALID;
1634 active_device_list[i].value.int_val = obj->integer.value;
1635 active_device_list[i].bind_info = NULL;
1636 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1637 (int)obj->integer.value));
1640 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1642 kfree(video->attached_array);
1644 video->attached_array = active_device_list;
1645 video->attached_count = count;
1647 kfree(buffer.pointer);
1653 * video : video bus device
1654 * event : notify event
1659 * 1. Find out the current active output device.
1660 * 2. Identify the next output device to switch to.
1661 * 3. call _DSS to do actual switch.
1664 static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1666 struct list_head *node;
1667 struct acpi_video_device *dev = NULL;
1668 struct acpi_video_device *dev_next = NULL;
1669 struct acpi_video_device *dev_prev = NULL;
1670 unsigned long state;
1673 mutex_lock(&video->device_list_lock);
1675 list_for_each(node, &video->video_device_list) {
1676 dev = container_of(node, struct acpi_video_device, entry);
1677 status = acpi_video_device_get_state(dev, &state);
1679 dev_next = container_of(node->next,
1680 struct acpi_video_device, entry);
1681 dev_prev = container_of(node->prev,
1682 struct acpi_video_device, entry);
1687 dev_next = container_of(node->next, struct acpi_video_device, entry);
1688 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1691 mutex_unlock(&video->device_list_lock);
1694 case ACPI_VIDEO_NOTIFY_CYCLE:
1695 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1696 acpi_video_device_set_state(dev, 0);
1697 acpi_video_device_set_state(dev_next, 0x80000001);
1699 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1700 acpi_video_device_set_state(dev, 0);
1701 acpi_video_device_set_state(dev_prev, 0x80000001);
1710 acpi_video_get_next_level(struct acpi_video_device *device,
1711 u32 level_current, u32 event)
1713 int min, max, min_above, max_below, i, l, delta = 255;
1714 max = max_below = 0;
1715 min = min_above = 255;
1716 /* Find closest level to level_current */
1717 for (i = 0; i < device->brightness->count; i++) {
1718 l = device->brightness->levels[i];
1719 if (abs(l - level_current) < abs(delta)) {
1720 delta = l - level_current;
1725 /* Ajust level_current to closest available level */
1726 level_current += delta;
1727 for (i = 0; i < device->brightness->count; i++) {
1728 l = device->brightness->levels[i];
1733 if (l < min_above && l > level_current)
1735 if (l > max_below && l < level_current)
1740 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1741 return (level_current < max) ? min_above : min;
1742 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1743 return (level_current < max) ? min_above : max;
1744 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1745 return (level_current > min) ? max_below : min;
1746 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1747 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1750 return level_current;
1755 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1757 unsigned long level_current, level_next;
1758 acpi_video_device_lcd_get_level_current(device, &level_current);
1759 level_next = acpi_video_get_next_level(device, level_current, event);
1760 acpi_video_device_lcd_set_level(device, level_next);
1764 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1765 struct acpi_device *device)
1768 struct acpi_device *dev;
1770 acpi_video_device_enumerate(video);
1772 list_for_each_entry(dev, &device->children, node) {
1774 status = acpi_video_bus_get_one_device(dev, video);
1775 if (ACPI_FAILURE(status)) {
1776 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1783 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1786 struct acpi_video_bus *video;
1789 if (!device || !device->video)
1792 video = device->video;
1794 acpi_video_device_remove_fs(device->dev);
1796 status = acpi_remove_notify_handler(device->dev->handle,
1798 acpi_video_device_notify);
1799 backlight_device_unregister(device->backlight);
1801 sysfs_remove_link(&device->dev->dev.kobj,
1803 sysfs_remove_link(&device->cdev->device.kobj,
1805 thermal_cooling_device_unregister(device->cdev);
1806 device->cdev = NULL;
1808 video_output_unregister(device->output_dev);
1813 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1816 struct acpi_video_device *dev, *next;
1818 mutex_lock(&video->device_list_lock);
1820 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1822 status = acpi_video_bus_put_one_device(dev);
1823 if (ACPI_FAILURE(status))
1824 printk(KERN_WARNING PREFIX
1825 "hhuuhhuu bug in acpi video driver.\n");
1827 if (dev->brightness) {
1828 kfree(dev->brightness->levels);
1829 kfree(dev->brightness);
1831 list_del(&dev->entry);
1835 mutex_unlock(&video->device_list_lock);
1840 /* acpi_video interface */
1842 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1844 return acpi_video_bus_DOS(video, 0, 0);
1847 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1849 return acpi_video_bus_DOS(video, 0, 1);
1852 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1854 struct acpi_video_bus *video = data;
1855 struct acpi_device *device = NULL;
1856 struct input_dev *input;
1862 device = video->device;
1863 input = video->input;
1866 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1867 * most likely via hotkey. */
1868 acpi_bus_generate_proc_event(device, event, 0);
1869 keycode = KEY_SWITCHVIDEOMODE;
1872 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1874 acpi_video_device_enumerate(video);
1875 acpi_video_device_rebind(video);
1876 acpi_video_switch_output(video, event);
1877 acpi_bus_generate_proc_event(device, event, 0);
1878 keycode = KEY_SWITCHVIDEOMODE;
1881 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1882 acpi_video_switch_output(video, event);
1883 acpi_bus_generate_proc_event(device, event, 0);
1884 keycode = KEY_SWITCHVIDEOMODE;
1886 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1887 acpi_video_switch_output(video, event);
1888 acpi_bus_generate_proc_event(device, event, 0);
1889 keycode = KEY_VIDEO_NEXT;
1891 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1892 acpi_video_switch_output(video, event);
1893 acpi_bus_generate_proc_event(device, event, 0);
1894 keycode = KEY_VIDEO_PREV;
1898 keycode = KEY_UNKNOWN;
1899 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1900 "Unsupported event [0x%x]\n", event));
1904 input_report_key(input, keycode, 1);
1906 input_report_key(input, keycode, 0);
1912 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1914 struct acpi_video_device *video_device = data;
1915 struct acpi_device *device = NULL;
1916 struct acpi_video_bus *bus;
1917 struct input_dev *input;
1923 device = video_device->dev;
1924 bus = video_device->video;
1928 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1929 acpi_video_switch_brightness(video_device, event);
1930 acpi_bus_generate_proc_event(device, event, 0);
1931 keycode = KEY_BRIGHTNESS_CYCLE;
1933 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1934 acpi_video_switch_brightness(video_device, event);
1935 acpi_bus_generate_proc_event(device, event, 0);
1936 keycode = KEY_BRIGHTNESSUP;
1938 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1939 acpi_video_switch_brightness(video_device, event);
1940 acpi_bus_generate_proc_event(device, event, 0);
1941 keycode = KEY_BRIGHTNESSDOWN;
1943 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1944 acpi_video_switch_brightness(video_device, event);
1945 acpi_bus_generate_proc_event(device, event, 0);
1946 keycode = KEY_BRIGHTNESS_ZERO;
1948 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1949 acpi_video_switch_brightness(video_device, event);
1950 acpi_bus_generate_proc_event(device, event, 0);
1951 keycode = KEY_DISPLAY_OFF;
1954 keycode = KEY_UNKNOWN;
1955 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1956 "Unsupported event [0x%x]\n", event));
1960 input_report_key(input, keycode, 1);
1962 input_report_key(input, keycode, 0);
1968 static int instance;
1969 static int acpi_video_bus_add(struct acpi_device *device)
1972 struct acpi_video_bus *video;
1973 struct input_dev *input;
1976 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1980 /* a hack to fix the duplicate name "VID" problem on T61 */
1981 if (!strcmp(device->pnp.bus_id, "VID")) {
1983 device->pnp.bus_id[3] = '0' + instance;
1987 video->device = device;
1988 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1989 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1990 acpi_driver_data(device) = video;
1992 acpi_video_bus_find_cap(video);
1993 error = acpi_video_bus_check(video);
1995 goto err_free_video;
1997 error = acpi_video_bus_add_fs(device);
1999 goto err_free_video;
2001 mutex_init(&video->device_list_lock);
2002 INIT_LIST_HEAD(&video->video_device_list);
2004 acpi_video_bus_get_devices(video, device);
2005 acpi_video_bus_start_devices(video);
2007 status = acpi_install_notify_handler(device->handle,
2009 acpi_video_bus_notify, video);
2010 if (ACPI_FAILURE(status)) {
2011 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2012 "Error installing notify handler\n"));
2014 goto err_stop_video;
2017 video->input = input = input_allocate_device();
2020 goto err_uninstall_notify;
2023 snprintf(video->phys, sizeof(video->phys),
2024 "%s/video/input0", acpi_device_hid(video->device));
2026 input->name = acpi_device_name(video->device);
2027 input->phys = video->phys;
2028 input->id.bustype = BUS_HOST;
2029 input->id.product = 0x06;
2030 input->dev.parent = &device->dev;
2031 input->evbit[0] = BIT(EV_KEY);
2032 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2033 set_bit(KEY_VIDEO_NEXT, input->keybit);
2034 set_bit(KEY_VIDEO_PREV, input->keybit);
2035 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2036 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2037 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2038 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2039 set_bit(KEY_DISPLAY_OFF, input->keybit);
2040 set_bit(KEY_UNKNOWN, input->keybit);
2042 error = input_register_device(input);
2044 goto err_free_input_dev;
2046 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2047 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2048 video->flags.multihead ? "yes" : "no",
2049 video->flags.rom ? "yes" : "no",
2050 video->flags.post ? "yes" : "no");
2055 input_free_device(input);
2056 err_uninstall_notify:
2057 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2058 acpi_video_bus_notify);
2060 acpi_video_bus_stop_devices(video);
2061 acpi_video_bus_put_devices(video);
2062 kfree(video->attached_array);
2063 acpi_video_bus_remove_fs(device);
2066 acpi_driver_data(device) = NULL;
2071 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2073 acpi_status status = 0;
2074 struct acpi_video_bus *video = NULL;
2077 if (!device || !acpi_driver_data(device))
2080 video = acpi_driver_data(device);
2082 acpi_video_bus_stop_devices(video);
2084 status = acpi_remove_notify_handler(video->device->handle,
2086 acpi_video_bus_notify);
2088 acpi_video_bus_put_devices(video);
2089 acpi_video_bus_remove_fs(device);
2091 input_unregister_device(video->input);
2092 kfree(video->attached_array);
2098 static int __init acpi_video_init(void)
2104 acpi_dbg_level = 0xFFFFFFFF;
2105 acpi_dbg_layer = 0x08000000;
2108 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2109 if (!acpi_video_dir)
2111 acpi_video_dir->owner = THIS_MODULE;
2113 result = acpi_bus_register_driver(&acpi_video_bus);
2115 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2122 static void __exit acpi_video_exit(void)
2125 acpi_bus_unregister_driver(&acpi_video_bus);
2127 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2132 module_init(acpi_video_init);
2133 module_exit(acpi_video_exit);