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 <linux/pci.h>
41 #include <linux/pci_ids.h>
42 #include <asm/uaccess.h>
44 #include <acpi/acpi_bus.h>
45 #include <acpi/acpi_drivers.h>
47 #define ACPI_VIDEO_CLASS "video"
48 #define ACPI_VIDEO_BUS_NAME "Video Bus"
49 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
50 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
51 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
52 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
53 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
54 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
56 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
57 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
58 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
59 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
60 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
62 #define MAX_NAME_LEN 20
64 #define ACPI_VIDEO_DISPLAY_CRT 1
65 #define ACPI_VIDEO_DISPLAY_TV 2
66 #define ACPI_VIDEO_DISPLAY_DVI 3
67 #define ACPI_VIDEO_DISPLAY_LCD 4
69 #define _COMPONENT ACPI_VIDEO_COMPONENT
70 ACPI_MODULE_NAME("video");
72 MODULE_AUTHOR("Bruno Ducrot");
73 MODULE_DESCRIPTION("ACPI Video Driver");
74 MODULE_LICENSE("GPL");
76 static int brightness_switch_enabled = 1;
77 module_param(brightness_switch_enabled, bool, 0644);
79 static int acpi_video_bus_add(struct acpi_device *device);
80 static int acpi_video_bus_remove(struct acpi_device *device, int type);
81 static int acpi_video_resume(struct acpi_device *device);
83 static const struct acpi_device_id video_device_ids[] = {
87 MODULE_DEVICE_TABLE(acpi, video_device_ids);
89 static struct acpi_driver acpi_video_bus = {
91 .class = ACPI_VIDEO_CLASS,
92 .ids = video_device_ids,
94 .add = acpi_video_bus_add,
95 .remove = acpi_video_bus_remove,
96 .resume = acpi_video_resume,
100 struct acpi_video_bus_flags {
101 u8 multihead:1; /* can switch video heads */
102 u8 rom:1; /* can retrieve a video rom */
103 u8 post:1; /* can configure the head to */
107 struct acpi_video_bus_cap {
108 u8 _DOS:1; /*Enable/Disable output switching */
109 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM:1; /*Get ROM Data */
111 u8 _GPD:1; /*Get POST Device */
112 u8 _SPD:1; /*Set POST Device */
113 u8 _VPO:1; /*Video POST Options */
117 struct acpi_video_device_attrib {
118 u32 display_index:4; /* A zero-based instance of the Display */
119 u32 display_port_attachment:4; /*This field differentiates the display type */
120 u32 display_type:4; /*Describe the specific type in use */
121 u32 vendor_specific:4; /*Chipset Vendor Specific */
122 u32 bios_can_detect:1; /*BIOS can detect the device */
123 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
125 u32 pipe_id:3; /*For VGA multiple-head devices. */
126 u32 reserved:10; /*Must be 0 */
127 u32 device_id_scheme:1; /*Device ID Scheme */
130 struct acpi_video_enumerated_device {
133 struct acpi_video_device_attrib attrib;
135 struct acpi_video_device *bind_info;
138 struct acpi_video_bus {
139 struct acpi_device *device;
141 struct acpi_video_enumerated_device *attached_array;
143 struct acpi_video_bus_cap cap;
144 struct acpi_video_bus_flags flags;
145 struct list_head video_device_list;
146 struct mutex device_list_lock; /* protects video_device_list */
147 struct proc_dir_entry *dir;
148 struct input_dev *input;
149 char phys[32]; /* for input device */
152 struct acpi_video_device_flags {
162 struct acpi_video_device_cap {
163 u8 _ADR:1; /*Return the unique ID */
164 u8 _BCL:1; /*Query list of brightness control levels supported */
165 u8 _BCM:1; /*Set the brightness level */
166 u8 _BQC:1; /* Get current brightness level */
167 u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
168 u8 _DDC:1; /*Return the EDID for this device */
169 u8 _DCS:1; /*Return status of output device */
170 u8 _DGS:1; /*Query graphics state */
171 u8 _DSS:1; /*Device state set */
174 struct acpi_video_brightness_flags {
175 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
176 u8 _BCL_reversed:1; /* _BCL package is in a reversed order*/
177 u8 _BCL_use_index:1; /* levels in _BCL are index values */
178 u8 _BCM_use_index:1; /* input of _BCM is an index value */
179 u8 _BQC_use_index:1; /* _BQC returns an index value */
182 struct acpi_video_device_brightness {
186 struct acpi_video_brightness_flags flags;
189 struct acpi_video_device {
190 unsigned long device_id;
191 struct acpi_video_device_flags flags;
192 struct acpi_video_device_cap cap;
193 struct list_head entry;
194 struct acpi_video_bus *video;
195 struct acpi_device *dev;
196 struct acpi_video_device_brightness *brightness;
197 struct backlight_device *backlight;
198 struct thermal_cooling_device *cdev;
199 struct output_device *output_dev;
203 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
204 static struct file_operations acpi_video_bus_info_fops = {
205 .owner = THIS_MODULE,
206 .open = acpi_video_bus_info_open_fs,
209 .release = single_release,
212 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
213 static struct file_operations acpi_video_bus_ROM_fops = {
214 .owner = THIS_MODULE,
215 .open = acpi_video_bus_ROM_open_fs,
218 .release = single_release,
221 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
223 static struct file_operations acpi_video_bus_POST_info_fops = {
224 .owner = THIS_MODULE,
225 .open = acpi_video_bus_POST_info_open_fs,
228 .release = single_release,
231 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
232 static struct file_operations acpi_video_bus_POST_fops = {
233 .owner = THIS_MODULE,
234 .open = acpi_video_bus_POST_open_fs,
237 .release = single_release,
240 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
241 static struct file_operations acpi_video_bus_DOS_fops = {
242 .owner = THIS_MODULE,
243 .open = acpi_video_bus_DOS_open_fs,
246 .release = single_release,
250 static int acpi_video_device_info_open_fs(struct inode *inode,
252 static struct file_operations acpi_video_device_info_fops = {
253 .owner = THIS_MODULE,
254 .open = acpi_video_device_info_open_fs,
257 .release = single_release,
260 static int acpi_video_device_state_open_fs(struct inode *inode,
262 static struct file_operations acpi_video_device_state_fops = {
263 .owner = THIS_MODULE,
264 .open = acpi_video_device_state_open_fs,
267 .release = single_release,
270 static int acpi_video_device_brightness_open_fs(struct inode *inode,
272 static struct file_operations acpi_video_device_brightness_fops = {
273 .owner = THIS_MODULE,
274 .open = acpi_video_device_brightness_open_fs,
277 .release = single_release,
280 static int acpi_video_device_EDID_open_fs(struct inode *inode,
282 static struct file_operations acpi_video_device_EDID_fops = {
283 .owner = THIS_MODULE,
284 .open = acpi_video_device_EDID_open_fs,
287 .release = single_release,
290 static char device_decode[][30] = {
291 "motherboard VGA device",
297 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
298 static void acpi_video_device_rebind(struct acpi_video_bus *video);
299 static void acpi_video_device_bind(struct acpi_video_bus *video,
300 struct acpi_video_device *device);
301 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
302 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
304 static int acpi_video_device_lcd_get_level_current(
305 struct acpi_video_device *device,
306 unsigned long long *level);
307 static int acpi_video_get_next_level(struct acpi_video_device *device,
308 u32 level_current, u32 event);
309 static int acpi_video_switch_brightness(struct acpi_video_device *device,
311 static int acpi_video_device_get_state(struct acpi_video_device *device,
312 unsigned long long *state);
313 static int acpi_video_output_get(struct output_device *od);
314 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
316 /*backlight device sysfs support*/
317 static int acpi_video_get_brightness(struct backlight_device *bd)
319 unsigned long long cur_level;
321 struct acpi_video_device *vd =
322 (struct acpi_video_device *)bl_get_data(bd);
324 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
326 for (i = 2; i < vd->brightness->count; i++) {
327 if (vd->brightness->levels[i] == cur_level)
328 /* The first two entries are special - see page 575
329 of the ACPI spec 3.0 */
335 static int acpi_video_set_brightness(struct backlight_device *bd)
337 int request_level = bd->props.brightness + 2;
338 struct acpi_video_device *vd =
339 (struct acpi_video_device *)bl_get_data(bd);
341 return acpi_video_device_lcd_set_level(vd,
342 vd->brightness->levels[request_level]);
345 static struct backlight_ops acpi_backlight_ops = {
346 .get_brightness = acpi_video_get_brightness,
347 .update_status = acpi_video_set_brightness,
350 /*video output device sysfs support*/
351 static int acpi_video_output_get(struct output_device *od)
353 unsigned long long state;
354 struct acpi_video_device *vd =
355 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
356 acpi_video_device_get_state(vd, &state);
360 static int acpi_video_output_set(struct output_device *od)
362 unsigned long state = od->request_state;
363 struct acpi_video_device *vd=
364 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
365 return acpi_video_device_set_state(vd, state);
368 static struct output_properties acpi_output_properties = {
369 .set_state = acpi_video_output_set,
370 .get_status = acpi_video_output_get,
374 /* thermal cooling device callbacks */
375 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
377 struct acpi_device *device = cdev->devdata;
378 struct acpi_video_device *video = acpi_driver_data(device);
380 return sprintf(buf, "%d\n", video->brightness->count - 3);
383 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
385 struct acpi_device *device = cdev->devdata;
386 struct acpi_video_device *video = acpi_driver_data(device);
387 unsigned long long level;
390 if (acpi_video_device_lcd_get_level_current(video, &level))
392 for (state = 2; state < video->brightness->count; state++)
393 if (level == video->brightness->levels[state])
394 return sprintf(buf, "%d\n",
395 video->brightness->count - state - 1);
401 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
403 struct acpi_device *device = cdev->devdata;
404 struct acpi_video_device *video = acpi_driver_data(device);
407 if ( state >= video->brightness->count - 2)
410 state = video->brightness->count - state;
411 level = video->brightness->levels[state -1];
412 return acpi_video_device_lcd_set_level(video, level);
415 static struct thermal_cooling_device_ops video_cooling_ops = {
416 .get_max_state = video_get_max_state,
417 .get_cur_state = video_get_cur_state,
418 .set_cur_state = video_set_cur_state,
421 /* --------------------------------------------------------------------------
423 -------------------------------------------------------------------------- */
428 acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
432 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
438 acpi_video_device_get_state(struct acpi_video_device *device,
439 unsigned long long *state)
443 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
449 acpi_video_device_set_state(struct acpi_video_device *device, int state)
452 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
453 struct acpi_object_list args = { 1, &arg0 };
454 unsigned long long ret;
457 arg0.integer.value = state;
458 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
464 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
465 union acpi_object **levels)
468 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
469 union acpi_object *obj;
474 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
475 if (!ACPI_SUCCESS(status))
477 obj = (union acpi_object *)buffer.pointer;
478 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
479 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
489 kfree(buffer.pointer);
495 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
498 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
499 struct acpi_object_list args = { 1, &arg0 };
502 arg0.integer.value = level;
504 status = acpi_evaluate_object(device->dev->handle, "_BCM",
506 if (ACPI_FAILURE(status)) {
507 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
511 device->brightness->curr = level;
512 for (state = 2; state < device->brightness->count; state++)
513 if (level == device->brightness->levels[state]) {
514 if (device->backlight)
515 device->backlight->props.brightness = state - 2;
519 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
524 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
525 unsigned long long *level)
527 acpi_status status = AE_OK;
529 if (device->cap._BQC || device->cap._BCQ) {
530 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
532 status = acpi_evaluate_integer(device->dev->handle, buf,
534 if (ACPI_SUCCESS(status)) {
535 if (device->brightness->flags._BQC_use_index) {
536 if (device->brightness->flags._BCL_reversed)
537 *level = device->brightness->count
539 *level = device->brightness->levels[*level + 2];
542 device->brightness->curr = *level;
546 * should we return an error or ignore this failure?
547 * dev->brightness->curr is a cached value which stores
548 * the correct current backlight level in most cases.
549 * ACPI video backlight still works w/ buggy _BQC.
550 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
552 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
553 device->cap._BQC = device->cap._BCQ = 0;
557 *level = device->brightness->curr;
562 acpi_video_device_EDID(struct acpi_video_device *device,
563 union acpi_object **edid, ssize_t length)
566 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
567 union acpi_object *obj;
568 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
569 struct acpi_object_list args = { 1, &arg0 };
577 arg0.integer.value = 1;
578 else if (length == 256)
579 arg0.integer.value = 2;
583 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
584 if (ACPI_FAILURE(status))
587 obj = buffer.pointer;
589 if (obj && obj->type == ACPI_TYPE_BUFFER)
592 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
603 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
606 unsigned long long tmp;
607 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
608 struct acpi_object_list args = { 1, &arg0 };
611 arg0.integer.value = option;
613 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
614 if (ACPI_SUCCESS(status))
615 status = tmp ? (-EINVAL) : (AE_OK);
621 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
625 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
631 acpi_video_bus_POST_options(struct acpi_video_bus *video,
632 unsigned long long *options)
636 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
644 * video : video bus device pointer
646 * 0. The system BIOS should NOT automatically switch(toggle)
647 * the active display output.
648 * 1. The system BIOS should automatically switch (toggle) the
649 * active display output. No switch event.
650 * 2. The _DGS value should be locked.
651 * 3. The system BIOS should not automatically switch (toggle) the
652 * active display output, but instead generate the display switch
655 * 0. The system BIOS should automatically control the brightness level
656 * of the LCD when the power changes from AC to DC
657 * 1. The system BIOS should NOT automatically control the brightness
658 * level of the LCD when the power changes from AC to DC.
664 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
666 acpi_integer status = 0;
667 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
668 struct acpi_object_list args = { 1, &arg0 };
671 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
675 arg0.integer.value = (lcd_flag << 2) | bios_flag;
676 video->dos_setting = arg0.integer.value;
677 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
684 * Simple comparison function used to sort backlight levels.
688 acpi_video_cmp_level(const void *a, const void *b)
690 return *(int *)a - *(int *)b;
695 * device : video output device (LCD, CRT, ..)
698 * Maximum brightness level
700 * Allocate and initialize device->brightness.
704 acpi_video_init_brightness(struct acpi_video_device *device)
706 union acpi_object *obj = NULL;
707 int i, max_level = 0, count = 0, level_ac_battery = 0;
708 unsigned long long level, level_old;
709 union acpi_object *o;
710 struct acpi_video_device_brightness *br = NULL;
711 int result = -EINVAL;
713 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
714 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
715 "LCD brightness level\n"));
719 if (obj->package.count < 2)
722 br = kzalloc(sizeof(*br), GFP_KERNEL);
724 printk(KERN_ERR "can't allocate memory\n");
729 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
736 for (i = 0; i < obj->package.count; i++) {
737 o = (union acpi_object *)&obj->package.elements[i];
738 if (o->type != ACPI_TYPE_INTEGER) {
739 printk(KERN_ERR PREFIX "Invalid data\n");
742 br->levels[count] = (u32) o->integer.value;
744 if (br->levels[count] > max_level)
745 max_level = br->levels[count];
750 * some buggy BIOS don't export the levels
751 * when machine is on AC/Battery in _BCL package.
752 * In this case, the first two elements in _BCL packages
753 * are also supported brightness levels that OS should take care of.
755 for (i = 2; i < count; i++)
756 if (br->levels[i] == br->levels[0] ||
757 br->levels[i] == br->levels[1])
760 if (level_ac_battery < 2) {
761 level_ac_battery = 2 - level_ac_battery;
762 br->flags._BCL_no_ac_battery_levels = 1;
763 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
764 br->levels[i] = br->levels[i - level_ac_battery];
765 count += level_ac_battery;
766 } else if (level_ac_battery > 2)
767 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
769 /* Check if the _BCL package is in a reversed order */
770 if (max_level == br->levels[2]) {
771 br->flags._BCL_reversed = 1;
772 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
773 acpi_video_cmp_level, NULL);
774 } else if (max_level != br->levels[count - 1])
776 "Found unordered _BCL package\n"));
779 device->brightness = br;
781 /* Check the input/output of _BQC/_BCL/_BCM */
782 if ((max_level < 100) && (max_level <= (count - 2)))
783 br->flags._BCL_use_index = 1;
786 * _BCM is always consistent with _BCL,
787 * at least for all the laptops we have ever seen.
789 br->flags._BCM_use_index = br->flags._BCL_use_index;
791 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
792 br->curr = max_level;
793 result = acpi_video_device_lcd_get_level_current(device, &level_old);
795 goto out_free_levels;
797 result = acpi_video_device_lcd_set_level(device, br->curr);
799 goto out_free_levels;
801 result = acpi_video_device_lcd_get_level_current(device, &level);
803 goto out_free_levels;
805 if ((level != level_old) && !br->flags._BCM_use_index) {
807 * This piece of code does not work correctly if the current
808 * brightness levels is 0.
809 * But I guess boxes that boot with such a dark screen are rare
810 * and no more code is needed to cover this specifial case.
813 if (level_ac_battery != 2) {
815 * For now, we don't support the _BCL like this:
816 * 16, 15, 0, 1, 2, 3, ..., 14, 15, 16
817 * because we may mess up the index returned by _BQC.
818 * Plus: we have not got a box like this.
820 ACPI_ERROR((AE_INFO, "_BCL not supported\n"));
822 br->flags._BQC_use_index = 1;
825 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
826 "found %d brightness levels\n", count - 2));
835 device->brightness = NULL;
842 * device : video output device (LCD, CRT, ..)
847 * Find out all required AML methods defined under the output
851 static void acpi_video_device_find_cap(struct acpi_video_device *device)
853 acpi_handle h_dummy1;
856 memset(&device->cap, 0, sizeof(device->cap));
858 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
859 device->cap._ADR = 1;
861 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
862 device->cap._BCL = 1;
864 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
865 device->cap._BCM = 1;
867 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
868 device->cap._BQC = 1;
869 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
871 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
872 device->cap._BCQ = 1;
875 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
876 device->cap._DDC = 1;
878 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
879 device->cap._DCS = 1;
881 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
882 device->cap._DGS = 1;
884 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
885 device->cap._DSS = 1;
888 if (acpi_video_backlight_support()) {
890 static int count = 0;
893 result = acpi_video_init_brightness(device);
896 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
900 sprintf(name, "acpi_video%d", count++);
901 device->backlight = backlight_device_register(name,
902 NULL, device, &acpi_backlight_ops);
903 device->backlight->props.max_brightness = device->brightness->count-3;
906 device->cdev = thermal_cooling_device_register("LCD",
907 device->dev, &video_cooling_ops);
908 if (IS_ERR(device->cdev))
911 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
913 result = sysfs_create_link(&device->dev->dev.kobj,
914 &device->cdev->device.kobj,
917 printk(KERN_ERR PREFIX "Create sysfs link\n");
918 result = sysfs_create_link(&device->cdev->device.kobj,
919 &device->dev->dev.kobj, "device");
921 printk(KERN_ERR PREFIX "Create sysfs link\n");
925 if (acpi_video_display_switch_support()) {
927 if (device->cap._DCS && device->cap._DSS) {
930 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
933 sprintf(name, "acpi_video%d", count++);
934 device->output_dev = video_output_register(name,
935 NULL, device, &acpi_output_properties);
943 * device : video output device (VGA)
948 * Find out all required AML methods defined under the video bus device.
951 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
953 acpi_handle h_dummy1;
955 memset(&video->cap, 0, sizeof(video->cap));
956 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
959 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
962 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
965 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
968 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
971 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
977 * Check whether the video bus device has required AML method to
978 * support the desired features
981 static int acpi_video_bus_check(struct acpi_video_bus *video)
983 acpi_status status = -ENOENT;
989 dev = acpi_get_physical_pci_device(video->device->handle);
994 /* Since there is no HID, CID and so on for VGA driver, we have
995 * to check well known required nodes.
998 /* Does this device support video switching? */
999 if (video->cap._DOS) {
1000 video->flags.multihead = 1;
1004 /* Does this device support retrieving a video ROM? */
1005 if (video->cap._ROM) {
1006 video->flags.rom = 1;
1010 /* Does this device support configuring which video device to POST? */
1011 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
1012 video->flags.post = 1;
1019 /* --------------------------------------------------------------------------
1020 FS Interface (/proc)
1021 -------------------------------------------------------------------------- */
1023 static struct proc_dir_entry *acpi_video_dir;
1027 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
1029 struct acpi_video_device *dev = seq->private;
1035 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1036 seq_printf(seq, "type: ");
1038 seq_printf(seq, "CRT\n");
1039 else if (dev->flags.lcd)
1040 seq_printf(seq, "LCD\n");
1041 else if (dev->flags.tvout)
1042 seq_printf(seq, "TVOUT\n");
1043 else if (dev->flags.dvi)
1044 seq_printf(seq, "DVI\n");
1046 seq_printf(seq, "UNKNOWN\n");
1048 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
1055 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
1057 return single_open(file, acpi_video_device_info_seq_show,
1061 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
1064 struct acpi_video_device *dev = seq->private;
1065 unsigned long long state;
1071 status = acpi_video_device_get_state(dev, &state);
1072 seq_printf(seq, "state: ");
1073 if (ACPI_SUCCESS(status))
1074 seq_printf(seq, "0x%02llx\n", state);
1076 seq_printf(seq, "<not supported>\n");
1078 status = acpi_video_device_query(dev, &state);
1079 seq_printf(seq, "query: ");
1080 if (ACPI_SUCCESS(status))
1081 seq_printf(seq, "0x%02llx\n", state);
1083 seq_printf(seq, "<not supported>\n");
1090 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
1092 return single_open(file, acpi_video_device_state_seq_show,
1097 acpi_video_device_write_state(struct file *file,
1098 const char __user * buffer,
1099 size_t count, loff_t * data)
1102 struct seq_file *m = file->private_data;
1103 struct acpi_video_device *dev = m->private;
1104 char str[12] = { 0 };
1108 if (!dev || count + 1 > sizeof str)
1111 if (copy_from_user(str, buffer, count))
1115 state = simple_strtoul(str, NULL, 0);
1116 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1118 status = acpi_video_device_set_state(dev, state);
1127 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1129 struct acpi_video_device *dev = seq->private;
1133 if (!dev || !dev->brightness) {
1134 seq_printf(seq, "<not supported>\n");
1138 seq_printf(seq, "levels: ");
1139 for (i = 2; i < dev->brightness->count; i++)
1140 seq_printf(seq, " %d", dev->brightness->levels[i]);
1141 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1147 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1149 return single_open(file, acpi_video_device_brightness_seq_show,
1154 acpi_video_device_write_brightness(struct file *file,
1155 const char __user * buffer,
1156 size_t count, loff_t * data)
1158 struct seq_file *m = file->private_data;
1159 struct acpi_video_device *dev = m->private;
1160 char str[5] = { 0 };
1161 unsigned int level = 0;
1165 if (!dev || !dev->brightness || count + 1 > sizeof str)
1168 if (copy_from_user(str, buffer, count))
1172 level = simple_strtoul(str, NULL, 0);
1177 /* validate through the list of available levels */
1178 for (i = 2; i < dev->brightness->count; i++)
1179 if (level == dev->brightness->levels[i]) {
1180 if (!acpi_video_device_lcd_set_level(dev, level))
1188 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1190 struct acpi_video_device *dev = seq->private;
1193 union acpi_object *edid = NULL;
1199 status = acpi_video_device_EDID(dev, &edid, 128);
1200 if (ACPI_FAILURE(status)) {
1201 status = acpi_video_device_EDID(dev, &edid, 256);
1204 if (ACPI_FAILURE(status)) {
1208 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1209 for (i = 0; i < edid->buffer.length; i++)
1210 seq_putc(seq, edid->buffer.pointer[i]);
1215 seq_printf(seq, "<not supported>\n");
1223 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1225 return single_open(file, acpi_video_device_EDID_seq_show,
1229 static int acpi_video_device_add_fs(struct acpi_device *device)
1231 struct proc_dir_entry *entry, *device_dir;
1232 struct acpi_video_device *vid_dev;
1234 vid_dev = acpi_driver_data(device);
1238 device_dir = proc_mkdir(acpi_device_bid(device),
1239 vid_dev->video->dir);
1243 device_dir->owner = THIS_MODULE;
1246 entry = proc_create_data("info", S_IRUGO, device_dir,
1247 &acpi_video_device_info_fops, acpi_driver_data(device));
1249 goto err_remove_dir;
1252 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1253 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1255 &acpi_video_device_state_fops,
1256 acpi_driver_data(device));
1258 goto err_remove_info;
1260 /* 'brightness' [R/W] */
1261 acpi_video_device_brightness_fops.write =
1262 acpi_video_device_write_brightness;
1263 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1265 &acpi_video_device_brightness_fops,
1266 acpi_driver_data(device));
1268 goto err_remove_state;
1271 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1272 &acpi_video_device_EDID_fops,
1273 acpi_driver_data(device));
1275 goto err_remove_brightness;
1277 acpi_device_dir(device) = device_dir;
1281 err_remove_brightness:
1282 remove_proc_entry("brightness", device_dir);
1284 remove_proc_entry("state", device_dir);
1286 remove_proc_entry("info", device_dir);
1288 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1292 static int acpi_video_device_remove_fs(struct acpi_device *device)
1294 struct acpi_video_device *vid_dev;
1295 struct proc_dir_entry *device_dir;
1297 vid_dev = acpi_driver_data(device);
1298 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1301 device_dir = acpi_device_dir(device);
1303 remove_proc_entry("info", device_dir);
1304 remove_proc_entry("state", device_dir);
1305 remove_proc_entry("brightness", device_dir);
1306 remove_proc_entry("EDID", device_dir);
1307 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1308 acpi_device_dir(device) = NULL;
1315 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1317 struct acpi_video_bus *video = seq->private;
1323 seq_printf(seq, "Switching heads: %s\n",
1324 video->flags.multihead ? "yes" : "no");
1325 seq_printf(seq, "Video ROM: %s\n",
1326 video->flags.rom ? "yes" : "no");
1327 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1328 video->flags.post ? "yes" : "no");
1334 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1336 return single_open(file, acpi_video_bus_info_seq_show,
1340 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1342 struct acpi_video_bus *video = seq->private;
1348 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1349 seq_printf(seq, "<TODO>\n");
1355 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1357 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1360 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1362 struct acpi_video_bus *video = seq->private;
1363 unsigned long long options;
1370 status = acpi_video_bus_POST_options(video, &options);
1371 if (ACPI_SUCCESS(status)) {
1372 if (!(options & 1)) {
1373 printk(KERN_WARNING PREFIX
1374 "The motherboard VGA device is not listed as a possible POST device.\n");
1375 printk(KERN_WARNING PREFIX
1376 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1378 printk(KERN_WARNING "%llx\n", options);
1379 seq_printf(seq, "can POST: <integrated video>");
1381 seq_printf(seq, " <PCI video>");
1383 seq_printf(seq, " <AGP video>");
1384 seq_putc(seq, '\n');
1386 seq_printf(seq, "<not supported>\n");
1392 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1394 return single_open(file, acpi_video_bus_POST_info_seq_show,
1398 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1400 struct acpi_video_bus *video = seq->private;
1402 unsigned long long id;
1408 status = acpi_video_bus_get_POST(video, &id);
1409 if (!ACPI_SUCCESS(status)) {
1410 seq_printf(seq, "<not supported>\n");
1413 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1419 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1421 struct acpi_video_bus *video = seq->private;
1424 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1429 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1431 return single_open(file, acpi_video_bus_POST_seq_show,
1435 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1437 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1441 acpi_video_bus_write_POST(struct file *file,
1442 const char __user * buffer,
1443 size_t count, loff_t * data)
1446 struct seq_file *m = file->private_data;
1447 struct acpi_video_bus *video = m->private;
1448 char str[12] = { 0 };
1449 unsigned long long opt, options;
1452 if (!video || count + 1 > sizeof str)
1455 status = acpi_video_bus_POST_options(video, &options);
1456 if (!ACPI_SUCCESS(status))
1459 if (copy_from_user(str, buffer, count))
1463 opt = strtoul(str, NULL, 0);
1467 /* just in case an OEM 'forgot' the motherboard... */
1470 if (options & (1ul << opt)) {
1471 status = acpi_video_bus_set_POST(video, opt);
1472 if (!ACPI_SUCCESS(status))
1481 acpi_video_bus_write_DOS(struct file *file,
1482 const char __user * buffer,
1483 size_t count, loff_t * data)
1486 struct seq_file *m = file->private_data;
1487 struct acpi_video_bus *video = m->private;
1488 char str[12] = { 0 };
1492 if (!video || count + 1 > sizeof str)
1495 if (copy_from_user(str, buffer, count))
1499 opt = strtoul(str, NULL, 0);
1503 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1505 if (!ACPI_SUCCESS(status))
1511 static int acpi_video_bus_add_fs(struct acpi_device *device)
1513 struct acpi_video_bus *video = acpi_driver_data(device);
1514 struct proc_dir_entry *device_dir;
1515 struct proc_dir_entry *entry;
1517 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1521 device_dir->owner = THIS_MODULE;
1524 entry = proc_create_data("info", S_IRUGO, device_dir,
1525 &acpi_video_bus_info_fops,
1526 acpi_driver_data(device));
1528 goto err_remove_dir;
1531 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1532 &acpi_video_bus_ROM_fops,
1533 acpi_driver_data(device));
1535 goto err_remove_info;
1537 /* 'POST_info' [R] */
1538 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1539 &acpi_video_bus_POST_info_fops,
1540 acpi_driver_data(device));
1542 goto err_remove_rom;
1545 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1546 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1548 &acpi_video_bus_POST_fops,
1549 acpi_driver_data(device));
1551 goto err_remove_post_info;
1554 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1555 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1557 &acpi_video_bus_DOS_fops,
1558 acpi_driver_data(device));
1560 goto err_remove_post;
1562 video->dir = acpi_device_dir(device) = device_dir;
1566 remove_proc_entry("POST", device_dir);
1567 err_remove_post_info:
1568 remove_proc_entry("POST_info", device_dir);
1570 remove_proc_entry("ROM", device_dir);
1572 remove_proc_entry("info", device_dir);
1574 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1578 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1580 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1583 remove_proc_entry("info", device_dir);
1584 remove_proc_entry("ROM", device_dir);
1585 remove_proc_entry("POST_info", device_dir);
1586 remove_proc_entry("POST", device_dir);
1587 remove_proc_entry("DOS", device_dir);
1588 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1589 acpi_device_dir(device) = NULL;
1595 /* --------------------------------------------------------------------------
1597 -------------------------------------------------------------------------- */
1599 /* device interface */
1600 static struct acpi_video_device_attrib*
1601 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1603 struct acpi_video_enumerated_device *ids;
1606 for (i = 0; i < video->attached_count; i++) {
1607 ids = &video->attached_array[i];
1608 if ((ids->value.int_val & 0xffff) == device_id)
1609 return &ids->value.attrib;
1616 acpi_video_bus_get_one_device(struct acpi_device *device,
1617 struct acpi_video_bus *video)
1619 unsigned long long device_id;
1621 struct acpi_video_device *data;
1622 struct acpi_video_device_attrib* attribute;
1624 if (!device || !video)
1628 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1629 if (ACPI_SUCCESS(status)) {
1631 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1635 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1636 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1637 device->driver_data = data;
1639 data->device_id = device_id;
1640 data->video = video;
1643 attribute = acpi_video_get_device_attr(video, device_id);
1645 if((attribute != NULL) && attribute->device_id_scheme) {
1646 switch (attribute->display_type) {
1647 case ACPI_VIDEO_DISPLAY_CRT:
1648 data->flags.crt = 1;
1650 case ACPI_VIDEO_DISPLAY_TV:
1651 data->flags.tvout = 1;
1653 case ACPI_VIDEO_DISPLAY_DVI:
1654 data->flags.dvi = 1;
1656 case ACPI_VIDEO_DISPLAY_LCD:
1657 data->flags.lcd = 1;
1660 data->flags.unknown = 1;
1663 if(attribute->bios_can_detect)
1664 data->flags.bios = 1;
1666 data->flags.unknown = 1;
1668 acpi_video_device_bind(video, data);
1669 acpi_video_device_find_cap(data);
1671 status = acpi_install_notify_handler(device->handle,
1673 acpi_video_device_notify,
1675 if (ACPI_FAILURE(status)) {
1676 printk(KERN_ERR PREFIX
1677 "Error installing notify handler\n");
1678 if(data->brightness)
1679 kfree(data->brightness->levels);
1680 kfree(data->brightness);
1685 mutex_lock(&video->device_list_lock);
1686 list_add_tail(&data->entry, &video->video_device_list);
1687 mutex_unlock(&video->device_list_lock);
1689 acpi_video_device_add_fs(device);
1699 * video : video bus device
1704 * Enumerate the video device list of the video bus,
1705 * bind the ids with the corresponding video devices
1706 * under the video bus.
1709 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1711 struct acpi_video_device *dev;
1713 mutex_lock(&video->device_list_lock);
1715 list_for_each_entry(dev, &video->video_device_list, entry)
1716 acpi_video_device_bind(video, dev);
1718 mutex_unlock(&video->device_list_lock);
1723 * video : video bus device
1724 * device : video output device under the video
1730 * Bind the ids with the corresponding video devices
1731 * under the video bus.
1735 acpi_video_device_bind(struct acpi_video_bus *video,
1736 struct acpi_video_device *device)
1738 struct acpi_video_enumerated_device *ids;
1741 for (i = 0; i < video->attached_count; i++) {
1742 ids = &video->attached_array[i];
1743 if (device->device_id == (ids->value.int_val & 0xffff)) {
1744 ids->bind_info = device;
1745 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1752 * video : video bus device
1757 * Call _DOD to enumerate all devices attached to display adapter
1761 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1766 struct acpi_video_enumerated_device *active_list;
1767 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1768 union acpi_object *dod = NULL;
1769 union acpi_object *obj;
1771 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1772 if (!ACPI_SUCCESS(status)) {
1773 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1777 dod = buffer.pointer;
1778 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1779 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1785 dod->package.count));
1787 active_list = kcalloc(1 + dod->package.count,
1788 sizeof(struct acpi_video_enumerated_device),
1796 for (i = 0; i < dod->package.count; i++) {
1797 obj = &dod->package.elements[i];
1799 if (obj->type != ACPI_TYPE_INTEGER) {
1800 printk(KERN_ERR PREFIX
1801 "Invalid _DOD data in element %d\n", i);
1805 active_list[count].value.int_val = obj->integer.value;
1806 active_list[count].bind_info = NULL;
1807 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1808 (int)obj->integer.value));
1812 kfree(video->attached_array);
1814 video->attached_array = active_list;
1815 video->attached_count = count;
1818 kfree(buffer.pointer);
1823 acpi_video_get_next_level(struct acpi_video_device *device,
1824 u32 level_current, u32 event)
1826 int min, max, min_above, max_below, i, l, delta = 255;
1827 max = max_below = 0;
1828 min = min_above = 255;
1829 /* Find closest level to level_current */
1830 for (i = 2; i < device->brightness->count; i++) {
1831 l = device->brightness->levels[i];
1832 if (abs(l - level_current) < abs(delta)) {
1833 delta = l - level_current;
1838 /* Ajust level_current to closest available level */
1839 level_current += delta;
1840 for (i = 2; i < device->brightness->count; i++) {
1841 l = device->brightness->levels[i];
1846 if (l < min_above && l > level_current)
1848 if (l > max_below && l < level_current)
1853 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1854 return (level_current < max) ? min_above : min;
1855 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1856 return (level_current < max) ? min_above : max;
1857 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1858 return (level_current > min) ? max_below : min;
1859 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1860 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1863 return level_current;
1868 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1870 unsigned long long level_current, level_next;
1871 int result = -EINVAL;
1873 if (!device->brightness)
1876 result = acpi_video_device_lcd_get_level_current(device,
1881 level_next = acpi_video_get_next_level(device, level_current, event);
1883 result = acpi_video_device_lcd_set_level(device, level_next);
1887 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1893 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1894 struct acpi_device *device)
1897 struct acpi_device *dev;
1899 acpi_video_device_enumerate(video);
1901 list_for_each_entry(dev, &device->children, node) {
1903 status = acpi_video_bus_get_one_device(dev, video);
1904 if (ACPI_FAILURE(status)) {
1905 printk(KERN_WARNING PREFIX
1906 "Cant attach device");
1913 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1916 struct acpi_video_bus *video;
1919 if (!device || !device->video)
1922 video = device->video;
1924 acpi_video_device_remove_fs(device->dev);
1926 status = acpi_remove_notify_handler(device->dev->handle,
1928 acpi_video_device_notify);
1929 backlight_device_unregister(device->backlight);
1931 sysfs_remove_link(&device->dev->dev.kobj,
1933 sysfs_remove_link(&device->cdev->device.kobj,
1935 thermal_cooling_device_unregister(device->cdev);
1936 device->cdev = NULL;
1938 video_output_unregister(device->output_dev);
1943 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1946 struct acpi_video_device *dev, *next;
1948 mutex_lock(&video->device_list_lock);
1950 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1952 status = acpi_video_bus_put_one_device(dev);
1953 if (ACPI_FAILURE(status))
1954 printk(KERN_WARNING PREFIX
1955 "hhuuhhuu bug in acpi video driver.\n");
1957 if (dev->brightness) {
1958 kfree(dev->brightness->levels);
1959 kfree(dev->brightness);
1961 list_del(&dev->entry);
1965 mutex_unlock(&video->device_list_lock);
1970 /* acpi_video interface */
1972 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1974 return acpi_video_bus_DOS(video, 0, 0);
1977 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1979 return acpi_video_bus_DOS(video, 0, 1);
1982 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1984 struct acpi_video_bus *video = data;
1985 struct acpi_device *device = NULL;
1986 struct input_dev *input;
1992 device = video->device;
1993 input = video->input;
1996 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1997 * most likely via hotkey. */
1998 acpi_bus_generate_proc_event(device, event, 0);
1999 keycode = KEY_SWITCHVIDEOMODE;
2002 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
2004 acpi_video_device_enumerate(video);
2005 acpi_video_device_rebind(video);
2006 acpi_bus_generate_proc_event(device, event, 0);
2007 keycode = KEY_SWITCHVIDEOMODE;
2010 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
2011 acpi_bus_generate_proc_event(device, event, 0);
2012 keycode = KEY_SWITCHVIDEOMODE;
2014 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
2015 acpi_bus_generate_proc_event(device, event, 0);
2016 keycode = KEY_VIDEO_NEXT;
2018 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
2019 acpi_bus_generate_proc_event(device, event, 0);
2020 keycode = KEY_VIDEO_PREV;
2024 keycode = KEY_UNKNOWN;
2025 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2026 "Unsupported event [0x%x]\n", event));
2030 acpi_notifier_call_chain(device, event, 0);
2031 input_report_key(input, keycode, 1);
2033 input_report_key(input, keycode, 0);
2039 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
2041 struct acpi_video_device *video_device = data;
2042 struct acpi_device *device = NULL;
2043 struct acpi_video_bus *bus;
2044 struct input_dev *input;
2050 device = video_device->dev;
2051 bus = video_device->video;
2055 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
2056 if (brightness_switch_enabled)
2057 acpi_video_switch_brightness(video_device, event);
2058 acpi_bus_generate_proc_event(device, event, 0);
2059 keycode = KEY_BRIGHTNESS_CYCLE;
2061 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
2062 if (brightness_switch_enabled)
2063 acpi_video_switch_brightness(video_device, event);
2064 acpi_bus_generate_proc_event(device, event, 0);
2065 keycode = KEY_BRIGHTNESSUP;
2067 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
2068 if (brightness_switch_enabled)
2069 acpi_video_switch_brightness(video_device, event);
2070 acpi_bus_generate_proc_event(device, event, 0);
2071 keycode = KEY_BRIGHTNESSDOWN;
2073 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
2074 if (brightness_switch_enabled)
2075 acpi_video_switch_brightness(video_device, event);
2076 acpi_bus_generate_proc_event(device, event, 0);
2077 keycode = KEY_BRIGHTNESS_ZERO;
2079 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
2080 if (brightness_switch_enabled)
2081 acpi_video_switch_brightness(video_device, event);
2082 acpi_bus_generate_proc_event(device, event, 0);
2083 keycode = KEY_DISPLAY_OFF;
2086 keycode = KEY_UNKNOWN;
2087 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2088 "Unsupported event [0x%x]\n", event));
2092 acpi_notifier_call_chain(device, event, 0);
2093 input_report_key(input, keycode, 1);
2095 input_report_key(input, keycode, 0);
2101 static int instance;
2102 static int acpi_video_resume(struct acpi_device *device)
2104 struct acpi_video_bus *video;
2105 struct acpi_video_device *video_device;
2108 if (!device || !acpi_driver_data(device))
2111 video = acpi_driver_data(device);
2113 for (i = 0; i < video->attached_count; i++) {
2114 video_device = video->attached_array[i].bind_info;
2115 if (video_device && video_device->backlight)
2116 acpi_video_set_brightness(video_device->backlight);
2121 static int acpi_video_bus_add(struct acpi_device *device)
2124 struct acpi_video_bus *video;
2125 struct input_dev *input;
2128 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2132 /* a hack to fix the duplicate name "VID" problem on T61 */
2133 if (!strcmp(device->pnp.bus_id, "VID")) {
2135 device->pnp.bus_id[3] = '0' + instance;
2138 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2139 if (!strcmp(device->pnp.bus_id, "VGA")) {
2141 device->pnp.bus_id[3] = '0' + instance;
2145 video->device = device;
2146 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2147 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2148 device->driver_data = video;
2150 acpi_video_bus_find_cap(video);
2151 error = acpi_video_bus_check(video);
2153 goto err_free_video;
2155 error = acpi_video_bus_add_fs(device);
2157 goto err_free_video;
2159 mutex_init(&video->device_list_lock);
2160 INIT_LIST_HEAD(&video->video_device_list);
2162 acpi_video_bus_get_devices(video, device);
2163 acpi_video_bus_start_devices(video);
2165 status = acpi_install_notify_handler(device->handle,
2167 acpi_video_bus_notify, video);
2168 if (ACPI_FAILURE(status)) {
2169 printk(KERN_ERR PREFIX
2170 "Error installing notify handler\n");
2172 goto err_stop_video;
2175 video->input = input = input_allocate_device();
2178 goto err_uninstall_notify;
2181 snprintf(video->phys, sizeof(video->phys),
2182 "%s/video/input0", acpi_device_hid(video->device));
2184 input->name = acpi_device_name(video->device);
2185 input->phys = video->phys;
2186 input->id.bustype = BUS_HOST;
2187 input->id.product = 0x06;
2188 input->dev.parent = &device->dev;
2189 input->evbit[0] = BIT(EV_KEY);
2190 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2191 set_bit(KEY_VIDEO_NEXT, input->keybit);
2192 set_bit(KEY_VIDEO_PREV, input->keybit);
2193 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2194 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2195 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2196 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2197 set_bit(KEY_DISPLAY_OFF, input->keybit);
2198 set_bit(KEY_UNKNOWN, input->keybit);
2200 error = input_register_device(input);
2202 goto err_free_input_dev;
2204 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2205 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2206 video->flags.multihead ? "yes" : "no",
2207 video->flags.rom ? "yes" : "no",
2208 video->flags.post ? "yes" : "no");
2213 input_free_device(input);
2214 err_uninstall_notify:
2215 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2216 acpi_video_bus_notify);
2218 acpi_video_bus_stop_devices(video);
2219 acpi_video_bus_put_devices(video);
2220 kfree(video->attached_array);
2221 acpi_video_bus_remove_fs(device);
2224 device->driver_data = NULL;
2229 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2231 acpi_status status = 0;
2232 struct acpi_video_bus *video = NULL;
2235 if (!device || !acpi_driver_data(device))
2238 video = acpi_driver_data(device);
2240 acpi_video_bus_stop_devices(video);
2242 status = acpi_remove_notify_handler(video->device->handle,
2244 acpi_video_bus_notify);
2246 acpi_video_bus_put_devices(video);
2247 acpi_video_bus_remove_fs(device);
2249 input_unregister_device(video->input);
2250 kfree(video->attached_array);
2256 static int __init intel_opregion_present(void)
2258 #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2259 struct pci_dev *dev = NULL;
2262 for_each_pci_dev(dev) {
2263 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2265 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2267 pci_read_config_dword(dev, 0xfc, &address);
2276 int acpi_video_register(void)
2280 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2281 if (!acpi_video_dir)
2283 acpi_video_dir->owner = THIS_MODULE;
2285 result = acpi_bus_register_driver(&acpi_video_bus);
2287 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2293 EXPORT_SYMBOL(acpi_video_register);
2296 * This is kind of nasty. Hardware using Intel chipsets may require
2297 * the video opregion code to be run first in order to initialise
2298 * state before any ACPI video calls are made. To handle this we defer
2299 * registration of the video class until the opregion code has run.
2302 static int __init acpi_video_init(void)
2304 if (intel_opregion_present())
2307 return acpi_video_register();
2310 static void __exit acpi_video_exit(void)
2313 acpi_bus_unregister_driver(&acpi_video_bus);
2315 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2320 module_init(acpi_video_init);
2321 module_exit(acpi_video_exit);