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[] = {
87 MODULE_DEVICE_TABLE(acpi, video_device_ids);
89 static struct acpi_driver acpi_video_bus = {
91 .class = ACPI_VIDEO_CLASS,
92 .ids = video_device_ids,
94 .add = acpi_video_bus_add,
95 .remove = acpi_video_bus_remove,
96 .resume = acpi_video_resume,
100 struct acpi_video_bus_flags {
101 u8 multihead:1; /* can switch video heads */
102 u8 rom:1; /* can retrieve a video rom */
103 u8 post:1; /* can configure the head to */
107 struct acpi_video_bus_cap {
108 u8 _DOS:1; /*Enable/Disable output switching */
109 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM:1; /*Get ROM Data */
111 u8 _GPD:1; /*Get POST Device */
112 u8 _SPD:1; /*Set POST Device */
113 u8 _VPO:1; /*Video POST Options */
117 struct acpi_video_device_attrib {
118 u32 display_index:4; /* A zero-based instance of the Display */
119 u32 display_port_attachment:4; /*This field differentiates the display type */
120 u32 display_type:4; /*Describe the specific type in use */
121 u32 vendor_specific:4; /*Chipset Vendor Specific */
122 u32 bios_can_detect:1; /*BIOS can detect the device */
123 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
125 u32 pipe_id:3; /*For VGA multiple-head devices. */
126 u32 reserved:10; /*Must be 0 */
127 u32 device_id_scheme:1; /*Device ID Scheme */
130 struct acpi_video_enumerated_device {
133 struct acpi_video_device_attrib attrib;
135 struct acpi_video_device *bind_info;
138 struct acpi_video_bus {
139 struct acpi_device *device;
141 struct acpi_video_enumerated_device *attached_array;
143 struct acpi_video_bus_cap cap;
144 struct acpi_video_bus_flags flags;
145 struct list_head video_device_list;
146 struct mutex device_list_lock; /* protects video_device_list */
147 struct proc_dir_entry *dir;
148 struct input_dev *input;
149 char phys[32]; /* for input device */
152 struct acpi_video_device_flags {
162 struct acpi_video_device_cap {
163 u8 _ADR:1; /*Return the unique ID */
164 u8 _BCL:1; /*Query list of brightness control levels supported */
165 u8 _BCM:1; /*Set the brightness level */
166 u8 _BQC:1; /* Get current brightness level */
167 u8 _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 {
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;
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,
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,
206 .release = single_release,
209 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
211 static struct file_operations acpi_video_bus_POST_info_fops = {
212 .open = acpi_video_bus_POST_info_open_fs,
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,
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,
231 .release = single_release,
235 static int acpi_video_device_info_open_fs(struct inode *inode,
237 static struct file_operations acpi_video_device_info_fops = {
238 .open = acpi_video_device_info_open_fs,
241 .release = single_release,
244 static int acpi_video_device_state_open_fs(struct inode *inode,
246 static struct file_operations acpi_video_device_state_fops = {
247 .open = acpi_video_device_state_open_fs,
250 .release = single_release,
253 static int acpi_video_device_brightness_open_fs(struct inode *inode,
255 static struct file_operations acpi_video_device_brightness_fops = {
256 .open = acpi_video_device_brightness_open_fs,
259 .release = single_release,
262 static int acpi_video_device_EDID_open_fs(struct inode *inode,
264 static struct file_operations acpi_video_device_EDID_fops = {
265 .open = acpi_video_device_EDID_open_fs,
268 .release = single_release,
271 static char device_decode[][30] = {
272 "motherboard VGA device",
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,
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,
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;
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 */
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]);
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)
333 struct acpi_video_device *vd =
334 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
335 acpi_video_device_get_state(vd, &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);
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);
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);
385 if ( state >= video->brightness->count - 2)
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 /* --------------------------------------------------------------------------
401 -------------------------------------------------------------------------- */
406 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
410 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
416 acpi_video_device_get_state(struct acpi_video_device *device,
417 unsigned long *state)
421 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
427 acpi_video_device_set_state(struct acpi_video_device *device, int state)
430 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
431 struct acpi_object_list args = { 1, &arg0 };
435 arg0.integer.value = state;
436 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
442 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
443 union acpi_object **levels)
446 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
447 union acpi_object *obj;
452 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
453 if (!ACPI_SUCCESS(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");
467 kfree(buffer.pointer);
473 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
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",
485 device->brightness->curr = level;
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,
496 *level = device->brightness->curr;
501 acpi_video_device_EDID(struct acpi_video_device *device,
502 union acpi_object **edid, ssize_t length)
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 };
516 arg0.integer.value = 1;
517 else if (length == 256)
518 arg0.integer.value = 2;
522 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
523 if (ACPI_FAILURE(status))
526 obj = buffer.pointer;
528 if (obj && obj->type == ACPI_TYPE_BUFFER)
531 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
542 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
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);
560 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
564 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
570 acpi_video_bus_POST_options(struct acpi_video_bus *video,
571 unsigned long *options)
575 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
583 * video : video bus device pointer
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
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.
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) {
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);
624 * device : video output device (LCD, CRT, ..)
629 * Find out all required AML methods defined under the output
633 static void acpi_video_device_find_cap(struct acpi_video_device *device)
635 acpi_handle h_dummy1;
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) {
672 union acpi_object *o;
674 br = kzalloc(sizeof(*br), GFP_KERNEL);
676 printk(KERN_ERR "can't allocate memory\n");
678 br->levels = kmalloc(obj->package.count *
679 sizeof *(br->levels), GFP_KERNEL);
683 for (i = 0; i < obj->package.count; i++) {
684 o = (union acpi_object *)&obj->package.
686 if (o->type != ACPI_TYPE_INTEGER) {
687 printk(KERN_ERR PREFIX "Invalid data\n");
690 br->levels[count] = (u32) o->integer.value;
692 if (br->levels[count] > max_level)
693 max_level = br->levels[count];
702 device->brightness = br;
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
704 "found %d brightness levels\n",
711 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
716 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
718 static int count = 0;
720 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
724 sprintf(name, "acpi_video%d", count++);
725 device->backlight = backlight_device_register(name,
726 NULL, device, &acpi_backlight_ops);
727 device->backlight->props.max_brightness = device->brightness->count-3;
728 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
729 backlight_update_status(device->backlight);
732 device->cdev = thermal_cooling_device_register("LCD",
733 device->dev, &video_cooling_ops);
734 if (IS_ERR(device->cdev))
738 printk(KERN_INFO PREFIX
739 "%s is registered as cooling_device%d\n",
740 device->dev->dev.bus_id, device->cdev->id);
741 result = sysfs_create_link(&device->dev->dev.kobj,
742 &device->cdev->device.kobj,
745 printk(KERN_ERR PREFIX "Create sysfs link\n");
746 result = sysfs_create_link(&device->cdev->device.kobj,
747 &device->dev->dev.kobj,
750 printk(KERN_ERR PREFIX "Create sysfs link\n");
753 if (device->cap._DCS && device->cap._DSS){
754 static int count = 0;
756 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
759 sprintf(name, "acpi_video%d", count++);
760 device->output_dev = video_output_register(name,
761 NULL, device, &acpi_output_properties);
769 * device : video output device (VGA)
774 * Find out all required AML methods defined under the video bus device.
777 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
779 acpi_handle h_dummy1;
781 memset(&video->cap, 0, sizeof(video->cap));
782 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
785 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
788 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
791 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
794 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
797 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
803 * Check whether the video bus device has required AML method to
804 * support the desired features
807 static int acpi_video_bus_check(struct acpi_video_bus *video)
809 acpi_status status = -ENOENT;
812 struct acpi_device *device;
817 device = video->device;
820 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
822 if (!ACPI_SUCCESS(status))
825 /* We need to attempt to determine whether the _ADR refers to a
826 PCI device or not. There's no terribly good way to do this,
827 so the best we can hope for is to assume that there'll never
828 be a video device in the host bridge */
829 if (device_id >= 0x10000) {
830 /* It looks like a PCI device. Does it exist? */
831 dev = acpi_get_physical_device(device->handle);
833 /* It doesn't look like a PCI device. Does its parent
836 if (acpi_get_parent(device->handle, &phandle))
838 dev = acpi_get_physical_device(phandle);
844 /* Since there is no HID, CID and so on for VGA driver, we have
845 * to check well known required nodes.
848 /* Does this device support video switching? */
849 if (video->cap._DOS) {
850 video->flags.multihead = 1;
854 /* Does this device support retrieving a video ROM? */
855 if (video->cap._ROM) {
856 video->flags.rom = 1;
860 /* Does this device support configuring which video device to POST? */
861 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
862 video->flags.post = 1;
869 /* --------------------------------------------------------------------------
871 -------------------------------------------------------------------------- */
873 static struct proc_dir_entry *acpi_video_dir;
877 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
879 struct acpi_video_device *dev = seq->private;
885 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
886 seq_printf(seq, "type: ");
888 seq_printf(seq, "CRT\n");
889 else if (dev->flags.lcd)
890 seq_printf(seq, "LCD\n");
891 else if (dev->flags.tvout)
892 seq_printf(seq, "TVOUT\n");
893 else if (dev->flags.dvi)
894 seq_printf(seq, "DVI\n");
896 seq_printf(seq, "UNKNOWN\n");
898 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
905 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
907 return single_open(file, acpi_video_device_info_seq_show,
911 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
914 struct acpi_video_device *dev = seq->private;
921 status = acpi_video_device_get_state(dev, &state);
922 seq_printf(seq, "state: ");
923 if (ACPI_SUCCESS(status))
924 seq_printf(seq, "0x%02lx\n", state);
926 seq_printf(seq, "<not supported>\n");
928 status = acpi_video_device_query(dev, &state);
929 seq_printf(seq, "query: ");
930 if (ACPI_SUCCESS(status))
931 seq_printf(seq, "0x%02lx\n", state);
933 seq_printf(seq, "<not supported>\n");
940 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
942 return single_open(file, acpi_video_device_state_seq_show,
947 acpi_video_device_write_state(struct file *file,
948 const char __user * buffer,
949 size_t count, loff_t * data)
952 struct seq_file *m = file->private_data;
953 struct acpi_video_device *dev = m->private;
954 char str[12] = { 0 };
958 if (!dev || count + 1 > sizeof str)
961 if (copy_from_user(str, buffer, count))
965 state = simple_strtoul(str, NULL, 0);
966 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
968 status = acpi_video_device_set_state(dev, state);
977 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
979 struct acpi_video_device *dev = seq->private;
983 if (!dev || !dev->brightness) {
984 seq_printf(seq, "<not supported>\n");
988 seq_printf(seq, "levels: ");
989 for (i = 0; i < dev->brightness->count; i++)
990 seq_printf(seq, " %d", dev->brightness->levels[i]);
991 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
997 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
999 return single_open(file, acpi_video_device_brightness_seq_show,
1004 acpi_video_device_write_brightness(struct file *file,
1005 const char __user * buffer,
1006 size_t count, loff_t * data)
1008 struct seq_file *m = file->private_data;
1009 struct acpi_video_device *dev = m->private;
1010 char str[5] = { 0 };
1011 unsigned int level = 0;
1015 if (!dev || !dev->brightness || count + 1 > sizeof str)
1018 if (copy_from_user(str, buffer, count))
1022 level = simple_strtoul(str, NULL, 0);
1027 /* validate through the list of available levels */
1028 for (i = 0; i < dev->brightness->count; i++)
1029 if (level == dev->brightness->levels[i]) {
1031 (acpi_video_device_lcd_set_level(dev, level)))
1032 dev->brightness->curr = level;
1039 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1041 struct acpi_video_device *dev = seq->private;
1044 union acpi_object *edid = NULL;
1050 status = acpi_video_device_EDID(dev, &edid, 128);
1051 if (ACPI_FAILURE(status)) {
1052 status = acpi_video_device_EDID(dev, &edid, 256);
1055 if (ACPI_FAILURE(status)) {
1059 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1060 for (i = 0; i < edid->buffer.length; i++)
1061 seq_putc(seq, edid->buffer.pointer[i]);
1066 seq_printf(seq, "<not supported>\n");
1074 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1076 return single_open(file, acpi_video_device_EDID_seq_show,
1080 static int acpi_video_device_add_fs(struct acpi_device *device)
1082 struct proc_dir_entry *entry = NULL;
1083 struct acpi_video_device *vid_dev;
1089 vid_dev = acpi_driver_data(device);
1093 if (!acpi_device_dir(device)) {
1094 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1095 vid_dev->video->dir);
1096 if (!acpi_device_dir(device))
1098 acpi_device_dir(device)->owner = THIS_MODULE;
1102 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1106 entry->proc_fops = &acpi_video_device_info_fops;
1107 entry->data = acpi_driver_data(device);
1108 entry->owner = THIS_MODULE;
1113 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1114 acpi_device_dir(device));
1118 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1119 entry->proc_fops = &acpi_video_device_state_fops;
1120 entry->data = acpi_driver_data(device);
1121 entry->owner = THIS_MODULE;
1124 /* 'brightness' [R/W] */
1126 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1127 acpi_device_dir(device));
1131 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
1132 entry->proc_fops = &acpi_video_device_brightness_fops;
1133 entry->data = acpi_driver_data(device);
1134 entry->owner = THIS_MODULE;
1138 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1142 entry->proc_fops = &acpi_video_device_EDID_fops;
1143 entry->data = acpi_driver_data(device);
1144 entry->owner = THIS_MODULE;
1150 static int acpi_video_device_remove_fs(struct acpi_device *device)
1152 struct acpi_video_device *vid_dev;
1154 vid_dev = acpi_driver_data(device);
1155 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1158 if (acpi_device_dir(device)) {
1159 remove_proc_entry("info", acpi_device_dir(device));
1160 remove_proc_entry("state", acpi_device_dir(device));
1161 remove_proc_entry("brightness", acpi_device_dir(device));
1162 remove_proc_entry("EDID", acpi_device_dir(device));
1163 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1164 acpi_device_dir(device) = NULL;
1171 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1173 struct acpi_video_bus *video = seq->private;
1179 seq_printf(seq, "Switching heads: %s\n",
1180 video->flags.multihead ? "yes" : "no");
1181 seq_printf(seq, "Video ROM: %s\n",
1182 video->flags.rom ? "yes" : "no");
1183 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1184 video->flags.post ? "yes" : "no");
1190 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1192 return single_open(file, acpi_video_bus_info_seq_show,
1196 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1198 struct acpi_video_bus *video = seq->private;
1204 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1205 seq_printf(seq, "<TODO>\n");
1211 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1213 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1216 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1218 struct acpi_video_bus *video = seq->private;
1219 unsigned long options;
1226 status = acpi_video_bus_POST_options(video, &options);
1227 if (ACPI_SUCCESS(status)) {
1228 if (!(options & 1)) {
1229 printk(KERN_WARNING PREFIX
1230 "The motherboard VGA device is not listed as a possible POST device.\n");
1231 printk(KERN_WARNING PREFIX
1232 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1234 printk("%lx\n", options);
1235 seq_printf(seq, "can POST: <integrated video>");
1237 seq_printf(seq, " <PCI video>");
1239 seq_printf(seq, " <AGP video>");
1240 seq_putc(seq, '\n');
1242 seq_printf(seq, "<not supported>\n");
1248 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1250 return single_open(file, acpi_video_bus_POST_info_seq_show,
1254 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1256 struct acpi_video_bus *video = seq->private;
1264 status = acpi_video_bus_get_POST(video, &id);
1265 if (!ACPI_SUCCESS(status)) {
1266 seq_printf(seq, "<not supported>\n");
1269 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1275 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1277 struct acpi_video_bus *video = seq->private;
1280 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1285 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1287 return single_open(file, acpi_video_bus_POST_seq_show,
1291 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1293 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1297 acpi_video_bus_write_POST(struct file *file,
1298 const char __user * buffer,
1299 size_t count, loff_t * data)
1302 struct seq_file *m = file->private_data;
1303 struct acpi_video_bus *video = m->private;
1304 char str[12] = { 0 };
1305 unsigned long opt, options;
1308 if (!video || count + 1 > sizeof str)
1311 status = acpi_video_bus_POST_options(video, &options);
1312 if (!ACPI_SUCCESS(status))
1315 if (copy_from_user(str, buffer, count))
1319 opt = strtoul(str, NULL, 0);
1323 /* just in case an OEM 'forgot' the motherboard... */
1326 if (options & (1ul << opt)) {
1327 status = acpi_video_bus_set_POST(video, opt);
1328 if (!ACPI_SUCCESS(status))
1337 acpi_video_bus_write_DOS(struct file *file,
1338 const char __user * buffer,
1339 size_t count, loff_t * data)
1342 struct seq_file *m = file->private_data;
1343 struct acpi_video_bus *video = m->private;
1344 char str[12] = { 0 };
1348 if (!video || count + 1 > sizeof str)
1351 if (copy_from_user(str, buffer, count))
1355 opt = strtoul(str, NULL, 0);
1359 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1361 if (!ACPI_SUCCESS(status))
1367 static int acpi_video_bus_add_fs(struct acpi_device *device)
1371 struct proc_dir_entry *entry = NULL;
1372 struct acpi_video_bus *video;
1376 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1378 if (!ACPI_SUCCESS(status))
1381 /* We need to attempt to determine whether the _ADR refers to a
1382 PCI device or not. There's no terribly good way to do this,
1383 so the best we can hope for is to assume that there'll never
1384 be a video device in the host bridge */
1385 if (device_id >= 0x10000) {
1386 /* It looks like a PCI device. Does it exist? */
1387 dev = acpi_get_physical_device(device->handle);
1389 /* It doesn't look like a PCI device. Does its parent
1391 acpi_handle phandle;
1392 if (acpi_get_parent(device->handle, &phandle))
1394 dev = acpi_get_physical_device(phandle);
1402 video = acpi_driver_data(device);
1404 if (!acpi_device_dir(device)) {
1405 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1407 if (!acpi_device_dir(device))
1409 video->dir = acpi_device_dir(device);
1410 acpi_device_dir(device)->owner = THIS_MODULE;
1414 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1418 entry->proc_fops = &acpi_video_bus_info_fops;
1419 entry->data = acpi_driver_data(device);
1420 entry->owner = THIS_MODULE;
1424 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1428 entry->proc_fops = &acpi_video_bus_ROM_fops;
1429 entry->data = acpi_driver_data(device);
1430 entry->owner = THIS_MODULE;
1433 /* 'POST_info' [R] */
1435 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
1439 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1440 entry->data = acpi_driver_data(device);
1441 entry->owner = THIS_MODULE;
1446 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1447 acpi_device_dir(device));
1451 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1452 entry->proc_fops = &acpi_video_bus_POST_fops;
1453 entry->data = acpi_driver_data(device);
1454 entry->owner = THIS_MODULE;
1459 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1460 acpi_device_dir(device));
1464 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1465 entry->proc_fops = &acpi_video_bus_DOS_fops;
1466 entry->data = acpi_driver_data(device);
1467 entry->owner = THIS_MODULE;
1473 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1475 struct acpi_video_bus *video;
1478 video = acpi_driver_data(device);
1480 if (acpi_device_dir(device)) {
1481 remove_proc_entry("info", acpi_device_dir(device));
1482 remove_proc_entry("ROM", acpi_device_dir(device));
1483 remove_proc_entry("POST_info", acpi_device_dir(device));
1484 remove_proc_entry("POST", acpi_device_dir(device));
1485 remove_proc_entry("DOS", acpi_device_dir(device));
1486 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1487 acpi_device_dir(device) = NULL;
1493 /* --------------------------------------------------------------------------
1495 -------------------------------------------------------------------------- */
1497 /* device interface */
1498 static struct acpi_video_device_attrib*
1499 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1503 for(count = 0; count < video->attached_count; count++)
1504 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1505 return &(video->attached_array[count].value.attrib);
1510 acpi_video_bus_get_one_device(struct acpi_device *device,
1511 struct acpi_video_bus *video)
1513 unsigned long device_id;
1515 struct acpi_video_device *data;
1516 struct acpi_video_device_attrib* attribute;
1518 if (!device || !video)
1522 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1523 if (ACPI_SUCCESS(status)) {
1525 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1529 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1530 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1531 acpi_driver_data(device) = data;
1533 data->device_id = device_id;
1534 data->video = video;
1537 attribute = acpi_video_get_device_attr(video, device_id);
1539 if((attribute != NULL) && attribute->device_id_scheme) {
1540 switch (attribute->display_type) {
1541 case ACPI_VIDEO_DISPLAY_CRT:
1542 data->flags.crt = 1;
1544 case ACPI_VIDEO_DISPLAY_TV:
1545 data->flags.tvout = 1;
1547 case ACPI_VIDEO_DISPLAY_DVI:
1548 data->flags.dvi = 1;
1550 case ACPI_VIDEO_DISPLAY_LCD:
1551 data->flags.lcd = 1;
1554 data->flags.unknown = 1;
1557 if(attribute->bios_can_detect)
1558 data->flags.bios = 1;
1560 data->flags.unknown = 1;
1562 acpi_video_device_bind(video, data);
1563 acpi_video_device_find_cap(data);
1565 status = acpi_install_notify_handler(device->handle,
1567 acpi_video_device_notify,
1569 if (ACPI_FAILURE(status)) {
1570 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1571 "Error installing notify handler\n"));
1572 if(data->brightness)
1573 kfree(data->brightness->levels);
1574 kfree(data->brightness);
1579 mutex_lock(&video->device_list_lock);
1580 list_add_tail(&data->entry, &video->video_device_list);
1581 mutex_unlock(&video->device_list_lock);
1583 acpi_video_device_add_fs(device);
1593 * video : video bus device
1598 * Enumerate the video device list of the video bus,
1599 * bind the ids with the corresponding video devices
1600 * under the video bus.
1603 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1605 struct acpi_video_device *dev;
1607 mutex_lock(&video->device_list_lock);
1609 list_for_each_entry(dev, &video->video_device_list, entry)
1610 acpi_video_device_bind(video, dev);
1612 mutex_unlock(&video->device_list_lock);
1617 * video : video bus device
1618 * device : video output device under the video
1624 * Bind the ids with the corresponding video devices
1625 * under the video bus.
1629 acpi_video_device_bind(struct acpi_video_bus *video,
1630 struct acpi_video_device *device)
1634 #define IDS_VAL(i) video->attached_array[i].value.int_val
1635 #define IDS_BIND(i) video->attached_array[i].bind_info
1637 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1638 i < video->attached_count; i++) {
1639 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1640 IDS_BIND(i) = device;
1641 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1650 * video : video bus device
1655 * Call _DOD to enumerate all devices attached to display adapter
1659 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1664 struct acpi_video_enumerated_device *active_device_list;
1665 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1666 union acpi_object *dod = NULL;
1667 union acpi_object *obj;
1669 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1670 if (!ACPI_SUCCESS(status)) {
1671 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1675 dod = buffer.pointer;
1676 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1677 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1682 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1683 dod->package.count));
1685 active_device_list = kmalloc((1 +
1686 dod->package.count) *
1688 acpi_video_enumerated_device),
1691 if (!active_device_list) {
1697 for (i = 0; i < dod->package.count; i++) {
1698 obj = &dod->package.elements[i];
1700 if (obj->type != ACPI_TYPE_INTEGER) {
1701 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
1702 active_device_list[i].value.int_val =
1703 ACPI_VIDEO_HEAD_INVALID;
1705 active_device_list[i].value.int_val = obj->integer.value;
1706 active_device_list[i].bind_info = NULL;
1707 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1708 (int)obj->integer.value));
1711 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1713 kfree(video->attached_array);
1715 video->attached_array = active_device_list;
1716 video->attached_count = count;
1718 kfree(buffer.pointer);
1723 acpi_video_get_next_level(struct acpi_video_device *device,
1724 u32 level_current, u32 event)
1726 int min, max, min_above, max_below, i, l, delta = 255;
1727 max = max_below = 0;
1728 min = min_above = 255;
1729 /* Find closest level to level_current */
1730 for (i = 0; i < device->brightness->count; i++) {
1731 l = device->brightness->levels[i];
1732 if (abs(l - level_current) < abs(delta)) {
1733 delta = l - level_current;
1738 /* Ajust level_current to closest available level */
1739 level_current += delta;
1740 for (i = 0; i < device->brightness->count; i++) {
1741 l = device->brightness->levels[i];
1746 if (l < min_above && l > level_current)
1748 if (l > max_below && l < level_current)
1753 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1754 return (level_current < max) ? min_above : min;
1755 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1756 return (level_current < max) ? min_above : max;
1757 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1758 return (level_current > min) ? max_below : min;
1759 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1760 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1763 return level_current;
1768 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1770 unsigned long level_current, level_next;
1771 acpi_video_device_lcd_get_level_current(device, &level_current);
1772 level_next = acpi_video_get_next_level(device, level_current, event);
1773 acpi_video_device_lcd_set_level(device, level_next);
1777 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1778 struct acpi_device *device)
1781 struct acpi_device *dev;
1783 acpi_video_device_enumerate(video);
1785 list_for_each_entry(dev, &device->children, node) {
1787 status = acpi_video_bus_get_one_device(dev, video);
1788 if (ACPI_FAILURE(status)) {
1789 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1796 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1799 struct acpi_video_bus *video;
1802 if (!device || !device->video)
1805 video = device->video;
1807 acpi_video_device_remove_fs(device->dev);
1809 status = acpi_remove_notify_handler(device->dev->handle,
1811 acpi_video_device_notify);
1812 backlight_device_unregister(device->backlight);
1814 sysfs_remove_link(&device->dev->dev.kobj,
1816 sysfs_remove_link(&device->cdev->device.kobj,
1818 thermal_cooling_device_unregister(device->cdev);
1819 device->cdev = NULL;
1821 video_output_unregister(device->output_dev);
1826 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1829 struct acpi_video_device *dev, *next;
1831 mutex_lock(&video->device_list_lock);
1833 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1835 status = acpi_video_bus_put_one_device(dev);
1836 if (ACPI_FAILURE(status))
1837 printk(KERN_WARNING PREFIX
1838 "hhuuhhuu bug in acpi video driver.\n");
1840 if (dev->brightness) {
1841 kfree(dev->brightness->levels);
1842 kfree(dev->brightness);
1844 list_del(&dev->entry);
1848 mutex_unlock(&video->device_list_lock);
1853 /* acpi_video interface */
1855 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1857 return acpi_video_bus_DOS(video, 0, 0);
1860 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1862 return acpi_video_bus_DOS(video, 0, 1);
1865 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1867 struct acpi_video_bus *video = data;
1868 struct acpi_device *device = NULL;
1869 struct input_dev *input;
1875 device = video->device;
1876 input = video->input;
1879 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1880 * most likely via hotkey. */
1881 acpi_bus_generate_proc_event(device, event, 0);
1882 keycode = KEY_SWITCHVIDEOMODE;
1885 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1887 acpi_video_device_enumerate(video);
1888 acpi_video_device_rebind(video);
1889 acpi_bus_generate_proc_event(device, event, 0);
1890 keycode = KEY_SWITCHVIDEOMODE;
1893 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1894 acpi_bus_generate_proc_event(device, event, 0);
1895 keycode = KEY_SWITCHVIDEOMODE;
1897 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1898 acpi_bus_generate_proc_event(device, event, 0);
1899 keycode = KEY_VIDEO_NEXT;
1901 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1902 acpi_bus_generate_proc_event(device, event, 0);
1903 keycode = KEY_VIDEO_PREV;
1907 keycode = KEY_UNKNOWN;
1908 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1909 "Unsupported event [0x%x]\n", event));
1913 acpi_notifier_call_chain(device, event, 0);
1914 input_report_key(input, keycode, 1);
1916 input_report_key(input, keycode, 0);
1922 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1924 struct acpi_video_device *video_device = data;
1925 struct acpi_device *device = NULL;
1926 struct acpi_video_bus *bus;
1927 struct input_dev *input;
1933 device = video_device->dev;
1934 bus = video_device->video;
1938 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1939 if (brightness_switch_enabled)
1940 acpi_video_switch_brightness(video_device, event);
1941 acpi_bus_generate_proc_event(device, event, 0);
1942 keycode = KEY_BRIGHTNESS_CYCLE;
1944 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1945 if (brightness_switch_enabled)
1946 acpi_video_switch_brightness(video_device, event);
1947 acpi_bus_generate_proc_event(device, event, 0);
1948 keycode = KEY_BRIGHTNESSUP;
1950 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1951 if (brightness_switch_enabled)
1952 acpi_video_switch_brightness(video_device, event);
1953 acpi_bus_generate_proc_event(device, event, 0);
1954 keycode = KEY_BRIGHTNESSDOWN;
1956 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1957 if (brightness_switch_enabled)
1958 acpi_video_switch_brightness(video_device, event);
1959 acpi_bus_generate_proc_event(device, event, 0);
1960 keycode = KEY_BRIGHTNESS_ZERO;
1962 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
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_DISPLAY_OFF;
1969 keycode = KEY_UNKNOWN;
1970 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1971 "Unsupported event [0x%x]\n", event));
1975 acpi_notifier_call_chain(device, event, 0);
1976 input_report_key(input, keycode, 1);
1978 input_report_key(input, keycode, 0);
1984 static int instance;
1985 static int acpi_video_resume(struct acpi_device *device)
1987 struct acpi_video_bus *video;
1988 struct acpi_video_device *video_device;
1991 if (!device || !acpi_driver_data(device))
1994 video = acpi_driver_data(device);
1996 for (i = 0; i < video->attached_count; i++) {
1997 video_device = video->attached_array[i].bind_info;
1998 if (video_device && video_device->backlight)
1999 acpi_video_set_brightness(video_device->backlight);
2004 static int acpi_video_bus_add(struct acpi_device *device)
2007 struct acpi_video_bus *video;
2008 struct input_dev *input;
2011 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
2015 /* a hack to fix the duplicate name "VID" problem on T61 */
2016 if (!strcmp(device->pnp.bus_id, "VID")) {
2018 device->pnp.bus_id[3] = '0' + instance;
2022 video->device = device;
2023 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2024 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2025 acpi_driver_data(device) = video;
2027 acpi_video_bus_find_cap(video);
2028 error = acpi_video_bus_check(video);
2030 goto err_free_video;
2032 error = acpi_video_bus_add_fs(device);
2034 goto err_free_video;
2036 mutex_init(&video->device_list_lock);
2037 INIT_LIST_HEAD(&video->video_device_list);
2039 acpi_video_bus_get_devices(video, device);
2040 acpi_video_bus_start_devices(video);
2042 status = acpi_install_notify_handler(device->handle,
2044 acpi_video_bus_notify, video);
2045 if (ACPI_FAILURE(status)) {
2046 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
2047 "Error installing notify handler\n"));
2049 goto err_stop_video;
2052 video->input = input = input_allocate_device();
2055 goto err_uninstall_notify;
2058 snprintf(video->phys, sizeof(video->phys),
2059 "%s/video/input0", acpi_device_hid(video->device));
2061 input->name = acpi_device_name(video->device);
2062 input->phys = video->phys;
2063 input->id.bustype = BUS_HOST;
2064 input->id.product = 0x06;
2065 input->dev.parent = &device->dev;
2066 input->evbit[0] = BIT(EV_KEY);
2067 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2068 set_bit(KEY_VIDEO_NEXT, input->keybit);
2069 set_bit(KEY_VIDEO_PREV, input->keybit);
2070 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2071 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2072 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2073 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2074 set_bit(KEY_DISPLAY_OFF, input->keybit);
2075 set_bit(KEY_UNKNOWN, input->keybit);
2077 error = input_register_device(input);
2079 goto err_free_input_dev;
2081 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2082 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2083 video->flags.multihead ? "yes" : "no",
2084 video->flags.rom ? "yes" : "no",
2085 video->flags.post ? "yes" : "no");
2090 input_free_device(input);
2091 err_uninstall_notify:
2092 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2093 acpi_video_bus_notify);
2095 acpi_video_bus_stop_devices(video);
2096 acpi_video_bus_put_devices(video);
2097 kfree(video->attached_array);
2098 acpi_video_bus_remove_fs(device);
2101 acpi_driver_data(device) = NULL;
2106 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2108 acpi_status status = 0;
2109 struct acpi_video_bus *video = NULL;
2112 if (!device || !acpi_driver_data(device))
2115 video = acpi_driver_data(device);
2117 acpi_video_bus_stop_devices(video);
2119 status = acpi_remove_notify_handler(video->device->handle,
2121 acpi_video_bus_notify);
2123 acpi_video_bus_put_devices(video);
2124 acpi_video_bus_remove_fs(device);
2126 input_unregister_device(video->input);
2127 kfree(video->attached_array);
2133 static int __init acpi_video_init(void)
2139 acpi_dbg_level = 0xFFFFFFFF;
2140 acpi_dbg_layer = 0x08000000;
2143 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2144 if (!acpi_video_dir)
2146 acpi_video_dir->owner = THIS_MODULE;
2148 result = acpi_bus_register_driver(&acpi_video_bus);
2150 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2157 static void __exit acpi_video_exit(void)
2160 acpi_bus_unregister_driver(&acpi_video_bus);
2162 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2167 module_init(acpi_video_init);
2168 module_exit(acpi_video_exit);