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