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