]> Pileus Git - ~andy/linux/blob - drivers/acpi/video.c
ACPI: video: Ignore devices that aren't present in hardware
[~andy/linux] / 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 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 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 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 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 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 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 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 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 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 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 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 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 && 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                 /*
757                  * If there exists the _BQC object, the _BQC object will be
758                  * called to get the current backlight brightness. Otherwise
759                  * the brightness will be set to the maximum.
760                  */
761                 if (device->cap._BQC)
762                         device->backlight->props.brightness =
763                                 acpi_video_get_brightness(device->backlight);
764                 else
765                         device->backlight->props.brightness =
766                                 device->backlight->props.max_brightness;
767                 backlight_update_status(device->backlight);
768                 kfree(name);
769
770                 device->cdev = thermal_cooling_device_register("LCD",
771                                         device->dev, &video_cooling_ops);
772                 if (IS_ERR(device->cdev))
773                         return;
774
775                 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
776                          device->cdev->id);
777                 result = sysfs_create_link(&device->dev->dev.kobj,
778                                 &device->cdev->device.kobj,
779                                 "thermal_cooling");
780                 if (result)
781                         printk(KERN_ERR PREFIX "Create sysfs link\n");
782                 result = sysfs_create_link(&device->cdev->device.kobj,
783                                 &device->dev->dev.kobj, "device");
784                 if (result)
785                         printk(KERN_ERR PREFIX "Create sysfs link\n");
786
787         }
788         if (device->cap._DCS && device->cap._DSS){
789                 static int count = 0;
790                 char *name;
791                 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
792                 if (!name)
793                         return;
794                 sprintf(name, "acpi_video%d", count++);
795                 device->output_dev = video_output_register(name,
796                                 NULL, device, &acpi_output_properties);
797                 kfree(name);
798         }
799         return;
800 }
801
802 /*
803  *  Arg:        
804  *      device  : video output device (VGA)
805  *
806  *  Return Value:
807  *      None
808  *
809  *  Find out all required AML methods defined under the video bus device.
810  */
811
812 static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
813 {
814         acpi_handle h_dummy1;
815
816         memset(&video->cap, 0, sizeof(video->cap));
817         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
818                 video->cap._DOS = 1;
819         }
820         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
821                 video->cap._DOD = 1;
822         }
823         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
824                 video->cap._ROM = 1;
825         }
826         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
827                 video->cap._GPD = 1;
828         }
829         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
830                 video->cap._SPD = 1;
831         }
832         if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
833                 video->cap._VPO = 1;
834         }
835 }
836
837 /*
838  * Check whether the video bus device has required AML method to
839  * support the desired features
840  */
841
842 static int acpi_video_bus_check(struct acpi_video_bus *video)
843 {
844         acpi_status status = -ENOENT;
845         struct device *dev;
846
847         if (!video)
848                 return -EINVAL;
849
850         dev = acpi_get_physical_pci_device(video->device->handle);
851         if (!dev)
852                 return -ENODEV;
853         put_device(dev);
854
855         /* Since there is no HID, CID and so on for VGA driver, we have
856          * to check well known required nodes.
857          */
858
859         /* Does this device support video switching? */
860         if (video->cap._DOS) {
861                 video->flags.multihead = 1;
862                 status = 0;
863         }
864
865         /* Does this device support retrieving a video ROM? */
866         if (video->cap._ROM) {
867                 video->flags.rom = 1;
868                 status = 0;
869         }
870
871         /* Does this device support configuring which video device to POST? */
872         if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
873                 video->flags.post = 1;
874                 status = 0;
875         }
876
877         return status;
878 }
879
880 /* --------------------------------------------------------------------------
881                               FS Interface (/proc)
882    -------------------------------------------------------------------------- */
883
884 static struct proc_dir_entry *acpi_video_dir;
885
886 /* video devices */
887
888 static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
889 {
890         struct acpi_video_device *dev = seq->private;
891
892
893         if (!dev)
894                 goto end;
895
896         seq_printf(seq, "device_id:    0x%04x\n", (u32) dev->device_id);
897         seq_printf(seq, "type:         ");
898         if (dev->flags.crt)
899                 seq_printf(seq, "CRT\n");
900         else if (dev->flags.lcd)
901                 seq_printf(seq, "LCD\n");
902         else if (dev->flags.tvout)
903                 seq_printf(seq, "TVOUT\n");
904         else if (dev->flags.dvi)
905                 seq_printf(seq, "DVI\n");
906         else
907                 seq_printf(seq, "UNKNOWN\n");
908
909         seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
910
911       end:
912         return 0;
913 }
914
915 static int
916 acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
917 {
918         return single_open(file, acpi_video_device_info_seq_show,
919                            PDE(inode)->data);
920 }
921
922 static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
923 {
924         int status;
925         struct acpi_video_device *dev = seq->private;
926         unsigned long long state;
927
928
929         if (!dev)
930                 goto end;
931
932         status = acpi_video_device_get_state(dev, &state);
933         seq_printf(seq, "state:     ");
934         if (ACPI_SUCCESS(status))
935                 seq_printf(seq, "0x%02llx\n", state);
936         else
937                 seq_printf(seq, "<not supported>\n");
938
939         status = acpi_video_device_query(dev, &state);
940         seq_printf(seq, "query:     ");
941         if (ACPI_SUCCESS(status))
942                 seq_printf(seq, "0x%02llx\n", state);
943         else
944                 seq_printf(seq, "<not supported>\n");
945
946       end:
947         return 0;
948 }
949
950 static int
951 acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
952 {
953         return single_open(file, acpi_video_device_state_seq_show,
954                            PDE(inode)->data);
955 }
956
957 static ssize_t
958 acpi_video_device_write_state(struct file *file,
959                               const char __user * buffer,
960                               size_t count, loff_t * data)
961 {
962         int status;
963         struct seq_file *m = file->private_data;
964         struct acpi_video_device *dev = m->private;
965         char str[12] = { 0 };
966         u32 state = 0;
967
968
969         if (!dev || count + 1 > sizeof str)
970                 return -EINVAL;
971
972         if (copy_from_user(str, buffer, count))
973                 return -EFAULT;
974
975         str[count] = 0;
976         state = simple_strtoul(str, NULL, 0);
977         state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
978
979         status = acpi_video_device_set_state(dev, state);
980
981         if (status)
982                 return -EFAULT;
983
984         return count;
985 }
986
987 static int
988 acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
989 {
990         struct acpi_video_device *dev = seq->private;
991         int i;
992
993
994         if (!dev || !dev->brightness) {
995                 seq_printf(seq, "<not supported>\n");
996                 return 0;
997         }
998
999         seq_printf(seq, "levels: ");
1000         for (i = 0; i < dev->brightness->count; i++)
1001                 seq_printf(seq, " %d", dev->brightness->levels[i]);
1002         seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1003
1004         return 0;
1005 }
1006
1007 static int
1008 acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1009 {
1010         return single_open(file, acpi_video_device_brightness_seq_show,
1011                            PDE(inode)->data);
1012 }
1013
1014 static ssize_t
1015 acpi_video_device_write_brightness(struct file *file,
1016                                    const char __user * buffer,
1017                                    size_t count, loff_t * data)
1018 {
1019         struct seq_file *m = file->private_data;
1020         struct acpi_video_device *dev = m->private;
1021         char str[5] = { 0 };
1022         unsigned int level = 0;
1023         int i;
1024
1025
1026         if (!dev || !dev->brightness || count + 1 > sizeof str)
1027                 return -EINVAL;
1028
1029         if (copy_from_user(str, buffer, count))
1030                 return -EFAULT;
1031
1032         str[count] = 0;
1033         level = simple_strtoul(str, NULL, 0);
1034
1035         if (level > 100)
1036                 return -EFAULT;
1037
1038         /* validate through the list of available levels */
1039         for (i = 0; i < dev->brightness->count; i++)
1040                 if (level == dev->brightness->levels[i]) {
1041                         if (ACPI_SUCCESS
1042                             (acpi_video_device_lcd_set_level(dev, level)))
1043                                 dev->brightness->curr = level;
1044                         break;
1045                 }
1046
1047         return count;
1048 }
1049
1050 static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1051 {
1052         struct acpi_video_device *dev = seq->private;
1053         int status;
1054         int i;
1055         union acpi_object *edid = NULL;
1056
1057
1058         if (!dev)
1059                 goto out;
1060
1061         status = acpi_video_device_EDID(dev, &edid, 128);
1062         if (ACPI_FAILURE(status)) {
1063                 status = acpi_video_device_EDID(dev, &edid, 256);
1064         }
1065
1066         if (ACPI_FAILURE(status)) {
1067                 goto out;
1068         }
1069
1070         if (edid && edid->type == ACPI_TYPE_BUFFER) {
1071                 for (i = 0; i < edid->buffer.length; i++)
1072                         seq_putc(seq, edid->buffer.pointer[i]);
1073         }
1074
1075       out:
1076         if (!edid)
1077                 seq_printf(seq, "<not supported>\n");
1078         else
1079                 kfree(edid);
1080
1081         return 0;
1082 }
1083
1084 static int
1085 acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1086 {
1087         return single_open(file, acpi_video_device_EDID_seq_show,
1088                            PDE(inode)->data);
1089 }
1090
1091 static int acpi_video_device_add_fs(struct acpi_device *device)
1092 {
1093         struct proc_dir_entry *entry, *device_dir;
1094         struct acpi_video_device *vid_dev;
1095
1096         vid_dev = acpi_driver_data(device);
1097         if (!vid_dev)
1098                 return -ENODEV;
1099
1100         device_dir = proc_mkdir(acpi_device_bid(device),
1101                                 vid_dev->video->dir);
1102         if (!device_dir)
1103                 return -ENOMEM;
1104
1105         device_dir->owner = THIS_MODULE;
1106
1107         /* 'info' [R] */
1108         entry = proc_create_data("info", S_IRUGO, device_dir,
1109                         &acpi_video_device_info_fops, acpi_driver_data(device));
1110         if (!entry)
1111                 goto err_remove_dir;
1112
1113         /* 'state' [R/W] */
1114         acpi_video_device_state_fops.write = acpi_video_device_write_state;
1115         entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1116                                  device_dir,
1117                                  &acpi_video_device_state_fops,
1118                                  acpi_driver_data(device));
1119         if (!entry)
1120                 goto err_remove_info;
1121
1122         /* 'brightness' [R/W] */
1123         acpi_video_device_brightness_fops.write =
1124                 acpi_video_device_write_brightness;
1125         entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1126                                  device_dir,
1127                                  &acpi_video_device_brightness_fops,
1128                                  acpi_driver_data(device));
1129         if (!entry)
1130                 goto err_remove_state;
1131
1132         /* 'EDID' [R] */
1133         entry = proc_create_data("EDID", S_IRUGO, device_dir,
1134                                  &acpi_video_device_EDID_fops,
1135                                  acpi_driver_data(device));
1136         if (!entry)
1137                 goto err_remove_brightness;
1138
1139         acpi_device_dir(device) = device_dir;
1140
1141         return 0;
1142
1143  err_remove_brightness:
1144         remove_proc_entry("brightness", device_dir);
1145  err_remove_state:
1146         remove_proc_entry("state", device_dir);
1147  err_remove_info:
1148         remove_proc_entry("info", device_dir);
1149  err_remove_dir:
1150         remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1151         return -ENOMEM;
1152 }
1153
1154 static int acpi_video_device_remove_fs(struct acpi_device *device)
1155 {
1156         struct acpi_video_device *vid_dev;
1157         struct proc_dir_entry *device_dir;
1158
1159         vid_dev = acpi_driver_data(device);
1160         if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1161                 return -ENODEV;
1162
1163         device_dir = acpi_device_dir(device);
1164         if (device_dir) {
1165                 remove_proc_entry("info", device_dir);
1166                 remove_proc_entry("state", device_dir);
1167                 remove_proc_entry("brightness", device_dir);
1168                 remove_proc_entry("EDID", device_dir);
1169                 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1170                 acpi_device_dir(device) = NULL;
1171         }
1172
1173         return 0;
1174 }
1175
1176 /* video bus */
1177 static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1178 {
1179         struct acpi_video_bus *video = seq->private;
1180
1181
1182         if (!video)
1183                 goto end;
1184
1185         seq_printf(seq, "Switching heads:              %s\n",
1186                    video->flags.multihead ? "yes" : "no");
1187         seq_printf(seq, "Video ROM:                    %s\n",
1188                    video->flags.rom ? "yes" : "no");
1189         seq_printf(seq, "Device to be POSTed on boot:  %s\n",
1190                    video->flags.post ? "yes" : "no");
1191
1192       end:
1193         return 0;
1194 }
1195
1196 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1197 {
1198         return single_open(file, acpi_video_bus_info_seq_show,
1199                            PDE(inode)->data);
1200 }
1201
1202 static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1203 {
1204         struct acpi_video_bus *video = seq->private;
1205
1206
1207         if (!video)
1208                 goto end;
1209
1210         printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1211         seq_printf(seq, "<TODO>\n");
1212
1213       end:
1214         return 0;
1215 }
1216
1217 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1218 {
1219         return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1220 }
1221
1222 static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1223 {
1224         struct acpi_video_bus *video = seq->private;
1225         unsigned long long options;
1226         int status;
1227
1228
1229         if (!video)
1230                 goto end;
1231
1232         status = acpi_video_bus_POST_options(video, &options);
1233         if (ACPI_SUCCESS(status)) {
1234                 if (!(options & 1)) {
1235                         printk(KERN_WARNING PREFIX
1236                                "The motherboard VGA device is not listed as a possible POST device.\n");
1237                         printk(KERN_WARNING PREFIX
1238                                "This indicates a BIOS bug. Please contact the manufacturer.\n");
1239                 }
1240                 printk("%llx\n", options);
1241                 seq_printf(seq, "can POST: <integrated video>");
1242                 if (options & 2)
1243                         seq_printf(seq, " <PCI video>");
1244                 if (options & 4)
1245                         seq_printf(seq, " <AGP video>");
1246                 seq_putc(seq, '\n');
1247         } else
1248                 seq_printf(seq, "<not supported>\n");
1249       end:
1250         return 0;
1251 }
1252
1253 static int
1254 acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1255 {
1256         return single_open(file, acpi_video_bus_POST_info_seq_show,
1257                            PDE(inode)->data);
1258 }
1259
1260 static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1261 {
1262         struct acpi_video_bus *video = seq->private;
1263         int status;
1264         unsigned long long id;
1265
1266
1267         if (!video)
1268                 goto end;
1269
1270         status = acpi_video_bus_get_POST(video, &id);
1271         if (!ACPI_SUCCESS(status)) {
1272                 seq_printf(seq, "<not supported>\n");
1273                 goto end;
1274         }
1275         seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1276
1277       end:
1278         return 0;
1279 }
1280
1281 static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1282 {
1283         struct acpi_video_bus *video = seq->private;
1284
1285
1286         seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1287
1288         return 0;
1289 }
1290
1291 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1292 {
1293         return single_open(file, acpi_video_bus_POST_seq_show,
1294                            PDE(inode)->data);
1295 }
1296
1297 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1298 {
1299         return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1300 }
1301
1302 static ssize_t
1303 acpi_video_bus_write_POST(struct file *file,
1304                           const char __user * buffer,
1305                           size_t count, loff_t * data)
1306 {
1307         int status;
1308         struct seq_file *m = file->private_data;
1309         struct acpi_video_bus *video = m->private;
1310         char str[12] = { 0 };
1311         unsigned long long opt, options;
1312
1313
1314         if (!video || count + 1 > sizeof str)
1315                 return -EINVAL;
1316
1317         status = acpi_video_bus_POST_options(video, &options);
1318         if (!ACPI_SUCCESS(status))
1319                 return -EINVAL;
1320
1321         if (copy_from_user(str, buffer, count))
1322                 return -EFAULT;
1323
1324         str[count] = 0;
1325         opt = strtoul(str, NULL, 0);
1326         if (opt > 3)
1327                 return -EFAULT;
1328
1329         /* just in case an OEM 'forgot' the motherboard... */
1330         options |= 1;
1331
1332         if (options & (1ul << opt)) {
1333                 status = acpi_video_bus_set_POST(video, opt);
1334                 if (!ACPI_SUCCESS(status))
1335                         return -EFAULT;
1336
1337         }
1338
1339         return count;
1340 }
1341
1342 static ssize_t
1343 acpi_video_bus_write_DOS(struct file *file,
1344                          const char __user * buffer,
1345                          size_t count, loff_t * data)
1346 {
1347         int status;
1348         struct seq_file *m = file->private_data;
1349         struct acpi_video_bus *video = m->private;
1350         char str[12] = { 0 };
1351         unsigned long opt;
1352
1353
1354         if (!video || count + 1 > sizeof str)
1355                 return -EINVAL;
1356
1357         if (copy_from_user(str, buffer, count))
1358                 return -EFAULT;
1359
1360         str[count] = 0;
1361         opt = strtoul(str, NULL, 0);
1362         if (opt > 7)
1363                 return -EFAULT;
1364
1365         status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1366
1367         if (!ACPI_SUCCESS(status))
1368                 return -EFAULT;
1369
1370         return count;
1371 }
1372
1373 static int acpi_video_bus_add_fs(struct acpi_device *device)
1374 {
1375         struct acpi_video_bus *video = acpi_driver_data(device);
1376         struct proc_dir_entry *device_dir;
1377         struct proc_dir_entry *entry;
1378
1379         device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1380         if (!device_dir)
1381                 return -ENOMEM;
1382
1383         device_dir->owner = THIS_MODULE;
1384
1385         /* 'info' [R] */
1386         entry = proc_create_data("info", S_IRUGO, device_dir,
1387                                  &acpi_video_bus_info_fops,
1388                                  acpi_driver_data(device));
1389         if (!entry)
1390                 goto err_remove_dir;
1391
1392         /* 'ROM' [R] */
1393         entry = proc_create_data("ROM", S_IRUGO, device_dir,
1394                                  &acpi_video_bus_ROM_fops,
1395                                  acpi_driver_data(device));
1396         if (!entry)
1397                 goto err_remove_info;
1398
1399         /* 'POST_info' [R] */
1400         entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1401                                  &acpi_video_bus_POST_info_fops,
1402                                  acpi_driver_data(device));
1403         if (!entry)
1404                 goto err_remove_rom;
1405
1406         /* 'POST' [R/W] */
1407         acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1408         entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1409                                  device_dir,
1410                                  &acpi_video_bus_POST_fops,
1411                                  acpi_driver_data(device));
1412         if (!entry)
1413                 goto err_remove_post_info;
1414
1415         /* 'DOS' [R/W] */
1416         acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1417         entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1418                                  device_dir,
1419                                  &acpi_video_bus_DOS_fops,
1420                                  acpi_driver_data(device));
1421         if (!entry)
1422                 goto err_remove_post;
1423
1424         video->dir = acpi_device_dir(device) = device_dir;
1425         return 0;
1426
1427  err_remove_post:
1428         remove_proc_entry("POST", device_dir);
1429  err_remove_post_info:
1430         remove_proc_entry("POST_info", device_dir);
1431  err_remove_rom:
1432         remove_proc_entry("ROM", device_dir);
1433  err_remove_info:
1434         remove_proc_entry("info", device_dir);
1435  err_remove_dir:
1436         remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1437         return -ENOMEM;
1438 }
1439
1440 static int acpi_video_bus_remove_fs(struct acpi_device *device)
1441 {
1442         struct proc_dir_entry *device_dir = acpi_device_dir(device);
1443
1444         if (device_dir) {
1445                 remove_proc_entry("info", device_dir);
1446                 remove_proc_entry("ROM", device_dir);
1447                 remove_proc_entry("POST_info", device_dir);
1448                 remove_proc_entry("POST", device_dir);
1449                 remove_proc_entry("DOS", device_dir);
1450                 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1451                 acpi_device_dir(device) = NULL;
1452         }
1453
1454         return 0;
1455 }
1456
1457 /* --------------------------------------------------------------------------
1458                                  Driver Interface
1459    -------------------------------------------------------------------------- */
1460
1461 /* device interface */
1462 static struct acpi_video_device_attrib*
1463 acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1464 {
1465         struct acpi_video_enumerated_device *ids;
1466         int i;
1467
1468         for (i = 0; i < video->attached_count; i++) {
1469                 ids = &video->attached_array[i];
1470                 if ((ids->value.int_val & 0xffff) == device_id)
1471                         return &ids->value.attrib;
1472         }
1473
1474         return NULL;
1475 }
1476
1477 static int
1478 acpi_video_bus_get_one_device(struct acpi_device *device,
1479                               struct acpi_video_bus *video)
1480 {
1481         unsigned long long device_id;
1482         int status;
1483         struct acpi_video_device *data;
1484         struct acpi_video_device_attrib* attribute;
1485
1486         if (!device || !video)
1487                 return -EINVAL;
1488
1489         status =
1490             acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1491         if (ACPI_SUCCESS(status)) {
1492
1493                 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1494                 if (!data)
1495                         return -ENOMEM;
1496
1497                 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1498                 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1499                 device->driver_data = data;
1500
1501                 data->device_id = device_id;
1502                 data->video = video;
1503                 data->dev = device;
1504
1505                 attribute = acpi_video_get_device_attr(video, device_id);
1506
1507                 if((attribute != NULL) && attribute->device_id_scheme) {
1508                         switch (attribute->display_type) {
1509                         case ACPI_VIDEO_DISPLAY_CRT:
1510                                 data->flags.crt = 1;
1511                                 break;
1512                         case ACPI_VIDEO_DISPLAY_TV:
1513                                 data->flags.tvout = 1;
1514                                 break;
1515                         case ACPI_VIDEO_DISPLAY_DVI:
1516                                 data->flags.dvi = 1;
1517                                 break;
1518                         case ACPI_VIDEO_DISPLAY_LCD:
1519                                 data->flags.lcd = 1;
1520                                 break;
1521                         default:
1522                                 data->flags.unknown = 1;
1523                                 break;
1524                         }
1525                         if(attribute->bios_can_detect)
1526                                 data->flags.bios = 1;
1527                 } else
1528                         data->flags.unknown = 1;
1529
1530                 acpi_video_device_bind(video, data);
1531                 acpi_video_device_find_cap(data);
1532
1533                 status = acpi_install_notify_handler(device->handle,
1534                                                      ACPI_DEVICE_NOTIFY,
1535                                                      acpi_video_device_notify,
1536                                                      data);
1537                 if (ACPI_FAILURE(status)) {
1538                         printk(KERN_ERR PREFIX
1539                                           "Error installing notify handler\n");
1540                         if(data->brightness)
1541                                 kfree(data->brightness->levels);
1542                         kfree(data->brightness);
1543                         kfree(data);
1544                         return -ENODEV;
1545                 }
1546
1547                 mutex_lock(&video->device_list_lock);
1548                 list_add_tail(&data->entry, &video->video_device_list);
1549                 mutex_unlock(&video->device_list_lock);
1550
1551                 acpi_video_device_add_fs(device);
1552
1553                 return 0;
1554         }
1555
1556         return -ENOENT;
1557 }
1558
1559 /*
1560  *  Arg:
1561  *      video   : video bus device 
1562  *
1563  *  Return:
1564  *      none
1565  *  
1566  *  Enumerate the video device list of the video bus, 
1567  *  bind the ids with the corresponding video devices
1568  *  under the video bus.
1569  */
1570
1571 static void acpi_video_device_rebind(struct acpi_video_bus *video)
1572 {
1573         struct acpi_video_device *dev;
1574
1575         mutex_lock(&video->device_list_lock);
1576
1577         list_for_each_entry(dev, &video->video_device_list, entry)
1578                 acpi_video_device_bind(video, dev);
1579
1580         mutex_unlock(&video->device_list_lock);
1581 }
1582
1583 /*
1584  *  Arg:
1585  *      video   : video bus device 
1586  *      device  : video output device under the video 
1587  *              bus
1588  *
1589  *  Return:
1590  *      none
1591  *  
1592  *  Bind the ids with the corresponding video devices
1593  *  under the video bus.
1594  */
1595
1596 static void
1597 acpi_video_device_bind(struct acpi_video_bus *video,
1598                        struct acpi_video_device *device)
1599 {
1600         struct acpi_video_enumerated_device *ids;
1601         int i;
1602
1603         for (i = 0; i < video->attached_count; i++) {
1604                 ids = &video->attached_array[i];
1605                 if (device->device_id == (ids->value.int_val & 0xffff)) {
1606                         ids->bind_info = device;
1607                         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1608                 }
1609         }
1610 }
1611
1612 /*
1613  *  Arg:
1614  *      video   : video bus device 
1615  *
1616  *  Return:
1617  *      < 0     : error
1618  *  
1619  *  Call _DOD to enumerate all devices attached to display adapter
1620  *
1621  */
1622
1623 static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1624 {
1625         int status;
1626         int count;
1627         int i;
1628         struct acpi_video_enumerated_device *active_list;
1629         struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1630         union acpi_object *dod = NULL;
1631         union acpi_object *obj;
1632
1633         status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1634         if (!ACPI_SUCCESS(status)) {
1635                 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
1636                 return status;
1637         }
1638
1639         dod = buffer.pointer;
1640         if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1641                 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1642                 status = -EFAULT;
1643                 goto out;
1644         }
1645
1646         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1647                           dod->package.count));
1648
1649         active_list = kcalloc(1 + dod->package.count,
1650                               sizeof(struct acpi_video_enumerated_device),
1651                               GFP_KERNEL);
1652         if (!active_list) {
1653                 status = -ENOMEM;
1654                 goto out;
1655         }
1656
1657         count = 0;
1658         for (i = 0; i < dod->package.count; i++) {
1659                 obj = &dod->package.elements[i];
1660
1661                 if (obj->type != ACPI_TYPE_INTEGER) {
1662                         printk(KERN_ERR PREFIX
1663                                 "Invalid _DOD data in element %d\n", i);
1664                         continue;
1665                 }
1666
1667                 active_list[count].value.int_val = obj->integer.value;
1668                 active_list[count].bind_info = NULL;
1669                 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1670                                   (int)obj->integer.value));
1671                 count++;
1672         }
1673
1674         kfree(video->attached_array);
1675
1676         video->attached_array = active_list;
1677         video->attached_count = count;
1678
1679  out:
1680         kfree(buffer.pointer);
1681         return status;
1682 }
1683
1684 static int
1685 acpi_video_get_next_level(struct acpi_video_device *device,
1686                           u32 level_current, u32 event)
1687 {
1688         int min, max, min_above, max_below, i, l, delta = 255;
1689         max = max_below = 0;
1690         min = min_above = 255;
1691         /* Find closest level to level_current */
1692         for (i = 0; i < device->brightness->count; i++) {
1693                 l = device->brightness->levels[i];
1694                 if (abs(l - level_current) < abs(delta)) {
1695                         delta = l - level_current;
1696                         if (!delta)
1697                                 break;
1698                 }
1699         }
1700         /* Ajust level_current to closest available level */
1701         level_current += delta;
1702         for (i = 0; i < device->brightness->count; i++) {
1703                 l = device->brightness->levels[i];
1704                 if (l < min)
1705                         min = l;
1706                 if (l > max)
1707                         max = l;
1708                 if (l < min_above && l > level_current)
1709                         min_above = l;
1710                 if (l > max_below && l < level_current)
1711                         max_below = l;
1712         }
1713
1714         switch (event) {
1715         case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1716                 return (level_current < max) ? min_above : min;
1717         case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1718                 return (level_current < max) ? min_above : max;
1719         case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1720                 return (level_current > min) ? max_below : min;
1721         case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1722         case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1723                 return 0;
1724         default:
1725                 return level_current;
1726         }
1727 }
1728
1729 static void
1730 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1731 {
1732         unsigned long long level_current, level_next;
1733         if (!device->brightness)
1734                 return;
1735         acpi_video_device_lcd_get_level_current(device, &level_current);
1736         level_next = acpi_video_get_next_level(device, level_current, event);
1737         acpi_video_device_lcd_set_level(device, level_next);
1738 }
1739
1740 static int
1741 acpi_video_bus_get_devices(struct acpi_video_bus *video,
1742                            struct acpi_device *device)
1743 {
1744         int status = 0;
1745         struct acpi_device *dev;
1746
1747         acpi_video_device_enumerate(video);
1748
1749         list_for_each_entry(dev, &device->children, node) {
1750
1751                 status = acpi_video_bus_get_one_device(dev, video);
1752                 if (ACPI_FAILURE(status)) {
1753                         printk(KERN_WARNING PREFIX
1754                                         "Cant attach device");
1755                         continue;
1756                 }
1757         }
1758         return status;
1759 }
1760
1761 static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1762 {
1763         acpi_status status;
1764         struct acpi_video_bus *video;
1765
1766
1767         if (!device || !device->video)
1768                 return -ENOENT;
1769
1770         video = device->video;
1771
1772         acpi_video_device_remove_fs(device->dev);
1773
1774         status = acpi_remove_notify_handler(device->dev->handle,
1775                                             ACPI_DEVICE_NOTIFY,
1776                                             acpi_video_device_notify);
1777         backlight_device_unregister(device->backlight);
1778         if (device->cdev) {
1779                 sysfs_remove_link(&device->dev->dev.kobj,
1780                                   "thermal_cooling");
1781                 sysfs_remove_link(&device->cdev->device.kobj,
1782                                   "device");
1783                 thermal_cooling_device_unregister(device->cdev);
1784                 device->cdev = NULL;
1785         }
1786         video_output_unregister(device->output_dev);
1787
1788         return 0;
1789 }
1790
1791 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1792 {
1793         int status;
1794         struct acpi_video_device *dev, *next;
1795
1796         mutex_lock(&video->device_list_lock);
1797
1798         list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1799
1800                 status = acpi_video_bus_put_one_device(dev);
1801                 if (ACPI_FAILURE(status))
1802                         printk(KERN_WARNING PREFIX
1803                                "hhuuhhuu bug in acpi video driver.\n");
1804
1805                 if (dev->brightness) {
1806                         kfree(dev->brightness->levels);
1807                         kfree(dev->brightness);
1808                 }
1809                 list_del(&dev->entry);
1810                 kfree(dev);
1811         }
1812
1813         mutex_unlock(&video->device_list_lock);
1814
1815         return 0;
1816 }
1817
1818 /* acpi_video interface */
1819
1820 static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1821 {
1822         return acpi_video_bus_DOS(video, 0, 0);
1823 }
1824
1825 static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1826 {
1827         return acpi_video_bus_DOS(video, 0, 1);
1828 }
1829
1830 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1831 {
1832         struct acpi_video_bus *video = data;
1833         struct acpi_device *device = NULL;
1834         struct input_dev *input;
1835         int keycode;
1836
1837         if (!video)
1838                 return;
1839
1840         device = video->device;
1841         input = video->input;
1842
1843         switch (event) {
1844         case ACPI_VIDEO_NOTIFY_SWITCH:  /* User requested a switch,
1845                                          * most likely via hotkey. */
1846                 acpi_bus_generate_proc_event(device, event, 0);
1847                 keycode = KEY_SWITCHVIDEOMODE;
1848                 break;
1849
1850         case ACPI_VIDEO_NOTIFY_PROBE:   /* User plugged in or removed a video
1851                                          * connector. */
1852                 acpi_video_device_enumerate(video);
1853                 acpi_video_device_rebind(video);
1854                 acpi_bus_generate_proc_event(device, event, 0);
1855                 keycode = KEY_SWITCHVIDEOMODE;
1856                 break;
1857
1858         case ACPI_VIDEO_NOTIFY_CYCLE:   /* Cycle Display output hotkey pressed. */
1859                 acpi_bus_generate_proc_event(device, event, 0);
1860                 keycode = KEY_SWITCHVIDEOMODE;
1861                 break;
1862         case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:     /* Next Display output hotkey pressed. */
1863                 acpi_bus_generate_proc_event(device, event, 0);
1864                 keycode = KEY_VIDEO_NEXT;
1865                 break;
1866         case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:     /* previous Display output hotkey pressed. */
1867                 acpi_bus_generate_proc_event(device, event, 0);
1868                 keycode = KEY_VIDEO_PREV;
1869                 break;
1870
1871         default:
1872                 keycode = KEY_UNKNOWN;
1873                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1874                                   "Unsupported event [0x%x]\n", event));
1875                 break;
1876         }
1877
1878         acpi_notifier_call_chain(device, event, 0);
1879         input_report_key(input, keycode, 1);
1880         input_sync(input);
1881         input_report_key(input, keycode, 0);
1882         input_sync(input);
1883
1884         return;
1885 }
1886
1887 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1888 {
1889         struct acpi_video_device *video_device = data;
1890         struct acpi_device *device = NULL;
1891         struct acpi_video_bus *bus;
1892         struct input_dev *input;
1893         int keycode;
1894
1895         if (!video_device)
1896                 return;
1897
1898         device = video_device->dev;
1899         bus = video_device->video;
1900         input = bus->input;
1901
1902         switch (event) {
1903         case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:        /* Cycle 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_BRIGHTNESS_CYCLE;
1908                 break;
1909         case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:  /* Increase 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_BRIGHTNESSUP;
1914                 break;
1915         case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:  /* Decrease brightness */
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_BRIGHTNESSDOWN;
1920                 break;
1921         case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
1922                 if (brightness_switch_enabled)
1923                         acpi_video_switch_brightness(video_device, event);
1924                 acpi_bus_generate_proc_event(device, event, 0);
1925                 keycode = KEY_BRIGHTNESS_ZERO;
1926                 break;
1927         case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:     /* display device off */
1928                 if (brightness_switch_enabled)
1929                         acpi_video_switch_brightness(video_device, event);
1930                 acpi_bus_generate_proc_event(device, event, 0);
1931                 keycode = KEY_DISPLAY_OFF;
1932                 break;
1933         default:
1934                 keycode = KEY_UNKNOWN;
1935                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1936                                   "Unsupported event [0x%x]\n", event));
1937                 break;
1938         }
1939
1940         acpi_notifier_call_chain(device, event, 0);
1941         input_report_key(input, keycode, 1);
1942         input_sync(input);
1943         input_report_key(input, keycode, 0);
1944         input_sync(input);
1945
1946         return;
1947 }
1948
1949 static int instance;
1950 static int acpi_video_resume(struct acpi_device *device)
1951 {
1952         struct acpi_video_bus *video;
1953         struct acpi_video_device *video_device;
1954         int i;
1955
1956         if (!device || !acpi_driver_data(device))
1957                 return -EINVAL;
1958
1959         video = acpi_driver_data(device);
1960
1961         for (i = 0; i < video->attached_count; i++) {
1962                 video_device = video->attached_array[i].bind_info;
1963                 if (video_device && video_device->backlight)
1964                         acpi_video_set_brightness(video_device->backlight);
1965         }
1966         return AE_OK;
1967 }
1968
1969 static int acpi_video_bus_add(struct acpi_device *device)
1970 {
1971         acpi_status status;
1972         struct acpi_video_bus *video;
1973         struct input_dev *input;
1974         int error;
1975
1976         video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1977         if (!video)
1978                 return -ENOMEM;
1979
1980         /* a hack to fix the duplicate name "VID" problem on T61 */
1981         if (!strcmp(device->pnp.bus_id, "VID")) {
1982                 if (instance)
1983                         device->pnp.bus_id[3] = '0' + instance;
1984                 instance ++;
1985         }
1986
1987         video->device = device;
1988         strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1989         strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1990         device->driver_data = video;
1991
1992         acpi_video_bus_find_cap(video);
1993         error = acpi_video_bus_check(video);
1994         if (error)
1995                 goto err_free_video;
1996
1997         error = acpi_video_bus_add_fs(device);
1998         if (error)
1999                 goto err_free_video;
2000
2001         mutex_init(&video->device_list_lock);
2002         INIT_LIST_HEAD(&video->video_device_list);
2003
2004         acpi_video_bus_get_devices(video, device);
2005         acpi_video_bus_start_devices(video);
2006
2007         status = acpi_install_notify_handler(device->handle,
2008                                              ACPI_DEVICE_NOTIFY,
2009                                              acpi_video_bus_notify, video);
2010         if (ACPI_FAILURE(status)) {
2011                 printk(KERN_ERR PREFIX
2012                                   "Error installing notify handler\n");
2013                 error = -ENODEV;
2014                 goto err_stop_video;
2015         }
2016
2017         video->input = input = input_allocate_device();
2018         if (!input) {
2019                 error = -ENOMEM;
2020                 goto err_uninstall_notify;
2021         }
2022
2023         snprintf(video->phys, sizeof(video->phys),
2024                 "%s/video/input0", acpi_device_hid(video->device));
2025
2026         input->name = acpi_device_name(video->device);
2027         input->phys = video->phys;
2028         input->id.bustype = BUS_HOST;
2029         input->id.product = 0x06;
2030         input->dev.parent = &device->dev;
2031         input->evbit[0] = BIT(EV_KEY);
2032         set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2033         set_bit(KEY_VIDEO_NEXT, input->keybit);
2034         set_bit(KEY_VIDEO_PREV, input->keybit);
2035         set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2036         set_bit(KEY_BRIGHTNESSUP, input->keybit);
2037         set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2038         set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2039         set_bit(KEY_DISPLAY_OFF, input->keybit);
2040         set_bit(KEY_UNKNOWN, input->keybit);
2041
2042         error = input_register_device(input);
2043         if (error)
2044                 goto err_free_input_dev;
2045
2046         printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s  rom: %s  post: %s)\n",
2047                ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2048                video->flags.multihead ? "yes" : "no",
2049                video->flags.rom ? "yes" : "no",
2050                video->flags.post ? "yes" : "no");
2051
2052         return 0;
2053
2054  err_free_input_dev:
2055         input_free_device(input);
2056  err_uninstall_notify:
2057         acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2058                                    acpi_video_bus_notify);
2059  err_stop_video:
2060         acpi_video_bus_stop_devices(video);
2061         acpi_video_bus_put_devices(video);
2062         kfree(video->attached_array);
2063         acpi_video_bus_remove_fs(device);
2064  err_free_video:
2065         kfree(video);
2066         device->driver_data = NULL;
2067
2068         return error;
2069 }
2070
2071 static int acpi_video_bus_remove(struct acpi_device *device, int type)
2072 {
2073         acpi_status status = 0;
2074         struct acpi_video_bus *video = NULL;
2075
2076
2077         if (!device || !acpi_driver_data(device))
2078                 return -EINVAL;
2079
2080         video = acpi_driver_data(device);
2081
2082         acpi_video_bus_stop_devices(video);
2083
2084         status = acpi_remove_notify_handler(video->device->handle,
2085                                             ACPI_DEVICE_NOTIFY,
2086                                             acpi_video_bus_notify);
2087
2088         acpi_video_bus_put_devices(video);
2089         acpi_video_bus_remove_fs(device);
2090
2091         input_unregister_device(video->input);
2092         kfree(video->attached_array);
2093         kfree(video);
2094
2095         return 0;
2096 }
2097
2098 static int __init acpi_video_init(void)
2099 {
2100         int result = 0;
2101
2102
2103         /*
2104            acpi_dbg_level = 0xFFFFFFFF;
2105            acpi_dbg_layer = 0x08000000;
2106          */
2107
2108         acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2109         if (!acpi_video_dir)
2110                 return -ENODEV;
2111         acpi_video_dir->owner = THIS_MODULE;
2112
2113         result = acpi_bus_register_driver(&acpi_video_bus);
2114         if (result < 0) {
2115                 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2116                 return -ENODEV;
2117         }
2118
2119         return 0;
2120 }
2121
2122 static void __exit acpi_video_exit(void)
2123 {
2124
2125         acpi_bus_unregister_driver(&acpi_video_bus);
2126
2127         remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2128
2129         return;
2130 }
2131
2132 module_init(acpi_video_init);
2133 module_exit(acpi_video_exit);