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 MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device *device);
78 static int acpi_video_bus_remove(struct acpi_device *device, int type);
79 static int acpi_video_resume(struct acpi_device *device);
81 static const struct acpi_device_id video_device_ids[] = {
85 MODULE_DEVICE_TABLE(acpi, video_device_ids);
87 static struct acpi_driver acpi_video_bus = {
89 .class = ACPI_VIDEO_CLASS,
90 .ids = video_device_ids,
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
94 .resume = acpi_video_resume,
98 struct acpi_video_bus_flags {
99 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
105 struct acpi_video_bus_cap {
106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
115 struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment:4; /*This field differentiates the display type */
118 u32 display_type:4; /*Describe the specific type in use */
119 u32 vendor_specific:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device {
131 struct acpi_video_device_attrib attrib;
133 struct acpi_video_device *bind_info;
136 struct acpi_video_bus {
137 struct acpi_device *device;
139 struct acpi_video_enumerated_device *attached_array;
141 struct acpi_video_bus_cap cap;
142 struct acpi_video_bus_flags flags;
143 struct list_head video_device_list;
144 struct mutex device_list_lock; /* protects video_device_list */
145 struct proc_dir_entry *dir;
146 struct input_dev *input;
147 char phys[32]; /* for input device */
150 struct acpi_video_device_flags {
160 struct acpi_video_device_cap {
161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
164 u8 _BQC:1; /* Get current brightness level */
165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
171 struct acpi_video_device_brightness {
177 struct acpi_video_device {
178 unsigned long device_id;
179 struct acpi_video_device_flags flags;
180 struct acpi_video_device_cap cap;
181 struct list_head entry;
182 struct acpi_video_bus *video;
183 struct acpi_device *dev;
184 struct acpi_video_device_brightness *brightness;
185 struct backlight_device *backlight;
186 struct thermal_cooling_device *cdev;
187 struct output_device *output_dev;
191 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192 static struct file_operations acpi_video_bus_info_fops = {
193 .owner = THIS_MODULE,
194 .open = acpi_video_bus_info_open_fs,
197 .release = single_release,
200 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
201 static struct file_operations acpi_video_bus_ROM_fops = {
202 .owner = THIS_MODULE,
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 .owner = THIS_MODULE,
213 .open = acpi_video_bus_POST_info_open_fs,
216 .release = single_release,
219 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
220 static struct file_operations acpi_video_bus_POST_fops = {
221 .owner = THIS_MODULE,
222 .open = acpi_video_bus_POST_open_fs,
225 .release = single_release,
228 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
229 static struct file_operations acpi_video_bus_DOS_fops = {
230 .owner = THIS_MODULE,
231 .open = acpi_video_bus_DOS_open_fs,
234 .release = single_release,
238 static int acpi_video_device_info_open_fs(struct inode *inode,
240 static struct file_operations acpi_video_device_info_fops = {
241 .owner = THIS_MODULE,
242 .open = acpi_video_device_info_open_fs,
245 .release = single_release,
248 static int acpi_video_device_state_open_fs(struct inode *inode,
250 static struct file_operations acpi_video_device_state_fops = {
251 .owner = THIS_MODULE,
252 .open = acpi_video_device_state_open_fs,
255 .release = single_release,
258 static int acpi_video_device_brightness_open_fs(struct inode *inode,
260 static struct file_operations acpi_video_device_brightness_fops = {
261 .owner = THIS_MODULE,
262 .open = acpi_video_device_brightness_open_fs,
265 .release = single_release,
268 static int acpi_video_device_EDID_open_fs(struct inode *inode,
270 static struct file_operations acpi_video_device_EDID_fops = {
271 .owner = THIS_MODULE,
272 .open = acpi_video_device_EDID_open_fs,
275 .release = single_release,
278 static char device_decode[][30] = {
279 "motherboard VGA device",
285 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
286 static void acpi_video_device_rebind(struct acpi_video_bus *video);
287 static void acpi_video_device_bind(struct acpi_video_bus *video,
288 struct acpi_video_device *device);
289 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
290 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
292 static int acpi_video_device_lcd_get_level_current(
293 struct acpi_video_device *device,
294 unsigned long *level);
295 static int acpi_video_get_next_level(struct acpi_video_device *device,
296 u32 level_current, u32 event);
297 static void acpi_video_switch_brightness(struct acpi_video_device *device,
299 static int acpi_video_device_get_state(struct acpi_video_device *device,
300 unsigned long *state);
301 static int acpi_video_output_get(struct output_device *od);
302 static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
304 /*backlight device sysfs support*/
305 static int acpi_video_get_brightness(struct backlight_device *bd)
307 unsigned long cur_level;
309 struct acpi_video_device *vd =
310 (struct acpi_video_device *)bl_get_data(bd);
311 acpi_video_device_lcd_get_level_current(vd, &cur_level);
312 for (i = 2; i < vd->brightness->count; i++) {
313 if (vd->brightness->levels[i] == cur_level)
314 /* The first two entries are special - see page 575
315 of the ACPI spec 3.0 */
321 static int acpi_video_set_brightness(struct backlight_device *bd)
323 int request_level = bd->props.brightness+2;
324 struct acpi_video_device *vd =
325 (struct acpi_video_device *)bl_get_data(bd);
326 acpi_video_device_lcd_set_level(vd,
327 vd->brightness->levels[request_level]);
331 static struct backlight_ops acpi_backlight_ops = {
332 .get_brightness = acpi_video_get_brightness,
333 .update_status = acpi_video_set_brightness,
336 /*video output device sysfs support*/
337 static int acpi_video_output_get(struct output_device *od)
340 struct acpi_video_device *vd =
341 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
342 acpi_video_device_get_state(vd, &state);
346 static int acpi_video_output_set(struct output_device *od)
348 unsigned long state = od->request_state;
349 struct acpi_video_device *vd=
350 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
351 return acpi_video_device_set_state(vd, state);
354 static struct output_properties acpi_output_properties = {
355 .set_state = acpi_video_output_set,
356 .get_status = acpi_video_output_get,
360 /* thermal cooling device callbacks */
361 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
363 struct acpi_device *device = cdev->devdata;
364 struct acpi_video_device *video = acpi_driver_data(device);
366 return sprintf(buf, "%d\n", video->brightness->count - 3);
369 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
371 struct acpi_device *device = cdev->devdata;
372 struct acpi_video_device *video = acpi_driver_data(device);
376 acpi_video_device_lcd_get_level_current(video, &level);
377 for (state = 2; state < video->brightness->count; state++)
378 if (level == video->brightness->levels[state])
379 return sprintf(buf, "%d\n",
380 video->brightness->count - state - 1);
386 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
388 struct acpi_device *device = cdev->devdata;
389 struct acpi_video_device *video = acpi_driver_data(device);
392 if ( state >= video->brightness->count - 2)
395 state = video->brightness->count - state;
396 level = video->brightness->levels[state -1];
397 return acpi_video_device_lcd_set_level(video, level);
400 static struct thermal_cooling_device_ops video_cooling_ops = {
401 .get_max_state = video_get_max_state,
402 .get_cur_state = video_get_cur_state,
403 .set_cur_state = video_set_cur_state,
406 /* --------------------------------------------------------------------------
408 -------------------------------------------------------------------------- */
413 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
417 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
423 acpi_video_device_get_state(struct acpi_video_device *device,
424 unsigned long *state)
428 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
434 acpi_video_device_set_state(struct acpi_video_device *device, int state)
437 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
438 struct acpi_object_list args = { 1, &arg0 };
442 arg0.integer.value = state;
443 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
449 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
450 union acpi_object **levels)
453 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
454 union acpi_object *obj;
459 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
460 if (!ACPI_SUCCESS(status))
462 obj = (union acpi_object *)buffer.pointer;
463 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
464 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
474 kfree(buffer.pointer);
480 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
483 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
484 struct acpi_object_list args = { 1, &arg0 };
487 arg0.integer.value = level;
489 if (device->cap._BCM)
490 status = acpi_evaluate_object(device->dev->handle, "_BCM",
492 device->brightness->curr = level;
497 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
498 unsigned long *level)
500 if (device->cap._BQC)
501 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
503 *level = device->brightness->curr;
508 acpi_video_device_EDID(struct acpi_video_device *device,
509 union acpi_object **edid, ssize_t length)
512 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
513 union acpi_object *obj;
514 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
515 struct acpi_object_list args = { 1, &arg0 };
523 arg0.integer.value = 1;
524 else if (length == 256)
525 arg0.integer.value = 2;
529 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
530 if (ACPI_FAILURE(status))
533 obj = buffer.pointer;
535 if (obj && obj->type == ACPI_TYPE_BUFFER)
538 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
549 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
553 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
554 struct acpi_object_list args = { 1, &arg0 };
557 arg0.integer.value = option;
559 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
560 if (ACPI_SUCCESS(status))
561 status = tmp ? (-EINVAL) : (AE_OK);
567 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
571 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
577 acpi_video_bus_POST_options(struct acpi_video_bus *video,
578 unsigned long *options)
582 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
590 * video : video bus device pointer
592 * 0. The system BIOS should NOT automatically switch(toggle)
593 * the active display output.
594 * 1. The system BIOS should automatically switch (toggle) the
595 * active display output. No switch event.
596 * 2. The _DGS value should be locked.
597 * 3. The system BIOS should not automatically switch (toggle) the
598 * active display output, but instead generate the display switch
601 * 0. The system BIOS should automatically control the brightness level
602 * of the LCD when the power changes from AC to DC
603 * 1. The system BIOS should NOT automatically control the brightness
604 * level of the LCD when the power changes from AC to DC.
610 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
612 acpi_integer status = 0;
613 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
614 struct acpi_object_list args = { 1, &arg0 };
617 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
621 arg0.integer.value = (lcd_flag << 2) | bios_flag;
622 video->dos_setting = arg0.integer.value;
623 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
631 * device : video output device (LCD, CRT, ..)
636 * Find out all required AML methods defined under the output
640 static void acpi_video_device_find_cap(struct acpi_video_device *device)
642 acpi_handle h_dummy1;
645 union acpi_object *obj = NULL;
646 struct acpi_video_device_brightness *br = NULL;
649 memset(&device->cap, 0, sizeof(device->cap));
651 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
652 device->cap._ADR = 1;
654 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
655 device->cap._BCL = 1;
657 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
658 device->cap._BCM = 1;
660 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
661 device->cap._BQC = 1;
662 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
663 device->cap._DDC = 1;
665 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
666 device->cap._DCS = 1;
668 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
669 device->cap._DGS = 1;
671 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
672 device->cap._DSS = 1;
675 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
677 if (obj->package.count >= 2) {
679 union acpi_object *o;
681 br = kzalloc(sizeof(*br), GFP_KERNEL);
683 printk(KERN_ERR "can't allocate memory\n");
685 br->levels = kmalloc(obj->package.count *
686 sizeof *(br->levels), GFP_KERNEL);
690 for (i = 0; i < obj->package.count; i++) {
691 o = (union acpi_object *)&obj->package.
693 if (o->type != ACPI_TYPE_INTEGER) {
694 printk(KERN_ERR PREFIX "Invalid data\n");
697 br->levels[count] = (u32) o->integer.value;
699 if (br->levels[count] > max_level)
700 max_level = br->levels[count];
709 device->brightness = br;
710 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
711 "found %d brightness levels\n",
718 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
723 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
725 static int count = 0;
727 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
731 sprintf(name, "acpi_video%d", count++);
732 device->backlight = backlight_device_register(name,
733 NULL, device, &acpi_backlight_ops);
734 device->backlight->props.max_brightness = device->brightness->count-3;
735 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
736 backlight_update_status(device->backlight);
739 device->cdev = thermal_cooling_device_register("LCD",
740 device->dev, &video_cooling_ops);
741 if (IS_ERR(device->cdev))
744 printk(KERN_INFO PREFIX
745 "%s is registered as cooling_device%d\n",
746 device->dev->dev.bus_id, device->cdev->id);
747 result = sysfs_create_link(&device->dev->dev.kobj,
748 &device->cdev->device.kobj,
751 printk(KERN_ERR PREFIX "Create sysfs link\n");
752 result = sysfs_create_link(&device->cdev->device.kobj,
753 &device->dev->dev.kobj, "device");
755 printk(KERN_ERR PREFIX "Create sysfs link\n");
758 if (device->cap._DCS && device->cap._DSS){
759 static int count = 0;
761 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
764 sprintf(name, "acpi_video%d", count++);
765 device->output_dev = video_output_register(name,
766 NULL, device, &acpi_output_properties);
774 * device : video output device (VGA)
779 * Find out all required AML methods defined under the video bus device.
782 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
784 acpi_handle h_dummy1;
786 memset(&video->cap, 0, sizeof(video->cap));
787 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
790 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
793 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
796 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
799 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
802 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
808 * Check whether the video bus device has required AML method to
809 * support the desired features
812 static int acpi_video_bus_check(struct acpi_video_bus *video)
814 acpi_status status = -ENOENT;
820 /* Since there is no HID, CID and so on for VGA driver, we have
821 * to check well known required nodes.
824 /* Does this device support video switching? */
825 if (video->cap._DOS) {
826 video->flags.multihead = 1;
830 /* Does this device support retrieving a video ROM? */
831 if (video->cap._ROM) {
832 video->flags.rom = 1;
836 /* Does this device support configuring which video device to POST? */
837 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
838 video->flags.post = 1;
845 /* --------------------------------------------------------------------------
847 -------------------------------------------------------------------------- */
849 static struct proc_dir_entry *acpi_video_dir;
853 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
855 struct acpi_video_device *dev = seq->private;
861 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
862 seq_printf(seq, "type: ");
864 seq_printf(seq, "CRT\n");
865 else if (dev->flags.lcd)
866 seq_printf(seq, "LCD\n");
867 else if (dev->flags.tvout)
868 seq_printf(seq, "TVOUT\n");
869 else if (dev->flags.dvi)
870 seq_printf(seq, "DVI\n");
872 seq_printf(seq, "UNKNOWN\n");
874 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
881 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
883 return single_open(file, acpi_video_device_info_seq_show,
887 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
890 struct acpi_video_device *dev = seq->private;
897 status = acpi_video_device_get_state(dev, &state);
898 seq_printf(seq, "state: ");
899 if (ACPI_SUCCESS(status))
900 seq_printf(seq, "0x%02lx\n", state);
902 seq_printf(seq, "<not supported>\n");
904 status = acpi_video_device_query(dev, &state);
905 seq_printf(seq, "query: ");
906 if (ACPI_SUCCESS(status))
907 seq_printf(seq, "0x%02lx\n", state);
909 seq_printf(seq, "<not supported>\n");
916 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
918 return single_open(file, acpi_video_device_state_seq_show,
923 acpi_video_device_write_state(struct file *file,
924 const char __user * buffer,
925 size_t count, loff_t * data)
928 struct seq_file *m = file->private_data;
929 struct acpi_video_device *dev = m->private;
930 char str[12] = { 0 };
934 if (!dev || count + 1 > sizeof str)
937 if (copy_from_user(str, buffer, count))
941 state = simple_strtoul(str, NULL, 0);
942 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
944 status = acpi_video_device_set_state(dev, state);
953 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
955 struct acpi_video_device *dev = seq->private;
959 if (!dev || !dev->brightness) {
960 seq_printf(seq, "<not supported>\n");
964 seq_printf(seq, "levels: ");
965 for (i = 0; i < dev->brightness->count; i++)
966 seq_printf(seq, " %d", dev->brightness->levels[i]);
967 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
973 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
975 return single_open(file, acpi_video_device_brightness_seq_show,
980 acpi_video_device_write_brightness(struct file *file,
981 const char __user * buffer,
982 size_t count, loff_t * data)
984 struct seq_file *m = file->private_data;
985 struct acpi_video_device *dev = m->private;
987 unsigned int level = 0;
991 if (!dev || !dev->brightness || count + 1 > sizeof str)
994 if (copy_from_user(str, buffer, count))
998 level = simple_strtoul(str, NULL, 0);
1003 /* validate through the list of available levels */
1004 for (i = 0; i < dev->brightness->count; i++)
1005 if (level == dev->brightness->levels[i]) {
1007 (acpi_video_device_lcd_set_level(dev, level)))
1008 dev->brightness->curr = level;
1015 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1017 struct acpi_video_device *dev = seq->private;
1020 union acpi_object *edid = NULL;
1026 status = acpi_video_device_EDID(dev, &edid, 128);
1027 if (ACPI_FAILURE(status)) {
1028 status = acpi_video_device_EDID(dev, &edid, 256);
1031 if (ACPI_FAILURE(status)) {
1035 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1036 for (i = 0; i < edid->buffer.length; i++)
1037 seq_putc(seq, edid->buffer.pointer[i]);
1042 seq_printf(seq, "<not supported>\n");
1050 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1052 return single_open(file, acpi_video_device_EDID_seq_show,
1056 static int acpi_video_device_add_fs(struct acpi_device *device)
1058 struct proc_dir_entry *entry, *device_dir;
1059 struct acpi_video_device *vid_dev;
1061 vid_dev = acpi_driver_data(device);
1065 device_dir = proc_mkdir(acpi_device_bid(device),
1066 vid_dev->video->dir);
1070 device_dir->owner = THIS_MODULE;
1073 entry = proc_create_data("info", S_IRUGO, acpi_device_dir(device),
1074 &acpi_video_device_info_fops, acpi_driver_data(device));
1076 goto err_remove_dir;
1079 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1080 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1081 acpi_device_dir(device),
1082 &acpi_video_device_state_fops,
1083 acpi_driver_data(device));
1085 goto err_remove_info;
1087 /* 'brightness' [R/W] */
1088 acpi_video_device_brightness_fops.write =
1089 acpi_video_device_write_brightness;
1090 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1091 acpi_device_dir(device),
1092 &acpi_video_device_brightness_fops,
1093 acpi_driver_data(device));
1095 goto err_remove_state;
1098 entry = proc_create_data("EDID", S_IRUGO, acpi_device_dir(device),
1099 &acpi_video_device_EDID_fops,
1100 acpi_driver_data(device));
1102 goto err_remove_brightness;
1106 err_remove_brightness:
1107 remove_proc_entry("brightness", device_dir);
1109 remove_proc_entry("state", device_dir);
1111 remove_proc_entry("info", device_dir);
1113 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1117 static int acpi_video_device_remove_fs(struct acpi_device *device)
1119 struct acpi_video_device *vid_dev;
1120 struct proc_dir_entry *device_dir;
1122 vid_dev = acpi_driver_data(device);
1123 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1126 device_dir = acpi_device_dir(device);
1128 remove_proc_entry("info", device_dir);
1129 remove_proc_entry("state", device_dir);
1130 remove_proc_entry("brightness", device_dir);
1131 remove_proc_entry("EDID", device_dir);
1132 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1133 acpi_device_dir(device) = NULL;
1140 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1142 struct acpi_video_bus *video = seq->private;
1148 seq_printf(seq, "Switching heads: %s\n",
1149 video->flags.multihead ? "yes" : "no");
1150 seq_printf(seq, "Video ROM: %s\n",
1151 video->flags.rom ? "yes" : "no");
1152 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1153 video->flags.post ? "yes" : "no");
1159 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1161 return single_open(file, acpi_video_bus_info_seq_show,
1165 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1167 struct acpi_video_bus *video = seq->private;
1173 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1174 seq_printf(seq, "<TODO>\n");
1180 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1182 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1185 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1187 struct acpi_video_bus *video = seq->private;
1188 unsigned long options;
1195 status = acpi_video_bus_POST_options(video, &options);
1196 if (ACPI_SUCCESS(status)) {
1197 if (!(options & 1)) {
1198 printk(KERN_WARNING PREFIX
1199 "The motherboard VGA device is not listed as a possible POST device.\n");
1200 printk(KERN_WARNING PREFIX
1201 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1203 printk("%lx\n", options);
1204 seq_printf(seq, "can POST: <integrated video>");
1206 seq_printf(seq, " <PCI video>");
1208 seq_printf(seq, " <AGP video>");
1209 seq_putc(seq, '\n');
1211 seq_printf(seq, "<not supported>\n");
1217 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1219 return single_open(file, acpi_video_bus_POST_info_seq_show,
1223 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1225 struct acpi_video_bus *video = seq->private;
1233 status = acpi_video_bus_get_POST(video, &id);
1234 if (!ACPI_SUCCESS(status)) {
1235 seq_printf(seq, "<not supported>\n");
1238 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1244 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1246 struct acpi_video_bus *video = seq->private;
1249 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1254 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1256 return single_open(file, acpi_video_bus_POST_seq_show,
1260 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1262 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1266 acpi_video_bus_write_POST(struct file *file,
1267 const char __user * buffer,
1268 size_t count, loff_t * data)
1271 struct seq_file *m = file->private_data;
1272 struct acpi_video_bus *video = m->private;
1273 char str[12] = { 0 };
1274 unsigned long opt, options;
1277 if (!video || count + 1 > sizeof str)
1280 status = acpi_video_bus_POST_options(video, &options);
1281 if (!ACPI_SUCCESS(status))
1284 if (copy_from_user(str, buffer, count))
1288 opt = strtoul(str, NULL, 0);
1292 /* just in case an OEM 'forgot' the motherboard... */
1295 if (options & (1ul << opt)) {
1296 status = acpi_video_bus_set_POST(video, opt);
1297 if (!ACPI_SUCCESS(status))
1306 acpi_video_bus_write_DOS(struct file *file,
1307 const char __user * buffer,
1308 size_t count, loff_t * data)
1311 struct seq_file *m = file->private_data;
1312 struct acpi_video_bus *video = m->private;
1313 char str[12] = { 0 };
1317 if (!video || count + 1 > sizeof str)
1320 if (copy_from_user(str, buffer, count))
1324 opt = strtoul(str, NULL, 0);
1328 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1330 if (!ACPI_SUCCESS(status))
1336 static int acpi_video_bus_add_fs(struct acpi_device *device)
1338 struct acpi_video_bus *video = acpi_driver_data(device);
1339 struct proc_dir_entry *device_dir;
1340 struct proc_dir_entry *entry;
1342 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1346 device_dir->owner = THIS_MODULE;
1349 entry = proc_create_data("info", S_IRUGO, acpi_device_dir(device),
1350 &acpi_video_bus_info_fops,
1351 acpi_driver_data(device));
1353 goto err_remove_dir;
1356 entry = proc_create_data("ROM", S_IRUGO, acpi_device_dir(device),
1357 &acpi_video_bus_ROM_fops,
1358 acpi_driver_data(device));
1360 goto err_remove_info;
1362 /* 'POST_info' [R] */
1363 entry = proc_create_data("POST_info", S_IRUGO, acpi_device_dir(device),
1364 &acpi_video_bus_POST_info_fops,
1365 acpi_driver_data(device));
1367 goto err_remove_rom;
1370 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1371 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1372 acpi_device_dir(device),
1373 &acpi_video_bus_POST_fops,
1374 acpi_driver_data(device));
1376 goto err_remove_post_info;
1379 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1380 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1381 acpi_device_dir(device),
1382 &acpi_video_bus_DOS_fops,
1383 acpi_driver_data(device));
1385 goto err_remove_post;
1387 video->dir = acpi_device_dir(device) = device_dir;
1391 remove_proc_entry("POST", device_dir);
1392 err_remove_post_info:
1393 remove_proc_entry("POST_info", device_dir);
1395 remove_proc_entry("ROM", device_dir);
1397 remove_proc_entry("info", device_dir);
1399 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1403 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1405 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1408 remove_proc_entry("info", device_dir);
1409 remove_proc_entry("ROM", device_dir);
1410 remove_proc_entry("POST_info", device_dir);
1411 remove_proc_entry("POST", device_dir);
1412 remove_proc_entry("DOS", device_dir);
1413 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1414 acpi_device_dir(device) = NULL;
1420 /* --------------------------------------------------------------------------
1422 -------------------------------------------------------------------------- */
1424 /* device interface */
1425 static struct acpi_video_device_attrib*
1426 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1428 struct acpi_video_enumerated_device *ids;
1431 for (i = 0; i < video->attached_count; i++) {
1432 ids = &video->attached_array[i];
1433 if ((ids->value.int_val & 0xffff) == device_id)
1434 return &ids->value.attrib;
1441 acpi_video_bus_get_one_device(struct acpi_device *device,
1442 struct acpi_video_bus *video)
1444 unsigned long device_id;
1446 struct acpi_video_device *data;
1447 struct acpi_video_device_attrib* attribute;
1449 if (!device || !video)
1453 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1454 if (ACPI_SUCCESS(status)) {
1456 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1460 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1461 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1462 acpi_driver_data(device) = data;
1464 data->device_id = device_id;
1465 data->video = video;
1468 attribute = acpi_video_get_device_attr(video, device_id);
1470 if((attribute != NULL) && attribute->device_id_scheme) {
1471 switch (attribute->display_type) {
1472 case ACPI_VIDEO_DISPLAY_CRT:
1473 data->flags.crt = 1;
1475 case ACPI_VIDEO_DISPLAY_TV:
1476 data->flags.tvout = 1;
1478 case ACPI_VIDEO_DISPLAY_DVI:
1479 data->flags.dvi = 1;
1481 case ACPI_VIDEO_DISPLAY_LCD:
1482 data->flags.lcd = 1;
1485 data->flags.unknown = 1;
1488 if(attribute->bios_can_detect)
1489 data->flags.bios = 1;
1491 data->flags.unknown = 1;
1493 acpi_video_device_bind(video, data);
1494 acpi_video_device_find_cap(data);
1496 status = acpi_install_notify_handler(device->handle,
1498 acpi_video_device_notify,
1500 if (ACPI_FAILURE(status)) {
1501 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1502 "Error installing notify handler\n"));
1503 if(data->brightness)
1504 kfree(data->brightness->levels);
1505 kfree(data->brightness);
1510 mutex_lock(&video->device_list_lock);
1511 list_add_tail(&data->entry, &video->video_device_list);
1512 mutex_unlock(&video->device_list_lock);
1514 acpi_video_device_add_fs(device);
1524 * video : video bus device
1529 * Enumerate the video device list of the video bus,
1530 * bind the ids with the corresponding video devices
1531 * under the video bus.
1534 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1536 struct acpi_video_device *dev;
1538 mutex_lock(&video->device_list_lock);
1540 list_for_each_entry(dev, &video->video_device_list, entry)
1541 acpi_video_device_bind(video, dev);
1543 mutex_unlock(&video->device_list_lock);
1548 * video : video bus device
1549 * device : video output device under the video
1555 * Bind the ids with the corresponding video devices
1556 * under the video bus.
1560 acpi_video_device_bind(struct acpi_video_bus *video,
1561 struct acpi_video_device *device)
1563 struct acpi_video_enumerated_device *ids;
1566 for (i = 0; i < video->attached_count; i++) {
1567 ids = &video->attached_array[i];
1568 if (device->device_id == (ids->value.int_val & 0xffff)) {
1569 ids->bind_info = device;
1570 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1577 * video : video bus device
1582 * Call _DOD to enumerate all devices attached to display adapter
1586 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1591 struct acpi_video_enumerated_device *active_list;
1592 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1593 union acpi_object *dod = NULL;
1594 union acpi_object *obj;
1596 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1597 if (!ACPI_SUCCESS(status)) {
1598 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1602 dod = buffer.pointer;
1603 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1604 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1609 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1610 dod->package.count));
1612 active_list = kcalloc(1 + dod->package.count,
1613 sizeof(struct acpi_video_enumerated_device),
1621 for (i = 0; i < dod->package.count; i++) {
1622 obj = &dod->package.elements[i];
1624 if (obj->type != ACPI_TYPE_INTEGER) {
1625 printk(KERN_ERR PREFIX
1626 "Invalid _DOD data in element %d\n", i);
1630 active_list[count].value.int_val = obj->integer.value;
1631 active_list[count].bind_info = NULL;
1632 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1633 (int)obj->integer.value));
1637 kfree(video->attached_array);
1639 video->attached_array = active_list;
1640 video->attached_count = count;
1643 kfree(buffer.pointer);
1648 acpi_video_get_next_level(struct acpi_video_device *device,
1649 u32 level_current, u32 event)
1651 int min, max, min_above, max_below, i, l, delta = 255;
1652 max = max_below = 0;
1653 min = min_above = 255;
1654 /* Find closest level to level_current */
1655 for (i = 0; i < device->brightness->count; i++) {
1656 l = device->brightness->levels[i];
1657 if (abs(l - level_current) < abs(delta)) {
1658 delta = l - level_current;
1663 /* Ajust level_current to closest available level */
1664 level_current += delta;
1665 for (i = 0; i < device->brightness->count; i++) {
1666 l = device->brightness->levels[i];
1671 if (l < min_above && l > level_current)
1673 if (l > max_below && l < level_current)
1678 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1679 return (level_current < max) ? min_above : min;
1680 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1681 return (level_current < max) ? min_above : max;
1682 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1683 return (level_current > min) ? max_below : min;
1684 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1685 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1688 return level_current;
1693 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1695 unsigned long level_current, level_next;
1696 acpi_video_device_lcd_get_level_current(device, &level_current);
1697 level_next = acpi_video_get_next_level(device, level_current, event);
1698 acpi_video_device_lcd_set_level(device, level_next);
1702 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1703 struct acpi_device *device)
1706 struct acpi_device *dev;
1708 acpi_video_device_enumerate(video);
1710 list_for_each_entry(dev, &device->children, node) {
1712 status = acpi_video_bus_get_one_device(dev, video);
1713 if (ACPI_FAILURE(status)) {
1714 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1721 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1724 struct acpi_video_bus *video;
1727 if (!device || !device->video)
1730 video = device->video;
1732 acpi_video_device_remove_fs(device->dev);
1734 status = acpi_remove_notify_handler(device->dev->handle,
1736 acpi_video_device_notify);
1737 backlight_device_unregister(device->backlight);
1739 sysfs_remove_link(&device->dev->dev.kobj,
1741 sysfs_remove_link(&device->cdev->device.kobj,
1743 thermal_cooling_device_unregister(device->cdev);
1744 device->cdev = NULL;
1746 video_output_unregister(device->output_dev);
1751 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1754 struct acpi_video_device *dev, *next;
1756 mutex_lock(&video->device_list_lock);
1758 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1760 status = acpi_video_bus_put_one_device(dev);
1761 if (ACPI_FAILURE(status))
1762 printk(KERN_WARNING PREFIX
1763 "hhuuhhuu bug in acpi video driver.\n");
1765 if (dev->brightness) {
1766 kfree(dev->brightness->levels);
1767 kfree(dev->brightness);
1769 list_del(&dev->entry);
1773 mutex_unlock(&video->device_list_lock);
1778 /* acpi_video interface */
1780 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1782 return acpi_video_bus_DOS(video, 0, 0);
1785 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1787 return acpi_video_bus_DOS(video, 0, 1);
1790 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1792 struct acpi_video_bus *video = data;
1793 struct acpi_device *device = NULL;
1794 struct input_dev *input;
1800 device = video->device;
1801 input = video->input;
1804 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1805 * most likely via hotkey. */
1806 acpi_bus_generate_proc_event(device, event, 0);
1807 keycode = KEY_SWITCHVIDEOMODE;
1810 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1812 acpi_video_device_enumerate(video);
1813 acpi_video_device_rebind(video);
1814 acpi_bus_generate_proc_event(device, event, 0);
1815 keycode = KEY_SWITCHVIDEOMODE;
1818 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1819 acpi_bus_generate_proc_event(device, event, 0);
1820 keycode = KEY_SWITCHVIDEOMODE;
1822 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1823 acpi_bus_generate_proc_event(device, event, 0);
1824 keycode = KEY_VIDEO_NEXT;
1826 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1827 acpi_bus_generate_proc_event(device, event, 0);
1828 keycode = KEY_VIDEO_PREV;
1832 keycode = KEY_UNKNOWN;
1833 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1834 "Unsupported event [0x%x]\n", event));
1838 acpi_notifier_call_chain(device, event, 0);
1839 input_report_key(input, keycode, 1);
1841 input_report_key(input, keycode, 0);
1847 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1849 struct acpi_video_device *video_device = data;
1850 struct acpi_device *device = NULL;
1851 struct acpi_video_bus *bus;
1852 struct input_dev *input;
1858 device = video_device->dev;
1859 bus = video_device->video;
1863 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1864 if (brightness_switch_enabled)
1865 acpi_video_switch_brightness(video_device, event);
1866 acpi_bus_generate_proc_event(device, event, 0);
1867 keycode = KEY_BRIGHTNESS_CYCLE;
1869 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1870 if (brightness_switch_enabled)
1871 acpi_video_switch_brightness(video_device, event);
1872 acpi_bus_generate_proc_event(device, event, 0);
1873 keycode = KEY_BRIGHTNESSUP;
1875 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1876 if (brightness_switch_enabled)
1877 acpi_video_switch_brightness(video_device, event);
1878 acpi_bus_generate_proc_event(device, event, 0);
1879 keycode = KEY_BRIGHTNESSDOWN;
1881 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1882 if (brightness_switch_enabled)
1883 acpi_video_switch_brightness(video_device, event);
1884 acpi_bus_generate_proc_event(device, event, 0);
1885 keycode = KEY_BRIGHTNESS_ZERO;
1887 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1888 if (brightness_switch_enabled)
1889 acpi_video_switch_brightness(video_device, event);
1890 acpi_bus_generate_proc_event(device, event, 0);
1891 keycode = KEY_DISPLAY_OFF;
1894 keycode = KEY_UNKNOWN;
1895 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1896 "Unsupported event [0x%x]\n", event));
1900 acpi_notifier_call_chain(device, event, 0);
1901 input_report_key(input, keycode, 1);
1903 input_report_key(input, keycode, 0);
1909 static int instance;
1910 static int acpi_video_resume(struct acpi_device *device)
1912 struct acpi_video_bus *video;
1913 struct acpi_video_device *video_device;
1916 if (!device || !acpi_driver_data(device))
1919 video = acpi_driver_data(device);
1921 for (i = 0; i < video->attached_count; i++) {
1922 video_device = video->attached_array[i].bind_info;
1923 if (video_device && video_device->backlight)
1924 acpi_video_set_brightness(video_device->backlight);
1929 static int acpi_video_bus_add(struct acpi_device *device)
1932 struct acpi_video_bus *video;
1933 struct input_dev *input;
1936 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1940 /* a hack to fix the duplicate name "VID" problem on T61 */
1941 if (!strcmp(device->pnp.bus_id, "VID")) {
1943 device->pnp.bus_id[3] = '0' + instance;
1947 video->device = device;
1948 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1949 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1950 acpi_driver_data(device) = video;
1952 acpi_video_bus_find_cap(video);
1953 error = acpi_video_bus_check(video);
1955 goto err_free_video;
1957 error = acpi_video_bus_add_fs(device);
1959 goto err_free_video;
1961 mutex_init(&video->device_list_lock);
1962 INIT_LIST_HEAD(&video->video_device_list);
1964 acpi_video_bus_get_devices(video, device);
1965 acpi_video_bus_start_devices(video);
1967 status = acpi_install_notify_handler(device->handle,
1969 acpi_video_bus_notify, video);
1970 if (ACPI_FAILURE(status)) {
1971 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1972 "Error installing notify handler\n"));
1974 goto err_stop_video;
1977 video->input = input = input_allocate_device();
1980 goto err_uninstall_notify;
1983 snprintf(video->phys, sizeof(video->phys),
1984 "%s/video/input0", acpi_device_hid(video->device));
1986 input->name = acpi_device_name(video->device);
1987 input->phys = video->phys;
1988 input->id.bustype = BUS_HOST;
1989 input->id.product = 0x06;
1990 input->dev.parent = &device->dev;
1991 input->evbit[0] = BIT(EV_KEY);
1992 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1993 set_bit(KEY_VIDEO_NEXT, input->keybit);
1994 set_bit(KEY_VIDEO_PREV, input->keybit);
1995 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1996 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1997 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1998 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1999 set_bit(KEY_DISPLAY_OFF, input->keybit);
2000 set_bit(KEY_UNKNOWN, input->keybit);
2002 error = input_register_device(input);
2004 goto err_free_input_dev;
2006 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2007 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2008 video->flags.multihead ? "yes" : "no",
2009 video->flags.rom ? "yes" : "no",
2010 video->flags.post ? "yes" : "no");
2015 input_free_device(input);
2016 err_uninstall_notify:
2017 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2018 acpi_video_bus_notify);
2020 acpi_video_bus_stop_devices(video);
2021 acpi_video_bus_put_devices(video);
2022 kfree(video->attached_array);
2023 acpi_video_bus_remove_fs(device);
2026 acpi_driver_data(device) = NULL;
2031 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2033 acpi_status status = 0;
2034 struct acpi_video_bus *video = NULL;
2037 if (!device || !acpi_driver_data(device))
2040 video = acpi_driver_data(device);
2042 acpi_video_bus_stop_devices(video);
2044 status = acpi_remove_notify_handler(video->device->handle,
2046 acpi_video_bus_notify);
2048 acpi_video_bus_put_devices(video);
2049 acpi_video_bus_remove_fs(device);
2051 input_unregister_device(video->input);
2052 kfree(video->attached_array);
2058 static int __init acpi_video_init(void)
2064 acpi_dbg_level = 0xFFFFFFFF;
2065 acpi_dbg_layer = 0x08000000;
2068 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2069 if (!acpi_video_dir)
2071 acpi_video_dir->owner = THIS_MODULE;
2073 result = acpi_bus_register_driver(&acpi_video_bus);
2075 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2082 static void __exit acpi_video_exit(void)
2085 acpi_bus_unregister_driver(&acpi_video_bus);
2087 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2092 module_init(acpi_video_init);
2093 module_exit(acpi_video_exit);