2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/list.h>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/thermal.h>
38 #include <linux/video_output.h>
39 #include <linux/sort.h>
40 #include <asm/uaccess.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device *device);
78 static int acpi_video_bus_remove(struct acpi_device *device, int type);
79 static int acpi_video_resume(struct acpi_device *device);
81 static const struct acpi_device_id video_device_ids[] = {
85 MODULE_DEVICE_TABLE(acpi, video_device_ids);
87 static struct acpi_driver acpi_video_bus = {
89 .class = ACPI_VIDEO_CLASS,
90 .ids = video_device_ids,
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
94 .resume = acpi_video_resume,
98 struct acpi_video_bus_flags {
99 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
105 struct acpi_video_bus_cap {
106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
115 struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment:4; /*This field differentiates the display type */
118 u32 display_type:4; /*Describe the specific type in use */
119 u32 vendor_specific:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device {
131 struct acpi_video_device_attrib attrib;
133 struct acpi_video_device *bind_info;
136 struct acpi_video_bus {
137 struct acpi_device *device;
139 struct acpi_video_enumerated_device *attached_array;
141 struct acpi_video_bus_cap cap;
142 struct acpi_video_bus_flags flags;
143 struct list_head video_device_list;
144 struct mutex device_list_lock; /* protects video_device_list */
145 struct proc_dir_entry *dir;
146 struct input_dev *input;
147 char phys[32]; /* for input device */
150 struct acpi_video_device_flags {
160 struct acpi_video_device_cap {
161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
164 u8 _BQC:1; /* Get current brightness level */
165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
171 struct acpi_video_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 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 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 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)
339 unsigned long long state;
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);
373 unsigned long long level;
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 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 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 };
439 unsigned long long ret;
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 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)
552 unsigned long long tmp;
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 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 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);
630 * Simple comparison function used to sort backlight levels.
634 acpi_video_cmp_level(const void *a, const void *b)
636 return *(int *)a - *(int *)b;
641 * device : video output device (LCD, CRT, ..)
644 * Maximum brightness level
646 * Allocate and initialize device->brightness.
650 acpi_video_init_brightness(struct acpi_video_device *device)
652 union acpi_object *obj = NULL;
653 int i, max_level = 0, count = 0;
654 union acpi_object *o;
655 struct acpi_video_device_brightness *br = NULL;
657 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
658 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
659 "LCD brightness level\n"));
663 if (obj->package.count < 2)
666 br = kzalloc(sizeof(*br), GFP_KERNEL);
668 printk(KERN_ERR "can't allocate memory\n");
672 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
677 for (i = 0; i < obj->package.count; i++) {
678 o = (union acpi_object *)&obj->package.elements[i];
679 if (o->type != ACPI_TYPE_INTEGER) {
680 printk(KERN_ERR PREFIX "Invalid data\n");
683 br->levels[count] = (u32) o->integer.value;
685 if (br->levels[count] > max_level)
686 max_level = br->levels[count];
690 /* don't sort the first two brightness levels */
691 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
692 acpi_video_cmp_level, NULL);
695 goto out_free_levels;
698 device->brightness = br;
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
708 device->brightness = NULL;
715 * device : video output device (LCD, CRT, ..)
720 * Find out all required AML methods defined under the output
724 static void acpi_video_device_find_cap(struct acpi_video_device *device)
726 acpi_handle h_dummy1;
730 memset(&device->cap, 0, sizeof(device->cap));
732 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
733 device->cap._ADR = 1;
735 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
736 device->cap._BCL = 1;
738 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
739 device->cap._BCM = 1;
741 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
742 device->cap._BQC = 1;
743 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
744 device->cap._DDC = 1;
746 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
747 device->cap._DCS = 1;
749 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
750 device->cap._DGS = 1;
752 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
753 device->cap._DSS = 1;
756 if (acpi_video_backlight_support())
757 max_level = acpi_video_init_brightness(device);
759 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
761 static int count = 0;
763 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
767 sprintf(name, "acpi_video%d", count++);
768 device->backlight = backlight_device_register(name,
769 NULL, device, &acpi_backlight_ops);
770 device->backlight->props.max_brightness = device->brightness->count-3;
772 * If there exists the _BQC object, the _BQC object will be
773 * called to get the current backlight brightness. Otherwise
774 * the brightness will be set to the maximum.
776 if (device->cap._BQC)
777 device->backlight->props.brightness =
778 acpi_video_get_brightness(device->backlight);
780 device->backlight->props.brightness =
781 device->backlight->props.max_brightness;
782 backlight_update_status(device->backlight);
785 device->cdev = thermal_cooling_device_register("LCD",
786 device->dev, &video_cooling_ops);
787 if (IS_ERR(device->cdev))
790 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
792 result = sysfs_create_link(&device->dev->dev.kobj,
793 &device->cdev->device.kobj,
796 printk(KERN_ERR PREFIX "Create sysfs link\n");
797 result = sysfs_create_link(&device->cdev->device.kobj,
798 &device->dev->dev.kobj, "device");
800 printk(KERN_ERR PREFIX "Create sysfs link\n");
804 if (acpi_video_display_switch_support()) {
806 if (device->cap._DCS && device->cap._DSS) {
809 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
812 sprintf(name, "acpi_video%d", count++);
813 device->output_dev = video_output_register(name,
814 NULL, device, &acpi_output_properties);
822 * device : video output device (VGA)
827 * Find out all required AML methods defined under the video bus device.
830 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
832 acpi_handle h_dummy1;
834 memset(&video->cap, 0, sizeof(video->cap));
835 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
838 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
841 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
844 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
847 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
850 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
856 * Check whether the video bus device has required AML method to
857 * support the desired features
860 static int acpi_video_bus_check(struct acpi_video_bus *video)
862 acpi_status status = -ENOENT;
868 dev = acpi_get_physical_pci_device(video->device->handle);
873 /* Since there is no HID, CID and so on for VGA driver, we have
874 * to check well known required nodes.
877 /* Does this device support video switching? */
878 if (video->cap._DOS) {
879 video->flags.multihead = 1;
883 /* Does this device support retrieving a video ROM? */
884 if (video->cap._ROM) {
885 video->flags.rom = 1;
889 /* Does this device support configuring which video device to POST? */
890 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
891 video->flags.post = 1;
898 /* --------------------------------------------------------------------------
900 -------------------------------------------------------------------------- */
902 static struct proc_dir_entry *acpi_video_dir;
906 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
908 struct acpi_video_device *dev = seq->private;
914 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
915 seq_printf(seq, "type: ");
917 seq_printf(seq, "CRT\n");
918 else if (dev->flags.lcd)
919 seq_printf(seq, "LCD\n");
920 else if (dev->flags.tvout)
921 seq_printf(seq, "TVOUT\n");
922 else if (dev->flags.dvi)
923 seq_printf(seq, "DVI\n");
925 seq_printf(seq, "UNKNOWN\n");
927 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
934 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
936 return single_open(file, acpi_video_device_info_seq_show,
940 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
943 struct acpi_video_device *dev = seq->private;
944 unsigned long long state;
950 status = acpi_video_device_get_state(dev, &state);
951 seq_printf(seq, "state: ");
952 if (ACPI_SUCCESS(status))
953 seq_printf(seq, "0x%02llx\n", state);
955 seq_printf(seq, "<not supported>\n");
957 status = acpi_video_device_query(dev, &state);
958 seq_printf(seq, "query: ");
959 if (ACPI_SUCCESS(status))
960 seq_printf(seq, "0x%02llx\n", state);
962 seq_printf(seq, "<not supported>\n");
969 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
971 return single_open(file, acpi_video_device_state_seq_show,
976 acpi_video_device_write_state(struct file *file,
977 const char __user * buffer,
978 size_t count, loff_t * data)
981 struct seq_file *m = file->private_data;
982 struct acpi_video_device *dev = m->private;
983 char str[12] = { 0 };
987 if (!dev || count + 1 > sizeof str)
990 if (copy_from_user(str, buffer, count))
994 state = simple_strtoul(str, NULL, 0);
995 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
997 status = acpi_video_device_set_state(dev, state);
1006 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1008 struct acpi_video_device *dev = seq->private;
1012 if (!dev || !dev->brightness) {
1013 seq_printf(seq, "<not supported>\n");
1017 seq_printf(seq, "levels: ");
1018 for (i = 0; i < dev->brightness->count; i++)
1019 seq_printf(seq, " %d", dev->brightness->levels[i]);
1020 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1026 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1028 return single_open(file, acpi_video_device_brightness_seq_show,
1033 acpi_video_device_write_brightness(struct file *file,
1034 const char __user * buffer,
1035 size_t count, loff_t * data)
1037 struct seq_file *m = file->private_data;
1038 struct acpi_video_device *dev = m->private;
1039 char str[5] = { 0 };
1040 unsigned int level = 0;
1044 if (!dev || !dev->brightness || count + 1 > sizeof str)
1047 if (copy_from_user(str, buffer, count))
1051 level = simple_strtoul(str, NULL, 0);
1056 /* validate through the list of available levels */
1057 for (i = 0; i < dev->brightness->count; i++)
1058 if (level == dev->brightness->levels[i]) {
1060 (acpi_video_device_lcd_set_level(dev, level)))
1061 dev->brightness->curr = level;
1068 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1070 struct acpi_video_device *dev = seq->private;
1073 union acpi_object *edid = NULL;
1079 status = acpi_video_device_EDID(dev, &edid, 128);
1080 if (ACPI_FAILURE(status)) {
1081 status = acpi_video_device_EDID(dev, &edid, 256);
1084 if (ACPI_FAILURE(status)) {
1088 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1089 for (i = 0; i < edid->buffer.length; i++)
1090 seq_putc(seq, edid->buffer.pointer[i]);
1095 seq_printf(seq, "<not supported>\n");
1103 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1105 return single_open(file, acpi_video_device_EDID_seq_show,
1109 static int acpi_video_device_add_fs(struct acpi_device *device)
1111 struct proc_dir_entry *entry, *device_dir;
1112 struct acpi_video_device *vid_dev;
1114 vid_dev = acpi_driver_data(device);
1118 device_dir = proc_mkdir(acpi_device_bid(device),
1119 vid_dev->video->dir);
1123 device_dir->owner = THIS_MODULE;
1126 entry = proc_create_data("info", S_IRUGO, device_dir,
1127 &acpi_video_device_info_fops, acpi_driver_data(device));
1129 goto err_remove_dir;
1132 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1133 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1135 &acpi_video_device_state_fops,
1136 acpi_driver_data(device));
1138 goto err_remove_info;
1140 /* 'brightness' [R/W] */
1141 acpi_video_device_brightness_fops.write =
1142 acpi_video_device_write_brightness;
1143 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1145 &acpi_video_device_brightness_fops,
1146 acpi_driver_data(device));
1148 goto err_remove_state;
1151 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1152 &acpi_video_device_EDID_fops,
1153 acpi_driver_data(device));
1155 goto err_remove_brightness;
1157 acpi_device_dir(device) = device_dir;
1161 err_remove_brightness:
1162 remove_proc_entry("brightness", device_dir);
1164 remove_proc_entry("state", device_dir);
1166 remove_proc_entry("info", device_dir);
1168 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1172 static int acpi_video_device_remove_fs(struct acpi_device *device)
1174 struct acpi_video_device *vid_dev;
1175 struct proc_dir_entry *device_dir;
1177 vid_dev = acpi_driver_data(device);
1178 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1181 device_dir = acpi_device_dir(device);
1183 remove_proc_entry("info", device_dir);
1184 remove_proc_entry("state", device_dir);
1185 remove_proc_entry("brightness", device_dir);
1186 remove_proc_entry("EDID", device_dir);
1187 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1188 acpi_device_dir(device) = NULL;
1195 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1197 struct acpi_video_bus *video = seq->private;
1203 seq_printf(seq, "Switching heads: %s\n",
1204 video->flags.multihead ? "yes" : "no");
1205 seq_printf(seq, "Video ROM: %s\n",
1206 video->flags.rom ? "yes" : "no");
1207 seq_printf(seq, "Device to be POSTed on boot: %s\n",
1208 video->flags.post ? "yes" : "no");
1214 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1216 return single_open(file, acpi_video_bus_info_seq_show,
1220 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1222 struct acpi_video_bus *video = seq->private;
1228 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1229 seq_printf(seq, "<TODO>\n");
1235 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1237 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1240 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1242 struct acpi_video_bus *video = seq->private;
1243 unsigned long long options;
1250 status = acpi_video_bus_POST_options(video, &options);
1251 if (ACPI_SUCCESS(status)) {
1252 if (!(options & 1)) {
1253 printk(KERN_WARNING PREFIX
1254 "The motherboard VGA device is not listed as a possible POST device.\n");
1255 printk(KERN_WARNING PREFIX
1256 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1258 printk("%llx\n", options);
1259 seq_printf(seq, "can POST: <integrated video>");
1261 seq_printf(seq, " <PCI video>");
1263 seq_printf(seq, " <AGP video>");
1264 seq_putc(seq, '\n');
1266 seq_printf(seq, "<not supported>\n");
1272 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1274 return single_open(file, acpi_video_bus_POST_info_seq_show,
1278 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1280 struct acpi_video_bus *video = seq->private;
1282 unsigned long long id;
1288 status = acpi_video_bus_get_POST(video, &id);
1289 if (!ACPI_SUCCESS(status)) {
1290 seq_printf(seq, "<not supported>\n");
1293 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1299 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1301 struct acpi_video_bus *video = seq->private;
1304 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1309 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1311 return single_open(file, acpi_video_bus_POST_seq_show,
1315 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1317 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1321 acpi_video_bus_write_POST(struct file *file,
1322 const char __user * buffer,
1323 size_t count, loff_t * data)
1326 struct seq_file *m = file->private_data;
1327 struct acpi_video_bus *video = m->private;
1328 char str[12] = { 0 };
1329 unsigned long long opt, options;
1332 if (!video || count + 1 > sizeof str)
1335 status = acpi_video_bus_POST_options(video, &options);
1336 if (!ACPI_SUCCESS(status))
1339 if (copy_from_user(str, buffer, count))
1343 opt = strtoul(str, NULL, 0);
1347 /* just in case an OEM 'forgot' the motherboard... */
1350 if (options & (1ul << opt)) {
1351 status = acpi_video_bus_set_POST(video, opt);
1352 if (!ACPI_SUCCESS(status))
1361 acpi_video_bus_write_DOS(struct file *file,
1362 const char __user * buffer,
1363 size_t count, loff_t * data)
1366 struct seq_file *m = file->private_data;
1367 struct acpi_video_bus *video = m->private;
1368 char str[12] = { 0 };
1372 if (!video || count + 1 > sizeof str)
1375 if (copy_from_user(str, buffer, count))
1379 opt = strtoul(str, NULL, 0);
1383 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1385 if (!ACPI_SUCCESS(status))
1391 static int acpi_video_bus_add_fs(struct acpi_device *device)
1393 struct acpi_video_bus *video = acpi_driver_data(device);
1394 struct proc_dir_entry *device_dir;
1395 struct proc_dir_entry *entry;
1397 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1401 device_dir->owner = THIS_MODULE;
1404 entry = proc_create_data("info", S_IRUGO, device_dir,
1405 &acpi_video_bus_info_fops,
1406 acpi_driver_data(device));
1408 goto err_remove_dir;
1411 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1412 &acpi_video_bus_ROM_fops,
1413 acpi_driver_data(device));
1415 goto err_remove_info;
1417 /* 'POST_info' [R] */
1418 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1419 &acpi_video_bus_POST_info_fops,
1420 acpi_driver_data(device));
1422 goto err_remove_rom;
1425 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1426 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1428 &acpi_video_bus_POST_fops,
1429 acpi_driver_data(device));
1431 goto err_remove_post_info;
1434 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1435 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1437 &acpi_video_bus_DOS_fops,
1438 acpi_driver_data(device));
1440 goto err_remove_post;
1442 video->dir = acpi_device_dir(device) = device_dir;
1446 remove_proc_entry("POST", device_dir);
1447 err_remove_post_info:
1448 remove_proc_entry("POST_info", device_dir);
1450 remove_proc_entry("ROM", device_dir);
1452 remove_proc_entry("info", device_dir);
1454 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1458 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1460 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1463 remove_proc_entry("info", device_dir);
1464 remove_proc_entry("ROM", device_dir);
1465 remove_proc_entry("POST_info", device_dir);
1466 remove_proc_entry("POST", device_dir);
1467 remove_proc_entry("DOS", device_dir);
1468 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1469 acpi_device_dir(device) = NULL;
1475 /* --------------------------------------------------------------------------
1477 -------------------------------------------------------------------------- */
1479 /* device interface */
1480 static struct acpi_video_device_attrib*
1481 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1483 struct acpi_video_enumerated_device *ids;
1486 for (i = 0; i < video->attached_count; i++) {
1487 ids = &video->attached_array[i];
1488 if ((ids->value.int_val & 0xffff) == device_id)
1489 return &ids->value.attrib;
1496 acpi_video_bus_get_one_device(struct acpi_device *device,
1497 struct acpi_video_bus *video)
1499 unsigned long long device_id;
1501 struct acpi_video_device *data;
1502 struct acpi_video_device_attrib* attribute;
1504 if (!device || !video)
1508 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1509 if (ACPI_SUCCESS(status)) {
1511 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1515 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1516 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1517 device->driver_data = data;
1519 data->device_id = device_id;
1520 data->video = video;
1523 attribute = acpi_video_get_device_attr(video, device_id);
1525 if((attribute != NULL) && attribute->device_id_scheme) {
1526 switch (attribute->display_type) {
1527 case ACPI_VIDEO_DISPLAY_CRT:
1528 data->flags.crt = 1;
1530 case ACPI_VIDEO_DISPLAY_TV:
1531 data->flags.tvout = 1;
1533 case ACPI_VIDEO_DISPLAY_DVI:
1534 data->flags.dvi = 1;
1536 case ACPI_VIDEO_DISPLAY_LCD:
1537 data->flags.lcd = 1;
1540 data->flags.unknown = 1;
1543 if(attribute->bios_can_detect)
1544 data->flags.bios = 1;
1546 data->flags.unknown = 1;
1548 acpi_video_device_bind(video, data);
1549 acpi_video_device_find_cap(data);
1551 status = acpi_install_notify_handler(device->handle,
1553 acpi_video_device_notify,
1555 if (ACPI_FAILURE(status)) {
1556 printk(KERN_ERR PREFIX
1557 "Error installing notify handler\n");
1558 if(data->brightness)
1559 kfree(data->brightness->levels);
1560 kfree(data->brightness);
1565 mutex_lock(&video->device_list_lock);
1566 list_add_tail(&data->entry, &video->video_device_list);
1567 mutex_unlock(&video->device_list_lock);
1569 acpi_video_device_add_fs(device);
1579 * video : video bus device
1584 * Enumerate the video device list of the video bus,
1585 * bind the ids with the corresponding video devices
1586 * under the video bus.
1589 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1591 struct acpi_video_device *dev;
1593 mutex_lock(&video->device_list_lock);
1595 list_for_each_entry(dev, &video->video_device_list, entry)
1596 acpi_video_device_bind(video, dev);
1598 mutex_unlock(&video->device_list_lock);
1603 * video : video bus device
1604 * device : video output device under the video
1610 * Bind the ids with the corresponding video devices
1611 * under the video bus.
1615 acpi_video_device_bind(struct acpi_video_bus *video,
1616 struct acpi_video_device *device)
1618 struct acpi_video_enumerated_device *ids;
1621 for (i = 0; i < video->attached_count; i++) {
1622 ids = &video->attached_array[i];
1623 if (device->device_id == (ids->value.int_val & 0xffff)) {
1624 ids->bind_info = device;
1625 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1632 * video : video bus device
1637 * Call _DOD to enumerate all devices attached to display adapter
1641 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1646 struct acpi_video_enumerated_device *active_list;
1647 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1648 union acpi_object *dod = NULL;
1649 union acpi_object *obj;
1651 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1652 if (!ACPI_SUCCESS(status)) {
1653 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1657 dod = buffer.pointer;
1658 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1659 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1664 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1665 dod->package.count));
1667 active_list = kcalloc(1 + dod->package.count,
1668 sizeof(struct acpi_video_enumerated_device),
1676 for (i = 0; i < dod->package.count; i++) {
1677 obj = &dod->package.elements[i];
1679 if (obj->type != ACPI_TYPE_INTEGER) {
1680 printk(KERN_ERR PREFIX
1681 "Invalid _DOD data in element %d\n", i);
1685 active_list[count].value.int_val = obj->integer.value;
1686 active_list[count].bind_info = NULL;
1687 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1688 (int)obj->integer.value));
1692 kfree(video->attached_array);
1694 video->attached_array = active_list;
1695 video->attached_count = count;
1698 kfree(buffer.pointer);
1703 acpi_video_get_next_level(struct acpi_video_device *device,
1704 u32 level_current, u32 event)
1706 int min, max, min_above, max_below, i, l, delta = 255;
1707 max = max_below = 0;
1708 min = min_above = 255;
1709 /* Find closest level to level_current */
1710 for (i = 0; i < device->brightness->count; i++) {
1711 l = device->brightness->levels[i];
1712 if (abs(l - level_current) < abs(delta)) {
1713 delta = l - level_current;
1718 /* Ajust level_current to closest available level */
1719 level_current += delta;
1720 for (i = 0; i < device->brightness->count; i++) {
1721 l = device->brightness->levels[i];
1726 if (l < min_above && l > level_current)
1728 if (l > max_below && l < level_current)
1733 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1734 return (level_current < max) ? min_above : min;
1735 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1736 return (level_current < max) ? min_above : max;
1737 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1738 return (level_current > min) ? max_below : min;
1739 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1740 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1743 return level_current;
1748 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1750 unsigned long long level_current, level_next;
1751 if (!device->brightness)
1753 acpi_video_device_lcd_get_level_current(device, &level_current);
1754 level_next = acpi_video_get_next_level(device, level_current, event);
1755 acpi_video_device_lcd_set_level(device, level_next);
1759 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1760 struct acpi_device *device)
1763 struct acpi_device *dev;
1765 acpi_video_device_enumerate(video);
1767 list_for_each_entry(dev, &device->children, node) {
1769 status = acpi_video_bus_get_one_device(dev, video);
1770 if (ACPI_FAILURE(status)) {
1771 printk(KERN_WARNING PREFIX
1772 "Cant attach device");
1779 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1782 struct acpi_video_bus *video;
1785 if (!device || !device->video)
1788 video = device->video;
1790 acpi_video_device_remove_fs(device->dev);
1792 status = acpi_remove_notify_handler(device->dev->handle,
1794 acpi_video_device_notify);
1795 backlight_device_unregister(device->backlight);
1797 sysfs_remove_link(&device->dev->dev.kobj,
1799 sysfs_remove_link(&device->cdev->device.kobj,
1801 thermal_cooling_device_unregister(device->cdev);
1802 device->cdev = NULL;
1804 video_output_unregister(device->output_dev);
1809 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1812 struct acpi_video_device *dev, *next;
1814 mutex_lock(&video->device_list_lock);
1816 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1818 status = acpi_video_bus_put_one_device(dev);
1819 if (ACPI_FAILURE(status))
1820 printk(KERN_WARNING PREFIX
1821 "hhuuhhuu bug in acpi video driver.\n");
1823 if (dev->brightness) {
1824 kfree(dev->brightness->levels);
1825 kfree(dev->brightness);
1827 list_del(&dev->entry);
1831 mutex_unlock(&video->device_list_lock);
1836 /* acpi_video interface */
1838 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1840 return acpi_video_bus_DOS(video, 0, 0);
1843 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1845 return acpi_video_bus_DOS(video, 0, 1);
1848 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1850 struct acpi_video_bus *video = data;
1851 struct acpi_device *device = NULL;
1852 struct input_dev *input;
1858 device = video->device;
1859 input = video->input;
1862 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1863 * most likely via hotkey. */
1864 acpi_bus_generate_proc_event(device, event, 0);
1865 keycode = KEY_SWITCHVIDEOMODE;
1868 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1870 acpi_video_device_enumerate(video);
1871 acpi_video_device_rebind(video);
1872 acpi_bus_generate_proc_event(device, event, 0);
1873 keycode = KEY_SWITCHVIDEOMODE;
1876 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
1877 acpi_bus_generate_proc_event(device, event, 0);
1878 keycode = KEY_SWITCHVIDEOMODE;
1880 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
1881 acpi_bus_generate_proc_event(device, event, 0);
1882 keycode = KEY_VIDEO_NEXT;
1884 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
1885 acpi_bus_generate_proc_event(device, event, 0);
1886 keycode = KEY_VIDEO_PREV;
1890 keycode = KEY_UNKNOWN;
1891 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1892 "Unsupported event [0x%x]\n", event));
1896 acpi_notifier_call_chain(device, event, 0);
1897 input_report_key(input, keycode, 1);
1899 input_report_key(input, keycode, 0);
1905 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1907 struct acpi_video_device *video_device = data;
1908 struct acpi_device *device = NULL;
1909 struct acpi_video_bus *bus;
1910 struct input_dev *input;
1916 device = video_device->dev;
1917 bus = video_device->video;
1921 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
1922 if (brightness_switch_enabled)
1923 acpi_video_switch_brightness(video_device, event);
1924 acpi_bus_generate_proc_event(device, event, 0);
1925 keycode = KEY_BRIGHTNESS_CYCLE;
1927 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
1928 if (brightness_switch_enabled)
1929 acpi_video_switch_brightness(video_device, event);
1930 acpi_bus_generate_proc_event(device, event, 0);
1931 keycode = KEY_BRIGHTNESSUP;
1933 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
1934 if (brightness_switch_enabled)
1935 acpi_video_switch_brightness(video_device, event);
1936 acpi_bus_generate_proc_event(device, event, 0);
1937 keycode = KEY_BRIGHTNESSDOWN;
1939 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1940 if (brightness_switch_enabled)
1941 acpi_video_switch_brightness(video_device, event);
1942 acpi_bus_generate_proc_event(device, event, 0);
1943 keycode = KEY_BRIGHTNESS_ZERO;
1945 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1946 if (brightness_switch_enabled)
1947 acpi_video_switch_brightness(video_device, event);
1948 acpi_bus_generate_proc_event(device, event, 0);
1949 keycode = KEY_DISPLAY_OFF;
1952 keycode = KEY_UNKNOWN;
1953 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1954 "Unsupported event [0x%x]\n", event));
1958 acpi_notifier_call_chain(device, event, 0);
1959 input_report_key(input, keycode, 1);
1961 input_report_key(input, keycode, 0);
1967 static int instance;
1968 static int acpi_video_resume(struct acpi_device *device)
1970 struct acpi_video_bus *video;
1971 struct acpi_video_device *video_device;
1974 if (!device || !acpi_driver_data(device))
1977 video = acpi_driver_data(device);
1979 for (i = 0; i < video->attached_count; i++) {
1980 video_device = video->attached_array[i].bind_info;
1981 if (video_device && video_device->backlight)
1982 acpi_video_set_brightness(video_device->backlight);
1987 static int acpi_video_bus_add(struct acpi_device *device)
1990 struct acpi_video_bus *video;
1991 struct input_dev *input;
1994 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1998 /* a hack to fix the duplicate name "VID" problem on T61 */
1999 if (!strcmp(device->pnp.bus_id, "VID")) {
2001 device->pnp.bus_id[3] = '0' + instance;
2005 video->device = device;
2006 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2007 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
2008 device->driver_data = video;
2010 acpi_video_bus_find_cap(video);
2011 error = acpi_video_bus_check(video);
2013 goto err_free_video;
2015 error = acpi_video_bus_add_fs(device);
2017 goto err_free_video;
2019 mutex_init(&video->device_list_lock);
2020 INIT_LIST_HEAD(&video->video_device_list);
2022 acpi_video_bus_get_devices(video, device);
2023 acpi_video_bus_start_devices(video);
2025 status = acpi_install_notify_handler(device->handle,
2027 acpi_video_bus_notify, video);
2028 if (ACPI_FAILURE(status)) {
2029 printk(KERN_ERR PREFIX
2030 "Error installing notify handler\n");
2032 goto err_stop_video;
2035 video->input = input = input_allocate_device();
2038 goto err_uninstall_notify;
2041 snprintf(video->phys, sizeof(video->phys),
2042 "%s/video/input0", acpi_device_hid(video->device));
2044 input->name = acpi_device_name(video->device);
2045 input->phys = video->phys;
2046 input->id.bustype = BUS_HOST;
2047 input->id.product = 0x06;
2048 input->dev.parent = &device->dev;
2049 input->evbit[0] = BIT(EV_KEY);
2050 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2051 set_bit(KEY_VIDEO_NEXT, input->keybit);
2052 set_bit(KEY_VIDEO_PREV, input->keybit);
2053 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2054 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2055 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2056 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2057 set_bit(KEY_DISPLAY_OFF, input->keybit);
2058 set_bit(KEY_UNKNOWN, input->keybit);
2060 error = input_register_device(input);
2062 goto err_free_input_dev;
2064 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
2065 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2066 video->flags.multihead ? "yes" : "no",
2067 video->flags.rom ? "yes" : "no",
2068 video->flags.post ? "yes" : "no");
2073 input_free_device(input);
2074 err_uninstall_notify:
2075 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2076 acpi_video_bus_notify);
2078 acpi_video_bus_stop_devices(video);
2079 acpi_video_bus_put_devices(video);
2080 kfree(video->attached_array);
2081 acpi_video_bus_remove_fs(device);
2084 device->driver_data = NULL;
2089 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2091 acpi_status status = 0;
2092 struct acpi_video_bus *video = NULL;
2095 if (!device || !acpi_driver_data(device))
2098 video = acpi_driver_data(device);
2100 acpi_video_bus_stop_devices(video);
2102 status = acpi_remove_notify_handler(video->device->handle,
2104 acpi_video_bus_notify);
2106 acpi_video_bus_put_devices(video);
2107 acpi_video_bus_remove_fs(device);
2109 input_unregister_device(video->input);
2110 kfree(video->attached_array);
2116 static int __init acpi_video_init(void)
2120 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2121 if (!acpi_video_dir)
2123 acpi_video_dir->owner = THIS_MODULE;
2125 result = acpi_bus_register_driver(&acpi_video_bus);
2127 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2134 static void __exit acpi_video_exit(void)
2137 acpi_bus_unregister_driver(&acpi_video_bus);
2139 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2144 module_init(acpi_video_init);
2145 module_exit(acpi_video_exit);