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_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 MAX_NAME_LEN 20
61 #define ACPI_VIDEO_DISPLAY_CRT 1
62 #define ACPI_VIDEO_DISPLAY_TV 2
63 #define ACPI_VIDEO_DISPLAY_DVI 3
64 #define ACPI_VIDEO_DISPLAY_LCD 4
66 #define _COMPONENT ACPI_VIDEO_COMPONENT
67 ACPI_MODULE_NAME("video");
69 MODULE_AUTHOR("Bruno Ducrot");
70 MODULE_DESCRIPTION("ACPI Video Driver");
71 MODULE_LICENSE("GPL");
73 static int brightness_switch_enabled = 1;
74 module_param(brightness_switch_enabled, bool, 0644);
76 static int acpi_video_bus_add(struct acpi_device *device);
77 static int acpi_video_bus_remove(struct acpi_device *device, int type);
78 static int acpi_video_resume(struct acpi_device *device);
80 static const struct acpi_device_id video_device_ids[] = {
84 MODULE_DEVICE_TABLE(acpi, video_device_ids);
86 static struct acpi_driver acpi_video_bus = {
88 .class = ACPI_VIDEO_CLASS,
89 .ids = video_device_ids,
91 .add = acpi_video_bus_add,
92 .remove = acpi_video_bus_remove,
93 .resume = acpi_video_resume,
97 struct acpi_video_bus_flags {
98 u8 multihead:1; /* can switch video heads */
99 u8 rom:1; /* can retrieve a video rom */
100 u8 post:1; /* can configure the head to */
104 struct acpi_video_bus_cap {
105 u8 _DOS:1; /*Enable/Disable output switching */
106 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
107 u8 _ROM:1; /*Get ROM Data */
108 u8 _GPD:1; /*Get POST Device */
109 u8 _SPD:1; /*Set POST Device */
110 u8 _VPO:1; /*Video POST Options */
114 struct acpi_video_device_attrib {
115 u32 display_index:4; /* A zero-based instance of the Display */
116 u32 display_port_attachment:4; /*This field differentiates the display type */
117 u32 display_type:4; /*Describe the specific type in use */
118 u32 vendor_specific:4; /*Chipset Vendor Specific */
119 u32 bios_can_detect:1; /*BIOS can detect the device */
120 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
122 u32 pipe_id:3; /*For VGA multiple-head devices. */
123 u32 reserved:10; /*Must be 0 */
124 u32 device_id_scheme:1; /*Device ID Scheme */
127 struct acpi_video_enumerated_device {
130 struct acpi_video_device_attrib attrib;
132 struct acpi_video_device *bind_info;
135 struct acpi_video_bus {
136 struct acpi_device *device;
138 struct acpi_video_enumerated_device *attached_array;
140 struct acpi_video_bus_cap cap;
141 struct acpi_video_bus_flags flags;
142 struct list_head video_device_list;
143 struct mutex device_list_lock; /* protects video_device_list */
144 struct proc_dir_entry *dir;
145 struct input_dev *input;
146 char phys[32]; /* for input device */
149 struct acpi_video_device_flags {
159 struct acpi_video_device_cap {
160 u8 _ADR:1; /*Return the unique ID */
161 u8 _BCL:1; /*Query list of brightness control levels supported */
162 u8 _BCM:1; /*Set the brightness level */
163 u8 _BQC:1; /* Get current brightness level */
164 u8 _DDC:1; /*Return the EDID for this device */
165 u8 _DCS:1; /*Return status of output device */
166 u8 _DGS:1; /*Query graphics state */
167 u8 _DSS:1; /*Device state set */
170 struct acpi_video_device_brightness {
176 struct acpi_video_device {
177 unsigned long device_id;
178 struct acpi_video_device_flags flags;
179 struct acpi_video_device_cap cap;
180 struct list_head entry;
181 struct acpi_video_bus *video;
182 struct acpi_device *dev;
183 struct acpi_video_device_brightness *brightness;
184 struct backlight_device *backlight;
185 struct thermal_cooling_device *cdev;
186 struct output_device *output_dev;
190 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
191 static struct file_operations acpi_video_bus_info_fops = {
192 .owner = THIS_MODULE,
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 .owner = THIS_MODULE,
202 .open = acpi_video_bus_ROM_open_fs,
205 .release = single_release,
208 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210 static struct file_operations acpi_video_bus_POST_info_fops = {
211 .owner = THIS_MODULE,
212 .open = acpi_video_bus_POST_info_open_fs,
215 .release = single_release,
218 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
219 static struct file_operations acpi_video_bus_POST_fops = {
220 .owner = THIS_MODULE,
221 .open = acpi_video_bus_POST_open_fs,
224 .release = single_release,
227 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
228 static struct file_operations acpi_video_bus_DOS_fops = {
229 .owner = THIS_MODULE,
230 .open = acpi_video_bus_DOS_open_fs,
233 .release = single_release,
237 static int acpi_video_device_info_open_fs(struct inode *inode,
239 static struct file_operations acpi_video_device_info_fops = {
240 .owner = THIS_MODULE,
241 .open = acpi_video_device_info_open_fs,
244 .release = single_release,
247 static int acpi_video_device_state_open_fs(struct inode *inode,
249 static struct file_operations acpi_video_device_state_fops = {
250 .owner = THIS_MODULE,
251 .open = acpi_video_device_state_open_fs,
254 .release = single_release,
257 static int acpi_video_device_brightness_open_fs(struct inode *inode,
259 static struct file_operations acpi_video_device_brightness_fops = {
260 .owner = THIS_MODULE,
261 .open = acpi_video_device_brightness_open_fs,
264 .release = single_release,
267 static int acpi_video_device_EDID_open_fs(struct inode *inode,
269 static struct file_operations acpi_video_device_EDID_fops = {
270 .owner = THIS_MODULE,
271 .open = acpi_video_device_EDID_open_fs,
274 .release = single_release,
277 static char device_decode[][30] = {
278 "motherboard VGA device",
284 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
285 static void acpi_video_device_rebind(struct acpi_video_bus *video);
286 static void acpi_video_device_bind(struct acpi_video_bus *video,
287 struct acpi_video_device *device);
288 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
289 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
291 static int acpi_video_device_lcd_get_level_current(
292 struct acpi_video_device *device,
293 unsigned long long *level);
294 static int acpi_video_get_next_level(struct acpi_video_device *device,
295 u32 level_current, u32 event);
296 static void acpi_video_switch_brightness(struct acpi_video_device *device,
298 static int acpi_video_device_get_state(struct acpi_video_device *device,
299 unsigned long long *state);
300 static int acpi_video_output_get(struct output_device *od);
301 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
303 /*backlight device sysfs support*/
304 static int acpi_video_get_brightness(struct backlight_device *bd)
306 unsigned long long cur_level;
308 struct acpi_video_device *vd =
309 (struct acpi_video_device *)bl_get_data(bd);
310 acpi_video_device_lcd_get_level_current(vd, &cur_level);
311 for (i = 2; i < vd->brightness->count; i++) {
312 if (vd->brightness->levels[i] == cur_level)
313 /* The first two entries are special - see page 575
314 of the ACPI spec 3.0 */
320 static int acpi_video_set_brightness(struct backlight_device *bd)
322 int request_level = bd->props.brightness+2;
323 struct acpi_video_device *vd =
324 (struct acpi_video_device *)bl_get_data(bd);
325 acpi_video_device_lcd_set_level(vd,
326 vd->brightness->levels[request_level]);
330 static struct backlight_ops acpi_backlight_ops = {
331 .get_brightness = acpi_video_get_brightness,
332 .update_status = acpi_video_set_brightness,
335 /*video output device sysfs support*/
336 static int acpi_video_output_get(struct output_device *od)
338 unsigned long long state;
339 struct acpi_video_device *vd =
340 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
341 acpi_video_device_get_state(vd, &state);
345 static int acpi_video_output_set(struct output_device *od)
347 unsigned long state = od->request_state;
348 struct acpi_video_device *vd=
349 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
350 return acpi_video_device_set_state(vd, state);
353 static struct output_properties acpi_output_properties = {
354 .set_state = acpi_video_output_set,
355 .get_status = acpi_video_output_get,
359 /* thermal cooling device callbacks */
360 static int video_get_max_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);
365 return sprintf(buf, "%d\n", video->brightness->count - 3);
368 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
370 struct acpi_device *device = cdev->devdata;
371 struct acpi_video_device *video = acpi_driver_data(device);
372 unsigned long long level;
375 acpi_video_device_lcd_get_level_current(video, &level);
376 for (state = 2; state < video->brightness->count; state++)
377 if (level == video->brightness->levels[state])
378 return sprintf(buf, "%d\n",
379 video->brightness->count - state - 1);
385 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
387 struct acpi_device *device = cdev->devdata;
388 struct acpi_video_device *video = acpi_driver_data(device);
391 if ( state >= video->brightness->count - 2)
394 state = video->brightness->count - state;
395 level = video->brightness->levels[state -1];
396 return acpi_video_device_lcd_set_level(video, level);
399 static struct thermal_cooling_device_ops video_cooling_ops = {
400 .get_max_state = video_get_max_state,
401 .get_cur_state = video_get_cur_state,
402 .set_cur_state = video_set_cur_state,
405 /* --------------------------------------------------------------------------
407 -------------------------------------------------------------------------- */
412 acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
416 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
422 acpi_video_device_get_state(struct acpi_video_device *device,
423 unsigned long long *state)
427 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
433 acpi_video_device_set_state(struct acpi_video_device *device, int state)
436 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
437 struct acpi_object_list args = { 1, &arg0 };
438 unsigned long long ret;
441 arg0.integer.value = state;
442 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
448 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
449 union acpi_object **levels)
452 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
453 union acpi_object *obj;
458 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
459 if (!ACPI_SUCCESS(status))
461 obj = (union acpi_object *)buffer.pointer;
462 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
463 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
473 kfree(buffer.pointer);
479 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
482 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
483 struct acpi_object_list args = { 1, &arg0 };
486 arg0.integer.value = level;
488 if (device->cap._BCM)
489 status = acpi_evaluate_object(device->dev->handle, "_BCM",
491 device->brightness->curr = level;
496 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
497 unsigned long long *level)
499 if (device->cap._BQC)
500 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
502 *level = device->brightness->curr;
507 acpi_video_device_EDID(struct acpi_video_device *device,
508 union acpi_object **edid, ssize_t length)
511 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
512 union acpi_object *obj;
513 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
514 struct acpi_object_list args = { 1, &arg0 };
522 arg0.integer.value = 1;
523 else if (length == 256)
524 arg0.integer.value = 2;
528 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
529 if (ACPI_FAILURE(status))
532 obj = buffer.pointer;
534 if (obj && obj->type == ACPI_TYPE_BUFFER)
537 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
548 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
551 unsigned long long tmp;
552 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
553 struct acpi_object_list args = { 1, &arg0 };
556 arg0.integer.value = option;
558 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
559 if (ACPI_SUCCESS(status))
560 status = tmp ? (-EINVAL) : (AE_OK);
566 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
570 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
576 acpi_video_bus_POST_options(struct acpi_video_bus *video,
577 unsigned long long *options)
581 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
589 * video : video bus device pointer
591 * 0. The system BIOS should NOT automatically switch(toggle)
592 * the active display output.
593 * 1. The system BIOS should automatically switch (toggle) the
594 * active display output. No switch event.
595 * 2. The _DGS value should be locked.
596 * 3. The system BIOS should not automatically switch (toggle) the
597 * active display output, but instead generate the display switch
600 * 0. The system BIOS should automatically control the brightness level
601 * of the LCD when the power changes from AC to DC
602 * 1. The system BIOS should NOT automatically control the brightness
603 * level of the LCD when the power changes from AC to DC.
609 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
611 acpi_integer status = 0;
612 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
613 struct acpi_object_list args = { 1, &arg0 };
616 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
620 arg0.integer.value = (lcd_flag << 2) | bios_flag;
621 video->dos_setting = arg0.integer.value;
622 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
630 * device : video output device (LCD, CRT, ..)
633 * Maximum brightness level
635 * Allocate and initialize device->brightness.
639 acpi_video_init_brightness(struct acpi_video_device *device)
641 union acpi_object *obj = NULL;
642 int i, max_level = 0, count = 0;
643 union acpi_object *o;
644 struct acpi_video_device_brightness *br = NULL;
646 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
647 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
648 "LCD brightness level\n"));
652 if (obj->package.count < 2)
655 br = kzalloc(sizeof(*br), GFP_KERNEL);
657 printk(KERN_ERR "can't allocate memory\n");
661 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
666 for (i = 0; i < obj->package.count; i++) {
667 o = (union acpi_object *)&obj->package.elements[i];
668 if (o->type != ACPI_TYPE_INTEGER) {
669 printk(KERN_ERR PREFIX "Invalid data\n");
672 br->levels[count] = (u32) o->integer.value;
674 if (br->levels[count] > max_level)
675 max_level = br->levels[count];
680 goto out_free_levels;
683 device->brightness = br;
684 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
693 device->brightness = NULL;
700 * device : video output device (LCD, CRT, ..)
705 * Find out all required AML methods defined under the output
709 static void acpi_video_device_find_cap(struct acpi_video_device *device)
711 acpi_handle h_dummy1;
715 memset(&device->cap, 0, sizeof(device->cap));
717 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
718 device->cap._ADR = 1;
720 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
721 device->cap._BCL = 1;
723 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
724 device->cap._BCM = 1;
726 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
727 device->cap._BQC = 1;
728 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
729 device->cap._DDC = 1;
731 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
732 device->cap._DCS = 1;
734 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
735 device->cap._DGS = 1;
737 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
738 device->cap._DSS = 1;
741 max_level = acpi_video_init_brightness(device);
743 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
745 static int count = 0;
747 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
751 sprintf(name, "acpi_video%d", count++);
752 device->backlight = backlight_device_register(name,
753 NULL, device, &acpi_backlight_ops);
754 device->backlight->props.max_brightness = device->brightness->count-3;
756 * If there exists the _BQC object, the _BQC object will be
757 * called to get the current backlight brightness. Otherwise
758 * the brightness will be set to the maximum.
760 if (device->cap._BQC)
761 device->backlight->props.brightness =
762 acpi_video_get_brightness(device->backlight);
764 device->backlight->props.brightness =
765 device->backlight->props.max_brightness;
766 backlight_update_status(device->backlight);
769 device->cdev = thermal_cooling_device_register("LCD",
770 device->dev, &video_cooling_ops);
771 if (IS_ERR(device->cdev))
774 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
776 result = sysfs_create_link(&device->dev->dev.kobj,
777 &device->cdev->device.kobj,
780 printk(KERN_ERR PREFIX "Create sysfs link\n");
781 result = sysfs_create_link(&device->cdev->device.kobj,
782 &device->dev->dev.kobj, "device");
784 printk(KERN_ERR PREFIX "Create sysfs link\n");
787 if (device->cap._DCS && device->cap._DSS){
788 static int count = 0;
790 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
793 sprintf(name, "acpi_video%d", count++);
794 device->output_dev = video_output_register(name,
795 NULL, device, &acpi_output_properties);
803 * device : video output device (VGA)
808 * Find out all required AML methods defined under the video bus device.
811 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
813 acpi_handle h_dummy1;
815 memset(&video->cap, 0, sizeof(video->cap));
816 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
819 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
822 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
825 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
828 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
831 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
837 * Check whether the video bus device has required AML method to
838 * support the desired features
841 static int acpi_video_bus_check(struct acpi_video_bus *video)
843 acpi_status status = -ENOENT;
849 /* Since there is no HID, CID and so on for VGA driver, we have
850 * to check well known required nodes.
853 /* Does this device support video switching? */
854 if (video->cap._DOS) {
855 video->flags.multihead = 1;
859 /* Does this device support retrieving a video ROM? */
860 if (video->cap._ROM) {
861 video->flags.rom = 1;
865 /* Does this device support configuring which video device to POST? */
866 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
867 video->flags.post = 1;
874 /* --------------------------------------------------------------------------
876 -------------------------------------------------------------------------- */
878 static struct proc_dir_entry *acpi_video_dir;
882 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
884 struct acpi_video_device *dev = seq->private;
890 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
891 seq_printf(seq, "type: ");
893 seq_printf(seq, "CRT\n");
894 else if (dev->flags.lcd)
895 seq_printf(seq, "LCD\n");
896 else if (dev->flags.tvout)
897 seq_printf(seq, "TVOUT\n");
898 else if (dev->flags.dvi)
899 seq_printf(seq, "DVI\n");
901 seq_printf(seq, "UNKNOWN\n");
903 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
910 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
912 return single_open(file, acpi_video_device_info_seq_show,
916 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
919 struct acpi_video_device *dev = seq->private;
920 unsigned long long state;
926 status = acpi_video_device_get_state(dev, &state);
927 seq_printf(seq, "state: ");
928 if (ACPI_SUCCESS(status))
929 seq_printf(seq, "0x%02llx\n", state);
931 seq_printf(seq, "<not supported>\n");
933 status = acpi_video_device_query(dev, &state);
934 seq_printf(seq, "query: ");
935 if (ACPI_SUCCESS(status))
936 seq_printf(seq, "0x%02llx\n", state);
938 seq_printf(seq, "<not supported>\n");
945 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
947 return single_open(file, acpi_video_device_state_seq_show,
952 acpi_video_device_write_state(struct file *file,
953 const char __user * buffer,
954 size_t count, loff_t * data)
957 struct seq_file *m = file->private_data;
958 struct acpi_video_device *dev = m->private;
959 char str[12] = { 0 };
963 if (!dev || count + 1 > sizeof str)
966 if (copy_from_user(str, buffer, count))
970 state = simple_strtoul(str, NULL, 0);
971 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
973 status = acpi_video_device_set_state(dev, state);
982 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
984 struct acpi_video_device *dev = seq->private;
988 if (!dev || !dev->brightness) {
989 seq_printf(seq, "<not supported>\n");
993 seq_printf(seq, "levels: ");
994 for (i = 0; i < dev->brightness->count; i++)
995 seq_printf(seq, " %d", dev->brightness->levels[i]);
996 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1002 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1004 return single_open(file, acpi_video_device_brightness_seq_show,
1009 acpi_video_device_write_brightness(struct file *file,
1010 const char __user * buffer,
1011 size_t count, loff_t * data)
1013 struct seq_file *m = file->private_data;
1014 struct acpi_video_device *dev = m->private;
1015 char str[5] = { 0 };
1016 unsigned int level = 0;
1020 if (!dev || !dev->brightness || count + 1 > sizeof str)
1023 if (copy_from_user(str, buffer, count))
1027 level = simple_strtoul(str, NULL, 0);
1032 /* validate through the list of available levels */
1033 for (i = 0; i < dev->brightness->count; i++)
1034 if (level == dev->brightness->levels[i]) {
1036 (acpi_video_device_lcd_set_level(dev, level)))
1037 dev->brightness->curr = level;
1044 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1046 struct acpi_video_device *dev = seq->private;
1049 union acpi_object *edid = NULL;
1055 status = acpi_video_device_EDID(dev, &edid, 128);
1056 if (ACPI_FAILURE(status)) {
1057 status = acpi_video_device_EDID(dev, &edid, 256);
1060 if (ACPI_FAILURE(status)) {
1064 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1065 for (i = 0; i < edid->buffer.length; i++)
1066 seq_putc(seq, edid->buffer.pointer[i]);
1071 seq_printf(seq, "<not supported>\n");
1079 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1081 return single_open(file, acpi_video_device_EDID_seq_show,
1085 static int acpi_video_device_add_fs(struct acpi_device *device)
1087 struct proc_dir_entry *entry, *device_dir;
1088 struct acpi_video_device *vid_dev;
1090 vid_dev = acpi_driver_data(device);
1094 device_dir = proc_mkdir(acpi_device_bid(device),
1095 vid_dev->video->dir);
1099 device_dir->owner = THIS_MODULE;
1102 entry = proc_create_data("info", S_IRUGO, device_dir,
1103 &acpi_video_device_info_fops, acpi_driver_data(device));
1105 goto err_remove_dir;
1108 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1109 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1111 &acpi_video_device_state_fops,
1112 acpi_driver_data(device));
1114 goto err_remove_info;
1116 /* 'brightness' [R/W] */
1117 acpi_video_device_brightness_fops.write =
1118 acpi_video_device_write_brightness;
1119 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1121 &acpi_video_device_brightness_fops,
1122 acpi_driver_data(device));
1124 goto err_remove_state;
1127 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1128 &acpi_video_device_EDID_fops,
1129 acpi_driver_data(device));
1131 goto err_remove_brightness;
1133 acpi_device_dir(device) = device_dir;
1137 err_remove_brightness:
1138 remove_proc_entry("brightness", device_dir);
1140 remove_proc_entry("state", device_dir);
1142 remove_proc_entry("info", device_dir);
1144 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1148 static int acpi_video_device_remove_fs(struct acpi_device *device)
1150 struct acpi_video_device *vid_dev;
1151 struct proc_dir_entry *device_dir;
1153 vid_dev = acpi_driver_data(device);
1154 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1157 device_dir = acpi_device_dir(device);
1159 remove_proc_entry("info", device_dir);
1160 remove_proc_entry("state", device_dir);
1161 remove_proc_entry("brightness", device_dir);
1162 remove_proc_entry("EDID", device_dir);
1163 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1164 acpi_device_dir(device) = NULL;
1171 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1173 struct acpi_video_bus *video = seq->private;
1179 seq_printf(seq, "Switching heads: %s\n",
1180 video->flags.multihead ? "yes" : "no");
1181 seq_printf(seq, "Video ROM: %s\n",
1182 video->flags.rom ? "yes" : "no");
1183 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1184 video->flags.post ? "yes" : "no");
1190 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1192 return single_open(file, acpi_video_bus_info_seq_show,
1196 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1198 struct acpi_video_bus *video = seq->private;
1204 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1205 seq_printf(seq, "<TODO>\n");
1211 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1213 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1216 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1218 struct acpi_video_bus *video = seq->private;
1219 unsigned long long options;
1226 status = acpi_video_bus_POST_options(video, &options);
1227 if (ACPI_SUCCESS(status)) {
1228 if (!(options & 1)) {
1229 printk(KERN_WARNING PREFIX
1230 "The motherboard VGA device is not listed as a possible POST device.\n");
1231 printk(KERN_WARNING PREFIX
1232 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1234 printk("%llx\n", options);
1235 seq_printf(seq, "can POST: <integrated video>");
1237 seq_printf(seq, " <PCI video>");
1239 seq_printf(seq, " <AGP video>");
1240 seq_putc(seq, '\n');
1242 seq_printf(seq, "<not supported>\n");
1248 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1250 return single_open(file, acpi_video_bus_POST_info_seq_show,
1254 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1256 struct acpi_video_bus *video = seq->private;
1258 unsigned long long id;
1264 status = acpi_video_bus_get_POST(video, &id);
1265 if (!ACPI_SUCCESS(status)) {
1266 seq_printf(seq, "<not supported>\n");
1269 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1275 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1277 struct acpi_video_bus *video = seq->private;
1280 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1285 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1287 return single_open(file, acpi_video_bus_POST_seq_show,
1291 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1293 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1297 acpi_video_bus_write_POST(struct file *file,
1298 const char __user * buffer,
1299 size_t count, loff_t * data)
1302 struct seq_file *m = file->private_data;
1303 struct acpi_video_bus *video = m->private;
1304 char str[12] = { 0 };
1305 unsigned long long opt, options;
1308 if (!video || count + 1 > sizeof str)
1311 status = acpi_video_bus_POST_options(video, &options);
1312 if (!ACPI_SUCCESS(status))
1315 if (copy_from_user(str, buffer, count))
1319 opt = strtoul(str, NULL, 0);
1323 /* just in case an OEM 'forgot' the motherboard... */
1326 if (options & (1ul << opt)) {
1327 status = acpi_video_bus_set_POST(video, opt);
1328 if (!ACPI_SUCCESS(status))
1337 acpi_video_bus_write_DOS(struct file *file,
1338 const char __user * buffer,
1339 size_t count, loff_t * data)
1342 struct seq_file *m = file->private_data;
1343 struct acpi_video_bus *video = m->private;
1344 char str[12] = { 0 };
1348 if (!video || count + 1 > sizeof str)
1351 if (copy_from_user(str, buffer, count))
1355 opt = strtoul(str, NULL, 0);
1359 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1361 if (!ACPI_SUCCESS(status))
1367 static int acpi_video_bus_add_fs(struct acpi_device *device)
1369 struct acpi_video_bus *video = acpi_driver_data(device);
1370 struct proc_dir_entry *device_dir;
1371 struct proc_dir_entry *entry;
1373 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1377 device_dir->owner = THIS_MODULE;
1380 entry = proc_create_data("info", S_IRUGO, device_dir,
1381 &acpi_video_bus_info_fops,
1382 acpi_driver_data(device));
1384 goto err_remove_dir;
1387 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1388 &acpi_video_bus_ROM_fops,
1389 acpi_driver_data(device));
1391 goto err_remove_info;
1393 /* 'POST_info' [R] */
1394 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1395 &acpi_video_bus_POST_info_fops,
1396 acpi_driver_data(device));
1398 goto err_remove_rom;
1401 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1402 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1404 &acpi_video_bus_POST_fops,
1405 acpi_driver_data(device));
1407 goto err_remove_post_info;
1410 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1411 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1413 &acpi_video_bus_DOS_fops,
1414 acpi_driver_data(device));
1416 goto err_remove_post;
1418 video->dir = acpi_device_dir(device) = device_dir;
1422 remove_proc_entry("POST", device_dir);
1423 err_remove_post_info:
1424 remove_proc_entry("POST_info", device_dir);
1426 remove_proc_entry("ROM", device_dir);
1428 remove_proc_entry("info", device_dir);
1430 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1434 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1436 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1439 remove_proc_entry("info", device_dir);
1440 remove_proc_entry("ROM", device_dir);
1441 remove_proc_entry("POST_info", device_dir);
1442 remove_proc_entry("POST", device_dir);
1443 remove_proc_entry("DOS", device_dir);
1444 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1445 acpi_device_dir(device) = NULL;
1451 /* --------------------------------------------------------------------------
1453 -------------------------------------------------------------------------- */
1455 /* device interface */
1456 static struct acpi_video_device_attrib*
1457 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1459 struct acpi_video_enumerated_device *ids;
1462 for (i = 0; i < video->attached_count; i++) {
1463 ids = &video->attached_array[i];
1464 if ((ids->value.int_val & 0xffff) == device_id)
1465 return &ids->value.attrib;
1472 acpi_video_bus_get_one_device(struct acpi_device *device,
1473 struct acpi_video_bus *video)
1475 unsigned long long device_id;
1477 struct acpi_video_device *data;
1478 struct acpi_video_device_attrib* attribute;
1480 if (!device || !video)
1484 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1485 if (ACPI_SUCCESS(status)) {
1487 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1491 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1492 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1493 device->driver_data = data;
1495 data->device_id = device_id;
1496 data->video = video;
1499 attribute = acpi_video_get_device_attr(video, device_id);
1501 if((attribute != NULL) && attribute->device_id_scheme) {
1502 switch (attribute->display_type) {
1503 case ACPI_VIDEO_DISPLAY_CRT:
1504 data->flags.crt = 1;
1506 case ACPI_VIDEO_DISPLAY_TV:
1507 data->flags.tvout = 1;
1509 case ACPI_VIDEO_DISPLAY_DVI:
1510 data->flags.dvi = 1;
1512 case ACPI_VIDEO_DISPLAY_LCD:
1513 data->flags.lcd = 1;
1516 data->flags.unknown = 1;
1519 if(attribute->bios_can_detect)
1520 data->flags.bios = 1;
1522 data->flags.unknown = 1;
1524 acpi_video_device_bind(video, data);
1525 acpi_video_device_find_cap(data);
1527 status = acpi_install_notify_handler(device->handle,
1529 acpi_video_device_notify,
1531 if (ACPI_FAILURE(status)) {
1532 printk(KERN_ERR PREFIX
1533 "Error installing notify handler\n");
1534 if(data->brightness)
1535 kfree(data->brightness->levels);
1536 kfree(data->brightness);
1541 mutex_lock(&video->device_list_lock);
1542 list_add_tail(&data->entry, &video->video_device_list);
1543 mutex_unlock(&video->device_list_lock);
1545 acpi_video_device_add_fs(device);
1555 * video : video bus device
1560 * Enumerate the video device list of the video bus,
1561 * bind the ids with the corresponding video devices
1562 * under the video bus.
1565 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1567 struct acpi_video_device *dev;
1569 mutex_lock(&video->device_list_lock);
1571 list_for_each_entry(dev, &video->video_device_list, entry)
1572 acpi_video_device_bind(video, dev);
1574 mutex_unlock(&video->device_list_lock);
1579 * video : video bus device
1580 * device : video output device under the video
1586 * Bind the ids with the corresponding video devices
1587 * under the video bus.
1591 acpi_video_device_bind(struct acpi_video_bus *video,
1592 struct acpi_video_device *device)
1594 struct acpi_video_enumerated_device *ids;
1597 for (i = 0; i < video->attached_count; i++) {
1598 ids = &video->attached_array[i];
1599 if (device->device_id == (ids->value.int_val & 0xffff)) {
1600 ids->bind_info = device;
1601 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1608 * video : video bus device
1613 * Call _DOD to enumerate all devices attached to display adapter
1617 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1622 struct acpi_video_enumerated_device *active_list;
1623 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1624 union acpi_object *dod = NULL;
1625 union acpi_object *obj;
1627 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1628 if (!ACPI_SUCCESS(status)) {
1629 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1633 dod = buffer.pointer;
1634 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1635 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1640 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1641 dod->package.count));
1643 active_list = kcalloc(1 + dod->package.count,
1644 sizeof(struct acpi_video_enumerated_device),
1652 for (i = 0; i < dod->package.count; i++) {
1653 obj = &dod->package.elements[i];
1655 if (obj->type != ACPI_TYPE_INTEGER) {
1656 printk(KERN_ERR PREFIX
1657 "Invalid _DOD data in element %d\n", i);
1661 active_list[count].value.int_val = obj->integer.value;
1662 active_list[count].bind_info = NULL;
1663 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1664 (int)obj->integer.value));
1668 kfree(video->attached_array);
1670 video->attached_array = active_list;
1671 video->attached_count = count;
1674 kfree(buffer.pointer);
1679 acpi_video_get_next_level(struct acpi_video_device *device,
1680 u32 level_current, u32 event)
1682 int min, max, min_above, max_below, i, l, delta = 255;
1683 max = max_below = 0;
1684 min = min_above = 255;
1685 /* Find closest level to level_current */
1686 for (i = 0; i < device->brightness->count; i++) {
1687 l = device->brightness->levels[i];
1688 if (abs(l - level_current) < abs(delta)) {
1689 delta = l - level_current;
1694 /* Ajust level_current to closest available level */
1695 level_current += delta;
1696 for (i = 0; i < device->brightness->count; i++) {
1697 l = device->brightness->levels[i];
1702 if (l < min_above && l > level_current)
1704 if (l > max_below && l < level_current)
1709 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1710 return (level_current < max) ? min_above : min;
1711 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1712 return (level_current < max) ? min_above : max;
1713 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1714 return (level_current > min) ? max_below : min;
1715 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1716 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1719 return level_current;
1724 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1726 unsigned long long level_current, level_next;
1727 if (!device->brightness)
1729 acpi_video_device_lcd_get_level_current(device, &level_current);
1730 level_next = acpi_video_get_next_level(device, level_current, event);
1731 acpi_video_device_lcd_set_level(device, level_next);
1735 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1736 struct acpi_device *device)
1739 struct acpi_device *dev;
1741 acpi_video_device_enumerate(video);
1743 list_for_each_entry(dev, &device->children, node) {
1745 status = acpi_video_bus_get_one_device(dev, video);
1746 if (ACPI_FAILURE(status)) {
1747 printk(KERN_WARNING PREFIX
1748 "Cant attach device");
1755 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1758 struct acpi_video_bus *video;
1761 if (!device || !device->video)
1764 video = device->video;
1766 acpi_video_device_remove_fs(device->dev);
1768 status = acpi_remove_notify_handler(device->dev->handle,
1770 acpi_video_device_notify);
1771 backlight_device_unregister(device->backlight);
1773 sysfs_remove_link(&device->dev->dev.kobj,
1775 sysfs_remove_link(&device->cdev->device.kobj,
1777 thermal_cooling_device_unregister(device->cdev);
1778 device->cdev = NULL;
1780 video_output_unregister(device->output_dev);
1785 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1788 struct acpi_video_device *dev, *next;
1790 mutex_lock(&video->device_list_lock);
1792 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1794 status = acpi_video_bus_put_one_device(dev);
1795 if (ACPI_FAILURE(status))
1796 printk(KERN_WARNING PREFIX
1797 "hhuuhhuu bug in acpi video driver.\n");
1799 if (dev->brightness) {
1800 kfree(dev->brightness->levels);
1801 kfree(dev->brightness);
1803 list_del(&dev->entry);
1807 mutex_unlock(&video->device_list_lock);
1812 /* acpi_video interface */
1814 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1816 return acpi_video_bus_DOS(video, 0, 0);
1819 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1821 return acpi_video_bus_DOS(video, 0, 1);
1824 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1826 struct acpi_video_bus *video = data;
1827 struct acpi_device *device = NULL;
1828 struct input_dev *input;
1834 device = video->device;
1835 input = video->input;
1838 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1839 * most likely via hotkey. */
1840 acpi_bus_generate_proc_event(device, event, 0);
1841 keycode = KEY_SWITCHVIDEOMODE;
1844 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1846 acpi_video_device_enumerate(video);
1847 acpi_video_device_rebind(video);
1848 acpi_bus_generate_proc_event(device, event, 0);
1849 keycode = KEY_SWITCHVIDEOMODE;
1852 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1853 acpi_bus_generate_proc_event(device, event, 0);
1854 keycode = KEY_SWITCHVIDEOMODE;
1856 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1857 acpi_bus_generate_proc_event(device, event, 0);
1858 keycode = KEY_VIDEO_NEXT;
1860 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1861 acpi_bus_generate_proc_event(device, event, 0);
1862 keycode = KEY_VIDEO_PREV;
1866 keycode = KEY_UNKNOWN;
1867 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1868 "Unsupported event [0x%x]\n", event));
1872 acpi_notifier_call_chain(device, event, 0);
1873 input_report_key(input, keycode, 1);
1875 input_report_key(input, keycode, 0);
1881 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1883 struct acpi_video_device *video_device = data;
1884 struct acpi_device *device = NULL;
1885 struct acpi_video_bus *bus;
1886 struct input_dev *input;
1892 device = video_device->dev;
1893 bus = video_device->video;
1897 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1898 if (brightness_switch_enabled)
1899 acpi_video_switch_brightness(video_device, event);
1900 acpi_bus_generate_proc_event(device, event, 0);
1901 keycode = KEY_BRIGHTNESS_CYCLE;
1903 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1904 if (brightness_switch_enabled)
1905 acpi_video_switch_brightness(video_device, event);
1906 acpi_bus_generate_proc_event(device, event, 0);
1907 keycode = KEY_BRIGHTNESSUP;
1909 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1910 if (brightness_switch_enabled)
1911 acpi_video_switch_brightness(video_device, event);
1912 acpi_bus_generate_proc_event(device, event, 0);
1913 keycode = KEY_BRIGHTNESSDOWN;
1915 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1916 if (brightness_switch_enabled)
1917 acpi_video_switch_brightness(video_device, event);
1918 acpi_bus_generate_proc_event(device, event, 0);
1919 keycode = KEY_BRIGHTNESS_ZERO;
1921 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1922 if (brightness_switch_enabled)
1923 acpi_video_switch_brightness(video_device, event);
1924 acpi_bus_generate_proc_event(device, event, 0);
1925 keycode = KEY_DISPLAY_OFF;
1928 keycode = KEY_UNKNOWN;
1929 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1930 "Unsupported event [0x%x]\n", event));
1934 acpi_notifier_call_chain(device, event, 0);
1935 input_report_key(input, keycode, 1);
1937 input_report_key(input, keycode, 0);
1943 static int instance;
1944 static int acpi_video_resume(struct acpi_device *device)
1946 struct acpi_video_bus *video;
1947 struct acpi_video_device *video_device;
1950 if (!device || !acpi_driver_data(device))
1953 video = acpi_driver_data(device);
1955 for (i = 0; i < video->attached_count; i++) {
1956 video_device = video->attached_array[i].bind_info;
1957 if (video_device && video_device->backlight)
1958 acpi_video_set_brightness(video_device->backlight);
1963 static int acpi_video_bus_add(struct acpi_device *device)
1966 struct acpi_video_bus *video;
1967 struct input_dev *input;
1970 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1974 /* a hack to fix the duplicate name "VID" problem on T61 */
1975 if (!strcmp(device->pnp.bus_id, "VID")) {
1977 device->pnp.bus_id[3] = '0' + instance;
1981 video->device = device;
1982 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1983 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1984 device->driver_data = video;
1986 acpi_video_bus_find_cap(video);
1987 error = acpi_video_bus_check(video);
1989 goto err_free_video;
1991 error = acpi_video_bus_add_fs(device);
1993 goto err_free_video;
1995 mutex_init(&video->device_list_lock);
1996 INIT_LIST_HEAD(&video->video_device_list);
1998 acpi_video_bus_get_devices(video, device);
1999 acpi_video_bus_start_devices(video);
2001 status = acpi_install_notify_handler(device->handle,
2003 acpi_video_bus_notify, video);
2004 if (ACPI_FAILURE(status)) {
2005 printk(KERN_ERR PREFIX
2006 "Error installing notify handler\n");
2008 goto err_stop_video;
2011 video->input = input = input_allocate_device();
2014 goto err_uninstall_notify;
2017 snprintf(video->phys, sizeof(video->phys),
2018 "%s/video/input0", acpi_device_hid(video->device));
2020 input->name = acpi_device_name(video->device);
2021 input->phys = video->phys;
2022 input->id.bustype = BUS_HOST;
2023 input->id.product = 0x06;
2024 input->dev.parent = &device->dev;
2025 input->evbit[0] = BIT(EV_KEY);
2026 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2027 set_bit(KEY_VIDEO_NEXT, input->keybit);
2028 set_bit(KEY_VIDEO_PREV, input->keybit);
2029 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2030 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2031 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2032 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2033 set_bit(KEY_DISPLAY_OFF, input->keybit);
2034 set_bit(KEY_UNKNOWN, input->keybit);
2036 error = input_register_device(input);
2038 goto err_free_input_dev;
2040 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2041 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2042 video->flags.multihead ? "yes" : "no",
2043 video->flags.rom ? "yes" : "no",
2044 video->flags.post ? "yes" : "no");
2049 input_free_device(input);
2050 err_uninstall_notify:
2051 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2052 acpi_video_bus_notify);
2054 acpi_video_bus_stop_devices(video);
2055 acpi_video_bus_put_devices(video);
2056 kfree(video->attached_array);
2057 acpi_video_bus_remove_fs(device);
2060 device->driver_data = NULL;
2065 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2067 acpi_status status = 0;
2068 struct acpi_video_bus *video = NULL;
2071 if (!device || !acpi_driver_data(device))
2074 video = acpi_driver_data(device);
2076 acpi_video_bus_stop_devices(video);
2078 status = acpi_remove_notify_handler(video->device->handle,
2080 acpi_video_bus_notify);
2082 acpi_video_bus_put_devices(video);
2083 acpi_video_bus_remove_fs(device);
2085 input_unregister_device(video->input);
2086 kfree(video->attached_array);
2092 static int __init acpi_video_init(void)
2096 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2097 if (!acpi_video_dir)
2099 acpi_video_dir->owner = THIS_MODULE;
2101 result = acpi_bus_register_driver(&acpi_video_bus);
2103 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2110 static void __exit acpi_video_exit(void)
2113 acpi_bus_unregister_driver(&acpi_video_bus);
2115 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2120 module_init(acpi_video_init);
2121 module_exit(acpi_video_exit);