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