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