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*/
176 struct acpi_video_device_brightness {
180 struct acpi_video_brightness_flags flags;
183 struct acpi_video_device {
184 unsigned long device_id;
185 struct acpi_video_device_flags flags;
186 struct acpi_video_device_cap cap;
187 struct list_head entry;
188 struct acpi_video_bus *video;
189 struct acpi_device *dev;
190 struct acpi_video_device_brightness *brightness;
191 struct backlight_device *backlight;
192 struct thermal_cooling_device *cdev;
193 struct output_device *output_dev;
197 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
198 static struct file_operations acpi_video_bus_info_fops = {
199 .owner = THIS_MODULE,
200 .open = acpi_video_bus_info_open_fs,
203 .release = single_release,
206 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
207 static struct file_operations acpi_video_bus_ROM_fops = {
208 .owner = THIS_MODULE,
209 .open = acpi_video_bus_ROM_open_fs,
212 .release = single_release,
215 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
217 static struct file_operations acpi_video_bus_POST_info_fops = {
218 .owner = THIS_MODULE,
219 .open = acpi_video_bus_POST_info_open_fs,
222 .release = single_release,
225 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
226 static struct file_operations acpi_video_bus_POST_fops = {
227 .owner = THIS_MODULE,
228 .open = acpi_video_bus_POST_open_fs,
231 .release = single_release,
234 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
235 static struct file_operations acpi_video_bus_DOS_fops = {
236 .owner = THIS_MODULE,
237 .open = acpi_video_bus_DOS_open_fs,
240 .release = single_release,
244 static int acpi_video_device_info_open_fs(struct inode *inode,
246 static struct file_operations acpi_video_device_info_fops = {
247 .owner = THIS_MODULE,
248 .open = acpi_video_device_info_open_fs,
251 .release = single_release,
254 static int acpi_video_device_state_open_fs(struct inode *inode,
256 static struct file_operations acpi_video_device_state_fops = {
257 .owner = THIS_MODULE,
258 .open = acpi_video_device_state_open_fs,
261 .release = single_release,
264 static int acpi_video_device_brightness_open_fs(struct inode *inode,
266 static struct file_operations acpi_video_device_brightness_fops = {
267 .owner = THIS_MODULE,
268 .open = acpi_video_device_brightness_open_fs,
271 .release = single_release,
274 static int acpi_video_device_EDID_open_fs(struct inode *inode,
276 static struct file_operations acpi_video_device_EDID_fops = {
277 .owner = THIS_MODULE,
278 .open = acpi_video_device_EDID_open_fs,
281 .release = single_release,
284 static char device_decode[][30] = {
285 "motherboard VGA device",
291 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
292 static void acpi_video_device_rebind(struct acpi_video_bus *video);
293 static void acpi_video_device_bind(struct acpi_video_bus *video,
294 struct acpi_video_device *device);
295 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
296 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
298 static int acpi_video_device_lcd_get_level_current(
299 struct acpi_video_device *device,
300 unsigned long long *level);
301 static int acpi_video_get_next_level(struct acpi_video_device *device,
302 u32 level_current, u32 event);
303 static int acpi_video_switch_brightness(struct acpi_video_device *device,
305 static int acpi_video_device_get_state(struct acpi_video_device *device,
306 unsigned long long *state);
307 static int acpi_video_output_get(struct output_device *od);
308 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
310 /*backlight device sysfs support*/
311 static int acpi_video_get_brightness(struct backlight_device *bd)
313 unsigned long long cur_level;
315 struct acpi_video_device *vd =
316 (struct acpi_video_device *)bl_get_data(bd);
318 if (acpi_video_device_lcd_get_level_current(vd, &cur_level))
320 for (i = 2; i < vd->brightness->count; i++) {
321 if (vd->brightness->levels[i] == cur_level)
322 /* The first two entries are special - see page 575
323 of the ACPI spec 3.0 */
329 static int acpi_video_set_brightness(struct backlight_device *bd)
331 int request_level = bd->props.brightness + 2;
332 struct acpi_video_device *vd =
333 (struct acpi_video_device *)bl_get_data(bd);
335 return acpi_video_device_lcd_set_level(vd,
336 vd->brightness->levels[request_level]);
339 static struct backlight_ops acpi_backlight_ops = {
340 .get_brightness = acpi_video_get_brightness,
341 .update_status = acpi_video_set_brightness,
344 /*video output device sysfs support*/
345 static int acpi_video_output_get(struct output_device *od)
347 unsigned long long state;
348 struct acpi_video_device *vd =
349 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
350 acpi_video_device_get_state(vd, &state);
354 static int acpi_video_output_set(struct output_device *od)
356 unsigned long state = od->request_state;
357 struct acpi_video_device *vd=
358 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
359 return acpi_video_device_set_state(vd, state);
362 static struct output_properties acpi_output_properties = {
363 .set_state = acpi_video_output_set,
364 .get_status = acpi_video_output_get,
368 /* thermal cooling device callbacks */
369 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
371 struct acpi_device *device = cdev->devdata;
372 struct acpi_video_device *video = acpi_driver_data(device);
374 return sprintf(buf, "%d\n", video->brightness->count - 3);
377 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
379 struct acpi_device *device = cdev->devdata;
380 struct acpi_video_device *video = acpi_driver_data(device);
381 unsigned long long level;
384 if (acpi_video_device_lcd_get_level_current(video, &level))
386 for (state = 2; state < video->brightness->count; state++)
387 if (level == video->brightness->levels[state])
388 return sprintf(buf, "%d\n",
389 video->brightness->count - state - 1);
395 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
397 struct acpi_device *device = cdev->devdata;
398 struct acpi_video_device *video = acpi_driver_data(device);
401 if ( state >= video->brightness->count - 2)
404 state = video->brightness->count - state;
405 level = video->brightness->levels[state -1];
406 return acpi_video_device_lcd_set_level(video, level);
409 static struct thermal_cooling_device_ops video_cooling_ops = {
410 .get_max_state = video_get_max_state,
411 .get_cur_state = video_get_cur_state,
412 .set_cur_state = video_set_cur_state,
415 /* --------------------------------------------------------------------------
417 -------------------------------------------------------------------------- */
422 acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
426 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
432 acpi_video_device_get_state(struct acpi_video_device *device,
433 unsigned long long *state)
437 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
443 acpi_video_device_set_state(struct acpi_video_device *device, int state)
446 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
447 struct acpi_object_list args = { 1, &arg0 };
448 unsigned long long ret;
451 arg0.integer.value = state;
452 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
458 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
459 union acpi_object **levels)
462 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
463 union acpi_object *obj;
468 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
469 if (!ACPI_SUCCESS(status))
471 obj = (union acpi_object *)buffer.pointer;
472 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
473 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
483 kfree(buffer.pointer);
489 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
492 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
493 struct acpi_object_list args = { 1, &arg0 };
496 arg0.integer.value = level;
498 status = acpi_evaluate_object(device->dev->handle, "_BCM",
500 if (ACPI_FAILURE(status)) {
501 ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
505 device->brightness->curr = level;
506 for (state = 2; state < device->brightness->count; state++)
507 if (level == device->brightness->levels[state]) {
508 device->backlight->props.brightness = state - 2;
512 ACPI_ERROR((AE_INFO, "Current brightness invalid"));
517 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
518 unsigned long long *level)
520 acpi_status status = AE_OK;
522 if (device->cap._BQC) {
523 status = acpi_evaluate_integer(device->dev->handle, "_BQC",
525 if (ACPI_SUCCESS(status)) {
526 device->brightness->curr = *level;
530 * should we return an error or ignore this failure?
531 * dev->brightness->curr is a cached value which stores
532 * the correct current backlight level in most cases.
533 * ACPI video backlight still works w/ buggy _BQC.
534 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
536 ACPI_WARNING((AE_INFO, "Evaluating _BQC failed"));
537 device->cap._BQC = 0;
541 *level = device->brightness->curr;
546 acpi_video_device_EDID(struct acpi_video_device *device,
547 union acpi_object **edid, ssize_t length)
550 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
551 union acpi_object *obj;
552 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
553 struct acpi_object_list args = { 1, &arg0 };
561 arg0.integer.value = 1;
562 else if (length == 256)
563 arg0.integer.value = 2;
567 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
568 if (ACPI_FAILURE(status))
571 obj = buffer.pointer;
573 if (obj && obj->type == ACPI_TYPE_BUFFER)
576 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
587 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
590 unsigned long long tmp;
591 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
592 struct acpi_object_list args = { 1, &arg0 };
595 arg0.integer.value = option;
597 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
598 if (ACPI_SUCCESS(status))
599 status = tmp ? (-EINVAL) : (AE_OK);
605 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
609 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
615 acpi_video_bus_POST_options(struct acpi_video_bus *video,
616 unsigned long long *options)
620 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
628 * video : video bus device pointer
630 * 0. The system BIOS should NOT automatically switch(toggle)
631 * the active display output.
632 * 1. The system BIOS should automatically switch (toggle) the
633 * active display output. No switch event.
634 * 2. The _DGS value should be locked.
635 * 3. The system BIOS should not automatically switch (toggle) the
636 * active display output, but instead generate the display switch
639 * 0. The system BIOS should automatically control the brightness level
640 * of the LCD when the power changes from AC to DC
641 * 1. The system BIOS should NOT automatically control the brightness
642 * level of the LCD when the power changes from AC to DC.
648 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
650 acpi_integer status = 0;
651 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
652 struct acpi_object_list args = { 1, &arg0 };
655 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
659 arg0.integer.value = (lcd_flag << 2) | bios_flag;
660 video->dos_setting = arg0.integer.value;
661 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
668 * Simple comparison function used to sort backlight levels.
672 acpi_video_cmp_level(const void *a, const void *b)
674 return *(int *)a - *(int *)b;
679 * device : video output device (LCD, CRT, ..)
682 * Maximum brightness level
684 * Allocate and initialize device->brightness.
688 acpi_video_init_brightness(struct acpi_video_device *device)
690 union acpi_object *obj = NULL;
691 int i, max_level = 0, count = 0, level_ac_battery = 0;
692 union acpi_object *o;
693 struct acpi_video_device_brightness *br = NULL;
695 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
696 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
697 "LCD brightness level\n"));
701 if (obj->package.count < 2)
704 br = kzalloc(sizeof(*br), GFP_KERNEL);
706 printk(KERN_ERR "can't allocate memory\n");
710 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
715 for (i = 0; i < obj->package.count; i++) {
716 o = (union acpi_object *)&obj->package.elements[i];
717 if (o->type != ACPI_TYPE_INTEGER) {
718 printk(KERN_ERR PREFIX "Invalid data\n");
721 br->levels[count] = (u32) o->integer.value;
723 if (br->levels[count] > max_level)
724 max_level = br->levels[count];
729 * some buggy BIOS don't export the levels
730 * when machine is on AC/Battery in _BCL package.
731 * In this case, the first two elements in _BCL packages
732 * are also supported brightness levels that OS should take care of.
734 for (i = 2; i < count; i++)
735 if (br->levels[i] == br->levels[0] ||
736 br->levels[i] == br->levels[1])
739 if (level_ac_battery < 2) {
740 level_ac_battery = 2 - level_ac_battery;
741 br->flags._BCL_no_ac_battery_levels = 1;
742 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
743 br->levels[i] = br->levels[i - level_ac_battery];
744 count += level_ac_battery;
745 } else if (level_ac_battery > 2)
746 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
748 /* Check if the _BCL package is in a reversed order */
749 if (max_level == br->levels[2]) {
750 br->flags._BCL_reversed = 1;
751 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
752 acpi_video_cmp_level, NULL);
753 } else if (max_level != br->levels[count - 1])
755 "Found unordered _BCL package\n"));
758 device->brightness = br;
759 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
760 "found %d brightness levels\n", count - 2));
769 device->brightness = NULL;
776 * device : video output device (LCD, CRT, ..)
781 * Find out all required AML methods defined under the output
785 static void acpi_video_device_find_cap(struct acpi_video_device *device)
787 acpi_handle h_dummy1;
791 memset(&device->cap, 0, sizeof(device->cap));
793 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
794 device->cap._ADR = 1;
796 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
797 device->cap._BCL = 1;
799 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
800 device->cap._BCM = 1;
802 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
803 device->cap._BQC = 1;
804 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
805 device->cap._DDC = 1;
807 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
808 device->cap._DCS = 1;
810 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
811 device->cap._DGS = 1;
813 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
814 device->cap._DSS = 1;
817 if (acpi_video_backlight_support())
818 max_level = acpi_video_init_brightness(device);
820 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
822 static int count = 0;
824 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
828 sprintf(name, "acpi_video%d", count++);
829 device->backlight = backlight_device_register(name,
830 NULL, device, &acpi_backlight_ops);
831 device->backlight->props.max_brightness = device->brightness->count-3;
833 * If there exists the _BQC object, the _BQC object will be
834 * called to get the current backlight brightness. Otherwise
835 * the brightness will be set to the maximum.
837 if (device->cap._BQC)
838 device->backlight->props.brightness =
839 acpi_video_get_brightness(device->backlight);
841 device->backlight->props.brightness =
842 device->backlight->props.max_brightness;
843 backlight_update_status(device->backlight);
846 device->cdev = thermal_cooling_device_register("LCD",
847 device->dev, &video_cooling_ops);
848 if (IS_ERR(device->cdev))
851 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
853 result = sysfs_create_link(&device->dev->dev.kobj,
854 &device->cdev->device.kobj,
857 printk(KERN_ERR PREFIX "Create sysfs link\n");
858 result = sysfs_create_link(&device->cdev->device.kobj,
859 &device->dev->dev.kobj, "device");
861 printk(KERN_ERR PREFIX "Create sysfs link\n");
865 if (acpi_video_display_switch_support()) {
867 if (device->cap._DCS && device->cap._DSS) {
870 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
873 sprintf(name, "acpi_video%d", count++);
874 device->output_dev = video_output_register(name,
875 NULL, device, &acpi_output_properties);
883 * device : video output device (VGA)
888 * Find out all required AML methods defined under the video bus device.
891 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
893 acpi_handle h_dummy1;
895 memset(&video->cap, 0, sizeof(video->cap));
896 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
899 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
902 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
905 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
908 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
911 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
917 * Check whether the video bus device has required AML method to
918 * support the desired features
921 static int acpi_video_bus_check(struct acpi_video_bus *video)
923 acpi_status status = -ENOENT;
929 dev = acpi_get_physical_pci_device(video->device->handle);
934 /* Since there is no HID, CID and so on for VGA driver, we have
935 * to check well known required nodes.
938 /* Does this device support video switching? */
939 if (video->cap._DOS) {
940 video->flags.multihead = 1;
944 /* Does this device support retrieving a video ROM? */
945 if (video->cap._ROM) {
946 video->flags.rom = 1;
950 /* Does this device support configuring which video device to POST? */
951 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
952 video->flags.post = 1;
959 /* --------------------------------------------------------------------------
961 -------------------------------------------------------------------------- */
963 static struct proc_dir_entry *acpi_video_dir;
967 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
969 struct acpi_video_device *dev = seq->private;
975 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
976 seq_printf(seq, "type: ");
978 seq_printf(seq, "CRT\n");
979 else if (dev->flags.lcd)
980 seq_printf(seq, "LCD\n");
981 else if (dev->flags.tvout)
982 seq_printf(seq, "TVOUT\n");
983 else if (dev->flags.dvi)
984 seq_printf(seq, "DVI\n");
986 seq_printf(seq, "UNKNOWN\n");
988 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
995 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
997 return single_open(file, acpi_video_device_info_seq_show,
1001 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
1004 struct acpi_video_device *dev = seq->private;
1005 unsigned long long state;
1011 status = acpi_video_device_get_state(dev, &state);
1012 seq_printf(seq, "state: ");
1013 if (ACPI_SUCCESS(status))
1014 seq_printf(seq, "0x%02llx\n", state);
1016 seq_printf(seq, "<not supported>\n");
1018 status = acpi_video_device_query(dev, &state);
1019 seq_printf(seq, "query: ");
1020 if (ACPI_SUCCESS(status))
1021 seq_printf(seq, "0x%02llx\n", state);
1023 seq_printf(seq, "<not supported>\n");
1030 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
1032 return single_open(file, acpi_video_device_state_seq_show,
1037 acpi_video_device_write_state(struct file *file,
1038 const char __user * buffer,
1039 size_t count, loff_t * data)
1042 struct seq_file *m = file->private_data;
1043 struct acpi_video_device *dev = m->private;
1044 char str[12] = { 0 };
1048 if (!dev || count + 1 > sizeof str)
1051 if (copy_from_user(str, buffer, count))
1055 state = simple_strtoul(str, NULL, 0);
1056 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1058 status = acpi_video_device_set_state(dev, state);
1067 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1069 struct acpi_video_device *dev = seq->private;
1073 if (!dev || !dev->brightness) {
1074 seq_printf(seq, "<not supported>\n");
1078 seq_printf(seq, "levels: ");
1079 for (i = 2; i < dev->brightness->count; i++)
1080 seq_printf(seq, " %d", dev->brightness->levels[i]);
1081 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1087 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1089 return single_open(file, acpi_video_device_brightness_seq_show,
1094 acpi_video_device_write_brightness(struct file *file,
1095 const char __user * buffer,
1096 size_t count, loff_t * data)
1098 struct seq_file *m = file->private_data;
1099 struct acpi_video_device *dev = m->private;
1100 char str[5] = { 0 };
1101 unsigned int level = 0;
1105 if (!dev || !dev->brightness || count + 1 > sizeof str)
1108 if (copy_from_user(str, buffer, count))
1112 level = simple_strtoul(str, NULL, 0);
1117 /* validate through the list of available levels */
1118 for (i = 2; i < dev->brightness->count; i++)
1119 if (level == dev->brightness->levels[i]) {
1120 if (!acpi_video_device_lcd_set_level(dev, level))
1128 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1130 struct acpi_video_device *dev = seq->private;
1133 union acpi_object *edid = NULL;
1139 status = acpi_video_device_EDID(dev, &edid, 128);
1140 if (ACPI_FAILURE(status)) {
1141 status = acpi_video_device_EDID(dev, &edid, 256);
1144 if (ACPI_FAILURE(status)) {
1148 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1149 for (i = 0; i < edid->buffer.length; i++)
1150 seq_putc(seq, edid->buffer.pointer[i]);
1155 seq_printf(seq, "<not supported>\n");
1163 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1165 return single_open(file, acpi_video_device_EDID_seq_show,
1169 static int acpi_video_device_add_fs(struct acpi_device *device)
1171 struct proc_dir_entry *entry, *device_dir;
1172 struct acpi_video_device *vid_dev;
1174 vid_dev = acpi_driver_data(device);
1178 device_dir = proc_mkdir(acpi_device_bid(device),
1179 vid_dev->video->dir);
1183 device_dir->owner = THIS_MODULE;
1186 entry = proc_create_data("info", S_IRUGO, device_dir,
1187 &acpi_video_device_info_fops, acpi_driver_data(device));
1189 goto err_remove_dir;
1192 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1193 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1195 &acpi_video_device_state_fops,
1196 acpi_driver_data(device));
1198 goto err_remove_info;
1200 /* 'brightness' [R/W] */
1201 acpi_video_device_brightness_fops.write =
1202 acpi_video_device_write_brightness;
1203 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1205 &acpi_video_device_brightness_fops,
1206 acpi_driver_data(device));
1208 goto err_remove_state;
1211 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1212 &acpi_video_device_EDID_fops,
1213 acpi_driver_data(device));
1215 goto err_remove_brightness;
1217 acpi_device_dir(device) = device_dir;
1221 err_remove_brightness:
1222 remove_proc_entry("brightness", device_dir);
1224 remove_proc_entry("state", device_dir);
1226 remove_proc_entry("info", device_dir);
1228 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1232 static int acpi_video_device_remove_fs(struct acpi_device *device)
1234 struct acpi_video_device *vid_dev;
1235 struct proc_dir_entry *device_dir;
1237 vid_dev = acpi_driver_data(device);
1238 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1241 device_dir = acpi_device_dir(device);
1243 remove_proc_entry("info", device_dir);
1244 remove_proc_entry("state", device_dir);
1245 remove_proc_entry("brightness", device_dir);
1246 remove_proc_entry("EDID", device_dir);
1247 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1248 acpi_device_dir(device) = NULL;
1255 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1257 struct acpi_video_bus *video = seq->private;
1263 seq_printf(seq, "Switching heads: %s\n",
1264 video->flags.multihead ? "yes" : "no");
1265 seq_printf(seq, "Video ROM: %s\n",
1266 video->flags.rom ? "yes" : "no");
1267 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1268 video->flags.post ? "yes" : "no");
1274 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1276 return single_open(file, acpi_video_bus_info_seq_show,
1280 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1282 struct acpi_video_bus *video = seq->private;
1288 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1289 seq_printf(seq, "<TODO>\n");
1295 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1297 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1300 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1302 struct acpi_video_bus *video = seq->private;
1303 unsigned long long options;
1310 status = acpi_video_bus_POST_options(video, &options);
1311 if (ACPI_SUCCESS(status)) {
1312 if (!(options & 1)) {
1313 printk(KERN_WARNING PREFIX
1314 "The motherboard VGA device is not listed as a possible POST device.\n");
1315 printk(KERN_WARNING PREFIX
1316 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1318 printk(KERN_WARNING "%llx\n", options);
1319 seq_printf(seq, "can POST: <integrated video>");
1321 seq_printf(seq, " <PCI video>");
1323 seq_printf(seq, " <AGP video>");
1324 seq_putc(seq, '\n');
1326 seq_printf(seq, "<not supported>\n");
1332 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1334 return single_open(file, acpi_video_bus_POST_info_seq_show,
1338 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1340 struct acpi_video_bus *video = seq->private;
1342 unsigned long long id;
1348 status = acpi_video_bus_get_POST(video, &id);
1349 if (!ACPI_SUCCESS(status)) {
1350 seq_printf(seq, "<not supported>\n");
1353 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1359 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1361 struct acpi_video_bus *video = seq->private;
1364 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1369 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1371 return single_open(file, acpi_video_bus_POST_seq_show,
1375 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1377 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1381 acpi_video_bus_write_POST(struct file *file,
1382 const char __user * buffer,
1383 size_t count, loff_t * data)
1386 struct seq_file *m = file->private_data;
1387 struct acpi_video_bus *video = m->private;
1388 char str[12] = { 0 };
1389 unsigned long long opt, options;
1392 if (!video || count + 1 > sizeof str)
1395 status = acpi_video_bus_POST_options(video, &options);
1396 if (!ACPI_SUCCESS(status))
1399 if (copy_from_user(str, buffer, count))
1403 opt = strtoul(str, NULL, 0);
1407 /* just in case an OEM 'forgot' the motherboard... */
1410 if (options & (1ul << opt)) {
1411 status = acpi_video_bus_set_POST(video, opt);
1412 if (!ACPI_SUCCESS(status))
1421 acpi_video_bus_write_DOS(struct file *file,
1422 const char __user * buffer,
1423 size_t count, loff_t * data)
1426 struct seq_file *m = file->private_data;
1427 struct acpi_video_bus *video = m->private;
1428 char str[12] = { 0 };
1432 if (!video || count + 1 > sizeof str)
1435 if (copy_from_user(str, buffer, count))
1439 opt = strtoul(str, NULL, 0);
1443 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1445 if (!ACPI_SUCCESS(status))
1451 static int acpi_video_bus_add_fs(struct acpi_device *device)
1453 struct acpi_video_bus *video = acpi_driver_data(device);
1454 struct proc_dir_entry *device_dir;
1455 struct proc_dir_entry *entry;
1457 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1461 device_dir->owner = THIS_MODULE;
1464 entry = proc_create_data("info", S_IRUGO, device_dir,
1465 &acpi_video_bus_info_fops,
1466 acpi_driver_data(device));
1468 goto err_remove_dir;
1471 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1472 &acpi_video_bus_ROM_fops,
1473 acpi_driver_data(device));
1475 goto err_remove_info;
1477 /* 'POST_info' [R] */
1478 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1479 &acpi_video_bus_POST_info_fops,
1480 acpi_driver_data(device));
1482 goto err_remove_rom;
1485 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1486 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1488 &acpi_video_bus_POST_fops,
1489 acpi_driver_data(device));
1491 goto err_remove_post_info;
1494 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1495 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1497 &acpi_video_bus_DOS_fops,
1498 acpi_driver_data(device));
1500 goto err_remove_post;
1502 video->dir = acpi_device_dir(device) = device_dir;
1506 remove_proc_entry("POST", device_dir);
1507 err_remove_post_info:
1508 remove_proc_entry("POST_info", device_dir);
1510 remove_proc_entry("ROM", device_dir);
1512 remove_proc_entry("info", device_dir);
1514 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1518 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1520 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1523 remove_proc_entry("info", device_dir);
1524 remove_proc_entry("ROM", device_dir);
1525 remove_proc_entry("POST_info", device_dir);
1526 remove_proc_entry("POST", device_dir);
1527 remove_proc_entry("DOS", device_dir);
1528 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1529 acpi_device_dir(device) = NULL;
1535 /* --------------------------------------------------------------------------
1537 -------------------------------------------------------------------------- */
1539 /* device interface */
1540 static struct acpi_video_device_attrib*
1541 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1543 struct acpi_video_enumerated_device *ids;
1546 for (i = 0; i < video->attached_count; i++) {
1547 ids = &video->attached_array[i];
1548 if ((ids->value.int_val & 0xffff) == device_id)
1549 return &ids->value.attrib;
1556 acpi_video_bus_get_one_device(struct acpi_device *device,
1557 struct acpi_video_bus *video)
1559 unsigned long long device_id;
1561 struct acpi_video_device *data;
1562 struct acpi_video_device_attrib* attribute;
1564 if (!device || !video)
1568 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1569 if (ACPI_SUCCESS(status)) {
1571 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1575 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1576 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1577 device->driver_data = data;
1579 data->device_id = device_id;
1580 data->video = video;
1583 attribute = acpi_video_get_device_attr(video, device_id);
1585 if((attribute != NULL) && attribute->device_id_scheme) {
1586 switch (attribute->display_type) {
1587 case ACPI_VIDEO_DISPLAY_CRT:
1588 data->flags.crt = 1;
1590 case ACPI_VIDEO_DISPLAY_TV:
1591 data->flags.tvout = 1;
1593 case ACPI_VIDEO_DISPLAY_DVI:
1594 data->flags.dvi = 1;
1596 case ACPI_VIDEO_DISPLAY_LCD:
1597 data->flags.lcd = 1;
1600 data->flags.unknown = 1;
1603 if(attribute->bios_can_detect)
1604 data->flags.bios = 1;
1606 data->flags.unknown = 1;
1608 acpi_video_device_bind(video, data);
1609 acpi_video_device_find_cap(data);
1611 status = acpi_install_notify_handler(device->handle,
1613 acpi_video_device_notify,
1615 if (ACPI_FAILURE(status)) {
1616 printk(KERN_ERR PREFIX
1617 "Error installing notify handler\n");
1618 if(data->brightness)
1619 kfree(data->brightness->levels);
1620 kfree(data->brightness);
1625 mutex_lock(&video->device_list_lock);
1626 list_add_tail(&data->entry, &video->video_device_list);
1627 mutex_unlock(&video->device_list_lock);
1629 acpi_video_device_add_fs(device);
1639 * video : video bus device
1644 * Enumerate the video device list of the video bus,
1645 * bind the ids with the corresponding video devices
1646 * under the video bus.
1649 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1651 struct acpi_video_device *dev;
1653 mutex_lock(&video->device_list_lock);
1655 list_for_each_entry(dev, &video->video_device_list, entry)
1656 acpi_video_device_bind(video, dev);
1658 mutex_unlock(&video->device_list_lock);
1663 * video : video bus device
1664 * device : video output device under the video
1670 * Bind the ids with the corresponding video devices
1671 * under the video bus.
1675 acpi_video_device_bind(struct acpi_video_bus *video,
1676 struct acpi_video_device *device)
1678 struct acpi_video_enumerated_device *ids;
1681 for (i = 0; i < video->attached_count; i++) {
1682 ids = &video->attached_array[i];
1683 if (device->device_id == (ids->value.int_val & 0xffff)) {
1684 ids->bind_info = device;
1685 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1692 * video : video bus device
1697 * Call _DOD to enumerate all devices attached to display adapter
1701 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1706 struct acpi_video_enumerated_device *active_list;
1707 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1708 union acpi_object *dod = NULL;
1709 union acpi_object *obj;
1711 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1712 if (!ACPI_SUCCESS(status)) {
1713 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1717 dod = buffer.pointer;
1718 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1719 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1724 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1725 dod->package.count));
1727 active_list = kcalloc(1 + dod->package.count,
1728 sizeof(struct acpi_video_enumerated_device),
1736 for (i = 0; i < dod->package.count; i++) {
1737 obj = &dod->package.elements[i];
1739 if (obj->type != ACPI_TYPE_INTEGER) {
1740 printk(KERN_ERR PREFIX
1741 "Invalid _DOD data in element %d\n", i);
1745 active_list[count].value.int_val = obj->integer.value;
1746 active_list[count].bind_info = NULL;
1747 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1748 (int)obj->integer.value));
1752 kfree(video->attached_array);
1754 video->attached_array = active_list;
1755 video->attached_count = count;
1758 kfree(buffer.pointer);
1763 acpi_video_get_next_level(struct acpi_video_device *device,
1764 u32 level_current, u32 event)
1766 int min, max, min_above, max_below, i, l, delta = 255;
1767 max = max_below = 0;
1768 min = min_above = 255;
1769 /* Find closest level to level_current */
1770 for (i = 2; i < device->brightness->count; i++) {
1771 l = device->brightness->levels[i];
1772 if (abs(l - level_current) < abs(delta)) {
1773 delta = l - level_current;
1778 /* Ajust level_current to closest available level */
1779 level_current += delta;
1780 for (i = 2; i < device->brightness->count; i++) {
1781 l = device->brightness->levels[i];
1786 if (l < min_above && l > level_current)
1788 if (l > max_below && l < level_current)
1793 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1794 return (level_current < max) ? min_above : min;
1795 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1796 return (level_current < max) ? min_above : max;
1797 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1798 return (level_current > min) ? max_below : min;
1799 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1800 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1803 return level_current;
1808 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1810 unsigned long long level_current, level_next;
1811 int result = -EINVAL;
1813 if (!device->brightness)
1816 result = acpi_video_device_lcd_get_level_current(device,
1821 level_next = acpi_video_get_next_level(device, level_current, event);
1823 result = acpi_video_device_lcd_set_level(device, level_next);
1827 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1833 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1834 struct acpi_device *device)
1837 struct acpi_device *dev;
1839 acpi_video_device_enumerate(video);
1841 list_for_each_entry(dev, &device->children, node) {
1843 status = acpi_video_bus_get_one_device(dev, video);
1844 if (ACPI_FAILURE(status)) {
1845 printk(KERN_WARNING PREFIX
1846 "Cant attach device");
1853 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1856 struct acpi_video_bus *video;
1859 if (!device || !device->video)
1862 video = device->video;
1864 acpi_video_device_remove_fs(device->dev);
1866 status = acpi_remove_notify_handler(device->dev->handle,
1868 acpi_video_device_notify);
1869 backlight_device_unregister(device->backlight);
1871 sysfs_remove_link(&device->dev->dev.kobj,
1873 sysfs_remove_link(&device->cdev->device.kobj,
1875 thermal_cooling_device_unregister(device->cdev);
1876 device->cdev = NULL;
1878 video_output_unregister(device->output_dev);
1883 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1886 struct acpi_video_device *dev, *next;
1888 mutex_lock(&video->device_list_lock);
1890 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1892 status = acpi_video_bus_put_one_device(dev);
1893 if (ACPI_FAILURE(status))
1894 printk(KERN_WARNING PREFIX
1895 "hhuuhhuu bug in acpi video driver.\n");
1897 if (dev->brightness) {
1898 kfree(dev->brightness->levels);
1899 kfree(dev->brightness);
1901 list_del(&dev->entry);
1905 mutex_unlock(&video->device_list_lock);
1910 /* acpi_video interface */
1912 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1914 return acpi_video_bus_DOS(video, 0, 0);
1917 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1919 return acpi_video_bus_DOS(video, 0, 1);
1922 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1924 struct acpi_video_bus *video = data;
1925 struct acpi_device *device = NULL;
1926 struct input_dev *input;
1932 device = video->device;
1933 input = video->input;
1936 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1937 * most likely via hotkey. */
1938 acpi_bus_generate_proc_event(device, event, 0);
1939 keycode = KEY_SWITCHVIDEOMODE;
1942 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1944 acpi_video_device_enumerate(video);
1945 acpi_video_device_rebind(video);
1946 acpi_bus_generate_proc_event(device, event, 0);
1947 keycode = KEY_SWITCHVIDEOMODE;
1950 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1951 acpi_bus_generate_proc_event(device, event, 0);
1952 keycode = KEY_SWITCHVIDEOMODE;
1954 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1955 acpi_bus_generate_proc_event(device, event, 0);
1956 keycode = KEY_VIDEO_NEXT;
1958 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1959 acpi_bus_generate_proc_event(device, event, 0);
1960 keycode = KEY_VIDEO_PREV;
1964 keycode = KEY_UNKNOWN;
1965 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1966 "Unsupported event [0x%x]\n", event));
1970 acpi_notifier_call_chain(device, event, 0);
1971 input_report_key(input, keycode, 1);
1973 input_report_key(input, keycode, 0);
1979 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1981 struct acpi_video_device *video_device = data;
1982 struct acpi_device *device = NULL;
1983 struct acpi_video_bus *bus;
1984 struct input_dev *input;
1990 device = video_device->dev;
1991 bus = video_device->video;
1995 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1996 if (brightness_switch_enabled)
1997 acpi_video_switch_brightness(video_device, event);
1998 acpi_bus_generate_proc_event(device, event, 0);
1999 keycode = KEY_BRIGHTNESS_CYCLE;
2001 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
2002 if (brightness_switch_enabled)
2003 acpi_video_switch_brightness(video_device, event);
2004 acpi_bus_generate_proc_event(device, event, 0);
2005 keycode = KEY_BRIGHTNESSUP;
2007 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
2008 if (brightness_switch_enabled)
2009 acpi_video_switch_brightness(video_device, event);
2010 acpi_bus_generate_proc_event(device, event, 0);
2011 keycode = KEY_BRIGHTNESSDOWN;
2013 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
2014 if (brightness_switch_enabled)
2015 acpi_video_switch_brightness(video_device, event);
2016 acpi_bus_generate_proc_event(device, event, 0);
2017 keycode = KEY_BRIGHTNESS_ZERO;
2019 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
2020 if (brightness_switch_enabled)
2021 acpi_video_switch_brightness(video_device, event);
2022 acpi_bus_generate_proc_event(device, event, 0);
2023 keycode = KEY_DISPLAY_OFF;
2026 keycode = KEY_UNKNOWN;
2027 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
2028 "Unsupported event [0x%x]\n", event));
2032 acpi_notifier_call_chain(device, event, 0);
2033 input_report_key(input, keycode, 1);
2035 input_report_key(input, keycode, 0);
2041 static int instance;
2042 static int acpi_video_resume(struct acpi_device *device)
2044 struct acpi_video_bus *video;
2045 struct acpi_video_device *video_device;
2048 if (!device || !acpi_driver_data(device))
2051 video = acpi_driver_data(device);
2053 for (i = 0; i < video->attached_count; i++) {
2054 video_device = video->attached_array[i].bind_info;
2055 if (video_device && video_device->backlight)
2056 acpi_video_set_brightness(video_device->backlight);
2061 static int acpi_video_bus_add(struct acpi_device *device)
2064 struct acpi_video_bus *video;
2065 struct input_dev *input;
2068 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2072 /* a hack to fix the duplicate name "VID" problem on T61 */
2073 if (!strcmp(device->pnp.bus_id, "VID")) {
2075 device->pnp.bus_id[3] = '0' + instance;
2078 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2079 if (!strcmp(device->pnp.bus_id, "VGA")) {
2081 device->pnp.bus_id[3] = '0' + instance;
2085 video->device = device;
2086 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2087 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2088 device->driver_data = video;
2090 acpi_video_bus_find_cap(video);
2091 error = acpi_video_bus_check(video);
2093 goto err_free_video;
2095 error = acpi_video_bus_add_fs(device);
2097 goto err_free_video;
2099 mutex_init(&video->device_list_lock);
2100 INIT_LIST_HEAD(&video->video_device_list);
2102 acpi_video_bus_get_devices(video, device);
2103 acpi_video_bus_start_devices(video);
2105 status = acpi_install_notify_handler(device->handle,
2107 acpi_video_bus_notify, video);
2108 if (ACPI_FAILURE(status)) {
2109 printk(KERN_ERR PREFIX
2110 "Error installing notify handler\n");
2112 goto err_stop_video;
2115 video->input = input = input_allocate_device();
2118 goto err_uninstall_notify;
2121 snprintf(video->phys, sizeof(video->phys),
2122 "%s/video/input0", acpi_device_hid(video->device));
2124 input->name = acpi_device_name(video->device);
2125 input->phys = video->phys;
2126 input->id.bustype = BUS_HOST;
2127 input->id.product = 0x06;
2128 input->dev.parent = &device->dev;
2129 input->evbit[0] = BIT(EV_KEY);
2130 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2131 set_bit(KEY_VIDEO_NEXT, input->keybit);
2132 set_bit(KEY_VIDEO_PREV, input->keybit);
2133 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2134 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2135 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2136 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2137 set_bit(KEY_DISPLAY_OFF, input->keybit);
2138 set_bit(KEY_UNKNOWN, input->keybit);
2140 error = input_register_device(input);
2142 goto err_free_input_dev;
2144 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2145 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2146 video->flags.multihead ? "yes" : "no",
2147 video->flags.rom ? "yes" : "no",
2148 video->flags.post ? "yes" : "no");
2153 input_free_device(input);
2154 err_uninstall_notify:
2155 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2156 acpi_video_bus_notify);
2158 acpi_video_bus_stop_devices(video);
2159 acpi_video_bus_put_devices(video);
2160 kfree(video->attached_array);
2161 acpi_video_bus_remove_fs(device);
2164 device->driver_data = NULL;
2169 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2171 acpi_status status = 0;
2172 struct acpi_video_bus *video = NULL;
2175 if (!device || !acpi_driver_data(device))
2178 video = acpi_driver_data(device);
2180 acpi_video_bus_stop_devices(video);
2182 status = acpi_remove_notify_handler(video->device->handle,
2184 acpi_video_bus_notify);
2186 acpi_video_bus_put_devices(video);
2187 acpi_video_bus_remove_fs(device);
2189 input_unregister_device(video->input);
2190 kfree(video->attached_array);
2196 static int __init acpi_video_init(void)
2200 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2201 if (!acpi_video_dir)
2203 acpi_video_dir->owner = THIS_MODULE;
2205 result = acpi_bus_register_driver(&acpi_video_bus);
2207 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2214 static void __exit acpi_video_exit(void)
2217 acpi_bus_unregister_driver(&acpi_video_bus);
2219 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2224 module_init(acpi_video_init);
2225 module_exit(acpi_video_exit);