]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/acpi/video.c
ACPI: video: DMI workaround broken Acer 5315 BIOS enabling display brightness
[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 },
5afc4abe
LB
565 {
566 .callback = video_set_bqc_offset,
567 .ident = "Acer Aspire 5710Z",
568 .matches = {
569 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
570 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"),
571 },
572 },
34ac272b
ZR
573 {
574 .callback = video_set_bqc_offset,
575 .ident = "eMachines E510",
576 .matches = {
577 DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"),
578 DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"),
579 },
580 },
93bcece2
ZR
581 {
582 .callback = video_set_bqc_offset,
583 .ident = "Acer Aspire 5315",
584 .matches = {
585 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
586 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"),
587 },
588 },
45cb50e6
ZR
589 {}
590};
591
1da177e4 592static int
4be44fcd 593acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
27663c58 594 unsigned long long *level)
1da177e4 595{
c8890f90
ZR
596 acpi_status status = AE_OK;
597
c60d638e
ZR
598 if (device->cap._BQC || device->cap._BCQ) {
599 char *buf = device->cap._BQC ? "_BQC" : "_BCQ";
600
601 status = acpi_evaluate_integer(device->dev->handle, buf,
c8890f90
ZR
602 NULL, level);
603 if (ACPI_SUCCESS(status)) {
1a7c618a
ZR
604 if (device->brightness->flags._BQC_use_index) {
605 if (device->brightness->flags._BCL_reversed)
606 *level = device->brightness->count
607 - 3 - (*level);
608 *level = device->brightness->levels[*level + 2];
609
610 }
45cb50e6 611 *level += bqc_offset_aml_bug_workaround;
c8890f90
ZR
612 device->brightness->curr = *level;
613 return 0;
614 } else {
615 /* Fixme:
616 * should we return an error or ignore this failure?
617 * dev->brightness->curr is a cached value which stores
618 * the correct current backlight level in most cases.
619 * ACPI video backlight still works w/ buggy _BQC.
620 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
621 */
c60d638e
ZR
622 ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf));
623 device->cap._BQC = device->cap._BCQ = 0;
c8890f90
ZR
624 }
625 }
626
4500ca8e 627 *level = device->brightness->curr;
c8890f90 628 return 0;
1da177e4
LT
629}
630
631static int
4be44fcd
LB
632acpi_video_device_EDID(struct acpi_video_device *device,
633 union acpi_object **edid, ssize_t length)
1da177e4 634{
4be44fcd
LB
635 int status;
636 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
637 union acpi_object *obj;
638 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
639 struct acpi_object_list args = { 1, &arg0 };
1da177e4 640
1da177e4
LT
641
642 *edid = NULL;
643
644 if (!device)
d550d98d 645 return -ENODEV;
1da177e4
LT
646 if (length == 128)
647 arg0.integer.value = 1;
648 else if (length == 256)
649 arg0.integer.value = 2;
650 else
d550d98d 651 return -EINVAL;
1da177e4 652
90130268 653 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
1da177e4 654 if (ACPI_FAILURE(status))
d550d98d 655 return -ENODEV;
1da177e4 656
50dd0969 657 obj = buffer.pointer;
1da177e4
LT
658
659 if (obj && obj->type == ACPI_TYPE_BUFFER)
660 *edid = obj;
661 else {
6468463a 662 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
1da177e4
LT
663 status = -EFAULT;
664 kfree(obj);
665 }
666
d550d98d 667 return status;
1da177e4
LT
668}
669
1da177e4
LT
670/* bus */
671
672static int
4be44fcd 673acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
1da177e4 674{
4be44fcd 675 int status;
27663c58 676 unsigned long long tmp;
4be44fcd
LB
677 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
678 struct acpi_object_list args = { 1, &arg0 };
1da177e4 679
1da177e4
LT
680
681 arg0.integer.value = option;
682
90130268 683 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
1da177e4 684 if (ACPI_SUCCESS(status))
4be44fcd 685 status = tmp ? (-EINVAL) : (AE_OK);
1da177e4 686
d550d98d 687 return status;
1da177e4
LT
688}
689
690static int
27663c58 691acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
1da177e4
LT
692{
693 int status;
694
90130268 695 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
1da177e4 696
d550d98d 697 return status;
1da177e4
LT
698}
699
700static int
4be44fcd 701acpi_video_bus_POST_options(struct acpi_video_bus *video,
27663c58 702 unsigned long long *options)
1da177e4 703{
4be44fcd 704 int status;
1da177e4 705
90130268 706 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
1da177e4
LT
707 *options &= 3;
708
d550d98d 709 return status;
1da177e4
LT
710}
711
712/*
713 * Arg:
714 * video : video bus device pointer
715 * bios_flag :
716 * 0. The system BIOS should NOT automatically switch(toggle)
717 * the active display output.
718 * 1. The system BIOS should automatically switch (toggle) the
98fb8fe1 719 * active display output. No switch event.
1da177e4
LT
720 * 2. The _DGS value should be locked.
721 * 3. The system BIOS should not automatically switch (toggle) the
722 * active display output, but instead generate the display switch
723 * event notify code.
724 * lcd_flag :
725 * 0. The system BIOS should automatically control the brightness level
98fb8fe1 726 * of the LCD when the power changes from AC to DC
1da177e4 727 * 1. The system BIOS should NOT automatically control the brightness
98fb8fe1 728 * level of the LCD when the power changes from AC to DC.
1da177e4
LT
729 * Return Value:
730 * -1 wrong arg.
731 */
732
733static int
4be44fcd 734acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
1da177e4 735{
4be44fcd
LB
736 acpi_integer status = 0;
737 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
738 struct acpi_object_list args = { 1, &arg0 };
1da177e4 739
1da177e4 740
4be44fcd 741 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
1da177e4
LT
742 status = -1;
743 goto Failed;
744 }
745 arg0.integer.value = (lcd_flag << 2) | bios_flag;
746 video->dos_setting = arg0.integer.value;
90130268 747 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
1da177e4 748
4be44fcd 749 Failed:
d550d98d 750 return status;
1da177e4
LT
751}
752
935e5f29
ZR
753/*
754 * Simple comparison function used to sort backlight levels.
755 */
756
757static int
758acpi_video_cmp_level(const void *a, const void *b)
759{
760 return *(int *)a - *(int *)b;
761}
762
1da177e4
LT
763/*
764 * Arg:
765 * device : video output device (LCD, CRT, ..)
766 *
767 * Return Value:
469778c1
JJ
768 * Maximum brightness level
769 *
770 * Allocate and initialize device->brightness.
771 */
772
773static int
774acpi_video_init_brightness(struct acpi_video_device *device)
775{
776 union acpi_object *obj = NULL;
d32f6947 777 int i, max_level = 0, count = 0, level_ac_battery = 0;
1a7c618a 778 unsigned long long level, level_old;
469778c1
JJ
779 union acpi_object *o;
780 struct acpi_video_device_brightness *br = NULL;
1a7c618a 781 int result = -EINVAL;
469778c1
JJ
782
783 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
785 "LCD brightness level\n"));
786 goto out;
787 }
788
789 if (obj->package.count < 2)
790 goto out;
791
792 br = kzalloc(sizeof(*br), GFP_KERNEL);
793 if (!br) {
794 printk(KERN_ERR "can't allocate memory\n");
1a7c618a 795 result = -ENOMEM;
469778c1
JJ
796 goto out;
797 }
798
d32f6947 799 br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
469778c1 800 GFP_KERNEL);
1a7c618a
ZR
801 if (!br->levels) {
802 result = -ENOMEM;
469778c1 803 goto out_free;
1a7c618a 804 }
469778c1
JJ
805
806 for (i = 0; i < obj->package.count; i++) {
807 o = (union acpi_object *)&obj->package.elements[i];
808 if (o->type != ACPI_TYPE_INTEGER) {
809 printk(KERN_ERR PREFIX "Invalid data\n");
810 continue;
811 }
812 br->levels[count] = (u32) o->integer.value;
813
814 if (br->levels[count] > max_level)
815 max_level = br->levels[count];
816 count++;
817 }
818
d32f6947
ZR
819 /*
820 * some buggy BIOS don't export the levels
821 * when machine is on AC/Battery in _BCL package.
822 * In this case, the first two elements in _BCL packages
823 * are also supported brightness levels that OS should take care of.
824 */
90af2cf6
ZR
825 for (i = 2; i < count; i++) {
826 if (br->levels[i] == br->levels[0])
d32f6947 827 level_ac_battery++;
90af2cf6
ZR
828 if (br->levels[i] == br->levels[1])
829 level_ac_battery++;
830 }
d32f6947
ZR
831
832 if (level_ac_battery < 2) {
833 level_ac_battery = 2 - level_ac_battery;
834 br->flags._BCL_no_ac_battery_levels = 1;
835 for (i = (count - 1 + level_ac_battery); i >= 2; i--)
836 br->levels[i] = br->levels[i - level_ac_battery];
837 count += level_ac_battery;
838 } else if (level_ac_battery > 2)
839 ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n"));
840
d80fb99f
ZR
841 /* Check if the _BCL package is in a reversed order */
842 if (max_level == br->levels[2]) {
843 br->flags._BCL_reversed = 1;
844 sort(&br->levels[2], count - 2, sizeof(br->levels[2]),
845 acpi_video_cmp_level, NULL);
846 } else if (max_level != br->levels[count - 1])
847 ACPI_ERROR((AE_INFO,
848 "Found unordered _BCL package\n"));
469778c1
JJ
849
850 br->count = count;
851 device->brightness = br;
1a7c618a
ZR
852
853 /* Check the input/output of _BQC/_BCL/_BCM */
854 if ((max_level < 100) && (max_level <= (count - 2)))
855 br->flags._BCL_use_index = 1;
856
857 /*
858 * _BCM is always consistent with _BCL,
859 * at least for all the laptops we have ever seen.
860 */
861 br->flags._BCM_use_index = br->flags._BCL_use_index;
862
863 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
e047cca6
ZR
864 br->curr = level_old = max_level;
865
866 if (!device->cap._BQC)
867 goto set_level;
868
1a7c618a
ZR
869 result = acpi_video_device_lcd_get_level_current(device, &level_old);
870 if (result)
871 goto out_free_levels;
872
e047cca6
ZR
873 /*
874 * Set the level to maximum and check if _BQC uses indexed value
875 */
876 result = acpi_video_device_lcd_set_level(device, max_level);
1a7c618a
ZR
877 if (result)
878 goto out_free_levels;
879
880 result = acpi_video_device_lcd_get_level_current(device, &level);
881 if (result)
882 goto out_free_levels;
883
e047cca6
ZR
884 br->flags._BQC_use_index = (level == max_level ? 0 : 1);
885
886 if (!br->flags._BQC_use_index)
887 goto set_level;
888
889 if (br->flags._BCL_reversed)
890 level_old = (br->count - 1) - level_old;
891 level_old = br->levels[level_old];
892
893set_level:
894 result = acpi_video_device_lcd_set_level(device, level_old);
895 if (result)
896 goto out_free_levels;
1a7c618a 897
d32f6947
ZR
898 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
899 "found %d brightness levels\n", count - 2));
469778c1 900 kfree(obj);
1a7c618a 901 return result;
469778c1
JJ
902
903out_free_levels:
904 kfree(br->levels);
905out_free:
906 kfree(br);
907out:
908 device->brightness = NULL;
909 kfree(obj);
1a7c618a 910 return result;
469778c1
JJ
911}
912
913/*
914 * Arg:
915 * device : video output device (LCD, CRT, ..)
916 *
917 * Return Value:
1da177e4
LT
918 * None
919 *
98fb8fe1 920 * Find out all required AML methods defined under the output
1da177e4
LT
921 * device.
922 */
923
4be44fcd 924static void acpi_video_device_find_cap(struct acpi_video_device *device)
1da177e4 925{
1da177e4 926 acpi_handle h_dummy1;
1da177e4 927
1da177e4 928
98934def 929 memset(&device->cap, 0, sizeof(device->cap));
1da177e4 930
90130268 931 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
1da177e4
LT
932 device->cap._ADR = 1;
933 }
90130268 934 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
4be44fcd 935 device->cap._BCL = 1;
1da177e4 936 }
90130268 937 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
4be44fcd 938 device->cap._BCM = 1;
1da177e4 939 }
2f3d000a
YL
940 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
941 device->cap._BQC = 1;
c60d638e
ZR
942 else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ",
943 &h_dummy1))) {
944 printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n");
945 device->cap._BCQ = 1;
946 }
947
90130268 948 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
4be44fcd 949 device->cap._DDC = 1;
1da177e4 950 }
90130268 951 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
1da177e4
LT
952 device->cap._DCS = 1;
953 }
90130268 954 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
1da177e4
LT
955 device->cap._DGS = 1;
956 }
90130268 957 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
1da177e4
LT
958 device->cap._DSS = 1;
959 }
960
1a7c618a 961 if (acpi_video_backlight_support()) {
702ed512 962 int result;
2f3d000a
YL
963 static int count = 0;
964 char *name;
1a7c618a
ZR
965
966 result = acpi_video_init_brightness(device);
967 if (result)
968 return;
2f3d000a
YL
969 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
970 if (!name)
971 return;
972
2f3d000a 973 sprintf(name, "acpi_video%d", count++);
2f3d000a 974 device->backlight = backlight_device_register(name,
599a52d1 975 NULL, device, &acpi_backlight_ops);
38531e6f 976 device->backlight->props.max_brightness = device->brightness->count-3;
2f3d000a 977 kfree(name);
702ed512
ZR
978
979 device->cdev = thermal_cooling_device_register("LCD",
980 device->dev, &video_cooling_ops);
43ff39f2
TS
981 if (IS_ERR(device->cdev))
982 return;
983
fc3a8828
GKH
984 dev_info(&device->dev->dev, "registered as cooling_device%d\n",
985 device->cdev->id);
9030062f
JL
986 result = sysfs_create_link(&device->dev->dev.kobj,
987 &device->cdev->device.kobj,
988 "thermal_cooling");
989 if (result)
990 printk(KERN_ERR PREFIX "Create sysfs link\n");
991 result = sysfs_create_link(&device->cdev->device.kobj,
992 &device->dev->dev.kobj, "device");
993 if (result)
994 printk(KERN_ERR PREFIX "Create sysfs link\n");
995
2f3d000a 996 }
c3d6de69
TR
997
998 if (acpi_video_display_switch_support()) {
999
1000 if (device->cap._DCS && device->cap._DSS) {
1001 static int count;
1002 char *name;
1003 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
1004 if (!name)
1005 return;
1006 sprintf(name, "acpi_video%d", count++);
1007 device->output_dev = video_output_register(name,
1008 NULL, device, &acpi_output_properties);
1009 kfree(name);
1010 }
23b0f015 1011 }
1da177e4
LT
1012}
1013
1014/*
1015 * Arg:
1016 * device : video output device (VGA)
1017 *
1018 * Return Value:
1019 * None
1020 *
98fb8fe1 1021 * Find out all required AML methods defined under the video bus device.
1da177e4
LT
1022 */
1023
4be44fcd 1024static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
1da177e4 1025{
4be44fcd 1026 acpi_handle h_dummy1;
1da177e4 1027
98934def 1028 memset(&video->cap, 0, sizeof(video->cap));
90130268 1029 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
1da177e4
LT
1030 video->cap._DOS = 1;
1031 }
90130268 1032 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
1da177e4
LT
1033 video->cap._DOD = 1;
1034 }
90130268 1035 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
1da177e4
LT
1036 video->cap._ROM = 1;
1037 }
90130268 1038 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
1da177e4
LT
1039 video->cap._GPD = 1;
1040 }
90130268 1041 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
1da177e4
LT
1042 video->cap._SPD = 1;
1043 }
90130268 1044 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
1da177e4
LT
1045 video->cap._VPO = 1;
1046 }
1047}
1048
1049/*
1050 * Check whether the video bus device has required AML method to
1051 * support the desired features
1052 */
1053
4be44fcd 1054static int acpi_video_bus_check(struct acpi_video_bus *video)
1da177e4 1055{
4be44fcd 1056 acpi_status status = -ENOENT;
22c13f9d 1057 struct device *dev;
1da177e4
LT
1058
1059 if (!video)
d550d98d 1060 return -EINVAL;
1da177e4 1061
22c13f9d
TR
1062 dev = acpi_get_physical_pci_device(video->device->handle);
1063 if (!dev)
1064 return -ENODEV;
1065 put_device(dev);
1066
1da177e4
LT
1067 /* Since there is no HID, CID and so on for VGA driver, we have
1068 * to check well known required nodes.
1069 */
1070
98fb8fe1 1071 /* Does this device support video switching? */
4be44fcd 1072 if (video->cap._DOS) {
1da177e4
LT
1073 video->flags.multihead = 1;
1074 status = 0;
1075 }
1076
98fb8fe1 1077 /* Does this device support retrieving a video ROM? */
4be44fcd 1078 if (video->cap._ROM) {
1da177e4
LT
1079 video->flags.rom = 1;
1080 status = 0;
1081 }
1082
98fb8fe1 1083 /* Does this device support configuring which video device to POST? */
4be44fcd 1084 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
1da177e4
LT
1085 video->flags.post = 1;
1086 status = 0;
1087 }
1088
d550d98d 1089 return status;
1da177e4
LT
1090}
1091
1092/* --------------------------------------------------------------------------
1093 FS Interface (/proc)
1094 -------------------------------------------------------------------------- */
1095
4be44fcd 1096static struct proc_dir_entry *acpi_video_dir;
1da177e4
LT
1097
1098/* video devices */
1099
4be44fcd 1100static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
1da177e4 1101{
50dd0969 1102 struct acpi_video_device *dev = seq->private;
1da177e4 1103
1da177e4
LT
1104
1105 if (!dev)
1106 goto end;
1107
1108 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
1109 seq_printf(seq, "type: ");
1110 if (dev->flags.crt)
1111 seq_printf(seq, "CRT\n");
1112 else if (dev->flags.lcd)
1113 seq_printf(seq, "LCD\n");
1114 else if (dev->flags.tvout)
1115 seq_printf(seq, "TVOUT\n");
82cae999
RZ
1116 else if (dev->flags.dvi)
1117 seq_printf(seq, "DVI\n");
1da177e4
LT
1118 else
1119 seq_printf(seq, "UNKNOWN\n");
1120
4be44fcd 1121 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
1da177e4 1122
4be44fcd 1123 end:
d550d98d 1124 return 0;
1da177e4
LT
1125}
1126
1127static int
4be44fcd 1128acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
1da177e4
LT
1129{
1130 return single_open(file, acpi_video_device_info_seq_show,
1131 PDE(inode)->data);
1132}
1133
4be44fcd 1134static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
1da177e4 1135{
4be44fcd 1136 int status;
50dd0969 1137 struct acpi_video_device *dev = seq->private;
27663c58 1138 unsigned long long state;
1da177e4 1139
1da177e4
LT
1140
1141 if (!dev)
1142 goto end;
1143
1144 status = acpi_video_device_get_state(dev, &state);
1145 seq_printf(seq, "state: ");
1146 if (ACPI_SUCCESS(status))
27663c58 1147 seq_printf(seq, "0x%02llx\n", state);
1da177e4
LT
1148 else
1149 seq_printf(seq, "<not supported>\n");
1150
1151 status = acpi_video_device_query(dev, &state);
1152 seq_printf(seq, "query: ");
1153 if (ACPI_SUCCESS(status))
27663c58 1154 seq_printf(seq, "0x%02llx\n", state);
1da177e4
LT
1155 else
1156 seq_printf(seq, "<not supported>\n");
1157
4be44fcd 1158 end:
d550d98d 1159 return 0;
1da177e4
LT
1160}
1161
1162static int
4be44fcd 1163acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
1da177e4
LT
1164{
1165 return single_open(file, acpi_video_device_state_seq_show,
1166 PDE(inode)->data);
1167}
1168
1169static ssize_t
4be44fcd
LB
1170acpi_video_device_write_state(struct file *file,
1171 const char __user * buffer,
1172 size_t count, loff_t * data)
1da177e4 1173{
4be44fcd 1174 int status;
50dd0969
JE
1175 struct seq_file *m = file->private_data;
1176 struct acpi_video_device *dev = m->private;
4be44fcd
LB
1177 char str[12] = { 0 };
1178 u32 state = 0;
1da177e4 1179
1da177e4
LT
1180
1181 if (!dev || count + 1 > sizeof str)
d550d98d 1182 return -EINVAL;
1da177e4
LT
1183
1184 if (copy_from_user(str, buffer, count))
d550d98d 1185 return -EFAULT;
1da177e4
LT
1186
1187 str[count] = 0;
1188 state = simple_strtoul(str, NULL, 0);
4be44fcd 1189 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1da177e4
LT
1190
1191 status = acpi_video_device_set_state(dev, state);
1192
1193 if (status)
d550d98d 1194 return -EFAULT;
1da177e4 1195
d550d98d 1196 return count;
1da177e4
LT
1197}
1198
1199static int
4be44fcd 1200acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
1da177e4 1201{
50dd0969 1202 struct acpi_video_device *dev = seq->private;
4be44fcd 1203 int i;
1da177e4 1204
1da177e4
LT
1205
1206 if (!dev || !dev->brightness) {
1207 seq_printf(seq, "<not supported>\n");
d550d98d 1208 return 0;
1da177e4
LT
1209 }
1210
1211 seq_printf(seq, "levels: ");
0a3db1ce 1212 for (i = 2; i < dev->brightness->count; i++)
1da177e4
LT
1213 seq_printf(seq, " %d", dev->brightness->levels[i]);
1214 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
1215
d550d98d 1216 return 0;
1da177e4
LT
1217}
1218
1219static int
4be44fcd 1220acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
1da177e4
LT
1221{
1222 return single_open(file, acpi_video_device_brightness_seq_show,
1223 PDE(inode)->data);
1224}
1225
1226static ssize_t
4be44fcd
LB
1227acpi_video_device_write_brightness(struct file *file,
1228 const char __user * buffer,
1229 size_t count, loff_t * data)
1da177e4 1230{
50dd0969
JE
1231 struct seq_file *m = file->private_data;
1232 struct acpi_video_device *dev = m->private;
c88c5786 1233 char str[5] = { 0 };
4be44fcd
LB
1234 unsigned int level = 0;
1235 int i;
1da177e4 1236
1da177e4 1237
59d399d3 1238 if (!dev || !dev->brightness || count + 1 > sizeof str)
d550d98d 1239 return -EINVAL;
1da177e4
LT
1240
1241 if (copy_from_user(str, buffer, count))
d550d98d 1242 return -EFAULT;
1da177e4
LT
1243
1244 str[count] = 0;
1245 level = simple_strtoul(str, NULL, 0);
4be44fcd 1246
1da177e4 1247 if (level > 100)
d550d98d 1248 return -EFAULT;
1da177e4 1249
98fb8fe1 1250 /* validate through the list of available levels */
0a3db1ce 1251 for (i = 2; i < dev->brightness->count; i++)
1da177e4 1252 if (level == dev->brightness->levels[i]) {
24450c7a
ZR
1253 if (!acpi_video_device_lcd_set_level(dev, level))
1254 return count;
1da177e4
LT
1255 break;
1256 }
1257
24450c7a 1258 return -EINVAL;
1da177e4
LT
1259}
1260
4be44fcd 1261static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
1da177e4 1262{
50dd0969 1263 struct acpi_video_device *dev = seq->private;
4be44fcd
LB
1264 int status;
1265 int i;
1266 union acpi_object *edid = NULL;
1da177e4 1267
1da177e4
LT
1268
1269 if (!dev)
1270 goto out;
1271
4be44fcd 1272 status = acpi_video_device_EDID(dev, &edid, 128);
1da177e4 1273 if (ACPI_FAILURE(status)) {
4be44fcd 1274 status = acpi_video_device_EDID(dev, &edid, 256);
1da177e4
LT
1275 }
1276
1277 if (ACPI_FAILURE(status)) {
1278 goto out;
1279 }
1280
1281 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1282 for (i = 0; i < edid->buffer.length; i++)
1283 seq_putc(seq, edid->buffer.pointer[i]);
1284 }
1285
4be44fcd 1286 out:
1da177e4
LT
1287 if (!edid)
1288 seq_printf(seq, "<not supported>\n");
1289 else
1290 kfree(edid);
1291
d550d98d 1292 return 0;
1da177e4
LT
1293}
1294
1295static int
4be44fcd 1296acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1da177e4
LT
1297{
1298 return single_open(file, acpi_video_device_EDID_seq_show,
1299 PDE(inode)->data);
1300}
1301
4be44fcd 1302static int acpi_video_device_add_fs(struct acpi_device *device)
1da177e4 1303{
251cb0bc 1304 struct proc_dir_entry *entry, *device_dir;
1da177e4
LT
1305 struct acpi_video_device *vid_dev;
1306
50dd0969 1307 vid_dev = acpi_driver_data(device);
1da177e4 1308 if (!vid_dev)
d550d98d 1309 return -ENODEV;
1da177e4 1310
251cb0bc
DT
1311 device_dir = proc_mkdir(acpi_device_bid(device),
1312 vid_dev->video->dir);
1313 if (!device_dir)
1314 return -ENOMEM;
1315
1da177e4 1316 /* 'info' [R] */
e0066c4e 1317 entry = proc_create_data("info", S_IRUGO, device_dir,
cf7acfab 1318 &acpi_video_device_info_fops, acpi_driver_data(device));
1da177e4 1319 if (!entry)
251cb0bc 1320 goto err_remove_dir;
1da177e4
LT
1321
1322 /* 'state' [R/W] */
cf7acfab 1323 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
e0066c4e 1324 device_dir,
cf7acfab
DL
1325 &acpi_video_device_state_fops,
1326 acpi_driver_data(device));
1da177e4 1327 if (!entry)
251cb0bc 1328 goto err_remove_info;
1da177e4
LT
1329
1330 /* 'brightness' [R/W] */
cf7acfab 1331 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
e0066c4e 1332 device_dir,
cf7acfab
DL
1333 &acpi_video_device_brightness_fops,
1334 acpi_driver_data(device));
1da177e4 1335 if (!entry)
251cb0bc 1336 goto err_remove_state;
1da177e4
LT
1337
1338 /* 'EDID' [R] */
e0066c4e 1339 entry = proc_create_data("EDID", S_IRUGO, device_dir,
cf7acfab
DL
1340 &acpi_video_device_EDID_fops,
1341 acpi_driver_data(device));
1da177e4 1342 if (!entry)
251cb0bc 1343 goto err_remove_brightness;
1da177e4 1344
e0066c4e
AD
1345 acpi_device_dir(device) = device_dir;
1346
d550d98d 1347 return 0;
251cb0bc
DT
1348
1349 err_remove_brightness:
1350 remove_proc_entry("brightness", device_dir);
1351 err_remove_state:
1352 remove_proc_entry("state", device_dir);
1353 err_remove_info:
1354 remove_proc_entry("info", device_dir);
1355 err_remove_dir:
1356 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1357 return -ENOMEM;
1da177e4
LT
1358}
1359
4be44fcd 1360static int acpi_video_device_remove_fs(struct acpi_device *device)
1da177e4
LT
1361{
1362 struct acpi_video_device *vid_dev;
251cb0bc 1363 struct proc_dir_entry *device_dir;
1da177e4 1364
50dd0969 1365 vid_dev = acpi_driver_data(device);
1da177e4 1366 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
d550d98d 1367 return -ENODEV;
1da177e4 1368
251cb0bc
DT
1369 device_dir = acpi_device_dir(device);
1370 if (device_dir) {
1371 remove_proc_entry("info", device_dir);
1372 remove_proc_entry("state", device_dir);
1373 remove_proc_entry("brightness", device_dir);
1374 remove_proc_entry("EDID", device_dir);
4be44fcd 1375 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1da177e4
LT
1376 acpi_device_dir(device) = NULL;
1377 }
1378
d550d98d 1379 return 0;
1da177e4
LT
1380}
1381
1da177e4 1382/* video bus */
4be44fcd 1383static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
1da177e4 1384{
50dd0969 1385 struct acpi_video_bus *video = seq->private;
1da177e4 1386
1da177e4
LT
1387
1388 if (!video)
1389 goto end;
1390
1391 seq_printf(seq, "Switching heads: %s\n",
4be44fcd 1392 video->flags.multihead ? "yes" : "no");
1da177e4 1393 seq_printf(seq, "Video ROM: %s\n",
4be44fcd 1394 video->flags.rom ? "yes" : "no");
1da177e4 1395 seq_printf(seq, "Device to be POSTed on boot: %s\n",
4be44fcd 1396 video->flags.post ? "yes" : "no");
1da177e4 1397
4be44fcd 1398 end:
d550d98d 1399 return 0;
1da177e4
LT
1400}
1401
4be44fcd 1402static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
1da177e4 1403{
4be44fcd
LB
1404 return single_open(file, acpi_video_bus_info_seq_show,
1405 PDE(inode)->data);
1da177e4
LT
1406}
1407
4be44fcd 1408static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
1da177e4 1409{
50dd0969 1410 struct acpi_video_bus *video = seq->private;
1da177e4 1411
1da177e4
LT
1412
1413 if (!video)
1414 goto end;
1415
96b2dd1f 1416 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
1da177e4
LT
1417 seq_printf(seq, "<TODO>\n");
1418
4be44fcd 1419 end:
d550d98d 1420 return 0;
1da177e4
LT
1421}
1422
4be44fcd 1423static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1da177e4
LT
1424{
1425 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1426}
1427
4be44fcd 1428static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1da177e4 1429{
50dd0969 1430 struct acpi_video_bus *video = seq->private;
27663c58 1431 unsigned long long options;
4be44fcd 1432 int status;
1da177e4 1433
1da177e4
LT
1434
1435 if (!video)
1436 goto end;
1437
1438 status = acpi_video_bus_POST_options(video, &options);
1439 if (ACPI_SUCCESS(status)) {
1440 if (!(options & 1)) {
4be44fcd
LB
1441 printk(KERN_WARNING PREFIX
1442 "The motherboard VGA device is not listed as a possible POST device.\n");
1443 printk(KERN_WARNING PREFIX
98fb8fe1 1444 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1da177e4 1445 }
4d939155 1446 printk(KERN_WARNING "%llx\n", options);
98fb8fe1 1447 seq_printf(seq, "can POST: <integrated video>");
1da177e4
LT
1448 if (options & 2)
1449 seq_printf(seq, " <PCI video>");
1450 if (options & 4)
1451 seq_printf(seq, " <AGP video>");
1452 seq_putc(seq, '\n');
1453 } else
1454 seq_printf(seq, "<not supported>\n");
4be44fcd 1455 end:
d550d98d 1456 return 0;
1da177e4
LT
1457}
1458
1459static int
4be44fcd 1460acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1da177e4 1461{
4be44fcd
LB
1462 return single_open(file, acpi_video_bus_POST_info_seq_show,
1463 PDE(inode)->data);
1da177e4
LT
1464}
1465
4be44fcd 1466static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1da177e4 1467{
50dd0969 1468 struct acpi_video_bus *video = seq->private;
4be44fcd 1469 int status;
27663c58 1470 unsigned long long id;
1da177e4 1471
1da177e4
LT
1472
1473 if (!video)
1474 goto end;
1475
4be44fcd 1476 status = acpi_video_bus_get_POST(video, &id);
1da177e4
LT
1477 if (!ACPI_SUCCESS(status)) {
1478 seq_printf(seq, "<not supported>\n");
1479 goto end;
1480 }
98fb8fe1 1481 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
1da177e4 1482
4be44fcd 1483 end:
d550d98d 1484 return 0;
1da177e4
LT
1485}
1486
4be44fcd 1487static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1da177e4 1488{
50dd0969 1489 struct acpi_video_bus *video = seq->private;
1da177e4 1490
1da177e4 1491
4be44fcd 1492 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
1da177e4 1493
d550d98d 1494 return 0;
1da177e4
LT
1495}
1496
4be44fcd 1497static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
1da177e4 1498{
4be44fcd
LB
1499 return single_open(file, acpi_video_bus_POST_seq_show,
1500 PDE(inode)->data);
1da177e4
LT
1501}
1502
4be44fcd 1503static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1da177e4
LT
1504{
1505 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1506}
1507
1508static ssize_t
4be44fcd
LB
1509acpi_video_bus_write_POST(struct file *file,
1510 const char __user * buffer,
1511 size_t count, loff_t * data)
1da177e4 1512{
4be44fcd 1513 int status;
50dd0969
JE
1514 struct seq_file *m = file->private_data;
1515 struct acpi_video_bus *video = m->private;
4be44fcd 1516 char str[12] = { 0 };
27663c58 1517 unsigned long long opt, options;
1da177e4 1518
1da177e4 1519
1da177e4 1520 if (!video || count + 1 > sizeof str)
d550d98d 1521 return -EINVAL;
1da177e4
LT
1522
1523 status = acpi_video_bus_POST_options(video, &options);
1524 if (!ACPI_SUCCESS(status))
d550d98d 1525 return -EINVAL;
1da177e4
LT
1526
1527 if (copy_from_user(str, buffer, count))
d550d98d 1528 return -EFAULT;
1da177e4
LT
1529
1530 str[count] = 0;
1531 opt = strtoul(str, NULL, 0);
1532 if (opt > 3)
d550d98d 1533 return -EFAULT;
1da177e4 1534
98fb8fe1 1535 /* just in case an OEM 'forgot' the motherboard... */
1da177e4
LT
1536 options |= 1;
1537
1538 if (options & (1ul << opt)) {
4be44fcd 1539 status = acpi_video_bus_set_POST(video, opt);
1da177e4 1540 if (!ACPI_SUCCESS(status))
d550d98d 1541 return -EFAULT;
1da177e4
LT
1542
1543 }
1544
d550d98d 1545 return count;
1da177e4
LT
1546}
1547
1548static ssize_t
4be44fcd
LB
1549acpi_video_bus_write_DOS(struct file *file,
1550 const char __user * buffer,
1551 size_t count, loff_t * data)
1da177e4 1552{
4be44fcd 1553 int status;
50dd0969
JE
1554 struct seq_file *m = file->private_data;
1555 struct acpi_video_bus *video = m->private;
4be44fcd
LB
1556 char str[12] = { 0 };
1557 unsigned long opt;
1da177e4 1558
1da177e4 1559
1da177e4 1560 if (!video || count + 1 > sizeof str)
d550d98d 1561 return -EINVAL;
1da177e4
LT
1562
1563 if (copy_from_user(str, buffer, count))
d550d98d 1564 return -EFAULT;
1da177e4
LT
1565
1566 str[count] = 0;
1567 opt = strtoul(str, NULL, 0);
1568 if (opt > 7)
d550d98d 1569 return -EFAULT;
1da177e4 1570
4be44fcd 1571 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
1da177e4
LT
1572
1573 if (!ACPI_SUCCESS(status))
d550d98d 1574 return -EFAULT;
1da177e4 1575
d550d98d 1576 return count;
1da177e4
LT
1577}
1578
4be44fcd 1579static int acpi_video_bus_add_fs(struct acpi_device *device)
1da177e4 1580{
251cb0bc
DT
1581 struct acpi_video_bus *video = acpi_driver_data(device);
1582 struct proc_dir_entry *device_dir;
1583 struct proc_dir_entry *entry;
1da177e4 1584
251cb0bc
DT
1585 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1586 if (!device_dir)
1587 return -ENOMEM;
1da177e4 1588
1da177e4 1589 /* 'info' [R] */
e0066c4e 1590 entry = proc_create_data("info", S_IRUGO, device_dir,
cf7acfab
DL
1591 &acpi_video_bus_info_fops,
1592 acpi_driver_data(device));
1da177e4 1593 if (!entry)
251cb0bc 1594 goto err_remove_dir;
1da177e4
LT
1595
1596 /* 'ROM' [R] */
e0066c4e 1597 entry = proc_create_data("ROM", S_IRUGO, device_dir,
cf7acfab
DL
1598 &acpi_video_bus_ROM_fops,
1599 acpi_driver_data(device));
1da177e4 1600 if (!entry)
251cb0bc 1601 goto err_remove_info;
1da177e4
LT
1602
1603 /* 'POST_info' [R] */
e0066c4e 1604 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
cf7acfab
DL
1605 &acpi_video_bus_POST_info_fops,
1606 acpi_driver_data(device));
1da177e4 1607 if (!entry)
251cb0bc 1608 goto err_remove_rom;
1da177e4
LT
1609
1610 /* 'POST' [R/W] */
08acd4f8 1611 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
e0066c4e 1612 device_dir,
cf7acfab
DL
1613 &acpi_video_bus_POST_fops,
1614 acpi_driver_data(device));
1da177e4 1615 if (!entry)
251cb0bc 1616 goto err_remove_post_info;
1da177e4
LT
1617
1618 /* 'DOS' [R/W] */
08acd4f8 1619 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
e0066c4e 1620 device_dir,
cf7acfab
DL
1621 &acpi_video_bus_DOS_fops,
1622 acpi_driver_data(device));
1da177e4 1623 if (!entry)
251cb0bc 1624 goto err_remove_post;
1da177e4 1625
251cb0bc 1626 video->dir = acpi_device_dir(device) = device_dir;
d550d98d 1627 return 0;
251cb0bc
DT
1628
1629 err_remove_post:
1630 remove_proc_entry("POST", device_dir);
1631 err_remove_post_info:
1632 remove_proc_entry("POST_info", device_dir);
1633 err_remove_rom:
1634 remove_proc_entry("ROM", device_dir);
1635 err_remove_info:
1636 remove_proc_entry("info", device_dir);
1637 err_remove_dir:
1638 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1639 return -ENOMEM;
1da177e4
LT
1640}
1641
4be44fcd 1642static int acpi_video_bus_remove_fs(struct acpi_device *device)
1da177e4 1643{
251cb0bc
DT
1644 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1645
1646 if (device_dir) {
1647 remove_proc_entry("info", device_dir);
1648 remove_proc_entry("ROM", device_dir);
1649 remove_proc_entry("POST_info", device_dir);
1650 remove_proc_entry("POST", device_dir);
1651 remove_proc_entry("DOS", device_dir);
4be44fcd 1652 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1da177e4
LT
1653 acpi_device_dir(device) = NULL;
1654 }
1655
d550d98d 1656 return 0;
1da177e4
LT
1657}
1658
1659/* --------------------------------------------------------------------------
1660 Driver Interface
1661 -------------------------------------------------------------------------- */
1662
1663/* device interface */
82cae999
RZ
1664static struct acpi_video_device_attrib*
1665acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1666{
78eed028
DT
1667 struct acpi_video_enumerated_device *ids;
1668 int i;
1669
1670 for (i = 0; i < video->attached_count; i++) {
1671 ids = &video->attached_array[i];
1672 if ((ids->value.int_val & 0xffff) == device_id)
1673 return &ids->value.attrib;
1674 }
82cae999 1675
82cae999
RZ
1676 return NULL;
1677}
1da177e4
LT
1678
1679static int
4be44fcd
LB
1680acpi_video_bus_get_one_device(struct acpi_device *device,
1681 struct acpi_video_bus *video)
1da177e4 1682{
27663c58 1683 unsigned long long device_id;
973bf491 1684 int status;
4be44fcd 1685 struct acpi_video_device *data;
82cae999 1686 struct acpi_video_device_attrib* attribute;
1da177e4
LT
1687
1688 if (!device || !video)
d550d98d 1689 return -EINVAL;
1da177e4 1690
4be44fcd
LB
1691 status =
1692 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1da177e4
LT
1693 if (ACPI_SUCCESS(status)) {
1694
36bcbec7 1695 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1da177e4 1696 if (!data)
d550d98d 1697 return -ENOMEM;
1da177e4 1698
1da177e4
LT
1699 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1700 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
db89b4f0 1701 device->driver_data = data;
1da177e4
LT
1702
1703 data->device_id = device_id;
1704 data->video = video;
1705 data->dev = device;
1706
82cae999
RZ
1707 attribute = acpi_video_get_device_attr(video, device_id);
1708
1709 if((attribute != NULL) && attribute->device_id_scheme) {
1710 switch (attribute->display_type) {
1711 case ACPI_VIDEO_DISPLAY_CRT:
1712 data->flags.crt = 1;
1713 break;
1714 case ACPI_VIDEO_DISPLAY_TV:
1715 data->flags.tvout = 1;
1716 break;
1717 case ACPI_VIDEO_DISPLAY_DVI:
1718 data->flags.dvi = 1;
1719 break;
1720 case ACPI_VIDEO_DISPLAY_LCD:
1721 data->flags.lcd = 1;
1722 break;
1723 default:
1724 data->flags.unknown = 1;
1725 break;
1726 }
1727 if(attribute->bios_can_detect)
1728 data->flags.bios = 1;
1729 } else
1da177e4 1730 data->flags.unknown = 1;
4be44fcd 1731
1da177e4
LT
1732 acpi_video_device_bind(video, data);
1733 acpi_video_device_find_cap(data);
1734
90130268 1735 status = acpi_install_notify_handler(device->handle,
4be44fcd
LB
1736 ACPI_DEVICE_NOTIFY,
1737 acpi_video_device_notify,
1738 data);
1da177e4 1739 if (ACPI_FAILURE(status)) {
55ac9a01
LM
1740 printk(KERN_ERR PREFIX
1741 "Error installing notify handler\n");
973bf491
YL
1742 if(data->brightness)
1743 kfree(data->brightness->levels);
1744 kfree(data->brightness);
1745 kfree(data);
1746 return -ENODEV;
1da177e4
LT
1747 }
1748
bbac81f5 1749 mutex_lock(&video->device_list_lock);
1da177e4 1750 list_add_tail(&data->entry, &video->video_device_list);
bbac81f5 1751 mutex_unlock(&video->device_list_lock);
1da177e4
LT
1752
1753 acpi_video_device_add_fs(device);
1754
d550d98d 1755 return 0;
1da177e4
LT
1756 }
1757
d550d98d 1758 return -ENOENT;
1da177e4
LT
1759}
1760
1761/*
1762 * Arg:
1763 * video : video bus device
1764 *
1765 * Return:
1766 * none
1767 *
1768 * Enumerate the video device list of the video bus,
1769 * bind the ids with the corresponding video devices
1770 * under the video bus.
4be44fcd 1771 */
1da177e4 1772
4be44fcd 1773static void acpi_video_device_rebind(struct acpi_video_bus *video)
1da177e4 1774{
ff102ea9
DT
1775 struct acpi_video_device *dev;
1776
bbac81f5 1777 mutex_lock(&video->device_list_lock);
ff102ea9
DT
1778
1779 list_for_each_entry(dev, &video->video_device_list, entry)
4be44fcd 1780 acpi_video_device_bind(video, dev);
ff102ea9 1781
bbac81f5 1782 mutex_unlock(&video->device_list_lock);
1da177e4
LT
1783}
1784
1785/*
1786 * Arg:
1787 * video : video bus device
1788 * device : video output device under the video
1789 * bus
1790 *
1791 * Return:
1792 * none
1793 *
1794 * Bind the ids with the corresponding video devices
1795 * under the video bus.
4be44fcd 1796 */
1da177e4
LT
1797
1798static void
4be44fcd
LB
1799acpi_video_device_bind(struct acpi_video_bus *video,
1800 struct acpi_video_device *device)
1da177e4 1801{
78eed028 1802 struct acpi_video_enumerated_device *ids;
4be44fcd 1803 int i;
1da177e4 1804
78eed028
DT
1805 for (i = 0; i < video->attached_count; i++) {
1806 ids = &video->attached_array[i];
1807 if (device->device_id == (ids->value.int_val & 0xffff)) {
1808 ids->bind_info = device;
1da177e4
LT
1809 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1810 }
1811 }
1da177e4
LT
1812}
1813
1814/*
1815 * Arg:
1816 * video : video bus device
1817 *
1818 * Return:
1819 * < 0 : error
1820 *
1821 * Call _DOD to enumerate all devices attached to display adapter
1822 *
4be44fcd 1823 */
1da177e4
LT
1824
1825static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1826{
4be44fcd
LB
1827 int status;
1828 int count;
1829 int i;
78eed028 1830 struct acpi_video_enumerated_device *active_list;
4be44fcd
LB
1831 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1832 union acpi_object *dod = NULL;
1833 union acpi_object *obj;
1da177e4 1834
90130268 1835 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
1da177e4 1836 if (!ACPI_SUCCESS(status)) {
a6fc6720 1837 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
d550d98d 1838 return status;
1da177e4
LT
1839 }
1840
50dd0969 1841 dod = buffer.pointer;
1da177e4 1842 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
a6fc6720 1843 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1da177e4
LT
1844 status = -EFAULT;
1845 goto out;
1846 }
1847
1848 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
4be44fcd 1849 dod->package.count));
1da177e4 1850
78eed028
DT
1851 active_list = kcalloc(1 + dod->package.count,
1852 sizeof(struct acpi_video_enumerated_device),
1853 GFP_KERNEL);
1854 if (!active_list) {
1da177e4
LT
1855 status = -ENOMEM;
1856 goto out;
1857 }
1858
1859 count = 0;
1860 for (i = 0; i < dod->package.count; i++) {
50dd0969 1861 obj = &dod->package.elements[i];
1da177e4
LT
1862
1863 if (obj->type != ACPI_TYPE_INTEGER) {
78eed028
DT
1864 printk(KERN_ERR PREFIX
1865 "Invalid _DOD data in element %d\n", i);
1866 continue;
1da177e4 1867 }
78eed028
DT
1868
1869 active_list[count].value.int_val = obj->integer.value;
1870 active_list[count].bind_info = NULL;
4be44fcd
LB
1871 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1872 (int)obj->integer.value));
1da177e4
LT
1873 count++;
1874 }
1da177e4 1875
6044ec88 1876 kfree(video->attached_array);
4be44fcd 1877
78eed028 1878 video->attached_array = active_list;
1da177e4 1879 video->attached_count = count;
78eed028
DT
1880
1881 out:
02438d87 1882 kfree(buffer.pointer);
d550d98d 1883 return status;
1da177e4
LT
1884}
1885
4be44fcd
LB
1886static int
1887acpi_video_get_next_level(struct acpi_video_device *device,
1888 u32 level_current, u32 event)
1da177e4 1889{
63f0edfc 1890 int min, max, min_above, max_below, i, l, delta = 255;
f4715189
TT
1891 max = max_below = 0;
1892 min = min_above = 255;
63f0edfc 1893 /* Find closest level to level_current */
0a3db1ce 1894 for (i = 2; i < device->brightness->count; i++) {
63f0edfc
AS
1895 l = device->brightness->levels[i];
1896 if (abs(l - level_current) < abs(delta)) {
1897 delta = l - level_current;
1898 if (!delta)
1899 break;
1900 }
1901 }
1902 /* Ajust level_current to closest available level */
1903 level_current += delta;
0a3db1ce 1904 for (i = 2; i < device->brightness->count; i++) {
f4715189
TT
1905 l = device->brightness->levels[i];
1906 if (l < min)
1907 min = l;
1908 if (l > max)
1909 max = l;
1910 if (l < min_above && l > level_current)
1911 min_above = l;
1912 if (l > max_below && l < level_current)
1913 max_below = l;
1914 }
1915
1916 switch (event) {
1917 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1918 return (level_current < max) ? min_above : min;
1919 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1920 return (level_current < max) ? min_above : max;
1921 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1922 return (level_current > min) ? max_below : min;
1923 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1924 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1925 return 0;
1926 default:
1927 return level_current;
1928 }
1da177e4
LT
1929}
1930
c8890f90 1931static int
4be44fcd 1932acpi_video_switch_brightness(struct acpi_video_device *device, int event)
1da177e4 1933{
27663c58 1934 unsigned long long level_current, level_next;
c8890f90
ZR
1935 int result = -EINVAL;
1936
469778c1 1937 if (!device->brightness)
c8890f90
ZR
1938 goto out;
1939
1940 result = acpi_video_device_lcd_get_level_current(device,
1941 &level_current);
1942 if (result)
1943 goto out;
1944
1da177e4 1945 level_next = acpi_video_get_next_level(device, level_current, event);
c8890f90 1946
24450c7a 1947 result = acpi_video_device_lcd_set_level(device, level_next);
c8890f90
ZR
1948
1949out:
1950 if (result)
1951 printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
1952
1953 return result;
1da177e4
LT
1954}
1955
1956static int
4be44fcd
LB
1957acpi_video_bus_get_devices(struct acpi_video_bus *video,
1958 struct acpi_device *device)
1da177e4 1959{
4be44fcd 1960 int status = 0;
ff102ea9 1961 struct acpi_device *dev;
1da177e4
LT
1962
1963 acpi_video_device_enumerate(video);
1964
ff102ea9 1965 list_for_each_entry(dev, &device->children, node) {
1da177e4
LT
1966
1967 status = acpi_video_bus_get_one_device(dev, video);
1968 if (ACPI_FAILURE(status)) {
55ac9a01
LM
1969 printk(KERN_WARNING PREFIX
1970 "Cant attach device");
1da177e4
LT
1971 continue;
1972 }
1da177e4 1973 }
d550d98d 1974 return status;
1da177e4
LT
1975}
1976
4be44fcd 1977static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1da177e4 1978{
031ec77b 1979 acpi_status status;
1da177e4
LT
1980 struct acpi_video_bus *video;
1981
1da177e4
LT
1982
1983 if (!device || !device->video)
d550d98d 1984 return -ENOENT;
1da177e4
LT
1985
1986 video = device->video;
1987
1da177e4
LT
1988 acpi_video_device_remove_fs(device->dev);
1989
90130268 1990 status = acpi_remove_notify_handler(device->dev->handle,
4be44fcd
LB
1991 ACPI_DEVICE_NOTIFY,
1992 acpi_video_device_notify);
599a52d1 1993 backlight_device_unregister(device->backlight);
702ed512
ZR
1994 if (device->cdev) {
1995 sysfs_remove_link(&device->dev->dev.kobj,
1996 "thermal_cooling");
1997 sysfs_remove_link(&device->cdev->device.kobj,
1998 "device");
1999 thermal_cooling_device_unregister(device->cdev);
2000 device->cdev = NULL;
2001 }
23b0f015 2002 video_output_unregister(device->output_dev);
ff102ea9 2003
d550d98d 2004 return 0;
1da177e4
LT
2005}
2006
4be44fcd 2007static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1da177e4 2008{
4be44fcd 2009 int status;
ff102ea9 2010 struct acpi_video_device *dev, *next;
1da177e4 2011
bbac81f5 2012 mutex_lock(&video->device_list_lock);
1da177e4 2013
ff102ea9 2014 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1da177e4 2015
ff102ea9 2016 status = acpi_video_bus_put_one_device(dev);
4be44fcd
LB
2017 if (ACPI_FAILURE(status))
2018 printk(KERN_WARNING PREFIX
2019 "hhuuhhuu bug in acpi video driver.\n");
1da177e4 2020
ff102ea9
DT
2021 if (dev->brightness) {
2022 kfree(dev->brightness->levels);
2023 kfree(dev->brightness);
2024 }
2025 list_del(&dev->entry);
2026 kfree(dev);
1da177e4
LT
2027 }
2028
bbac81f5 2029 mutex_unlock(&video->device_list_lock);
ff102ea9 2030
d550d98d 2031 return 0;
1da177e4
LT
2032}
2033
2034/* acpi_video interface */
2035
4be44fcd 2036static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
1da177e4 2037{
a21101c4 2038 return acpi_video_bus_DOS(video, 0, 0);
1da177e4
LT
2039}
2040
4be44fcd 2041static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1da177e4
LT
2042{
2043 return acpi_video_bus_DOS(video, 0, 1);
2044}
2045
7015558f 2046static void acpi_video_bus_notify(struct acpi_device *device, u32 event)
1da177e4 2047{
7015558f 2048 struct acpi_video_bus *video = acpi_driver_data(device);
e9dab196
LY
2049 struct input_dev *input;
2050 int keycode;
2051
1da177e4 2052 if (!video)
d550d98d 2053 return;
1da177e4 2054
e9dab196 2055 input = video->input;
1da177e4
LT
2056
2057 switch (event) {
98fb8fe1 2058 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
1da177e4 2059 * most likely via hotkey. */
14e04fb3 2060 acpi_bus_generate_proc_event(device, event, 0);
e9dab196 2061 keycode = KEY_SWITCHVIDEOMODE;
1da177e4
LT
2062 break;
2063
98fb8fe1 2064 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
1da177e4
LT
2065 * connector. */
2066 acpi_video_device_enumerate(video);
2067 acpi_video_device_rebind(video);
14e04fb3 2068 acpi_bus_generate_proc_event(device, event, 0);
e9dab196 2069 keycode = KEY_SWITCHVIDEOMODE;
1da177e4
LT
2070 break;
2071
4be44fcd 2072 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
25c87f7f 2073 acpi_bus_generate_proc_event(device, event, 0);
e9dab196
LY
2074 keycode = KEY_SWITCHVIDEOMODE;
2075 break;
4be44fcd 2076 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
25c87f7f 2077 acpi_bus_generate_proc_event(device, event, 0);
e9dab196
LY
2078 keycode = KEY_VIDEO_NEXT;
2079 break;
4be44fcd 2080 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
14e04fb3 2081 acpi_bus_generate_proc_event(device, event, 0);
e9dab196 2082 keycode = KEY_VIDEO_PREV;
1da177e4
LT
2083 break;
2084
2085 default:
e9dab196 2086 keycode = KEY_UNKNOWN;
1da177e4 2087 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 2088 "Unsupported event [0x%x]\n", event));
1da177e4
LT
2089 break;
2090 }
2091
7761f638 2092 acpi_notifier_call_chain(device, event, 0);
e9dab196
LY
2093 input_report_key(input, keycode, 1);
2094 input_sync(input);
2095 input_report_key(input, keycode, 0);
2096 input_sync(input);
2097
d550d98d 2098 return;
1da177e4
LT
2099}
2100
4be44fcd 2101static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1da177e4 2102{
50dd0969 2103 struct acpi_video_device *video_device = data;
4be44fcd 2104 struct acpi_device *device = NULL;
e9dab196
LY
2105 struct acpi_video_bus *bus;
2106 struct input_dev *input;
2107 int keycode;
1da177e4 2108
1da177e4 2109 if (!video_device)
d550d98d 2110 return;
1da177e4 2111
e6afa0de 2112 device = video_device->dev;
e9dab196
LY
2113 bus = video_device->video;
2114 input = bus->input;
1da177e4
LT
2115
2116 switch (event) {
4be44fcd 2117 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
8a681a4d
ZR
2118 if (brightness_switch_enabled)
2119 acpi_video_switch_brightness(video_device, event);
14e04fb3 2120 acpi_bus_generate_proc_event(device, event, 0);
e9dab196
LY
2121 keycode = KEY_BRIGHTNESS_CYCLE;
2122 break;
4be44fcd 2123 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
8a681a4d
ZR
2124 if (brightness_switch_enabled)
2125 acpi_video_switch_brightness(video_device, event);
25c87f7f 2126 acpi_bus_generate_proc_event(device, event, 0);
e9dab196
LY
2127 keycode = KEY_BRIGHTNESSUP;
2128 break;
4be44fcd 2129 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
8a681a4d
ZR
2130 if (brightness_switch_enabled)
2131 acpi_video_switch_brightness(video_device, event);
25c87f7f 2132 acpi_bus_generate_proc_event(device, event, 0);
e9dab196
LY
2133 keycode = KEY_BRIGHTNESSDOWN;
2134 break;
4be44fcd 2135 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
8a681a4d
ZR
2136 if (brightness_switch_enabled)
2137 acpi_video_switch_brightness(video_device, event);
25c87f7f 2138 acpi_bus_generate_proc_event(device, event, 0);
e9dab196
LY
2139 keycode = KEY_BRIGHTNESS_ZERO;
2140 break;
4be44fcd 2141 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
8a681a4d
ZR
2142 if (brightness_switch_enabled)
2143 acpi_video_switch_brightness(video_device, event);
14e04fb3 2144 acpi_bus_generate_proc_event(device, event, 0);
e9dab196 2145 keycode = KEY_DISPLAY_OFF;
1da177e4
LT
2146 break;
2147 default:
e9dab196 2148 keycode = KEY_UNKNOWN;
1da177e4 2149 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 2150 "Unsupported event [0x%x]\n", event));
1da177e4
LT
2151 break;
2152 }
e9dab196 2153
7761f638 2154 acpi_notifier_call_chain(device, event, 0);
e9dab196
LY
2155 input_report_key(input, keycode, 1);
2156 input_sync(input);
2157 input_report_key(input, keycode, 0);
2158 input_sync(input);
2159
d550d98d 2160 return;
1da177e4
LT
2161}
2162
e6d9da1d 2163static int instance;
863c1490
MG
2164static int acpi_video_resume(struct acpi_device *device)
2165{
2166 struct acpi_video_bus *video;
2167 struct acpi_video_device *video_device;
2168 int i;
2169
2170 if (!device || !acpi_driver_data(device))
2171 return -EINVAL;
2172
2173 video = acpi_driver_data(device);
2174
2175 for (i = 0; i < video->attached_count; i++) {
2176 video_device = video->attached_array[i].bind_info;
2177 if (video_device && video_device->backlight)
2178 acpi_video_set_brightness(video_device->backlight);
2179 }
2180 return AE_OK;
2181}
2182
4be44fcd 2183static int acpi_video_bus_add(struct acpi_device *device)
1da177e4 2184{
f51e8391 2185 struct acpi_video_bus *video;
e9dab196 2186 struct input_dev *input;
f51e8391 2187 int error;
1da177e4 2188
36bcbec7 2189 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1da177e4 2190 if (!video)
d550d98d 2191 return -ENOMEM;
1da177e4 2192
e6d9da1d
ZR
2193 /* a hack to fix the duplicate name "VID" problem on T61 */
2194 if (!strcmp(device->pnp.bus_id, "VID")) {
2195 if (instance)
2196 device->pnp.bus_id[3] = '0' + instance;
2197 instance ++;
2198 }
f3b39f13
ZY
2199 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2200 if (!strcmp(device->pnp.bus_id, "VGA")) {
2201 if (instance)
2202 device->pnp.bus_id[3] = '0' + instance;
2203 instance++;
2204 }
e6d9da1d 2205
e6afa0de 2206 video->device = device;
1da177e4
LT
2207 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
2208 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
db89b4f0 2209 device->driver_data = video;
1da177e4
LT
2210
2211 acpi_video_bus_find_cap(video);
f51e8391
DT
2212 error = acpi_video_bus_check(video);
2213 if (error)
2214 goto err_free_video;
1da177e4 2215
f51e8391
DT
2216 error = acpi_video_bus_add_fs(device);
2217 if (error)
2218 goto err_free_video;
1da177e4 2219
bbac81f5 2220 mutex_init(&video->device_list_lock);
1da177e4
LT
2221 INIT_LIST_HEAD(&video->video_device_list);
2222
2223 acpi_video_bus_get_devices(video, device);
2224 acpi_video_bus_start_devices(video);
2225
e9dab196 2226 video->input = input = input_allocate_device();
f51e8391
DT
2227 if (!input) {
2228 error = -ENOMEM;
7015558f 2229 goto err_stop_video;
f51e8391 2230 }
e9dab196
LY
2231
2232 snprintf(video->phys, sizeof(video->phys),
2233 "%s/video/input0", acpi_device_hid(video->device));
2234
2235 input->name = acpi_device_name(video->device);
2236 input->phys = video->phys;
2237 input->id.bustype = BUS_HOST;
2238 input->id.product = 0x06;
91c05c66 2239 input->dev.parent = &device->dev;
e9dab196
LY
2240 input->evbit[0] = BIT(EV_KEY);
2241 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2242 set_bit(KEY_VIDEO_NEXT, input->keybit);
2243 set_bit(KEY_VIDEO_PREV, input->keybit);
2244 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2245 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2246 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2247 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2248 set_bit(KEY_DISPLAY_OFF, input->keybit);
2249 set_bit(KEY_UNKNOWN, input->keybit);
e9dab196 2250
f51e8391
DT
2251 error = input_register_device(input);
2252 if (error)
2253 goto err_free_input_dev;
e9dab196 2254
1da177e4 2255 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
4be44fcd
LB
2256 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2257 video->flags.multihead ? "yes" : "no",
2258 video->flags.rom ? "yes" : "no",
2259 video->flags.post ? "yes" : "no");
1da177e4 2260
f51e8391
DT
2261 return 0;
2262
2263 err_free_input_dev:
2264 input_free_device(input);
f51e8391
DT
2265 err_stop_video:
2266 acpi_video_bus_stop_devices(video);
2267 acpi_video_bus_put_devices(video);
2268 kfree(video->attached_array);
2269 acpi_video_bus_remove_fs(device);
2270 err_free_video:
2271 kfree(video);
db89b4f0 2272 device->driver_data = NULL;
1da177e4 2273
f51e8391 2274 return error;
1da177e4
LT
2275}
2276
4be44fcd 2277static int acpi_video_bus_remove(struct acpi_device *device, int type)
1da177e4 2278{
4be44fcd 2279 struct acpi_video_bus *video = NULL;
1da177e4 2280
1da177e4
LT
2281
2282 if (!device || !acpi_driver_data(device))
d550d98d 2283 return -EINVAL;
1da177e4 2284
50dd0969 2285 video = acpi_driver_data(device);
1da177e4
LT
2286
2287 acpi_video_bus_stop_devices(video);
1da177e4
LT
2288 acpi_video_bus_put_devices(video);
2289 acpi_video_bus_remove_fs(device);
2290
e9dab196 2291 input_unregister_device(video->input);
6044ec88 2292 kfree(video->attached_array);
1da177e4
LT
2293 kfree(video);
2294
d550d98d 2295 return 0;
1da177e4
LT
2296}
2297
74a365b3
MG
2298static int __init intel_opregion_present(void)
2299{
2300#if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE)
2301 struct pci_dev *dev = NULL;
2302 u32 address;
2303
2304 for_each_pci_dev(dev) {
2305 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
2306 continue;
2307 if (dev->vendor != PCI_VENDOR_ID_INTEL)
2308 continue;
2309 pci_read_config_dword(dev, 0xfc, &address);
2310 if (!address)
2311 continue;
2312 return 1;
2313 }
2314#endif
2315 return 0;
2316}
2317
2318int acpi_video_register(void)
1da177e4 2319{
4be44fcd 2320 int result = 0;
1da177e4 2321
1da177e4
LT
2322 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2323 if (!acpi_video_dir)
d550d98d 2324 return -ENODEV;
1da177e4
LT
2325
2326 result = acpi_bus_register_driver(&acpi_video_bus);
2327 if (result < 0) {
2328 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
d550d98d 2329 return -ENODEV;
1da177e4
LT
2330 }
2331
d550d98d 2332 return 0;
1da177e4 2333}
74a365b3
MG
2334EXPORT_SYMBOL(acpi_video_register);
2335
2336/*
2337 * This is kind of nasty. Hardware using Intel chipsets may require
2338 * the video opregion code to be run first in order to initialise
2339 * state before any ACPI video calls are made. To handle this we defer
2340 * registration of the video class until the opregion code has run.
2341 */
2342
2343static int __init acpi_video_init(void)
2344{
45cb50e6
ZR
2345 dmi_check_system(video_dmi_table);
2346
74a365b3
MG
2347 if (intel_opregion_present())
2348 return 0;
2349
2350 return acpi_video_register();
2351}
1da177e4 2352
3b1c1c11 2353void __exit acpi_video_exit(void)
1da177e4 2354{
1da177e4
LT
2355
2356 acpi_bus_unregister_driver(&acpi_video_bus);
2357
2358 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2359
d550d98d 2360 return;
1da177e4 2361}
3b1c1c11 2362EXPORT_SYMBOL(acpi_video_exit);
1da177e4
LT
2363
2364module_init(acpi_video_init);
2365module_exit(acpi_video_exit);