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_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,
339 /* --------------------------------------------------------------------------
341 -------------------------------------------------------------------------- */
346 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
350 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
356 acpi_video_device_get_state(struct acpi_video_device *device,
357 unsigned long *state)
361 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
367 acpi_video_device_set_state(struct acpi_video_device *device, int state)
370 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
371 struct acpi_object_list args = { 1, &arg0 };
375 arg0.integer.value = state;
376 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
382 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
383 union acpi_object **levels)
386 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
387 union acpi_object *obj;
392 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
393 if (!ACPI_SUCCESS(status))
395 obj = (union acpi_object *)buffer.pointer;
396 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
397 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
407 kfree(buffer.pointer);
413 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
416 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
417 struct acpi_object_list args = { 1, &arg0 };
420 arg0.integer.value = level;
422 if (device->cap._BCM)
423 status = acpi_evaluate_object(device->dev->handle, "_BCM",
425 device->brightness->curr = level;
430 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
431 unsigned long *level)
433 if (device->cap._BQC)
434 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
436 *level = device->brightness->curr;
441 acpi_video_device_EDID(struct acpi_video_device *device,
442 union acpi_object **edid, ssize_t length)
445 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
446 union acpi_object *obj;
447 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
448 struct acpi_object_list args = { 1, &arg0 };
456 arg0.integer.value = 1;
457 else if (length == 256)
458 arg0.integer.value = 2;
462 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
463 if (ACPI_FAILURE(status))
466 obj = buffer.pointer;
468 if (obj && obj->type == ACPI_TYPE_BUFFER)
471 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
482 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
486 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
487 struct acpi_object_list args = { 1, &arg0 };
490 arg0.integer.value = option;
492 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
493 if (ACPI_SUCCESS(status))
494 status = tmp ? (-EINVAL) : (AE_OK);
500 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
504 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
510 acpi_video_bus_POST_options(struct acpi_video_bus *video,
511 unsigned long *options)
515 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
523 * video : video bus device pointer
525 * 0. The system BIOS should NOT automatically switch(toggle)
526 * the active display output.
527 * 1. The system BIOS should automatically switch (toggle) the
528 * active display output. No switch event.
529 * 2. The _DGS value should be locked.
530 * 3. The system BIOS should not automatically switch (toggle) the
531 * active display output, but instead generate the display switch
534 * 0. The system BIOS should automatically control the brightness level
535 * of the LCD when the power changes from AC to DC
536 * 1. The system BIOS should NOT automatically control the brightness
537 * level of the LCD when the power changes from AC to DC.
543 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
545 acpi_integer status = 0;
546 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
547 struct acpi_object_list args = { 1, &arg0 };
550 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
554 arg0.integer.value = (lcd_flag << 2) | bios_flag;
555 video->dos_setting = arg0.integer.value;
556 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
564 * device : video output device (LCD, CRT, ..)
569 * Find out all required AML methods defined under the output
573 static void acpi_video_device_find_cap(struct acpi_video_device *device)
575 acpi_handle h_dummy1;
578 union acpi_object *obj = NULL;
579 struct acpi_video_device_brightness *br = NULL;
582 memset(&device->cap, 0, sizeof(device->cap));
584 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
585 device->cap._ADR = 1;
587 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
588 device->cap._BCL = 1;
590 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
591 device->cap._BCM = 1;
593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
594 device->cap._BQC = 1;
595 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
596 device->cap._DDC = 1;
598 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
599 device->cap._DCS = 1;
601 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
602 device->cap._DGS = 1;
604 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
605 device->cap._DSS = 1;
608 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
610 if (obj->package.count >= 2) {
612 union acpi_object *o;
614 br = kzalloc(sizeof(*br), GFP_KERNEL);
616 printk(KERN_ERR "can't allocate memory\n");
618 br->levels = kmalloc(obj->package.count *
619 sizeof *(br->levels), GFP_KERNEL);
623 for (i = 0; i < obj->package.count; i++) {
624 o = (union acpi_object *)&obj->package.
626 if (o->type != ACPI_TYPE_INTEGER) {
627 printk(KERN_ERR PREFIX "Invalid data\n");
630 br->levels[count] = (u32) o->integer.value;
632 if (br->levels[count] > max_level)
633 max_level = br->levels[count];
642 device->brightness = br;
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "found %d brightness levels\n",
651 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
656 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
658 static int count = 0;
660 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
664 sprintf(name, "acpi_video%d", count++);
665 acpi_video_device_lcd_get_level_current(device, &tmp);
666 device->backlight = backlight_device_register(name,
667 NULL, device, &acpi_backlight_ops);
668 device->backlight->props.max_brightness = max_level;
669 device->backlight->props.brightness = (int)tmp;
670 backlight_update_status(device->backlight);
674 if (device->cap._DCS && device->cap._DSS){
675 static int count = 0;
677 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
680 sprintf(name, "acpi_video%d", count++);
681 device->output_dev = video_output_register(name,
682 NULL, device, &acpi_output_properties);
690 * device : video output device (VGA)
695 * Find out all required AML methods defined under the video bus device.
698 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
700 acpi_handle h_dummy1;
702 memset(&video->cap, 0, sizeof(video->cap));
703 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
706 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
709 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
712 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
715 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
718 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
724 * Check whether the video bus device has required AML method to
725 * support the desired features
728 static int acpi_video_bus_check(struct acpi_video_bus *video)
730 acpi_status status = -ENOENT;
736 /* Since there is no HID, CID and so on for VGA driver, we have
737 * to check well known required nodes.
740 /* Does this device support video switching? */
741 if (video->cap._DOS) {
742 video->flags.multihead = 1;
746 /* Does this device support retrieving a video ROM? */
747 if (video->cap._ROM) {
748 video->flags.rom = 1;
752 /* Does this device support configuring which video device to POST? */
753 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
754 video->flags.post = 1;
761 /* --------------------------------------------------------------------------
763 -------------------------------------------------------------------------- */
765 static struct proc_dir_entry *acpi_video_dir;
769 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
771 struct acpi_video_device *dev = seq->private;
777 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
778 seq_printf(seq, "type: ");
780 seq_printf(seq, "CRT\n");
781 else if (dev->flags.lcd)
782 seq_printf(seq, "LCD\n");
783 else if (dev->flags.tvout)
784 seq_printf(seq, "TVOUT\n");
785 else if (dev->flags.dvi)
786 seq_printf(seq, "DVI\n");
788 seq_printf(seq, "UNKNOWN\n");
790 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
797 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
799 return single_open(file, acpi_video_device_info_seq_show,
803 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
806 struct acpi_video_device *dev = seq->private;
813 status = acpi_video_device_get_state(dev, &state);
814 seq_printf(seq, "state: ");
815 if (ACPI_SUCCESS(status))
816 seq_printf(seq, "0x%02lx\n", state);
818 seq_printf(seq, "<not supported>\n");
820 status = acpi_video_device_query(dev, &state);
821 seq_printf(seq, "query: ");
822 if (ACPI_SUCCESS(status))
823 seq_printf(seq, "0x%02lx\n", state);
825 seq_printf(seq, "<not supported>\n");
832 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
834 return single_open(file, acpi_video_device_state_seq_show,
839 acpi_video_device_write_state(struct file *file,
840 const char __user * buffer,
841 size_t count, loff_t * data)
844 struct seq_file *m = file->private_data;
845 struct acpi_video_device *dev = m->private;
846 char str[12] = { 0 };
850 if (!dev || count + 1 > sizeof str)
853 if (copy_from_user(str, buffer, count))
857 state = simple_strtoul(str, NULL, 0);
858 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
860 status = acpi_video_device_set_state(dev, state);
869 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
871 struct acpi_video_device *dev = seq->private;
875 if (!dev || !dev->brightness) {
876 seq_printf(seq, "<not supported>\n");
880 seq_printf(seq, "levels: ");
881 for (i = 0; i < dev->brightness->count; i++)
882 seq_printf(seq, " %d", dev->brightness->levels[i]);
883 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
889 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
891 return single_open(file, acpi_video_device_brightness_seq_show,
896 acpi_video_device_write_brightness(struct file *file,
897 const char __user * buffer,
898 size_t count, loff_t * data)
900 struct seq_file *m = file->private_data;
901 struct acpi_video_device *dev = m->private;
903 unsigned int level = 0;
907 if (!dev || !dev->brightness || count + 1 > sizeof str)
910 if (copy_from_user(str, buffer, count))
914 level = simple_strtoul(str, NULL, 0);
919 /* validate through the list of available levels */
920 for (i = 0; i < dev->brightness->count; i++)
921 if (level == dev->brightness->levels[i]) {
923 (acpi_video_device_lcd_set_level(dev, level)))
924 dev->brightness->curr = level;
931 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
933 struct acpi_video_device *dev = seq->private;
936 union acpi_object *edid = NULL;
942 status = acpi_video_device_EDID(dev, &edid, 128);
943 if (ACPI_FAILURE(status)) {
944 status = acpi_video_device_EDID(dev, &edid, 256);
947 if (ACPI_FAILURE(status)) {
951 if (edid && edid->type == ACPI_TYPE_BUFFER) {
952 for (i = 0; i < edid->buffer.length; i++)
953 seq_putc(seq, edid->buffer.pointer[i]);
958 seq_printf(seq, "<not supported>\n");
966 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
968 return single_open(file, acpi_video_device_EDID_seq_show,
972 static int acpi_video_device_add_fs(struct acpi_device *device)
974 struct proc_dir_entry *entry = NULL;
975 struct acpi_video_device *vid_dev;
981 vid_dev = acpi_driver_data(device);
985 if (!acpi_device_dir(device)) {
986 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
987 vid_dev->video->dir);
988 if (!acpi_device_dir(device))
990 acpi_device_dir(device)->owner = THIS_MODULE;
994 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
998 entry->proc_fops = &acpi_video_device_info_fops;
999 entry->data = acpi_driver_data(device);
1000 entry->owner = THIS_MODULE;
1005 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1006 acpi_device_dir(device));
1010 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1011 entry->proc_fops = &acpi_video_device_state_fops;
1012 entry->data = acpi_driver_data(device);
1013 entry->owner = THIS_MODULE;
1016 /* 'brightness' [R/W] */
1018 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1019 acpi_device_dir(device));
1023 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1024 entry->proc_fops = &acpi_video_device_brightness_fops;
1025 entry->data = acpi_driver_data(device);
1026 entry->owner = THIS_MODULE;
1030 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1034 entry->proc_fops = &acpi_video_device_EDID_fops;
1035 entry->data = acpi_driver_data(device);
1036 entry->owner = THIS_MODULE;
1042 static int acpi_video_device_remove_fs(struct acpi_device *device)
1044 struct acpi_video_device *vid_dev;
1046 vid_dev = acpi_driver_data(device);
1047 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1050 if (acpi_device_dir(device)) {
1051 remove_proc_entry("info", acpi_device_dir(device));
1052 remove_proc_entry("state", acpi_device_dir(device));
1053 remove_proc_entry("brightness", acpi_device_dir(device));
1054 remove_proc_entry("EDID", acpi_device_dir(device));
1055 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1056 acpi_device_dir(device) = NULL;
1063 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1065 struct acpi_video_bus *video = seq->private;
1071 seq_printf(seq, "Switching heads: %s\n",
1072 video->flags.multihead ? "yes" : "no");
1073 seq_printf(seq, "Video ROM: %s\n",
1074 video->flags.rom ? "yes" : "no");
1075 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1076 video->flags.post ? "yes" : "no");
1082 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1084 return single_open(file, acpi_video_bus_info_seq_show,
1088 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1090 struct acpi_video_bus *video = seq->private;
1096 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1097 seq_printf(seq, "<TODO>\n");
1103 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1105 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1108 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1110 struct acpi_video_bus *video = seq->private;
1111 unsigned long options;
1118 status = acpi_video_bus_POST_options(video, &options);
1119 if (ACPI_SUCCESS(status)) {
1120 if (!(options & 1)) {
1121 printk(KERN_WARNING PREFIX
1122 "The motherboard VGA device is not listed as a possible POST device.\n");
1123 printk(KERN_WARNING PREFIX
1124 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1126 printk("%lx\n", options);
1127 seq_printf(seq, "can POST: <integrated video>");
1129 seq_printf(seq, " <PCI video>");
1131 seq_printf(seq, " <AGP video>");
1132 seq_putc(seq, '\n');
1134 seq_printf(seq, "<not supported>\n");
1140 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1142 return single_open(file, acpi_video_bus_POST_info_seq_show,
1146 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1148 struct acpi_video_bus *video = seq->private;
1156 status = acpi_video_bus_get_POST(video, &id);
1157 if (!ACPI_SUCCESS(status)) {
1158 seq_printf(seq, "<not supported>\n");
1161 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1167 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1169 struct acpi_video_bus *video = seq->private;
1172 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1177 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1179 return single_open(file, acpi_video_bus_POST_seq_show,
1183 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1185 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1189 acpi_video_bus_write_POST(struct file *file,
1190 const char __user * buffer,
1191 size_t count, loff_t * data)
1194 struct seq_file *m = file->private_data;
1195 struct acpi_video_bus *video = m->private;
1196 char str[12] = { 0 };
1197 unsigned long opt, options;
1200 if (!video || count + 1 > sizeof str)
1203 status = acpi_video_bus_POST_options(video, &options);
1204 if (!ACPI_SUCCESS(status))
1207 if (copy_from_user(str, buffer, count))
1211 opt = strtoul(str, NULL, 0);
1215 /* just in case an OEM 'forgot' the motherboard... */
1218 if (options & (1ul << opt)) {
1219 status = acpi_video_bus_set_POST(video, opt);
1220 if (!ACPI_SUCCESS(status))
1229 acpi_video_bus_write_DOS(struct file *file,
1230 const char __user * buffer,
1231 size_t count, loff_t * data)
1234 struct seq_file *m = file->private_data;
1235 struct acpi_video_bus *video = m->private;
1236 char str[12] = { 0 };
1240 if (!video || count + 1 > sizeof str)
1243 if (copy_from_user(str, buffer, count))
1247 opt = strtoul(str, NULL, 0);
1251 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1253 if (!ACPI_SUCCESS(status))
1259 static int acpi_video_bus_add_fs(struct acpi_device *device)
1261 struct proc_dir_entry *entry = NULL;
1262 struct acpi_video_bus *video;
1265 video = acpi_driver_data(device);
1267 if (!acpi_device_dir(device)) {
1268 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1270 if (!acpi_device_dir(device))
1272 video->dir = acpi_device_dir(device);
1273 acpi_device_dir(device)->owner = THIS_MODULE;
1277 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1281 entry->proc_fops = &acpi_video_bus_info_fops;
1282 entry->data = acpi_driver_data(device);
1283 entry->owner = THIS_MODULE;
1287 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1291 entry->proc_fops = &acpi_video_bus_ROM_fops;
1292 entry->data = acpi_driver_data(device);
1293 entry->owner = THIS_MODULE;
1296 /* 'POST_info' [R] */
1298 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1302 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1303 entry->data = acpi_driver_data(device);
1304 entry->owner = THIS_MODULE;
1309 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1310 acpi_device_dir(device));
1314 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1315 entry->proc_fops = &acpi_video_bus_POST_fops;
1316 entry->data = acpi_driver_data(device);
1317 entry->owner = THIS_MODULE;
1322 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1323 acpi_device_dir(device));
1327 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1328 entry->proc_fops = &acpi_video_bus_DOS_fops;
1329 entry->data = acpi_driver_data(device);
1330 entry->owner = THIS_MODULE;
1336 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1338 struct acpi_video_bus *video;
1341 video = acpi_driver_data(device);
1343 if (acpi_device_dir(device)) {
1344 remove_proc_entry("info", acpi_device_dir(device));
1345 remove_proc_entry("ROM", acpi_device_dir(device));
1346 remove_proc_entry("POST_info", acpi_device_dir(device));
1347 remove_proc_entry("POST", acpi_device_dir(device));
1348 remove_proc_entry("DOS", acpi_device_dir(device));
1349 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1350 acpi_device_dir(device) = NULL;
1356 /* --------------------------------------------------------------------------
1358 -------------------------------------------------------------------------- */
1360 /* device interface */
1361 static struct acpi_video_device_attrib*
1362 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1366 for(count = 0; count < video->attached_count; count++)
1367 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1368 return &(video->attached_array[count].value.attrib);
1373 acpi_video_bus_get_one_device(struct acpi_device *device,
1374 struct acpi_video_bus *video)
1376 unsigned long device_id;
1378 struct acpi_video_device *data;
1379 struct acpi_video_device_attrib* attribute;
1381 if (!device || !video)
1385 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1386 if (ACPI_SUCCESS(status)) {
1388 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1392 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1393 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1394 acpi_driver_data(device) = data;
1396 data->device_id = device_id;
1397 data->video = video;
1400 attribute = acpi_video_get_device_attr(video, device_id);
1402 if((attribute != NULL) && attribute->device_id_scheme) {
1403 switch (attribute->display_type) {
1404 case ACPI_VIDEO_DISPLAY_CRT:
1405 data->flags.crt = 1;
1407 case ACPI_VIDEO_DISPLAY_TV:
1408 data->flags.tvout = 1;
1410 case ACPI_VIDEO_DISPLAY_DVI:
1411 data->flags.dvi = 1;
1413 case ACPI_VIDEO_DISPLAY_LCD:
1414 data->flags.lcd = 1;
1417 data->flags.unknown = 1;
1420 if(attribute->bios_can_detect)
1421 data->flags.bios = 1;
1423 data->flags.unknown = 1;
1425 acpi_video_device_bind(video, data);
1426 acpi_video_device_find_cap(data);
1428 status = acpi_install_notify_handler(device->handle,
1430 acpi_video_device_notify,
1432 if (ACPI_FAILURE(status)) {
1433 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1434 "Error installing notify handler\n"));
1435 if(data->brightness)
1436 kfree(data->brightness->levels);
1437 kfree(data->brightness);
1442 mutex_lock(&video->device_list_lock);
1443 list_add_tail(&data->entry, &video->video_device_list);
1444 mutex_unlock(&video->device_list_lock);
1446 acpi_video_device_add_fs(device);
1456 * video : video bus device
1461 * Enumerate the video device list of the video bus,
1462 * bind the ids with the corresponding video devices
1463 * under the video bus.
1466 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1468 struct acpi_video_device *dev;
1470 mutex_lock(&video->device_list_lock);
1472 list_for_each_entry(dev, &video->video_device_list, entry)
1473 acpi_video_device_bind(video, dev);
1475 mutex_unlock(&video->device_list_lock);
1480 * video : video bus device
1481 * device : video output device under the video
1487 * Bind the ids with the corresponding video devices
1488 * under the video bus.
1492 acpi_video_device_bind(struct acpi_video_bus *video,
1493 struct acpi_video_device *device)
1497 #define IDS_VAL(i) video->attached_array[i].value.int_val
1498 #define IDS_BIND(i) video->attached_array[i].bind_info
1500 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1501 i < video->attached_count; i++) {
1502 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1503 IDS_BIND(i) = device;
1504 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1513 * video : video bus device
1518 * Call _DOD to enumerate all devices attached to display adapter
1522 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1527 struct acpi_video_enumerated_device *active_device_list;
1528 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1529 union acpi_object *dod = NULL;
1530 union acpi_object *obj;
1532 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1533 if (!ACPI_SUCCESS(status)) {
1534 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1538 dod = buffer.pointer;
1539 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1540 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1545 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1546 dod->package.count));
1548 active_device_list = kmalloc((1 +
1549 dod->package.count) *
1551 acpi_video_enumerated_device),
1554 if (!active_device_list) {
1560 for (i = 0; i < dod->package.count; i++) {
1561 obj = &dod->package.elements[i];
1563 if (obj->type != ACPI_TYPE_INTEGER) {
1564 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1565 active_device_list[i].value.int_val =
1566 ACPI_VIDEO_HEAD_INVALID;
1568 active_device_list[i].value.int_val = obj->integer.value;
1569 active_device_list[i].bind_info = NULL;
1570 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1571 (int)obj->integer.value));
1574 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1576 kfree(video->attached_array);
1578 video->attached_array = active_device_list;
1579 video->attached_count = count;
1581 kfree(buffer.pointer);
1586 acpi_video_get_next_level(struct acpi_video_device *device,
1587 u32 level_current, u32 event)
1589 int min, max, min_above, max_below, i, l, delta = 255;
1590 max = max_below = 0;
1591 min = min_above = 255;
1592 /* Find closest level to level_current */
1593 for (i = 0; i < device->brightness->count; i++) {
1594 l = device->brightness->levels[i];
1595 if (abs(l - level_current) < abs(delta)) {
1596 delta = l - level_current;
1601 /* Ajust level_current to closest available level */
1602 level_current += delta;
1603 for (i = 0; i < device->brightness->count; i++) {
1604 l = device->brightness->levels[i];
1609 if (l < min_above && l > level_current)
1611 if (l > max_below && l < level_current)
1616 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1617 return (level_current < max) ? min_above : min;
1618 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1619 return (level_current < max) ? min_above : max;
1620 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1621 return (level_current > min) ? max_below : min;
1622 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1623 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1626 return level_current;
1631 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1633 unsigned long level_current, level_next;
1634 acpi_video_device_lcd_get_level_current(device, &level_current);
1635 level_next = acpi_video_get_next_level(device, level_current, event);
1636 acpi_video_device_lcd_set_level(device, level_next);
1640 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1641 struct acpi_device *device)
1644 struct acpi_device *dev;
1646 acpi_video_device_enumerate(video);
1648 list_for_each_entry(dev, &device->children, node) {
1650 status = acpi_video_bus_get_one_device(dev, video);
1651 if (ACPI_FAILURE(status)) {
1652 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1659 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1662 struct acpi_video_bus *video;
1665 if (!device || !device->video)
1668 video = device->video;
1670 acpi_video_device_remove_fs(device->dev);
1672 status = acpi_remove_notify_handler(device->dev->handle,
1674 acpi_video_device_notify);
1675 backlight_device_unregister(device->backlight);
1676 video_output_unregister(device->output_dev);
1681 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1684 struct acpi_video_device *dev, *next;
1686 mutex_lock(&video->device_list_lock);
1688 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1690 status = acpi_video_bus_put_one_device(dev);
1691 if (ACPI_FAILURE(status))
1692 printk(KERN_WARNING PREFIX
1693 "hhuuhhuu bug in acpi video driver.\n");
1695 if (dev->brightness) {
1696 kfree(dev->brightness->levels);
1697 kfree(dev->brightness);
1699 list_del(&dev->entry);
1703 mutex_unlock(&video->device_list_lock);
1708 /* acpi_video interface */
1710 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1712 return acpi_video_bus_DOS(video, 0, 0);
1715 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1717 return acpi_video_bus_DOS(video, 0, 1);
1720 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1722 struct acpi_video_bus *video = data;
1723 struct acpi_device *device = NULL;
1724 struct input_dev *input;
1730 device = video->device;
1731 input = video->input;
1734 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1735 * most likely via hotkey. */
1736 acpi_bus_generate_proc_event(device, event, 0);
1737 keycode = KEY_SWITCHVIDEOMODE;
1740 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1742 acpi_video_device_enumerate(video);
1743 acpi_video_device_rebind(video);
1744 acpi_bus_generate_proc_event(device, event, 0);
1745 keycode = KEY_SWITCHVIDEOMODE;
1748 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1749 acpi_bus_generate_proc_event(device, event, 0);
1750 keycode = KEY_SWITCHVIDEOMODE;
1752 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1753 acpi_bus_generate_proc_event(device, event, 0);
1754 keycode = KEY_VIDEO_NEXT;
1756 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1757 acpi_bus_generate_proc_event(device, event, 0);
1758 keycode = KEY_VIDEO_PREV;
1762 keycode = KEY_UNKNOWN;
1763 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1764 "Unsupported event [0x%x]\n", event));
1768 acpi_notifier_call_chain(device, event, 0);
1769 input_report_key(input, keycode, 1);
1771 input_report_key(input, keycode, 0);
1777 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1779 struct acpi_video_device *video_device = data;
1780 struct acpi_device *device = NULL;
1781 struct acpi_video_bus *bus;
1782 struct input_dev *input;
1788 device = video_device->dev;
1789 bus = video_device->video;
1793 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1794 if (brightness_switch_enabled)
1795 acpi_video_switch_brightness(video_device, event);
1796 acpi_bus_generate_proc_event(device, event, 0);
1797 keycode = KEY_BRIGHTNESS_CYCLE;
1799 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1800 if (brightness_switch_enabled)
1801 acpi_video_switch_brightness(video_device, event);
1802 acpi_bus_generate_proc_event(device, event, 0);
1803 keycode = KEY_BRIGHTNESSUP;
1805 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1806 if (brightness_switch_enabled)
1807 acpi_video_switch_brightness(video_device, event);
1808 acpi_bus_generate_proc_event(device, event, 0);
1809 keycode = KEY_BRIGHTNESSDOWN;
1811 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1812 if (brightness_switch_enabled)
1813 acpi_video_switch_brightness(video_device, event);
1814 acpi_bus_generate_proc_event(device, event, 0);
1815 keycode = KEY_BRIGHTNESS_ZERO;
1817 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1818 if (brightness_switch_enabled)
1819 acpi_video_switch_brightness(video_device, event);
1820 acpi_bus_generate_proc_event(device, event, 0);
1821 keycode = KEY_DISPLAY_OFF;
1824 keycode = KEY_UNKNOWN;
1825 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1826 "Unsupported event [0x%x]\n", event));
1830 acpi_notifier_call_chain(device, event, 0);
1831 input_report_key(input, keycode, 1);
1833 input_report_key(input, keycode, 0);
1839 static int instance;
1840 static int acpi_video_bus_add(struct acpi_device *device)
1843 struct acpi_video_bus *video;
1844 struct input_dev *input;
1847 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1851 /* a hack to fix the duplicate name "VID" problem on T61 */
1852 if (!strcmp(device->pnp.bus_id, "VID")) {
1854 device->pnp.bus_id[3] = '0' + instance;
1858 video->device = device;
1859 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1860 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1861 acpi_driver_data(device) = video;
1863 acpi_video_bus_find_cap(video);
1864 error = acpi_video_bus_check(video);
1866 goto err_free_video;
1868 error = acpi_video_bus_add_fs(device);
1870 goto err_free_video;
1872 mutex_init(&video->device_list_lock);
1873 INIT_LIST_HEAD(&video->video_device_list);
1875 acpi_video_bus_get_devices(video, device);
1876 acpi_video_bus_start_devices(video);
1878 status = acpi_install_notify_handler(device->handle,
1880 acpi_video_bus_notify, video);
1881 if (ACPI_FAILURE(status)) {
1882 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1883 "Error installing notify handler\n"));
1885 goto err_stop_video;
1888 video->input = input = input_allocate_device();
1891 goto err_uninstall_notify;
1894 snprintf(video->phys, sizeof(video->phys),
1895 "%s/video/input0", acpi_device_hid(video->device));
1897 input->name = acpi_device_name(video->device);
1898 input->phys = video->phys;
1899 input->id.bustype = BUS_HOST;
1900 input->id.product = 0x06;
1901 input->dev.parent = &device->dev;
1902 input->evbit[0] = BIT(EV_KEY);
1903 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1904 set_bit(KEY_VIDEO_NEXT, input->keybit);
1905 set_bit(KEY_VIDEO_PREV, input->keybit);
1906 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1907 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1908 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1909 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1910 set_bit(KEY_DISPLAY_OFF, input->keybit);
1911 set_bit(KEY_UNKNOWN, input->keybit);
1913 error = input_register_device(input);
1915 goto err_free_input_dev;
1917 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1918 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1919 video->flags.multihead ? "yes" : "no",
1920 video->flags.rom ? "yes" : "no",
1921 video->flags.post ? "yes" : "no");
1926 input_free_device(input);
1927 err_uninstall_notify:
1928 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1929 acpi_video_bus_notify);
1931 acpi_video_bus_stop_devices(video);
1932 acpi_video_bus_put_devices(video);
1933 kfree(video->attached_array);
1934 acpi_video_bus_remove_fs(device);
1937 acpi_driver_data(device) = NULL;
1942 static int acpi_video_bus_remove(struct acpi_device *device, int type)
1944 acpi_status status = 0;
1945 struct acpi_video_bus *video = NULL;
1948 if (!device || !acpi_driver_data(device))
1951 video = acpi_driver_data(device);
1953 acpi_video_bus_stop_devices(video);
1955 status = acpi_remove_notify_handler(video->device->handle,
1957 acpi_video_bus_notify);
1959 acpi_video_bus_put_devices(video);
1960 acpi_video_bus_remove_fs(device);
1962 input_unregister_device(video->input);
1963 kfree(video->attached_array);
1969 static int __init acpi_video_init(void)
1975 acpi_dbg_level = 0xFFFFFFFF;
1976 acpi_dbg_layer = 0x08000000;
1979 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1980 if (!acpi_video_dir)
1982 acpi_video_dir->owner = THIS_MODULE;
1984 result = acpi_bus_register_driver(&acpi_video_bus);
1986 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1993 static void __exit acpi_video_exit(void)
1996 acpi_bus_unregister_driver(&acpi_video_bus);
1998 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2003 module_init(acpi_video_init);
2004 module_exit(acpi_video_exit);