2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/thermal.h>
38 #include <linux/video_output.h>
39 #include <linux/sort.h>
40 #include <asm/uaccess.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device *device);
78 static int acpi_video_bus_remove(struct acpi_device *device, int type);
79 static int acpi_video_resume(struct acpi_device *device);
81 static const struct acpi_device_id video_device_ids[] = {
85 MODULE_DEVICE_TABLE(acpi, video_device_ids);
87 static struct acpi_driver acpi_video_bus = {
89 .class = ACPI_VIDEO_CLASS,
90 .ids = video_device_ids,
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
94 .resume = acpi_video_resume,
98 struct acpi_video_bus_flags {
99 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
105 struct acpi_video_bus_cap {
106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
115 struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment:4; /*This field differentiates the display type */
118 u32 display_type:4; /*Describe the specific type in use */
119 u32 vendor_specific:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device {
131 struct acpi_video_device_attrib attrib;
133 struct acpi_video_device *bind_info;
136 struct acpi_video_bus {
137 struct acpi_device *device;
139 struct acpi_video_enumerated_device *attached_array;
141 struct acpi_video_bus_cap cap;
142 struct acpi_video_bus_flags flags;
143 struct list_head video_device_list;
144 struct mutex device_list_lock; /* protects video_device_list */
145 struct proc_dir_entry *dir;
146 struct input_dev *input;
147 char phys[32]; /* for input device */
150 struct acpi_video_device_flags {
160 struct acpi_video_device_cap {
161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
164 u8 _BQC:1; /* Get current brightness level */
165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
171 struct acpi_video_brightness_flags {
172 u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */
173 u8 _BCL_reversed:1; /* _BCL package is in a reversed order*/
174 u8 _BCL_use_index:1; /* levels in _BCL are index values */
175 u8 _BCM_use_index:1; /* input of _BCM is an index value */
176 u8 _BQC_use_index:1; /* _BQC returns an index value */
179 struct acpi_video_device_brightness {
183 struct acpi_video_brightness_flags flags;
186 struct acpi_video_device {
187 unsigned long device_id;
188 struct acpi_video_device_flags flags;
189 struct acpi_video_device_cap cap;
190 struct list_head entry;
191 struct acpi_video_bus *video;
192 struct acpi_device *dev;
193 struct acpi_video_device_brightness *brightness;
194 struct backlight_device *backlight;
195 struct thermal_cooling_device *cdev;
196 struct output_device *output_dev;
200 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
201 static struct file_operations acpi_video_bus_info_fops = {
202 .owner = THIS_MODULE,
203 .open = acpi_video_bus_info_open_fs,
206 .release = single_release,
209 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
210 static struct file_operations acpi_video_bus_ROM_fops = {
211 .owner = THIS_MODULE,
212 .open = acpi_video_bus_ROM_open_fs,
215 .release = single_release,
218 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
220 static struct file_operations acpi_video_bus_POST_info_fops = {
221 .owner = THIS_MODULE,
222 .open = acpi_video_bus_POST_info_open_fs,
225 .release = single_release,
228 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
229 static struct file_operations acpi_video_bus_POST_fops = {
230 .owner = THIS_MODULE,
231 .open = acpi_video_bus_POST_open_fs,
234 .release = single_release,
237 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
238 static struct file_operations acpi_video_bus_DOS_fops = {
239 .owner = THIS_MODULE,
240 .open = acpi_video_bus_DOS_open_fs,
243 .release = single_release,
247 static int acpi_video_device_info_open_fs(struct inode *inode,
249 static struct file_operations acpi_video_device_info_fops = {
250 .owner = THIS_MODULE,
251 .open = acpi_video_device_info_open_fs,
254 .release = single_release,
257 static int acpi_video_device_state_open_fs(struct inode *inode,
259 static struct file_operations acpi_video_device_state_fops = {
260 .owner = THIS_MODULE,
261 .open = acpi_video_device_state_open_fs,
264 .release = single_release,
267 static int acpi_video_device_brightness_open_fs(struct inode *inode,
269 static struct file_operations acpi_video_device_brightness_fops = {
270 .owner = THIS_MODULE,
271 .open = acpi_video_device_brightness_open_fs,
274 .release = single_release,
277 static int acpi_video_device_EDID_open_fs(struct inode *inode,
279 static struct file_operations acpi_video_device_EDID_fops = {
280 .owner = THIS_MODULE,
281 .open = acpi_video_device_EDID_open_fs,
284 .release = single_release,
287 static char device_decode[][30] = {
288 "motherboard VGA device",
294 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
295 static void acpi_video_device_rebind(struct acpi_video_bus *video);
296 static void acpi_video_device_bind(struct acpi_video_bus *video,
297 struct acpi_video_device *device);
298 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
299 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
301 static int acpi_video_device_lcd_get_level_current(
302 struct acpi_video_device *device,
303 unsigned long long *level);
304 static int acpi_video_get_next_level(struct acpi_video_device *device,
305 u32 level_current, u32 event);
306 static int acpi_video_switch_brightness(struct acpi_video_device *device,
308 static int acpi_video_device_get_state(struct acpi_video_device *device,
309 unsigned long long *state);
310 static int acpi_video_output_get(struct output_device *od);
311 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
313 /*backlight device sysfs support*/
314 static int acpi_video_get_brightness(struct backlight_device *bd)
316 unsigned long long cur_level;
318 struct acpi_video_device *vd =
319 (struct acpi_video_device *)bl_get_data(bd);
321 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
323 for (i = 2; i < vd->brightness->count; i++) {
324 if (vd->brightness->levels[i] == cur_level)
325 /* The first two entries are special - see page 575
326 of the ACPI spec 3.0 */
332 static int acpi_video_set_brightness(struct backlight_device *bd)
334 int request_level = bd->props.brightness + 2;
335 struct acpi_video_device *vd =
336 (struct acpi_video_device *)bl_get_data(bd);
338 return acpi_video_device_lcd_set_level(vd,
339 vd->brightness->levels[request_level]);
342 static struct backlight_ops acpi_backlight_ops = {
343 .get_brightness = acpi_video_get_brightness,
344 .update_status = acpi_video_set_brightness,
347 /*video output device sysfs support*/
348 static int acpi_video_output_get(struct output_device *od)
350 unsigned long long state;
351 struct acpi_video_device *vd =
352 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
353 acpi_video_device_get_state(vd, &state);
357 static int acpi_video_output_set(struct output_device *od)
359 unsigned long state = od->request_state;
360 struct acpi_video_device *vd=
361 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
362 return acpi_video_device_set_state(vd, state);
365 static struct output_properties acpi_output_properties = {
366 .set_state = acpi_video_output_set,
367 .get_status = acpi_video_output_get,
371 /* thermal cooling device callbacks */
372 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
374 struct acpi_device *device = cdev->devdata;
375 struct acpi_video_device *video = acpi_driver_data(device);
377 return sprintf(buf, "%d\n", video->brightness->count - 3);
380 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
382 struct acpi_device *device = cdev->devdata;
383 struct acpi_video_device *video = acpi_driver_data(device);
384 unsigned long long level;
387 if (acpi_video_device_lcd_get_level_current(video, &level))
389 for (state = 2; state < video->brightness->count; state++)
390 if (level == video->brightness->levels[state])
391 return sprintf(buf, "%d\n",
392 video->brightness->count - state - 1);
398 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
400 struct acpi_device *device = cdev->devdata;
401 struct acpi_video_device *video = acpi_driver_data(device);
404 if ( state >= video->brightness->count - 2)
407 state = video->brightness->count - state;
408 level = video->brightness->levels[state -1];
409 return acpi_video_device_lcd_set_level(video, level);
412 static struct thermal_cooling_device_ops video_cooling_ops = {
413 .get_max_state = video_get_max_state,
414 .get_cur_state = video_get_cur_state,
415 .set_cur_state = video_set_cur_state,
418 /* --------------------------------------------------------------------------
420 -------------------------------------------------------------------------- */
425 acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
429 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
435 acpi_video_device_get_state(struct acpi_video_device *device,
436 unsigned long long *state)
440 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
446 acpi_video_device_set_state(struct acpi_video_device *device, int state)
449 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
450 struct acpi_object_list args = { 1, &arg0 };
451 unsigned long long ret;
454 arg0.integer.value = state;
455 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
461 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
462 union acpi_object **levels)
465 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
466 union acpi_object *obj;
471 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
472 if (!ACPI_SUCCESS(status))
474 obj = (union acpi_object *)buffer.pointer;
475 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
476 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
486 kfree(buffer.pointer);
492 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
495 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
496 struct acpi_object_list args = { 1, &arg0 };
499 arg0.integer.value = level;
501 status = acpi_evaluate_object(device->dev->handle, "_BCM",
503 if (ACPI_FAILURE(status)) {
504 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
508 device->brightness->curr = level;
509 for (state = 2; state < device->brightness->count; state++)
510 if (level == device->brightness->levels[state]) {
511 if (device->backlight)
512 device->backlight->props.brightness = state - 2;
516 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
521 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
522 unsigned long long *level)
524 acpi_status status = AE_OK;
526 if (device->cap._BQC) {
527 status = acpi_evaluate_integer(device->dev->handle, "_BQC",
529 if (ACPI_SUCCESS(status)) {
530 if (device->brightness->flags._BQC_use_index) {
531 if (device->brightness->flags._BCL_reversed)
532 *level = device->brightness->count
534 *level = device->brightness->levels[*level + 2];
537 device->brightness->curr = *level;
541 * should we return an error or ignore this failure?
542 * dev->brightness->curr is a cached value which stores
543 * the correct current backlight level in most cases.
544 * ACPI video backlight still works w/ buggy _BQC.
545 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
547 ACPI_WARNING((AE_INFO, "Evaluating _BQC failed"));
548 device->cap._BQC = 0;
552 *level = device->brightness->curr;
557 acpi_video_device_EDID(struct acpi_video_device *device,
558 union acpi_object **edid, ssize_t length)
561 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
562 union acpi_object *obj;
563 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
564 struct acpi_object_list args = { 1, &arg0 };
572 arg0.integer.value = 1;
573 else if (length == 256)
574 arg0.integer.value = 2;
578 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
579 if (ACPI_FAILURE(status))
582 obj = buffer.pointer;
584 if (obj && obj->type == ACPI_TYPE_BUFFER)
587 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
598 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
601 unsigned long long tmp;
602 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
603 struct acpi_object_list args = { 1, &arg0 };
606 arg0.integer.value = option;
608 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
609 if (ACPI_SUCCESS(status))
610 status = tmp ? (-EINVAL) : (AE_OK);
616 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
620 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
626 acpi_video_bus_POST_options(struct acpi_video_bus *video,
627 unsigned long long *options)
631 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
639 * video : video bus device pointer
641 * 0. The system BIOS should NOT automatically switch(toggle)
642 * the active display output.
643 * 1. The system BIOS should automatically switch (toggle) the
644 * active display output. No switch event.
645 * 2. The _DGS value should be locked.
646 * 3. The system BIOS should not automatically switch (toggle) the
647 * active display output, but instead generate the display switch
650 * 0. The system BIOS should automatically control the brightness level
651 * of the LCD when the power changes from AC to DC
652 * 1. The system BIOS should NOT automatically control the brightness
653 * level of the LCD when the power changes from AC to DC.
659 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
661 acpi_integer status = 0;
662 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
663 struct acpi_object_list args = { 1, &arg0 };
666 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
670 arg0.integer.value = (lcd_flag << 2) | bios_flag;
671 video->dos_setting = arg0.integer.value;
672 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
679 * Simple comparison function used to sort backlight levels.
683 acpi_video_cmp_level(const void *a, const void *b)
685 return *(int *)a - *(int *)b;
690 * device : video output device (LCD, CRT, ..)
693 * Maximum brightness level
695 * Allocate and initialize device->brightness.
699 acpi_video_init_brightness(struct acpi_video_device *device)
701 union acpi_object *obj = NULL;
702 int i, max_level = 0, count = 0, level_ac_battery = 0;
703 unsigned long long level, level_old;
704 union acpi_object *o;
705 struct acpi_video_device_brightness *br = NULL;
706 int result = -EINVAL;
708 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
709 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
710 "LCD brightness level\n"));
714 if (obj->package.count < 2)
717 br = kzalloc(sizeof(*br), GFP_KERNEL);
719 printk(KERN_ERR "can't allocate memory\n");
724 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
731 for (i = 0; i < obj->package.count; i++) {
732 o = (union acpi_object *)&obj->package.elements[i];
733 if (o->type != ACPI_TYPE_INTEGER) {
734 printk(KERN_ERR PREFIX "Invalid data\n");
737 br->levels[count] = (u32) o->integer.value;
739 if (br->levels[count] > max_level)
740 max_level = br->levels[count];
745 * some buggy BIOS don't export the levels
746 * when machine is on AC/Battery in _BCL package.
747 * In this case, the first two elements in _BCL packages
748 * are also supported brightness levels that OS should take care of.
750 for (i = 2; i < count; i++)
751 if (br->levels[i] == br->levels[0] ||
752 br->levels[i] == br->levels[1])
755 if (level_ac_battery < 2) {
756 level_ac_battery = 2 - level_ac_battery;
757 br->flags._BCL_no_ac_battery_levels = 1;
758 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
759 br->levels[i] = br->levels[i - level_ac_battery];
760 count += level_ac_battery;
761 } else if (level_ac_battery > 2)
762 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
764 /* Check if the _BCL package is in a reversed order */
765 if (max_level == br->levels[2]) {
766 br->flags._BCL_reversed = 1;
767 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
768 acpi_video_cmp_level, NULL);
769 } else if (max_level != br->levels[count - 1])
771 "Found unordered _BCL package\n"));
774 device->brightness = br;
776 /* Check the input/output of _BQC/_BCL/_BCM */
777 if ((max_level < 100) && (max_level <= (count - 2)))
778 br->flags._BCL_use_index = 1;
781 * _BCM is always consistent with _BCL,
782 * at least for all the laptops we have ever seen.
784 br->flags._BCM_use_index = br->flags._BCL_use_index;
786 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
787 br->curr = max_level;
788 result = acpi_video_device_lcd_get_level_current(device, &level_old);
790 goto out_free_levels;
792 result = acpi_video_device_lcd_set_level(device, br->curr);
794 goto out_free_levels;
796 result = acpi_video_device_lcd_get_level_current(device, &level);
798 goto out_free_levels;
800 if ((level != level_old) && !br->flags._BCM_use_index) {
802 * This piece of code does not work correctly if the current
803 * brightness levels is 0.
804 * But I guess boxes that boot with such a dark screen are rare
805 * and no more code is needed to cover this specifial case.
808 if (level_ac_battery != 2) {
810 * For now, we don't support the _BCL like this:
811 * 16, 15, 0, 1, 2, 3, ..., 14, 15, 16
812 * because we may mess up the index returned by _BQC.
813 * Plus: we have not got a box like this.
815 ACPI_ERROR((AE_INFO, "_BCL not supported\n"));
817 br->flags._BQC_use_index = 1;
820 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
821 "found %d brightness levels\n", count - 2));
830 device->brightness = NULL;
837 * device : video output device (LCD, CRT, ..)
842 * Find out all required AML methods defined under the output
846 static void acpi_video_device_find_cap(struct acpi_video_device *device)
848 acpi_handle h_dummy1;
851 memset(&device->cap, 0, sizeof(device->cap));
853 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
854 device->cap._ADR = 1;
856 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
857 device->cap._BCL = 1;
859 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
860 device->cap._BCM = 1;
862 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
863 device->cap._BQC = 1;
864 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
865 device->cap._DDC = 1;
867 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
868 device->cap._DCS = 1;
870 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
871 device->cap._DGS = 1;
873 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
874 device->cap._DSS = 1;
877 if (acpi_video_backlight_support()) {
879 static int count = 0;
882 result = acpi_video_init_brightness(device);
885 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
889 sprintf(name, "acpi_video%d", count++);
890 device->backlight = backlight_device_register(name,
891 NULL, device, &acpi_backlight_ops);
892 device->backlight->props.max_brightness = device->brightness->count-3;
895 device->cdev = thermal_cooling_device_register("LCD",
896 device->dev, &video_cooling_ops);
897 if (IS_ERR(device->cdev))
900 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
902 result = sysfs_create_link(&device->dev->dev.kobj,
903 &device->cdev->device.kobj,
906 printk(KERN_ERR PREFIX "Create sysfs link\n");
907 result = sysfs_create_link(&device->cdev->device.kobj,
908 &device->dev->dev.kobj, "device");
910 printk(KERN_ERR PREFIX "Create sysfs link\n");
914 if (acpi_video_display_switch_support()) {
916 if (device->cap._DCS && device->cap._DSS) {
919 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
922 sprintf(name, "acpi_video%d", count++);
923 device->output_dev = video_output_register(name,
924 NULL, device, &acpi_output_properties);
932 * device : video output device (VGA)
937 * Find out all required AML methods defined under the video bus device.
940 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
942 acpi_handle h_dummy1;
944 memset(&video->cap, 0, sizeof(video->cap));
945 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
948 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
951 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
954 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
957 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
960 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
966 * Check whether the video bus device has required AML method to
967 * support the desired features
970 static int acpi_video_bus_check(struct acpi_video_bus *video)
972 acpi_status status = -ENOENT;
978 dev = acpi_get_physical_pci_device(video->device->handle);
983 /* Since there is no HID, CID and so on for VGA driver, we have
984 * to check well known required nodes.
987 /* Does this device support video switching? */
988 if (video->cap._DOS) {
989 video->flags.multihead = 1;
993 /* Does this device support retrieving a video ROM? */
994 if (video->cap._ROM) {
995 video->flags.rom = 1;
999 /* Does this device support configuring which video device to POST? */
1000 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
1001 video->flags.post = 1;
1008 /* --------------------------------------------------------------------------
1009 FS Interface (/proc)
1010 -------------------------------------------------------------------------- */
1012 static struct proc_dir_entry *acpi_video_dir;
1016 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
1018 struct acpi_video_device *dev = seq->private;
1024 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1025 seq_printf(seq, "type: ");
1027 seq_printf(seq, "CRT\n");
1028 else if (dev->flags.lcd)
1029 seq_printf(seq, "LCD\n");
1030 else if (dev->flags.tvout)
1031 seq_printf(seq, "TVOUT\n");
1032 else if (dev->flags.dvi)
1033 seq_printf(seq, "DVI\n");
1035 seq_printf(seq, "UNKNOWN\n");
1037 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
1044 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
1046 return single_open(file, acpi_video_device_info_seq_show,
1050 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
1053 struct acpi_video_device *dev = seq->private;
1054 unsigned long long state;
1060 status = acpi_video_device_get_state(dev, &state);
1061 seq_printf(seq, "state: ");
1062 if (ACPI_SUCCESS(status))
1063 seq_printf(seq, "0x%02llx\n", state);
1065 seq_printf(seq, "<not supported>\n");
1067 status = acpi_video_device_query(dev, &state);
1068 seq_printf(seq, "query: ");
1069 if (ACPI_SUCCESS(status))
1070 seq_printf(seq, "0x%02llx\n", state);
1072 seq_printf(seq, "<not supported>\n");
1079 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
1081 return single_open(file, acpi_video_device_state_seq_show,
1086 acpi_video_device_write_state(struct file *file,
1087 const char __user * buffer,
1088 size_t count, loff_t * data)
1091 struct seq_file *m = file->private_data;
1092 struct acpi_video_device *dev = m->private;
1093 char str[12] = { 0 };
1097 if (!dev || count + 1 > sizeof str)
1100 if (copy_from_user(str, buffer, count))
1104 state = simple_strtoul(str, NULL, 0);
1105 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1107 status = acpi_video_device_set_state(dev, state);
1116 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1118 struct acpi_video_device *dev = seq->private;
1122 if (!dev || !dev->brightness) {
1123 seq_printf(seq, "<not supported>\n");
1127 seq_printf(seq, "levels: ");
1128 for (i = 2; i < dev->brightness->count; i++)
1129 seq_printf(seq, " %d", dev->brightness->levels[i]);
1130 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1136 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1138 return single_open(file, acpi_video_device_brightness_seq_show,
1143 acpi_video_device_write_brightness(struct file *file,
1144 const char __user * buffer,
1145 size_t count, loff_t * data)
1147 struct seq_file *m = file->private_data;
1148 struct acpi_video_device *dev = m->private;
1149 char str[5] = { 0 };
1150 unsigned int level = 0;
1154 if (!dev || !dev->brightness || count + 1 > sizeof str)
1157 if (copy_from_user(str, buffer, count))
1161 level = simple_strtoul(str, NULL, 0);
1166 /* validate through the list of available levels */
1167 for (i = 2; i < dev->brightness->count; i++)
1168 if (level == dev->brightness->levels[i]) {
1169 if (!acpi_video_device_lcd_set_level(dev, level))
1177 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1179 struct acpi_video_device *dev = seq->private;
1182 union acpi_object *edid = NULL;
1188 status = acpi_video_device_EDID(dev, &edid, 128);
1189 if (ACPI_FAILURE(status)) {
1190 status = acpi_video_device_EDID(dev, &edid, 256);
1193 if (ACPI_FAILURE(status)) {
1197 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1198 for (i = 0; i < edid->buffer.length; i++)
1199 seq_putc(seq, edid->buffer.pointer[i]);
1204 seq_printf(seq, "<not supported>\n");
1212 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1214 return single_open(file, acpi_video_device_EDID_seq_show,
1218 static int acpi_video_device_add_fs(struct acpi_device *device)
1220 struct proc_dir_entry *entry, *device_dir;
1221 struct acpi_video_device *vid_dev;
1223 vid_dev = acpi_driver_data(device);
1227 device_dir = proc_mkdir(acpi_device_bid(device),
1228 vid_dev->video->dir);
1232 device_dir->owner = THIS_MODULE;
1235 entry = proc_create_data("info", S_IRUGO, device_dir,
1236 &acpi_video_device_info_fops, acpi_driver_data(device));
1238 goto err_remove_dir;
1241 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1242 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1244 &acpi_video_device_state_fops,
1245 acpi_driver_data(device));
1247 goto err_remove_info;
1249 /* 'brightness' [R/W] */
1250 acpi_video_device_brightness_fops.write =
1251 acpi_video_device_write_brightness;
1252 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1254 &acpi_video_device_brightness_fops,
1255 acpi_driver_data(device));
1257 goto err_remove_state;
1260 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1261 &acpi_video_device_EDID_fops,
1262 acpi_driver_data(device));
1264 goto err_remove_brightness;
1266 acpi_device_dir(device) = device_dir;
1270 err_remove_brightness:
1271 remove_proc_entry("brightness", device_dir);
1273 remove_proc_entry("state", device_dir);
1275 remove_proc_entry("info", device_dir);
1277 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1281 static int acpi_video_device_remove_fs(struct acpi_device *device)
1283 struct acpi_video_device *vid_dev;
1284 struct proc_dir_entry *device_dir;
1286 vid_dev = acpi_driver_data(device);
1287 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1290 device_dir = acpi_device_dir(device);
1292 remove_proc_entry("info", device_dir);
1293 remove_proc_entry("state", device_dir);
1294 remove_proc_entry("brightness", device_dir);
1295 remove_proc_entry("EDID", device_dir);
1296 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1297 acpi_device_dir(device) = NULL;
1304 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1306 struct acpi_video_bus *video = seq->private;
1312 seq_printf(seq, "Switching heads: %s\n",
1313 video->flags.multihead ? "yes" : "no");
1314 seq_printf(seq, "Video ROM: %s\n",
1315 video->flags.rom ? "yes" : "no");
1316 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1317 video->flags.post ? "yes" : "no");
1323 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1325 return single_open(file, acpi_video_bus_info_seq_show,
1329 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1331 struct acpi_video_bus *video = seq->private;
1337 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1338 seq_printf(seq, "<TODO>\n");
1344 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1346 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1349 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1351 struct acpi_video_bus *video = seq->private;
1352 unsigned long long options;
1359 status = acpi_video_bus_POST_options(video, &options);
1360 if (ACPI_SUCCESS(status)) {
1361 if (!(options & 1)) {
1362 printk(KERN_WARNING PREFIX
1363 "The motherboard VGA device is not listed as a possible POST device.\n");
1364 printk(KERN_WARNING PREFIX
1365 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1367 printk(KERN_WARNING "%llx\n", options);
1368 seq_printf(seq, "can POST: <integrated video>");
1370 seq_printf(seq, " <PCI video>");
1372 seq_printf(seq, " <AGP video>");
1373 seq_putc(seq, '\n');
1375 seq_printf(seq, "<not supported>\n");
1381 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1383 return single_open(file, acpi_video_bus_POST_info_seq_show,
1387 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1389 struct acpi_video_bus *video = seq->private;
1391 unsigned long long id;
1397 status = acpi_video_bus_get_POST(video, &id);
1398 if (!ACPI_SUCCESS(status)) {
1399 seq_printf(seq, "<not supported>\n");
1402 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1408 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1410 struct acpi_video_bus *video = seq->private;
1413 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1418 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1420 return single_open(file, acpi_video_bus_POST_seq_show,
1424 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1426 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1430 acpi_video_bus_write_POST(struct file *file,
1431 const char __user * buffer,
1432 size_t count, loff_t * data)
1435 struct seq_file *m = file->private_data;
1436 struct acpi_video_bus *video = m->private;
1437 char str[12] = { 0 };
1438 unsigned long long opt, options;
1441 if (!video || count + 1 > sizeof str)
1444 status = acpi_video_bus_POST_options(video, &options);
1445 if (!ACPI_SUCCESS(status))
1448 if (copy_from_user(str, buffer, count))
1452 opt = strtoul(str, NULL, 0);
1456 /* just in case an OEM 'forgot' the motherboard... */
1459 if (options & (1ul << opt)) {
1460 status = acpi_video_bus_set_POST(video, opt);
1461 if (!ACPI_SUCCESS(status))
1470 acpi_video_bus_write_DOS(struct file *file,
1471 const char __user * buffer,
1472 size_t count, loff_t * data)
1475 struct seq_file *m = file->private_data;
1476 struct acpi_video_bus *video = m->private;
1477 char str[12] = { 0 };
1481 if (!video || count + 1 > sizeof str)
1484 if (copy_from_user(str, buffer, count))
1488 opt = strtoul(str, NULL, 0);
1492 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1494 if (!ACPI_SUCCESS(status))
1500 static int acpi_video_bus_add_fs(struct acpi_device *device)
1502 struct acpi_video_bus *video = acpi_driver_data(device);
1503 struct proc_dir_entry *device_dir;
1504 struct proc_dir_entry *entry;
1506 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1510 device_dir->owner = THIS_MODULE;
1513 entry = proc_create_data("info", S_IRUGO, device_dir,
1514 &acpi_video_bus_info_fops,
1515 acpi_driver_data(device));
1517 goto err_remove_dir;
1520 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1521 &acpi_video_bus_ROM_fops,
1522 acpi_driver_data(device));
1524 goto err_remove_info;
1526 /* 'POST_info' [R] */
1527 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1528 &acpi_video_bus_POST_info_fops,
1529 acpi_driver_data(device));
1531 goto err_remove_rom;
1534 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1535 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1537 &acpi_video_bus_POST_fops,
1538 acpi_driver_data(device));
1540 goto err_remove_post_info;
1543 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1544 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1546 &acpi_video_bus_DOS_fops,
1547 acpi_driver_data(device));
1549 goto err_remove_post;
1551 video->dir = acpi_device_dir(device) = device_dir;
1555 remove_proc_entry("POST", device_dir);
1556 err_remove_post_info:
1557 remove_proc_entry("POST_info", device_dir);
1559 remove_proc_entry("ROM", device_dir);
1561 remove_proc_entry("info", device_dir);
1563 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1567 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1569 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1572 remove_proc_entry("info", device_dir);
1573 remove_proc_entry("ROM", device_dir);
1574 remove_proc_entry("POST_info", device_dir);
1575 remove_proc_entry("POST", device_dir);
1576 remove_proc_entry("DOS", device_dir);
1577 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1578 acpi_device_dir(device) = NULL;
1584 /* --------------------------------------------------------------------------
1586 -------------------------------------------------------------------------- */
1588 /* device interface */
1589 static struct acpi_video_device_attrib*
1590 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1592 struct acpi_video_enumerated_device *ids;
1595 for (i = 0; i < video->attached_count; i++) {
1596 ids = &video->attached_array[i];
1597 if ((ids->value.int_val & 0xffff) == device_id)
1598 return &ids->value.attrib;
1605 acpi_video_bus_get_one_device(struct acpi_device *device,
1606 struct acpi_video_bus *video)
1608 unsigned long long device_id;
1610 struct acpi_video_device *data;
1611 struct acpi_video_device_attrib* attribute;
1613 if (!device || !video)
1617 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1618 if (ACPI_SUCCESS(status)) {
1620 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1624 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1625 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1626 device->driver_data = data;
1628 data->device_id = device_id;
1629 data->video = video;
1632 attribute = acpi_video_get_device_attr(video, device_id);
1634 if((attribute != NULL) && attribute->device_id_scheme) {
1635 switch (attribute->display_type) {
1636 case ACPI_VIDEO_DISPLAY_CRT:
1637 data->flags.crt = 1;
1639 case ACPI_VIDEO_DISPLAY_TV:
1640 data->flags.tvout = 1;
1642 case ACPI_VIDEO_DISPLAY_DVI:
1643 data->flags.dvi = 1;
1645 case ACPI_VIDEO_DISPLAY_LCD:
1646 data->flags.lcd = 1;
1649 data->flags.unknown = 1;
1652 if(attribute->bios_can_detect)
1653 data->flags.bios = 1;
1655 data->flags.unknown = 1;
1657 acpi_video_device_bind(video, data);
1658 acpi_video_device_find_cap(data);
1660 status = acpi_install_notify_handler(device->handle,
1662 acpi_video_device_notify,
1664 if (ACPI_FAILURE(status)) {
1665 printk(KERN_ERR PREFIX
1666 "Error installing notify handler\n");
1667 if(data->brightness)
1668 kfree(data->brightness->levels);
1669 kfree(data->brightness);
1674 mutex_lock(&video->device_list_lock);
1675 list_add_tail(&data->entry, &video->video_device_list);
1676 mutex_unlock(&video->device_list_lock);
1678 acpi_video_device_add_fs(device);
1688 * video : video bus device
1693 * Enumerate the video device list of the video bus,
1694 * bind the ids with the corresponding video devices
1695 * under the video bus.
1698 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1700 struct acpi_video_device *dev;
1702 mutex_lock(&video->device_list_lock);
1704 list_for_each_entry(dev, &video->video_device_list, entry)
1705 acpi_video_device_bind(video, dev);
1707 mutex_unlock(&video->device_list_lock);
1712 * video : video bus device
1713 * device : video output device under the video
1719 * Bind the ids with the corresponding video devices
1720 * under the video bus.
1724 acpi_video_device_bind(struct acpi_video_bus *video,
1725 struct acpi_video_device *device)
1727 struct acpi_video_enumerated_device *ids;
1730 for (i = 0; i < video->attached_count; i++) {
1731 ids = &video->attached_array[i];
1732 if (device->device_id == (ids->value.int_val & 0xffff)) {
1733 ids->bind_info = device;
1734 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1741 * video : video bus device
1746 * Call _DOD to enumerate all devices attached to display adapter
1750 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1755 struct acpi_video_enumerated_device *active_list;
1756 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1757 union acpi_object *dod = NULL;
1758 union acpi_object *obj;
1760 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1761 if (!ACPI_SUCCESS(status)) {
1762 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1766 dod = buffer.pointer;
1767 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1768 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1773 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1774 dod->package.count));
1776 active_list = kcalloc(1 + dod->package.count,
1777 sizeof(struct acpi_video_enumerated_device),
1785 for (i = 0; i < dod->package.count; i++) {
1786 obj = &dod->package.elements[i];
1788 if (obj->type != ACPI_TYPE_INTEGER) {
1789 printk(KERN_ERR PREFIX
1790 "Invalid _DOD data in element %d\n", i);
1794 active_list[count].value.int_val = obj->integer.value;
1795 active_list[count].bind_info = NULL;
1796 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1797 (int)obj->integer.value));
1801 kfree(video->attached_array);
1803 video->attached_array = active_list;
1804 video->attached_count = count;
1807 kfree(buffer.pointer);
1812 acpi_video_get_next_level(struct acpi_video_device *device,
1813 u32 level_current, u32 event)
1815 int min, max, min_above, max_below, i, l, delta = 255;
1816 max = max_below = 0;
1817 min = min_above = 255;
1818 /* Find closest level to level_current */
1819 for (i = 2; i < device->brightness->count; i++) {
1820 l = device->brightness->levels[i];
1821 if (abs(l - level_current) < abs(delta)) {
1822 delta = l - level_current;
1827 /* Ajust level_current to closest available level */
1828 level_current += delta;
1829 for (i = 2; i < device->brightness->count; i++) {
1830 l = device->brightness->levels[i];
1835 if (l < min_above && l > level_current)
1837 if (l > max_below && l < level_current)
1842 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1843 return (level_current < max) ? min_above : min;
1844 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1845 return (level_current < max) ? min_above : max;
1846 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1847 return (level_current > min) ? max_below : min;
1848 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1849 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1852 return level_current;
1857 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1859 unsigned long long level_current, level_next;
1860 int result = -EINVAL;
1862 if (!device->brightness)
1865 result = acpi_video_device_lcd_get_level_current(device,
1870 level_next = acpi_video_get_next_level(device, level_current, event);
1872 result = acpi_video_device_lcd_set_level(device, level_next);
1876 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1882 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1883 struct acpi_device *device)
1886 struct acpi_device *dev;
1888 acpi_video_device_enumerate(video);
1890 list_for_each_entry(dev, &device->children, node) {
1892 status = acpi_video_bus_get_one_device(dev, video);
1893 if (ACPI_FAILURE(status)) {
1894 printk(KERN_WARNING PREFIX
1895 "Cant attach device");
1902 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1905 struct acpi_video_bus *video;
1908 if (!device || !device->video)
1911 video = device->video;
1913 acpi_video_device_remove_fs(device->dev);
1915 status = acpi_remove_notify_handler(device->dev->handle,
1917 acpi_video_device_notify);
1918 backlight_device_unregister(device->backlight);
1920 sysfs_remove_link(&device->dev->dev.kobj,
1922 sysfs_remove_link(&device->cdev->device.kobj,
1924 thermal_cooling_device_unregister(device->cdev);
1925 device->cdev = NULL;
1927 video_output_unregister(device->output_dev);
1932 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1935 struct acpi_video_device *dev, *next;
1937 mutex_lock(&video->device_list_lock);
1939 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1941 status = acpi_video_bus_put_one_device(dev);
1942 if (ACPI_FAILURE(status))
1943 printk(KERN_WARNING PREFIX
1944 "hhuuhhuu bug in acpi video driver.\n");
1946 if (dev->brightness) {
1947 kfree(dev->brightness->levels);
1948 kfree(dev->brightness);
1950 list_del(&dev->entry);
1954 mutex_unlock(&video->device_list_lock);
1959 /* acpi_video interface */
1961 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1963 return acpi_video_bus_DOS(video, 0, 0);
1966 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1968 return acpi_video_bus_DOS(video, 0, 1);
1971 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1973 struct acpi_video_bus *video = data;
1974 struct acpi_device *device = NULL;
1975 struct input_dev *input;
1981 device = video->device;
1982 input = video->input;
1985 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1986 * most likely via hotkey. */
1987 acpi_bus_generate_proc_event(device, event, 0);
1988 keycode = KEY_SWITCHVIDEOMODE;
1991 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1993 acpi_video_device_enumerate(video);
1994 acpi_video_device_rebind(video);
1995 acpi_bus_generate_proc_event(device, event, 0);
1996 keycode = KEY_SWITCHVIDEOMODE;
1999 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
2000 acpi_bus_generate_proc_event(device, event, 0);
2001 keycode = KEY_SWITCHVIDEOMODE;
2003 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
2004 acpi_bus_generate_proc_event(device, event, 0);
2005 keycode = KEY_VIDEO_NEXT;
2007 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
2008 acpi_bus_generate_proc_event(device, event, 0);
2009 keycode = KEY_VIDEO_PREV;
2013 keycode = KEY_UNKNOWN;
2014 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2015 "Unsupported event [0x%x]\n", event));
2019 acpi_notifier_call_chain(device, event, 0);
2020 input_report_key(input, keycode, 1);
2022 input_report_key(input, keycode, 0);
2028 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
2030 struct acpi_video_device *video_device = data;
2031 struct acpi_device *device = NULL;
2032 struct acpi_video_bus *bus;
2033 struct input_dev *input;
2039 device = video_device->dev;
2040 bus = video_device->video;
2044 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
2045 if (brightness_switch_enabled)
2046 acpi_video_switch_brightness(video_device, event);
2047 acpi_bus_generate_proc_event(device, event, 0);
2048 keycode = KEY_BRIGHTNESS_CYCLE;
2050 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
2051 if (brightness_switch_enabled)
2052 acpi_video_switch_brightness(video_device, event);
2053 acpi_bus_generate_proc_event(device, event, 0);
2054 keycode = KEY_BRIGHTNESSUP;
2056 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
2057 if (brightness_switch_enabled)
2058 acpi_video_switch_brightness(video_device, event);
2059 acpi_bus_generate_proc_event(device, event, 0);
2060 keycode = KEY_BRIGHTNESSDOWN;
2062 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
2063 if (brightness_switch_enabled)
2064 acpi_video_switch_brightness(video_device, event);
2065 acpi_bus_generate_proc_event(device, event, 0);
2066 keycode = KEY_BRIGHTNESS_ZERO;
2068 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
2069 if (brightness_switch_enabled)
2070 acpi_video_switch_brightness(video_device, event);
2071 acpi_bus_generate_proc_event(device, event, 0);
2072 keycode = KEY_DISPLAY_OFF;
2075 keycode = KEY_UNKNOWN;
2076 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2077 "Unsupported event [0x%x]\n", event));
2081 acpi_notifier_call_chain(device, event, 0);
2082 input_report_key(input, keycode, 1);
2084 input_report_key(input, keycode, 0);
2090 static int instance;
2091 static int acpi_video_resume(struct acpi_device *device)
2093 struct acpi_video_bus *video;
2094 struct acpi_video_device *video_device;
2097 if (!device || !acpi_driver_data(device))
2100 video = acpi_driver_data(device);
2102 for (i = 0; i < video->attached_count; i++) {
2103 video_device = video->attached_array[i].bind_info;
2104 if (video_device && video_device->backlight)
2105 acpi_video_set_brightness(video_device->backlight);
2110 static int acpi_video_bus_add(struct acpi_device *device)
2113 struct acpi_video_bus *video;
2114 struct input_dev *input;
2117 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2121 /* a hack to fix the duplicate name "VID" problem on T61 */
2122 if (!strcmp(device->pnp.bus_id, "VID")) {
2124 device->pnp.bus_id[3] = '0' + instance;
2127 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2128 if (!strcmp(device->pnp.bus_id, "VGA")) {
2130 device->pnp.bus_id[3] = '0' + instance;
2134 video->device = device;
2135 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2136 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2137 device->driver_data = video;
2139 acpi_video_bus_find_cap(video);
2140 error = acpi_video_bus_check(video);
2142 goto err_free_video;
2144 error = acpi_video_bus_add_fs(device);
2146 goto err_free_video;
2148 mutex_init(&video->device_list_lock);
2149 INIT_LIST_HEAD(&video->video_device_list);
2151 acpi_video_bus_get_devices(video, device);
2152 acpi_video_bus_start_devices(video);
2154 status = acpi_install_notify_handler(device->handle,
2156 acpi_video_bus_notify, video);
2157 if (ACPI_FAILURE(status)) {
2158 printk(KERN_ERR PREFIX
2159 "Error installing notify handler\n");
2161 goto err_stop_video;
2164 video->input = input = input_allocate_device();
2167 goto err_uninstall_notify;
2170 snprintf(video->phys, sizeof(video->phys),
2171 "%s/video/input0", acpi_device_hid(video->device));
2173 input->name = acpi_device_name(video->device);
2174 input->phys = video->phys;
2175 input->id.bustype = BUS_HOST;
2176 input->id.product = 0x06;
2177 input->dev.parent = &device->dev;
2178 input->evbit[0] = BIT(EV_KEY);
2179 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2180 set_bit(KEY_VIDEO_NEXT, input->keybit);
2181 set_bit(KEY_VIDEO_PREV, input->keybit);
2182 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2183 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2184 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2185 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2186 set_bit(KEY_DISPLAY_OFF, input->keybit);
2187 set_bit(KEY_UNKNOWN, input->keybit);
2189 error = input_register_device(input);
2191 goto err_free_input_dev;
2193 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2194 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2195 video->flags.multihead ? "yes" : "no",
2196 video->flags.rom ? "yes" : "no",
2197 video->flags.post ? "yes" : "no");
2202 input_free_device(input);
2203 err_uninstall_notify:
2204 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2205 acpi_video_bus_notify);
2207 acpi_video_bus_stop_devices(video);
2208 acpi_video_bus_put_devices(video);
2209 kfree(video->attached_array);
2210 acpi_video_bus_remove_fs(device);
2213 device->driver_data = NULL;
2218 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2220 acpi_status status = 0;
2221 struct acpi_video_bus *video = NULL;
2224 if (!device || !acpi_driver_data(device))
2227 video = acpi_driver_data(device);
2229 acpi_video_bus_stop_devices(video);
2231 status = acpi_remove_notify_handler(video->device->handle,
2233 acpi_video_bus_notify);
2235 acpi_video_bus_put_devices(video);
2236 acpi_video_bus_remove_fs(device);
2238 input_unregister_device(video->input);
2239 kfree(video->attached_array);
2245 static int __init acpi_video_init(void)
2249 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2250 if (!acpi_video_dir)
2252 acpi_video_dir->owner = THIS_MODULE;
2254 result = acpi_bus_register_driver(&acpi_video_bus);
2256 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2263 static void __exit acpi_video_exit(void)
2266 acpi_bus_unregister_driver(&acpi_video_bus);
2268 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2273 module_init(acpi_video_init);
2274 module_exit(acpi_video_exit);