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 };
487 arg0.integer.value = level;
489 if (device->cap._BCM)
490 status = acpi_evaluate_object(device->dev->handle, "_BCM",
492 device->brightness->curr = level;
493 for (state = 2; state < device->brightness->count; state++)
494 if (level == device->brightness->levels[state])
495 device->backlight->props.brightness = state - 2;
501 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
502 unsigned long long *level)
504 if (device->cap._BQC)
505 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
507 *level = device->brightness->curr;
512 acpi_video_device_EDID(struct acpi_video_device *device,
513 union acpi_object **edid, ssize_t length)
516 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
517 union acpi_object *obj;
518 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
519 struct acpi_object_list args = { 1, &arg0 };
527 arg0.integer.value = 1;
528 else if (length == 256)
529 arg0.integer.value = 2;
533 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
534 if (ACPI_FAILURE(status))
537 obj = buffer.pointer;
539 if (obj && obj->type == ACPI_TYPE_BUFFER)
542 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
553 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
556 unsigned long long tmp;
557 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
558 struct acpi_object_list args = { 1, &arg0 };
561 arg0.integer.value = option;
563 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
564 if (ACPI_SUCCESS(status))
565 status = tmp ? (-EINVAL) : (AE_OK);
571 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
575 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
581 acpi_video_bus_POST_options(struct acpi_video_bus *video,
582 unsigned long long *options)
586 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
594 * video : video bus device pointer
596 * 0. The system BIOS should NOT automatically switch(toggle)
597 * the active display output.
598 * 1. The system BIOS should automatically switch (toggle) the
599 * active display output. No switch event.
600 * 2. The _DGS value should be locked.
601 * 3. The system BIOS should not automatically switch (toggle) the
602 * active display output, but instead generate the display switch
605 * 0. The system BIOS should automatically control the brightness level
606 * of the LCD when the power changes from AC to DC
607 * 1. The system BIOS should NOT automatically control the brightness
608 * level of the LCD when the power changes from AC to DC.
614 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
616 acpi_integer status = 0;
617 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
618 struct acpi_object_list args = { 1, &arg0 };
621 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
625 arg0.integer.value = (lcd_flag << 2) | bios_flag;
626 video->dos_setting = arg0.integer.value;
627 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
635 * device : video output device (LCD, CRT, ..)
638 * Maximum brightness level
640 * Allocate and initialize device->brightness.
644 acpi_video_init_brightness(struct acpi_video_device *device)
646 union acpi_object *obj = NULL;
647 int i, max_level = 0, count = 0;
648 union acpi_object *o;
649 struct acpi_video_device_brightness *br = NULL;
651 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
652 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
653 "LCD brightness level\n"));
657 if (obj->package.count < 2)
660 br = kzalloc(sizeof(*br), GFP_KERNEL);
662 printk(KERN_ERR "can't allocate memory\n");
666 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
671 for (i = 0; i < obj->package.count; i++) {
672 o = (union acpi_object *)&obj->package.elements[i];
673 if (o->type != ACPI_TYPE_INTEGER) {
674 printk(KERN_ERR PREFIX "Invalid data\n");
677 br->levels[count] = (u32) o->integer.value;
679 if (br->levels[count] > max_level)
680 max_level = br->levels[count];
685 goto out_free_levels;
688 device->brightness = br;
689 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
698 device->brightness = NULL;
705 * device : video output device (LCD, CRT, ..)
710 * Find out all required AML methods defined under the output
714 static void acpi_video_device_find_cap(struct acpi_video_device *device)
716 acpi_handle h_dummy1;
720 memset(&device->cap, 0, sizeof(device->cap));
722 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
723 device->cap._ADR = 1;
725 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
726 device->cap._BCL = 1;
728 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
729 device->cap._BCM = 1;
731 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
732 device->cap._BQC = 1;
733 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
734 device->cap._DDC = 1;
736 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
737 device->cap._DCS = 1;
739 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
740 device->cap._DGS = 1;
742 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
743 device->cap._DSS = 1;
746 if (acpi_video_backlight_support())
747 max_level = acpi_video_init_brightness(device);
749 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
751 static int count = 0;
753 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
757 sprintf(name, "acpi_video%d", count++);
758 device->backlight = backlight_device_register(name,
759 NULL, device, &acpi_backlight_ops);
760 device->backlight->props.max_brightness = device->brightness->count-3;
762 * If there exists the _BQC object, the _BQC object will be
763 * called to get the current backlight brightness. Otherwise
764 * the brightness will be set to the maximum.
766 if (device->cap._BQC)
767 device->backlight->props.brightness =
768 acpi_video_get_brightness(device->backlight);
770 device->backlight->props.brightness =
771 device->backlight->props.max_brightness;
772 backlight_update_status(device->backlight);
775 device->cdev = thermal_cooling_device_register("LCD",
776 device->dev, &video_cooling_ops);
777 if (IS_ERR(device->cdev))
780 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
782 result = sysfs_create_link(&device->dev->dev.kobj,
783 &device->cdev->device.kobj,
786 printk(KERN_ERR PREFIX "Create sysfs link\n");
787 result = sysfs_create_link(&device->cdev->device.kobj,
788 &device->dev->dev.kobj, "device");
790 printk(KERN_ERR PREFIX "Create sysfs link\n");
794 if (acpi_video_display_switch_support()) {
796 if (device->cap._DCS && device->cap._DSS) {
799 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
802 sprintf(name, "acpi_video%d", count++);
803 device->output_dev = video_output_register(name,
804 NULL, device, &acpi_output_properties);
812 * device : video output device (VGA)
817 * Find out all required AML methods defined under the video bus device.
820 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
822 acpi_handle h_dummy1;
824 memset(&video->cap, 0, sizeof(video->cap));
825 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
828 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
831 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
834 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
837 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
840 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
846 * Check whether the video bus device has required AML method to
847 * support the desired features
850 static int acpi_video_bus_check(struct acpi_video_bus *video)
852 acpi_status status = -ENOENT;
858 dev = acpi_get_physical_pci_device(video->device->handle);
863 /* Since there is no HID, CID and so on for VGA driver, we have
864 * to check well known required nodes.
867 /* Does this device support video switching? */
868 if (video->cap._DOS) {
869 video->flags.multihead = 1;
873 /* Does this device support retrieving a video ROM? */
874 if (video->cap._ROM) {
875 video->flags.rom = 1;
879 /* Does this device support configuring which video device to POST? */
880 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
881 video->flags.post = 1;
888 /* --------------------------------------------------------------------------
890 -------------------------------------------------------------------------- */
892 static struct proc_dir_entry *acpi_video_dir;
896 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
898 struct acpi_video_device *dev = seq->private;
904 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
905 seq_printf(seq, "type: ");
907 seq_printf(seq, "CRT\n");
908 else if (dev->flags.lcd)
909 seq_printf(seq, "LCD\n");
910 else if (dev->flags.tvout)
911 seq_printf(seq, "TVOUT\n");
912 else if (dev->flags.dvi)
913 seq_printf(seq, "DVI\n");
915 seq_printf(seq, "UNKNOWN\n");
917 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
924 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
926 return single_open(file, acpi_video_device_info_seq_show,
930 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
933 struct acpi_video_device *dev = seq->private;
934 unsigned long long state;
940 status = acpi_video_device_get_state(dev, &state);
941 seq_printf(seq, "state: ");
942 if (ACPI_SUCCESS(status))
943 seq_printf(seq, "0x%02llx\n", state);
945 seq_printf(seq, "<not supported>\n");
947 status = acpi_video_device_query(dev, &state);
948 seq_printf(seq, "query: ");
949 if (ACPI_SUCCESS(status))
950 seq_printf(seq, "0x%02llx\n", state);
952 seq_printf(seq, "<not supported>\n");
959 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
961 return single_open(file, acpi_video_device_state_seq_show,
966 acpi_video_device_write_state(struct file *file,
967 const char __user * buffer,
968 size_t count, loff_t * data)
971 struct seq_file *m = file->private_data;
972 struct acpi_video_device *dev = m->private;
973 char str[12] = { 0 };
977 if (!dev || count + 1 > sizeof str)
980 if (copy_from_user(str, buffer, count))
984 state = simple_strtoul(str, NULL, 0);
985 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
987 status = acpi_video_device_set_state(dev, state);
996 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
998 struct acpi_video_device *dev = seq->private;
1002 if (!dev || !dev->brightness) {
1003 seq_printf(seq, "<not supported>\n");
1007 seq_printf(seq, "levels: ");
1008 for (i = 0; i < dev->brightness->count; i++)
1009 seq_printf(seq, " %d", dev->brightness->levels[i]);
1010 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1016 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1018 return single_open(file, acpi_video_device_brightness_seq_show,
1023 acpi_video_device_write_brightness(struct file *file,
1024 const char __user * buffer,
1025 size_t count, loff_t * data)
1027 struct seq_file *m = file->private_data;
1028 struct acpi_video_device *dev = m->private;
1029 char str[5] = { 0 };
1030 unsigned int level = 0;
1034 if (!dev || !dev->brightness || count + 1 > sizeof str)
1037 if (copy_from_user(str, buffer, count))
1041 level = simple_strtoul(str, NULL, 0);
1046 /* validate through the list of available levels */
1047 for (i = 0; i < dev->brightness->count; i++)
1048 if (level == dev->brightness->levels[i]) {
1050 (acpi_video_device_lcd_set_level(dev, level)))
1051 dev->brightness->curr = level;
1058 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1060 struct acpi_video_device *dev = seq->private;
1063 union acpi_object *edid = NULL;
1069 status = acpi_video_device_EDID(dev, &edid, 128);
1070 if (ACPI_FAILURE(status)) {
1071 status = acpi_video_device_EDID(dev, &edid, 256);
1074 if (ACPI_FAILURE(status)) {
1078 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1079 for (i = 0; i < edid->buffer.length; i++)
1080 seq_putc(seq, edid->buffer.pointer[i]);
1085 seq_printf(seq, "<not supported>\n");
1093 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1095 return single_open(file, acpi_video_device_EDID_seq_show,
1099 static int acpi_video_device_add_fs(struct acpi_device *device)
1101 struct proc_dir_entry *entry, *device_dir;
1102 struct acpi_video_device *vid_dev;
1104 vid_dev = acpi_driver_data(device);
1108 device_dir = proc_mkdir(acpi_device_bid(device),
1109 vid_dev->video->dir);
1113 device_dir->owner = THIS_MODULE;
1116 entry = proc_create_data("info", S_IRUGO, device_dir,
1117 &acpi_video_device_info_fops, acpi_driver_data(device));
1119 goto err_remove_dir;
1122 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1123 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1125 &acpi_video_device_state_fops,
1126 acpi_driver_data(device));
1128 goto err_remove_info;
1130 /* 'brightness' [R/W] */
1131 acpi_video_device_brightness_fops.write =
1132 acpi_video_device_write_brightness;
1133 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1135 &acpi_video_device_brightness_fops,
1136 acpi_driver_data(device));
1138 goto err_remove_state;
1141 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1142 &acpi_video_device_EDID_fops,
1143 acpi_driver_data(device));
1145 goto err_remove_brightness;
1147 acpi_device_dir(device) = device_dir;
1151 err_remove_brightness:
1152 remove_proc_entry("brightness", device_dir);
1154 remove_proc_entry("state", device_dir);
1156 remove_proc_entry("info", device_dir);
1158 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1162 static int acpi_video_device_remove_fs(struct acpi_device *device)
1164 struct acpi_video_device *vid_dev;
1165 struct proc_dir_entry *device_dir;
1167 vid_dev = acpi_driver_data(device);
1168 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1171 device_dir = acpi_device_dir(device);
1173 remove_proc_entry("info", device_dir);
1174 remove_proc_entry("state", device_dir);
1175 remove_proc_entry("brightness", device_dir);
1176 remove_proc_entry("EDID", device_dir);
1177 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1178 acpi_device_dir(device) = NULL;
1185 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1187 struct acpi_video_bus *video = seq->private;
1193 seq_printf(seq, "Switching heads: %s\n",
1194 video->flags.multihead ? "yes" : "no");
1195 seq_printf(seq, "Video ROM: %s\n",
1196 video->flags.rom ? "yes" : "no");
1197 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1198 video->flags.post ? "yes" : "no");
1204 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1206 return single_open(file, acpi_video_bus_info_seq_show,
1210 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1212 struct acpi_video_bus *video = seq->private;
1218 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1219 seq_printf(seq, "<TODO>\n");
1225 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1227 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1230 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1232 struct acpi_video_bus *video = seq->private;
1233 unsigned long long options;
1240 status = acpi_video_bus_POST_options(video, &options);
1241 if (ACPI_SUCCESS(status)) {
1242 if (!(options & 1)) {
1243 printk(KERN_WARNING PREFIX
1244 "The motherboard VGA device is not listed as a possible POST device.\n");
1245 printk(KERN_WARNING PREFIX
1246 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1248 printk("%llx\n", options);
1249 seq_printf(seq, "can POST: <integrated video>");
1251 seq_printf(seq, " <PCI video>");
1253 seq_printf(seq, " <AGP video>");
1254 seq_putc(seq, '\n');
1256 seq_printf(seq, "<not supported>\n");
1262 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1264 return single_open(file, acpi_video_bus_POST_info_seq_show,
1268 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1270 struct acpi_video_bus *video = seq->private;
1272 unsigned long long id;
1278 status = acpi_video_bus_get_POST(video, &id);
1279 if (!ACPI_SUCCESS(status)) {
1280 seq_printf(seq, "<not supported>\n");
1283 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1289 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1291 struct acpi_video_bus *video = seq->private;
1294 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1299 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1301 return single_open(file, acpi_video_bus_POST_seq_show,
1305 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1307 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1311 acpi_video_bus_write_POST(struct file *file,
1312 const char __user * buffer,
1313 size_t count, loff_t * data)
1316 struct seq_file *m = file->private_data;
1317 struct acpi_video_bus *video = m->private;
1318 char str[12] = { 0 };
1319 unsigned long long opt, options;
1322 if (!video || count + 1 > sizeof str)
1325 status = acpi_video_bus_POST_options(video, &options);
1326 if (!ACPI_SUCCESS(status))
1329 if (copy_from_user(str, buffer, count))
1333 opt = strtoul(str, NULL, 0);
1337 /* just in case an OEM 'forgot' the motherboard... */
1340 if (options & (1ul << opt)) {
1341 status = acpi_video_bus_set_POST(video, opt);
1342 if (!ACPI_SUCCESS(status))
1351 acpi_video_bus_write_DOS(struct file *file,
1352 const char __user * buffer,
1353 size_t count, loff_t * data)
1356 struct seq_file *m = file->private_data;
1357 struct acpi_video_bus *video = m->private;
1358 char str[12] = { 0 };
1362 if (!video || count + 1 > sizeof str)
1365 if (copy_from_user(str, buffer, count))
1369 opt = strtoul(str, NULL, 0);
1373 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1375 if (!ACPI_SUCCESS(status))
1381 static int acpi_video_bus_add_fs(struct acpi_device *device)
1383 struct acpi_video_bus *video = acpi_driver_data(device);
1384 struct proc_dir_entry *device_dir;
1385 struct proc_dir_entry *entry;
1387 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1391 device_dir->owner = THIS_MODULE;
1394 entry = proc_create_data("info", S_IRUGO, device_dir,
1395 &acpi_video_bus_info_fops,
1396 acpi_driver_data(device));
1398 goto err_remove_dir;
1401 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1402 &acpi_video_bus_ROM_fops,
1403 acpi_driver_data(device));
1405 goto err_remove_info;
1407 /* 'POST_info' [R] */
1408 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1409 &acpi_video_bus_POST_info_fops,
1410 acpi_driver_data(device));
1412 goto err_remove_rom;
1415 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1416 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1418 &acpi_video_bus_POST_fops,
1419 acpi_driver_data(device));
1421 goto err_remove_post_info;
1424 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1425 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1427 &acpi_video_bus_DOS_fops,
1428 acpi_driver_data(device));
1430 goto err_remove_post;
1432 video->dir = acpi_device_dir(device) = device_dir;
1436 remove_proc_entry("POST", device_dir);
1437 err_remove_post_info:
1438 remove_proc_entry("POST_info", device_dir);
1440 remove_proc_entry("ROM", device_dir);
1442 remove_proc_entry("info", device_dir);
1444 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1448 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1450 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1453 remove_proc_entry("info", device_dir);
1454 remove_proc_entry("ROM", device_dir);
1455 remove_proc_entry("POST_info", device_dir);
1456 remove_proc_entry("POST", device_dir);
1457 remove_proc_entry("DOS", device_dir);
1458 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1459 acpi_device_dir(device) = NULL;
1465 /* --------------------------------------------------------------------------
1467 -------------------------------------------------------------------------- */
1469 /* device interface */
1470 static struct acpi_video_device_attrib*
1471 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1473 struct acpi_video_enumerated_device *ids;
1476 for (i = 0; i < video->attached_count; i++) {
1477 ids = &video->attached_array[i];
1478 if ((ids->value.int_val & 0xffff) == device_id)
1479 return &ids->value.attrib;
1486 acpi_video_bus_get_one_device(struct acpi_device *device,
1487 struct acpi_video_bus *video)
1489 unsigned long long device_id;
1491 struct acpi_video_device *data;
1492 struct acpi_video_device_attrib* attribute;
1494 if (!device || !video)
1498 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1499 if (ACPI_SUCCESS(status)) {
1501 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1505 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1506 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1507 device->driver_data = data;
1509 data->device_id = device_id;
1510 data->video = video;
1513 attribute = acpi_video_get_device_attr(video, device_id);
1515 if((attribute != NULL) && attribute->device_id_scheme) {
1516 switch (attribute->display_type) {
1517 case ACPI_VIDEO_DISPLAY_CRT:
1518 data->flags.crt = 1;
1520 case ACPI_VIDEO_DISPLAY_TV:
1521 data->flags.tvout = 1;
1523 case ACPI_VIDEO_DISPLAY_DVI:
1524 data->flags.dvi = 1;
1526 case ACPI_VIDEO_DISPLAY_LCD:
1527 data->flags.lcd = 1;
1530 data->flags.unknown = 1;
1533 if(attribute->bios_can_detect)
1534 data->flags.bios = 1;
1536 data->flags.unknown = 1;
1538 acpi_video_device_bind(video, data);
1539 acpi_video_device_find_cap(data);
1541 status = acpi_install_notify_handler(device->handle,
1543 acpi_video_device_notify,
1545 if (ACPI_FAILURE(status)) {
1546 printk(KERN_ERR PREFIX
1547 "Error installing notify handler\n");
1548 if(data->brightness)
1549 kfree(data->brightness->levels);
1550 kfree(data->brightness);
1555 mutex_lock(&video->device_list_lock);
1556 list_add_tail(&data->entry, &video->video_device_list);
1557 mutex_unlock(&video->device_list_lock);
1559 acpi_video_device_add_fs(device);
1569 * video : video bus device
1574 * Enumerate the video device list of the video bus,
1575 * bind the ids with the corresponding video devices
1576 * under the video bus.
1579 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1581 struct acpi_video_device *dev;
1583 mutex_lock(&video->device_list_lock);
1585 list_for_each_entry(dev, &video->video_device_list, entry)
1586 acpi_video_device_bind(video, dev);
1588 mutex_unlock(&video->device_list_lock);
1593 * video : video bus device
1594 * device : video output device under the video
1600 * Bind the ids with the corresponding video devices
1601 * under the video bus.
1605 acpi_video_device_bind(struct acpi_video_bus *video,
1606 struct acpi_video_device *device)
1608 struct acpi_video_enumerated_device *ids;
1611 for (i = 0; i < video->attached_count; i++) {
1612 ids = &video->attached_array[i];
1613 if (device->device_id == (ids->value.int_val & 0xffff)) {
1614 ids->bind_info = device;
1615 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1622 * video : video bus device
1627 * Call _DOD to enumerate all devices attached to display adapter
1631 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1636 struct acpi_video_enumerated_device *active_list;
1637 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1638 union acpi_object *dod = NULL;
1639 union acpi_object *obj;
1641 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1642 if (!ACPI_SUCCESS(status)) {
1643 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1647 dod = buffer.pointer;
1648 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1649 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1654 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1655 dod->package.count));
1657 active_list = kcalloc(1 + dod->package.count,
1658 sizeof(struct acpi_video_enumerated_device),
1666 for (i = 0; i < dod->package.count; i++) {
1667 obj = &dod->package.elements[i];
1669 if (obj->type != ACPI_TYPE_INTEGER) {
1670 printk(KERN_ERR PREFIX
1671 "Invalid _DOD data in element %d\n", i);
1675 active_list[count].value.int_val = obj->integer.value;
1676 active_list[count].bind_info = NULL;
1677 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1678 (int)obj->integer.value));
1682 kfree(video->attached_array);
1684 video->attached_array = active_list;
1685 video->attached_count = count;
1688 kfree(buffer.pointer);
1693 acpi_video_get_next_level(struct acpi_video_device *device,
1694 u32 level_current, u32 event)
1696 int min, max, min_above, max_below, i, l, delta = 255;
1697 max = max_below = 0;
1698 min = min_above = 255;
1699 /* Find closest level to level_current */
1700 for (i = 0; i < device->brightness->count; i++) {
1701 l = device->brightness->levels[i];
1702 if (abs(l - level_current) < abs(delta)) {
1703 delta = l - level_current;
1708 /* Ajust level_current to closest available level */
1709 level_current += delta;
1710 for (i = 0; i < device->brightness->count; i++) {
1711 l = device->brightness->levels[i];
1716 if (l < min_above && l > level_current)
1718 if (l > max_below && l < level_current)
1723 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1724 return (level_current < max) ? min_above : min;
1725 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1726 return (level_current < max) ? min_above : max;
1727 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1728 return (level_current > min) ? max_below : min;
1729 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1730 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1733 return level_current;
1738 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1740 unsigned long long level_current, level_next;
1741 if (!device->brightness)
1743 acpi_video_device_lcd_get_level_current(device, &level_current);
1744 level_next = acpi_video_get_next_level(device, level_current, event);
1745 acpi_video_device_lcd_set_level(device, level_next);
1749 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1750 struct acpi_device *device)
1753 struct acpi_device *dev;
1755 acpi_video_device_enumerate(video);
1757 list_for_each_entry(dev, &device->children, node) {
1759 status = acpi_video_bus_get_one_device(dev, video);
1760 if (ACPI_FAILURE(status)) {
1761 printk(KERN_WARNING PREFIX
1762 "Cant attach device");
1769 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1772 struct acpi_video_bus *video;
1775 if (!device || !device->video)
1778 video = device->video;
1780 acpi_video_device_remove_fs(device->dev);
1782 status = acpi_remove_notify_handler(device->dev->handle,
1784 acpi_video_device_notify);
1785 backlight_device_unregister(device->backlight);
1787 sysfs_remove_link(&device->dev->dev.kobj,
1789 sysfs_remove_link(&device->cdev->device.kobj,
1791 thermal_cooling_device_unregister(device->cdev);
1792 device->cdev = NULL;
1794 video_output_unregister(device->output_dev);
1799 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1802 struct acpi_video_device *dev, *next;
1804 mutex_lock(&video->device_list_lock);
1806 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1808 status = acpi_video_bus_put_one_device(dev);
1809 if (ACPI_FAILURE(status))
1810 printk(KERN_WARNING PREFIX
1811 "hhuuhhuu bug in acpi video driver.\n");
1813 if (dev->brightness) {
1814 kfree(dev->brightness->levels);
1815 kfree(dev->brightness);
1817 list_del(&dev->entry);
1821 mutex_unlock(&video->device_list_lock);
1826 /* acpi_video interface */
1828 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1830 return acpi_video_bus_DOS(video, 0, 0);
1833 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1835 return acpi_video_bus_DOS(video, 0, 1);
1838 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1840 struct acpi_video_bus *video = data;
1841 struct acpi_device *device = NULL;
1842 struct input_dev *input;
1848 device = video->device;
1849 input = video->input;
1852 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1853 * most likely via hotkey. */
1854 acpi_bus_generate_proc_event(device, event, 0);
1855 keycode = KEY_SWITCHVIDEOMODE;
1858 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1860 acpi_video_device_enumerate(video);
1861 acpi_video_device_rebind(video);
1862 acpi_bus_generate_proc_event(device, event, 0);
1863 keycode = KEY_SWITCHVIDEOMODE;
1866 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1867 acpi_bus_generate_proc_event(device, event, 0);
1868 keycode = KEY_SWITCHVIDEOMODE;
1870 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1871 acpi_bus_generate_proc_event(device, event, 0);
1872 keycode = KEY_VIDEO_NEXT;
1874 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1875 acpi_bus_generate_proc_event(device, event, 0);
1876 keycode = KEY_VIDEO_PREV;
1880 keycode = KEY_UNKNOWN;
1881 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1882 "Unsupported event [0x%x]\n", event));
1886 acpi_notifier_call_chain(device, event, 0);
1887 input_report_key(input, keycode, 1);
1889 input_report_key(input, keycode, 0);
1895 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1897 struct acpi_video_device *video_device = data;
1898 struct acpi_device *device = NULL;
1899 struct acpi_video_bus *bus;
1900 struct input_dev *input;
1906 device = video_device->dev;
1907 bus = video_device->video;
1911 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1912 if (brightness_switch_enabled)
1913 acpi_video_switch_brightness(video_device, event);
1914 acpi_bus_generate_proc_event(device, event, 0);
1915 keycode = KEY_BRIGHTNESS_CYCLE;
1917 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1918 if (brightness_switch_enabled)
1919 acpi_video_switch_brightness(video_device, event);
1920 acpi_bus_generate_proc_event(device, event, 0);
1921 keycode = KEY_BRIGHTNESSUP;
1923 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1924 if (brightness_switch_enabled)
1925 acpi_video_switch_brightness(video_device, event);
1926 acpi_bus_generate_proc_event(device, event, 0);
1927 keycode = KEY_BRIGHTNESSDOWN;
1929 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1930 if (brightness_switch_enabled)
1931 acpi_video_switch_brightness(video_device, event);
1932 acpi_bus_generate_proc_event(device, event, 0);
1933 keycode = KEY_BRIGHTNESS_ZERO;
1935 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1936 if (brightness_switch_enabled)
1937 acpi_video_switch_brightness(video_device, event);
1938 acpi_bus_generate_proc_event(device, event, 0);
1939 keycode = KEY_DISPLAY_OFF;
1942 keycode = KEY_UNKNOWN;
1943 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1944 "Unsupported event [0x%x]\n", event));
1948 acpi_notifier_call_chain(device, event, 0);
1949 input_report_key(input, keycode, 1);
1951 input_report_key(input, keycode, 0);
1957 static int instance;
1958 static int acpi_video_resume(struct acpi_device *device)
1960 struct acpi_video_bus *video;
1961 struct acpi_video_device *video_device;
1964 if (!device || !acpi_driver_data(device))
1967 video = acpi_driver_data(device);
1969 for (i = 0; i < video->attached_count; i++) {
1970 video_device = video->attached_array[i].bind_info;
1971 if (video_device && video_device->backlight)
1972 acpi_video_set_brightness(video_device->backlight);
1977 static int acpi_video_bus_add(struct acpi_device *device)
1980 struct acpi_video_bus *video;
1981 struct input_dev *input;
1984 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1988 /* a hack to fix the duplicate name "VID" problem on T61 */
1989 if (!strcmp(device->pnp.bus_id, "VID")) {
1991 device->pnp.bus_id[3] = '0' + instance;
1995 video->device = device;
1996 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1997 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1998 device->driver_data = video;
2000 acpi_video_bus_find_cap(video);
2001 error = acpi_video_bus_check(video);
2003 goto err_free_video;
2005 error = acpi_video_bus_add_fs(device);
2007 goto err_free_video;
2009 mutex_init(&video->device_list_lock);
2010 INIT_LIST_HEAD(&video->video_device_list);
2012 acpi_video_bus_get_devices(video, device);
2013 acpi_video_bus_start_devices(video);
2015 status = acpi_install_notify_handler(device->handle,
2017 acpi_video_bus_notify, video);
2018 if (ACPI_FAILURE(status)) {
2019 printk(KERN_ERR PREFIX
2020 "Error installing notify handler\n");
2022 goto err_stop_video;
2025 video->input = input = input_allocate_device();
2028 goto err_uninstall_notify;
2031 snprintf(video->phys, sizeof(video->phys),
2032 "%s/video/input0", acpi_device_hid(video->device));
2034 input->name = acpi_device_name(video->device);
2035 input->phys = video->phys;
2036 input->id.bustype = BUS_HOST;
2037 input->id.product = 0x06;
2038 input->dev.parent = &device->dev;
2039 input->evbit[0] = BIT(EV_KEY);
2040 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2041 set_bit(KEY_VIDEO_NEXT, input->keybit);
2042 set_bit(KEY_VIDEO_PREV, input->keybit);
2043 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2044 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2045 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2046 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2047 set_bit(KEY_DISPLAY_OFF, input->keybit);
2048 set_bit(KEY_UNKNOWN, input->keybit);
2050 error = input_register_device(input);
2052 goto err_free_input_dev;
2054 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2055 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2056 video->flags.multihead ? "yes" : "no",
2057 video->flags.rom ? "yes" : "no",
2058 video->flags.post ? "yes" : "no");
2063 input_free_device(input);
2064 err_uninstall_notify:
2065 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2066 acpi_video_bus_notify);
2068 acpi_video_bus_stop_devices(video);
2069 acpi_video_bus_put_devices(video);
2070 kfree(video->attached_array);
2071 acpi_video_bus_remove_fs(device);
2074 device->driver_data = NULL;
2079 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2081 acpi_status status = 0;
2082 struct acpi_video_bus *video = NULL;
2085 if (!device || !acpi_driver_data(device))
2088 video = acpi_driver_data(device);
2090 acpi_video_bus_stop_devices(video);
2092 status = acpi_remove_notify_handler(video->device->handle,
2094 acpi_video_bus_notify);
2096 acpi_video_bus_put_devices(video);
2097 acpi_video_bus_remove_fs(device);
2099 input_unregister_device(video->input);
2100 kfree(video->attached_array);
2106 static int __init acpi_video_init(void)
2110 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2111 if (!acpi_video_dir)
2113 acpi_video_dir->owner = THIS_MODULE;
2115 result = acpi_bus_register_driver(&acpi_video_bus);
2117 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2124 static void __exit acpi_video_exit(void)
2127 acpi_bus_unregister_driver(&acpi_video_bus);
2129 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2134 module_init(acpi_video_init);
2135 module_exit(acpi_video_exit);