Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-backlight
[linux-2.6] / drivers / acpi / video.c
1 /*
2  *  video.c - ACPI Video Driver ($Revision:$)
3  *
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>
7  *
8  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9  *
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.
14  *
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.
19  *
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.
23  *
24  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25  */
26
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>
40
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
43
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
53
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
59
60 #define MAX_NAME_LEN    20
61
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
66
67 #define _COMPONENT              ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
69
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
73
74 static int brightness_switch_enabled = 1;
75 module_param(brightness_switch_enabled, bool, 0644);
76
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);
80
81 static const struct acpi_device_id video_device_ids[] = {
82         {ACPI_VIDEO_HID, 0},
83         {"", 0},
84 };
85 MODULE_DEVICE_TABLE(acpi, video_device_ids);
86
87 static struct acpi_driver acpi_video_bus = {
88         .name = "video",
89         .class = ACPI_VIDEO_CLASS,
90         .ids = video_device_ids,
91         .ops = {
92                 .add = acpi_video_bus_add,
93                 .remove = acpi_video_bus_remove,
94                 .resume = acpi_video_resume,
95                 },
96 };
97
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 */
102         u8 reserved:5;
103 };
104
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 */
112         u8 reserved:2;
113 };
114
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 
122                                    the VGA device. */
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 */
126 };
127
128 struct acpi_video_enumerated_device {
129         union {
130                 u32 int_val;
131                 struct acpi_video_device_attrib attrib;
132         } value;
133         struct acpi_video_device *bind_info;
134 };
135
136 struct acpi_video_bus {
137         struct acpi_device *device;
138         u8 dos_setting;
139         struct acpi_video_enumerated_device *attached_array;
140         u8 attached_count;
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 */
148 };
149
150 struct acpi_video_device_flags {
151         u8 crt:1;
152         u8 lcd:1;
153         u8 tvout:1;
154         u8 dvi:1;
155         u8 bios:1;
156         u8 unknown:1;
157         u8 reserved:2;
158 };
159
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 */
169 };
170
171 struct acpi_video_device_brightness {
172         int curr;
173         int count;
174         int *levels;
175 };
176
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;
188 };
189
190 /* bus */
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,
195         .read = seq_read,
196         .llseek = seq_lseek,
197         .release = single_release,
198 };
199
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,
204         .read = seq_read,
205         .llseek = seq_lseek,
206         .release = single_release,
207 };
208
209 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210                                             struct file *file);
211 static struct file_operations acpi_video_bus_POST_info_fops = {
212         .owner = THIS_MODULE,
213         .open = acpi_video_bus_POST_info_open_fs,
214         .read = seq_read,
215         .llseek = seq_lseek,
216         .release = single_release,
217 };
218
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,
223         .read = seq_read,
224         .llseek = seq_lseek,
225         .release = single_release,
226 };
227
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,
232         .read = seq_read,
233         .llseek = seq_lseek,
234         .release = single_release,
235 };
236
237 /* device */
238 static int acpi_video_device_info_open_fs(struct inode *inode,
239                                           struct file *file);
240 static struct file_operations acpi_video_device_info_fops = {
241         .owner = THIS_MODULE,
242         .open = acpi_video_device_info_open_fs,
243         .read = seq_read,
244         .llseek = seq_lseek,
245         .release = single_release,
246 };
247
248 static int acpi_video_device_state_open_fs(struct inode *inode,
249                                            struct file *file);
250 static struct file_operations acpi_video_device_state_fops = {
251         .owner = THIS_MODULE,
252         .open = acpi_video_device_state_open_fs,
253         .read = seq_read,
254         .llseek = seq_lseek,
255         .release = single_release,
256 };
257
258 static int acpi_video_device_brightness_open_fs(struct inode *inode,
259                                                 struct file *file);
260 static struct file_operations acpi_video_device_brightness_fops = {
261         .owner = THIS_MODULE,
262         .open = acpi_video_device_brightness_open_fs,
263         .read = seq_read,
264         .llseek = seq_lseek,
265         .release = single_release,
266 };
267
268 static int acpi_video_device_EDID_open_fs(struct inode *inode,
269                                           struct file *file);
270 static struct file_operations acpi_video_device_EDID_fops = {
271         .owner = THIS_MODULE,
272         .open = acpi_video_device_EDID_open_fs,
273         .read = seq_read,
274         .llseek = seq_lseek,
275         .release = single_release,
276 };
277
278 static char device_decode[][30] = {
279         "motherboard VGA device",
280         "PCI VGA device",
281         "AGP VGA device",
282         "UNKNOWN",
283 };
284
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,
291                         int level);
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,
298                                          int event);
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);
303
304 /*backlight device sysfs support*/
305 static int acpi_video_get_brightness(struct backlight_device *bd)
306 {
307         unsigned long cur_level;
308         int i;
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 */
316                         return i-2;
317         }
318         return 0;
319 }
320
321 static int acpi_video_set_brightness(struct backlight_device *bd)
322 {
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]);
328         return 0;
329 }
330
331 static struct backlight_ops acpi_backlight_ops = {
332         .get_brightness = acpi_video_get_brightness,
333         .update_status  = acpi_video_set_brightness,
334 };
335
336 /*video output device sysfs support*/
337 static int acpi_video_output_get(struct output_device *od)
338 {
339         unsigned 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);
343         return (int)state;
344 }
345
346 static int acpi_video_output_set(struct output_device *od)
347 {
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);
352 }
353
354 static struct output_properties acpi_output_properties = {
355         .set_state = acpi_video_output_set,
356         .get_status = acpi_video_output_get,
357 };
358
359
360 /* thermal cooling device callbacks */
361 static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
362 {
363         struct acpi_device *device = cdev->devdata;
364         struct acpi_video_device *video = acpi_driver_data(device);
365
366         return sprintf(buf, "%d\n", video->brightness->count - 3);
367 }
368
369 static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
370 {
371         struct acpi_device *device = cdev->devdata;
372         struct acpi_video_device *video = acpi_driver_data(device);
373         unsigned long level;
374         int state;
375
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);
381
382         return -EINVAL;
383 }
384
385 static int
386 video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
387 {
388         struct acpi_device *device = cdev->devdata;
389         struct acpi_video_device *video = acpi_driver_data(device);
390         int level;
391
392         if ( state >= video->brightness->count - 2)
393                 return -EINVAL;
394
395         state = video->brightness->count - state;
396         level = video->brightness->levels[state -1];
397         return acpi_video_device_lcd_set_level(video, level);
398 }
399
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,
404 };
405
406 /* --------------------------------------------------------------------------
407                                Video Management
408    -------------------------------------------------------------------------- */
409
410 /* device */
411
412 static int
413 acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
414 {
415         int status;
416
417         status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
418
419         return status;
420 }
421
422 static int
423 acpi_video_device_get_state(struct acpi_video_device *device,
424                             unsigned long *state)
425 {
426         int status;
427
428         status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
429
430         return status;
431 }
432
433 static int
434 acpi_video_device_set_state(struct acpi_video_device *device, int state)
435 {
436         int status;
437         union acpi_object arg0 = { ACPI_TYPE_INTEGER };
438         struct acpi_object_list args = { 1, &arg0 };
439         unsigned long ret;
440
441
442         arg0.integer.value = state;
443         status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
444
445         return status;
446 }
447
448 static int
449 acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
450                                    union acpi_object **levels)
451 {
452         int status;
453         struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
454         union acpi_object *obj;
455
456
457         *levels = NULL;
458
459         status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
460         if (!ACPI_SUCCESS(status))
461                 return 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");
465                 status = -EFAULT;
466                 goto err;
467         }
468
469         *levels = obj;
470
471         return 0;
472
473       err:
474         kfree(buffer.pointer);
475
476         return status;
477 }
478
479 static int
480 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
481 {
482         int status = AE_OK;
483         union acpi_object arg0 = { ACPI_TYPE_INTEGER };
484         struct acpi_object_list args = { 1, &arg0 };
485
486
487         arg0.integer.value = level;
488
489         if (device->cap._BCM)
490                 status = acpi_evaluate_object(device->dev->handle, "_BCM",
491                                               &args, NULL);
492         device->brightness->curr = level;
493         return status;
494 }
495
496 static int
497 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
498                                         unsigned long *level)
499 {
500         if (device->cap._BQC)
501                 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
502                                              level);
503         *level = device->brightness->curr;
504         return AE_OK;
505 }
506
507 static int
508 acpi_video_device_EDID(struct acpi_video_device *device,
509                        union acpi_object **edid, ssize_t length)
510 {
511         int status;
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 };
516
517
518         *edid = NULL;
519
520         if (!device)
521                 return -ENODEV;
522         if (length == 128)
523                 arg0.integer.value = 1;
524         else if (length == 256)
525                 arg0.integer.value = 2;
526         else
527                 return -EINVAL;
528
529         status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
530         if (ACPI_FAILURE(status))
531                 return -ENODEV;
532
533         obj = buffer.pointer;
534
535         if (obj && obj->type == ACPI_TYPE_BUFFER)
536                 *edid = obj;
537         else {
538                 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
539                 status = -EFAULT;
540                 kfree(obj);
541         }
542
543         return status;
544 }
545
546 /* bus */
547
548 static int
549 acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
550 {
551         int status;
552         unsigned long tmp;
553         union acpi_object arg0 = { ACPI_TYPE_INTEGER };
554         struct acpi_object_list args = { 1, &arg0 };
555
556
557         arg0.integer.value = option;
558
559         status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
560         if (ACPI_SUCCESS(status))
561                 status = tmp ? (-EINVAL) : (AE_OK);
562
563         return status;
564 }
565
566 static int
567 acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
568 {
569         int status;
570
571         status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
572
573         return status;
574 }
575
576 static int
577 acpi_video_bus_POST_options(struct acpi_video_bus *video,
578                             unsigned long *options)
579 {
580         int status;
581
582         status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
583         *options &= 3;
584
585         return status;
586 }
587
588 /*
589  *  Arg:
590  *      video           : video bus device pointer
591  *      bios_flag       : 
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
599  *                      event notify code.
600  *      lcd_flag        :
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.
605  * Return Value:
606  *              -1      wrong arg.
607  */
608
609 static int
610 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
611 {
612         acpi_integer status = 0;
613         union acpi_object arg0 = { ACPI_TYPE_INTEGER };
614         struct acpi_object_list args = { 1, &arg0 };
615
616
617         if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
618                 status = -1;
619                 goto Failed;
620         }
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);
624
625       Failed:
626         return status;
627 }
628
629 /*
630  *  Arg:        
631  *      device  : video output device (LCD, CRT, ..)
632  *
633  *  Return Value:
634  *      Maximum brightness level
635  *
636  *  Allocate and initialize device->brightness.
637  */
638
639 static int
640 acpi_video_init_brightness(struct acpi_video_device *device)
641 {
642         union acpi_object *obj = NULL;
643         int i, max_level = 0, count = 0;
644         union acpi_object *o;
645         struct acpi_video_device_brightness *br = NULL;
646
647         if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
648                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
649                                                 "LCD brightness level\n"));
650                 goto out;
651         }
652
653         if (obj->package.count < 2)
654                 goto out;
655
656         br = kzalloc(sizeof(*br), GFP_KERNEL);
657         if (!br) {
658                 printk(KERN_ERR "can't allocate memory\n");
659                 goto out;
660         }
661
662         br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
663                                 GFP_KERNEL);
664         if (!br->levels)
665                 goto out_free;
666
667         for (i = 0; i < obj->package.count; i++) {
668                 o = (union acpi_object *)&obj->package.elements[i];
669                 if (o->type != ACPI_TYPE_INTEGER) {
670                         printk(KERN_ERR PREFIX "Invalid data\n");
671                         continue;
672                 }
673                 br->levels[count] = (u32) o->integer.value;
674
675                 if (br->levels[count] > max_level)
676                         max_level = br->levels[count];
677                 count++;
678         }
679
680         if (count < 2)
681                 goto out_free_levels;
682
683         br->count = count;
684         device->brightness = br;
685         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
686         kfree(obj);
687         return max_level;
688
689 out_free_levels:
690         kfree(br->levels);
691 out_free:
692         kfree(br);
693 out:
694         device->brightness = NULL;
695         kfree(obj);
696         return 0;
697 }
698
699 /*
700  *  Arg:
701  *      device  : video output device (LCD, CRT, ..)
702  *
703  *  Return Value:
704  *      None
705  *
706  *  Find out all required AML methods defined under the output
707  *  device.
708  */
709
710 static void acpi_video_device_find_cap(struct acpi_video_device *device)
711 {
712         acpi_handle h_dummy1;
713         u32 max_level = 0;
714
715
716         memset(&device->cap, 0, sizeof(device->cap));
717
718         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
719                 device->cap._ADR = 1;
720         }
721         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
722                 device->cap._BCL = 1;
723         }
724         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
725                 device->cap._BCM = 1;
726         }
727         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
728                 device->cap._BQC = 1;
729         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
730                 device->cap._DDC = 1;
731         }
732         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
733                 device->cap._DCS = 1;
734         }
735         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
736                 device->cap._DGS = 1;
737         }
738         if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
739                 device->cap._DSS = 1;
740         }
741
742         max_level = acpi_video_init_brightness(device);
743
744         if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
745                 int result;
746                 static int count = 0;
747                 char *name;
748                 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
749                 if (!name)
750                         return;
751
752                 sprintf(name, "acpi_video%d", count++);
753                 device->backlight = backlight_device_register(name,
754                         NULL, device, &acpi_backlight_ops);
755                 device->backlight->props.max_brightness = device->brightness->count-3;
756                 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
757                 backlight_update_status(device->backlight);
758                 kfree(name);
759
760                 device->cdev = thermal_cooling_device_register("LCD",
761                                         device->dev, &video_cooling_ops);
762                 if (IS_ERR(device->cdev))
763                         return;
764
765                 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
766                          device->cdev->id);
767                 result = sysfs_create_link(&device->dev->dev.kobj,
768                                 &device->cdev->device.kobj,
769                                 "thermal_cooling");
770                 if (result)
771                         printk(KERN_ERR PREFIX "Create sysfs link\n");
772                 result = sysfs_create_link(&device->cdev->device.kobj,
773                                 &device->dev->dev.kobj, "device");
774                 if (result)
775                         printk(KERN_ERR PREFIX "Create sysfs link\n");
776
777         }
778         if (device->cap._DCS && device->cap._DSS){
779                 static int count = 0;
780                 char *name;
781                 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
782                 if (!name)
783                         return;
784                 sprintf(name, "acpi_video%d", count++);
785                 device->output_dev = video_output_register(name,
786                                 NULL, device, &acpi_output_properties);
787                 kfree(name);
788         }
789         return;
790 }
791
792 /*
793  *  Arg:        
794  *      device  : video output device (VGA)
795  *
796  *  Return Value:
797  *      None
798  *
799  *  Find out all required AML methods defined under the video bus device.
800  */
801
802 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
803 {
804         acpi_handle h_dummy1;
805
806         memset(&video->cap, 0, sizeof(video->cap));
807         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
808                 video->cap._DOS = 1;
809         }
810         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
811                 video->cap._DOD = 1;
812         }
813         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
814                 video->cap._ROM = 1;
815         }
816         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
817                 video->cap._GPD = 1;
818         }
819         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
820                 video->cap._SPD = 1;
821         }
822         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
823                 video->cap._VPO = 1;
824         }
825 }
826
827 /*
828  * Check whether the video bus device has required AML method to
829  * support the desired features
830  */
831
832 static int acpi_video_bus_check(struct acpi_video_bus *video)
833 {
834         acpi_status status = -ENOENT;
835
836
837         if (!video)
838                 return -EINVAL;
839
840         /* Since there is no HID, CID and so on for VGA driver, we have
841          * to check well known required nodes.
842          */
843
844         /* Does this device support video switching? */
845         if (video->cap._DOS) {
846                 video->flags.multihead = 1;
847                 status = 0;
848         }
849
850         /* Does this device support retrieving a video ROM? */
851         if (video->cap._ROM) {
852                 video->flags.rom = 1;
853                 status = 0;
854         }
855
856         /* Does this device support configuring which video device to POST? */
857         if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
858                 video->flags.post = 1;
859                 status = 0;
860         }
861
862         return status;
863 }
864
865 /* --------------------------------------------------------------------------
866                               FS Interface (/proc)
867    -------------------------------------------------------------------------- */
868
869 static struct proc_dir_entry *acpi_video_dir;
870
871 /* video devices */
872
873 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
874 {
875         struct acpi_video_device *dev = seq->private;
876
877
878         if (!dev)
879                 goto end;
880
881         seq_printf(seq, "device_id:    0x%04x\n", (u32) dev->device_id);
882         seq_printf(seq, "type:         ");
883         if (dev->flags.crt)
884                 seq_printf(seq, "CRT\n");
885         else if (dev->flags.lcd)
886                 seq_printf(seq, "LCD\n");
887         else if (dev->flags.tvout)
888                 seq_printf(seq, "TVOUT\n");
889         else if (dev->flags.dvi)
890                 seq_printf(seq, "DVI\n");
891         else
892                 seq_printf(seq, "UNKNOWN\n");
893
894         seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
895
896       end:
897         return 0;
898 }
899
900 static int
901 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
902 {
903         return single_open(file, acpi_video_device_info_seq_show,
904                            PDE(inode)->data);
905 }
906
907 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
908 {
909         int status;
910         struct acpi_video_device *dev = seq->private;
911         unsigned long state;
912
913
914         if (!dev)
915                 goto end;
916
917         status = acpi_video_device_get_state(dev, &state);
918         seq_printf(seq, "state:     ");
919         if (ACPI_SUCCESS(status))
920                 seq_printf(seq, "0x%02lx\n", state);
921         else
922                 seq_printf(seq, "<not supported>\n");
923
924         status = acpi_video_device_query(dev, &state);
925         seq_printf(seq, "query:     ");
926         if (ACPI_SUCCESS(status))
927                 seq_printf(seq, "0x%02lx\n", state);
928         else
929                 seq_printf(seq, "<not supported>\n");
930
931       end:
932         return 0;
933 }
934
935 static int
936 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
937 {
938         return single_open(file, acpi_video_device_state_seq_show,
939                            PDE(inode)->data);
940 }
941
942 static ssize_t
943 acpi_video_device_write_state(struct file *file,
944                               const char __user * buffer,
945                               size_t count, loff_t * data)
946 {
947         int status;
948         struct seq_file *m = file->private_data;
949         struct acpi_video_device *dev = m->private;
950         char str[12] = { 0 };
951         u32 state = 0;
952
953
954         if (!dev || count + 1 > sizeof str)
955                 return -EINVAL;
956
957         if (copy_from_user(str, buffer, count))
958                 return -EFAULT;
959
960         str[count] = 0;
961         state = simple_strtoul(str, NULL, 0);
962         state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
963
964         status = acpi_video_device_set_state(dev, state);
965
966         if (status)
967                 return -EFAULT;
968
969         return count;
970 }
971
972 static int
973 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
974 {
975         struct acpi_video_device *dev = seq->private;
976         int i;
977
978
979         if (!dev || !dev->brightness) {
980                 seq_printf(seq, "<not supported>\n");
981                 return 0;
982         }
983
984         seq_printf(seq, "levels: ");
985         for (i = 0; i < dev->brightness->count; i++)
986                 seq_printf(seq, " %d", dev->brightness->levels[i]);
987         seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
988
989         return 0;
990 }
991
992 static int
993 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
994 {
995         return single_open(file, acpi_video_device_brightness_seq_show,
996                            PDE(inode)->data);
997 }
998
999 static ssize_t
1000 acpi_video_device_write_brightness(struct file *file,
1001                                    const char __user * buffer,
1002                                    size_t count, loff_t * data)
1003 {
1004         struct seq_file *m = file->private_data;
1005         struct acpi_video_device *dev = m->private;
1006         char str[5] = { 0 };
1007         unsigned int level = 0;
1008         int i;
1009
1010
1011         if (!dev || !dev->brightness || count + 1 > sizeof str)
1012                 return -EINVAL;
1013
1014         if (copy_from_user(str, buffer, count))
1015                 return -EFAULT;
1016
1017         str[count] = 0;
1018         level = simple_strtoul(str, NULL, 0);
1019
1020         if (level > 100)
1021                 return -EFAULT;
1022
1023         /* validate through the list of available levels */
1024         for (i = 0; i < dev->brightness->count; i++)
1025                 if (level == dev->brightness->levels[i]) {
1026                         if (ACPI_SUCCESS
1027                             (acpi_video_device_lcd_set_level(dev, level)))
1028                                 dev->brightness->curr = level;
1029                         break;
1030                 }
1031
1032         return count;
1033 }
1034
1035 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1036 {
1037         struct acpi_video_device *dev = seq->private;
1038         int status;
1039         int i;
1040         union acpi_object *edid = NULL;
1041
1042
1043         if (!dev)
1044                 goto out;
1045
1046         status = acpi_video_device_EDID(dev, &edid, 128);
1047         if (ACPI_FAILURE(status)) {
1048                 status = acpi_video_device_EDID(dev, &edid, 256);
1049         }
1050
1051         if (ACPI_FAILURE(status)) {
1052                 goto out;
1053         }
1054
1055         if (edid && edid->type == ACPI_TYPE_BUFFER) {
1056                 for (i = 0; i < edid->buffer.length; i++)
1057                         seq_putc(seq, edid->buffer.pointer[i]);
1058         }
1059
1060       out:
1061         if (!edid)
1062                 seq_printf(seq, "<not supported>\n");
1063         else
1064                 kfree(edid);
1065
1066         return 0;
1067 }
1068
1069 static int
1070 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1071 {
1072         return single_open(file, acpi_video_device_EDID_seq_show,
1073                            PDE(inode)->data);
1074 }
1075
1076 static int acpi_video_device_add_fs(struct acpi_device *device)
1077 {
1078         struct proc_dir_entry *entry, *device_dir;
1079         struct acpi_video_device *vid_dev;
1080
1081         vid_dev = acpi_driver_data(device);
1082         if (!vid_dev)
1083                 return -ENODEV;
1084
1085         device_dir = proc_mkdir(acpi_device_bid(device),
1086                                 vid_dev->video->dir);
1087         if (!device_dir)
1088                 return -ENOMEM;
1089
1090         device_dir->owner = THIS_MODULE;
1091
1092         /* 'info' [R] */
1093         entry = proc_create_data("info", S_IRUGO, device_dir,
1094                         &acpi_video_device_info_fops, acpi_driver_data(device));
1095         if (!entry)
1096                 goto err_remove_dir;
1097
1098         /* 'state' [R/W] */
1099         acpi_video_device_state_fops.write = acpi_video_device_write_state;
1100         entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1101                                  device_dir,
1102                                  &acpi_video_device_state_fops,
1103                                  acpi_driver_data(device));
1104         if (!entry)
1105                 goto err_remove_info;
1106
1107         /* 'brightness' [R/W] */
1108         acpi_video_device_brightness_fops.write =
1109                 acpi_video_device_write_brightness;
1110         entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1111                                  device_dir,
1112                                  &acpi_video_device_brightness_fops,
1113                                  acpi_driver_data(device));
1114         if (!entry)
1115                 goto err_remove_state;
1116
1117         /* 'EDID' [R] */
1118         entry = proc_create_data("EDID", S_IRUGO, device_dir,
1119                                  &acpi_video_device_EDID_fops,
1120                                  acpi_driver_data(device));
1121         if (!entry)
1122                 goto err_remove_brightness;
1123
1124         acpi_device_dir(device) = device_dir;
1125
1126         return 0;
1127
1128  err_remove_brightness:
1129         remove_proc_entry("brightness", device_dir);
1130  err_remove_state:
1131         remove_proc_entry("state", device_dir);
1132  err_remove_info:
1133         remove_proc_entry("info", device_dir);
1134  err_remove_dir:
1135         remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1136         return -ENOMEM;
1137 }
1138
1139 static int acpi_video_device_remove_fs(struct acpi_device *device)
1140 {
1141         struct acpi_video_device *vid_dev;
1142         struct proc_dir_entry *device_dir;
1143
1144         vid_dev = acpi_driver_data(device);
1145         if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1146                 return -ENODEV;
1147
1148         device_dir = acpi_device_dir(device);
1149         if (device_dir) {
1150                 remove_proc_entry("info", device_dir);
1151                 remove_proc_entry("state", device_dir);
1152                 remove_proc_entry("brightness", device_dir);
1153                 remove_proc_entry("EDID", device_dir);
1154                 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1155                 acpi_device_dir(device) = NULL;
1156         }
1157
1158         return 0;
1159 }
1160
1161 /* video bus */
1162 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1163 {
1164         struct acpi_video_bus *video = seq->private;
1165
1166
1167         if (!video)
1168                 goto end;
1169
1170         seq_printf(seq, "Switching heads:              %s\n",
1171                    video->flags.multihead ? "yes" : "no");
1172         seq_printf(seq, "Video ROM:                    %s\n",
1173                    video->flags.rom ? "yes" : "no");
1174         seq_printf(seq, "Device to be POSTed on boot:  %s\n",
1175                    video->flags.post ? "yes" : "no");
1176
1177       end:
1178         return 0;
1179 }
1180
1181 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1182 {
1183         return single_open(file, acpi_video_bus_info_seq_show,
1184                            PDE(inode)->data);
1185 }
1186
1187 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1188 {
1189         struct acpi_video_bus *video = seq->private;
1190
1191
1192         if (!video)
1193                 goto end;
1194
1195         printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1196         seq_printf(seq, "<TODO>\n");
1197
1198       end:
1199         return 0;
1200 }
1201
1202 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1203 {
1204         return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1205 }
1206
1207 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1208 {
1209         struct acpi_video_bus *video = seq->private;
1210         unsigned long options;
1211         int status;
1212
1213
1214         if (!video)
1215                 goto end;
1216
1217         status = acpi_video_bus_POST_options(video, &options);
1218         if (ACPI_SUCCESS(status)) {
1219                 if (!(options & 1)) {
1220                         printk(KERN_WARNING PREFIX
1221                                "The motherboard VGA device is not listed as a possible POST device.\n");
1222                         printk(KERN_WARNING PREFIX
1223                                "This indicates a BIOS bug. Please contact the manufacturer.\n");
1224                 }
1225                 printk("%lx\n", options);
1226                 seq_printf(seq, "can POST: <integrated video>");
1227                 if (options & 2)
1228                         seq_printf(seq, " <PCI video>");
1229                 if (options & 4)
1230                         seq_printf(seq, " <AGP video>");
1231                 seq_putc(seq, '\n');
1232         } else
1233                 seq_printf(seq, "<not supported>\n");
1234       end:
1235         return 0;
1236 }
1237
1238 static int
1239 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1240 {
1241         return single_open(file, acpi_video_bus_POST_info_seq_show,
1242                            PDE(inode)->data);
1243 }
1244
1245 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1246 {
1247         struct acpi_video_bus *video = seq->private;
1248         int status;
1249         unsigned long id;
1250
1251
1252         if (!video)
1253                 goto end;
1254
1255         status = acpi_video_bus_get_POST(video, &id);
1256         if (!ACPI_SUCCESS(status)) {
1257                 seq_printf(seq, "<not supported>\n");
1258                 goto end;
1259         }
1260         seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1261
1262       end:
1263         return 0;
1264 }
1265
1266 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1267 {
1268         struct acpi_video_bus *video = seq->private;
1269
1270
1271         seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1272
1273         return 0;
1274 }
1275
1276 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1277 {
1278         return single_open(file, acpi_video_bus_POST_seq_show,
1279                            PDE(inode)->data);
1280 }
1281
1282 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1283 {
1284         return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1285 }
1286
1287 static ssize_t
1288 acpi_video_bus_write_POST(struct file *file,
1289                           const char __user * buffer,
1290                           size_t count, loff_t * data)
1291 {
1292         int status;
1293         struct seq_file *m = file->private_data;
1294         struct acpi_video_bus *video = m->private;
1295         char str[12] = { 0 };
1296         unsigned long opt, options;
1297
1298
1299         if (!video || count + 1 > sizeof str)
1300                 return -EINVAL;
1301
1302         status = acpi_video_bus_POST_options(video, &options);
1303         if (!ACPI_SUCCESS(status))
1304                 return -EINVAL;
1305
1306         if (copy_from_user(str, buffer, count))
1307                 return -EFAULT;
1308
1309         str[count] = 0;
1310         opt = strtoul(str, NULL, 0);
1311         if (opt > 3)
1312                 return -EFAULT;
1313
1314         /* just in case an OEM 'forgot' the motherboard... */
1315         options |= 1;
1316
1317         if (options & (1ul << opt)) {
1318                 status = acpi_video_bus_set_POST(video, opt);
1319                 if (!ACPI_SUCCESS(status))
1320                         return -EFAULT;
1321
1322         }
1323
1324         return count;
1325 }
1326
1327 static ssize_t
1328 acpi_video_bus_write_DOS(struct file *file,
1329                          const char __user * buffer,
1330                          size_t count, loff_t * data)
1331 {
1332         int status;
1333         struct seq_file *m = file->private_data;
1334         struct acpi_video_bus *video = m->private;
1335         char str[12] = { 0 };
1336         unsigned long opt;
1337
1338
1339         if (!video || count + 1 > sizeof str)
1340                 return -EINVAL;
1341
1342         if (copy_from_user(str, buffer, count))
1343                 return -EFAULT;
1344
1345         str[count] = 0;
1346         opt = strtoul(str, NULL, 0);
1347         if (opt > 7)
1348                 return -EFAULT;
1349
1350         status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1351
1352         if (!ACPI_SUCCESS(status))
1353                 return -EFAULT;
1354
1355         return count;
1356 }
1357
1358 static int acpi_video_bus_add_fs(struct acpi_device *device)
1359 {
1360         struct acpi_video_bus *video = acpi_driver_data(device);
1361         struct proc_dir_entry *device_dir;
1362         struct proc_dir_entry *entry;
1363
1364         device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1365         if (!device_dir)
1366                 return -ENOMEM;
1367
1368         device_dir->owner = THIS_MODULE;
1369
1370         /* 'info' [R] */
1371         entry = proc_create_data("info", S_IRUGO, device_dir,
1372                                  &acpi_video_bus_info_fops,
1373                                  acpi_driver_data(device));
1374         if (!entry)
1375                 goto err_remove_dir;
1376
1377         /* 'ROM' [R] */
1378         entry = proc_create_data("ROM", S_IRUGO, device_dir,
1379                                  &acpi_video_bus_ROM_fops,
1380                                  acpi_driver_data(device));
1381         if (!entry)
1382                 goto err_remove_info;
1383
1384         /* 'POST_info' [R] */
1385         entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1386                                  &acpi_video_bus_POST_info_fops,
1387                                  acpi_driver_data(device));
1388         if (!entry)
1389                 goto err_remove_rom;
1390
1391         /* 'POST' [R/W] */
1392         acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1393         entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1394                                  device_dir,
1395                                  &acpi_video_bus_POST_fops,
1396                                  acpi_driver_data(device));
1397         if (!entry)
1398                 goto err_remove_post_info;
1399
1400         /* 'DOS' [R/W] */
1401         acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1402         entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1403                                  device_dir,
1404                                  &acpi_video_bus_DOS_fops,
1405                                  acpi_driver_data(device));
1406         if (!entry)
1407                 goto err_remove_post;
1408
1409         video->dir = acpi_device_dir(device) = device_dir;
1410         return 0;
1411
1412  err_remove_post:
1413         remove_proc_entry("POST", device_dir);
1414  err_remove_post_info:
1415         remove_proc_entry("POST_info", device_dir);
1416  err_remove_rom:
1417         remove_proc_entry("ROM", device_dir);
1418  err_remove_info:
1419         remove_proc_entry("info", device_dir);
1420  err_remove_dir:
1421         remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1422         return -ENOMEM;
1423 }
1424
1425 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1426 {
1427         struct proc_dir_entry *device_dir = acpi_device_dir(device);
1428
1429         if (device_dir) {
1430                 remove_proc_entry("info", device_dir);
1431                 remove_proc_entry("ROM", device_dir);
1432                 remove_proc_entry("POST_info", device_dir);
1433                 remove_proc_entry("POST", device_dir);
1434                 remove_proc_entry("DOS", device_dir);
1435                 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1436                 acpi_device_dir(device) = NULL;
1437         }
1438
1439         return 0;
1440 }
1441
1442 /* --------------------------------------------------------------------------
1443                                  Driver Interface
1444    -------------------------------------------------------------------------- */
1445
1446 /* device interface */
1447 static struct acpi_video_device_attrib*
1448 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1449 {
1450         struct acpi_video_enumerated_device *ids;
1451         int i;
1452
1453         for (i = 0; i < video->attached_count; i++) {
1454                 ids = &video->attached_array[i];
1455                 if ((ids->value.int_val & 0xffff) == device_id)
1456                         return &ids->value.attrib;
1457         }
1458
1459         return NULL;
1460 }
1461
1462 static int
1463 acpi_video_bus_get_one_device(struct acpi_device *device,
1464                               struct acpi_video_bus *video)
1465 {
1466         unsigned long device_id;
1467         int status;
1468         struct acpi_video_device *data;
1469         struct acpi_video_device_attrib* attribute;
1470
1471         if (!device || !video)
1472                 return -EINVAL;
1473
1474         status =
1475             acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1476         if (ACPI_SUCCESS(status)) {
1477
1478                 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1479                 if (!data)
1480                         return -ENOMEM;
1481
1482                 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1483                 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1484                 acpi_driver_data(device) = data;
1485
1486                 data->device_id = device_id;
1487                 data->video = video;
1488                 data->dev = device;
1489
1490                 attribute = acpi_video_get_device_attr(video, device_id);
1491
1492                 if((attribute != NULL) && attribute->device_id_scheme) {
1493                         switch (attribute->display_type) {
1494                         case ACPI_VIDEO_DISPLAY_CRT:
1495                                 data->flags.crt = 1;
1496                                 break;
1497                         case ACPI_VIDEO_DISPLAY_TV:
1498                                 data->flags.tvout = 1;
1499                                 break;
1500                         case ACPI_VIDEO_DISPLAY_DVI:
1501                                 data->flags.dvi = 1;
1502                                 break;
1503                         case ACPI_VIDEO_DISPLAY_LCD:
1504                                 data->flags.lcd = 1;
1505                                 break;
1506                         default:
1507                                 data->flags.unknown = 1;
1508                                 break;
1509                         }
1510                         if(attribute->bios_can_detect)
1511                                 data->flags.bios = 1;
1512                 } else
1513                         data->flags.unknown = 1;
1514
1515                 acpi_video_device_bind(video, data);
1516                 acpi_video_device_find_cap(data);
1517
1518                 status = acpi_install_notify_handler(device->handle,
1519                                                      ACPI_DEVICE_NOTIFY,
1520                                                      acpi_video_device_notify,
1521                                                      data);
1522                 if (ACPI_FAILURE(status)) {
1523                         ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1524                                           "Error installing notify handler\n"));
1525                         if(data->brightness)
1526                                 kfree(data->brightness->levels);
1527                         kfree(data->brightness);
1528                         kfree(data);
1529                         return -ENODEV;
1530                 }
1531
1532                 mutex_lock(&video->device_list_lock);
1533                 list_add_tail(&data->entry, &video->video_device_list);
1534                 mutex_unlock(&video->device_list_lock);
1535
1536                 acpi_video_device_add_fs(device);
1537
1538                 return 0;
1539         }
1540
1541         return -ENOENT;
1542 }
1543
1544 /*
1545  *  Arg:
1546  *      video   : video bus device 
1547  *
1548  *  Return:
1549  *      none
1550  *  
1551  *  Enumerate the video device list of the video bus, 
1552  *  bind the ids with the corresponding video devices
1553  *  under the video bus.
1554  */
1555
1556 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1557 {
1558         struct acpi_video_device *dev;
1559
1560         mutex_lock(&video->device_list_lock);
1561
1562         list_for_each_entry(dev, &video->video_device_list, entry)
1563                 acpi_video_device_bind(video, dev);
1564
1565         mutex_unlock(&video->device_list_lock);
1566 }
1567
1568 /*
1569  *  Arg:
1570  *      video   : video bus device 
1571  *      device  : video output device under the video 
1572  *              bus
1573  *
1574  *  Return:
1575  *      none
1576  *  
1577  *  Bind the ids with the corresponding video devices
1578  *  under the video bus.
1579  */
1580
1581 static void
1582 acpi_video_device_bind(struct acpi_video_bus *video,
1583                        struct acpi_video_device *device)
1584 {
1585         struct acpi_video_enumerated_device *ids;
1586         int i;
1587
1588         for (i = 0; i < video->attached_count; i++) {
1589                 ids = &video->attached_array[i];
1590                 if (device->device_id == (ids->value.int_val & 0xffff)) {
1591                         ids->bind_info = device;
1592                         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1593                 }
1594         }
1595 }
1596
1597 /*
1598  *  Arg:
1599  *      video   : video bus device 
1600  *
1601  *  Return:
1602  *      < 0     : error
1603  *  
1604  *  Call _DOD to enumerate all devices attached to display adapter
1605  *
1606  */
1607
1608 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1609 {
1610         int status;
1611         int count;
1612         int i;
1613         struct acpi_video_enumerated_device *active_list;
1614         struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1615         union acpi_object *dod = NULL;
1616         union acpi_object *obj;
1617
1618         status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1619         if (!ACPI_SUCCESS(status)) {
1620                 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1621                 return status;
1622         }
1623
1624         dod = buffer.pointer;
1625         if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1626                 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1627                 status = -EFAULT;
1628                 goto out;
1629         }
1630
1631         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1632                           dod->package.count));
1633
1634         active_list = kcalloc(1 + dod->package.count,
1635                               sizeof(struct acpi_video_enumerated_device),
1636                               GFP_KERNEL);
1637         if (!active_list) {
1638                 status = -ENOMEM;
1639                 goto out;
1640         }
1641
1642         count = 0;
1643         for (i = 0; i < dod->package.count; i++) {
1644                 obj = &dod->package.elements[i];
1645
1646                 if (obj->type != ACPI_TYPE_INTEGER) {
1647                         printk(KERN_ERR PREFIX
1648                                 "Invalid _DOD data in element %d\n", i);
1649                         continue;
1650                 }
1651
1652                 active_list[count].value.int_val = obj->integer.value;
1653                 active_list[count].bind_info = NULL;
1654                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1655                                   (int)obj->integer.value));
1656                 count++;
1657         }
1658
1659         kfree(video->attached_array);
1660
1661         video->attached_array = active_list;
1662         video->attached_count = count;
1663
1664  out:
1665         kfree(buffer.pointer);
1666         return status;
1667 }
1668
1669 static int
1670 acpi_video_get_next_level(struct acpi_video_device *device,
1671                           u32 level_current, u32 event)
1672 {
1673         int min, max, min_above, max_below, i, l, delta = 255;
1674         max = max_below = 0;
1675         min = min_above = 255;
1676         /* Find closest level to level_current */
1677         for (i = 0; i < device->brightness->count; i++) {
1678                 l = device->brightness->levels[i];
1679                 if (abs(l - level_current) < abs(delta)) {
1680                         delta = l - level_current;
1681                         if (!delta)
1682                                 break;
1683                 }
1684         }
1685         /* Ajust level_current to closest available level */
1686         level_current += delta;
1687         for (i = 0; i < device->brightness->count; i++) {
1688                 l = device->brightness->levels[i];
1689                 if (l < min)
1690                         min = l;
1691                 if (l > max)
1692                         max = l;
1693                 if (l < min_above && l > level_current)
1694                         min_above = l;
1695                 if (l > max_below && l < level_current)
1696                         max_below = l;
1697         }
1698
1699         switch (event) {
1700         case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1701                 return (level_current < max) ? min_above : min;
1702         case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1703                 return (level_current < max) ? min_above : max;
1704         case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1705                 return (level_current > min) ? max_below : min;
1706         case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1707         case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1708                 return 0;
1709         default:
1710                 return level_current;
1711         }
1712 }
1713
1714 static void
1715 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1716 {
1717         unsigned long level_current, level_next;
1718         if (!device->brightness)
1719                 return;
1720         acpi_video_device_lcd_get_level_current(device, &level_current);
1721         level_next = acpi_video_get_next_level(device, level_current, event);
1722         acpi_video_device_lcd_set_level(device, level_next);
1723 }
1724
1725 static int
1726 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1727                            struct acpi_device *device)
1728 {
1729         int status = 0;
1730         struct acpi_device *dev;
1731
1732         acpi_video_device_enumerate(video);
1733
1734         list_for_each_entry(dev, &device->children, node) {
1735
1736                 status = acpi_video_bus_get_one_device(dev, video);
1737                 if (ACPI_FAILURE(status)) {
1738                         ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1739                                         "Cant attach device"));
1740                         continue;
1741                 }
1742         }
1743         return status;
1744 }
1745
1746 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1747 {
1748         acpi_status status;
1749         struct acpi_video_bus *video;
1750
1751
1752         if (!device || !device->video)
1753                 return -ENOENT;
1754
1755         video = device->video;
1756
1757         acpi_video_device_remove_fs(device->dev);
1758
1759         status = acpi_remove_notify_handler(device->dev->handle,
1760                                             ACPI_DEVICE_NOTIFY,
1761                                             acpi_video_device_notify);
1762         backlight_device_unregister(device->backlight);
1763         if (device->cdev) {
1764                 sysfs_remove_link(&device->dev->dev.kobj,
1765                                   "thermal_cooling");
1766                 sysfs_remove_link(&device->cdev->device.kobj,
1767                                   "device");
1768                 thermal_cooling_device_unregister(device->cdev);
1769                 device->cdev = NULL;
1770         }
1771         video_output_unregister(device->output_dev);
1772
1773         return 0;
1774 }
1775
1776 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1777 {
1778         int status;
1779         struct acpi_video_device *dev, *next;
1780
1781         mutex_lock(&video->device_list_lock);
1782
1783         list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1784
1785                 status = acpi_video_bus_put_one_device(dev);
1786                 if (ACPI_FAILURE(status))
1787                         printk(KERN_WARNING PREFIX
1788                                "hhuuhhuu bug in acpi video driver.\n");
1789
1790                 if (dev->brightness) {
1791                         kfree(dev->brightness->levels);
1792                         kfree(dev->brightness);
1793                 }
1794                 list_del(&dev->entry);
1795                 kfree(dev);
1796         }
1797
1798         mutex_unlock(&video->device_list_lock);
1799
1800         return 0;
1801 }
1802
1803 /* acpi_video interface */
1804
1805 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1806 {
1807         return acpi_video_bus_DOS(video, 0, 0);
1808 }
1809
1810 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1811 {
1812         return acpi_video_bus_DOS(video, 0, 1);
1813 }
1814
1815 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1816 {
1817         struct acpi_video_bus *video = data;
1818         struct acpi_device *device = NULL;
1819         struct input_dev *input;
1820         int keycode;
1821
1822         if (!video)
1823                 return;
1824
1825         device = video->device;
1826         input = video->input;
1827
1828         switch (event) {
1829         case ACPI_VIDEO_NOTIFY_SWITCH:  /* User requested a switch,
1830                                          * most likely via hotkey. */
1831                 acpi_bus_generate_proc_event(device, event, 0);
1832                 keycode = KEY_SWITCHVIDEOMODE;
1833                 break;
1834
1835         case ACPI_VIDEO_NOTIFY_PROBE:   /* User plugged in or removed a video
1836                                          * connector. */
1837                 acpi_video_device_enumerate(video);
1838                 acpi_video_device_rebind(video);
1839                 acpi_bus_generate_proc_event(device, event, 0);
1840                 keycode = KEY_SWITCHVIDEOMODE;
1841                 break;
1842
1843         case ACPI_VIDEO_NOTIFY_CYCLE:   /* Cycle Display output hotkey pressed. */
1844                 acpi_bus_generate_proc_event(device, event, 0);
1845                 keycode = KEY_SWITCHVIDEOMODE;
1846                 break;
1847         case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:     /* Next Display output hotkey pressed. */
1848                 acpi_bus_generate_proc_event(device, event, 0);
1849                 keycode = KEY_VIDEO_NEXT;
1850                 break;
1851         case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:     /* previous Display output hotkey pressed. */
1852                 acpi_bus_generate_proc_event(device, event, 0);
1853                 keycode = KEY_VIDEO_PREV;
1854                 break;
1855
1856         default:
1857                 keycode = KEY_UNKNOWN;
1858                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1859                                   "Unsupported event [0x%x]\n", event));
1860                 break;
1861         }
1862
1863         acpi_notifier_call_chain(device, event, 0);
1864         input_report_key(input, keycode, 1);
1865         input_sync(input);
1866         input_report_key(input, keycode, 0);
1867         input_sync(input);
1868
1869         return;
1870 }
1871
1872 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1873 {
1874         struct acpi_video_device *video_device = data;
1875         struct acpi_device *device = NULL;
1876         struct acpi_video_bus *bus;
1877         struct input_dev *input;
1878         int keycode;
1879
1880         if (!video_device)
1881                 return;
1882
1883         device = video_device->dev;
1884         bus = video_device->video;
1885         input = bus->input;
1886
1887         switch (event) {
1888         case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:        /* Cycle brightness */
1889                 if (brightness_switch_enabled)
1890                         acpi_video_switch_brightness(video_device, event);
1891                 acpi_bus_generate_proc_event(device, event, 0);
1892                 keycode = KEY_BRIGHTNESS_CYCLE;
1893                 break;
1894         case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:  /* Increase brightness */
1895                 if (brightness_switch_enabled)
1896                         acpi_video_switch_brightness(video_device, event);
1897                 acpi_bus_generate_proc_event(device, event, 0);
1898                 keycode = KEY_BRIGHTNESSUP;
1899                 break;
1900         case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:  /* Decrease brightness */
1901                 if (brightness_switch_enabled)
1902                         acpi_video_switch_brightness(video_device, event);
1903                 acpi_bus_generate_proc_event(device, event, 0);
1904                 keycode = KEY_BRIGHTNESSDOWN;
1905                 break;
1906         case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1907                 if (brightness_switch_enabled)
1908                         acpi_video_switch_brightness(video_device, event);
1909                 acpi_bus_generate_proc_event(device, event, 0);
1910                 keycode = KEY_BRIGHTNESS_ZERO;
1911                 break;
1912         case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:     /* display device off */
1913                 if (brightness_switch_enabled)
1914                         acpi_video_switch_brightness(video_device, event);
1915                 acpi_bus_generate_proc_event(device, event, 0);
1916                 keycode = KEY_DISPLAY_OFF;
1917                 break;
1918         default:
1919                 keycode = KEY_UNKNOWN;
1920                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1921                                   "Unsupported event [0x%x]\n", event));
1922                 break;
1923         }
1924
1925         acpi_notifier_call_chain(device, event, 0);
1926         input_report_key(input, keycode, 1);
1927         input_sync(input);
1928         input_report_key(input, keycode, 0);
1929         input_sync(input);
1930
1931         return;
1932 }
1933
1934 static int instance;
1935 static int acpi_video_resume(struct acpi_device *device)
1936 {
1937         struct acpi_video_bus *video;
1938         struct acpi_video_device *video_device;
1939         int i;
1940
1941         if (!device || !acpi_driver_data(device))
1942                 return -EINVAL;
1943
1944         video = acpi_driver_data(device);
1945
1946         for (i = 0; i < video->attached_count; i++) {
1947                 video_device = video->attached_array[i].bind_info;
1948                 if (video_device && video_device->backlight)
1949                         acpi_video_set_brightness(video_device->backlight);
1950         }
1951         return AE_OK;
1952 }
1953
1954 static int acpi_video_bus_add(struct acpi_device *device)
1955 {
1956         acpi_status status;
1957         struct acpi_video_bus *video;
1958         struct input_dev *input;
1959         int error;
1960
1961         video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1962         if (!video)
1963                 return -ENOMEM;
1964
1965         /* a hack to fix the duplicate name "VID" problem on T61 */
1966         if (!strcmp(device->pnp.bus_id, "VID")) {
1967                 if (instance)
1968                         device->pnp.bus_id[3] = '0' + instance;
1969                 instance ++;
1970         }
1971
1972         video->device = device;
1973         strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1974         strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1975         acpi_driver_data(device) = video;
1976
1977         acpi_video_bus_find_cap(video);
1978         error = acpi_video_bus_check(video);
1979         if (error)
1980                 goto err_free_video;
1981
1982         error = acpi_video_bus_add_fs(device);
1983         if (error)
1984                 goto err_free_video;
1985
1986         mutex_init(&video->device_list_lock);
1987         INIT_LIST_HEAD(&video->video_device_list);
1988
1989         acpi_video_bus_get_devices(video, device);
1990         acpi_video_bus_start_devices(video);
1991
1992         status = acpi_install_notify_handler(device->handle,
1993                                              ACPI_DEVICE_NOTIFY,
1994                                              acpi_video_bus_notify, video);
1995         if (ACPI_FAILURE(status)) {
1996                 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1997                                   "Error installing notify handler\n"));
1998                 error = -ENODEV;
1999                 goto err_stop_video;
2000         }
2001
2002         video->input = input = input_allocate_device();
2003         if (!input) {
2004                 error = -ENOMEM;
2005                 goto err_uninstall_notify;
2006         }
2007
2008         snprintf(video->phys, sizeof(video->phys),
2009                 "%s/video/input0", acpi_device_hid(video->device));
2010
2011         input->name = acpi_device_name(video->device);
2012         input->phys = video->phys;
2013         input->id.bustype = BUS_HOST;
2014         input->id.product = 0x06;
2015         input->dev.parent = &device->dev;
2016         input->evbit[0] = BIT(EV_KEY);
2017         set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2018         set_bit(KEY_VIDEO_NEXT, input->keybit);
2019         set_bit(KEY_VIDEO_PREV, input->keybit);
2020         set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2021         set_bit(KEY_BRIGHTNESSUP, input->keybit);
2022         set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2023         set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2024         set_bit(KEY_DISPLAY_OFF, input->keybit);
2025         set_bit(KEY_UNKNOWN, input->keybit);
2026
2027         error = input_register_device(input);
2028         if (error)
2029                 goto err_free_input_dev;
2030
2031         printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s  rom: %s  post: %s)\n",
2032                ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2033                video->flags.multihead ? "yes" : "no",
2034                video->flags.rom ? "yes" : "no",
2035                video->flags.post ? "yes" : "no");
2036
2037         return 0;
2038
2039  err_free_input_dev:
2040         input_free_device(input);
2041  err_uninstall_notify:
2042         acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2043                                    acpi_video_bus_notify);
2044  err_stop_video:
2045         acpi_video_bus_stop_devices(video);
2046         acpi_video_bus_put_devices(video);
2047         kfree(video->attached_array);
2048         acpi_video_bus_remove_fs(device);
2049  err_free_video:
2050         kfree(video);
2051         acpi_driver_data(device) = NULL;
2052
2053         return error;
2054 }
2055
2056 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2057 {
2058         acpi_status status = 0;
2059         struct acpi_video_bus *video = NULL;
2060
2061
2062         if (!device || !acpi_driver_data(device))
2063                 return -EINVAL;
2064
2065         video = acpi_driver_data(device);
2066
2067         acpi_video_bus_stop_devices(video);
2068
2069         status = acpi_remove_notify_handler(video->device->handle,
2070                                             ACPI_DEVICE_NOTIFY,
2071                                             acpi_video_bus_notify);
2072
2073         acpi_video_bus_put_devices(video);
2074         acpi_video_bus_remove_fs(device);
2075
2076         input_unregister_device(video->input);
2077         kfree(video->attached_array);
2078         kfree(video);
2079
2080         return 0;
2081 }
2082
2083 static int __init acpi_video_init(void)
2084 {
2085         int result = 0;
2086
2087
2088         /*
2089            acpi_dbg_level = 0xFFFFFFFF;
2090            acpi_dbg_layer = 0x08000000;
2091          */
2092
2093         acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2094         if (!acpi_video_dir)
2095                 return -ENODEV;
2096         acpi_video_dir->owner = THIS_MODULE;
2097
2098         result = acpi_bus_register_driver(&acpi_video_bus);
2099         if (result < 0) {
2100                 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2101                 return -ENODEV;
2102         }
2103
2104         return 0;
2105 }
2106
2107 static void __exit acpi_video_exit(void)
2108 {
2109
2110         acpi_bus_unregister_driver(&acpi_video_bus);
2111
2112         remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2113
2114         return;
2115 }
2116
2117 module_init(acpi_video_init);
2118 module_exit(acpi_video_exit);