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