2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/video_output.h>
38 #include <asm/uaccess.h>
40 #include <acpi/acpi_bus.h>
41 #include <acpi/acpi_drivers.h>
43 #define ACPI_VIDEO_COMPONENT 0x08000000
44 #define ACPI_VIDEO_CLASS "video"
45 #define ACPI_VIDEO_BUS_NAME "Video Bus"
46 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
47 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
49 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
59 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60 #define ACPI_VIDEO_HEAD_END (~0u)
61 #define MAX_NAME_LEN 20
63 #define ACPI_VIDEO_DISPLAY_CRT 1
64 #define ACPI_VIDEO_DISPLAY_TV 2
65 #define ACPI_VIDEO_DISPLAY_DVI 3
66 #define ACPI_VIDEO_DISPLAY_LCD 4
68 #define _COMPONENT ACPI_VIDEO_COMPONENT
69 ACPI_MODULE_NAME("video");
71 MODULE_AUTHOR("Bruno Ducrot");
72 MODULE_DESCRIPTION("ACPI Video Driver");
73 MODULE_LICENSE("GPL");
75 static int brightness_switch_enabled = 1;
76 module_param(brightness_switch_enabled, bool, 0644);
78 static int acpi_video_bus_add(struct acpi_device *device);
79 static int acpi_video_bus_remove(struct acpi_device *device, int type);
81 static const struct acpi_device_id video_device_ids[] = {
85 MODULE_DEVICE_TABLE(acpi, video_device_ids);
87 static struct acpi_driver acpi_video_bus = {
89 .class = ACPI_VIDEO_CLASS,
90 .ids = video_device_ids,
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
97 struct acpi_video_bus_flags {
98 u8 multihead:1; /* can switch video heads */
99 u8 rom:1; /* can retrieve a video rom */
100 u8 post:1; /* can configure the head to */
104 struct acpi_video_bus_cap {
105 u8 _DOS:1; /*Enable/Disable output switching */
106 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
107 u8 _ROM:1; /*Get ROM Data */
108 u8 _GPD:1; /*Get POST Device */
109 u8 _SPD:1; /*Set POST Device */
110 u8 _VPO:1; /*Video POST Options */
114 struct acpi_video_device_attrib {
115 u32 display_index:4; /* A zero-based instance of the Display */
116 u32 display_port_attachment:4; /*This field differentiates the display type */
117 u32 display_type:4; /*Describe the specific type in use */
118 u32 vendor_specific:4; /*Chipset Vendor Specific */
119 u32 bios_can_detect:1; /*BIOS can detect the device */
120 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
122 u32 pipe_id:3; /*For VGA multiple-head devices. */
123 u32 reserved:10; /*Must be 0 */
124 u32 device_id_scheme:1; /*Device ID Scheme */
127 struct acpi_video_enumerated_device {
130 struct acpi_video_device_attrib attrib;
132 struct acpi_video_device *bind_info;
135 struct acpi_video_bus {
136 struct acpi_device *device;
138 struct acpi_video_enumerated_device *attached_array;
140 struct acpi_video_bus_cap cap;
141 struct acpi_video_bus_flags flags;
142 struct list_head video_device_list;
143 struct mutex device_list_lock; /* protects video_device_list */
144 struct proc_dir_entry *dir;
145 struct input_dev *input;
146 char phys[32]; /* for input device */
149 struct acpi_video_device_flags {
159 struct acpi_video_device_cap {
160 u8 _ADR:1; /*Return the unique ID */
161 u8 _BCL:1; /*Query list of brightness control levels supported */
162 u8 _BCM:1; /*Set the brightness level */
163 u8 _BQC:1; /* Get current brightness level */
164 u8 _DDC:1; /*Return the EDID for this device */
165 u8 _DCS:1; /*Return status of output device */
166 u8 _DGS:1; /*Query graphics state */
167 u8 _DSS:1; /*Device state set */
170 struct acpi_video_device_brightness {
176 struct acpi_video_device {
177 unsigned long device_id;
178 struct acpi_video_device_flags flags;
179 struct acpi_video_device_cap cap;
180 struct list_head entry;
181 struct acpi_video_bus *video;
182 struct acpi_device *dev;
183 struct acpi_video_device_brightness *brightness;
184 struct backlight_device *backlight;
185 struct output_device *output_dev;
189 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
190 static struct file_operations acpi_video_bus_info_fops = {
191 .open = acpi_video_bus_info_open_fs,
194 .release = single_release,
197 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
198 static struct file_operations acpi_video_bus_ROM_fops = {
199 .open = acpi_video_bus_ROM_open_fs,
202 .release = single_release,
205 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
207 static struct file_operations acpi_video_bus_POST_info_fops = {
208 .open = acpi_video_bus_POST_info_open_fs,
211 .release = single_release,
214 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
215 static struct file_operations acpi_video_bus_POST_fops = {
216 .open = acpi_video_bus_POST_open_fs,
219 .release = single_release,
222 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
223 static struct file_operations acpi_video_bus_DOS_fops = {
224 .open = acpi_video_bus_DOS_open_fs,
227 .release = single_release,
231 static int acpi_video_device_info_open_fs(struct inode *inode,
233 static struct file_operations acpi_video_device_info_fops = {
234 .open = acpi_video_device_info_open_fs,
237 .release = single_release,
240 static int acpi_video_device_state_open_fs(struct inode *inode,
242 static struct file_operations acpi_video_device_state_fops = {
243 .open = acpi_video_device_state_open_fs,
246 .release = single_release,
249 static int acpi_video_device_brightness_open_fs(struct inode *inode,
251 static struct file_operations acpi_video_device_brightness_fops = {
252 .open = acpi_video_device_brightness_open_fs,
255 .release = single_release,
258 static int acpi_video_device_EDID_open_fs(struct inode *inode,
260 static struct file_operations acpi_video_device_EDID_fops = {
261 .open = acpi_video_device_EDID_open_fs,
264 .release = single_release,
267 static char device_decode[][30] = {
268 "motherboard VGA device",
274 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
275 static void acpi_video_device_rebind(struct acpi_video_bus *video);
276 static void acpi_video_device_bind(struct acpi_video_bus *video,
277 struct acpi_video_device *device);
278 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
279 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
280 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
282 static int acpi_video_device_lcd_get_level_current(
283 struct acpi_video_device *device,
284 unsigned long *level);
285 static int acpi_video_get_next_level(struct acpi_video_device *device,
286 u32 level_current, u32 event);
287 static void acpi_video_switch_brightness(struct acpi_video_device *device,
289 static int acpi_video_device_get_state(struct acpi_video_device *device,
290 unsigned long *state);
291 static int acpi_video_output_get(struct output_device *od);
292 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
294 /*backlight device sysfs support*/
295 static int acpi_video_get_brightness(struct backlight_device *bd)
297 unsigned long cur_level;
298 struct acpi_video_device *vd =
299 (struct acpi_video_device *)bl_get_data(bd);
300 acpi_video_device_lcd_get_level_current(vd, &cur_level);
301 return (int) cur_level;
304 static int acpi_video_set_brightness(struct backlight_device *bd)
306 int request_level = bd->props.brightness;
307 struct acpi_video_device *vd =
308 (struct acpi_video_device *)bl_get_data(bd);
309 acpi_video_device_lcd_set_level(vd, request_level);
313 static struct backlight_ops acpi_backlight_ops = {
314 .get_brightness = acpi_video_get_brightness,
315 .update_status = acpi_video_set_brightness,
318 /*video output device sysfs support*/
319 static int acpi_video_output_get(struct output_device *od)
322 struct acpi_video_device *vd =
323 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
324 acpi_video_device_get_state(vd, &state);
328 static int acpi_video_output_set(struct output_device *od)
330 unsigned long state = od->request_state;
331 struct acpi_video_device *vd=
332 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
333 return acpi_video_device_set_state(vd, state);
336 static struct output_properties acpi_output_properties = {
337 .set_state = acpi_video_output_set,
338 .get_status = acpi_video_output_get,
340 /* --------------------------------------------------------------------------
342 -------------------------------------------------------------------------- */
347 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
351 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
357 acpi_video_device_get_state(struct acpi_video_device *device,
358 unsigned long *state)
362 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
368 acpi_video_device_set_state(struct acpi_video_device *device, int state)
371 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
372 struct acpi_object_list args = { 1, &arg0 };
376 arg0.integer.value = state;
377 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
383 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
384 union acpi_object **levels)
387 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
388 union acpi_object *obj;
393 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
394 if (!ACPI_SUCCESS(status))
396 obj = (union acpi_object *)buffer.pointer;
397 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
398 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
408 kfree(buffer.pointer);
414 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
417 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
418 struct acpi_object_list args = { 1, &arg0 };
421 arg0.integer.value = level;
423 if (device->cap._BCM)
424 status = acpi_evaluate_object(device->dev->handle, "_BCM",
426 device->brightness->curr = level;
431 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
432 unsigned long *level)
434 if (device->cap._BQC)
435 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
437 *level = device->brightness->curr;
442 acpi_video_device_EDID(struct acpi_video_device *device,
443 union acpi_object **edid, ssize_t length)
446 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
447 union acpi_object *obj;
448 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
449 struct acpi_object_list args = { 1, &arg0 };
457 arg0.integer.value = 1;
458 else if (length == 256)
459 arg0.integer.value = 2;
463 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
464 if (ACPI_FAILURE(status))
467 obj = buffer.pointer;
469 if (obj && obj->type == ACPI_TYPE_BUFFER)
472 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
483 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
487 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
488 struct acpi_object_list args = { 1, &arg0 };
491 arg0.integer.value = option;
493 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
494 if (ACPI_SUCCESS(status))
495 status = tmp ? (-EINVAL) : (AE_OK);
501 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
505 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
511 acpi_video_bus_POST_options(struct acpi_video_bus *video,
512 unsigned long *options)
516 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
524 * video : video bus device pointer
526 * 0. The system BIOS should NOT automatically switch(toggle)
527 * the active display output.
528 * 1. The system BIOS should automatically switch (toggle) the
529 * active display output. No switch event.
530 * 2. The _DGS value should be locked.
531 * 3. The system BIOS should not automatically switch (toggle) the
532 * active display output, but instead generate the display switch
535 * 0. The system BIOS should automatically control the brightness level
536 * of the LCD when the power changes from AC to DC
537 * 1. The system BIOS should NOT automatically control the brightness
538 * level of the LCD when the power changes from AC to DC.
544 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
546 acpi_integer status = 0;
547 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
548 struct acpi_object_list args = { 1, &arg0 };
551 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
555 arg0.integer.value = (lcd_flag << 2) | bios_flag;
556 video->dos_setting = arg0.integer.value;
557 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
565 * device : video output device (LCD, CRT, ..)
570 * Find out all required AML methods defined under the output
574 static void acpi_video_device_find_cap(struct acpi_video_device *device)
576 acpi_handle h_dummy1;
579 union acpi_object *obj = NULL;
580 struct acpi_video_device_brightness *br = NULL;
583 memset(&device->cap, 0, sizeof(device->cap));
585 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
586 device->cap._ADR = 1;
588 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
589 device->cap._BCL = 1;
591 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
592 device->cap._BCM = 1;
594 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
595 device->cap._BQC = 1;
596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
597 device->cap._DDC = 1;
599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
600 device->cap._DCS = 1;
602 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
603 device->cap._DGS = 1;
605 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
606 device->cap._DSS = 1;
609 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
611 if (obj->package.count >= 2) {
613 union acpi_object *o;
615 br = kzalloc(sizeof(*br), GFP_KERNEL);
617 printk(KERN_ERR "can't allocate memory\n");
619 br->levels = kmalloc(obj->package.count *
620 sizeof *(br->levels), GFP_KERNEL);
624 for (i = 0; i < obj->package.count; i++) {
625 o = (union acpi_object *)&obj->package.
627 if (o->type != ACPI_TYPE_INTEGER) {
628 printk(KERN_ERR PREFIX "Invalid data\n");
631 br->levels[count] = (u32) o->integer.value;
633 if (br->levels[count] > max_level)
634 max_level = br->levels[count];
643 device->brightness = br;
644 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
645 "found %d brightness levels\n",
652 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
657 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
659 static int count = 0;
661 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
665 sprintf(name, "acpi_video%d", count++);
666 acpi_video_device_lcd_get_level_current(device, &tmp);
667 device->backlight = backlight_device_register(name,
668 NULL, device, &acpi_backlight_ops);
669 device->backlight->props.max_brightness = max_level;
670 device->backlight->props.brightness = (int)tmp;
671 backlight_update_status(device->backlight);
675 if (device->cap._DCS && device->cap._DSS){
676 static int count = 0;
678 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
681 sprintf(name, "acpi_video%d", count++);
682 device->output_dev = video_output_register(name,
683 NULL, device, &acpi_output_properties);
691 * device : video output device (VGA)
696 * Find out all required AML methods defined under the video bus device.
699 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
701 acpi_handle h_dummy1;
703 memset(&video->cap, 0, sizeof(video->cap));
704 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
716 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
719 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
725 * Check whether the video bus device has required AML method to
726 * support the desired features
729 static int acpi_video_bus_check(struct acpi_video_bus *video)
731 acpi_status status = -ENOENT;
737 /* Since there is no HID, CID and so on for VGA driver, we have
738 * to check well known required nodes.
741 /* Does this device support video switching? */
742 if (video->cap._DOS) {
743 video->flags.multihead = 1;
747 /* Does this device support retrieving a video ROM? */
748 if (video->cap._ROM) {
749 video->flags.rom = 1;
753 /* Does this device support configuring which video device to POST? */
754 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
755 video->flags.post = 1;
762 /* --------------------------------------------------------------------------
764 -------------------------------------------------------------------------- */
766 static struct proc_dir_entry *acpi_video_dir;
770 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
772 struct acpi_video_device *dev = seq->private;
778 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
779 seq_printf(seq, "type: ");
781 seq_printf(seq, "CRT\n");
782 else if (dev->flags.lcd)
783 seq_printf(seq, "LCD\n");
784 else if (dev->flags.tvout)
785 seq_printf(seq, "TVOUT\n");
786 else if (dev->flags.dvi)
787 seq_printf(seq, "DVI\n");
789 seq_printf(seq, "UNKNOWN\n");
791 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
798 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
800 return single_open(file, acpi_video_device_info_seq_show,
804 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
807 struct acpi_video_device *dev = seq->private;
814 status = acpi_video_device_get_state(dev, &state);
815 seq_printf(seq, "state: ");
816 if (ACPI_SUCCESS(status))
817 seq_printf(seq, "0x%02lx\n", state);
819 seq_printf(seq, "<not supported>\n");
821 status = acpi_video_device_query(dev, &state);
822 seq_printf(seq, "query: ");
823 if (ACPI_SUCCESS(status))
824 seq_printf(seq, "0x%02lx\n", state);
826 seq_printf(seq, "<not supported>\n");
833 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
835 return single_open(file, acpi_video_device_state_seq_show,
840 acpi_video_device_write_state(struct file *file,
841 const char __user * buffer,
842 size_t count, loff_t * data)
845 struct seq_file *m = file->private_data;
846 struct acpi_video_device *dev = m->private;
847 char str[12] = { 0 };
851 if (!dev || count + 1 > sizeof str)
854 if (copy_from_user(str, buffer, count))
858 state = simple_strtoul(str, NULL, 0);
859 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
861 status = acpi_video_device_set_state(dev, state);
870 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
872 struct acpi_video_device *dev = seq->private;
876 if (!dev || !dev->brightness) {
877 seq_printf(seq, "<not supported>\n");
881 seq_printf(seq, "levels: ");
882 for (i = 0; i < dev->brightness->count; i++)
883 seq_printf(seq, " %d", dev->brightness->levels[i]);
884 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
890 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
892 return single_open(file, acpi_video_device_brightness_seq_show,
897 acpi_video_device_write_brightness(struct file *file,
898 const char __user * buffer,
899 size_t count, loff_t * data)
901 struct seq_file *m = file->private_data;
902 struct acpi_video_device *dev = m->private;
904 unsigned int level = 0;
908 if (!dev || !dev->brightness || count + 1 > sizeof str)
911 if (copy_from_user(str, buffer, count))
915 level = simple_strtoul(str, NULL, 0);
920 /* validate through the list of available levels */
921 for (i = 0; i < dev->brightness->count; i++)
922 if (level == dev->brightness->levels[i]) {
924 (acpi_video_device_lcd_set_level(dev, level)))
925 dev->brightness->curr = level;
932 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
934 struct acpi_video_device *dev = seq->private;
937 union acpi_object *edid = NULL;
943 status = acpi_video_device_EDID(dev, &edid, 128);
944 if (ACPI_FAILURE(status)) {
945 status = acpi_video_device_EDID(dev, &edid, 256);
948 if (ACPI_FAILURE(status)) {
952 if (edid && edid->type == ACPI_TYPE_BUFFER) {
953 for (i = 0; i < edid->buffer.length; i++)
954 seq_putc(seq, edid->buffer.pointer[i]);
959 seq_printf(seq, "<not supported>\n");
967 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
969 return single_open(file, acpi_video_device_EDID_seq_show,
973 static int acpi_video_device_add_fs(struct acpi_device *device)
975 struct proc_dir_entry *entry = NULL;
976 struct acpi_video_device *vid_dev;
982 vid_dev = acpi_driver_data(device);
986 if (!acpi_device_dir(device)) {
987 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
988 vid_dev->video->dir);
989 if (!acpi_device_dir(device))
991 acpi_device_dir(device)->owner = THIS_MODULE;
995 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
999 entry->proc_fops = &acpi_video_device_info_fops;
1000 entry->data = acpi_driver_data(device);
1001 entry->owner = THIS_MODULE;
1006 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1007 acpi_device_dir(device));
1011 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1012 entry->proc_fops = &acpi_video_device_state_fops;
1013 entry->data = acpi_driver_data(device);
1014 entry->owner = THIS_MODULE;
1017 /* 'brightness' [R/W] */
1019 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1020 acpi_device_dir(device));
1024 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1025 entry->proc_fops = &acpi_video_device_brightness_fops;
1026 entry->data = acpi_driver_data(device);
1027 entry->owner = THIS_MODULE;
1031 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1035 entry->proc_fops = &acpi_video_device_EDID_fops;
1036 entry->data = acpi_driver_data(device);
1037 entry->owner = THIS_MODULE;
1043 static int acpi_video_device_remove_fs(struct acpi_device *device)
1045 struct acpi_video_device *vid_dev;
1047 vid_dev = acpi_driver_data(device);
1048 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1051 if (acpi_device_dir(device)) {
1052 remove_proc_entry("info", acpi_device_dir(device));
1053 remove_proc_entry("state", acpi_device_dir(device));
1054 remove_proc_entry("brightness", acpi_device_dir(device));
1055 remove_proc_entry("EDID", acpi_device_dir(device));
1056 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1057 acpi_device_dir(device) = NULL;
1064 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1066 struct acpi_video_bus *video = seq->private;
1072 seq_printf(seq, "Switching heads: %s\n",
1073 video->flags.multihead ? "yes" : "no");
1074 seq_printf(seq, "Video ROM: %s\n",
1075 video->flags.rom ? "yes" : "no");
1076 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1077 video->flags.post ? "yes" : "no");
1083 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1085 return single_open(file, acpi_video_bus_info_seq_show,
1089 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1091 struct acpi_video_bus *video = seq->private;
1097 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1098 seq_printf(seq, "<TODO>\n");
1104 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1106 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1109 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1111 struct acpi_video_bus *video = seq->private;
1112 unsigned long options;
1119 status = acpi_video_bus_POST_options(video, &options);
1120 if (ACPI_SUCCESS(status)) {
1121 if (!(options & 1)) {
1122 printk(KERN_WARNING PREFIX
1123 "The motherboard VGA device is not listed as a possible POST device.\n");
1124 printk(KERN_WARNING PREFIX
1125 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1127 printk("%lx\n", options);
1128 seq_printf(seq, "can POST: <integrated video>");
1130 seq_printf(seq, " <PCI video>");
1132 seq_printf(seq, " <AGP video>");
1133 seq_putc(seq, '\n');
1135 seq_printf(seq, "<not supported>\n");
1141 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1143 return single_open(file, acpi_video_bus_POST_info_seq_show,
1147 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1149 struct acpi_video_bus *video = seq->private;
1157 status = acpi_video_bus_get_POST(video, &id);
1158 if (!ACPI_SUCCESS(status)) {
1159 seq_printf(seq, "<not supported>\n");
1162 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1168 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1170 struct acpi_video_bus *video = seq->private;
1173 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1178 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1180 return single_open(file, acpi_video_bus_POST_seq_show,
1184 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1186 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1190 acpi_video_bus_write_POST(struct file *file,
1191 const char __user * buffer,
1192 size_t count, loff_t * data)
1195 struct seq_file *m = file->private_data;
1196 struct acpi_video_bus *video = m->private;
1197 char str[12] = { 0 };
1198 unsigned long opt, options;
1201 if (!video || count + 1 > sizeof str)
1204 status = acpi_video_bus_POST_options(video, &options);
1205 if (!ACPI_SUCCESS(status))
1208 if (copy_from_user(str, buffer, count))
1212 opt = strtoul(str, NULL, 0);
1216 /* just in case an OEM 'forgot' the motherboard... */
1219 if (options & (1ul << opt)) {
1220 status = acpi_video_bus_set_POST(video, opt);
1221 if (!ACPI_SUCCESS(status))
1230 acpi_video_bus_write_DOS(struct file *file,
1231 const char __user * buffer,
1232 size_t count, loff_t * data)
1235 struct seq_file *m = file->private_data;
1236 struct acpi_video_bus *video = m->private;
1237 char str[12] = { 0 };
1241 if (!video || count + 1 > sizeof str)
1244 if (copy_from_user(str, buffer, count))
1248 opt = strtoul(str, NULL, 0);
1252 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1254 if (!ACPI_SUCCESS(status))
1260 static int acpi_video_bus_add_fs(struct acpi_device *device)
1262 struct proc_dir_entry *entry = NULL;
1263 struct acpi_video_bus *video;
1266 video = acpi_driver_data(device);
1268 if (!acpi_device_dir(device)) {
1269 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1271 if (!acpi_device_dir(device))
1273 video->dir = acpi_device_dir(device);
1274 acpi_device_dir(device)->owner = THIS_MODULE;
1278 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1282 entry->proc_fops = &acpi_video_bus_info_fops;
1283 entry->data = acpi_driver_data(device);
1284 entry->owner = THIS_MODULE;
1288 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1292 entry->proc_fops = &acpi_video_bus_ROM_fops;
1293 entry->data = acpi_driver_data(device);
1294 entry->owner = THIS_MODULE;
1297 /* 'POST_info' [R] */
1299 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1303 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1304 entry->data = acpi_driver_data(device);
1305 entry->owner = THIS_MODULE;
1310 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1311 acpi_device_dir(device));
1315 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1316 entry->proc_fops = &acpi_video_bus_POST_fops;
1317 entry->data = acpi_driver_data(device);
1318 entry->owner = THIS_MODULE;
1323 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1324 acpi_device_dir(device));
1328 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1329 entry->proc_fops = &acpi_video_bus_DOS_fops;
1330 entry->data = acpi_driver_data(device);
1331 entry->owner = THIS_MODULE;
1337 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1339 struct acpi_video_bus *video;
1342 video = acpi_driver_data(device);
1344 if (acpi_device_dir(device)) {
1345 remove_proc_entry("info", acpi_device_dir(device));
1346 remove_proc_entry("ROM", acpi_device_dir(device));
1347 remove_proc_entry("POST_info", acpi_device_dir(device));
1348 remove_proc_entry("POST", acpi_device_dir(device));
1349 remove_proc_entry("DOS", acpi_device_dir(device));
1350 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1351 acpi_device_dir(device) = NULL;
1357 /* --------------------------------------------------------------------------
1359 -------------------------------------------------------------------------- */
1361 /* device interface */
1362 static struct acpi_video_device_attrib*
1363 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1367 for(count = 0; count < video->attached_count; count++)
1368 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1369 return &(video->attached_array[count].value.attrib);
1374 acpi_video_bus_get_one_device(struct acpi_device *device,
1375 struct acpi_video_bus *video)
1377 unsigned long device_id;
1379 struct acpi_video_device *data;
1380 struct acpi_video_device_attrib* attribute;
1382 if (!device || !video)
1386 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1387 if (ACPI_SUCCESS(status)) {
1389 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1393 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1394 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1395 acpi_driver_data(device) = data;
1397 data->device_id = device_id;
1398 data->video = video;
1401 attribute = acpi_video_get_device_attr(video, device_id);
1403 if((attribute != NULL) && attribute->device_id_scheme) {
1404 switch (attribute->display_type) {
1405 case ACPI_VIDEO_DISPLAY_CRT:
1406 data->flags.crt = 1;
1408 case ACPI_VIDEO_DISPLAY_TV:
1409 data->flags.tvout = 1;
1411 case ACPI_VIDEO_DISPLAY_DVI:
1412 data->flags.dvi = 1;
1414 case ACPI_VIDEO_DISPLAY_LCD:
1415 data->flags.lcd = 1;
1418 data->flags.unknown = 1;
1421 if(attribute->bios_can_detect)
1422 data->flags.bios = 1;
1424 data->flags.unknown = 1;
1426 acpi_video_device_bind(video, data);
1427 acpi_video_device_find_cap(data);
1429 status = acpi_install_notify_handler(device->handle,
1431 acpi_video_device_notify,
1433 if (ACPI_FAILURE(status)) {
1434 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1435 "Error installing notify handler\n"));
1436 if(data->brightness)
1437 kfree(data->brightness->levels);
1438 kfree(data->brightness);
1443 mutex_lock(&video->device_list_lock);
1444 list_add_tail(&data->entry, &video->video_device_list);
1445 mutex_unlock(&video->device_list_lock);
1447 acpi_video_device_add_fs(device);
1457 * video : video bus device
1462 * Enumerate the video device list of the video bus,
1463 * bind the ids with the corresponding video devices
1464 * under the video bus.
1467 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1469 struct acpi_video_device *dev;
1471 mutex_lock(&video->device_list_lock);
1473 list_for_each_entry(dev, &video->video_device_list, entry)
1474 acpi_video_device_bind(video, dev);
1476 mutex_unlock(&video->device_list_lock);
1481 * video : video bus device
1482 * device : video output device under the video
1488 * Bind the ids with the corresponding video devices
1489 * under the video bus.
1493 acpi_video_device_bind(struct acpi_video_bus *video,
1494 struct acpi_video_device *device)
1498 #define IDS_VAL(i) video->attached_array[i].value.int_val
1499 #define IDS_BIND(i) video->attached_array[i].bind_info
1501 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1502 i < video->attached_count; i++) {
1503 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1504 IDS_BIND(i) = device;
1505 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1514 * video : video bus device
1519 * Call _DOD to enumerate all devices attached to display adapter
1523 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1528 struct acpi_video_enumerated_device *active_device_list;
1529 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1530 union acpi_object *dod = NULL;
1531 union acpi_object *obj;
1533 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1534 if (!ACPI_SUCCESS(status)) {
1535 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1539 dod = buffer.pointer;
1540 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1541 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1546 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1547 dod->package.count));
1549 active_device_list = kmalloc((1 +
1550 dod->package.count) *
1552 acpi_video_enumerated_device),
1555 if (!active_device_list) {
1561 for (i = 0; i < dod->package.count; i++) {
1562 obj = &dod->package.elements[i];
1564 if (obj->type != ACPI_TYPE_INTEGER) {
1565 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1566 active_device_list[i].value.int_val =
1567 ACPI_VIDEO_HEAD_INVALID;
1569 active_device_list[i].value.int_val = obj->integer.value;
1570 active_device_list[i].bind_info = NULL;
1571 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1572 (int)obj->integer.value));
1575 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1577 kfree(video->attached_array);
1579 video->attached_array = active_device_list;
1580 video->attached_count = count;
1582 kfree(buffer.pointer);
1588 * video : video bus device
1589 * event : notify event
1594 * 1. Find out the current active output device.
1595 * 2. Identify the next output device to switch to.
1596 * 3. call _DSS to do actual switch.
1599 static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1601 struct list_head *node;
1602 struct acpi_video_device *dev = NULL;
1603 struct acpi_video_device *dev_next = NULL;
1604 struct acpi_video_device *dev_prev = NULL;
1605 unsigned long state;
1608 mutex_lock(&video->device_list_lock);
1610 list_for_each(node, &video->video_device_list) {
1611 dev = container_of(node, struct acpi_video_device, entry);
1612 status = acpi_video_device_get_state(dev, &state);
1614 dev_next = container_of(node->next,
1615 struct acpi_video_device, entry);
1616 dev_prev = container_of(node->prev,
1617 struct acpi_video_device, entry);
1622 dev_next = container_of(node->next, struct acpi_video_device, entry);
1623 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1626 mutex_unlock(&video->device_list_lock);
1629 case ACPI_VIDEO_NOTIFY_CYCLE:
1630 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1631 acpi_video_device_set_state(dev, 0);
1632 acpi_video_device_set_state(dev_next, 0x80000001);
1634 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1635 acpi_video_device_set_state(dev, 0);
1636 acpi_video_device_set_state(dev_prev, 0x80000001);
1645 acpi_video_get_next_level(struct acpi_video_device *device,
1646 u32 level_current, u32 event)
1648 int min, max, min_above, max_below, i, l, delta = 255;
1649 max = max_below = 0;
1650 min = min_above = 255;
1651 /* Find closest level to level_current */
1652 for (i = 0; i < device->brightness->count; i++) {
1653 l = device->brightness->levels[i];
1654 if (abs(l - level_current) < abs(delta)) {
1655 delta = l - level_current;
1660 /* Ajust level_current to closest available level */
1661 level_current += delta;
1662 for (i = 0; i < device->brightness->count; i++) {
1663 l = device->brightness->levels[i];
1668 if (l < min_above && l > level_current)
1670 if (l > max_below && l < level_current)
1675 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1676 return (level_current < max) ? min_above : min;
1677 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1678 return (level_current < max) ? min_above : max;
1679 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1680 return (level_current > min) ? max_below : min;
1681 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1682 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1685 return level_current;
1690 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1692 unsigned long level_current, level_next;
1693 acpi_video_device_lcd_get_level_current(device, &level_current);
1694 level_next = acpi_video_get_next_level(device, level_current, event);
1695 acpi_video_device_lcd_set_level(device, level_next);
1699 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1700 struct acpi_device *device)
1703 struct acpi_device *dev;
1705 acpi_video_device_enumerate(video);
1707 list_for_each_entry(dev, &device->children, node) {
1709 status = acpi_video_bus_get_one_device(dev, video);
1710 if (ACPI_FAILURE(status)) {
1711 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1718 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1721 struct acpi_video_bus *video;
1724 if (!device || !device->video)
1727 video = device->video;
1729 acpi_video_device_remove_fs(device->dev);
1731 status = acpi_remove_notify_handler(device->dev->handle,
1733 acpi_video_device_notify);
1734 backlight_device_unregister(device->backlight);
1735 video_output_unregister(device->output_dev);
1740 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1743 struct acpi_video_device *dev, *next;
1745 mutex_lock(&video->device_list_lock);
1747 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1749 status = acpi_video_bus_put_one_device(dev);
1750 if (ACPI_FAILURE(status))
1751 printk(KERN_WARNING PREFIX
1752 "hhuuhhuu bug in acpi video driver.\n");
1754 if (dev->brightness) {
1755 kfree(dev->brightness->levels);
1756 kfree(dev->brightness);
1758 list_del(&dev->entry);
1762 mutex_unlock(&video->device_list_lock);
1767 /* acpi_video interface */
1769 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1771 return acpi_video_bus_DOS(video, 0, 0);
1774 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1776 return acpi_video_bus_DOS(video, 0, 1);
1779 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1781 struct acpi_video_bus *video = data;
1782 struct acpi_device *device = NULL;
1783 struct input_dev *input;
1789 device = video->device;
1790 input = video->input;
1793 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1794 * most likely via hotkey. */
1795 acpi_bus_generate_proc_event(device, event, 0);
1796 keycode = KEY_SWITCHVIDEOMODE;
1799 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1801 acpi_video_device_enumerate(video);
1802 acpi_video_device_rebind(video);
1803 acpi_video_switch_output(video, event);
1804 acpi_bus_generate_proc_event(device, event, 0);
1805 keycode = KEY_SWITCHVIDEOMODE;
1808 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1809 acpi_video_switch_output(video, event);
1810 acpi_bus_generate_proc_event(device, event, 0);
1811 keycode = KEY_SWITCHVIDEOMODE;
1813 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1814 acpi_video_switch_output(video, event);
1815 acpi_bus_generate_proc_event(device, event, 0);
1816 keycode = KEY_VIDEO_NEXT;
1818 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1819 acpi_video_switch_output(video, event);
1820 acpi_bus_generate_proc_event(device, event, 0);
1821 keycode = KEY_VIDEO_PREV;
1825 keycode = KEY_UNKNOWN;
1826 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1827 "Unsupported event [0x%x]\n", event));
1831 input_report_key(input, keycode, 1);
1833 input_report_key(input, keycode, 0);
1839 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1841 struct acpi_video_device *video_device = data;
1842 struct acpi_device *device = NULL;
1843 struct acpi_video_bus *bus;
1844 struct input_dev *input;
1850 device = video_device->dev;
1851 bus = video_device->video;
1855 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1856 if (brightness_switch_enabled)
1857 acpi_video_switch_brightness(video_device, event);
1858 acpi_bus_generate_proc_event(device, event, 0);
1859 keycode = KEY_BRIGHTNESS_CYCLE;
1861 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1862 if (brightness_switch_enabled)
1863 acpi_video_switch_brightness(video_device, event);
1864 acpi_bus_generate_proc_event(device, event, 0);
1865 keycode = KEY_BRIGHTNESSUP;
1867 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1868 if (brightness_switch_enabled)
1869 acpi_video_switch_brightness(video_device, event);
1870 acpi_bus_generate_proc_event(device, event, 0);
1871 keycode = KEY_BRIGHTNESSDOWN;
1873 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1874 if (brightness_switch_enabled)
1875 acpi_video_switch_brightness(video_device, event);
1876 acpi_bus_generate_proc_event(device, event, 0);
1877 keycode = KEY_BRIGHTNESS_ZERO;
1879 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1880 if (brightness_switch_enabled)
1881 acpi_video_switch_brightness(video_device, event);
1882 acpi_bus_generate_proc_event(device, event, 0);
1883 keycode = KEY_DISPLAY_OFF;
1886 keycode = KEY_UNKNOWN;
1887 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1888 "Unsupported event [0x%x]\n", event));
1892 input_report_key(input, keycode, 1);
1894 input_report_key(input, keycode, 0);
1900 static int instance;
1901 static int acpi_video_bus_add(struct acpi_device *device)
1904 struct acpi_video_bus *video;
1905 struct input_dev *input;
1908 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1912 /* a hack to fix the duplicate name "VID" problem on T61 */
1913 if (!strcmp(device->pnp.bus_id, "VID")) {
1915 device->pnp.bus_id[3] = '0' + instance;
1919 video->device = device;
1920 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1921 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1922 acpi_driver_data(device) = video;
1924 acpi_video_bus_find_cap(video);
1925 error = acpi_video_bus_check(video);
1927 goto err_free_video;
1929 error = acpi_video_bus_add_fs(device);
1931 goto err_free_video;
1933 mutex_init(&video->device_list_lock);
1934 INIT_LIST_HEAD(&video->video_device_list);
1936 acpi_video_bus_get_devices(video, device);
1937 acpi_video_bus_start_devices(video);
1939 status = acpi_install_notify_handler(device->handle,
1941 acpi_video_bus_notify, video);
1942 if (ACPI_FAILURE(status)) {
1943 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1944 "Error installing notify handler\n"));
1946 goto err_stop_video;
1949 video->input = input = input_allocate_device();
1952 goto err_uninstall_notify;
1955 snprintf(video->phys, sizeof(video->phys),
1956 "%s/video/input0", acpi_device_hid(video->device));
1958 input->name = acpi_device_name(video->device);
1959 input->phys = video->phys;
1960 input->id.bustype = BUS_HOST;
1961 input->id.product = 0x06;
1962 input->dev.parent = &device->dev;
1963 input->evbit[0] = BIT(EV_KEY);
1964 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1965 set_bit(KEY_VIDEO_NEXT, input->keybit);
1966 set_bit(KEY_VIDEO_PREV, input->keybit);
1967 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1968 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1969 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1970 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1971 set_bit(KEY_DISPLAY_OFF, input->keybit);
1972 set_bit(KEY_UNKNOWN, input->keybit);
1974 error = input_register_device(input);
1976 goto err_free_input_dev;
1978 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1979 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1980 video->flags.multihead ? "yes" : "no",
1981 video->flags.rom ? "yes" : "no",
1982 video->flags.post ? "yes" : "no");
1987 input_free_device(input);
1988 err_uninstall_notify:
1989 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1990 acpi_video_bus_notify);
1992 acpi_video_bus_stop_devices(video);
1993 acpi_video_bus_put_devices(video);
1994 kfree(video->attached_array);
1995 acpi_video_bus_remove_fs(device);
1998 acpi_driver_data(device) = NULL;
2003 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2005 acpi_status status = 0;
2006 struct acpi_video_bus *video = NULL;
2009 if (!device || !acpi_driver_data(device))
2012 video = acpi_driver_data(device);
2014 acpi_video_bus_stop_devices(video);
2016 status = acpi_remove_notify_handler(video->device->handle,
2018 acpi_video_bus_notify);
2020 acpi_video_bus_put_devices(video);
2021 acpi_video_bus_remove_fs(device);
2023 input_unregister_device(video->input);
2024 kfree(video->attached_array);
2030 static int __init acpi_video_init(void)
2036 acpi_dbg_level = 0xFFFFFFFF;
2037 acpi_dbg_layer = 0x08000000;
2040 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2041 if (!acpi_video_dir)
2043 acpi_video_dir->owner = THIS_MODULE;
2045 result = acpi_bus_register_driver(&acpi_video_bus);
2047 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2054 static void __exit acpi_video_exit(void)
2057 acpi_bus_unregister_driver(&acpi_video_bus);
2059 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2064 module_init(acpi_video_init);
2065 module_exit(acpi_video_exit);