Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / acpi / video.c
blob33df8bf07e83b02706570e3267cef3247f008167
1 /*
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 <asm/uaccess.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
44 #define ACPI_VIDEO_COMPONENT 0x08000000
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 ACPI_VIDEO_HEAD_INVALID (~0u - 1)
61 #define ACPI_VIDEO_HEAD_END (~0u)
62 #define MAX_NAME_LEN 20
64 #define ACPI_VIDEO_DISPLAY_CRT 1
65 #define ACPI_VIDEO_DISPLAY_TV 2
66 #define ACPI_VIDEO_DISPLAY_DVI 3
67 #define ACPI_VIDEO_DISPLAY_LCD 4
69 #define _COMPONENT ACPI_VIDEO_COMPONENT
70 ACPI_MODULE_NAME("video");
72 MODULE_AUTHOR("Bruno Ducrot");
73 MODULE_DESCRIPTION("ACPI Video Driver");
74 MODULE_LICENSE("GPL");
76 static int brightness_switch_enabled = 1;
77 module_param(brightness_switch_enabled, bool, 0644);
79 static int acpi_video_bus_add(struct acpi_device *device);
80 static int acpi_video_bus_remove(struct acpi_device *device, int type);
81 static int acpi_video_resume(struct acpi_device *device);
83 static const struct acpi_device_id video_device_ids[] = {
84 {ACPI_VIDEO_HID, 0},
85 {"", 0},
87 MODULE_DEVICE_TABLE(acpi, video_device_ids);
89 static struct acpi_driver acpi_video_bus = {
90 .name = "video",
91 .class = ACPI_VIDEO_CLASS,
92 .ids = video_device_ids,
93 .ops = {
94 .add = acpi_video_bus_add,
95 .remove = acpi_video_bus_remove,
96 .resume = acpi_video_resume,
100 struct acpi_video_bus_flags {
101 u8 multihead:1; /* can switch video heads */
102 u8 rom:1; /* can retrieve a video rom */
103 u8 post:1; /* can configure the head to */
104 u8 reserved:5;
107 struct acpi_video_bus_cap {
108 u8 _DOS:1; /*Enable/Disable output switching */
109 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM:1; /*Get ROM Data */
111 u8 _GPD:1; /*Get POST Device */
112 u8 _SPD:1; /*Set POST Device */
113 u8 _VPO:1; /*Video POST Options */
114 u8 reserved:2;
117 struct acpi_video_device_attrib {
118 u32 display_index:4; /* A zero-based instance of the Display */
119 u32 display_port_attachment:4; /*This field differentiates the display type */
120 u32 display_type:4; /*Describe the specific type in use */
121 u32 vendor_specific:4; /*Chipset Vendor Specific */
122 u32 bios_can_detect:1; /*BIOS can detect the device */
123 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
124 the VGA device. */
125 u32 pipe_id:3; /*For VGA multiple-head devices. */
126 u32 reserved:10; /*Must be 0 */
127 u32 device_id_scheme:1; /*Device ID Scheme */
130 struct acpi_video_enumerated_device {
131 union {
132 u32 int_val;
133 struct acpi_video_device_attrib attrib;
134 } value;
135 struct acpi_video_device *bind_info;
138 struct acpi_video_bus {
139 struct acpi_device *device;
140 u8 dos_setting;
141 struct acpi_video_enumerated_device *attached_array;
142 u8 attached_count;
143 struct acpi_video_bus_cap cap;
144 struct acpi_video_bus_flags flags;
145 struct list_head video_device_list;
146 struct mutex device_list_lock; /* protects video_device_list */
147 struct proc_dir_entry *dir;
148 struct input_dev *input;
149 char phys[32]; /* for input device */
152 struct acpi_video_device_flags {
153 u8 crt:1;
154 u8 lcd:1;
155 u8 tvout:1;
156 u8 dvi:1;
157 u8 bios:1;
158 u8 unknown:1;
159 u8 reserved:2;
162 struct acpi_video_device_cap {
163 u8 _ADR:1; /*Return the unique ID */
164 u8 _BCL:1; /*Query list of brightness control levels supported */
165 u8 _BCM:1; /*Set the brightness level */
166 u8 _BQC:1; /* Get current brightness level */
167 u8 _DDC:1; /*Return the EDID for this device */
168 u8 _DCS:1; /*Return status of output device */
169 u8 _DGS:1; /*Query graphics state */
170 u8 _DSS:1; /*Device state set */
173 struct acpi_video_device_brightness {
174 int curr;
175 int count;
176 int *levels;
179 struct acpi_video_device {
180 unsigned long device_id;
181 struct acpi_video_device_flags flags;
182 struct acpi_video_device_cap cap;
183 struct list_head entry;
184 struct acpi_video_bus *video;
185 struct acpi_device *dev;
186 struct acpi_video_device_brightness *brightness;
187 struct backlight_device *backlight;
188 struct thermal_cooling_device *cdev;
189 struct output_device *output_dev;
192 /* bus */
193 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
194 static struct file_operations acpi_video_bus_info_fops = {
195 .open = acpi_video_bus_info_open_fs,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
201 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
202 static struct file_operations acpi_video_bus_ROM_fops = {
203 .open = acpi_video_bus_ROM_open_fs,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = single_release,
209 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210 struct file *file);
211 static struct file_operations acpi_video_bus_POST_info_fops = {
212 .open = acpi_video_bus_POST_info_open_fs,
213 .read = seq_read,
214 .llseek = seq_lseek,
215 .release = single_release,
218 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
219 static struct file_operations acpi_video_bus_POST_fops = {
220 .open = acpi_video_bus_POST_open_fs,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
226 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
227 static struct file_operations acpi_video_bus_DOS_fops = {
228 .open = acpi_video_bus_DOS_open_fs,
229 .read = seq_read,
230 .llseek = seq_lseek,
231 .release = single_release,
234 /* device */
235 static int acpi_video_device_info_open_fs(struct inode *inode,
236 struct file *file);
237 static struct file_operations acpi_video_device_info_fops = {
238 .open = acpi_video_device_info_open_fs,
239 .read = seq_read,
240 .llseek = seq_lseek,
241 .release = single_release,
244 static int acpi_video_device_state_open_fs(struct inode *inode,
245 struct file *file);
246 static struct file_operations acpi_video_device_state_fops = {
247 .open = acpi_video_device_state_open_fs,
248 .read = seq_read,
249 .llseek = seq_lseek,
250 .release = single_release,
253 static int acpi_video_device_brightness_open_fs(struct inode *inode,
254 struct file *file);
255 static struct file_operations acpi_video_device_brightness_fops = {
256 .open = acpi_video_device_brightness_open_fs,
257 .read = seq_read,
258 .llseek = seq_lseek,
259 .release = single_release,
262 static int acpi_video_device_EDID_open_fs(struct inode *inode,
263 struct file *file);
264 static struct file_operations acpi_video_device_EDID_fops = {
265 .open = acpi_video_device_EDID_open_fs,
266 .read = seq_read,
267 .llseek = seq_lseek,
268 .release = single_release,
271 static char device_decode[][30] = {
272 "motherboard VGA device",
273 "PCI VGA device",
274 "AGP VGA device",
275 "UNKNOWN",
278 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
279 static void acpi_video_device_rebind(struct acpi_video_bus *video);
280 static void acpi_video_device_bind(struct acpi_video_bus *video,
281 struct acpi_video_device *device);
282 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
283 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
284 int level);
285 static int acpi_video_device_lcd_get_level_current(
286 struct acpi_video_device *device,
287 unsigned long *level);
288 static int acpi_video_get_next_level(struct acpi_video_device *device,
289 u32 level_current, u32 event);
290 static void acpi_video_switch_brightness(struct acpi_video_device *device,
291 int event);
292 static int acpi_video_device_get_state(struct acpi_video_device *device,
293 unsigned long *state);
294 static int acpi_video_output_get(struct output_device *od);
295 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
297 /*backlight device sysfs support*/
298 static int acpi_video_get_brightness(struct backlight_device *bd)
300 unsigned long cur_level;
301 int i;
302 struct acpi_video_device *vd =
303 (struct acpi_video_device *)bl_get_data(bd);
304 acpi_video_device_lcd_get_level_current(vd, &cur_level);
305 for (i = 2; i < vd->brightness->count; i++) {
306 if (vd->brightness->levels[i] == cur_level)
307 /* The first two entries are special - see page 575
308 of the ACPI spec 3.0 */
309 return i-2;
311 return 0;
314 static int acpi_video_set_brightness(struct backlight_device *bd)
316 int request_level = bd->props.brightness+2;
317 struct acpi_video_device *vd =
318 (struct acpi_video_device *)bl_get_data(bd);
319 acpi_video_device_lcd_set_level(vd,
320 vd->brightness->levels[request_level]);
321 return 0;
324 static struct backlight_ops acpi_backlight_ops = {
325 .get_brightness = acpi_video_get_brightness,
326 .update_status = acpi_video_set_brightness,
329 /*video output device sysfs support*/
330 static int acpi_video_output_get(struct output_device *od)
332 unsigned long state;
333 struct acpi_video_device *vd =
334 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
335 acpi_video_device_get_state(vd, &state);
336 return (int)state;
339 static int acpi_video_output_set(struct output_device *od)
341 unsigned long state = od->request_state;
342 struct acpi_video_device *vd=
343 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
344 return acpi_video_device_set_state(vd, state);
347 static struct output_properties acpi_output_properties = {
348 .set_state = acpi_video_output_set,
349 .get_status = acpi_video_output_get,
353 /* thermal cooling device callbacks */
354 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
356 struct acpi_device *device = cdev->devdata;
357 struct acpi_video_device *video = acpi_driver_data(device);
359 return sprintf(buf, "%d\n", video->brightness->count - 3);
362 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
364 struct acpi_device *device = cdev->devdata;
365 struct acpi_video_device *video = acpi_driver_data(device);
366 unsigned long level;
367 int state;
369 acpi_video_device_lcd_get_level_current(video, &level);
370 for (state = 2; state < video->brightness->count; state++)
371 if (level == video->brightness->levels[state])
372 return sprintf(buf, "%d\n",
373 video->brightness->count - state - 1);
375 return -EINVAL;
378 static int
379 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
381 struct acpi_device *device = cdev->devdata;
382 struct acpi_video_device *video = acpi_driver_data(device);
383 int level;
385 if ( state >= video->brightness->count - 2)
386 return -EINVAL;
388 state = video->brightness->count - state;
389 level = video->brightness->levels[state -1];
390 return acpi_video_device_lcd_set_level(video, level);
393 static struct thermal_cooling_device_ops video_cooling_ops = {
394 .get_max_state = video_get_max_state,
395 .get_cur_state = video_get_cur_state,
396 .set_cur_state = video_set_cur_state,
399 /* --------------------------------------------------------------------------
400 Video Management
401 -------------------------------------------------------------------------- */
403 /* device */
405 static int
406 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
408 int status;
410 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
412 return status;
415 static int
416 acpi_video_device_get_state(struct acpi_video_device *device,
417 unsigned long *state)
419 int status;
421 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
423 return status;
426 static int
427 acpi_video_device_set_state(struct acpi_video_device *device, int state)
429 int status;
430 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
431 struct acpi_object_list args = { 1, &arg0 };
432 unsigned long ret;
435 arg0.integer.value = state;
436 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
438 return status;
441 static int
442 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
443 union acpi_object **levels)
445 int status;
446 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
447 union acpi_object *obj;
450 *levels = NULL;
452 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
453 if (!ACPI_SUCCESS(status))
454 return status;
455 obj = (union acpi_object *)buffer.pointer;
456 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
457 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
458 status = -EFAULT;
459 goto err;
462 *levels = obj;
464 return 0;
466 err:
467 kfree(buffer.pointer);
469 return status;
472 static int
473 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
475 int status = AE_OK;
476 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
477 struct acpi_object_list args = { 1, &arg0 };
480 arg0.integer.value = level;
482 if (device->cap._BCM)
483 status = acpi_evaluate_object(device->dev->handle, "_BCM",
484 &args, NULL);
485 device->brightness->curr = level;
486 return status;
489 static int
490 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
491 unsigned long *level)
493 if (device->cap._BQC)
494 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
495 level);
496 *level = device->brightness->curr;
497 return AE_OK;
500 static int
501 acpi_video_device_EDID(struct acpi_video_device *device,
502 union acpi_object **edid, ssize_t length)
504 int status;
505 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
506 union acpi_object *obj;
507 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
508 struct acpi_object_list args = { 1, &arg0 };
511 *edid = NULL;
513 if (!device)
514 return -ENODEV;
515 if (length == 128)
516 arg0.integer.value = 1;
517 else if (length == 256)
518 arg0.integer.value = 2;
519 else
520 return -EINVAL;
522 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
523 if (ACPI_FAILURE(status))
524 return -ENODEV;
526 obj = buffer.pointer;
528 if (obj && obj->type == ACPI_TYPE_BUFFER)
529 *edid = obj;
530 else {
531 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
532 status = -EFAULT;
533 kfree(obj);
536 return status;
539 /* bus */
541 static int
542 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
544 int status;
545 unsigned long tmp;
546 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
547 struct acpi_object_list args = { 1, &arg0 };
550 arg0.integer.value = option;
552 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
553 if (ACPI_SUCCESS(status))
554 status = tmp ? (-EINVAL) : (AE_OK);
556 return status;
559 static int
560 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
562 int status;
564 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
566 return status;
569 static int
570 acpi_video_bus_POST_options(struct acpi_video_bus *video,
571 unsigned long *options)
573 int status;
575 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
576 *options &= 3;
578 return status;
582 * Arg:
583 * video : video bus device pointer
584 * bios_flag :
585 * 0. The system BIOS should NOT automatically switch(toggle)
586 * the active display output.
587 * 1. The system BIOS should automatically switch (toggle) the
588 * active display output. No switch event.
589 * 2. The _DGS value should be locked.
590 * 3. The system BIOS should not automatically switch (toggle) the
591 * active display output, but instead generate the display switch
592 * event notify code.
593 * lcd_flag :
594 * 0. The system BIOS should automatically control the brightness level
595 * of the LCD when the power changes from AC to DC
596 * 1. The system BIOS should NOT automatically control the brightness
597 * level of the LCD when the power changes from AC to DC.
598 * Return Value:
599 * -1 wrong arg.
602 static int
603 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
605 acpi_integer status = 0;
606 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
607 struct acpi_object_list args = { 1, &arg0 };
610 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
611 status = -1;
612 goto Failed;
614 arg0.integer.value = (lcd_flag << 2) | bios_flag;
615 video->dos_setting = arg0.integer.value;
616 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
618 Failed:
619 return status;
623 * Arg:
624 * device : video output device (LCD, CRT, ..)
626 * Return Value:
627 * None
629 * Find out all required AML methods defined under the output
630 * device.
633 static void acpi_video_device_find_cap(struct acpi_video_device *device)
635 acpi_handle h_dummy1;
636 int i;
637 u32 max_level = 0;
638 union acpi_object *obj = NULL;
639 struct acpi_video_device_brightness *br = NULL;
642 memset(&device->cap, 0, sizeof(device->cap));
644 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
645 device->cap._ADR = 1;
647 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
648 device->cap._BCL = 1;
650 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
651 device->cap._BCM = 1;
653 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
654 device->cap._BQC = 1;
655 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
656 device->cap._DDC = 1;
658 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
659 device->cap._DCS = 1;
661 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
662 device->cap._DGS = 1;
664 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
665 device->cap._DSS = 1;
668 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
670 if (obj->package.count >= 2) {
671 int count = 0;
672 union acpi_object *o;
674 br = kzalloc(sizeof(*br), GFP_KERNEL);
675 if (!br) {
676 printk(KERN_ERR "can't allocate memory\n");
677 } else {
678 br->levels = kmalloc(obj->package.count *
679 sizeof *(br->levels), GFP_KERNEL);
680 if (!br->levels)
681 goto out;
683 for (i = 0; i < obj->package.count; i++) {
684 o = (union acpi_object *)&obj->package.
685 elements[i];
686 if (o->type != ACPI_TYPE_INTEGER) {
687 printk(KERN_ERR PREFIX "Invalid data\n");
688 continue;
690 br->levels[count] = (u32) o->integer.value;
692 if (br->levels[count] > max_level)
693 max_level = br->levels[count];
694 count++;
696 out:
697 if (count < 2) {
698 kfree(br->levels);
699 kfree(br);
700 } else {
701 br->count = count;
702 device->brightness = br;
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
704 "found %d brightness levels\n",
705 count));
710 } else {
711 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
714 kfree(obj);
716 <<<<<<< HEAD:drivers/acpi/video.c
717 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
718 =======
719 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
720 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
721 int result;
722 static int count = 0;
723 char *name;
724 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
725 if (!name)
726 return;
728 sprintf(name, "acpi_video%d", count++);
729 device->backlight = backlight_device_register(name,
730 NULL, device, &acpi_backlight_ops);
731 device->backlight->props.max_brightness = device->brightness->count-3;
732 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
733 backlight_update_status(device->backlight);
734 kfree(name);
736 device->cdev = thermal_cooling_device_register("LCD",
737 device->dev, &video_cooling_ops);
738 <<<<<<< HEAD:drivers/acpi/video.c
739 =======
740 if (IS_ERR(device->cdev))
741 return;
743 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
744 if (device->cdev) {
745 printk(KERN_INFO PREFIX
746 "%s is registered as cooling_device%d\n",
747 device->dev->dev.bus_id, device->cdev->id);
748 result = sysfs_create_link(&device->dev->dev.kobj,
749 &device->cdev->device.kobj,
750 "thermal_cooling");
751 if (result)
752 printk(KERN_ERR PREFIX "Create sysfs link\n");
753 result = sysfs_create_link(&device->cdev->device.kobj,
754 &device->dev->dev.kobj,
755 "device");
756 if (result)
757 printk(KERN_ERR PREFIX "Create sysfs link\n");
760 if (device->cap._DCS && device->cap._DSS){
761 static int count = 0;
762 char *name;
763 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
764 if (!name)
765 return;
766 sprintf(name, "acpi_video%d", count++);
767 device->output_dev = video_output_register(name,
768 NULL, device, &acpi_output_properties);
769 kfree(name);
771 return;
775 * Arg:
776 * device : video output device (VGA)
778 * Return Value:
779 * None
781 * Find out all required AML methods defined under the video bus device.
784 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
786 acpi_handle h_dummy1;
788 memset(&video->cap, 0, sizeof(video->cap));
789 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
790 video->cap._DOS = 1;
792 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
793 video->cap._DOD = 1;
795 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
796 video->cap._ROM = 1;
798 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
799 video->cap._GPD = 1;
801 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
802 video->cap._SPD = 1;
804 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
805 video->cap._VPO = 1;
810 * Check whether the video bus device has required AML method to
811 * support the desired features
814 static int acpi_video_bus_check(struct acpi_video_bus *video)
816 acpi_status status = -ENOENT;
817 <<<<<<< HEAD:drivers/acpi/video.c
818 long device_id;
819 struct device *dev;
820 struct acpi_device *device;
821 =======
823 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
825 if (!video)
826 return -EINVAL;
828 <<<<<<< HEAD:drivers/acpi/video.c
829 device = video->device;
831 status =
832 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
834 if (!ACPI_SUCCESS(status))
835 return -ENODEV;
837 /* We need to attempt to determine whether the _ADR refers to a
838 PCI device or not. There's no terribly good way to do this,
839 so the best we can hope for is to assume that there'll never
840 be a video device in the host bridge */
841 if (device_id >= 0x10000) {
842 /* It looks like a PCI device. Does it exist? */
843 dev = acpi_get_physical_device(device->handle);
844 } else {
845 /* It doesn't look like a PCI device. Does its parent
846 exist? */
847 acpi_handle phandle;
848 if (acpi_get_parent(device->handle, &phandle))
849 return -ENODEV;
850 dev = acpi_get_physical_device(phandle);
852 if (!dev)
853 return -ENODEV;
854 put_device(dev);
856 =======
857 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
858 /* Since there is no HID, CID and so on for VGA driver, we have
859 * to check well known required nodes.
862 /* Does this device support video switching? */
863 if (video->cap._DOS) {
864 video->flags.multihead = 1;
865 status = 0;
868 /* Does this device support retrieving a video ROM? */
869 if (video->cap._ROM) {
870 video->flags.rom = 1;
871 status = 0;
874 /* Does this device support configuring which video device to POST? */
875 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
876 video->flags.post = 1;
877 status = 0;
880 return status;
883 /* --------------------------------------------------------------------------
884 FS Interface (/proc)
885 -------------------------------------------------------------------------- */
887 static struct proc_dir_entry *acpi_video_dir;
889 /* video devices */
891 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
893 struct acpi_video_device *dev = seq->private;
896 if (!dev)
897 goto end;
899 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
900 seq_printf(seq, "type: ");
901 if (dev->flags.crt)
902 seq_printf(seq, "CRT\n");
903 else if (dev->flags.lcd)
904 seq_printf(seq, "LCD\n");
905 else if (dev->flags.tvout)
906 seq_printf(seq, "TVOUT\n");
907 else if (dev->flags.dvi)
908 seq_printf(seq, "DVI\n");
909 else
910 seq_printf(seq, "UNKNOWN\n");
912 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
914 end:
915 return 0;
918 static int
919 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
921 return single_open(file, acpi_video_device_info_seq_show,
922 PDE(inode)->data);
925 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
927 int status;
928 struct acpi_video_device *dev = seq->private;
929 unsigned long state;
932 if (!dev)
933 goto end;
935 status = acpi_video_device_get_state(dev, &state);
936 seq_printf(seq, "state: ");
937 if (ACPI_SUCCESS(status))
938 seq_printf(seq, "0x%02lx\n", state);
939 else
940 seq_printf(seq, "<not supported>\n");
942 status = acpi_video_device_query(dev, &state);
943 seq_printf(seq, "query: ");
944 if (ACPI_SUCCESS(status))
945 seq_printf(seq, "0x%02lx\n", state);
946 else
947 seq_printf(seq, "<not supported>\n");
949 end:
950 return 0;
953 static int
954 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
956 return single_open(file, acpi_video_device_state_seq_show,
957 PDE(inode)->data);
960 static ssize_t
961 acpi_video_device_write_state(struct file *file,
962 const char __user * buffer,
963 size_t count, loff_t * data)
965 int status;
966 struct seq_file *m = file->private_data;
967 struct acpi_video_device *dev = m->private;
968 char str[12] = { 0 };
969 u32 state = 0;
972 if (!dev || count + 1 > sizeof str)
973 return -EINVAL;
975 if (copy_from_user(str, buffer, count))
976 return -EFAULT;
978 str[count] = 0;
979 state = simple_strtoul(str, NULL, 0);
980 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
982 status = acpi_video_device_set_state(dev, state);
984 if (status)
985 return -EFAULT;
987 return count;
990 static int
991 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
993 struct acpi_video_device *dev = seq->private;
994 int i;
997 if (!dev || !dev->brightness) {
998 seq_printf(seq, "<not supported>\n");
999 return 0;
1002 seq_printf(seq, "levels: ");
1003 for (i = 0; i < dev->brightness->count; i++)
1004 seq_printf(seq, " %d", dev->brightness->levels[i]);
1005 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1007 return 0;
1010 static int
1011 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1013 return single_open(file, acpi_video_device_brightness_seq_show,
1014 PDE(inode)->data);
1017 static ssize_t
1018 acpi_video_device_write_brightness(struct file *file,
1019 const char __user * buffer,
1020 size_t count, loff_t * data)
1022 struct seq_file *m = file->private_data;
1023 struct acpi_video_device *dev = m->private;
1024 char str[5] = { 0 };
1025 unsigned int level = 0;
1026 int i;
1029 if (!dev || !dev->brightness || count + 1 > sizeof str)
1030 return -EINVAL;
1032 if (copy_from_user(str, buffer, count))
1033 return -EFAULT;
1035 str[count] = 0;
1036 level = simple_strtoul(str, NULL, 0);
1038 if (level > 100)
1039 return -EFAULT;
1041 /* validate through the list of available levels */
1042 for (i = 0; i < dev->brightness->count; i++)
1043 if (level == dev->brightness->levels[i]) {
1044 if (ACPI_SUCCESS
1045 (acpi_video_device_lcd_set_level(dev, level)))
1046 dev->brightness->curr = level;
1047 break;
1050 return count;
1053 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1055 struct acpi_video_device *dev = seq->private;
1056 int status;
1057 int i;
1058 union acpi_object *edid = NULL;
1061 if (!dev)
1062 goto out;
1064 status = acpi_video_device_EDID(dev, &edid, 128);
1065 if (ACPI_FAILURE(status)) {
1066 status = acpi_video_device_EDID(dev, &edid, 256);
1069 if (ACPI_FAILURE(status)) {
1070 goto out;
1073 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1074 for (i = 0; i < edid->buffer.length; i++)
1075 seq_putc(seq, edid->buffer.pointer[i]);
1078 out:
1079 if (!edid)
1080 seq_printf(seq, "<not supported>\n");
1081 else
1082 kfree(edid);
1084 return 0;
1087 static int
1088 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1090 return single_open(file, acpi_video_device_EDID_seq_show,
1091 PDE(inode)->data);
1094 static int acpi_video_device_add_fs(struct acpi_device *device)
1096 struct proc_dir_entry *entry = NULL;
1097 struct acpi_video_device *vid_dev;
1100 if (!device)
1101 return -ENODEV;
1103 vid_dev = acpi_driver_data(device);
1104 if (!vid_dev)
1105 return -ENODEV;
1107 if (!acpi_device_dir(device)) {
1108 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1109 vid_dev->video->dir);
1110 if (!acpi_device_dir(device))
1111 return -ENODEV;
1112 acpi_device_dir(device)->owner = THIS_MODULE;
1115 /* 'info' [R] */
1116 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1117 if (!entry)
1118 return -ENODEV;
1119 else {
1120 entry->proc_fops = &acpi_video_device_info_fops;
1121 entry->data = acpi_driver_data(device);
1122 entry->owner = THIS_MODULE;
1125 /* 'state' [R/W] */
1126 entry =
1127 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1128 acpi_device_dir(device));
1129 if (!entry)
1130 return -ENODEV;
1131 else {
1132 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1133 entry->proc_fops = &acpi_video_device_state_fops;
1134 entry->data = acpi_driver_data(device);
1135 entry->owner = THIS_MODULE;
1138 /* 'brightness' [R/W] */
1139 entry =
1140 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1141 acpi_device_dir(device));
1142 if (!entry)
1143 return -ENODEV;
1144 else {
1145 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1146 entry->proc_fops = &acpi_video_device_brightness_fops;
1147 entry->data = acpi_driver_data(device);
1148 entry->owner = THIS_MODULE;
1151 /* 'EDID' [R] */
1152 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1153 if (!entry)
1154 return -ENODEV;
1155 else {
1156 entry->proc_fops = &acpi_video_device_EDID_fops;
1157 entry->data = acpi_driver_data(device);
1158 entry->owner = THIS_MODULE;
1161 return 0;
1164 static int acpi_video_device_remove_fs(struct acpi_device *device)
1166 struct acpi_video_device *vid_dev;
1168 vid_dev = acpi_driver_data(device);
1169 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1170 return -ENODEV;
1172 if (acpi_device_dir(device)) {
1173 remove_proc_entry("info", acpi_device_dir(device));
1174 remove_proc_entry("state", acpi_device_dir(device));
1175 remove_proc_entry("brightness", acpi_device_dir(device));
1176 remove_proc_entry("EDID", acpi_device_dir(device));
1177 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1178 acpi_device_dir(device) = NULL;
1181 return 0;
1184 /* video bus */
1185 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1187 struct acpi_video_bus *video = seq->private;
1190 if (!video)
1191 goto end;
1193 seq_printf(seq, "Switching heads: %s\n",
1194 video->flags.multihead ? "yes" : "no");
1195 seq_printf(seq, "Video ROM: %s\n",
1196 video->flags.rom ? "yes" : "no");
1197 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1198 video->flags.post ? "yes" : "no");
1200 end:
1201 return 0;
1204 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1206 return single_open(file, acpi_video_bus_info_seq_show,
1207 PDE(inode)->data);
1210 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1212 struct acpi_video_bus *video = seq->private;
1215 if (!video)
1216 goto end;
1218 <<<<<<< HEAD:drivers/acpi/video.c
1219 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1220 =======
1221 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1222 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
1223 seq_printf(seq, "<TODO>\n");
1225 end:
1226 return 0;
1229 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1231 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1234 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1236 struct acpi_video_bus *video = seq->private;
1237 unsigned long options;
1238 int status;
1241 if (!video)
1242 goto end;
1244 status = acpi_video_bus_POST_options(video, &options);
1245 if (ACPI_SUCCESS(status)) {
1246 if (!(options & 1)) {
1247 printk(KERN_WARNING PREFIX
1248 "The motherboard VGA device is not listed as a possible POST device.\n");
1249 printk(KERN_WARNING PREFIX
1250 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1252 printk("%lx\n", options);
1253 seq_printf(seq, "can POST: <integrated video>");
1254 if (options & 2)
1255 seq_printf(seq, " <PCI video>");
1256 if (options & 4)
1257 seq_printf(seq, " <AGP video>");
1258 seq_putc(seq, '\n');
1259 } else
1260 seq_printf(seq, "<not supported>\n");
1261 end:
1262 return 0;
1265 static int
1266 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1268 return single_open(file, acpi_video_bus_POST_info_seq_show,
1269 PDE(inode)->data);
1272 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1274 struct acpi_video_bus *video = seq->private;
1275 int status;
1276 unsigned long id;
1279 if (!video)
1280 goto end;
1282 status = acpi_video_bus_get_POST(video, &id);
1283 if (!ACPI_SUCCESS(status)) {
1284 seq_printf(seq, "<not supported>\n");
1285 goto end;
1287 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1289 end:
1290 return 0;
1293 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1295 struct acpi_video_bus *video = seq->private;
1298 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1300 return 0;
1303 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1305 return single_open(file, acpi_video_bus_POST_seq_show,
1306 PDE(inode)->data);
1309 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1311 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1314 static ssize_t
1315 acpi_video_bus_write_POST(struct file *file,
1316 const char __user * buffer,
1317 size_t count, loff_t * data)
1319 int status;
1320 struct seq_file *m = file->private_data;
1321 struct acpi_video_bus *video = m->private;
1322 char str[12] = { 0 };
1323 unsigned long opt, options;
1326 if (!video || count + 1 > sizeof str)
1327 return -EINVAL;
1329 status = acpi_video_bus_POST_options(video, &options);
1330 if (!ACPI_SUCCESS(status))
1331 return -EINVAL;
1333 if (copy_from_user(str, buffer, count))
1334 return -EFAULT;
1336 str[count] = 0;
1337 opt = strtoul(str, NULL, 0);
1338 if (opt > 3)
1339 return -EFAULT;
1341 /* just in case an OEM 'forgot' the motherboard... */
1342 options |= 1;
1344 if (options & (1ul << opt)) {
1345 status = acpi_video_bus_set_POST(video, opt);
1346 if (!ACPI_SUCCESS(status))
1347 return -EFAULT;
1351 return count;
1354 static ssize_t
1355 acpi_video_bus_write_DOS(struct file *file,
1356 const char __user * buffer,
1357 size_t count, loff_t * data)
1359 int status;
1360 struct seq_file *m = file->private_data;
1361 struct acpi_video_bus *video = m->private;
1362 char str[12] = { 0 };
1363 unsigned long opt;
1366 if (!video || count + 1 > sizeof str)
1367 return -EINVAL;
1369 if (copy_from_user(str, buffer, count))
1370 return -EFAULT;
1372 str[count] = 0;
1373 opt = strtoul(str, NULL, 0);
1374 if (opt > 7)
1375 return -EFAULT;
1377 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1379 if (!ACPI_SUCCESS(status))
1380 return -EFAULT;
1382 return count;
1385 static int acpi_video_bus_add_fs(struct acpi_device *device)
1387 <<<<<<< HEAD:drivers/acpi/video.c
1388 long device_id;
1389 int status;
1390 =======
1391 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
1392 struct proc_dir_entry *entry = NULL;
1393 struct acpi_video_bus *video;
1394 <<<<<<< HEAD:drivers/acpi/video.c
1395 struct device *dev;
1397 status =
1398 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1400 if (!ACPI_SUCCESS(status))
1401 return -ENODEV;
1403 /* We need to attempt to determine whether the _ADR refers to a
1404 PCI device or not. There's no terribly good way to do this,
1405 so the best we can hope for is to assume that there'll never
1406 be a video device in the host bridge */
1407 if (device_id >= 0x10000) {
1408 /* It looks like a PCI device. Does it exist? */
1409 dev = acpi_get_physical_device(device->handle);
1410 } else {
1411 /* It doesn't look like a PCI device. Does its parent
1412 exist? */
1413 acpi_handle phandle;
1414 if (acpi_get_parent(device->handle, &phandle))
1415 return -ENODEV;
1416 dev = acpi_get_physical_device(phandle);
1418 if (!dev)
1419 return -ENODEV;
1420 put_device(dev);
1422 =======
1423 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/acpi/video.c
1426 video = acpi_driver_data(device);
1428 if (!acpi_device_dir(device)) {
1429 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1430 acpi_video_dir);
1431 if (!acpi_device_dir(device))
1432 return -ENODEV;
1433 video->dir = acpi_device_dir(device);
1434 acpi_device_dir(device)->owner = THIS_MODULE;
1437 /* 'info' [R] */
1438 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1439 if (!entry)
1440 return -ENODEV;
1441 else {
1442 entry->proc_fops = &acpi_video_bus_info_fops;
1443 entry->data = acpi_driver_data(device);
1444 entry->owner = THIS_MODULE;
1447 /* 'ROM' [R] */
1448 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1449 if (!entry)
1450 return -ENODEV;
1451 else {
1452 entry->proc_fops = &acpi_video_bus_ROM_fops;
1453 entry->data = acpi_driver_data(device);
1454 entry->owner = THIS_MODULE;
1457 /* 'POST_info' [R] */
1458 entry =
1459 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1460 if (!entry)
1461 return -ENODEV;
1462 else {
1463 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1464 entry->data = acpi_driver_data(device);
1465 entry->owner = THIS_MODULE;
1468 /* 'POST' [R/W] */
1469 entry =
1470 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1471 acpi_device_dir(device));
1472 if (!entry)
1473 return -ENODEV;
1474 else {
1475 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1476 entry->proc_fops = &acpi_video_bus_POST_fops;
1477 entry->data = acpi_driver_data(device);
1478 entry->owner = THIS_MODULE;
1481 /* 'DOS' [R/W] */
1482 entry =
1483 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1484 acpi_device_dir(device));
1485 if (!entry)
1486 return -ENODEV;
1487 else {
1488 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1489 entry->proc_fops = &acpi_video_bus_DOS_fops;
1490 entry->data = acpi_driver_data(device);
1491 entry->owner = THIS_MODULE;
1494 return 0;
1497 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1499 struct acpi_video_bus *video;
1502 video = acpi_driver_data(device);
1504 if (acpi_device_dir(device)) {
1505 remove_proc_entry("info", acpi_device_dir(device));
1506 remove_proc_entry("ROM", acpi_device_dir(device));
1507 remove_proc_entry("POST_info", acpi_device_dir(device));
1508 remove_proc_entry("POST", acpi_device_dir(device));
1509 remove_proc_entry("DOS", acpi_device_dir(device));
1510 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1511 acpi_device_dir(device) = NULL;
1514 return 0;
1517 /* --------------------------------------------------------------------------
1518 Driver Interface
1519 -------------------------------------------------------------------------- */
1521 /* device interface */
1522 static struct acpi_video_device_attrib*
1523 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1525 int count;
1527 for(count = 0; count < video->attached_count; count++)
1528 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1529 return &(video->attached_array[count].value.attrib);
1530 return NULL;
1533 static int
1534 acpi_video_bus_get_one_device(struct acpi_device *device,
1535 struct acpi_video_bus *video)
1537 unsigned long device_id;
1538 int status;
1539 struct acpi_video_device *data;
1540 struct acpi_video_device_attrib* attribute;
1542 if (!device || !video)
1543 return -EINVAL;
1545 status =
1546 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1547 if (ACPI_SUCCESS(status)) {
1549 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1550 if (!data)
1551 return -ENOMEM;
1553 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1554 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1555 acpi_driver_data(device) = data;
1557 data->device_id = device_id;
1558 data->video = video;
1559 data->dev = device;
1561 attribute = acpi_video_get_device_attr(video, device_id);
1563 if((attribute != NULL) && attribute->device_id_scheme) {
1564 switch (attribute->display_type) {
1565 case ACPI_VIDEO_DISPLAY_CRT:
1566 data->flags.crt = 1;
1567 break;
1568 case ACPI_VIDEO_DISPLAY_TV:
1569 data->flags.tvout = 1;
1570 break;
1571 case ACPI_VIDEO_DISPLAY_DVI:
1572 data->flags.dvi = 1;
1573 break;
1574 case ACPI_VIDEO_DISPLAY_LCD:
1575 data->flags.lcd = 1;
1576 break;
1577 default:
1578 data->flags.unknown = 1;
1579 break;
1581 if(attribute->bios_can_detect)
1582 data->flags.bios = 1;
1583 } else
1584 data->flags.unknown = 1;
1586 acpi_video_device_bind(video, data);
1587 acpi_video_device_find_cap(data);
1589 status = acpi_install_notify_handler(device->handle,
1590 ACPI_DEVICE_NOTIFY,
1591 acpi_video_device_notify,
1592 data);
1593 if (ACPI_FAILURE(status)) {
1594 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1595 "Error installing notify handler\n"));
1596 if(data->brightness)
1597 kfree(data->brightness->levels);
1598 kfree(data->brightness);
1599 kfree(data);
1600 return -ENODEV;
1603 mutex_lock(&video->device_list_lock);
1604 list_add_tail(&data->entry, &video->video_device_list);
1605 mutex_unlock(&video->device_list_lock);
1607 acpi_video_device_add_fs(device);
1609 return 0;
1612 return -ENOENT;
1616 * Arg:
1617 * video : video bus device
1619 * Return:
1620 * none
1622 * Enumerate the video device list of the video bus,
1623 * bind the ids with the corresponding video devices
1624 * under the video bus.
1627 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1629 struct acpi_video_device *dev;
1631 mutex_lock(&video->device_list_lock);
1633 list_for_each_entry(dev, &video->video_device_list, entry)
1634 acpi_video_device_bind(video, dev);
1636 mutex_unlock(&video->device_list_lock);
1640 * Arg:
1641 * video : video bus device
1642 * device : video output device under the video
1643 * bus
1645 * Return:
1646 * none
1648 * Bind the ids with the corresponding video devices
1649 * under the video bus.
1652 static void
1653 acpi_video_device_bind(struct acpi_video_bus *video,
1654 struct acpi_video_device *device)
1656 int i;
1658 #define IDS_VAL(i) video->attached_array[i].value.int_val
1659 #define IDS_BIND(i) video->attached_array[i].bind_info
1661 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1662 i < video->attached_count; i++) {
1663 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1664 IDS_BIND(i) = device;
1665 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1668 #undef IDS_VAL
1669 #undef IDS_BIND
1673 * Arg:
1674 * video : video bus device
1676 * Return:
1677 * < 0 : error
1679 * Call _DOD to enumerate all devices attached to display adapter
1683 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1685 int status;
1686 int count;
1687 int i;
1688 struct acpi_video_enumerated_device *active_device_list;
1689 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1690 union acpi_object *dod = NULL;
1691 union acpi_object *obj;
1693 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1694 if (!ACPI_SUCCESS(status)) {
1695 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1696 return status;
1699 dod = buffer.pointer;
1700 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1701 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1702 status = -EFAULT;
1703 goto out;
1706 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1707 dod->package.count));
1709 active_device_list = kmalloc((1 +
1710 dod->package.count) *
1711 sizeof(struct
1712 acpi_video_enumerated_device),
1713 GFP_KERNEL);
1715 if (!active_device_list) {
1716 status = -ENOMEM;
1717 goto out;
1720 count = 0;
1721 for (i = 0; i < dod->package.count; i++) {
1722 obj = &dod->package.elements[i];
1724 if (obj->type != ACPI_TYPE_INTEGER) {
1725 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1726 active_device_list[i].value.int_val =
1727 ACPI_VIDEO_HEAD_INVALID;
1729 active_device_list[i].value.int_val = obj->integer.value;
1730 active_device_list[i].bind_info = NULL;
1731 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1732 (int)obj->integer.value));
1733 count++;
1735 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1737 kfree(video->attached_array);
1739 video->attached_array = active_device_list;
1740 video->attached_count = count;
1741 out:
1742 kfree(buffer.pointer);
1743 return status;
1746 static int
1747 acpi_video_get_next_level(struct acpi_video_device *device,
1748 u32 level_current, u32 event)
1750 int min, max, min_above, max_below, i, l, delta = 255;
1751 max = max_below = 0;
1752 min = min_above = 255;
1753 /* Find closest level to level_current */
1754 for (i = 0; i < device->brightness->count; i++) {
1755 l = device->brightness->levels[i];
1756 if (abs(l - level_current) < abs(delta)) {
1757 delta = l - level_current;
1758 if (!delta)
1759 break;
1762 /* Ajust level_current to closest available level */
1763 level_current += delta;
1764 for (i = 0; i < device->brightness->count; i++) {
1765 l = device->brightness->levels[i];
1766 if (l < min)
1767 min = l;
1768 if (l > max)
1769 max = l;
1770 if (l < min_above && l > level_current)
1771 min_above = l;
1772 if (l > max_below && l < level_current)
1773 max_below = l;
1776 switch (event) {
1777 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1778 return (level_current < max) ? min_above : min;
1779 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1780 return (level_current < max) ? min_above : max;
1781 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1782 return (level_current > min) ? max_below : min;
1783 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1784 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1785 return 0;
1786 default:
1787 return level_current;
1791 static void
1792 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1794 unsigned long level_current, level_next;
1795 acpi_video_device_lcd_get_level_current(device, &level_current);
1796 level_next = acpi_video_get_next_level(device, level_current, event);
1797 acpi_video_device_lcd_set_level(device, level_next);
1800 static int
1801 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1802 struct acpi_device *device)
1804 int status = 0;
1805 struct acpi_device *dev;
1807 acpi_video_device_enumerate(video);
1809 list_for_each_entry(dev, &device->children, node) {
1811 status = acpi_video_bus_get_one_device(dev, video);
1812 if (ACPI_FAILURE(status)) {
1813 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1814 continue;
1817 return status;
1820 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1822 acpi_status status;
1823 struct acpi_video_bus *video;
1826 if (!device || !device->video)
1827 return -ENOENT;
1829 video = device->video;
1831 acpi_video_device_remove_fs(device->dev);
1833 status = acpi_remove_notify_handler(device->dev->handle,
1834 ACPI_DEVICE_NOTIFY,
1835 acpi_video_device_notify);
1836 backlight_device_unregister(device->backlight);
1837 if (device->cdev) {
1838 sysfs_remove_link(&device->dev->dev.kobj,
1839 "thermal_cooling");
1840 sysfs_remove_link(&device->cdev->device.kobj,
1841 "device");
1842 thermal_cooling_device_unregister(device->cdev);
1843 device->cdev = NULL;
1845 video_output_unregister(device->output_dev);
1847 return 0;
1850 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1852 int status;
1853 struct acpi_video_device *dev, *next;
1855 mutex_lock(&video->device_list_lock);
1857 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1859 status = acpi_video_bus_put_one_device(dev);
1860 if (ACPI_FAILURE(status))
1861 printk(KERN_WARNING PREFIX
1862 "hhuuhhuu bug in acpi video driver.\n");
1864 if (dev->brightness) {
1865 kfree(dev->brightness->levels);
1866 kfree(dev->brightness);
1868 list_del(&dev->entry);
1869 kfree(dev);
1872 mutex_unlock(&video->device_list_lock);
1874 return 0;
1877 /* acpi_video interface */
1879 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1881 return acpi_video_bus_DOS(video, 0, 0);
1884 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1886 return acpi_video_bus_DOS(video, 0, 1);
1889 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1891 struct acpi_video_bus *video = data;
1892 struct acpi_device *device = NULL;
1893 struct input_dev *input;
1894 int keycode;
1896 if (!video)
1897 return;
1899 device = video->device;
1900 input = video->input;
1902 switch (event) {
1903 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1904 * most likely via hotkey. */
1905 acpi_bus_generate_proc_event(device, event, 0);
1906 keycode = KEY_SWITCHVIDEOMODE;
1907 break;
1909 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1910 * connector. */
1911 acpi_video_device_enumerate(video);
1912 acpi_video_device_rebind(video);
1913 acpi_bus_generate_proc_event(device, event, 0);
1914 keycode = KEY_SWITCHVIDEOMODE;
1915 break;
1917 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1918 acpi_bus_generate_proc_event(device, event, 0);
1919 keycode = KEY_SWITCHVIDEOMODE;
1920 break;
1921 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1922 acpi_bus_generate_proc_event(device, event, 0);
1923 keycode = KEY_VIDEO_NEXT;
1924 break;
1925 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1926 acpi_bus_generate_proc_event(device, event, 0);
1927 keycode = KEY_VIDEO_PREV;
1928 break;
1930 default:
1931 keycode = KEY_UNKNOWN;
1932 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1933 "Unsupported event [0x%x]\n", event));
1934 break;
1937 acpi_notifier_call_chain(device, event, 0);
1938 input_report_key(input, keycode, 1);
1939 input_sync(input);
1940 input_report_key(input, keycode, 0);
1941 input_sync(input);
1943 return;
1946 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1948 struct acpi_video_device *video_device = data;
1949 struct acpi_device *device = NULL;
1950 struct acpi_video_bus *bus;
1951 struct input_dev *input;
1952 int keycode;
1954 if (!video_device)
1955 return;
1957 device = video_device->dev;
1958 bus = video_device->video;
1959 input = bus->input;
1961 switch (event) {
1962 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1963 if (brightness_switch_enabled)
1964 acpi_video_switch_brightness(video_device, event);
1965 acpi_bus_generate_proc_event(device, event, 0);
1966 keycode = KEY_BRIGHTNESS_CYCLE;
1967 break;
1968 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1969 if (brightness_switch_enabled)
1970 acpi_video_switch_brightness(video_device, event);
1971 acpi_bus_generate_proc_event(device, event, 0);
1972 keycode = KEY_BRIGHTNESSUP;
1973 break;
1974 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1975 if (brightness_switch_enabled)
1976 acpi_video_switch_brightness(video_device, event);
1977 acpi_bus_generate_proc_event(device, event, 0);
1978 keycode = KEY_BRIGHTNESSDOWN;
1979 break;
1980 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1981 if (brightness_switch_enabled)
1982 acpi_video_switch_brightness(video_device, event);
1983 acpi_bus_generate_proc_event(device, event, 0);
1984 keycode = KEY_BRIGHTNESS_ZERO;
1985 break;
1986 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1987 if (brightness_switch_enabled)
1988 acpi_video_switch_brightness(video_device, event);
1989 acpi_bus_generate_proc_event(device, event, 0);
1990 keycode = KEY_DISPLAY_OFF;
1991 break;
1992 default:
1993 keycode = KEY_UNKNOWN;
1994 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1995 "Unsupported event [0x%x]\n", event));
1996 break;
1999 acpi_notifier_call_chain(device, event, 0);
2000 input_report_key(input, keycode, 1);
2001 input_sync(input);
2002 input_report_key(input, keycode, 0);
2003 input_sync(input);
2005 return;
2008 static int instance;
2009 static int acpi_video_resume(struct acpi_device *device)
2011 struct acpi_video_bus *video;
2012 struct acpi_video_device *video_device;
2013 int i;
2015 if (!device || !acpi_driver_data(device))
2016 return -EINVAL;
2018 video = acpi_driver_data(device);
2020 for (i = 0; i < video->attached_count; i++) {
2021 video_device = video->attached_array[i].bind_info;
2022 if (video_device && video_device->backlight)
2023 acpi_video_set_brightness(video_device->backlight);
2025 return AE_OK;
2028 static int acpi_video_bus_add(struct acpi_device *device)
2030 acpi_status status;
2031 struct acpi_video_bus *video;
2032 struct input_dev *input;
2033 int error;
2035 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2036 if (!video)
2037 return -ENOMEM;
2039 /* a hack to fix the duplicate name "VID" problem on T61 */
2040 if (!strcmp(device->pnp.bus_id, "VID")) {
2041 if (instance)
2042 device->pnp.bus_id[3] = '0' + instance;
2043 instance ++;
2046 video->device = device;
2047 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2048 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2049 acpi_driver_data(device) = video;
2051 acpi_video_bus_find_cap(video);
2052 error = acpi_video_bus_check(video);
2053 if (error)
2054 goto err_free_video;
2056 error = acpi_video_bus_add_fs(device);
2057 if (error)
2058 goto err_free_video;
2060 mutex_init(&video->device_list_lock);
2061 INIT_LIST_HEAD(&video->video_device_list);
2063 acpi_video_bus_get_devices(video, device);
2064 acpi_video_bus_start_devices(video);
2066 status = acpi_install_notify_handler(device->handle,
2067 ACPI_DEVICE_NOTIFY,
2068 acpi_video_bus_notify, video);
2069 if (ACPI_FAILURE(status)) {
2070 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2071 "Error installing notify handler\n"));
2072 error = -ENODEV;
2073 goto err_stop_video;
2076 video->input = input = input_allocate_device();
2077 if (!input) {
2078 error = -ENOMEM;
2079 goto err_uninstall_notify;
2082 snprintf(video->phys, sizeof(video->phys),
2083 "%s/video/input0", acpi_device_hid(video->device));
2085 input->name = acpi_device_name(video->device);
2086 input->phys = video->phys;
2087 input->id.bustype = BUS_HOST;
2088 input->id.product = 0x06;
2089 input->dev.parent = &device->dev;
2090 input->evbit[0] = BIT(EV_KEY);
2091 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2092 set_bit(KEY_VIDEO_NEXT, input->keybit);
2093 set_bit(KEY_VIDEO_PREV, input->keybit);
2094 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2095 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2096 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2097 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2098 set_bit(KEY_DISPLAY_OFF, input->keybit);
2099 set_bit(KEY_UNKNOWN, input->keybit);
2101 error = input_register_device(input);
2102 if (error)
2103 goto err_free_input_dev;
2105 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2106 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2107 video->flags.multihead ? "yes" : "no",
2108 video->flags.rom ? "yes" : "no",
2109 video->flags.post ? "yes" : "no");
2111 return 0;
2113 err_free_input_dev:
2114 input_free_device(input);
2115 err_uninstall_notify:
2116 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2117 acpi_video_bus_notify);
2118 err_stop_video:
2119 acpi_video_bus_stop_devices(video);
2120 acpi_video_bus_put_devices(video);
2121 kfree(video->attached_array);
2122 acpi_video_bus_remove_fs(device);
2123 err_free_video:
2124 kfree(video);
2125 acpi_driver_data(device) = NULL;
2127 return error;
2130 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2132 acpi_status status = 0;
2133 struct acpi_video_bus *video = NULL;
2136 if (!device || !acpi_driver_data(device))
2137 return -EINVAL;
2139 video = acpi_driver_data(device);
2141 acpi_video_bus_stop_devices(video);
2143 status = acpi_remove_notify_handler(video->device->handle,
2144 ACPI_DEVICE_NOTIFY,
2145 acpi_video_bus_notify);
2147 acpi_video_bus_put_devices(video);
2148 acpi_video_bus_remove_fs(device);
2150 input_unregister_device(video->input);
2151 kfree(video->attached_array);
2152 kfree(video);
2154 return 0;
2157 static int __init acpi_video_init(void)
2159 int result = 0;
2163 acpi_dbg_level = 0xFFFFFFFF;
2164 acpi_dbg_layer = 0x08000000;
2167 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2168 if (!acpi_video_dir)
2169 return -ENODEV;
2170 acpi_video_dir->owner = THIS_MODULE;
2172 result = acpi_bus_register_driver(&acpi_video_bus);
2173 if (result < 0) {
2174 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2175 return -ENODEV;
2178 return 0;
2181 static void __exit acpi_video_exit(void)
2184 acpi_bus_unregister_driver(&acpi_video_bus);
2186 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2188 return;
2191 module_init(acpi_video_init);
2192 module_exit(acpi_video_exit);