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 <linux/sort.h>
40 #include <asm/uaccess.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device *device);
78 static int acpi_video_bus_remove(struct acpi_device *device, int type);
79 static int acpi_video_resume(struct acpi_device *device);
81 static const struct acpi_device_id video_device_ids[] = {
85 MODULE_DEVICE_TABLE(acpi, video_device_ids);
87 static struct acpi_driver acpi_video_bus = {
89 .class = ACPI_VIDEO_CLASS,
90 .ids = video_device_ids,
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
94 .resume = acpi_video_resume,
98 struct acpi_video_bus_flags {
99 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
105 struct acpi_video_bus_cap {
106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
115 struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment:4; /*This field differentiates the display type */
118 u32 display_type:4; /*Describe the specific type in use */
119 u32 vendor_specific:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device {
131 struct acpi_video_device_attrib attrib;
133 struct acpi_video_device *bind_info;
136 struct acpi_video_bus {
137 struct acpi_device *device;
139 struct acpi_video_enumerated_device *attached_array;
141 struct acpi_video_bus_cap cap;
142 struct acpi_video_bus_flags flags;
143 struct list_head video_device_list;
144 struct mutex device_list_lock; /* protects video_device_list */
145 struct proc_dir_entry *dir;
146 struct input_dev *input;
147 char phys[32]; /* for input device */
150 struct acpi_video_device_flags {
160 struct acpi_video_device_cap {
161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
164 u8 _BQC:1; /* Get current brightness level */
165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
171 struct acpi_video_device_brightness {
177 struct acpi_video_device {
178 unsigned long device_id;
179 struct acpi_video_device_flags flags;
180 struct acpi_video_device_cap cap;
181 struct list_head entry;
182 struct acpi_video_bus *video;
183 struct acpi_device *dev;
184 struct acpi_video_device_brightness *brightness;
185 struct backlight_device *backlight;
186 struct thermal_cooling_device *cdev;
187 struct output_device *output_dev;
191 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192 static struct file_operations acpi_video_bus_info_fops = {
193 .owner = THIS_MODULE,
194 .open = acpi_video_bus_info_open_fs,
197 .release = single_release,
200 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
201 static struct file_operations acpi_video_bus_ROM_fops = {
202 .owner = THIS_MODULE,
203 .open = acpi_video_bus_ROM_open_fs,
206 .release = single_release,
209 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
211 static struct file_operations acpi_video_bus_POST_info_fops = {
212 .owner = THIS_MODULE,
213 .open = acpi_video_bus_POST_info_open_fs,
216 .release = single_release,
219 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
220 static struct file_operations acpi_video_bus_POST_fops = {
221 .owner = THIS_MODULE,
222 .open = acpi_video_bus_POST_open_fs,
225 .release = single_release,
228 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
229 static struct file_operations acpi_video_bus_DOS_fops = {
230 .owner = THIS_MODULE,
231 .open = acpi_video_bus_DOS_open_fs,
234 .release = single_release,
238 static int acpi_video_device_info_open_fs(struct inode *inode,
240 static struct file_operations acpi_video_device_info_fops = {
241 .owner = THIS_MODULE,
242 .open = acpi_video_device_info_open_fs,
245 .release = single_release,
248 static int acpi_video_device_state_open_fs(struct inode *inode,
250 static struct file_operations acpi_video_device_state_fops = {
251 .owner = THIS_MODULE,
252 .open = acpi_video_device_state_open_fs,
255 .release = single_release,
258 static int acpi_video_device_brightness_open_fs(struct inode *inode,
260 static struct file_operations acpi_video_device_brightness_fops = {
261 .owner = THIS_MODULE,
262 .open = acpi_video_device_brightness_open_fs,
265 .release = single_release,
268 static int acpi_video_device_EDID_open_fs(struct inode *inode,
270 static struct file_operations acpi_video_device_EDID_fops = {
271 .owner = THIS_MODULE,
272 .open = acpi_video_device_EDID_open_fs,
275 .release = single_release,
278 static char device_decode[][30] = {
279 "motherboard VGA device",
285 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
286 static void acpi_video_device_rebind(struct acpi_video_bus *video);
287 static void acpi_video_device_bind(struct acpi_video_bus *video,
288 struct acpi_video_device *device);
289 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
290 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
292 static int acpi_video_device_lcd_get_level_current(
293 struct acpi_video_device *device,
294 unsigned long long *level);
295 static int acpi_video_get_next_level(struct acpi_video_device *device,
296 u32 level_current, u32 event);
297 static int acpi_video_switch_brightness(struct acpi_video_device *device,
299 static int acpi_video_device_get_state(struct acpi_video_device *device,
300 unsigned long long *state);
301 static int acpi_video_output_get(struct output_device *od);
302 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
304 /*backlight device sysfs support*/
305 static int acpi_video_get_brightness(struct backlight_device *bd)
307 unsigned long long cur_level;
309 struct acpi_video_device *vd =
310 (struct acpi_video_device *)bl_get_data(bd);
312 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
314 for (i = 2; i < vd->brightness->count; i++) {
315 if (vd->brightness->levels[i] == cur_level)
316 /* The first two entries are special - see page 575
317 of the ACPI spec 3.0 */
323 static int acpi_video_set_brightness(struct backlight_device *bd)
325 int request_level = bd->props.brightness + 2;
326 struct acpi_video_device *vd =
327 (struct acpi_video_device *)bl_get_data(bd);
329 return acpi_video_device_lcd_set_level(vd,
330 vd->brightness->levels[request_level]);
333 static struct backlight_ops acpi_backlight_ops = {
334 .get_brightness = acpi_video_get_brightness,
335 .update_status = acpi_video_set_brightness,
338 /*video output device sysfs support*/
339 static int acpi_video_output_get(struct output_device *od)
341 unsigned long long state;
342 struct acpi_video_device *vd =
343 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
344 acpi_video_device_get_state(vd, &state);
348 static int acpi_video_output_set(struct output_device *od)
350 unsigned long state = od->request_state;
351 struct acpi_video_device *vd=
352 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
353 return acpi_video_device_set_state(vd, state);
356 static struct output_properties acpi_output_properties = {
357 .set_state = acpi_video_output_set,
358 .get_status = acpi_video_output_get,
362 /* thermal cooling device callbacks */
363 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
365 struct acpi_device *device = cdev->devdata;
366 struct acpi_video_device *video = acpi_driver_data(device);
368 return sprintf(buf, "%d\n", video->brightness->count - 3);
371 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
373 struct acpi_device *device = cdev->devdata;
374 struct acpi_video_device *video = acpi_driver_data(device);
375 unsigned long long level;
378 if (acpi_video_device_lcd_get_level_current(video, &level))
380 for (state = 2; state < video->brightness->count; state++)
381 if (level == video->brightness->levels[state])
382 return sprintf(buf, "%d\n",
383 video->brightness->count - state - 1);
389 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
391 struct acpi_device *device = cdev->devdata;
392 struct acpi_video_device *video = acpi_driver_data(device);
395 if ( state >= video->brightness->count - 2)
398 state = video->brightness->count - state;
399 level = video->brightness->levels[state -1];
400 return acpi_video_device_lcd_set_level(video, level);
403 static struct thermal_cooling_device_ops video_cooling_ops = {
404 .get_max_state = video_get_max_state,
405 .get_cur_state = video_get_cur_state,
406 .set_cur_state = video_set_cur_state,
409 /* --------------------------------------------------------------------------
411 -------------------------------------------------------------------------- */
416 acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
420 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
426 acpi_video_device_get_state(struct acpi_video_device *device,
427 unsigned long long *state)
431 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
437 acpi_video_device_set_state(struct acpi_video_device *device, int state)
440 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
441 struct acpi_object_list args = { 1, &arg0 };
442 unsigned long long ret;
445 arg0.integer.value = state;
446 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
452 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
453 union acpi_object **levels)
456 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
457 union acpi_object *obj;
462 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
463 if (!ACPI_SUCCESS(status))
465 obj = (union acpi_object *)buffer.pointer;
466 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
467 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
477 kfree(buffer.pointer);
483 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
486 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
487 struct acpi_object_list args = { 1, &arg0 };
490 arg0.integer.value = level;
492 status = acpi_evaluate_object(device->dev->handle, "_BCM",
494 if (ACPI_FAILURE(status)) {
495 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
499 device->brightness->curr = level;
500 for (state = 2; state < device->brightness->count; state++)
501 if (level == device->brightness->levels[state]) {
502 device->backlight->props.brightness = state - 2;
506 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
511 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
512 unsigned long long *level)
514 acpi_status status = AE_OK;
516 if (device->cap._BQC) {
517 status = acpi_evaluate_integer(device->dev->handle, "_BQC",
519 if (ACPI_SUCCESS(status)) {
520 device->brightness->curr = *level;
524 * should we return an error or ignore this failure?
525 * dev->brightness->curr is a cached value which stores
526 * the correct current backlight level in most cases.
527 * ACPI video backlight still works w/ buggy _BQC.
528 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
530 ACPI_WARNING((AE_INFO, "Evaluating _BQC failed"));
531 device->cap._BQC = 0;
535 *level = device->brightness->curr;
540 acpi_video_device_EDID(struct acpi_video_device *device,
541 union acpi_object **edid, ssize_t length)
544 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
545 union acpi_object *obj;
546 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
547 struct acpi_object_list args = { 1, &arg0 };
555 arg0.integer.value = 1;
556 else if (length == 256)
557 arg0.integer.value = 2;
561 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
562 if (ACPI_FAILURE(status))
565 obj = buffer.pointer;
567 if (obj && obj->type == ACPI_TYPE_BUFFER)
570 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
581 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
584 unsigned long long tmp;
585 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
586 struct acpi_object_list args = { 1, &arg0 };
589 arg0.integer.value = option;
591 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
592 if (ACPI_SUCCESS(status))
593 status = tmp ? (-EINVAL) : (AE_OK);
599 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
603 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
609 acpi_video_bus_POST_options(struct acpi_video_bus *video,
610 unsigned long long *options)
614 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
622 * video : video bus device pointer
624 * 0. The system BIOS should NOT automatically switch(toggle)
625 * the active display output.
626 * 1. The system BIOS should automatically switch (toggle) the
627 * active display output. No switch event.
628 * 2. The _DGS value should be locked.
629 * 3. The system BIOS should not automatically switch (toggle) the
630 * active display output, but instead generate the display switch
633 * 0. The system BIOS should automatically control the brightness level
634 * of the LCD when the power changes from AC to DC
635 * 1. The system BIOS should NOT automatically control the brightness
636 * level of the LCD when the power changes from AC to DC.
642 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
644 acpi_integer status = 0;
645 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
646 struct acpi_object_list args = { 1, &arg0 };
649 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
653 arg0.integer.value = (lcd_flag << 2) | bios_flag;
654 video->dos_setting = arg0.integer.value;
655 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
662 * Simple comparison function used to sort backlight levels.
666 acpi_video_cmp_level(const void *a, const void *b)
668 return *(int *)a - *(int *)b;
673 * device : video output device (LCD, CRT, ..)
676 * Maximum brightness level
678 * Allocate and initialize device->brightness.
682 acpi_video_init_brightness(struct acpi_video_device *device)
684 union acpi_object *obj = NULL;
685 int i, max_level = 0, count = 0;
686 union acpi_object *o;
687 struct acpi_video_device_brightness *br = NULL;
689 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
690 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
691 "LCD brightness level\n"));
695 if (obj->package.count < 2)
698 br = kzalloc(sizeof(*br), GFP_KERNEL);
700 printk(KERN_ERR "can't allocate memory\n");
704 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
709 for (i = 0; i < obj->package.count; i++) {
710 o = (union acpi_object *)&obj->package.elements[i];
711 if (o->type != ACPI_TYPE_INTEGER) {
712 printk(KERN_ERR PREFIX "Invalid data\n");
715 br->levels[count] = (u32) o->integer.value;
717 if (br->levels[count] > max_level)
718 max_level = br->levels[count];
722 /* don't sort the first two brightness levels */
723 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
724 acpi_video_cmp_level, NULL);
727 goto out_free_levels;
730 device->brightness = br;
731 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
740 device->brightness = NULL;
747 * device : video output device (LCD, CRT, ..)
752 * Find out all required AML methods defined under the output
756 static void acpi_video_device_find_cap(struct acpi_video_device *device)
758 acpi_handle h_dummy1;
762 memset(&device->cap, 0, sizeof(device->cap));
764 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
765 device->cap._ADR = 1;
767 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
768 device->cap._BCL = 1;
770 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
771 device->cap._BCM = 1;
773 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
774 device->cap._BQC = 1;
775 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
776 device->cap._DDC = 1;
778 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
779 device->cap._DCS = 1;
781 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
782 device->cap._DGS = 1;
784 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
785 device->cap._DSS = 1;
788 if (acpi_video_backlight_support())
789 max_level = acpi_video_init_brightness(device);
791 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
793 static int count = 0;
795 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
799 sprintf(name, "acpi_video%d", count++);
800 device->backlight = backlight_device_register(name,
801 NULL, device, &acpi_backlight_ops);
802 device->backlight->props.max_brightness = device->brightness->count-3;
804 * If there exists the _BQC object, the _BQC object will be
805 * called to get the current backlight brightness. Otherwise
806 * the brightness will be set to the maximum.
808 if (device->cap._BQC)
809 device->backlight->props.brightness =
810 acpi_video_get_brightness(device->backlight);
812 device->backlight->props.brightness =
813 device->backlight->props.max_brightness;
814 backlight_update_status(device->backlight);
817 device->cdev = thermal_cooling_device_register("LCD",
818 device->dev, &video_cooling_ops);
819 if (IS_ERR(device->cdev))
822 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
824 result = sysfs_create_link(&device->dev->dev.kobj,
825 &device->cdev->device.kobj,
828 printk(KERN_ERR PREFIX "Create sysfs link\n");
829 result = sysfs_create_link(&device->cdev->device.kobj,
830 &device->dev->dev.kobj, "device");
832 printk(KERN_ERR PREFIX "Create sysfs link\n");
836 if (acpi_video_display_switch_support()) {
838 if (device->cap._DCS && device->cap._DSS) {
841 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
844 sprintf(name, "acpi_video%d", count++);
845 device->output_dev = video_output_register(name,
846 NULL, device, &acpi_output_properties);
854 * device : video output device (VGA)
859 * Find out all required AML methods defined under the video bus device.
862 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
864 acpi_handle h_dummy1;
866 memset(&video->cap, 0, sizeof(video->cap));
867 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
870 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
873 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
876 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
879 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
882 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
888 * Check whether the video bus device has required AML method to
889 * support the desired features
892 static int acpi_video_bus_check(struct acpi_video_bus *video)
894 acpi_status status = -ENOENT;
900 dev = acpi_get_physical_pci_device(video->device->handle);
905 /* Since there is no HID, CID and so on for VGA driver, we have
906 * to check well known required nodes.
909 /* Does this device support video switching? */
910 if (video->cap._DOS) {
911 video->flags.multihead = 1;
915 /* Does this device support retrieving a video ROM? */
916 if (video->cap._ROM) {
917 video->flags.rom = 1;
921 /* Does this device support configuring which video device to POST? */
922 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
923 video->flags.post = 1;
930 /* --------------------------------------------------------------------------
932 -------------------------------------------------------------------------- */
934 static struct proc_dir_entry *acpi_video_dir;
938 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
940 struct acpi_video_device *dev = seq->private;
946 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
947 seq_printf(seq, "type: ");
949 seq_printf(seq, "CRT\n");
950 else if (dev->flags.lcd)
951 seq_printf(seq, "LCD\n");
952 else if (dev->flags.tvout)
953 seq_printf(seq, "TVOUT\n");
954 else if (dev->flags.dvi)
955 seq_printf(seq, "DVI\n");
957 seq_printf(seq, "UNKNOWN\n");
959 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
966 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
968 return single_open(file, acpi_video_device_info_seq_show,
972 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
975 struct acpi_video_device *dev = seq->private;
976 unsigned long long state;
982 status = acpi_video_device_get_state(dev, &state);
983 seq_printf(seq, "state: ");
984 if (ACPI_SUCCESS(status))
985 seq_printf(seq, "0x%02llx\n", state);
987 seq_printf(seq, "<not supported>\n");
989 status = acpi_video_device_query(dev, &state);
990 seq_printf(seq, "query: ");
991 if (ACPI_SUCCESS(status))
992 seq_printf(seq, "0x%02llx\n", state);
994 seq_printf(seq, "<not supported>\n");
1001 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
1003 return single_open(file, acpi_video_device_state_seq_show,
1008 acpi_video_device_write_state(struct file *file,
1009 const char __user * buffer,
1010 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[12] = { 0 };
1019 if (!dev || count + 1 > sizeof str)
1022 if (copy_from_user(str, buffer, count))
1026 state = simple_strtoul(str, NULL, 0);
1027 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1029 status = acpi_video_device_set_state(dev, state);
1038 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1040 struct acpi_video_device *dev = seq->private;
1044 if (!dev || !dev->brightness) {
1045 seq_printf(seq, "<not supported>\n");
1049 seq_printf(seq, "levels: ");
1050 for (i = 2; i < dev->brightness->count; i++)
1051 seq_printf(seq, " %d", dev->brightness->levels[i]);
1052 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1058 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1060 return single_open(file, acpi_video_device_brightness_seq_show,
1065 acpi_video_device_write_brightness(struct file *file,
1066 const char __user * buffer,
1067 size_t count, loff_t * data)
1069 struct seq_file *m = file->private_data;
1070 struct acpi_video_device *dev = m->private;
1071 char str[5] = { 0 };
1072 unsigned int level = 0;
1076 if (!dev || !dev->brightness || count + 1 > sizeof str)
1079 if (copy_from_user(str, buffer, count))
1083 level = simple_strtoul(str, NULL, 0);
1088 /* validate through the list of available levels */
1089 for (i = 2; i < dev->brightness->count; i++)
1090 if (level == dev->brightness->levels[i]) {
1091 if (!acpi_video_device_lcd_set_level(dev, level))
1099 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1101 struct acpi_video_device *dev = seq->private;
1104 union acpi_object *edid = NULL;
1110 status = acpi_video_device_EDID(dev, &edid, 128);
1111 if (ACPI_FAILURE(status)) {
1112 status = acpi_video_device_EDID(dev, &edid, 256);
1115 if (ACPI_FAILURE(status)) {
1119 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1120 for (i = 0; i < edid->buffer.length; i++)
1121 seq_putc(seq, edid->buffer.pointer[i]);
1126 seq_printf(seq, "<not supported>\n");
1134 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1136 return single_open(file, acpi_video_device_EDID_seq_show,
1140 static int acpi_video_device_add_fs(struct acpi_device *device)
1142 struct proc_dir_entry *entry, *device_dir;
1143 struct acpi_video_device *vid_dev;
1145 vid_dev = acpi_driver_data(device);
1149 device_dir = proc_mkdir(acpi_device_bid(device),
1150 vid_dev->video->dir);
1154 device_dir->owner = THIS_MODULE;
1157 entry = proc_create_data("info", S_IRUGO, device_dir,
1158 &acpi_video_device_info_fops, acpi_driver_data(device));
1160 goto err_remove_dir;
1163 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1164 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1166 &acpi_video_device_state_fops,
1167 acpi_driver_data(device));
1169 goto err_remove_info;
1171 /* 'brightness' [R/W] */
1172 acpi_video_device_brightness_fops.write =
1173 acpi_video_device_write_brightness;
1174 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1176 &acpi_video_device_brightness_fops,
1177 acpi_driver_data(device));
1179 goto err_remove_state;
1182 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1183 &acpi_video_device_EDID_fops,
1184 acpi_driver_data(device));
1186 goto err_remove_brightness;
1188 acpi_device_dir(device) = device_dir;
1192 err_remove_brightness:
1193 remove_proc_entry("brightness", device_dir);
1195 remove_proc_entry("state", device_dir);
1197 remove_proc_entry("info", device_dir);
1199 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1203 static int acpi_video_device_remove_fs(struct acpi_device *device)
1205 struct acpi_video_device *vid_dev;
1206 struct proc_dir_entry *device_dir;
1208 vid_dev = acpi_driver_data(device);
1209 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1212 device_dir = acpi_device_dir(device);
1214 remove_proc_entry("info", device_dir);
1215 remove_proc_entry("state", device_dir);
1216 remove_proc_entry("brightness", device_dir);
1217 remove_proc_entry("EDID", device_dir);
1218 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1219 acpi_device_dir(device) = NULL;
1226 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1228 struct acpi_video_bus *video = seq->private;
1234 seq_printf(seq, "Switching heads: %s\n",
1235 video->flags.multihead ? "yes" : "no");
1236 seq_printf(seq, "Video ROM: %s\n",
1237 video->flags.rom ? "yes" : "no");
1238 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1239 video->flags.post ? "yes" : "no");
1245 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1247 return single_open(file, acpi_video_bus_info_seq_show,
1251 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1253 struct acpi_video_bus *video = seq->private;
1259 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1260 seq_printf(seq, "<TODO>\n");
1266 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1268 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1271 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1273 struct acpi_video_bus *video = seq->private;
1274 unsigned long long options;
1281 status = acpi_video_bus_POST_options(video, &options);
1282 if (ACPI_SUCCESS(status)) {
1283 if (!(options & 1)) {
1284 printk(KERN_WARNING PREFIX
1285 "The motherboard VGA device is not listed as a possible POST device.\n");
1286 printk(KERN_WARNING PREFIX
1287 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1289 printk(KERN_WARNING "%llx\n", options);
1290 seq_printf(seq, "can POST: <integrated video>");
1292 seq_printf(seq, " <PCI video>");
1294 seq_printf(seq, " <AGP video>");
1295 seq_putc(seq, '\n');
1297 seq_printf(seq, "<not supported>\n");
1303 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1305 return single_open(file, acpi_video_bus_POST_info_seq_show,
1309 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1311 struct acpi_video_bus *video = seq->private;
1313 unsigned long long id;
1319 status = acpi_video_bus_get_POST(video, &id);
1320 if (!ACPI_SUCCESS(status)) {
1321 seq_printf(seq, "<not supported>\n");
1324 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1330 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1332 struct acpi_video_bus *video = seq->private;
1335 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1340 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1342 return single_open(file, acpi_video_bus_POST_seq_show,
1346 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1348 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1352 acpi_video_bus_write_POST(struct file *file,
1353 const char __user * buffer,
1354 size_t count, loff_t * data)
1357 struct seq_file *m = file->private_data;
1358 struct acpi_video_bus *video = m->private;
1359 char str[12] = { 0 };
1360 unsigned long long opt, options;
1363 if (!video || count + 1 > sizeof str)
1366 status = acpi_video_bus_POST_options(video, &options);
1367 if (!ACPI_SUCCESS(status))
1370 if (copy_from_user(str, buffer, count))
1374 opt = strtoul(str, NULL, 0);
1378 /* just in case an OEM 'forgot' the motherboard... */
1381 if (options & (1ul << opt)) {
1382 status = acpi_video_bus_set_POST(video, opt);
1383 if (!ACPI_SUCCESS(status))
1392 acpi_video_bus_write_DOS(struct file *file,
1393 const char __user * buffer,
1394 size_t count, loff_t * data)
1397 struct seq_file *m = file->private_data;
1398 struct acpi_video_bus *video = m->private;
1399 char str[12] = { 0 };
1403 if (!video || count + 1 > sizeof str)
1406 if (copy_from_user(str, buffer, count))
1410 opt = strtoul(str, NULL, 0);
1414 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1416 if (!ACPI_SUCCESS(status))
1422 static int acpi_video_bus_add_fs(struct acpi_device *device)
1424 struct acpi_video_bus *video = acpi_driver_data(device);
1425 struct proc_dir_entry *device_dir;
1426 struct proc_dir_entry *entry;
1428 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1432 device_dir->owner = THIS_MODULE;
1435 entry = proc_create_data("info", S_IRUGO, device_dir,
1436 &acpi_video_bus_info_fops,
1437 acpi_driver_data(device));
1439 goto err_remove_dir;
1442 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1443 &acpi_video_bus_ROM_fops,
1444 acpi_driver_data(device));
1446 goto err_remove_info;
1448 /* 'POST_info' [R] */
1449 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1450 &acpi_video_bus_POST_info_fops,
1451 acpi_driver_data(device));
1453 goto err_remove_rom;
1456 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1457 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1459 &acpi_video_bus_POST_fops,
1460 acpi_driver_data(device));
1462 goto err_remove_post_info;
1465 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1466 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1468 &acpi_video_bus_DOS_fops,
1469 acpi_driver_data(device));
1471 goto err_remove_post;
1473 video->dir = acpi_device_dir(device) = device_dir;
1477 remove_proc_entry("POST", device_dir);
1478 err_remove_post_info:
1479 remove_proc_entry("POST_info", device_dir);
1481 remove_proc_entry("ROM", device_dir);
1483 remove_proc_entry("info", device_dir);
1485 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1489 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1491 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1494 remove_proc_entry("info", device_dir);
1495 remove_proc_entry("ROM", device_dir);
1496 remove_proc_entry("POST_info", device_dir);
1497 remove_proc_entry("POST", device_dir);
1498 remove_proc_entry("DOS", device_dir);
1499 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1500 acpi_device_dir(device) = NULL;
1506 /* --------------------------------------------------------------------------
1508 -------------------------------------------------------------------------- */
1510 /* device interface */
1511 static struct acpi_video_device_attrib*
1512 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1514 struct acpi_video_enumerated_device *ids;
1517 for (i = 0; i < video->attached_count; i++) {
1518 ids = &video->attached_array[i];
1519 if ((ids->value.int_val & 0xffff) == device_id)
1520 return &ids->value.attrib;
1527 acpi_video_bus_get_one_device(struct acpi_device *device,
1528 struct acpi_video_bus *video)
1530 unsigned long long device_id;
1532 struct acpi_video_device *data;
1533 struct acpi_video_device_attrib* attribute;
1535 if (!device || !video)
1539 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1540 if (ACPI_SUCCESS(status)) {
1542 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1546 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1547 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1548 device->driver_data = data;
1550 data->device_id = device_id;
1551 data->video = video;
1554 attribute = acpi_video_get_device_attr(video, device_id);
1556 if((attribute != NULL) && attribute->device_id_scheme) {
1557 switch (attribute->display_type) {
1558 case ACPI_VIDEO_DISPLAY_CRT:
1559 data->flags.crt = 1;
1561 case ACPI_VIDEO_DISPLAY_TV:
1562 data->flags.tvout = 1;
1564 case ACPI_VIDEO_DISPLAY_DVI:
1565 data->flags.dvi = 1;
1567 case ACPI_VIDEO_DISPLAY_LCD:
1568 data->flags.lcd = 1;
1571 data->flags.unknown = 1;
1574 if(attribute->bios_can_detect)
1575 data->flags.bios = 1;
1577 data->flags.unknown = 1;
1579 acpi_video_device_bind(video, data);
1580 acpi_video_device_find_cap(data);
1582 status = acpi_install_notify_handler(device->handle,
1584 acpi_video_device_notify,
1586 if (ACPI_FAILURE(status)) {
1587 printk(KERN_ERR PREFIX
1588 "Error installing notify handler\n");
1589 if(data->brightness)
1590 kfree(data->brightness->levels);
1591 kfree(data->brightness);
1596 mutex_lock(&video->device_list_lock);
1597 list_add_tail(&data->entry, &video->video_device_list);
1598 mutex_unlock(&video->device_list_lock);
1600 acpi_video_device_add_fs(device);
1610 * video : video bus device
1615 * Enumerate the video device list of the video bus,
1616 * bind the ids with the corresponding video devices
1617 * under the video bus.
1620 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1622 struct acpi_video_device *dev;
1624 mutex_lock(&video->device_list_lock);
1626 list_for_each_entry(dev, &video->video_device_list, entry)
1627 acpi_video_device_bind(video, dev);
1629 mutex_unlock(&video->device_list_lock);
1634 * video : video bus device
1635 * device : video output device under the video
1641 * Bind the ids with the corresponding video devices
1642 * under the video bus.
1646 acpi_video_device_bind(struct acpi_video_bus *video,
1647 struct acpi_video_device *device)
1649 struct acpi_video_enumerated_device *ids;
1652 for (i = 0; i < video->attached_count; i++) {
1653 ids = &video->attached_array[i];
1654 if (device->device_id == (ids->value.int_val & 0xffff)) {
1655 ids->bind_info = device;
1656 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1663 * video : video bus device
1668 * Call _DOD to enumerate all devices attached to display adapter
1672 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1677 struct acpi_video_enumerated_device *active_list;
1678 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1679 union acpi_object *dod = NULL;
1680 union acpi_object *obj;
1682 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1683 if (!ACPI_SUCCESS(status)) {
1684 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1688 dod = buffer.pointer;
1689 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1690 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1695 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1696 dod->package.count));
1698 active_list = kcalloc(1 + dod->package.count,
1699 sizeof(struct acpi_video_enumerated_device),
1707 for (i = 0; i < dod->package.count; i++) {
1708 obj = &dod->package.elements[i];
1710 if (obj->type != ACPI_TYPE_INTEGER) {
1711 printk(KERN_ERR PREFIX
1712 "Invalid _DOD data in element %d\n", i);
1716 active_list[count].value.int_val = obj->integer.value;
1717 active_list[count].bind_info = NULL;
1718 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1719 (int)obj->integer.value));
1723 kfree(video->attached_array);
1725 video->attached_array = active_list;
1726 video->attached_count = count;
1729 kfree(buffer.pointer);
1734 acpi_video_get_next_level(struct acpi_video_device *device,
1735 u32 level_current, u32 event)
1737 int min, max, min_above, max_below, i, l, delta = 255;
1738 max = max_below = 0;
1739 min = min_above = 255;
1740 /* Find closest level to level_current */
1741 for (i = 2; i < device->brightness->count; i++) {
1742 l = device->brightness->levels[i];
1743 if (abs(l - level_current) < abs(delta)) {
1744 delta = l - level_current;
1749 /* Ajust level_current to closest available level */
1750 level_current += delta;
1751 for (i = 2; i < device->brightness->count; i++) {
1752 l = device->brightness->levels[i];
1757 if (l < min_above && l > level_current)
1759 if (l > max_below && l < level_current)
1764 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1765 return (level_current < max) ? min_above : min;
1766 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1767 return (level_current < max) ? min_above : max;
1768 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1769 return (level_current > min) ? max_below : min;
1770 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1771 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1774 return level_current;
1779 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1781 unsigned long long level_current, level_next;
1782 int result = -EINVAL;
1784 if (!device->brightness)
1787 result = acpi_video_device_lcd_get_level_current(device,
1792 level_next = acpi_video_get_next_level(device, level_current, event);
1794 result = acpi_video_device_lcd_set_level(device, level_next);
1798 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1804 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1805 struct acpi_device *device)
1808 struct acpi_device *dev;
1810 acpi_video_device_enumerate(video);
1812 list_for_each_entry(dev, &device->children, node) {
1814 status = acpi_video_bus_get_one_device(dev, video);
1815 if (ACPI_FAILURE(status)) {
1816 printk(KERN_WARNING PREFIX
1817 "Cant attach device");
1824 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1827 struct acpi_video_bus *video;
1830 if (!device || !device->video)
1833 video = device->video;
1835 acpi_video_device_remove_fs(device->dev);
1837 status = acpi_remove_notify_handler(device->dev->handle,
1839 acpi_video_device_notify);
1840 backlight_device_unregister(device->backlight);
1842 sysfs_remove_link(&device->dev->dev.kobj,
1844 sysfs_remove_link(&device->cdev->device.kobj,
1846 thermal_cooling_device_unregister(device->cdev);
1847 device->cdev = NULL;
1849 video_output_unregister(device->output_dev);
1854 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1857 struct acpi_video_device *dev, *next;
1859 mutex_lock(&video->device_list_lock);
1861 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1863 status = acpi_video_bus_put_one_device(dev);
1864 if (ACPI_FAILURE(status))
1865 printk(KERN_WARNING PREFIX
1866 "hhuuhhuu bug in acpi video driver.\n");
1868 if (dev->brightness) {
1869 kfree(dev->brightness->levels);
1870 kfree(dev->brightness);
1872 list_del(&dev->entry);
1876 mutex_unlock(&video->device_list_lock);
1881 /* acpi_video interface */
1883 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1885 return acpi_video_bus_DOS(video, 0, 0);
1888 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1890 return acpi_video_bus_DOS(video, 0, 1);
1893 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1895 struct acpi_video_bus *video = data;
1896 struct acpi_device *device = NULL;
1897 struct input_dev *input;
1903 device = video->device;
1904 input = video->input;
1907 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1908 * most likely via hotkey. */
1909 acpi_bus_generate_proc_event(device, event, 0);
1910 keycode = KEY_SWITCHVIDEOMODE;
1913 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1915 acpi_video_device_enumerate(video);
1916 acpi_video_device_rebind(video);
1917 acpi_bus_generate_proc_event(device, event, 0);
1918 keycode = KEY_SWITCHVIDEOMODE;
1921 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1922 acpi_bus_generate_proc_event(device, event, 0);
1923 keycode = KEY_SWITCHVIDEOMODE;
1925 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1926 acpi_bus_generate_proc_event(device, event, 0);
1927 keycode = KEY_VIDEO_NEXT;
1929 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1930 acpi_bus_generate_proc_event(device, event, 0);
1931 keycode = KEY_VIDEO_PREV;
1935 keycode = KEY_UNKNOWN;
1936 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1937 "Unsupported event [0x%x]\n", event));
1941 acpi_notifier_call_chain(device, event, 0);
1942 input_report_key(input, keycode, 1);
1944 input_report_key(input, keycode, 0);
1950 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1952 struct acpi_video_device *video_device = data;
1953 struct acpi_device *device = NULL;
1954 struct acpi_video_bus *bus;
1955 struct input_dev *input;
1961 device = video_device->dev;
1962 bus = video_device->video;
1966 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1967 if (brightness_switch_enabled)
1968 acpi_video_switch_brightness(video_device, event);
1969 acpi_bus_generate_proc_event(device, event, 0);
1970 keycode = KEY_BRIGHTNESS_CYCLE;
1972 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1973 if (brightness_switch_enabled)
1974 acpi_video_switch_brightness(video_device, event);
1975 acpi_bus_generate_proc_event(device, event, 0);
1976 keycode = KEY_BRIGHTNESSUP;
1978 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1979 if (brightness_switch_enabled)
1980 acpi_video_switch_brightness(video_device, event);
1981 acpi_bus_generate_proc_event(device, event, 0);
1982 keycode = KEY_BRIGHTNESSDOWN;
1984 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1985 if (brightness_switch_enabled)
1986 acpi_video_switch_brightness(video_device, event);
1987 acpi_bus_generate_proc_event(device, event, 0);
1988 keycode = KEY_BRIGHTNESS_ZERO;
1990 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1991 if (brightness_switch_enabled)
1992 acpi_video_switch_brightness(video_device, event);
1993 acpi_bus_generate_proc_event(device, event, 0);
1994 keycode = KEY_DISPLAY_OFF;
1997 keycode = KEY_UNKNOWN;
1998 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1999 "Unsupported event [0x%x]\n", event));
2003 acpi_notifier_call_chain(device, event, 0);
2004 input_report_key(input, keycode, 1);
2006 input_report_key(input, keycode, 0);
2012 static int instance;
2013 static int acpi_video_resume(struct acpi_device *device)
2015 struct acpi_video_bus *video;
2016 struct acpi_video_device *video_device;
2019 if (!device || !acpi_driver_data(device))
2022 video = acpi_driver_data(device);
2024 for (i = 0; i < video->attached_count; i++) {
2025 video_device = video->attached_array[i].bind_info;
2026 if (video_device && video_device->backlight)
2027 acpi_video_set_brightness(video_device->backlight);
2032 static int acpi_video_bus_add(struct acpi_device *device)
2035 struct acpi_video_bus *video;
2036 struct input_dev *input;
2039 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2043 /* a hack to fix the duplicate name "VID" problem on T61 */
2044 if (!strcmp(device->pnp.bus_id, "VID")) {
2046 device->pnp.bus_id[3] = '0' + instance;
2049 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2050 if (!strcmp(device->pnp.bus_id, "VGA")) {
2052 device->pnp.bus_id[3] = '0' + instance;
2056 video->device = device;
2057 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2058 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2059 device->driver_data = video;
2061 acpi_video_bus_find_cap(video);
2062 error = acpi_video_bus_check(video);
2064 goto err_free_video;
2066 error = acpi_video_bus_add_fs(device);
2068 goto err_free_video;
2070 mutex_init(&video->device_list_lock);
2071 INIT_LIST_HEAD(&video->video_device_list);
2073 acpi_video_bus_get_devices(video, device);
2074 acpi_video_bus_start_devices(video);
2076 status = acpi_install_notify_handler(device->handle,
2078 acpi_video_bus_notify, video);
2079 if (ACPI_FAILURE(status)) {
2080 printk(KERN_ERR PREFIX
2081 "Error installing notify handler\n");
2083 goto err_stop_video;
2086 video->input = input = input_allocate_device();
2089 goto err_uninstall_notify;
2092 snprintf(video->phys, sizeof(video->phys),
2093 "%s/video/input0", acpi_device_hid(video->device));
2095 input->name = acpi_device_name(video->device);
2096 input->phys = video->phys;
2097 input->id.bustype = BUS_HOST;
2098 input->id.product = 0x06;
2099 input->dev.parent = &device->dev;
2100 input->evbit[0] = BIT(EV_KEY);
2101 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2102 set_bit(KEY_VIDEO_NEXT, input->keybit);
2103 set_bit(KEY_VIDEO_PREV, input->keybit);
2104 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2105 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2106 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2107 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2108 set_bit(KEY_DISPLAY_OFF, input->keybit);
2109 set_bit(KEY_UNKNOWN, input->keybit);
2111 error = input_register_device(input);
2113 goto err_free_input_dev;
2115 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2116 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2117 video->flags.multihead ? "yes" : "no",
2118 video->flags.rom ? "yes" : "no",
2119 video->flags.post ? "yes" : "no");
2124 input_free_device(input);
2125 err_uninstall_notify:
2126 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2127 acpi_video_bus_notify);
2129 acpi_video_bus_stop_devices(video);
2130 acpi_video_bus_put_devices(video);
2131 kfree(video->attached_array);
2132 acpi_video_bus_remove_fs(device);
2135 device->driver_data = NULL;
2140 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2142 acpi_status status = 0;
2143 struct acpi_video_bus *video = NULL;
2146 if (!device || !acpi_driver_data(device))
2149 video = acpi_driver_data(device);
2151 acpi_video_bus_stop_devices(video);
2153 status = acpi_remove_notify_handler(video->device->handle,
2155 acpi_video_bus_notify);
2157 acpi_video_bus_put_devices(video);
2158 acpi_video_bus_remove_fs(device);
2160 input_unregister_device(video->input);
2161 kfree(video->attached_array);
2167 static int __init acpi_video_init(void)
2171 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2172 if (!acpi_video_dir)
2174 acpi_video_dir->owner = THIS_MODULE;
2176 result = acpi_bus_register_driver(&acpi_video_bus);
2178 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2185 static void __exit acpi_video_exit(void)
2188 acpi_bus_unregister_driver(&acpi_video_bus);
2190 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2195 module_init(acpi_video_init);
2196 module_exit(acpi_video_exit);