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