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, unsigned
378 struct acpi_device *device = cdev->devdata;
379 struct acpi_video_device *video = acpi_driver_data(device);
381 *state = video->brightness->count - 3;
385 static int video_get_cur_state(struct thermal_cooling_device *cdev, unsigned
388 struct acpi_device *device = cdev->devdata;
389 struct acpi_video_device *video = acpi_driver_data(device);
390 unsigned long long level;
393 if (acpi_video_device_lcd_get_level_current(video, &level))
395 for (offset = 2; offset < video->brightness->count; offset++)
396 if (level == video->brightness->levels[offset]) {
397 *state = video->brightness->count - offset - 1;
405 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
407 struct acpi_device *device = cdev->devdata;
408 struct acpi_video_device *video = acpi_driver_data(device);
411 if ( state >= video->brightness->count - 2)
414 state = video->brightness->count - state;
415 level = video->brightness->levels[state -1];
416 return acpi_video_device_lcd_set_level(video, level);
419 static struct thermal_cooling_device_ops video_cooling_ops = {
420 .get_max_state = video_get_max_state,
421 .get_cur_state = video_get_cur_state,
422 .set_cur_state = video_set_cur_state,
425 /* --------------------------------------------------------------------------
427 -------------------------------------------------------------------------- */
432 acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
436 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
442 acpi_video_device_get_state(struct acpi_video_device *device,
443 unsigned long long *state)
447 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
453 acpi_video_device_set_state(struct acpi_video_device *device, int state)
456 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
457 struct acpi_object_list args = { 1, &arg0 };
458 unsigned long long ret;
461 arg0.integer.value = state;
462 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
468 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
469 union acpi_object **levels)
472 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
473 union acpi_object *obj;
478 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
479 if (!ACPI_SUCCESS(status))
481 obj = (union acpi_object *)buffer.pointer;
482 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
483 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
493 kfree(buffer.pointer);
499 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
502 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
503 struct acpi_object_list args = { 1, &arg0 };
506 arg0.integer.value = level;
508 status = acpi_evaluate_object(device->dev->handle, "_BCM",
510 if (ACPI_FAILURE(status)) {
511 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
515 device->brightness->curr = level;
516 for (state = 2; state < device->brightness->count; state++)
517 if (level == device->brightness->levels[state]) {
518 if (device->backlight)
519 device->backlight->props.brightness = state - 2;
523 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
528 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
529 unsigned long long *level)
531 acpi_status status = AE_OK;
533 if (device->cap._BQC || device->cap._BCQ) {
534 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
536 status = acpi_evaluate_integer(device->dev->handle, buf,
538 if (ACPI_SUCCESS(status)) {
539 if (device->brightness->flags._BQC_use_index) {
540 if (device->brightness->flags._BCL_reversed)
541 *level = device->brightness->count
543 *level = device->brightness->levels[*level + 2];
546 device->brightness->curr = *level;
550 * should we return an error or ignore this failure?
551 * dev->brightness->curr is a cached value which stores
552 * the correct current backlight level in most cases.
553 * ACPI video backlight still works w/ buggy _BQC.
554 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
556 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
557 device->cap._BQC = device->cap._BCQ = 0;
561 *level = device->brightness->curr;
566 acpi_video_device_EDID(struct acpi_video_device *device,
567 union acpi_object **edid, ssize_t length)
570 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
571 union acpi_object *obj;
572 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
573 struct acpi_object_list args = { 1, &arg0 };
581 arg0.integer.value = 1;
582 else if (length == 256)
583 arg0.integer.value = 2;
587 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
588 if (ACPI_FAILURE(status))
591 obj = buffer.pointer;
593 if (obj && obj->type == ACPI_TYPE_BUFFER)
596 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
607 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
610 unsigned long long tmp;
611 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
612 struct acpi_object_list args = { 1, &arg0 };
615 arg0.integer.value = option;
617 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
618 if (ACPI_SUCCESS(status))
619 status = tmp ? (-EINVAL) : (AE_OK);
625 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
629 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
635 acpi_video_bus_POST_options(struct acpi_video_bus *video,
636 unsigned long long *options)
640 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
648 * video : video bus device pointer
650 * 0. The system BIOS should NOT automatically switch(toggle)
651 * the active display output.
652 * 1. The system BIOS should automatically switch (toggle) the
653 * active display output. No switch event.
654 * 2. The _DGS value should be locked.
655 * 3. The system BIOS should not automatically switch (toggle) the
656 * active display output, but instead generate the display switch
659 * 0. The system BIOS should automatically control the brightness level
660 * of the LCD when the power changes from AC to DC
661 * 1. The system BIOS should NOT automatically control the brightness
662 * level of the LCD when the power changes from AC to DC.
668 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
670 acpi_integer status = 0;
671 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
672 struct acpi_object_list args = { 1, &arg0 };
675 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
679 arg0.integer.value = (lcd_flag << 2) | bios_flag;
680 video->dos_setting = arg0.integer.value;
681 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
688 * Simple comparison function used to sort backlight levels.
692 acpi_video_cmp_level(const void *a, const void *b)
694 return *(int *)a - *(int *)b;
699 * device : video output device (LCD, CRT, ..)
702 * Maximum brightness level
704 * Allocate and initialize device->brightness.
708 acpi_video_init_brightness(struct acpi_video_device *device)
710 union acpi_object *obj = NULL;
711 int i, max_level = 0, count = 0, level_ac_battery = 0;
712 unsigned long long level, level_old;
713 union acpi_object *o;
714 struct acpi_video_device_brightness *br = NULL;
715 int result = -EINVAL;
717 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
718 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
719 "LCD brightness level\n"));
723 if (obj->package.count < 2)
726 br = kzalloc(sizeof(*br), GFP_KERNEL);
728 printk(KERN_ERR "can't allocate memory\n");
733 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
740 for (i = 0; i < obj->package.count; i++) {
741 o = (union acpi_object *)&obj->package.elements[i];
742 if (o->type != ACPI_TYPE_INTEGER) {
743 printk(KERN_ERR PREFIX "Invalid data\n");
746 br->levels[count] = (u32) o->integer.value;
748 if (br->levels[count] > max_level)
749 max_level = br->levels[count];
754 * some buggy BIOS don't export the levels
755 * when machine is on AC/Battery in _BCL package.
756 * In this case, the first two elements in _BCL packages
757 * are also supported brightness levels that OS should take care of.
759 for (i = 2; i < count; i++)
760 if (br->levels[i] == br->levels[0] ||
761 br->levels[i] == br->levels[1])
764 if (level_ac_battery < 2) {
765 level_ac_battery = 2 - level_ac_battery;
766 br->flags._BCL_no_ac_battery_levels = 1;
767 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
768 br->levels[i] = br->levels[i - level_ac_battery];
769 count += level_ac_battery;
770 } else if (level_ac_battery > 2)
771 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
773 /* Check if the _BCL package is in a reversed order */
774 if (max_level == br->levels[2]) {
775 br->flags._BCL_reversed = 1;
776 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
777 acpi_video_cmp_level, NULL);
778 } else if (max_level != br->levels[count - 1])
780 "Found unordered _BCL package\n"));
783 device->brightness = br;
785 /* Check the input/output of _BQC/_BCL/_BCM */
786 if ((max_level < 100) && (max_level <= (count - 2)))
787 br->flags._BCL_use_index = 1;
790 * _BCM is always consistent with _BCL,
791 * at least for all the laptops we have ever seen.
793 br->flags._BCM_use_index = br->flags._BCL_use_index;
795 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
796 br->curr = max_level;
797 result = acpi_video_device_lcd_get_level_current(device, &level_old);
799 goto out_free_levels;
801 result = acpi_video_device_lcd_set_level(device, br->curr);
803 goto out_free_levels;
805 result = acpi_video_device_lcd_get_level_current(device, &level);
807 goto out_free_levels;
809 if ((level != level_old) && !br->flags._BCM_use_index) {
811 * This piece of code does not work correctly if the current
812 * brightness levels is 0.
813 * But I guess boxes that boot with such a dark screen are rare
814 * and no more code is needed to cover this specifial case.
817 if (level_ac_battery != 2) {
819 * For now, we don't support the _BCL like this:
820 * 16, 15, 0, 1, 2, 3, ..., 14, 15, 16
821 * because we may mess up the index returned by _BQC.
822 * Plus: we have not got a box like this.
824 ACPI_ERROR((AE_INFO, "_BCL not supported\n"));
826 br->flags._BQC_use_index = 1;
829 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
830 "found %d brightness levels\n", count - 2));
839 device->brightness = NULL;
846 * device : video output device (LCD, CRT, ..)
851 * Find out all required AML methods defined under the output
855 static void acpi_video_device_find_cap(struct acpi_video_device *device)
857 acpi_handle h_dummy1;
860 memset(&device->cap, 0, sizeof(device->cap));
862 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
863 device->cap._ADR = 1;
865 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
866 device->cap._BCL = 1;
868 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
869 device->cap._BCM = 1;
871 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
872 device->cap._BQC = 1;
873 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
875 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
876 device->cap._BCQ = 1;
879 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
880 device->cap._DDC = 1;
882 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
883 device->cap._DCS = 1;
885 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
886 device->cap._DGS = 1;
888 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
889 device->cap._DSS = 1;
892 if (acpi_video_backlight_support()) {
894 static int count = 0;
897 result = acpi_video_init_brightness(device);
900 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
904 sprintf(name, "acpi_video%d", count++);
905 device->backlight = backlight_device_register(name,
906 NULL, device, &acpi_backlight_ops);
907 device->backlight->props.max_brightness = device->brightness->count-3;
910 device->cdev = thermal_cooling_device_register("LCD",
911 device->dev, &video_cooling_ops);
912 if (IS_ERR(device->cdev))
915 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
917 result = sysfs_create_link(&device->dev->dev.kobj,
918 &device->cdev->device.kobj,
921 printk(KERN_ERR PREFIX "Create sysfs link\n");
922 result = sysfs_create_link(&device->cdev->device.kobj,
923 &device->dev->dev.kobj, "device");
925 printk(KERN_ERR PREFIX "Create sysfs link\n");
929 if (acpi_video_display_switch_support()) {
931 if (device->cap._DCS && device->cap._DSS) {
934 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
937 sprintf(name, "acpi_video%d", count++);
938 device->output_dev = video_output_register(name,
939 NULL, device, &acpi_output_properties);
947 * device : video output device (VGA)
952 * Find out all required AML methods defined under the video bus device.
955 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
957 acpi_handle h_dummy1;
959 memset(&video->cap, 0, sizeof(video->cap));
960 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
963 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
966 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
969 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
972 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
975 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
981 * Check whether the video bus device has required AML method to
982 * support the desired features
985 static int acpi_video_bus_check(struct acpi_video_bus *video)
987 acpi_status status = -ENOENT;
993 dev = acpi_get_physical_pci_device(video->device->handle);
998 /* Since there is no HID, CID and so on for VGA driver, we have
999 * to check well known required nodes.
1002 /* Does this device support video switching? */
1003 if (video->cap._DOS) {
1004 video->flags.multihead = 1;
1008 /* Does this device support retrieving a video ROM? */
1009 if (video->cap._ROM) {
1010 video->flags.rom = 1;
1014 /* Does this device support configuring which video device to POST? */
1015 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
1016 video->flags.post = 1;
1023 /* --------------------------------------------------------------------------
1024 FS Interface (/proc)
1025 -------------------------------------------------------------------------- */
1027 static struct proc_dir_entry *acpi_video_dir;
1031 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
1033 struct acpi_video_device *dev = seq->private;
1039 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1040 seq_printf(seq, "type: ");
1042 seq_printf(seq, "CRT\n");
1043 else if (dev->flags.lcd)
1044 seq_printf(seq, "LCD\n");
1045 else if (dev->flags.tvout)
1046 seq_printf(seq, "TVOUT\n");
1047 else if (dev->flags.dvi)
1048 seq_printf(seq, "DVI\n");
1050 seq_printf(seq, "UNKNOWN\n");
1052 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
1059 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
1061 return single_open(file, acpi_video_device_info_seq_show,
1065 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
1068 struct acpi_video_device *dev = seq->private;
1069 unsigned long long state;
1075 status = acpi_video_device_get_state(dev, &state);
1076 seq_printf(seq, "state: ");
1077 if (ACPI_SUCCESS(status))
1078 seq_printf(seq, "0x%02llx\n", state);
1080 seq_printf(seq, "<not supported>\n");
1082 status = acpi_video_device_query(dev, &state);
1083 seq_printf(seq, "query: ");
1084 if (ACPI_SUCCESS(status))
1085 seq_printf(seq, "0x%02llx\n", state);
1087 seq_printf(seq, "<not supported>\n");
1094 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
1096 return single_open(file, acpi_video_device_state_seq_show,
1101 acpi_video_device_write_state(struct file *file,
1102 const char __user * buffer,
1103 size_t count, loff_t * data)
1106 struct seq_file *m = file->private_data;
1107 struct acpi_video_device *dev = m->private;
1108 char str[12] = { 0 };
1112 if (!dev || count + 1 > sizeof str)
1115 if (copy_from_user(str, buffer, count))
1119 state = simple_strtoul(str, NULL, 0);
1120 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1122 status = acpi_video_device_set_state(dev, state);
1131 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1133 struct acpi_video_device *dev = seq->private;
1137 if (!dev || !dev->brightness) {
1138 seq_printf(seq, "<not supported>\n");
1142 seq_printf(seq, "levels: ");
1143 for (i = 2; i < dev->brightness->count; i++)
1144 seq_printf(seq, " %d", dev->brightness->levels[i]);
1145 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1151 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1153 return single_open(file, acpi_video_device_brightness_seq_show,
1158 acpi_video_device_write_brightness(struct file *file,
1159 const char __user * buffer,
1160 size_t count, loff_t * data)
1162 struct seq_file *m = file->private_data;
1163 struct acpi_video_device *dev = m->private;
1164 char str[5] = { 0 };
1165 unsigned int level = 0;
1169 if (!dev || !dev->brightness || count + 1 > sizeof str)
1172 if (copy_from_user(str, buffer, count))
1176 level = simple_strtoul(str, NULL, 0);
1181 /* validate through the list of available levels */
1182 for (i = 2; i < dev->brightness->count; i++)
1183 if (level == dev->brightness->levels[i]) {
1184 if (!acpi_video_device_lcd_set_level(dev, level))
1192 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1194 struct acpi_video_device *dev = seq->private;
1197 union acpi_object *edid = NULL;
1203 status = acpi_video_device_EDID(dev, &edid, 128);
1204 if (ACPI_FAILURE(status)) {
1205 status = acpi_video_device_EDID(dev, &edid, 256);
1208 if (ACPI_FAILURE(status)) {
1212 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1213 for (i = 0; i < edid->buffer.length; i++)
1214 seq_putc(seq, edid->buffer.pointer[i]);
1219 seq_printf(seq, "<not supported>\n");
1227 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1229 return single_open(file, acpi_video_device_EDID_seq_show,
1233 static int acpi_video_device_add_fs(struct acpi_device *device)
1235 struct proc_dir_entry *entry, *device_dir;
1236 struct acpi_video_device *vid_dev;
1238 vid_dev = acpi_driver_data(device);
1242 device_dir = proc_mkdir(acpi_device_bid(device),
1243 vid_dev->video->dir);
1247 device_dir->owner = THIS_MODULE;
1250 entry = proc_create_data("info", S_IRUGO, device_dir,
1251 &acpi_video_device_info_fops, acpi_driver_data(device));
1253 goto err_remove_dir;
1256 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1257 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1259 &acpi_video_device_state_fops,
1260 acpi_driver_data(device));
1262 goto err_remove_info;
1264 /* 'brightness' [R/W] */
1265 acpi_video_device_brightness_fops.write =
1266 acpi_video_device_write_brightness;
1267 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1269 &acpi_video_device_brightness_fops,
1270 acpi_driver_data(device));
1272 goto err_remove_state;
1275 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1276 &acpi_video_device_EDID_fops,
1277 acpi_driver_data(device));
1279 goto err_remove_brightness;
1281 acpi_device_dir(device) = device_dir;
1285 err_remove_brightness:
1286 remove_proc_entry("brightness", device_dir);
1288 remove_proc_entry("state", device_dir);
1290 remove_proc_entry("info", device_dir);
1292 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1296 static int acpi_video_device_remove_fs(struct acpi_device *device)
1298 struct acpi_video_device *vid_dev;
1299 struct proc_dir_entry *device_dir;
1301 vid_dev = acpi_driver_data(device);
1302 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1305 device_dir = acpi_device_dir(device);
1307 remove_proc_entry("info", device_dir);
1308 remove_proc_entry("state", device_dir);
1309 remove_proc_entry("brightness", device_dir);
1310 remove_proc_entry("EDID", device_dir);
1311 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1312 acpi_device_dir(device) = NULL;
1319 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1321 struct acpi_video_bus *video = seq->private;
1327 seq_printf(seq, "Switching heads: %s\n",
1328 video->flags.multihead ? "yes" : "no");
1329 seq_printf(seq, "Video ROM: %s\n",
1330 video->flags.rom ? "yes" : "no");
1331 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1332 video->flags.post ? "yes" : "no");
1338 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1340 return single_open(file, acpi_video_bus_info_seq_show,
1344 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1346 struct acpi_video_bus *video = seq->private;
1352 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1353 seq_printf(seq, "<TODO>\n");
1359 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1361 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1364 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1366 struct acpi_video_bus *video = seq->private;
1367 unsigned long long options;
1374 status = acpi_video_bus_POST_options(video, &options);
1375 if (ACPI_SUCCESS(status)) {
1376 if (!(options & 1)) {
1377 printk(KERN_WARNING PREFIX
1378 "The motherboard VGA device is not listed as a possible POST device.\n");
1379 printk(KERN_WARNING PREFIX
1380 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1382 printk(KERN_WARNING "%llx\n", options);
1383 seq_printf(seq, "can POST: <integrated video>");
1385 seq_printf(seq, " <PCI video>");
1387 seq_printf(seq, " <AGP video>");
1388 seq_putc(seq, '\n');
1390 seq_printf(seq, "<not supported>\n");
1396 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1398 return single_open(file, acpi_video_bus_POST_info_seq_show,
1402 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1404 struct acpi_video_bus *video = seq->private;
1406 unsigned long long id;
1412 status = acpi_video_bus_get_POST(video, &id);
1413 if (!ACPI_SUCCESS(status)) {
1414 seq_printf(seq, "<not supported>\n");
1417 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1423 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1425 struct acpi_video_bus *video = seq->private;
1428 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1433 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1435 return single_open(file, acpi_video_bus_POST_seq_show,
1439 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1441 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1445 acpi_video_bus_write_POST(struct file *file,
1446 const char __user * buffer,
1447 size_t count, loff_t * data)
1450 struct seq_file *m = file->private_data;
1451 struct acpi_video_bus *video = m->private;
1452 char str[12] = { 0 };
1453 unsigned long long opt, options;
1456 if (!video || count + 1 > sizeof str)
1459 status = acpi_video_bus_POST_options(video, &options);
1460 if (!ACPI_SUCCESS(status))
1463 if (copy_from_user(str, buffer, count))
1467 opt = strtoul(str, NULL, 0);
1471 /* just in case an OEM 'forgot' the motherboard... */
1474 if (options & (1ul << opt)) {
1475 status = acpi_video_bus_set_POST(video, opt);
1476 if (!ACPI_SUCCESS(status))
1485 acpi_video_bus_write_DOS(struct file *file,
1486 const char __user * buffer,
1487 size_t count, loff_t * data)
1490 struct seq_file *m = file->private_data;
1491 struct acpi_video_bus *video = m->private;
1492 char str[12] = { 0 };
1496 if (!video || count + 1 > sizeof str)
1499 if (copy_from_user(str, buffer, count))
1503 opt = strtoul(str, NULL, 0);
1507 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1509 if (!ACPI_SUCCESS(status))
1515 static int acpi_video_bus_add_fs(struct acpi_device *device)
1517 struct acpi_video_bus *video = acpi_driver_data(device);
1518 struct proc_dir_entry *device_dir;
1519 struct proc_dir_entry *entry;
1521 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1525 device_dir->owner = THIS_MODULE;
1528 entry = proc_create_data("info", S_IRUGO, device_dir,
1529 &acpi_video_bus_info_fops,
1530 acpi_driver_data(device));
1532 goto err_remove_dir;
1535 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1536 &acpi_video_bus_ROM_fops,
1537 acpi_driver_data(device));
1539 goto err_remove_info;
1541 /* 'POST_info' [R] */
1542 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1543 &acpi_video_bus_POST_info_fops,
1544 acpi_driver_data(device));
1546 goto err_remove_rom;
1549 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1550 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1552 &acpi_video_bus_POST_fops,
1553 acpi_driver_data(device));
1555 goto err_remove_post_info;
1558 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1559 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1561 &acpi_video_bus_DOS_fops,
1562 acpi_driver_data(device));
1564 goto err_remove_post;
1566 video->dir = acpi_device_dir(device) = device_dir;
1570 remove_proc_entry("POST", device_dir);
1571 err_remove_post_info:
1572 remove_proc_entry("POST_info", device_dir);
1574 remove_proc_entry("ROM", device_dir);
1576 remove_proc_entry("info", device_dir);
1578 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1582 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1584 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1587 remove_proc_entry("info", device_dir);
1588 remove_proc_entry("ROM", device_dir);
1589 remove_proc_entry("POST_info", device_dir);
1590 remove_proc_entry("POST", device_dir);
1591 remove_proc_entry("DOS", device_dir);
1592 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1593 acpi_device_dir(device) = NULL;
1599 /* --------------------------------------------------------------------------
1601 -------------------------------------------------------------------------- */
1603 /* device interface */
1604 static struct acpi_video_device_attrib*
1605 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1607 struct acpi_video_enumerated_device *ids;
1610 for (i = 0; i < video->attached_count; i++) {
1611 ids = &video->attached_array[i];
1612 if ((ids->value.int_val & 0xffff) == device_id)
1613 return &ids->value.attrib;
1620 acpi_video_bus_get_one_device(struct acpi_device *device,
1621 struct acpi_video_bus *video)
1623 unsigned long long device_id;
1625 struct acpi_video_device *data;
1626 struct acpi_video_device_attrib* attribute;
1628 if (!device || !video)
1632 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1633 if (ACPI_SUCCESS(status)) {
1635 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1639 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1640 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1641 device->driver_data = data;
1643 data->device_id = device_id;
1644 data->video = video;
1647 attribute = acpi_video_get_device_attr(video, device_id);
1649 if((attribute != NULL) && attribute->device_id_scheme) {
1650 switch (attribute->display_type) {
1651 case ACPI_VIDEO_DISPLAY_CRT:
1652 data->flags.crt = 1;
1654 case ACPI_VIDEO_DISPLAY_TV:
1655 data->flags.tvout = 1;
1657 case ACPI_VIDEO_DISPLAY_DVI:
1658 data->flags.dvi = 1;
1660 case ACPI_VIDEO_DISPLAY_LCD:
1661 data->flags.lcd = 1;
1664 data->flags.unknown = 1;
1667 if(attribute->bios_can_detect)
1668 data->flags.bios = 1;
1670 data->flags.unknown = 1;
1672 acpi_video_device_bind(video, data);
1673 acpi_video_device_find_cap(data);
1675 status = acpi_install_notify_handler(device->handle,
1677 acpi_video_device_notify,
1679 if (ACPI_FAILURE(status)) {
1680 printk(KERN_ERR PREFIX
1681 "Error installing notify handler\n");
1682 if(data->brightness)
1683 kfree(data->brightness->levels);
1684 kfree(data->brightness);
1689 mutex_lock(&video->device_list_lock);
1690 list_add_tail(&data->entry, &video->video_device_list);
1691 mutex_unlock(&video->device_list_lock);
1693 acpi_video_device_add_fs(device);
1703 * video : video bus device
1708 * Enumerate the video device list of the video bus,
1709 * bind the ids with the corresponding video devices
1710 * under the video bus.
1713 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1715 struct acpi_video_device *dev;
1717 mutex_lock(&video->device_list_lock);
1719 list_for_each_entry(dev, &video->video_device_list, entry)
1720 acpi_video_device_bind(video, dev);
1722 mutex_unlock(&video->device_list_lock);
1727 * video : video bus device
1728 * device : video output device under the video
1734 * Bind the ids with the corresponding video devices
1735 * under the video bus.
1739 acpi_video_device_bind(struct acpi_video_bus *video,
1740 struct acpi_video_device *device)
1742 struct acpi_video_enumerated_device *ids;
1745 for (i = 0; i < video->attached_count; i++) {
1746 ids = &video->attached_array[i];
1747 if (device->device_id == (ids->value.int_val & 0xffff)) {
1748 ids->bind_info = device;
1749 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1756 * video : video bus device
1761 * Call _DOD to enumerate all devices attached to display adapter
1765 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1770 struct acpi_video_enumerated_device *active_list;
1771 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1772 union acpi_object *dod = NULL;
1773 union acpi_object *obj;
1775 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1776 if (!ACPI_SUCCESS(status)) {
1777 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1781 dod = buffer.pointer;
1782 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1783 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1788 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1789 dod->package.count));
1791 active_list = kcalloc(1 + dod->package.count,
1792 sizeof(struct acpi_video_enumerated_device),
1800 for (i = 0; i < dod->package.count; i++) {
1801 obj = &dod->package.elements[i];
1803 if (obj->type != ACPI_TYPE_INTEGER) {
1804 printk(KERN_ERR PREFIX
1805 "Invalid _DOD data in element %d\n", i);
1809 active_list[count].value.int_val = obj->integer.value;
1810 active_list[count].bind_info = NULL;
1811 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1812 (int)obj->integer.value));
1816 kfree(video->attached_array);
1818 video->attached_array = active_list;
1819 video->attached_count = count;
1822 kfree(buffer.pointer);
1827 acpi_video_get_next_level(struct acpi_video_device *device,
1828 u32 level_current, u32 event)
1830 int min, max, min_above, max_below, i, l, delta = 255;
1831 max = max_below = 0;
1832 min = min_above = 255;
1833 /* Find closest level to level_current */
1834 for (i = 2; i < device->brightness->count; i++) {
1835 l = device->brightness->levels[i];
1836 if (abs(l - level_current) < abs(delta)) {
1837 delta = l - level_current;
1842 /* Ajust level_current to closest available level */
1843 level_current += delta;
1844 for (i = 2; i < device->brightness->count; i++) {
1845 l = device->brightness->levels[i];
1850 if (l < min_above && l > level_current)
1852 if (l > max_below && l < level_current)
1857 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1858 return (level_current < max) ? min_above : min;
1859 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1860 return (level_current < max) ? min_above : max;
1861 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1862 return (level_current > min) ? max_below : min;
1863 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1864 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1867 return level_current;
1872 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1874 unsigned long long level_current, level_next;
1875 int result = -EINVAL;
1877 if (!device->brightness)
1880 result = acpi_video_device_lcd_get_level_current(device,
1885 level_next = acpi_video_get_next_level(device, level_current, event);
1887 result = acpi_video_device_lcd_set_level(device, level_next);
1891 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1897 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1898 struct acpi_device *device)
1901 struct acpi_device *dev;
1903 acpi_video_device_enumerate(video);
1905 list_for_each_entry(dev, &device->children, node) {
1907 status = acpi_video_bus_get_one_device(dev, video);
1908 if (ACPI_FAILURE(status)) {
1909 printk(KERN_WARNING PREFIX
1910 "Cant attach device");
1917 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1920 struct acpi_video_bus *video;
1923 if (!device || !device->video)
1926 video = device->video;
1928 acpi_video_device_remove_fs(device->dev);
1930 status = acpi_remove_notify_handler(device->dev->handle,
1932 acpi_video_device_notify);
1933 backlight_device_unregister(device->backlight);
1935 sysfs_remove_link(&device->dev->dev.kobj,
1937 sysfs_remove_link(&device->cdev->device.kobj,
1939 thermal_cooling_device_unregister(device->cdev);
1940 device->cdev = NULL;
1942 video_output_unregister(device->output_dev);
1947 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1950 struct acpi_video_device *dev, *next;
1952 mutex_lock(&video->device_list_lock);
1954 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1956 status = acpi_video_bus_put_one_device(dev);
1957 if (ACPI_FAILURE(status))
1958 printk(KERN_WARNING PREFIX
1959 "hhuuhhuu bug in acpi video driver.\n");
1961 if (dev->brightness) {
1962 kfree(dev->brightness->levels);
1963 kfree(dev->brightness);
1965 list_del(&dev->entry);
1969 mutex_unlock(&video->device_list_lock);
1974 /* acpi_video interface */
1976 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1978 return acpi_video_bus_DOS(video, 0, 0);
1981 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1983 return acpi_video_bus_DOS(video, 0, 1);
1986 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1988 struct acpi_video_bus *video = data;
1989 struct acpi_device *device = NULL;
1990 struct input_dev *input;
1996 device = video->device;
1997 input = video->input;
2000 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
2001 * most likely via hotkey. */
2002 acpi_bus_generate_proc_event(device, event, 0);
2003 keycode = KEY_SWITCHVIDEOMODE;
2006 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
2008 acpi_video_device_enumerate(video);
2009 acpi_video_device_rebind(video);
2010 acpi_bus_generate_proc_event(device, event, 0);
2011 keycode = KEY_SWITCHVIDEOMODE;
2014 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
2015 acpi_bus_generate_proc_event(device, event, 0);
2016 keycode = KEY_SWITCHVIDEOMODE;
2018 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
2019 acpi_bus_generate_proc_event(device, event, 0);
2020 keycode = KEY_VIDEO_NEXT;
2022 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
2023 acpi_bus_generate_proc_event(device, event, 0);
2024 keycode = KEY_VIDEO_PREV;
2028 keycode = KEY_UNKNOWN;
2029 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2030 "Unsupported event [0x%x]\n", event));
2034 acpi_notifier_call_chain(device, event, 0);
2035 input_report_key(input, keycode, 1);
2037 input_report_key(input, keycode, 0);
2043 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
2045 struct acpi_video_device *video_device = data;
2046 struct acpi_device *device = NULL;
2047 struct acpi_video_bus *bus;
2048 struct input_dev *input;
2054 device = video_device->dev;
2055 bus = video_device->video;
2059 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
2060 if (brightness_switch_enabled)
2061 acpi_video_switch_brightness(video_device, event);
2062 acpi_bus_generate_proc_event(device, event, 0);
2063 keycode = KEY_BRIGHTNESS_CYCLE;
2065 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
2066 if (brightness_switch_enabled)
2067 acpi_video_switch_brightness(video_device, event);
2068 acpi_bus_generate_proc_event(device, event, 0);
2069 keycode = KEY_BRIGHTNESSUP;
2071 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
2072 if (brightness_switch_enabled)
2073 acpi_video_switch_brightness(video_device, event);
2074 acpi_bus_generate_proc_event(device, event, 0);
2075 keycode = KEY_BRIGHTNESSDOWN;
2077 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
2078 if (brightness_switch_enabled)
2079 acpi_video_switch_brightness(video_device, event);
2080 acpi_bus_generate_proc_event(device, event, 0);
2081 keycode = KEY_BRIGHTNESS_ZERO;
2083 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
2084 if (brightness_switch_enabled)
2085 acpi_video_switch_brightness(video_device, event);
2086 acpi_bus_generate_proc_event(device, event, 0);
2087 keycode = KEY_DISPLAY_OFF;
2090 keycode = KEY_UNKNOWN;
2091 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2092 "Unsupported event [0x%x]\n", event));
2096 acpi_notifier_call_chain(device, event, 0);
2097 input_report_key(input, keycode, 1);
2099 input_report_key(input, keycode, 0);
2105 static int instance;
2106 static int acpi_video_resume(struct acpi_device *device)
2108 struct acpi_video_bus *video;
2109 struct acpi_video_device *video_device;
2112 if (!device || !acpi_driver_data(device))
2115 video = acpi_driver_data(device);
2117 for (i = 0; i < video->attached_count; i++) {
2118 video_device = video->attached_array[i].bind_info;
2119 if (video_device && video_device->backlight)
2120 acpi_video_set_brightness(video_device->backlight);
2125 static int acpi_video_bus_add(struct acpi_device *device)
2128 struct acpi_video_bus *video;
2129 struct input_dev *input;
2132 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2136 /* a hack to fix the duplicate name "VID" problem on T61 */
2137 if (!strcmp(device->pnp.bus_id, "VID")) {
2139 device->pnp.bus_id[3] = '0' + instance;
2142 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2143 if (!strcmp(device->pnp.bus_id, "VGA")) {
2145 device->pnp.bus_id[3] = '0' + instance;
2149 video->device = device;
2150 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2151 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2152 device->driver_data = video;
2154 acpi_video_bus_find_cap(video);
2155 error = acpi_video_bus_check(video);
2157 goto err_free_video;
2159 error = acpi_video_bus_add_fs(device);
2161 goto err_free_video;
2163 mutex_init(&video->device_list_lock);
2164 INIT_LIST_HEAD(&video->video_device_list);
2166 acpi_video_bus_get_devices(video, device);
2167 acpi_video_bus_start_devices(video);
2169 status = acpi_install_notify_handler(device->handle,
2171 acpi_video_bus_notify, video);
2172 if (ACPI_FAILURE(status)) {
2173 printk(KERN_ERR PREFIX
2174 "Error installing notify handler\n");
2176 goto err_stop_video;
2179 video->input = input = input_allocate_device();
2182 goto err_uninstall_notify;
2185 snprintf(video->phys, sizeof(video->phys),
2186 "%s/video/input0", acpi_device_hid(video->device));
2188 input->name = acpi_device_name(video->device);
2189 input->phys = video->phys;
2190 input->id.bustype = BUS_HOST;
2191 input->id.product = 0x06;
2192 input->dev.parent = &device->dev;
2193 input->evbit[0] = BIT(EV_KEY);
2194 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2195 set_bit(KEY_VIDEO_NEXT, input->keybit);
2196 set_bit(KEY_VIDEO_PREV, input->keybit);
2197 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2198 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2199 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2200 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2201 set_bit(KEY_DISPLAY_OFF, input->keybit);
2202 set_bit(KEY_UNKNOWN, input->keybit);
2204 error = input_register_device(input);
2206 goto err_free_input_dev;
2208 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2209 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2210 video->flags.multihead ? "yes" : "no",
2211 video->flags.rom ? "yes" : "no",
2212 video->flags.post ? "yes" : "no");
2217 input_free_device(input);
2218 err_uninstall_notify:
2219 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2220 acpi_video_bus_notify);
2222 acpi_video_bus_stop_devices(video);
2223 acpi_video_bus_put_devices(video);
2224 kfree(video->attached_array);
2225 acpi_video_bus_remove_fs(device);
2228 device->driver_data = NULL;
2233 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2235 acpi_status status = 0;
2236 struct acpi_video_bus *video = NULL;
2239 if (!device || !acpi_driver_data(device))
2242 video = acpi_driver_data(device);
2244 acpi_video_bus_stop_devices(video);
2246 status = acpi_remove_notify_handler(video->device->handle,
2248 acpi_video_bus_notify);
2250 acpi_video_bus_put_devices(video);
2251 acpi_video_bus_remove_fs(device);
2253 input_unregister_device(video->input);
2254 kfree(video->attached_array);
2260 static int __init intel_opregion_present(void)
2262 #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2263 struct pci_dev *dev = NULL;
2266 for_each_pci_dev(dev) {
2267 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2269 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2271 pci_read_config_dword(dev, 0xfc, &address);
2280 int acpi_video_register(void)
2284 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2285 if (!acpi_video_dir)
2287 acpi_video_dir->owner = THIS_MODULE;
2289 result = acpi_bus_register_driver(&acpi_video_bus);
2291 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2297 EXPORT_SYMBOL(acpi_video_register);
2300 * This is kind of nasty. Hardware using Intel chipsets may require
2301 * the video opregion code to be run first in order to initialise
2302 * state before any ACPI video calls are made. To handle this we defer
2303 * registration of the video class until the opregion code has run.
2306 static int __init acpi_video_init(void)
2308 if (intel_opregion_present())
2311 return acpi_video_register();
2314 static void __exit acpi_video_exit(void)
2317 acpi_bus_unregister_driver(&acpi_video_bus);
2319 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2324 module_init(acpi_video_init);
2325 module_exit(acpi_video_exit);