2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/thermal.h>
38 #include <linux/video_output.h>
39 #include <asm/uaccess.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
44 #define ACPI_VIDEO_COMPONENT 0x08000000
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device *device);
78 static int acpi_video_bus_remove(struct acpi_device *device, int type);
79 static int acpi_video_resume(struct acpi_device *device);
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,
94 .resume = acpi_video_resume,
98 struct acpi_video_bus_flags {
99 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
105 struct acpi_video_bus_cap {
106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
115 struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment:4; /*This field differentiates the display type */
118 u32 display_type:4; /*Describe the specific type in use */
119 u32 vendor_specific:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device {
131 struct acpi_video_device_attrib attrib;
133 struct acpi_video_device *bind_info;
136 struct acpi_video_bus {
137 struct acpi_device *device;
139 struct acpi_video_enumerated_device *attached_array;
141 struct acpi_video_bus_cap cap;
142 struct acpi_video_bus_flags flags;
143 struct list_head video_device_list;
144 struct mutex device_list_lock; /* protects video_device_list */
145 struct proc_dir_entry *dir;
146 struct input_dev *input;
147 char phys[32]; /* for input device */
150 struct acpi_video_device_flags {
160 struct acpi_video_device_cap {
161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
164 u8 _BQC:1; /* Get current brightness level */
165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
171 struct acpi_video_device_brightness {
177 struct acpi_video_device {
178 unsigned long device_id;
179 struct acpi_video_device_flags flags;
180 struct acpi_video_device_cap cap;
181 struct list_head entry;
182 struct acpi_video_bus *video;
183 struct acpi_device *dev;
184 struct acpi_video_device_brightness *brightness;
185 struct backlight_device *backlight;
186 struct thermal_cooling_device *cdev;
187 struct output_device *output_dev;
191 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192 static struct file_operations acpi_video_bus_info_fops = {
193 .open = acpi_video_bus_info_open_fs,
196 .release = single_release,
199 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
200 static struct file_operations acpi_video_bus_ROM_fops = {
201 .open = acpi_video_bus_ROM_open_fs,
204 .release = single_release,
207 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
209 static struct file_operations acpi_video_bus_POST_info_fops = {
210 .open = acpi_video_bus_POST_info_open_fs,
213 .release = single_release,
216 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
217 static struct file_operations acpi_video_bus_POST_fops = {
218 .open = acpi_video_bus_POST_open_fs,
221 .release = single_release,
224 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
225 static struct file_operations acpi_video_bus_DOS_fops = {
226 .open = acpi_video_bus_DOS_open_fs,
229 .release = single_release,
233 static int acpi_video_device_info_open_fs(struct inode *inode,
235 static struct file_operations acpi_video_device_info_fops = {
236 .open = acpi_video_device_info_open_fs,
239 .release = single_release,
242 static int acpi_video_device_state_open_fs(struct inode *inode,
244 static struct file_operations acpi_video_device_state_fops = {
245 .open = acpi_video_device_state_open_fs,
248 .release = single_release,
251 static int acpi_video_device_brightness_open_fs(struct inode *inode,
253 static struct file_operations acpi_video_device_brightness_fops = {
254 .open = acpi_video_device_brightness_open_fs,
257 .release = single_release,
260 static int acpi_video_device_EDID_open_fs(struct inode *inode,
262 static struct file_operations acpi_video_device_EDID_fops = {
263 .open = acpi_video_device_EDID_open_fs,
266 .release = single_release,
269 static char device_decode[][30] = {
270 "motherboard VGA device",
276 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
277 static void acpi_video_device_rebind(struct acpi_video_bus *video);
278 static void acpi_video_device_bind(struct acpi_video_bus *video,
279 struct acpi_video_device *device);
280 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
281 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
283 static int acpi_video_device_lcd_get_level_current(
284 struct acpi_video_device *device,
285 unsigned long *level);
286 static int acpi_video_get_next_level(struct acpi_video_device *device,
287 u32 level_current, u32 event);
288 static void acpi_video_switch_brightness(struct acpi_video_device *device,
290 static int acpi_video_device_get_state(struct acpi_video_device *device,
291 unsigned long *state);
292 static int acpi_video_output_get(struct output_device *od);
293 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
295 /*backlight device sysfs support*/
296 static int acpi_video_get_brightness(struct backlight_device *bd)
298 unsigned long cur_level;
300 struct acpi_video_device *vd =
301 (struct acpi_video_device *)bl_get_data(bd);
302 acpi_video_device_lcd_get_level_current(vd, &cur_level);
303 for (i = 2; i < vd->brightness->count; i++) {
304 if (vd->brightness->levels[i] == cur_level)
305 /* The first two entries are special - see page 575
306 of the ACPI spec 3.0 */
312 static int acpi_video_set_brightness(struct backlight_device *bd)
314 int request_level = bd->props.brightness+2;
315 struct acpi_video_device *vd =
316 (struct acpi_video_device *)bl_get_data(bd);
317 acpi_video_device_lcd_set_level(vd,
318 vd->brightness->levels[request_level]);
322 static struct backlight_ops acpi_backlight_ops = {
323 .get_brightness = acpi_video_get_brightness,
324 .update_status = acpi_video_set_brightness,
327 /*video output device sysfs support*/
328 static int acpi_video_output_get(struct output_device *od)
331 struct acpi_video_device *vd =
332 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
333 acpi_video_device_get_state(vd, &state);
337 static int acpi_video_output_set(struct output_device *od)
339 unsigned long state = od->request_state;
340 struct acpi_video_device *vd=
341 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
342 return acpi_video_device_set_state(vd, state);
345 static struct output_properties acpi_output_properties = {
346 .set_state = acpi_video_output_set,
347 .get_status = acpi_video_output_get,
351 /* thermal cooling device callbacks */
352 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
354 struct acpi_device *device = cdev->devdata;
355 struct acpi_video_device *video = acpi_driver_data(device);
357 return sprintf(buf, "%d\n", video->brightness->count - 3);
360 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
362 struct acpi_device *device = cdev->devdata;
363 struct acpi_video_device *video = acpi_driver_data(device);
367 acpi_video_device_lcd_get_level_current(video, &level);
368 for (state = 2; state < video->brightness->count; state++)
369 if (level == video->brightness->levels[state])
370 return sprintf(buf, "%d\n",
371 video->brightness->count - state - 1);
377 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
379 struct acpi_device *device = cdev->devdata;
380 struct acpi_video_device *video = acpi_driver_data(device);
383 if ( state >= video->brightness->count - 2)
386 state = video->brightness->count - state;
387 level = video->brightness->levels[state -1];
388 return acpi_video_device_lcd_set_level(video, level);
391 static struct thermal_cooling_device_ops video_cooling_ops = {
392 .get_max_state = video_get_max_state,
393 .get_cur_state = video_get_cur_state,
394 .set_cur_state = video_set_cur_state,
397 /* --------------------------------------------------------------------------
399 -------------------------------------------------------------------------- */
404 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
408 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
414 acpi_video_device_get_state(struct acpi_video_device *device,
415 unsigned long *state)
419 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
425 acpi_video_device_set_state(struct acpi_video_device *device, int state)
428 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
429 struct acpi_object_list args = { 1, &arg0 };
433 arg0.integer.value = state;
434 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
440 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
441 union acpi_object **levels)
444 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
445 union acpi_object *obj;
450 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
451 if (!ACPI_SUCCESS(status))
453 obj = (union acpi_object *)buffer.pointer;
454 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
455 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
465 kfree(buffer.pointer);
471 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
474 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
475 struct acpi_object_list args = { 1, &arg0 };
478 arg0.integer.value = level;
480 if (device->cap._BCM)
481 status = acpi_evaluate_object(device->dev->handle, "_BCM",
483 device->brightness->curr = level;
488 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
489 unsigned long *level)
491 if (device->cap._BQC)
492 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
494 *level = device->brightness->curr;
499 acpi_video_device_EDID(struct acpi_video_device *device,
500 union acpi_object **edid, ssize_t length)
503 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
504 union acpi_object *obj;
505 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
506 struct acpi_object_list args = { 1, &arg0 };
514 arg0.integer.value = 1;
515 else if (length == 256)
516 arg0.integer.value = 2;
520 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
521 if (ACPI_FAILURE(status))
524 obj = buffer.pointer;
526 if (obj && obj->type == ACPI_TYPE_BUFFER)
529 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
540 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
544 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
545 struct acpi_object_list args = { 1, &arg0 };
548 arg0.integer.value = option;
550 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
551 if (ACPI_SUCCESS(status))
552 status = tmp ? (-EINVAL) : (AE_OK);
558 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
562 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
568 acpi_video_bus_POST_options(struct acpi_video_bus *video,
569 unsigned long *options)
573 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
581 * video : video bus device pointer
583 * 0. The system BIOS should NOT automatically switch(toggle)
584 * the active display output.
585 * 1. The system BIOS should automatically switch (toggle) the
586 * active display output. No switch event.
587 * 2. The _DGS value should be locked.
588 * 3. The system BIOS should not automatically switch (toggle) the
589 * active display output, but instead generate the display switch
592 * 0. The system BIOS should automatically control the brightness level
593 * of the LCD when the power changes from AC to DC
594 * 1. The system BIOS should NOT automatically control the brightness
595 * level of the LCD when the power changes from AC to DC.
601 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
603 acpi_integer status = 0;
604 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
605 struct acpi_object_list args = { 1, &arg0 };
608 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
612 arg0.integer.value = (lcd_flag << 2) | bios_flag;
613 video->dos_setting = arg0.integer.value;
614 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
622 * device : video output device (LCD, CRT, ..)
627 * Find out all required AML methods defined under the output
631 static void acpi_video_device_find_cap(struct acpi_video_device *device)
633 acpi_handle h_dummy1;
636 union acpi_object *obj = NULL;
637 struct acpi_video_device_brightness *br = NULL;
640 memset(&device->cap, 0, sizeof(device->cap));
642 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
643 device->cap._ADR = 1;
645 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
646 device->cap._BCL = 1;
648 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
649 device->cap._BCM = 1;
651 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
652 device->cap._BQC = 1;
653 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
654 device->cap._DDC = 1;
656 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
657 device->cap._DCS = 1;
659 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
660 device->cap._DGS = 1;
662 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
663 device->cap._DSS = 1;
666 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
668 if (obj->package.count >= 2) {
670 union acpi_object *o;
672 br = kzalloc(sizeof(*br), GFP_KERNEL);
674 printk(KERN_ERR "can't allocate memory\n");
676 br->levels = kmalloc(obj->package.count *
677 sizeof *(br->levels), GFP_KERNEL);
681 for (i = 0; i < obj->package.count; i++) {
682 o = (union acpi_object *)&obj->package.
684 if (o->type != ACPI_TYPE_INTEGER) {
685 printk(KERN_ERR PREFIX "Invalid data\n");
688 br->levels[count] = (u32) o->integer.value;
690 if (br->levels[count] > max_level)
691 max_level = br->levels[count];
700 device->brightness = br;
701 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
702 "found %d brightness levels\n",
709 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
714 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
716 static int count = 0;
718 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
722 sprintf(name, "acpi_video%d", count++);
723 device->backlight = backlight_device_register(name,
724 NULL, device, &acpi_backlight_ops);
725 device->backlight->props.max_brightness = device->brightness->count-3;
726 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
727 backlight_update_status(device->backlight);
730 device->cdev = thermal_cooling_device_register("LCD",
731 device->dev, &video_cooling_ops);
732 if (IS_ERR(device->cdev))
735 printk(KERN_INFO PREFIX
736 "%s is registered as cooling_device%d\n",
737 device->dev->dev.bus_id, device->cdev->id);
738 result = sysfs_create_link(&device->dev->dev.kobj,
739 &device->cdev->device.kobj,
742 printk(KERN_ERR PREFIX "Create sysfs link\n");
743 result = sysfs_create_link(&device->cdev->device.kobj,
744 &device->dev->dev.kobj, "device");
746 printk(KERN_ERR PREFIX "Create sysfs link\n");
749 if (device->cap._DCS && device->cap._DSS){
750 static int count = 0;
752 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
755 sprintf(name, "acpi_video%d", count++);
756 device->output_dev = video_output_register(name,
757 NULL, device, &acpi_output_properties);
765 * device : video output device (VGA)
770 * Find out all required AML methods defined under the video bus device.
773 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
775 acpi_handle h_dummy1;
777 memset(&video->cap, 0, sizeof(video->cap));
778 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
781 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
784 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
787 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
790 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
793 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
799 * Check whether the video bus device has required AML method to
800 * support the desired features
803 static int acpi_video_bus_check(struct acpi_video_bus *video)
805 acpi_status status = -ENOENT;
811 /* Since there is no HID, CID and so on for VGA driver, we have
812 * to check well known required nodes.
815 /* Does this device support video switching? */
816 if (video->cap._DOS) {
817 video->flags.multihead = 1;
821 /* Does this device support retrieving a video ROM? */
822 if (video->cap._ROM) {
823 video->flags.rom = 1;
827 /* Does this device support configuring which video device to POST? */
828 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
829 video->flags.post = 1;
836 /* --------------------------------------------------------------------------
838 -------------------------------------------------------------------------- */
840 static struct proc_dir_entry *acpi_video_dir;
844 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
846 struct acpi_video_device *dev = seq->private;
852 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
853 seq_printf(seq, "type: ");
855 seq_printf(seq, "CRT\n");
856 else if (dev->flags.lcd)
857 seq_printf(seq, "LCD\n");
858 else if (dev->flags.tvout)
859 seq_printf(seq, "TVOUT\n");
860 else if (dev->flags.dvi)
861 seq_printf(seq, "DVI\n");
863 seq_printf(seq, "UNKNOWN\n");
865 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
872 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
874 return single_open(file, acpi_video_device_info_seq_show,
878 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
881 struct acpi_video_device *dev = seq->private;
888 status = acpi_video_device_get_state(dev, &state);
889 seq_printf(seq, "state: ");
890 if (ACPI_SUCCESS(status))
891 seq_printf(seq, "0x%02lx\n", state);
893 seq_printf(seq, "<not supported>\n");
895 status = acpi_video_device_query(dev, &state);
896 seq_printf(seq, "query: ");
897 if (ACPI_SUCCESS(status))
898 seq_printf(seq, "0x%02lx\n", state);
900 seq_printf(seq, "<not supported>\n");
907 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
909 return single_open(file, acpi_video_device_state_seq_show,
914 acpi_video_device_write_state(struct file *file,
915 const char __user * buffer,
916 size_t count, loff_t * data)
919 struct seq_file *m = file->private_data;
920 struct acpi_video_device *dev = m->private;
921 char str[12] = { 0 };
925 if (!dev || count + 1 > sizeof str)
928 if (copy_from_user(str, buffer, count))
932 state = simple_strtoul(str, NULL, 0);
933 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
935 status = acpi_video_device_set_state(dev, state);
944 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
946 struct acpi_video_device *dev = seq->private;
950 if (!dev || !dev->brightness) {
951 seq_printf(seq, "<not supported>\n");
955 seq_printf(seq, "levels: ");
956 for (i = 0; i < dev->brightness->count; i++)
957 seq_printf(seq, " %d", dev->brightness->levels[i]);
958 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
964 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
966 return single_open(file, acpi_video_device_brightness_seq_show,
971 acpi_video_device_write_brightness(struct file *file,
972 const char __user * buffer,
973 size_t count, loff_t * data)
975 struct seq_file *m = file->private_data;
976 struct acpi_video_device *dev = m->private;
978 unsigned int level = 0;
982 if (!dev || !dev->brightness || count + 1 > sizeof str)
985 if (copy_from_user(str, buffer, count))
989 level = simple_strtoul(str, NULL, 0);
994 /* validate through the list of available levels */
995 for (i = 0; i < dev->brightness->count; i++)
996 if (level == dev->brightness->levels[i]) {
998 (acpi_video_device_lcd_set_level(dev, level)))
999 dev->brightness->curr = level;
1006 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1008 struct acpi_video_device *dev = seq->private;
1011 union acpi_object *edid = NULL;
1017 status = acpi_video_device_EDID(dev, &edid, 128);
1018 if (ACPI_FAILURE(status)) {
1019 status = acpi_video_device_EDID(dev, &edid, 256);
1022 if (ACPI_FAILURE(status)) {
1026 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1027 for (i = 0; i < edid->buffer.length; i++)
1028 seq_putc(seq, edid->buffer.pointer[i]);
1033 seq_printf(seq, "<not supported>\n");
1041 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1043 return single_open(file, acpi_video_device_EDID_seq_show,
1047 static int acpi_video_device_add_fs(struct acpi_device *device)
1049 struct proc_dir_entry *entry, *device_dir;
1050 struct acpi_video_device *vid_dev;
1052 vid_dev = acpi_driver_data(device);
1056 device_dir = proc_mkdir(acpi_device_bid(device),
1057 vid_dev->video->dir);
1061 device_dir->owner = THIS_MODULE;
1064 entry = create_proc_entry("info", S_IRUGO, device_dir);
1066 goto err_remove_dir;
1068 entry->proc_fops = &acpi_video_device_info_fops;
1069 entry->data = acpi_driver_data(device);
1070 entry->owner = THIS_MODULE;
1073 entry = create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1076 goto err_remove_info;
1078 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1079 entry->proc_fops = &acpi_video_device_state_fops;
1080 entry->data = acpi_driver_data(device);
1081 entry->owner = THIS_MODULE;
1083 /* 'brightness' [R/W] */
1084 entry = create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1087 goto err_remove_state;
1089 acpi_video_device_brightness_fops.write =
1090 acpi_video_device_write_brightness;
1091 entry->proc_fops = &acpi_video_device_brightness_fops;
1092 entry->data = acpi_driver_data(device);
1093 entry->owner = THIS_MODULE;
1096 entry = create_proc_entry("EDID", S_IRUGO, device_dir);
1098 goto err_remove_brightness;
1100 entry->proc_fops = &acpi_video_device_EDID_fops;
1101 entry->data = acpi_driver_data(device);
1102 entry->owner = THIS_MODULE;
1104 acpi_device_dir(device) = device_dir;
1107 err_remove_brightness:
1108 remove_proc_entry("brightness", device_dir);
1110 remove_proc_entry("state", device_dir);
1112 remove_proc_entry("info", device_dir);
1114 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1118 static int acpi_video_device_remove_fs(struct acpi_device *device)
1120 struct acpi_video_device *vid_dev;
1121 struct proc_dir_entry *device_dir;
1123 vid_dev = acpi_driver_data(device);
1124 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1127 device_dir = acpi_device_dir(device);
1129 remove_proc_entry("info", device_dir);
1130 remove_proc_entry("state", device_dir);
1131 remove_proc_entry("brightness", device_dir);
1132 remove_proc_entry("EDID", device_dir);
1133 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1134 acpi_device_dir(device) = NULL;
1141 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1143 struct acpi_video_bus *video = seq->private;
1149 seq_printf(seq, "Switching heads: %s\n",
1150 video->flags.multihead ? "yes" : "no");
1151 seq_printf(seq, "Video ROM: %s\n",
1152 video->flags.rom ? "yes" : "no");
1153 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1154 video->flags.post ? "yes" : "no");
1160 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1162 return single_open(file, acpi_video_bus_info_seq_show,
1166 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1168 struct acpi_video_bus *video = seq->private;
1174 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1175 seq_printf(seq, "<TODO>\n");
1181 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1183 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1186 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1188 struct acpi_video_bus *video = seq->private;
1189 unsigned long options;
1196 status = acpi_video_bus_POST_options(video, &options);
1197 if (ACPI_SUCCESS(status)) {
1198 if (!(options & 1)) {
1199 printk(KERN_WARNING PREFIX
1200 "The motherboard VGA device is not listed as a possible POST device.\n");
1201 printk(KERN_WARNING PREFIX
1202 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1204 printk("%lx\n", options);
1205 seq_printf(seq, "can POST: <integrated video>");
1207 seq_printf(seq, " <PCI video>");
1209 seq_printf(seq, " <AGP video>");
1210 seq_putc(seq, '\n');
1212 seq_printf(seq, "<not supported>\n");
1218 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1220 return single_open(file, acpi_video_bus_POST_info_seq_show,
1224 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1226 struct acpi_video_bus *video = seq->private;
1234 status = acpi_video_bus_get_POST(video, &id);
1235 if (!ACPI_SUCCESS(status)) {
1236 seq_printf(seq, "<not supported>\n");
1239 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1245 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1247 struct acpi_video_bus *video = seq->private;
1250 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1255 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1257 return single_open(file, acpi_video_bus_POST_seq_show,
1261 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1263 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1267 acpi_video_bus_write_POST(struct file *file,
1268 const char __user * buffer,
1269 size_t count, loff_t * data)
1272 struct seq_file *m = file->private_data;
1273 struct acpi_video_bus *video = m->private;
1274 char str[12] = { 0 };
1275 unsigned long opt, options;
1278 if (!video || count + 1 > sizeof str)
1281 status = acpi_video_bus_POST_options(video, &options);
1282 if (!ACPI_SUCCESS(status))
1285 if (copy_from_user(str, buffer, count))
1289 opt = strtoul(str, NULL, 0);
1293 /* just in case an OEM 'forgot' the motherboard... */
1296 if (options & (1ul << opt)) {
1297 status = acpi_video_bus_set_POST(video, opt);
1298 if (!ACPI_SUCCESS(status))
1307 acpi_video_bus_write_DOS(struct file *file,
1308 const char __user * buffer,
1309 size_t count, loff_t * data)
1312 struct seq_file *m = file->private_data;
1313 struct acpi_video_bus *video = m->private;
1314 char str[12] = { 0 };
1318 if (!video || count + 1 > sizeof str)
1321 if (copy_from_user(str, buffer, count))
1325 opt = strtoul(str, NULL, 0);
1329 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1331 if (!ACPI_SUCCESS(status))
1337 static int acpi_video_bus_add_fs(struct acpi_device *device)
1339 struct acpi_video_bus *video = acpi_driver_data(device);
1340 struct proc_dir_entry *device_dir;
1341 struct proc_dir_entry *entry;
1343 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1347 device_dir->owner = THIS_MODULE;
1350 entry = create_proc_entry("info", S_IRUGO, device_dir);
1352 goto err_remove_dir;
1354 entry->proc_fops = &acpi_video_bus_info_fops;
1355 entry->data = acpi_driver_data(device);
1356 entry->owner = THIS_MODULE;
1359 entry = create_proc_entry("ROM", S_IRUGO, device_dir);
1361 goto err_remove_info;
1363 entry->proc_fops = &acpi_video_bus_ROM_fops;
1364 entry->data = acpi_driver_data(device);
1365 entry->owner = THIS_MODULE;
1367 /* 'POST_info' [R] */
1368 entry = create_proc_entry("POST_info", S_IRUGO, device_dir);
1370 goto err_remove_rom;
1372 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1373 entry->data = acpi_driver_data(device);
1374 entry->owner = THIS_MODULE;
1377 entry = create_proc_entry("POST", S_IFREG | S_IRUGO | S_IWUSR,
1380 goto err_remove_post_info;
1382 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1383 entry->proc_fops = &acpi_video_bus_POST_fops;
1384 entry->data = acpi_driver_data(device);
1385 entry->owner = THIS_MODULE;
1388 entry = create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1391 goto err_remove_post;
1393 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1394 entry->proc_fops = &acpi_video_bus_DOS_fops;
1395 entry->data = acpi_driver_data(device);
1396 entry->owner = THIS_MODULE;
1398 video->dir = acpi_device_dir(device) = device_dir;
1402 remove_proc_entry("POST", device_dir);
1403 err_remove_post_info:
1404 remove_proc_entry("POST_info", device_dir);
1406 remove_proc_entry("ROM", device_dir);
1408 remove_proc_entry("info", device_dir);
1410 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1414 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1416 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1419 remove_proc_entry("info", device_dir);
1420 remove_proc_entry("ROM", device_dir);
1421 remove_proc_entry("POST_info", device_dir);
1422 remove_proc_entry("POST", device_dir);
1423 remove_proc_entry("DOS", device_dir);
1424 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1425 acpi_device_dir(device) = NULL;
1431 /* --------------------------------------------------------------------------
1433 -------------------------------------------------------------------------- */
1435 /* device interface */
1436 static struct acpi_video_device_attrib*
1437 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1439 struct acpi_video_enumerated_device *ids;
1442 for (i = 0; i < video->attached_count; i++) {
1443 ids = &video->attached_array[i];
1444 if ((ids->value.int_val & 0xffff) == device_id)
1445 return &ids->value.attrib;
1452 acpi_video_bus_get_one_device(struct acpi_device *device,
1453 struct acpi_video_bus *video)
1455 unsigned long device_id;
1457 struct acpi_video_device *data;
1458 struct acpi_video_device_attrib* attribute;
1460 if (!device || !video)
1464 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1465 if (ACPI_SUCCESS(status)) {
1467 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1471 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1472 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1473 acpi_driver_data(device) = data;
1475 data->device_id = device_id;
1476 data->video = video;
1479 attribute = acpi_video_get_device_attr(video, device_id);
1481 if((attribute != NULL) && attribute->device_id_scheme) {
1482 switch (attribute->display_type) {
1483 case ACPI_VIDEO_DISPLAY_CRT:
1484 data->flags.crt = 1;
1486 case ACPI_VIDEO_DISPLAY_TV:
1487 data->flags.tvout = 1;
1489 case ACPI_VIDEO_DISPLAY_DVI:
1490 data->flags.dvi = 1;
1492 case ACPI_VIDEO_DISPLAY_LCD:
1493 data->flags.lcd = 1;
1496 data->flags.unknown = 1;
1499 if(attribute->bios_can_detect)
1500 data->flags.bios = 1;
1502 data->flags.unknown = 1;
1504 acpi_video_device_bind(video, data);
1505 acpi_video_device_find_cap(data);
1507 status = acpi_install_notify_handler(device->handle,
1509 acpi_video_device_notify,
1511 if (ACPI_FAILURE(status)) {
1512 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1513 "Error installing notify handler\n"));
1514 if(data->brightness)
1515 kfree(data->brightness->levels);
1516 kfree(data->brightness);
1521 mutex_lock(&video->device_list_lock);
1522 list_add_tail(&data->entry, &video->video_device_list);
1523 mutex_unlock(&video->device_list_lock);
1525 acpi_video_device_add_fs(device);
1535 * video : video bus device
1540 * Enumerate the video device list of the video bus,
1541 * bind the ids with the corresponding video devices
1542 * under the video bus.
1545 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1547 struct acpi_video_device *dev;
1549 mutex_lock(&video->device_list_lock);
1551 list_for_each_entry(dev, &video->video_device_list, entry)
1552 acpi_video_device_bind(video, dev);
1554 mutex_unlock(&video->device_list_lock);
1559 * video : video bus device
1560 * device : video output device under the video
1566 * Bind the ids with the corresponding video devices
1567 * under the video bus.
1571 acpi_video_device_bind(struct acpi_video_bus *video,
1572 struct acpi_video_device *device)
1574 struct acpi_video_enumerated_device *ids;
1577 for (i = 0; i < video->attached_count; i++) {
1578 ids = &video->attached_array[i];
1579 if (device->device_id == (ids->value.int_val & 0xffff)) {
1580 ids->bind_info = device;
1581 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1588 * video : video bus device
1593 * Call _DOD to enumerate all devices attached to display adapter
1597 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1602 struct acpi_video_enumerated_device *active_list;
1603 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1604 union acpi_object *dod = NULL;
1605 union acpi_object *obj;
1607 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1608 if (!ACPI_SUCCESS(status)) {
1609 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1613 dod = buffer.pointer;
1614 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1615 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1620 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1621 dod->package.count));
1623 active_list = kcalloc(1 + dod->package.count,
1624 sizeof(struct acpi_video_enumerated_device),
1632 for (i = 0; i < dod->package.count; i++) {
1633 obj = &dod->package.elements[i];
1635 if (obj->type != ACPI_TYPE_INTEGER) {
1636 printk(KERN_ERR PREFIX
1637 "Invalid _DOD data in element %d\n", i);
1641 active_list[count].value.int_val = obj->integer.value;
1642 active_list[count].bind_info = NULL;
1643 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1644 (int)obj->integer.value));
1648 kfree(video->attached_array);
1650 video->attached_array = active_list;
1651 video->attached_count = count;
1654 kfree(buffer.pointer);
1659 acpi_video_get_next_level(struct acpi_video_device *device,
1660 u32 level_current, u32 event)
1662 int min, max, min_above, max_below, i, l, delta = 255;
1663 max = max_below = 0;
1664 min = min_above = 255;
1665 /* Find closest level to level_current */
1666 for (i = 0; i < device->brightness->count; i++) {
1667 l = device->brightness->levels[i];
1668 if (abs(l - level_current) < abs(delta)) {
1669 delta = l - level_current;
1674 /* Ajust level_current to closest available level */
1675 level_current += delta;
1676 for (i = 0; i < device->brightness->count; i++) {
1677 l = device->brightness->levels[i];
1682 if (l < min_above && l > level_current)
1684 if (l > max_below && l < level_current)
1689 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1690 return (level_current < max) ? min_above : min;
1691 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1692 return (level_current < max) ? min_above : max;
1693 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1694 return (level_current > min) ? max_below : min;
1695 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1696 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1699 return level_current;
1704 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1706 unsigned long level_current, level_next;
1707 acpi_video_device_lcd_get_level_current(device, &level_current);
1708 level_next = acpi_video_get_next_level(device, level_current, event);
1709 acpi_video_device_lcd_set_level(device, level_next);
1713 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1714 struct acpi_device *device)
1717 struct acpi_device *dev;
1719 acpi_video_device_enumerate(video);
1721 list_for_each_entry(dev, &device->children, node) {
1723 status = acpi_video_bus_get_one_device(dev, video);
1724 if (ACPI_FAILURE(status)) {
1725 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1732 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1735 struct acpi_video_bus *video;
1738 if (!device || !device->video)
1741 video = device->video;
1743 acpi_video_device_remove_fs(device->dev);
1745 status = acpi_remove_notify_handler(device->dev->handle,
1747 acpi_video_device_notify);
1748 backlight_device_unregister(device->backlight);
1750 sysfs_remove_link(&device->dev->dev.kobj,
1752 sysfs_remove_link(&device->cdev->device.kobj,
1754 thermal_cooling_device_unregister(device->cdev);
1755 device->cdev = NULL;
1757 video_output_unregister(device->output_dev);
1762 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1765 struct acpi_video_device *dev, *next;
1767 mutex_lock(&video->device_list_lock);
1769 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1771 status = acpi_video_bus_put_one_device(dev);
1772 if (ACPI_FAILURE(status))
1773 printk(KERN_WARNING PREFIX
1774 "hhuuhhuu bug in acpi video driver.\n");
1776 if (dev->brightness) {
1777 kfree(dev->brightness->levels);
1778 kfree(dev->brightness);
1780 list_del(&dev->entry);
1784 mutex_unlock(&video->device_list_lock);
1789 /* acpi_video interface */
1791 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1793 return acpi_video_bus_DOS(video, 0, 0);
1796 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1798 return acpi_video_bus_DOS(video, 0, 1);
1801 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1803 struct acpi_video_bus *video = data;
1804 struct acpi_device *device = NULL;
1805 struct input_dev *input;
1811 device = video->device;
1812 input = video->input;
1815 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1816 * most likely via hotkey. */
1817 acpi_bus_generate_proc_event(device, event, 0);
1818 keycode = KEY_SWITCHVIDEOMODE;
1821 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1823 acpi_video_device_enumerate(video);
1824 acpi_video_device_rebind(video);
1825 acpi_bus_generate_proc_event(device, event, 0);
1826 keycode = KEY_SWITCHVIDEOMODE;
1829 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1830 acpi_bus_generate_proc_event(device, event, 0);
1831 keycode = KEY_SWITCHVIDEOMODE;
1833 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1834 acpi_bus_generate_proc_event(device, event, 0);
1835 keycode = KEY_VIDEO_NEXT;
1837 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1838 acpi_bus_generate_proc_event(device, event, 0);
1839 keycode = KEY_VIDEO_PREV;
1843 keycode = KEY_UNKNOWN;
1844 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1845 "Unsupported event [0x%x]\n", event));
1849 acpi_notifier_call_chain(device, event, 0);
1850 input_report_key(input, keycode, 1);
1852 input_report_key(input, keycode, 0);
1858 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1860 struct acpi_video_device *video_device = data;
1861 struct acpi_device *device = NULL;
1862 struct acpi_video_bus *bus;
1863 struct input_dev *input;
1869 device = video_device->dev;
1870 bus = video_device->video;
1874 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1875 if (brightness_switch_enabled)
1876 acpi_video_switch_brightness(video_device, event);
1877 acpi_bus_generate_proc_event(device, event, 0);
1878 keycode = KEY_BRIGHTNESS_CYCLE;
1880 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1881 if (brightness_switch_enabled)
1882 acpi_video_switch_brightness(video_device, event);
1883 acpi_bus_generate_proc_event(device, event, 0);
1884 keycode = KEY_BRIGHTNESSUP;
1886 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1887 if (brightness_switch_enabled)
1888 acpi_video_switch_brightness(video_device, event);
1889 acpi_bus_generate_proc_event(device, event, 0);
1890 keycode = KEY_BRIGHTNESSDOWN;
1892 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1893 if (brightness_switch_enabled)
1894 acpi_video_switch_brightness(video_device, event);
1895 acpi_bus_generate_proc_event(device, event, 0);
1896 keycode = KEY_BRIGHTNESS_ZERO;
1898 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1899 if (brightness_switch_enabled)
1900 acpi_video_switch_brightness(video_device, event);
1901 acpi_bus_generate_proc_event(device, event, 0);
1902 keycode = KEY_DISPLAY_OFF;
1905 keycode = KEY_UNKNOWN;
1906 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1907 "Unsupported event [0x%x]\n", event));
1911 acpi_notifier_call_chain(device, event, 0);
1912 input_report_key(input, keycode, 1);
1914 input_report_key(input, keycode, 0);
1920 static int instance;
1921 static int acpi_video_resume(struct acpi_device *device)
1923 struct acpi_video_bus *video;
1924 struct acpi_video_device *video_device;
1927 if (!device || !acpi_driver_data(device))
1930 video = acpi_driver_data(device);
1932 for (i = 0; i < video->attached_count; i++) {
1933 video_device = video->attached_array[i].bind_info;
1934 if (video_device && video_device->backlight)
1935 acpi_video_set_brightness(video_device->backlight);
1940 static int acpi_video_bus_add(struct acpi_device *device)
1943 struct acpi_video_bus *video;
1944 struct input_dev *input;
1947 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1951 /* a hack to fix the duplicate name "VID" problem on T61 */
1952 if (!strcmp(device->pnp.bus_id, "VID")) {
1954 device->pnp.bus_id[3] = '0' + instance;
1958 video->device = device;
1959 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1960 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1961 acpi_driver_data(device) = video;
1963 acpi_video_bus_find_cap(video);
1964 error = acpi_video_bus_check(video);
1966 goto err_free_video;
1968 error = acpi_video_bus_add_fs(device);
1970 goto err_free_video;
1972 mutex_init(&video->device_list_lock);
1973 INIT_LIST_HEAD(&video->video_device_list);
1975 acpi_video_bus_get_devices(video, device);
1976 acpi_video_bus_start_devices(video);
1978 status = acpi_install_notify_handler(device->handle,
1980 acpi_video_bus_notify, video);
1981 if (ACPI_FAILURE(status)) {
1982 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1983 "Error installing notify handler\n"));
1985 goto err_stop_video;
1988 video->input = input = input_allocate_device();
1991 goto err_uninstall_notify;
1994 snprintf(video->phys, sizeof(video->phys),
1995 "%s/video/input0", acpi_device_hid(video->device));
1997 input->name = acpi_device_name(video->device);
1998 input->phys = video->phys;
1999 input->id.bustype = BUS_HOST;
2000 input->id.product = 0x06;
2001 input->dev.parent = &device->dev;
2002 input->evbit[0] = BIT(EV_KEY);
2003 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2004 set_bit(KEY_VIDEO_NEXT, input->keybit);
2005 set_bit(KEY_VIDEO_PREV, input->keybit);
2006 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2007 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2008 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2009 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2010 set_bit(KEY_DISPLAY_OFF, input->keybit);
2011 set_bit(KEY_UNKNOWN, input->keybit);
2013 error = input_register_device(input);
2015 goto err_free_input_dev;
2017 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2018 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2019 video->flags.multihead ? "yes" : "no",
2020 video->flags.rom ? "yes" : "no",
2021 video->flags.post ? "yes" : "no");
2026 input_free_device(input);
2027 err_uninstall_notify:
2028 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2029 acpi_video_bus_notify);
2031 acpi_video_bus_stop_devices(video);
2032 acpi_video_bus_put_devices(video);
2033 kfree(video->attached_array);
2034 acpi_video_bus_remove_fs(device);
2037 acpi_driver_data(device) = NULL;
2042 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2044 acpi_status status = 0;
2045 struct acpi_video_bus *video = NULL;
2048 if (!device || !acpi_driver_data(device))
2051 video = acpi_driver_data(device);
2053 acpi_video_bus_stop_devices(video);
2055 status = acpi_remove_notify_handler(video->device->handle,
2057 acpi_video_bus_notify);
2059 acpi_video_bus_put_devices(video);
2060 acpi_video_bus_remove_fs(device);
2062 input_unregister_device(video->input);
2063 kfree(video->attached_array);
2069 static int __init acpi_video_init(void)
2075 acpi_dbg_level = 0xFFFFFFFF;
2076 acpi_dbg_layer = 0x08000000;
2079 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2080 if (!acpi_video_dir)
2082 acpi_video_dir->owner = THIS_MODULE;
2084 result = acpi_bus_register_driver(&acpi_video_bus);
2086 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2093 static void __exit acpi_video_exit(void)
2096 acpi_bus_unregister_driver(&acpi_video_bus);
2098 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2103 module_init(acpi_video_init);
2104 module_exit(acpi_video_exit);