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