2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/video_output.h>
38 #include <asm/uaccess.h>
40 #include <acpi/acpi_bus.h>
41 #include <acpi/acpi_drivers.h>
43 #define ACPI_VIDEO_COMPONENT 0x08000000
44 #define ACPI_VIDEO_CLASS "video"
45 #define ACPI_VIDEO_BUS_NAME "Video Bus"
46 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
47 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
49 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
59 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60 #define ACPI_VIDEO_HEAD_END (~0u)
61 #define MAX_NAME_LEN 20
63 #define ACPI_VIDEO_DISPLAY_CRT 1
64 #define ACPI_VIDEO_DISPLAY_TV 2
65 #define ACPI_VIDEO_DISPLAY_DVI 3
66 #define ACPI_VIDEO_DISPLAY_LCD 4
68 #define _COMPONENT ACPI_VIDEO_COMPONENT
69 ACPI_MODULE_NAME("video");
71 MODULE_AUTHOR("Bruno Ducrot");
72 MODULE_DESCRIPTION("ACPI Video Driver");
73 MODULE_LICENSE("GPL");
75 static int acpi_video_bus_add(struct acpi_device *device);
76 static int acpi_video_bus_remove(struct acpi_device *device, int type);
78 static const struct acpi_device_id video_device_ids[] = {
82 MODULE_DEVICE_TABLE(acpi, video_device_ids);
84 static struct acpi_driver acpi_video_bus = {
86 .class = ACPI_VIDEO_CLASS,
87 .ids = video_device_ids,
89 .add = acpi_video_bus_add,
90 .remove = acpi_video_bus_remove,
94 struct acpi_video_bus_flags {
95 u8 multihead:1; /* can switch video heads */
96 u8 rom:1; /* can retrieve a video rom */
97 u8 post:1; /* can configure the head to */
101 struct acpi_video_bus_cap {
102 u8 _DOS:1; /*Enable/Disable output switching */
103 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
104 u8 _ROM:1; /*Get ROM Data */
105 u8 _GPD:1; /*Get POST Device */
106 u8 _SPD:1; /*Set POST Device */
107 u8 _VPO:1; /*Video POST Options */
111 struct acpi_video_device_attrib {
112 u32 display_index:4; /* A zero-based instance of the Display */
113 u32 display_port_attachment:4; /*This field differentiates the display type */
114 u32 display_type:4; /*Describe the specific type in use */
115 u32 vendor_specific:4; /*Chipset Vendor Specific */
116 u32 bios_can_detect:1; /*BIOS can detect the device */
117 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
119 u32 pipe_id:3; /*For VGA multiple-head devices. */
120 u32 reserved:10; /*Must be 0 */
121 u32 device_id_scheme:1; /*Device ID Scheme */
124 struct acpi_video_enumerated_device {
127 struct acpi_video_device_attrib attrib;
129 struct acpi_video_device *bind_info;
132 struct acpi_video_bus {
133 struct acpi_device *device;
135 struct acpi_video_enumerated_device *attached_array;
137 struct acpi_video_bus_cap cap;
138 struct acpi_video_bus_flags flags;
139 struct list_head video_device_list;
140 struct mutex device_list_lock; /* protects video_device_list */
141 struct proc_dir_entry *dir;
142 struct input_dev *input;
143 char phys[32]; /* for input device */
146 struct acpi_video_device_flags {
156 struct acpi_video_device_cap {
157 u8 _ADR:1; /*Return the unique ID */
158 u8 _BCL:1; /*Query list of brightness control levels supported */
159 u8 _BCM:1; /*Set the brightness level */
160 u8 _BQC:1; /* Get current brightness level */
161 u8 _DDC:1; /*Return the EDID for this device */
162 u8 _DCS:1; /*Return status of output device */
163 u8 _DGS:1; /*Query graphics state */
164 u8 _DSS:1; /*Device state set */
167 struct acpi_video_device_brightness {
173 struct acpi_video_device {
174 unsigned long device_id;
175 struct acpi_video_device_flags flags;
176 struct acpi_video_device_cap cap;
177 struct list_head entry;
178 struct acpi_video_bus *video;
179 struct acpi_device *dev;
180 struct acpi_video_device_brightness *brightness;
181 struct backlight_device *backlight;
182 struct output_device *output_dev;
186 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
187 static struct file_operations acpi_video_bus_info_fops = {
188 .open = acpi_video_bus_info_open_fs,
191 .release = single_release,
194 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
195 static struct file_operations acpi_video_bus_ROM_fops = {
196 .open = acpi_video_bus_ROM_open_fs,
199 .release = single_release,
202 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
204 static struct file_operations acpi_video_bus_POST_info_fops = {
205 .open = acpi_video_bus_POST_info_open_fs,
208 .release = single_release,
211 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
212 static struct file_operations acpi_video_bus_POST_fops = {
213 .open = acpi_video_bus_POST_open_fs,
216 .release = single_release,
219 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
220 static struct file_operations acpi_video_bus_DOS_fops = {
221 .open = acpi_video_bus_DOS_open_fs,
224 .release = single_release,
228 static int acpi_video_device_info_open_fs(struct inode *inode,
230 static struct file_operations acpi_video_device_info_fops = {
231 .open = acpi_video_device_info_open_fs,
234 .release = single_release,
237 static int acpi_video_device_state_open_fs(struct inode *inode,
239 static struct file_operations acpi_video_device_state_fops = {
240 .open = acpi_video_device_state_open_fs,
243 .release = single_release,
246 static int acpi_video_device_brightness_open_fs(struct inode *inode,
248 static struct file_operations acpi_video_device_brightness_fops = {
249 .open = acpi_video_device_brightness_open_fs,
252 .release = single_release,
255 static int acpi_video_device_EDID_open_fs(struct inode *inode,
257 static struct file_operations acpi_video_device_EDID_fops = {
258 .open = acpi_video_device_EDID_open_fs,
261 .release = single_release,
264 static char device_decode[][30] = {
265 "motherboard VGA device",
271 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
272 static void acpi_video_device_rebind(struct acpi_video_bus *video);
273 static void acpi_video_device_bind(struct acpi_video_bus *video,
274 struct acpi_video_device *device);
275 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
276 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
277 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
279 static int acpi_video_device_lcd_get_level_current(
280 struct acpi_video_device *device,
281 unsigned long *level);
282 static int acpi_video_get_next_level(struct acpi_video_device *device,
283 u32 level_current, u32 event);
284 static void acpi_video_switch_brightness(struct acpi_video_device *device,
286 static int acpi_video_device_get_state(struct acpi_video_device *device,
287 unsigned long *state);
288 static int acpi_video_output_get(struct output_device *od);
289 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
291 /*backlight device sysfs support*/
292 static int acpi_video_get_brightness(struct backlight_device *bd)
294 unsigned long cur_level;
296 struct acpi_video_device *vd =
297 (struct acpi_video_device *)bl_get_data(bd);
298 acpi_video_device_lcd_get_level_current(vd, &cur_level);
299 for (i = 2; i < vd->brightness->count; i++) {
300 if (vd->brightness->levels[i] == cur_level)
301 /* The first two entries are special - see page 575
302 of the ACPI spec 3.0 */
308 static int acpi_video_set_brightness(struct backlight_device *bd)
310 int request_level = bd->props.brightness+2;
311 struct acpi_video_device *vd =
312 (struct acpi_video_device *)bl_get_data(bd);
313 acpi_video_device_lcd_set_level(vd,
314 vd->brightness->levels[request_level]);
318 static struct backlight_ops acpi_backlight_ops = {
319 .get_brightness = acpi_video_get_brightness,
320 .update_status = acpi_video_set_brightness,
323 /*video output device sysfs support*/
324 static int acpi_video_output_get(struct output_device *od)
327 struct acpi_video_device *vd =
328 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
329 acpi_video_device_get_state(vd, &state);
333 static int acpi_video_output_set(struct output_device *od)
335 unsigned long state = od->request_state;
336 struct acpi_video_device *vd=
337 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
338 return acpi_video_device_set_state(vd, state);
341 static struct output_properties acpi_output_properties = {
342 .set_state = acpi_video_output_set,
343 .get_status = acpi_video_output_get,
345 /* --------------------------------------------------------------------------
347 -------------------------------------------------------------------------- */
352 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
356 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
362 acpi_video_device_get_state(struct acpi_video_device *device,
363 unsigned long *state)
367 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
373 acpi_video_device_set_state(struct acpi_video_device *device, int state)
376 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
377 struct acpi_object_list args = { 1, &arg0 };
381 arg0.integer.value = state;
382 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
388 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
389 union acpi_object **levels)
392 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
393 union acpi_object *obj;
398 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
399 if (!ACPI_SUCCESS(status))
401 obj = (union acpi_object *)buffer.pointer;
402 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
403 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
413 kfree(buffer.pointer);
419 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
422 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
423 struct acpi_object_list args = { 1, &arg0 };
426 arg0.integer.value = level;
428 if (device->cap._BCM)
429 status = acpi_evaluate_object(device->dev->handle, "_BCM",
431 device->brightness->curr = level;
436 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
437 unsigned long *level)
439 if (device->cap._BQC)
440 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
442 *level = device->brightness->curr;
447 acpi_video_device_EDID(struct acpi_video_device *device,
448 union acpi_object **edid, ssize_t length)
451 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
452 union acpi_object *obj;
453 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
454 struct acpi_object_list args = { 1, &arg0 };
462 arg0.integer.value = 1;
463 else if (length == 256)
464 arg0.integer.value = 2;
468 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
469 if (ACPI_FAILURE(status))
472 obj = buffer.pointer;
474 if (obj && obj->type == ACPI_TYPE_BUFFER)
477 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
488 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
492 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
493 struct acpi_object_list args = { 1, &arg0 };
496 arg0.integer.value = option;
498 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
499 if (ACPI_SUCCESS(status))
500 status = tmp ? (-EINVAL) : (AE_OK);
506 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
510 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
516 acpi_video_bus_POST_options(struct acpi_video_bus *video,
517 unsigned long *options)
521 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
529 * video : video bus device pointer
531 * 0. The system BIOS should NOT automatically switch(toggle)
532 * the active display output.
533 * 1. The system BIOS should automatically switch (toggle) the
534 * active display output. No switch event.
535 * 2. The _DGS value should be locked.
536 * 3. The system BIOS should not automatically switch (toggle) the
537 * active display output, but instead generate the display switch
540 * 0. The system BIOS should automatically control the brightness level
541 * of the LCD when the power changes from AC to DC
542 * 1. The system BIOS should NOT automatically control the brightness
543 * level of the LCD when the power changes from AC to DC.
549 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
551 acpi_integer status = 0;
552 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
553 struct acpi_object_list args = { 1, &arg0 };
556 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
560 arg0.integer.value = (lcd_flag << 2) | bios_flag;
561 video->dos_setting = arg0.integer.value;
562 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
570 * device : video output device (LCD, CRT, ..)
575 * Find out all required AML methods defined under the output
579 static void acpi_video_device_find_cap(struct acpi_video_device *device)
581 acpi_handle h_dummy1;
584 union acpi_object *obj = NULL;
585 struct acpi_video_device_brightness *br = NULL;
588 memset(&device->cap, 0, sizeof(device->cap));
590 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
591 device->cap._ADR = 1;
593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
594 device->cap._BCL = 1;
596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
597 device->cap._BCM = 1;
599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
600 device->cap._BQC = 1;
601 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
602 device->cap._DDC = 1;
604 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
605 device->cap._DCS = 1;
607 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
608 device->cap._DGS = 1;
610 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
611 device->cap._DSS = 1;
614 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
616 if (obj->package.count >= 2) {
618 union acpi_object *o;
620 br = kzalloc(sizeof(*br), GFP_KERNEL);
622 printk(KERN_ERR "can't allocate memory\n");
624 br->levels = kmalloc(obj->package.count *
625 sizeof *(br->levels), GFP_KERNEL);
629 for (i = 0; i < obj->package.count; i++) {
630 o = (union acpi_object *)&obj->package.
632 if (o->type != ACPI_TYPE_INTEGER) {
633 printk(KERN_ERR PREFIX "Invalid data\n");
636 br->levels[count] = (u32) o->integer.value;
638 if (br->levels[count] > max_level)
639 max_level = br->levels[count];
648 device->brightness = br;
649 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
650 "found %d brightness levels\n",
657 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
662 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
663 static int count = 0;
665 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
669 sprintf(name, "acpi_video%d", count++);
670 device->backlight = backlight_device_register(name,
671 NULL, device, &acpi_backlight_ops);
672 device->backlight->props.max_brightness = device->brightness->count-3;
673 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
674 backlight_update_status(device->backlight);
678 if (device->cap._DCS && device->cap._DSS){
679 static int count = 0;
681 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
684 sprintf(name, "acpi_video%d", count++);
685 device->output_dev = video_output_register(name,
686 NULL, device, &acpi_output_properties);
694 * device : video output device (VGA)
699 * Find out all required AML methods defined under the video bus device.
702 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
704 acpi_handle h_dummy1;
706 memset(&video->cap, 0, sizeof(video->cap));
707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
716 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
719 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
722 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
728 * Check whether the video bus device has required AML method to
729 * support the desired features
732 static int acpi_video_bus_check(struct acpi_video_bus *video)
734 acpi_status status = -ENOENT;
740 /* Since there is no HID, CID and so on for VGA driver, we have
741 * to check well known required nodes.
744 /* Does this device support video switching? */
745 if (video->cap._DOS) {
746 video->flags.multihead = 1;
750 /* Does this device support retrieving a video ROM? */
751 if (video->cap._ROM) {
752 video->flags.rom = 1;
756 /* Does this device support configuring which video device to POST? */
757 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
758 video->flags.post = 1;
765 /* --------------------------------------------------------------------------
767 -------------------------------------------------------------------------- */
769 static struct proc_dir_entry *acpi_video_dir;
773 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
775 struct acpi_video_device *dev = seq->private;
781 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
782 seq_printf(seq, "type: ");
784 seq_printf(seq, "CRT\n");
785 else if (dev->flags.lcd)
786 seq_printf(seq, "LCD\n");
787 else if (dev->flags.tvout)
788 seq_printf(seq, "TVOUT\n");
789 else if (dev->flags.dvi)
790 seq_printf(seq, "DVI\n");
792 seq_printf(seq, "UNKNOWN\n");
794 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
801 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
803 return single_open(file, acpi_video_device_info_seq_show,
807 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
810 struct acpi_video_device *dev = seq->private;
817 status = acpi_video_device_get_state(dev, &state);
818 seq_printf(seq, "state: ");
819 if (ACPI_SUCCESS(status))
820 seq_printf(seq, "0x%02lx\n", state);
822 seq_printf(seq, "<not supported>\n");
824 status = acpi_video_device_query(dev, &state);
825 seq_printf(seq, "query: ");
826 if (ACPI_SUCCESS(status))
827 seq_printf(seq, "0x%02lx\n", state);
829 seq_printf(seq, "<not supported>\n");
836 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
838 return single_open(file, acpi_video_device_state_seq_show,
843 acpi_video_device_write_state(struct file *file,
844 const char __user * buffer,
845 size_t count, loff_t * data)
848 struct seq_file *m = file->private_data;
849 struct acpi_video_device *dev = m->private;
850 char str[12] = { 0 };
854 if (!dev || count + 1 > sizeof str)
857 if (copy_from_user(str, buffer, count))
861 state = simple_strtoul(str, NULL, 0);
862 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
864 status = acpi_video_device_set_state(dev, state);
873 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
875 struct acpi_video_device *dev = seq->private;
879 if (!dev || !dev->brightness) {
880 seq_printf(seq, "<not supported>\n");
884 seq_printf(seq, "levels: ");
885 for (i = 0; i < dev->brightness->count; i++)
886 seq_printf(seq, " %d", dev->brightness->levels[i]);
887 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
893 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
895 return single_open(file, acpi_video_device_brightness_seq_show,
900 acpi_video_device_write_brightness(struct file *file,
901 const char __user * buffer,
902 size_t count, loff_t * data)
904 struct seq_file *m = file->private_data;
905 struct acpi_video_device *dev = m->private;
907 unsigned int level = 0;
911 if (!dev || !dev->brightness || count + 1 > sizeof str)
914 if (copy_from_user(str, buffer, count))
918 level = simple_strtoul(str, NULL, 0);
923 /* validate through the list of available levels */
924 for (i = 0; i < dev->brightness->count; i++)
925 if (level == dev->brightness->levels[i]) {
927 (acpi_video_device_lcd_set_level(dev, level)))
928 dev->brightness->curr = level;
935 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
937 struct acpi_video_device *dev = seq->private;
940 union acpi_object *edid = NULL;
946 status = acpi_video_device_EDID(dev, &edid, 128);
947 if (ACPI_FAILURE(status)) {
948 status = acpi_video_device_EDID(dev, &edid, 256);
951 if (ACPI_FAILURE(status)) {
955 if (edid && edid->type == ACPI_TYPE_BUFFER) {
956 for (i = 0; i < edid->buffer.length; i++)
957 seq_putc(seq, edid->buffer.pointer[i]);
962 seq_printf(seq, "<not supported>\n");
970 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
972 return single_open(file, acpi_video_device_EDID_seq_show,
976 static int acpi_video_device_add_fs(struct acpi_device *device)
978 struct proc_dir_entry *entry = NULL;
979 struct acpi_video_device *vid_dev;
985 vid_dev = acpi_driver_data(device);
989 if (!acpi_device_dir(device)) {
990 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
991 vid_dev->video->dir);
992 if (!acpi_device_dir(device))
994 acpi_device_dir(device)->owner = THIS_MODULE;
998 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1002 entry->proc_fops = &acpi_video_device_info_fops;
1003 entry->data = acpi_driver_data(device);
1004 entry->owner = THIS_MODULE;
1009 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1010 acpi_device_dir(device));
1014 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1015 entry->proc_fops = &acpi_video_device_state_fops;
1016 entry->data = acpi_driver_data(device);
1017 entry->owner = THIS_MODULE;
1020 /* 'brightness' [R/W] */
1022 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1023 acpi_device_dir(device));
1027 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1028 entry->proc_fops = &acpi_video_device_brightness_fops;
1029 entry->data = acpi_driver_data(device);
1030 entry->owner = THIS_MODULE;
1034 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1038 entry->proc_fops = &acpi_video_device_EDID_fops;
1039 entry->data = acpi_driver_data(device);
1040 entry->owner = THIS_MODULE;
1046 static int acpi_video_device_remove_fs(struct acpi_device *device)
1048 struct acpi_video_device *vid_dev;
1050 vid_dev = acpi_driver_data(device);
1051 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1054 if (acpi_device_dir(device)) {
1055 remove_proc_entry("info", acpi_device_dir(device));
1056 remove_proc_entry("state", acpi_device_dir(device));
1057 remove_proc_entry("brightness", acpi_device_dir(device));
1058 remove_proc_entry("EDID", acpi_device_dir(device));
1059 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1060 acpi_device_dir(device) = NULL;
1067 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1069 struct acpi_video_bus *video = seq->private;
1075 seq_printf(seq, "Switching heads: %s\n",
1076 video->flags.multihead ? "yes" : "no");
1077 seq_printf(seq, "Video ROM: %s\n",
1078 video->flags.rom ? "yes" : "no");
1079 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1080 video->flags.post ? "yes" : "no");
1086 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1088 return single_open(file, acpi_video_bus_info_seq_show,
1092 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1094 struct acpi_video_bus *video = seq->private;
1100 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1101 seq_printf(seq, "<TODO>\n");
1107 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1109 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1112 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1114 struct acpi_video_bus *video = seq->private;
1115 unsigned long options;
1122 status = acpi_video_bus_POST_options(video, &options);
1123 if (ACPI_SUCCESS(status)) {
1124 if (!(options & 1)) {
1125 printk(KERN_WARNING PREFIX
1126 "The motherboard VGA device is not listed as a possible POST device.\n");
1127 printk(KERN_WARNING PREFIX
1128 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1130 printk("%lx\n", options);
1131 seq_printf(seq, "can POST: <integrated video>");
1133 seq_printf(seq, " <PCI video>");
1135 seq_printf(seq, " <AGP video>");
1136 seq_putc(seq, '\n');
1138 seq_printf(seq, "<not supported>\n");
1144 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1146 return single_open(file, acpi_video_bus_POST_info_seq_show,
1150 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1152 struct acpi_video_bus *video = seq->private;
1160 status = acpi_video_bus_get_POST(video, &id);
1161 if (!ACPI_SUCCESS(status)) {
1162 seq_printf(seq, "<not supported>\n");
1165 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1171 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1173 struct acpi_video_bus *video = seq->private;
1176 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1181 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1183 return single_open(file, acpi_video_bus_POST_seq_show,
1187 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1189 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1193 acpi_video_bus_write_POST(struct file *file,
1194 const char __user * buffer,
1195 size_t count, loff_t * data)
1198 struct seq_file *m = file->private_data;
1199 struct acpi_video_bus *video = m->private;
1200 char str[12] = { 0 };
1201 unsigned long opt, options;
1204 if (!video || count + 1 > sizeof str)
1207 status = acpi_video_bus_POST_options(video, &options);
1208 if (!ACPI_SUCCESS(status))
1211 if (copy_from_user(str, buffer, count))
1215 opt = strtoul(str, NULL, 0);
1219 /* just in case an OEM 'forgot' the motherboard... */
1222 if (options & (1ul << opt)) {
1223 status = acpi_video_bus_set_POST(video, opt);
1224 if (!ACPI_SUCCESS(status))
1233 acpi_video_bus_write_DOS(struct file *file,
1234 const char __user * buffer,
1235 size_t count, loff_t * data)
1238 struct seq_file *m = file->private_data;
1239 struct acpi_video_bus *video = m->private;
1240 char str[12] = { 0 };
1244 if (!video || count + 1 > sizeof str)
1247 if (copy_from_user(str, buffer, count))
1251 opt = strtoul(str, NULL, 0);
1255 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1257 if (!ACPI_SUCCESS(status))
1263 static int acpi_video_bus_add_fs(struct acpi_device *device)
1267 struct proc_dir_entry *entry = NULL;
1268 struct acpi_video_bus *video;
1272 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1274 if (!ACPI_SUCCESS(status))
1277 /* We need to attempt to determine whether the _ADR refers to a
1278 PCI device or not. There's no terribly good way to do this,
1279 so the best we can hope for is to assume that there'll never
1280 be a video device in the host bridge */
1281 if (device_id >= 0x10000) {
1282 /* It looks like a PCI device. Does it exist? */
1283 dev = acpi_get_physical_device(device->handle);
1285 /* It doesn't look like a PCI device. Does its parent
1287 acpi_handle phandle;
1288 if (acpi_get_parent(device->handle, &phandle))
1290 dev = acpi_get_physical_device(phandle);
1298 video = acpi_driver_data(device);
1300 if (!acpi_device_dir(device)) {
1301 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1303 if (!acpi_device_dir(device))
1305 video->dir = acpi_device_dir(device);
1306 acpi_device_dir(device)->owner = THIS_MODULE;
1310 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1314 entry->proc_fops = &acpi_video_bus_info_fops;
1315 entry->data = acpi_driver_data(device);
1316 entry->owner = THIS_MODULE;
1320 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1324 entry->proc_fops = &acpi_video_bus_ROM_fops;
1325 entry->data = acpi_driver_data(device);
1326 entry->owner = THIS_MODULE;
1329 /* 'POST_info' [R] */
1331 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1335 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1336 entry->data = acpi_driver_data(device);
1337 entry->owner = THIS_MODULE;
1342 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1343 acpi_device_dir(device));
1347 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1348 entry->proc_fops = &acpi_video_bus_POST_fops;
1349 entry->data = acpi_driver_data(device);
1350 entry->owner = THIS_MODULE;
1355 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1356 acpi_device_dir(device));
1360 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1361 entry->proc_fops = &acpi_video_bus_DOS_fops;
1362 entry->data = acpi_driver_data(device);
1363 entry->owner = THIS_MODULE;
1369 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1371 struct acpi_video_bus *video;
1374 video = acpi_driver_data(device);
1376 if (acpi_device_dir(device)) {
1377 remove_proc_entry("info", acpi_device_dir(device));
1378 remove_proc_entry("ROM", acpi_device_dir(device));
1379 remove_proc_entry("POST_info", acpi_device_dir(device));
1380 remove_proc_entry("POST", acpi_device_dir(device));
1381 remove_proc_entry("DOS", acpi_device_dir(device));
1382 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1383 acpi_device_dir(device) = NULL;
1389 /* --------------------------------------------------------------------------
1391 -------------------------------------------------------------------------- */
1393 /* device interface */
1394 static struct acpi_video_device_attrib*
1395 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1399 for(count = 0; count < video->attached_count; count++)
1400 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1401 return &(video->attached_array[count].value.attrib);
1406 acpi_video_bus_get_one_device(struct acpi_device *device,
1407 struct acpi_video_bus *video)
1409 unsigned long device_id;
1411 struct acpi_video_device *data;
1412 struct acpi_video_device_attrib* attribute;
1414 if (!device || !video)
1418 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1419 if (ACPI_SUCCESS(status)) {
1421 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1425 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1426 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1427 acpi_driver_data(device) = data;
1429 data->device_id = device_id;
1430 data->video = video;
1433 attribute = acpi_video_get_device_attr(video, device_id);
1435 if((attribute != NULL) && attribute->device_id_scheme) {
1436 switch (attribute->display_type) {
1437 case ACPI_VIDEO_DISPLAY_CRT:
1438 data->flags.crt = 1;
1440 case ACPI_VIDEO_DISPLAY_TV:
1441 data->flags.tvout = 1;
1443 case ACPI_VIDEO_DISPLAY_DVI:
1444 data->flags.dvi = 1;
1446 case ACPI_VIDEO_DISPLAY_LCD:
1447 data->flags.lcd = 1;
1450 data->flags.unknown = 1;
1453 if(attribute->bios_can_detect)
1454 data->flags.bios = 1;
1456 data->flags.unknown = 1;
1458 acpi_video_device_bind(video, data);
1459 acpi_video_device_find_cap(data);
1461 status = acpi_install_notify_handler(device->handle,
1463 acpi_video_device_notify,
1465 if (ACPI_FAILURE(status)) {
1466 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1467 "Error installing notify handler\n"));
1468 if(data->brightness)
1469 kfree(data->brightness->levels);
1470 kfree(data->brightness);
1475 mutex_lock(&video->device_list_lock);
1476 list_add_tail(&data->entry, &video->video_device_list);
1477 mutex_unlock(&video->device_list_lock);
1479 acpi_video_device_add_fs(device);
1489 * video : video bus device
1494 * Enumerate the video device list of the video bus,
1495 * bind the ids with the corresponding video devices
1496 * under the video bus.
1499 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1501 struct acpi_video_device *dev;
1503 mutex_lock(&video->device_list_lock);
1505 list_for_each_entry(dev, &video->video_device_list, entry)
1506 acpi_video_device_bind(video, dev);
1508 mutex_unlock(&video->device_list_lock);
1513 * video : video bus device
1514 * device : video output device under the video
1520 * Bind the ids with the corresponding video devices
1521 * under the video bus.
1525 acpi_video_device_bind(struct acpi_video_bus *video,
1526 struct acpi_video_device *device)
1530 #define IDS_VAL(i) video->attached_array[i].value.int_val
1531 #define IDS_BIND(i) video->attached_array[i].bind_info
1533 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1534 i < video->attached_count; i++) {
1535 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1536 IDS_BIND(i) = device;
1537 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1546 * video : video bus device
1551 * Call _DOD to enumerate all devices attached to display adapter
1555 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1560 struct acpi_video_enumerated_device *active_device_list;
1561 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1562 union acpi_object *dod = NULL;
1563 union acpi_object *obj;
1565 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1566 if (!ACPI_SUCCESS(status)) {
1567 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1571 dod = buffer.pointer;
1572 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1573 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1578 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1579 dod->package.count));
1581 active_device_list = kmalloc((1 +
1582 dod->package.count) *
1584 acpi_video_enumerated_device),
1587 if (!active_device_list) {
1593 for (i = 0; i < dod->package.count; i++) {
1594 obj = &dod->package.elements[i];
1596 if (obj->type != ACPI_TYPE_INTEGER) {
1597 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1598 active_device_list[i].value.int_val =
1599 ACPI_VIDEO_HEAD_INVALID;
1601 active_device_list[i].value.int_val = obj->integer.value;
1602 active_device_list[i].bind_info = NULL;
1603 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1604 (int)obj->integer.value));
1607 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1609 kfree(video->attached_array);
1611 video->attached_array = active_device_list;
1612 video->attached_count = count;
1614 kfree(buffer.pointer);
1620 * video : video bus device
1621 * event : notify event
1626 * 1. Find out the current active output device.
1627 * 2. Identify the next output device to switch to.
1628 * 3. call _DSS to do actual switch.
1631 static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1633 struct list_head *node;
1634 struct acpi_video_device *dev = NULL;
1635 struct acpi_video_device *dev_next = NULL;
1636 struct acpi_video_device *dev_prev = NULL;
1637 unsigned long state;
1640 mutex_lock(&video->device_list_lock);
1642 list_for_each(node, &video->video_device_list) {
1643 dev = container_of(node, struct acpi_video_device, entry);
1644 status = acpi_video_device_get_state(dev, &state);
1646 dev_next = container_of(node->next,
1647 struct acpi_video_device, entry);
1648 dev_prev = container_of(node->prev,
1649 struct acpi_video_device, entry);
1654 dev_next = container_of(node->next, struct acpi_video_device, entry);
1655 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1658 mutex_unlock(&video->device_list_lock);
1661 case ACPI_VIDEO_NOTIFY_CYCLE:
1662 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1663 acpi_video_device_set_state(dev, 0);
1664 acpi_video_device_set_state(dev_next, 0x80000001);
1666 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1667 acpi_video_device_set_state(dev, 0);
1668 acpi_video_device_set_state(dev_prev, 0x80000001);
1677 acpi_video_get_next_level(struct acpi_video_device *device,
1678 u32 level_current, u32 event)
1680 int min, max, min_above, max_below, i, l, delta = 255;
1681 max = max_below = 0;
1682 min = min_above = 255;
1683 /* Find closest level to level_current */
1684 for (i = 0; i < device->brightness->count; i++) {
1685 l = device->brightness->levels[i];
1686 if (abs(l - level_current) < abs(delta)) {
1687 delta = l - level_current;
1692 /* Ajust level_current to closest available level */
1693 level_current += delta;
1694 for (i = 0; i < device->brightness->count; i++) {
1695 l = device->brightness->levels[i];
1700 if (l < min_above && l > level_current)
1702 if (l > max_below && l < level_current)
1707 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1708 return (level_current < max) ? min_above : min;
1709 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1710 return (level_current < max) ? min_above : max;
1711 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1712 return (level_current > min) ? max_below : min;
1713 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1714 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1717 return level_current;
1722 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1724 unsigned long level_current, level_next;
1725 acpi_video_device_lcd_get_level_current(device, &level_current);
1726 level_next = acpi_video_get_next_level(device, level_current, event);
1727 acpi_video_device_lcd_set_level(device, level_next);
1731 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1732 struct acpi_device *device)
1735 struct acpi_device *dev;
1737 acpi_video_device_enumerate(video);
1739 list_for_each_entry(dev, &device->children, node) {
1741 status = acpi_video_bus_get_one_device(dev, video);
1742 if (ACPI_FAILURE(status)) {
1743 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1750 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1753 struct acpi_video_bus *video;
1756 if (!device || !device->video)
1759 video = device->video;
1761 acpi_video_device_remove_fs(device->dev);
1763 status = acpi_remove_notify_handler(device->dev->handle,
1765 acpi_video_device_notify);
1766 backlight_device_unregister(device->backlight);
1767 video_output_unregister(device->output_dev);
1772 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1775 struct acpi_video_device *dev, *next;
1777 mutex_lock(&video->device_list_lock);
1779 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1781 status = acpi_video_bus_put_one_device(dev);
1782 if (ACPI_FAILURE(status))
1783 printk(KERN_WARNING PREFIX
1784 "hhuuhhuu bug in acpi video driver.\n");
1786 if (dev->brightness) {
1787 kfree(dev->brightness->levels);
1788 kfree(dev->brightness);
1790 list_del(&dev->entry);
1794 mutex_unlock(&video->device_list_lock);
1799 /* acpi_video interface */
1801 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1803 return acpi_video_bus_DOS(video, 0, 0);
1806 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1808 return acpi_video_bus_DOS(video, 0, 1);
1811 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1813 struct acpi_video_bus *video = data;
1814 struct acpi_device *device = NULL;
1815 struct input_dev *input;
1821 device = video->device;
1822 input = video->input;
1825 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1826 * most likely via hotkey. */
1827 acpi_bus_generate_proc_event(device, event, 0);
1828 keycode = KEY_SWITCHVIDEOMODE;
1831 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1833 acpi_video_device_enumerate(video);
1834 acpi_video_device_rebind(video);
1835 acpi_video_switch_output(video, event);
1836 acpi_bus_generate_proc_event(device, event, 0);
1837 keycode = KEY_SWITCHVIDEOMODE;
1840 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1841 acpi_video_switch_output(video, event);
1842 acpi_bus_generate_proc_event(device, event, 0);
1843 keycode = KEY_SWITCHVIDEOMODE;
1845 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1846 acpi_video_switch_output(video, event);
1847 acpi_bus_generate_proc_event(device, event, 0);
1848 keycode = KEY_VIDEO_NEXT;
1850 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1851 acpi_video_switch_output(video, event);
1852 acpi_bus_generate_proc_event(device, event, 0);
1853 keycode = KEY_VIDEO_PREV;
1857 keycode = KEY_UNKNOWN;
1858 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1859 "Unsupported event [0x%x]\n", event));
1863 input_report_key(input, keycode, 1);
1865 input_report_key(input, keycode, 0);
1871 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1873 struct acpi_video_device *video_device = data;
1874 struct acpi_device *device = NULL;
1875 struct acpi_video_bus *bus;
1876 struct input_dev *input;
1882 device = video_device->dev;
1883 bus = video_device->video;
1887 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1888 acpi_video_switch_brightness(video_device, event);
1889 acpi_bus_generate_proc_event(device, event, 0);
1890 keycode = KEY_BRIGHTNESS_CYCLE;
1892 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1893 acpi_video_switch_brightness(video_device, event);
1894 acpi_bus_generate_proc_event(device, event, 0);
1895 keycode = KEY_BRIGHTNESSUP;
1897 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1898 acpi_video_switch_brightness(video_device, event);
1899 acpi_bus_generate_proc_event(device, event, 0);
1900 keycode = KEY_BRIGHTNESSDOWN;
1902 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1903 acpi_video_switch_brightness(video_device, event);
1904 acpi_bus_generate_proc_event(device, event, 0);
1905 keycode = KEY_BRIGHTNESS_ZERO;
1907 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1908 acpi_video_switch_brightness(video_device, event);
1909 acpi_bus_generate_proc_event(device, event, 0);
1910 keycode = KEY_DISPLAY_OFF;
1913 keycode = KEY_UNKNOWN;
1914 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1915 "Unsupported event [0x%x]\n", event));
1919 input_report_key(input, keycode, 1);
1921 input_report_key(input, keycode, 0);
1927 static int instance;
1928 static int acpi_video_bus_add(struct acpi_device *device)
1931 struct acpi_video_bus *video;
1932 struct input_dev *input;
1935 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1939 /* a hack to fix the duplicate name "VID" problem on T61 */
1940 if (!strcmp(device->pnp.bus_id, "VID")) {
1942 device->pnp.bus_id[3] = '0' + instance;
1946 video->device = device;
1947 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1948 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1949 acpi_driver_data(device) = video;
1951 acpi_video_bus_find_cap(video);
1952 error = acpi_video_bus_check(video);
1954 goto err_free_video;
1956 error = acpi_video_bus_add_fs(device);
1958 goto err_free_video;
1960 mutex_init(&video->device_list_lock);
1961 INIT_LIST_HEAD(&video->video_device_list);
1963 acpi_video_bus_get_devices(video, device);
1964 acpi_video_bus_start_devices(video);
1966 status = acpi_install_notify_handler(device->handle,
1968 acpi_video_bus_notify, video);
1969 if (ACPI_FAILURE(status)) {
1970 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1971 "Error installing notify handler\n"));
1973 goto err_stop_video;
1976 video->input = input = input_allocate_device();
1979 goto err_uninstall_notify;
1982 snprintf(video->phys, sizeof(video->phys),
1983 "%s/video/input0", acpi_device_hid(video->device));
1985 input->name = acpi_device_name(video->device);
1986 input->phys = video->phys;
1987 input->id.bustype = BUS_HOST;
1988 input->id.product = 0x06;
1989 input->dev.parent = &device->dev;
1990 input->evbit[0] = BIT(EV_KEY);
1991 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1992 set_bit(KEY_VIDEO_NEXT, input->keybit);
1993 set_bit(KEY_VIDEO_PREV, input->keybit);
1994 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1995 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1996 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1997 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1998 set_bit(KEY_DISPLAY_OFF, input->keybit);
1999 set_bit(KEY_UNKNOWN, input->keybit);
2001 error = input_register_device(input);
2003 goto err_free_input_dev;
2005 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2006 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2007 video->flags.multihead ? "yes" : "no",
2008 video->flags.rom ? "yes" : "no",
2009 video->flags.post ? "yes" : "no");
2014 input_free_device(input);
2015 err_uninstall_notify:
2016 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2017 acpi_video_bus_notify);
2019 acpi_video_bus_stop_devices(video);
2020 acpi_video_bus_put_devices(video);
2021 kfree(video->attached_array);
2022 acpi_video_bus_remove_fs(device);
2025 acpi_driver_data(device) = NULL;
2030 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2032 acpi_status status = 0;
2033 struct acpi_video_bus *video = NULL;
2036 if (!device || !acpi_driver_data(device))
2039 video = acpi_driver_data(device);
2041 acpi_video_bus_stop_devices(video);
2043 status = acpi_remove_notify_handler(video->device->handle,
2045 acpi_video_bus_notify);
2047 acpi_video_bus_put_devices(video);
2048 acpi_video_bus_remove_fs(device);
2050 input_unregister_device(video->input);
2051 kfree(video->attached_array);
2057 static int __init acpi_video_init(void)
2063 acpi_dbg_level = 0xFFFFFFFF;
2064 acpi_dbg_layer = 0x08000000;
2067 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2068 if (!acpi_video_dir)
2070 acpi_video_dir->owner = THIS_MODULE;
2072 result = acpi_bus_register_driver(&acpi_video_bus);
2074 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2081 static void __exit acpi_video_exit(void)
2084 acpi_bus_unregister_driver(&acpi_video_bus);
2086 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2091 module_init(acpi_video_init);
2092 module_exit(acpi_video_exit);