Commit | Line | Data |
---|---|---|
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> | |
6 | * | |
7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or (at | |
12 | * your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
22 | * | |
23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
24 | */ | |
25 | ||
26 | #include <linux/kernel.h> | |
27 | #include <linux/module.h> | |
28 | #include <linux/init.h> | |
29 | #include <linux/types.h> | |
30 | #include <linux/list.h> | |
31 | #include <linux/proc_fs.h> | |
32 | #include <linux/seq_file.h> | |
33 | ||
34 | #include <asm/uaccess.h> | |
35 | ||
36 | #include <acpi/acpi_bus.h> | |
37 | #include <acpi/acpi_drivers.h> | |
38 | ||
39 | #define ACPI_VIDEO_COMPONENT 0x08000000 | |
40 | #define ACPI_VIDEO_CLASS "video" | |
41 | #define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver" | |
42 | #define ACPI_VIDEO_BUS_NAME "Video Bus" | |
43 | #define ACPI_VIDEO_DEVICE_NAME "Video Device" | |
44 | #define ACPI_VIDEO_NOTIFY_SWITCH 0x80 | |
45 | #define ACPI_VIDEO_NOTIFY_PROBE 0x81 | |
46 | #define ACPI_VIDEO_NOTIFY_CYCLE 0x82 | |
47 | #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 | |
48 | #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 | |
49 | ||
50 | #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82 | |
51 | #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83 | |
52 | #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84 | |
53 | #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85 | |
54 | #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86 | |
55 | ||
1da177e4 LT |
56 | #define ACPI_VIDEO_HEAD_INVALID (~0u - 1) |
57 | #define ACPI_VIDEO_HEAD_END (~0u) | |
58 | ||
1da177e4 | 59 | #define _COMPONENT ACPI_VIDEO_COMPONENT |
4be44fcd | 60 | ACPI_MODULE_NAME("acpi_video") |
1da177e4 | 61 | |
4be44fcd | 62 | MODULE_AUTHOR("Bruno Ducrot"); |
1da177e4 LT |
63 | MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME); |
64 | MODULE_LICENSE("GPL"); | |
65 | ||
4be44fcd LB |
66 | static int acpi_video_bus_add(struct acpi_device *device); |
67 | static int acpi_video_bus_remove(struct acpi_device *device, int type); | |
68 | static int acpi_video_bus_match(struct acpi_device *device, | |
69 | struct acpi_driver *driver); | |
1da177e4 LT |
70 | |
71 | static struct acpi_driver acpi_video_bus = { | |
72 | .name = ACPI_VIDEO_DRIVER_NAME, | |
73 | .class = ACPI_VIDEO_CLASS, | |
74 | .ops = { | |
75 | .add = acpi_video_bus_add, | |
76 | .remove = acpi_video_bus_remove, | |
77 | .match = acpi_video_bus_match, | |
4be44fcd | 78 | }, |
1da177e4 LT |
79 | }; |
80 | ||
81 | struct acpi_video_bus_flags { | |
4be44fcd LB |
82 | u8 multihead:1; /* can switch video heads */ |
83 | u8 rom:1; /* can retrieve a video rom */ | |
84 | u8 post:1; /* can configure the head to */ | |
85 | u8 reserved:5; | |
1da177e4 LT |
86 | }; |
87 | ||
88 | struct acpi_video_bus_cap { | |
4be44fcd LB |
89 | u8 _DOS:1; /*Enable/Disable output switching */ |
90 | u8 _DOD:1; /*Enumerate all devices attached to display adapter */ | |
91 | u8 _ROM:1; /*Get ROM Data */ | |
92 | u8 _GPD:1; /*Get POST Device */ | |
93 | u8 _SPD:1; /*Set POST Device */ | |
94 | u8 _VPO:1; /*Video POST Options */ | |
95 | u8 reserved:2; | |
1da177e4 LT |
96 | }; |
97 | ||
4be44fcd LB |
98 | struct acpi_video_device_attrib { |
99 | u32 display_index:4; /* A zero-based instance of the Display */ | |
100 | u32 display_port_attachment:4; /*This field differenates displays type */ | |
101 | u32 display_type:4; /*Describe the specific type in use */ | |
102 | u32 vendor_specific:4; /*Chipset Vendor Specifi */ | |
103 | u32 bios_can_detect:1; /*BIOS can detect the device */ | |
104 | u32 depend_on_vga:1; /*Non-VGA output device whose power is related to | |
105 | the VGA device. */ | |
106 | u32 pipe_id:3; /*For VGA multiple-head devices. */ | |
107 | u32 reserved:10; /*Must be 0 */ | |
108 | u32 device_id_scheme:1; /*Device ID Scheme */ | |
1da177e4 LT |
109 | }; |
110 | ||
111 | struct acpi_video_enumerated_device { | |
112 | union { | |
113 | u32 int_val; | |
4be44fcd | 114 | struct acpi_video_device_attrib attrib; |
1da177e4 LT |
115 | } value; |
116 | struct acpi_video_device *bind_info; | |
117 | }; | |
118 | ||
119 | struct acpi_video_bus { | |
4be44fcd LB |
120 | acpi_handle handle; |
121 | u8 dos_setting; | |
1da177e4 | 122 | struct acpi_video_enumerated_device *attached_array; |
4be44fcd LB |
123 | u8 attached_count; |
124 | struct acpi_video_bus_cap cap; | |
1da177e4 | 125 | struct acpi_video_bus_flags flags; |
4be44fcd LB |
126 | struct semaphore sem; |
127 | struct list_head video_device_list; | |
128 | struct proc_dir_entry *dir; | |
1da177e4 LT |
129 | }; |
130 | ||
131 | struct acpi_video_device_flags { | |
4be44fcd LB |
132 | u8 crt:1; |
133 | u8 lcd:1; | |
134 | u8 tvout:1; | |
135 | u8 bios:1; | |
136 | u8 unknown:1; | |
137 | u8 reserved:3; | |
1da177e4 LT |
138 | }; |
139 | ||
140 | struct acpi_video_device_cap { | |
4be44fcd LB |
141 | u8 _ADR:1; /*Return the unique ID */ |
142 | u8 _BCL:1; /*Query list of brightness control levels supported */ | |
143 | u8 _BCM:1; /*Set the brightness level */ | |
144 | u8 _DDC:1; /*Return the EDID for this device */ | |
145 | u8 _DCS:1; /*Return status of output device */ | |
146 | u8 _DGS:1; /*Query graphics state */ | |
147 | u8 _DSS:1; /*Device state set */ | |
148 | u8 _reserved:1; | |
1da177e4 LT |
149 | }; |
150 | ||
151 | struct acpi_video_device_brightness { | |
4be44fcd LB |
152 | int curr; |
153 | int count; | |
154 | int *levels; | |
1da177e4 LT |
155 | }; |
156 | ||
157 | struct acpi_video_device { | |
4be44fcd LB |
158 | acpi_handle handle; |
159 | unsigned long device_id; | |
160 | struct acpi_video_device_flags flags; | |
161 | struct acpi_video_device_cap cap; | |
162 | struct list_head entry; | |
163 | struct acpi_video_bus *video; | |
164 | struct acpi_device *dev; | |
1da177e4 LT |
165 | struct acpi_video_device_brightness *brightness; |
166 | }; | |
167 | ||
1da177e4 LT |
168 | /* bus */ |
169 | static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file); | |
170 | static struct file_operations acpi_video_bus_info_fops = { | |
4be44fcd LB |
171 | .open = acpi_video_bus_info_open_fs, |
172 | .read = seq_read, | |
173 | .llseek = seq_lseek, | |
174 | .release = single_release, | |
1da177e4 LT |
175 | }; |
176 | ||
177 | static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file); | |
178 | static struct file_operations acpi_video_bus_ROM_fops = { | |
4be44fcd LB |
179 | .open = acpi_video_bus_ROM_open_fs, |
180 | .read = seq_read, | |
181 | .llseek = seq_lseek, | |
182 | .release = single_release, | |
1da177e4 LT |
183 | }; |
184 | ||
4be44fcd LB |
185 | static int acpi_video_bus_POST_info_open_fs(struct inode *inode, |
186 | struct file *file); | |
1da177e4 | 187 | static struct file_operations acpi_video_bus_POST_info_fops = { |
4be44fcd LB |
188 | .open = acpi_video_bus_POST_info_open_fs, |
189 | .read = seq_read, | |
190 | .llseek = seq_lseek, | |
191 | .release = single_release, | |
1da177e4 LT |
192 | }; |
193 | ||
194 | static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file); | |
195 | static struct file_operations acpi_video_bus_POST_fops = { | |
4be44fcd LB |
196 | .open = acpi_video_bus_POST_open_fs, |
197 | .read = seq_read, | |
198 | .llseek = seq_lseek, | |
199 | .release = single_release, | |
1da177e4 LT |
200 | }; |
201 | ||
1da177e4 LT |
202 | static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file); |
203 | static struct file_operations acpi_video_bus_DOS_fops = { | |
4be44fcd LB |
204 | .open = acpi_video_bus_DOS_open_fs, |
205 | .read = seq_read, | |
206 | .llseek = seq_lseek, | |
207 | .release = single_release, | |
1da177e4 LT |
208 | }; |
209 | ||
210 | /* device */ | |
4be44fcd LB |
211 | static int acpi_video_device_info_open_fs(struct inode *inode, |
212 | struct file *file); | |
1da177e4 | 213 | static struct file_operations acpi_video_device_info_fops = { |
4be44fcd LB |
214 | .open = acpi_video_device_info_open_fs, |
215 | .read = seq_read, | |
216 | .llseek = seq_lseek, | |
217 | .release = single_release, | |
1da177e4 LT |
218 | }; |
219 | ||
4be44fcd LB |
220 | static int acpi_video_device_state_open_fs(struct inode *inode, |
221 | struct file *file); | |
1da177e4 | 222 | static struct file_operations acpi_video_device_state_fops = { |
4be44fcd LB |
223 | .open = acpi_video_device_state_open_fs, |
224 | .read = seq_read, | |
225 | .llseek = seq_lseek, | |
226 | .release = single_release, | |
1da177e4 LT |
227 | }; |
228 | ||
4be44fcd LB |
229 | static int acpi_video_device_brightness_open_fs(struct inode *inode, |
230 | struct file *file); | |
1da177e4 | 231 | static struct file_operations acpi_video_device_brightness_fops = { |
4be44fcd LB |
232 | .open = acpi_video_device_brightness_open_fs, |
233 | .read = seq_read, | |
234 | .llseek = seq_lseek, | |
235 | .release = single_release, | |
1da177e4 LT |
236 | }; |
237 | ||
4be44fcd LB |
238 | static int acpi_video_device_EDID_open_fs(struct inode *inode, |
239 | struct file *file); | |
1da177e4 | 240 | static struct file_operations acpi_video_device_EDID_fops = { |
4be44fcd LB |
241 | .open = acpi_video_device_EDID_open_fs, |
242 | .read = seq_read, | |
243 | .llseek = seq_lseek, | |
244 | .release = single_release, | |
1da177e4 LT |
245 | }; |
246 | ||
4be44fcd | 247 | static char device_decode[][30] = { |
1da177e4 LT |
248 | "motherboard VGA device", |
249 | "PCI VGA device", | |
250 | "AGP VGA device", | |
251 | "UNKNOWN", | |
252 | }; | |
253 | ||
4be44fcd LB |
254 | static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data); |
255 | static void acpi_video_device_rebind(struct acpi_video_bus *video); | |
256 | static void acpi_video_device_bind(struct acpi_video_bus *video, | |
257 | struct acpi_video_device *device); | |
1da177e4 | 258 | static int acpi_video_device_enumerate(struct acpi_video_bus *video); |
4be44fcd LB |
259 | static int acpi_video_switch_output(struct acpi_video_bus *video, int event); |
260 | static int acpi_video_get_next_level(struct acpi_video_device *device, | |
261 | u32 level_current, u32 event); | |
262 | static void acpi_video_switch_brightness(struct acpi_video_device *device, | |
263 | int event); | |
1da177e4 LT |
264 | |
265 | /* -------------------------------------------------------------------------- | |
266 | Video Management | |
267 | -------------------------------------------------------------------------- */ | |
268 | ||
269 | /* device */ | |
270 | ||
271 | static int | |
4be44fcd | 272 | acpi_video_device_query(struct acpi_video_device *device, unsigned long *state) |
1da177e4 | 273 | { |
4be44fcd | 274 | int status; |
1da177e4 LT |
275 | status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state); |
276 | ||
d550d98d | 277 | return status; |
1da177e4 LT |
278 | } |
279 | ||
280 | static int | |
4be44fcd LB |
281 | acpi_video_device_get_state(struct acpi_video_device *device, |
282 | unsigned long *state) | |
1da177e4 | 283 | { |
4be44fcd | 284 | int status; |
1da177e4 | 285 | |
1da177e4 LT |
286 | |
287 | status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state); | |
288 | ||
d550d98d | 289 | return status; |
1da177e4 LT |
290 | } |
291 | ||
292 | static int | |
4be44fcd | 293 | acpi_video_device_set_state(struct acpi_video_device *device, int state) |
1da177e4 | 294 | { |
4be44fcd LB |
295 | int status; |
296 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
297 | struct acpi_object_list args = { 1, &arg0 }; | |
824b558b | 298 | unsigned long ret; |
1da177e4 | 299 | |
1da177e4 LT |
300 | |
301 | arg0.integer.value = state; | |
824b558b | 302 | status = acpi_evaluate_integer(device->handle, "_DSS", &args, &ret); |
1da177e4 | 303 | |
d550d98d | 304 | return status; |
1da177e4 LT |
305 | } |
306 | ||
307 | static int | |
4be44fcd LB |
308 | acpi_video_device_lcd_query_levels(struct acpi_video_device *device, |
309 | union acpi_object **levels) | |
1da177e4 | 310 | { |
4be44fcd LB |
311 | int status; |
312 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
313 | union acpi_object *obj; | |
1da177e4 | 314 | |
1da177e4 LT |
315 | |
316 | *levels = NULL; | |
317 | ||
318 | status = acpi_evaluate_object(device->handle, "_BCL", NULL, &buffer); | |
319 | if (!ACPI_SUCCESS(status)) | |
d550d98d | 320 | return status; |
4be44fcd | 321 | obj = (union acpi_object *)buffer.pointer; |
6665bda7 | 322 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
6468463a | 323 | printk(KERN_ERR PREFIX "Invalid _BCL data\n"); |
1da177e4 LT |
324 | status = -EFAULT; |
325 | goto err; | |
326 | } | |
327 | ||
328 | *levels = obj; | |
329 | ||
d550d98d | 330 | return 0; |
1da177e4 | 331 | |
4be44fcd | 332 | err: |
6044ec88 | 333 | kfree(buffer.pointer); |
1da177e4 | 334 | |
d550d98d | 335 | return status; |
1da177e4 LT |
336 | } |
337 | ||
338 | static int | |
4be44fcd | 339 | acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) |
1da177e4 | 340 | { |
4be44fcd LB |
341 | int status; |
342 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
343 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 344 | |
1da177e4 LT |
345 | |
346 | arg0.integer.value = level; | |
347 | status = acpi_evaluate_object(device->handle, "_BCM", &args, NULL); | |
348 | ||
349 | printk(KERN_DEBUG "set_level status: %x\n", status); | |
d550d98d | 350 | return status; |
1da177e4 LT |
351 | } |
352 | ||
353 | static int | |
4be44fcd LB |
354 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, |
355 | unsigned long *level) | |
1da177e4 | 356 | { |
4be44fcd | 357 | int status; |
1da177e4 LT |
358 | |
359 | status = acpi_evaluate_integer(device->handle, "_BQC", NULL, level); | |
360 | ||
d550d98d | 361 | return status; |
1da177e4 LT |
362 | } |
363 | ||
364 | static int | |
4be44fcd LB |
365 | acpi_video_device_EDID(struct acpi_video_device *device, |
366 | union acpi_object **edid, ssize_t length) | |
1da177e4 | 367 | { |
4be44fcd LB |
368 | int status; |
369 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
370 | union acpi_object *obj; | |
371 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
372 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 373 | |
1da177e4 LT |
374 | |
375 | *edid = NULL; | |
376 | ||
377 | if (!device) | |
d550d98d | 378 | return -ENODEV; |
1da177e4 LT |
379 | if (length == 128) |
380 | arg0.integer.value = 1; | |
381 | else if (length == 256) | |
382 | arg0.integer.value = 2; | |
383 | else | |
d550d98d | 384 | return -EINVAL; |
1da177e4 LT |
385 | |
386 | status = acpi_evaluate_object(device->handle, "_DDC", &args, &buffer); | |
387 | if (ACPI_FAILURE(status)) | |
d550d98d | 388 | return -ENODEV; |
1da177e4 | 389 | |
4be44fcd | 390 | obj = (union acpi_object *)buffer.pointer; |
1da177e4 LT |
391 | |
392 | if (obj && obj->type == ACPI_TYPE_BUFFER) | |
393 | *edid = obj; | |
394 | else { | |
6468463a | 395 | printk(KERN_ERR PREFIX "Invalid _DDC data\n"); |
1da177e4 LT |
396 | status = -EFAULT; |
397 | kfree(obj); | |
398 | } | |
399 | ||
d550d98d | 400 | return status; |
1da177e4 LT |
401 | } |
402 | ||
1da177e4 LT |
403 | /* bus */ |
404 | ||
405 | static int | |
4be44fcd | 406 | acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option) |
1da177e4 | 407 | { |
4be44fcd LB |
408 | int status; |
409 | unsigned long tmp; | |
410 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
411 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 412 | |
1da177e4 LT |
413 | |
414 | arg0.integer.value = option; | |
415 | ||
416 | status = acpi_evaluate_integer(video->handle, "_SPD", &args, &tmp); | |
417 | if (ACPI_SUCCESS(status)) | |
4be44fcd | 418 | status = tmp ? (-EINVAL) : (AE_OK); |
1da177e4 | 419 | |
d550d98d | 420 | return status; |
1da177e4 LT |
421 | } |
422 | ||
423 | static int | |
4be44fcd | 424 | acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id) |
1da177e4 LT |
425 | { |
426 | int status; | |
427 | ||
1da177e4 LT |
428 | |
429 | status = acpi_evaluate_integer(video->handle, "_GPD", NULL, id); | |
430 | ||
d550d98d | 431 | return status; |
1da177e4 LT |
432 | } |
433 | ||
434 | static int | |
4be44fcd LB |
435 | acpi_video_bus_POST_options(struct acpi_video_bus *video, |
436 | unsigned long *options) | |
1da177e4 | 437 | { |
4be44fcd | 438 | int status; |
1da177e4 LT |
439 | |
440 | status = acpi_evaluate_integer(video->handle, "_VPO", NULL, options); | |
441 | *options &= 3; | |
442 | ||
d550d98d | 443 | return status; |
1da177e4 LT |
444 | } |
445 | ||
446 | /* | |
447 | * Arg: | |
448 | * video : video bus device pointer | |
449 | * bios_flag : | |
450 | * 0. The system BIOS should NOT automatically switch(toggle) | |
451 | * the active display output. | |
452 | * 1. The system BIOS should automatically switch (toggle) the | |
453 | * active display output. No swich event. | |
454 | * 2. The _DGS value should be locked. | |
455 | * 3. The system BIOS should not automatically switch (toggle) the | |
456 | * active display output, but instead generate the display switch | |
457 | * event notify code. | |
458 | * lcd_flag : | |
459 | * 0. The system BIOS should automatically control the brightness level | |
460 | * of the LCD, when the power changes from AC to DC | |
461 | * 1. The system BIOS should NOT automatically control the brightness | |
462 | * level of the LCD, when the power changes from AC to DC. | |
463 | * Return Value: | |
464 | * -1 wrong arg. | |
465 | */ | |
466 | ||
467 | static int | |
4be44fcd | 468 | acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) |
1da177e4 | 469 | { |
4be44fcd LB |
470 | acpi_integer status = 0; |
471 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
472 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 473 | |
1da177e4 | 474 | |
4be44fcd | 475 | if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) { |
1da177e4 LT |
476 | status = -1; |
477 | goto Failed; | |
478 | } | |
479 | arg0.integer.value = (lcd_flag << 2) | bios_flag; | |
480 | video->dos_setting = arg0.integer.value; | |
481 | acpi_evaluate_object(video->handle, "_DOS", &args, NULL); | |
482 | ||
4be44fcd | 483 | Failed: |
d550d98d | 484 | return status; |
1da177e4 LT |
485 | } |
486 | ||
487 | /* | |
488 | * Arg: | |
489 | * device : video output device (LCD, CRT, ..) | |
490 | * | |
491 | * Return Value: | |
492 | * None | |
493 | * | |
494 | * Find out all required AML method defined under the output | |
495 | * device. | |
496 | */ | |
497 | ||
4be44fcd | 498 | static void acpi_video_device_find_cap(struct acpi_video_device *device) |
1da177e4 | 499 | { |
4be44fcd | 500 | acpi_integer status; |
1da177e4 LT |
501 | acpi_handle h_dummy1; |
502 | int i; | |
503 | union acpi_object *obj = NULL; | |
504 | struct acpi_video_device_brightness *br = NULL; | |
505 | ||
1da177e4 | 506 | |
4be44fcd | 507 | memset(&device->cap, 0, 4); |
1da177e4 | 508 | |
4be44fcd | 509 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ADR", &h_dummy1))) { |
1da177e4 LT |
510 | device->cap._ADR = 1; |
511 | } | |
4be44fcd LB |
512 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCL", &h_dummy1))) { |
513 | device->cap._BCL = 1; | |
1da177e4 | 514 | } |
4be44fcd LB |
515 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_BCM", &h_dummy1))) { |
516 | device->cap._BCM = 1; | |
1da177e4 | 517 | } |
4be44fcd LB |
518 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DDC", &h_dummy1))) { |
519 | device->cap._DDC = 1; | |
1da177e4 | 520 | } |
4be44fcd | 521 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DCS", &h_dummy1))) { |
1da177e4 LT |
522 | device->cap._DCS = 1; |
523 | } | |
4be44fcd | 524 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DGS", &h_dummy1))) { |
1da177e4 LT |
525 | device->cap._DGS = 1; |
526 | } | |
4be44fcd | 527 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DSS", &h_dummy1))) { |
1da177e4 LT |
528 | device->cap._DSS = 1; |
529 | } | |
530 | ||
531 | status = acpi_video_device_lcd_query_levels(device, &obj); | |
532 | ||
533 | if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) { | |
534 | int count = 0; | |
535 | union acpi_object *o; | |
4be44fcd | 536 | |
d1dd0c23 | 537 | br = kmalloc(sizeof(*br), GFP_KERNEL); |
1da177e4 LT |
538 | if (!br) { |
539 | printk(KERN_ERR "can't allocate memory\n"); | |
540 | } else { | |
d1dd0c23 PM |
541 | memset(br, 0, sizeof(*br)); |
542 | br->levels = kmalloc(obj->package.count * | |
4be44fcd | 543 | sizeof *(br->levels), GFP_KERNEL); |
1da177e4 LT |
544 | if (!br->levels) |
545 | goto out; | |
546 | ||
547 | for (i = 0; i < obj->package.count; i++) { | |
4be44fcd LB |
548 | o = (union acpi_object *)&obj->package. |
549 | elements[i]; | |
1da177e4 | 550 | if (o->type != ACPI_TYPE_INTEGER) { |
6468463a | 551 | printk(KERN_ERR PREFIX "Invalid data\n"); |
1da177e4 LT |
552 | continue; |
553 | } | |
554 | br->levels[count] = (u32) o->integer.value; | |
555 | count++; | |
556 | } | |
4be44fcd | 557 | out: |
1da177e4 | 558 | if (count < 2) { |
d1dd0c23 | 559 | kfree(br->levels); |
1da177e4 LT |
560 | kfree(br); |
561 | } else { | |
562 | br->count = count; | |
563 | device->brightness = br; | |
4be44fcd LB |
564 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
565 | "found %d brightness levels\n", | |
566 | count)); | |
1da177e4 LT |
567 | } |
568 | } | |
569 | } | |
570 | ||
d1dd0c23 | 571 | kfree(obj); |
1da177e4 | 572 | |
d550d98d | 573 | return; |
1da177e4 LT |
574 | } |
575 | ||
576 | /* | |
577 | * Arg: | |
578 | * device : video output device (VGA) | |
579 | * | |
580 | * Return Value: | |
581 | * None | |
582 | * | |
583 | * Find out all required AML method defined under the video bus device. | |
584 | */ | |
585 | ||
4be44fcd | 586 | static void acpi_video_bus_find_cap(struct acpi_video_bus *video) |
1da177e4 | 587 | { |
4be44fcd | 588 | acpi_handle h_dummy1; |
1da177e4 | 589 | |
4be44fcd LB |
590 | memset(&video->cap, 0, 4); |
591 | if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOS", &h_dummy1))) { | |
1da177e4 LT |
592 | video->cap._DOS = 1; |
593 | } | |
4be44fcd | 594 | if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_DOD", &h_dummy1))) { |
1da177e4 LT |
595 | video->cap._DOD = 1; |
596 | } | |
4be44fcd | 597 | if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_ROM", &h_dummy1))) { |
1da177e4 LT |
598 | video->cap._ROM = 1; |
599 | } | |
4be44fcd | 600 | if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_GPD", &h_dummy1))) { |
1da177e4 LT |
601 | video->cap._GPD = 1; |
602 | } | |
4be44fcd | 603 | if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_SPD", &h_dummy1))) { |
1da177e4 LT |
604 | video->cap._SPD = 1; |
605 | } | |
4be44fcd | 606 | if (ACPI_SUCCESS(acpi_get_handle(video->handle, "_VPO", &h_dummy1))) { |
1da177e4 LT |
607 | video->cap._VPO = 1; |
608 | } | |
609 | } | |
610 | ||
611 | /* | |
612 | * Check whether the video bus device has required AML method to | |
613 | * support the desired features | |
614 | */ | |
615 | ||
4be44fcd | 616 | static int acpi_video_bus_check(struct acpi_video_bus *video) |
1da177e4 | 617 | { |
4be44fcd | 618 | acpi_status status = -ENOENT; |
1da177e4 | 619 | |
1da177e4 LT |
620 | |
621 | if (!video) | |
d550d98d | 622 | return -EINVAL; |
1da177e4 LT |
623 | |
624 | /* Since there is no HID, CID and so on for VGA driver, we have | |
625 | * to check well known required nodes. | |
626 | */ | |
627 | ||
628 | /* Does this device able to support video switching ? */ | |
4be44fcd | 629 | if (video->cap._DOS) { |
1da177e4 LT |
630 | video->flags.multihead = 1; |
631 | status = 0; | |
632 | } | |
633 | ||
634 | /* Does this device able to retrieve a retrieve a video ROM ? */ | |
4be44fcd | 635 | if (video->cap._ROM) { |
1da177e4 LT |
636 | video->flags.rom = 1; |
637 | status = 0; | |
638 | } | |
639 | ||
640 | /* Does this device able to configure which video device to POST ? */ | |
4be44fcd | 641 | if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { |
1da177e4 LT |
642 | video->flags.post = 1; |
643 | status = 0; | |
644 | } | |
645 | ||
d550d98d | 646 | return status; |
1da177e4 LT |
647 | } |
648 | ||
649 | /* -------------------------------------------------------------------------- | |
650 | FS Interface (/proc) | |
651 | -------------------------------------------------------------------------- */ | |
652 | ||
4be44fcd | 653 | static struct proc_dir_entry *acpi_video_dir; |
1da177e4 LT |
654 | |
655 | /* video devices */ | |
656 | ||
4be44fcd | 657 | static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 658 | { |
4be44fcd LB |
659 | struct acpi_video_device *dev = |
660 | (struct acpi_video_device *)seq->private; | |
1da177e4 | 661 | |
1da177e4 LT |
662 | |
663 | if (!dev) | |
664 | goto end; | |
665 | ||
666 | seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id); | |
667 | seq_printf(seq, "type: "); | |
668 | if (dev->flags.crt) | |
669 | seq_printf(seq, "CRT\n"); | |
670 | else if (dev->flags.lcd) | |
671 | seq_printf(seq, "LCD\n"); | |
672 | else if (dev->flags.tvout) | |
673 | seq_printf(seq, "TVOUT\n"); | |
674 | else | |
675 | seq_printf(seq, "UNKNOWN\n"); | |
676 | ||
4be44fcd | 677 | seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no"); |
1da177e4 | 678 | |
4be44fcd | 679 | end: |
d550d98d | 680 | return 0; |
1da177e4 LT |
681 | } |
682 | ||
683 | static int | |
4be44fcd | 684 | acpi_video_device_info_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
685 | { |
686 | return single_open(file, acpi_video_device_info_seq_show, | |
687 | PDE(inode)->data); | |
688 | } | |
689 | ||
4be44fcd | 690 | static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 691 | { |
4be44fcd LB |
692 | int status; |
693 | struct acpi_video_device *dev = | |
694 | (struct acpi_video_device *)seq->private; | |
695 | unsigned long state; | |
1da177e4 | 696 | |
1da177e4 LT |
697 | |
698 | if (!dev) | |
699 | goto end; | |
700 | ||
701 | status = acpi_video_device_get_state(dev, &state); | |
702 | seq_printf(seq, "state: "); | |
703 | if (ACPI_SUCCESS(status)) | |
704 | seq_printf(seq, "0x%02lx\n", state); | |
705 | else | |
706 | seq_printf(seq, "<not supported>\n"); | |
707 | ||
708 | status = acpi_video_device_query(dev, &state); | |
709 | seq_printf(seq, "query: "); | |
710 | if (ACPI_SUCCESS(status)) | |
711 | seq_printf(seq, "0x%02lx\n", state); | |
712 | else | |
713 | seq_printf(seq, "<not supported>\n"); | |
714 | ||
4be44fcd | 715 | end: |
d550d98d | 716 | return 0; |
1da177e4 LT |
717 | } |
718 | ||
719 | static int | |
4be44fcd | 720 | acpi_video_device_state_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
721 | { |
722 | return single_open(file, acpi_video_device_state_seq_show, | |
723 | PDE(inode)->data); | |
724 | } | |
725 | ||
726 | static ssize_t | |
4be44fcd LB |
727 | acpi_video_device_write_state(struct file *file, |
728 | const char __user * buffer, | |
729 | size_t count, loff_t * data) | |
1da177e4 | 730 | { |
4be44fcd LB |
731 | int status; |
732 | struct seq_file *m = (struct seq_file *)file->private_data; | |
733 | struct acpi_video_device *dev = (struct acpi_video_device *)m->private; | |
734 | char str[12] = { 0 }; | |
735 | u32 state = 0; | |
1da177e4 | 736 | |
1da177e4 LT |
737 | |
738 | if (!dev || count + 1 > sizeof str) | |
d550d98d | 739 | return -EINVAL; |
1da177e4 LT |
740 | |
741 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 742 | return -EFAULT; |
1da177e4 LT |
743 | |
744 | str[count] = 0; | |
745 | state = simple_strtoul(str, NULL, 0); | |
4be44fcd | 746 | state &= ((1ul << 31) | (1ul << 30) | (1ul << 0)); |
1da177e4 LT |
747 | |
748 | status = acpi_video_device_set_state(dev, state); | |
749 | ||
750 | if (status) | |
d550d98d | 751 | return -EFAULT; |
1da177e4 | 752 | |
d550d98d | 753 | return count; |
1da177e4 LT |
754 | } |
755 | ||
756 | static int | |
4be44fcd | 757 | acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 758 | { |
4be44fcd LB |
759 | struct acpi_video_device *dev = |
760 | (struct acpi_video_device *)seq->private; | |
761 | int i; | |
1da177e4 | 762 | |
1da177e4 LT |
763 | |
764 | if (!dev || !dev->brightness) { | |
765 | seq_printf(seq, "<not supported>\n"); | |
d550d98d | 766 | return 0; |
1da177e4 LT |
767 | } |
768 | ||
769 | seq_printf(seq, "levels: "); | |
770 | for (i = 0; i < dev->brightness->count; i++) | |
771 | seq_printf(seq, " %d", dev->brightness->levels[i]); | |
772 | seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr); | |
773 | ||
d550d98d | 774 | return 0; |
1da177e4 LT |
775 | } |
776 | ||
777 | static int | |
4be44fcd | 778 | acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
779 | { |
780 | return single_open(file, acpi_video_device_brightness_seq_show, | |
781 | PDE(inode)->data); | |
782 | } | |
783 | ||
784 | static ssize_t | |
4be44fcd LB |
785 | acpi_video_device_write_brightness(struct file *file, |
786 | const char __user * buffer, | |
787 | size_t count, loff_t * data) | |
1da177e4 | 788 | { |
4be44fcd LB |
789 | struct seq_file *m = (struct seq_file *)file->private_data; |
790 | struct acpi_video_device *dev = (struct acpi_video_device *)m->private; | |
791 | char str[4] = { 0 }; | |
792 | unsigned int level = 0; | |
793 | int i; | |
1da177e4 | 794 | |
1da177e4 | 795 | |
59d399d3 | 796 | if (!dev || !dev->brightness || count + 1 > sizeof str) |
d550d98d | 797 | return -EINVAL; |
1da177e4 LT |
798 | |
799 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 800 | return -EFAULT; |
1da177e4 LT |
801 | |
802 | str[count] = 0; | |
803 | level = simple_strtoul(str, NULL, 0); | |
4be44fcd | 804 | |
1da177e4 | 805 | if (level > 100) |
d550d98d | 806 | return -EFAULT; |
1da177e4 LT |
807 | |
808 | /* validate though the list of available levels */ | |
809 | for (i = 0; i < dev->brightness->count; i++) | |
810 | if (level == dev->brightness->levels[i]) { | |
4be44fcd LB |
811 | if (ACPI_SUCCESS |
812 | (acpi_video_device_lcd_set_level(dev, level))) | |
1da177e4 LT |
813 | dev->brightness->curr = level; |
814 | break; | |
815 | } | |
816 | ||
d550d98d | 817 | return count; |
1da177e4 LT |
818 | } |
819 | ||
4be44fcd | 820 | static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 821 | { |
4be44fcd LB |
822 | struct acpi_video_device *dev = |
823 | (struct acpi_video_device *)seq->private; | |
824 | int status; | |
825 | int i; | |
826 | union acpi_object *edid = NULL; | |
1da177e4 | 827 | |
1da177e4 LT |
828 | |
829 | if (!dev) | |
830 | goto out; | |
831 | ||
4be44fcd | 832 | status = acpi_video_device_EDID(dev, &edid, 128); |
1da177e4 | 833 | if (ACPI_FAILURE(status)) { |
4be44fcd | 834 | status = acpi_video_device_EDID(dev, &edid, 256); |
1da177e4 LT |
835 | } |
836 | ||
837 | if (ACPI_FAILURE(status)) { | |
838 | goto out; | |
839 | } | |
840 | ||
841 | if (edid && edid->type == ACPI_TYPE_BUFFER) { | |
842 | for (i = 0; i < edid->buffer.length; i++) | |
843 | seq_putc(seq, edid->buffer.pointer[i]); | |
844 | } | |
845 | ||
4be44fcd | 846 | out: |
1da177e4 LT |
847 | if (!edid) |
848 | seq_printf(seq, "<not supported>\n"); | |
849 | else | |
850 | kfree(edid); | |
851 | ||
d550d98d | 852 | return 0; |
1da177e4 LT |
853 | } |
854 | ||
855 | static int | |
4be44fcd | 856 | acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
857 | { |
858 | return single_open(file, acpi_video_device_EDID_seq_show, | |
859 | PDE(inode)->data); | |
860 | } | |
861 | ||
4be44fcd | 862 | static int acpi_video_device_add_fs(struct acpi_device *device) |
1da177e4 | 863 | { |
4be44fcd | 864 | struct proc_dir_entry *entry = NULL; |
1da177e4 LT |
865 | struct acpi_video_device *vid_dev; |
866 | ||
1da177e4 LT |
867 | |
868 | if (!device) | |
d550d98d | 869 | return -ENODEV; |
1da177e4 | 870 | |
4be44fcd | 871 | vid_dev = (struct acpi_video_device *)acpi_driver_data(device); |
1da177e4 | 872 | if (!vid_dev) |
d550d98d | 873 | return -ENODEV; |
1da177e4 LT |
874 | |
875 | if (!acpi_device_dir(device)) { | |
876 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | |
4be44fcd | 877 | vid_dev->video->dir); |
1da177e4 | 878 | if (!acpi_device_dir(device)) |
d550d98d | 879 | return -ENODEV; |
1da177e4 LT |
880 | acpi_device_dir(device)->owner = THIS_MODULE; |
881 | } | |
882 | ||
883 | /* 'info' [R] */ | |
884 | entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device)); | |
885 | if (!entry) | |
d550d98d | 886 | return -ENODEV; |
1da177e4 LT |
887 | else { |
888 | entry->proc_fops = &acpi_video_device_info_fops; | |
889 | entry->data = acpi_driver_data(device); | |
890 | entry->owner = THIS_MODULE; | |
891 | } | |
892 | ||
893 | /* 'state' [R/W] */ | |
4be44fcd LB |
894 | entry = |
895 | create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR, | |
896 | acpi_device_dir(device)); | |
1da177e4 | 897 | if (!entry) |
d550d98d | 898 | return -ENODEV; |
1da177e4 | 899 | else { |
d479e908 | 900 | acpi_video_device_state_fops.write = acpi_video_device_write_state; |
1da177e4 | 901 | entry->proc_fops = &acpi_video_device_state_fops; |
1da177e4 LT |
902 | entry->data = acpi_driver_data(device); |
903 | entry->owner = THIS_MODULE; | |
904 | } | |
905 | ||
906 | /* 'brightness' [R/W] */ | |
4be44fcd LB |
907 | entry = |
908 | create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR, | |
909 | acpi_device_dir(device)); | |
1da177e4 | 910 | if (!entry) |
d550d98d | 911 | return -ENODEV; |
1da177e4 | 912 | else { |
d479e908 | 913 | acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness; |
1da177e4 | 914 | entry->proc_fops = &acpi_video_device_brightness_fops; |
1da177e4 LT |
915 | entry->data = acpi_driver_data(device); |
916 | entry->owner = THIS_MODULE; | |
917 | } | |
918 | ||
919 | /* 'EDID' [R] */ | |
920 | entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device)); | |
921 | if (!entry) | |
d550d98d | 922 | return -ENODEV; |
1da177e4 LT |
923 | else { |
924 | entry->proc_fops = &acpi_video_device_EDID_fops; | |
925 | entry->data = acpi_driver_data(device); | |
926 | entry->owner = THIS_MODULE; | |
927 | } | |
928 | ||
d550d98d | 929 | return 0; |
1da177e4 LT |
930 | } |
931 | ||
4be44fcd | 932 | static int acpi_video_device_remove_fs(struct acpi_device *device) |
1da177e4 LT |
933 | { |
934 | struct acpi_video_device *vid_dev; | |
1da177e4 | 935 | |
4be44fcd | 936 | vid_dev = (struct acpi_video_device *)acpi_driver_data(device); |
1da177e4 | 937 | if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) |
d550d98d | 938 | return -ENODEV; |
1da177e4 LT |
939 | |
940 | if (acpi_device_dir(device)) { | |
941 | remove_proc_entry("info", acpi_device_dir(device)); | |
942 | remove_proc_entry("state", acpi_device_dir(device)); | |
943 | remove_proc_entry("brightness", acpi_device_dir(device)); | |
944 | remove_proc_entry("EDID", acpi_device_dir(device)); | |
4be44fcd | 945 | remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir); |
1da177e4 LT |
946 | acpi_device_dir(device) = NULL; |
947 | } | |
948 | ||
d550d98d | 949 | return 0; |
1da177e4 LT |
950 | } |
951 | ||
1da177e4 | 952 | /* video bus */ |
4be44fcd | 953 | static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 954 | { |
4be44fcd | 955 | struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; |
1da177e4 | 956 | |
1da177e4 LT |
957 | |
958 | if (!video) | |
959 | goto end; | |
960 | ||
961 | seq_printf(seq, "Switching heads: %s\n", | |
4be44fcd | 962 | video->flags.multihead ? "yes" : "no"); |
1da177e4 | 963 | seq_printf(seq, "Video ROM: %s\n", |
4be44fcd | 964 | video->flags.rom ? "yes" : "no"); |
1da177e4 | 965 | seq_printf(seq, "Device to be POSTed on boot: %s\n", |
4be44fcd | 966 | video->flags.post ? "yes" : "no"); |
1da177e4 | 967 | |
4be44fcd | 968 | end: |
d550d98d | 969 | return 0; |
1da177e4 LT |
970 | } |
971 | ||
4be44fcd | 972 | static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 973 | { |
4be44fcd LB |
974 | return single_open(file, acpi_video_bus_info_seq_show, |
975 | PDE(inode)->data); | |
1da177e4 LT |
976 | } |
977 | ||
4be44fcd | 978 | static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 979 | { |
4be44fcd | 980 | struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; |
1da177e4 | 981 | |
1da177e4 LT |
982 | |
983 | if (!video) | |
984 | goto end; | |
985 | ||
986 | printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__); | |
987 | seq_printf(seq, "<TODO>\n"); | |
988 | ||
4be44fcd | 989 | end: |
d550d98d | 990 | return 0; |
1da177e4 LT |
991 | } |
992 | ||
4be44fcd | 993 | static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
994 | { |
995 | return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data); | |
996 | } | |
997 | ||
4be44fcd | 998 | static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 999 | { |
4be44fcd LB |
1000 | struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; |
1001 | unsigned long options; | |
1002 | int status; | |
1da177e4 | 1003 | |
1da177e4 LT |
1004 | |
1005 | if (!video) | |
1006 | goto end; | |
1007 | ||
1008 | status = acpi_video_bus_POST_options(video, &options); | |
1009 | if (ACPI_SUCCESS(status)) { | |
1010 | if (!(options & 1)) { | |
4be44fcd LB |
1011 | printk(KERN_WARNING PREFIX |
1012 | "The motherboard VGA device is not listed as a possible POST device.\n"); | |
1013 | printk(KERN_WARNING PREFIX | |
1014 | "This indicate a BIOS bug. Please contact the manufacturer.\n"); | |
1da177e4 LT |
1015 | } |
1016 | printk("%lx\n", options); | |
1017 | seq_printf(seq, "can POST: <intgrated video>"); | |
1018 | if (options & 2) | |
1019 | seq_printf(seq, " <PCI video>"); | |
1020 | if (options & 4) | |
1021 | seq_printf(seq, " <AGP video>"); | |
1022 | seq_putc(seq, '\n'); | |
1023 | } else | |
1024 | seq_printf(seq, "<not supported>\n"); | |
4be44fcd | 1025 | end: |
d550d98d | 1026 | return 0; |
1da177e4 LT |
1027 | } |
1028 | ||
1029 | static int | |
4be44fcd | 1030 | acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 1031 | { |
4be44fcd LB |
1032 | return single_open(file, acpi_video_bus_POST_info_seq_show, |
1033 | PDE(inode)->data); | |
1da177e4 LT |
1034 | } |
1035 | ||
4be44fcd | 1036 | static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1037 | { |
4be44fcd LB |
1038 | struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; |
1039 | int status; | |
1040 | unsigned long id; | |
1da177e4 | 1041 | |
1da177e4 LT |
1042 | |
1043 | if (!video) | |
1044 | goto end; | |
1045 | ||
4be44fcd | 1046 | status = acpi_video_bus_get_POST(video, &id); |
1da177e4 LT |
1047 | if (!ACPI_SUCCESS(status)) { |
1048 | seq_printf(seq, "<not supported>\n"); | |
1049 | goto end; | |
1050 | } | |
4be44fcd | 1051 | seq_printf(seq, "device posted is <%s>\n", device_decode[id & 3]); |
1da177e4 | 1052 | |
4be44fcd | 1053 | end: |
d550d98d | 1054 | return 0; |
1da177e4 LT |
1055 | } |
1056 | ||
4be44fcd | 1057 | static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1058 | { |
4be44fcd | 1059 | struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; |
1da177e4 | 1060 | |
1da177e4 | 1061 | |
4be44fcd | 1062 | seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting); |
1da177e4 | 1063 | |
d550d98d | 1064 | return 0; |
1da177e4 LT |
1065 | } |
1066 | ||
4be44fcd | 1067 | static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 1068 | { |
4be44fcd LB |
1069 | return single_open(file, acpi_video_bus_POST_seq_show, |
1070 | PDE(inode)->data); | |
1da177e4 LT |
1071 | } |
1072 | ||
4be44fcd | 1073 | static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1074 | { |
1075 | return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data); | |
1076 | } | |
1077 | ||
1078 | static ssize_t | |
4be44fcd LB |
1079 | acpi_video_bus_write_POST(struct file *file, |
1080 | const char __user * buffer, | |
1081 | size_t count, loff_t * data) | |
1da177e4 | 1082 | { |
4be44fcd LB |
1083 | int status; |
1084 | struct seq_file *m = (struct seq_file *)file->private_data; | |
1085 | struct acpi_video_bus *video = (struct acpi_video_bus *)m->private; | |
1086 | char str[12] = { 0 }; | |
1087 | unsigned long opt, options; | |
1da177e4 | 1088 | |
1da177e4 | 1089 | |
1da177e4 | 1090 | if (!video || count + 1 > sizeof str) |
d550d98d | 1091 | return -EINVAL; |
1da177e4 LT |
1092 | |
1093 | status = acpi_video_bus_POST_options(video, &options); | |
1094 | if (!ACPI_SUCCESS(status)) | |
d550d98d | 1095 | return -EINVAL; |
1da177e4 LT |
1096 | |
1097 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 1098 | return -EFAULT; |
1da177e4 LT |
1099 | |
1100 | str[count] = 0; | |
1101 | opt = strtoul(str, NULL, 0); | |
1102 | if (opt > 3) | |
d550d98d | 1103 | return -EFAULT; |
1da177e4 LT |
1104 | |
1105 | /* just in case an OEM 'forget' the motherboard... */ | |
1106 | options |= 1; | |
1107 | ||
1108 | if (options & (1ul << opt)) { | |
4be44fcd | 1109 | status = acpi_video_bus_set_POST(video, opt); |
1da177e4 | 1110 | if (!ACPI_SUCCESS(status)) |
d550d98d | 1111 | return -EFAULT; |
1da177e4 LT |
1112 | |
1113 | } | |
1114 | ||
d550d98d | 1115 | return count; |
1da177e4 LT |
1116 | } |
1117 | ||
1118 | static ssize_t | |
4be44fcd LB |
1119 | acpi_video_bus_write_DOS(struct file *file, |
1120 | const char __user * buffer, | |
1121 | size_t count, loff_t * data) | |
1da177e4 | 1122 | { |
4be44fcd LB |
1123 | int status; |
1124 | struct seq_file *m = (struct seq_file *)file->private_data; | |
1125 | struct acpi_video_bus *video = (struct acpi_video_bus *)m->private; | |
1126 | char str[12] = { 0 }; | |
1127 | unsigned long opt; | |
1da177e4 | 1128 | |
1da177e4 | 1129 | |
1da177e4 | 1130 | if (!video || count + 1 > sizeof str) |
d550d98d | 1131 | return -EINVAL; |
1da177e4 LT |
1132 | |
1133 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 1134 | return -EFAULT; |
1da177e4 LT |
1135 | |
1136 | str[count] = 0; | |
1137 | opt = strtoul(str, NULL, 0); | |
1138 | if (opt > 7) | |
d550d98d | 1139 | return -EFAULT; |
1da177e4 | 1140 | |
4be44fcd | 1141 | status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2); |
1da177e4 LT |
1142 | |
1143 | if (!ACPI_SUCCESS(status)) | |
d550d98d | 1144 | return -EFAULT; |
1da177e4 | 1145 | |
d550d98d | 1146 | return count; |
1da177e4 LT |
1147 | } |
1148 | ||
4be44fcd | 1149 | static int acpi_video_bus_add_fs(struct acpi_device *device) |
1da177e4 | 1150 | { |
4be44fcd LB |
1151 | struct proc_dir_entry *entry = NULL; |
1152 | struct acpi_video_bus *video; | |
1da177e4 | 1153 | |
1da177e4 | 1154 | |
4be44fcd | 1155 | video = (struct acpi_video_bus *)acpi_driver_data(device); |
1da177e4 LT |
1156 | |
1157 | if (!acpi_device_dir(device)) { | |
1158 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | |
4be44fcd | 1159 | acpi_video_dir); |
1da177e4 | 1160 | if (!acpi_device_dir(device)) |
d550d98d | 1161 | return -ENODEV; |
1da177e4 LT |
1162 | video->dir = acpi_device_dir(device); |
1163 | acpi_device_dir(device)->owner = THIS_MODULE; | |
1164 | } | |
1165 | ||
1166 | /* 'info' [R] */ | |
1167 | entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device)); | |
1168 | if (!entry) | |
d550d98d | 1169 | return -ENODEV; |
1da177e4 LT |
1170 | else { |
1171 | entry->proc_fops = &acpi_video_bus_info_fops; | |
1172 | entry->data = acpi_driver_data(device); | |
1173 | entry->owner = THIS_MODULE; | |
1174 | } | |
1175 | ||
1176 | /* 'ROM' [R] */ | |
1177 | entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device)); | |
1178 | if (!entry) | |
d550d98d | 1179 | return -ENODEV; |
1da177e4 LT |
1180 | else { |
1181 | entry->proc_fops = &acpi_video_bus_ROM_fops; | |
1182 | entry->data = acpi_driver_data(device); | |
1183 | entry->owner = THIS_MODULE; | |
1184 | } | |
1185 | ||
1186 | /* 'POST_info' [R] */ | |
4be44fcd LB |
1187 | entry = |
1188 | create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device)); | |
1da177e4 | 1189 | if (!entry) |
d550d98d | 1190 | return -ENODEV; |
1da177e4 LT |
1191 | else { |
1192 | entry->proc_fops = &acpi_video_bus_POST_info_fops; | |
1193 | entry->data = acpi_driver_data(device); | |
1194 | entry->owner = THIS_MODULE; | |
1195 | } | |
1196 | ||
1197 | /* 'POST' [R/W] */ | |
4be44fcd LB |
1198 | entry = |
1199 | create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR, | |
1200 | acpi_device_dir(device)); | |
1da177e4 | 1201 | if (!entry) |
d550d98d | 1202 | return -ENODEV; |
1da177e4 | 1203 | else { |
d479e908 | 1204 | acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST; |
1da177e4 | 1205 | entry->proc_fops = &acpi_video_bus_POST_fops; |
1da177e4 LT |
1206 | entry->data = acpi_driver_data(device); |
1207 | entry->owner = THIS_MODULE; | |
1208 | } | |
1209 | ||
1210 | /* 'DOS' [R/W] */ | |
4be44fcd LB |
1211 | entry = |
1212 | create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR, | |
1213 | acpi_device_dir(device)); | |
1da177e4 | 1214 | if (!entry) |
d550d98d | 1215 | return -ENODEV; |
1da177e4 | 1216 | else { |
d479e908 | 1217 | acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS; |
1da177e4 | 1218 | entry->proc_fops = &acpi_video_bus_DOS_fops; |
1da177e4 LT |
1219 | entry->data = acpi_driver_data(device); |
1220 | entry->owner = THIS_MODULE; | |
1221 | } | |
1222 | ||
d550d98d | 1223 | return 0; |
1da177e4 LT |
1224 | } |
1225 | ||
4be44fcd | 1226 | static int acpi_video_bus_remove_fs(struct acpi_device *device) |
1da177e4 | 1227 | { |
4be44fcd | 1228 | struct acpi_video_bus *video; |
1da177e4 | 1229 | |
1da177e4 | 1230 | |
4be44fcd | 1231 | video = (struct acpi_video_bus *)acpi_driver_data(device); |
1da177e4 LT |
1232 | |
1233 | if (acpi_device_dir(device)) { | |
1234 | remove_proc_entry("info", acpi_device_dir(device)); | |
1235 | remove_proc_entry("ROM", acpi_device_dir(device)); | |
1236 | remove_proc_entry("POST_info", acpi_device_dir(device)); | |
1237 | remove_proc_entry("POST", acpi_device_dir(device)); | |
1238 | remove_proc_entry("DOS", acpi_device_dir(device)); | |
4be44fcd | 1239 | remove_proc_entry(acpi_device_bid(device), acpi_video_dir); |
1da177e4 LT |
1240 | acpi_device_dir(device) = NULL; |
1241 | } | |
1242 | ||
d550d98d | 1243 | return 0; |
1da177e4 LT |
1244 | } |
1245 | ||
1246 | /* -------------------------------------------------------------------------- | |
1247 | Driver Interface | |
1248 | -------------------------------------------------------------------------- */ | |
1249 | ||
1250 | /* device interface */ | |
1251 | ||
1252 | static int | |
4be44fcd LB |
1253 | acpi_video_bus_get_one_device(struct acpi_device *device, |
1254 | struct acpi_video_bus *video) | |
1da177e4 | 1255 | { |
4be44fcd | 1256 | unsigned long device_id; |
973bf491 | 1257 | int status; |
4be44fcd | 1258 | struct acpi_video_device *data; |
1da177e4 | 1259 | |
1da177e4 LT |
1260 | |
1261 | if (!device || !video) | |
d550d98d | 1262 | return -EINVAL; |
1da177e4 | 1263 | |
4be44fcd LB |
1264 | status = |
1265 | acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); | |
1da177e4 LT |
1266 | if (ACPI_SUCCESS(status)) { |
1267 | ||
1268 | data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL); | |
1269 | if (!data) | |
d550d98d | 1270 | return -ENOMEM; |
1da177e4 LT |
1271 | |
1272 | memset(data, 0, sizeof(struct acpi_video_device)); | |
1273 | ||
1274 | data->handle = device->handle; | |
1275 | strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); | |
1276 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); | |
1277 | acpi_driver_data(device) = data; | |
1278 | ||
1279 | data->device_id = device_id; | |
1280 | data->video = video; | |
1281 | data->dev = device; | |
1282 | ||
1283 | switch (device_id & 0xffff) { | |
1284 | case 0x0100: | |
1285 | data->flags.crt = 1; | |
1286 | break; | |
1287 | case 0x0400: | |
1288 | data->flags.lcd = 1; | |
1289 | break; | |
1290 | case 0x0200: | |
1291 | data->flags.tvout = 1; | |
1292 | break; | |
1293 | default: | |
1294 | data->flags.unknown = 1; | |
1295 | break; | |
1296 | } | |
4be44fcd | 1297 | |
1da177e4 LT |
1298 | acpi_video_device_bind(video, data); |
1299 | acpi_video_device_find_cap(data); | |
1300 | ||
1301 | status = acpi_install_notify_handler(data->handle, | |
4be44fcd LB |
1302 | ACPI_DEVICE_NOTIFY, |
1303 | acpi_video_device_notify, | |
1304 | data); | |
1da177e4 LT |
1305 | if (ACPI_FAILURE(status)) { |
1306 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
4be44fcd | 1307 | "Error installing notify handler\n")); |
973bf491 YL |
1308 | if(data->brightness) |
1309 | kfree(data->brightness->levels); | |
1310 | kfree(data->brightness); | |
1311 | kfree(data); | |
1312 | return -ENODEV; | |
1da177e4 LT |
1313 | } |
1314 | ||
1315 | down(&video->sem); | |
1316 | list_add_tail(&data->entry, &video->video_device_list); | |
1317 | up(&video->sem); | |
1318 | ||
1319 | acpi_video_device_add_fs(device); | |
1320 | ||
d550d98d | 1321 | return 0; |
1da177e4 LT |
1322 | } |
1323 | ||
d550d98d | 1324 | return -ENOENT; |
1da177e4 LT |
1325 | } |
1326 | ||
1327 | /* | |
1328 | * Arg: | |
1329 | * video : video bus device | |
1330 | * | |
1331 | * Return: | |
1332 | * none | |
1333 | * | |
1334 | * Enumerate the video device list of the video bus, | |
1335 | * bind the ids with the corresponding video devices | |
1336 | * under the video bus. | |
4be44fcd | 1337 | */ |
1da177e4 | 1338 | |
4be44fcd | 1339 | static void acpi_video_device_rebind(struct acpi_video_bus *video) |
1da177e4 | 1340 | { |
4be44fcd | 1341 | struct list_head *node, *next; |
1da177e4 | 1342 | list_for_each_safe(node, next, &video->video_device_list) { |
4be44fcd LB |
1343 | struct acpi_video_device *dev = |
1344 | container_of(node, struct acpi_video_device, entry); | |
1345 | acpi_video_device_bind(video, dev); | |
1da177e4 LT |
1346 | } |
1347 | } | |
1348 | ||
1349 | /* | |
1350 | * Arg: | |
1351 | * video : video bus device | |
1352 | * device : video output device under the video | |
1353 | * bus | |
1354 | * | |
1355 | * Return: | |
1356 | * none | |
1357 | * | |
1358 | * Bind the ids with the corresponding video devices | |
1359 | * under the video bus. | |
4be44fcd | 1360 | */ |
1da177e4 LT |
1361 | |
1362 | static void | |
4be44fcd LB |
1363 | acpi_video_device_bind(struct acpi_video_bus *video, |
1364 | struct acpi_video_device *device) | |
1da177e4 | 1365 | { |
4be44fcd | 1366 | int i; |
1da177e4 LT |
1367 | |
1368 | #define IDS_VAL(i) video->attached_array[i].value.int_val | |
1369 | #define IDS_BIND(i) video->attached_array[i].bind_info | |
4be44fcd LB |
1370 | |
1371 | for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID && | |
1372 | i < video->attached_count; i++) { | |
1373 | if (device->device_id == (IDS_VAL(i) & 0xffff)) { | |
1da177e4 LT |
1374 | IDS_BIND(i) = device; |
1375 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i)); | |
1376 | } | |
1377 | } | |
1378 | #undef IDS_VAL | |
1379 | #undef IDS_BIND | |
1380 | } | |
1381 | ||
1382 | /* | |
1383 | * Arg: | |
1384 | * video : video bus device | |
1385 | * | |
1386 | * Return: | |
1387 | * < 0 : error | |
1388 | * | |
1389 | * Call _DOD to enumerate all devices attached to display adapter | |
1390 | * | |
4be44fcd | 1391 | */ |
1da177e4 LT |
1392 | |
1393 | static int acpi_video_device_enumerate(struct acpi_video_bus *video) | |
1394 | { | |
4be44fcd LB |
1395 | int status; |
1396 | int count; | |
1397 | int i; | |
1da177e4 | 1398 | struct acpi_video_enumerated_device *active_device_list; |
4be44fcd LB |
1399 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
1400 | union acpi_object *dod = NULL; | |
1401 | union acpi_object *obj; | |
1da177e4 | 1402 | |
1da177e4 LT |
1403 | |
1404 | status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer); | |
1405 | if (!ACPI_SUCCESS(status)) { | |
a6fc6720 | 1406 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD")); |
d550d98d | 1407 | return status; |
1da177e4 LT |
1408 | } |
1409 | ||
4be44fcd | 1410 | dod = (union acpi_object *)buffer.pointer; |
1da177e4 | 1411 | if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { |
a6fc6720 | 1412 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data")); |
1da177e4 LT |
1413 | status = -EFAULT; |
1414 | goto out; | |
1415 | } | |
1416 | ||
1417 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n", | |
4be44fcd | 1418 | dod->package.count)); |
1da177e4 | 1419 | |
4be44fcd LB |
1420 | active_device_list = kmalloc((1 + |
1421 | dod->package.count) * | |
1422 | sizeof(struct | |
1423 | acpi_video_enumerated_device), | |
1424 | GFP_KERNEL); | |
1da177e4 LT |
1425 | |
1426 | if (!active_device_list) { | |
1427 | status = -ENOMEM; | |
1428 | goto out; | |
1429 | } | |
1430 | ||
1431 | count = 0; | |
1432 | for (i = 0; i < dod->package.count; i++) { | |
4be44fcd | 1433 | obj = (union acpi_object *)&dod->package.elements[i]; |
1da177e4 LT |
1434 | |
1435 | if (obj->type != ACPI_TYPE_INTEGER) { | |
6468463a | 1436 | printk(KERN_ERR PREFIX "Invalid _DOD data\n"); |
4be44fcd LB |
1437 | active_device_list[i].value.int_val = |
1438 | ACPI_VIDEO_HEAD_INVALID; | |
1da177e4 LT |
1439 | } |
1440 | active_device_list[i].value.int_val = obj->integer.value; | |
1441 | active_device_list[i].bind_info = NULL; | |
4be44fcd LB |
1442 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i, |
1443 | (int)obj->integer.value)); | |
1da177e4 LT |
1444 | count++; |
1445 | } | |
1446 | active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END; | |
1447 | ||
6044ec88 | 1448 | kfree(video->attached_array); |
4be44fcd | 1449 | |
1da177e4 LT |
1450 | video->attached_array = active_device_list; |
1451 | video->attached_count = count; | |
4be44fcd | 1452 | out: |
1da177e4 | 1453 | acpi_os_free(buffer.pointer); |
d550d98d | 1454 | return status; |
1da177e4 LT |
1455 | } |
1456 | ||
1457 | /* | |
1458 | * Arg: | |
1459 | * video : video bus device | |
1460 | * event : Nontify Event | |
1461 | * | |
1462 | * Return: | |
1463 | * < 0 : error | |
1464 | * | |
1465 | * 1. Find out the current active output device. | |
1466 | * 2. Identify the next output device to switch | |
1467 | * 3. call _DSS to do actual switch. | |
4be44fcd | 1468 | */ |
1da177e4 | 1469 | |
4be44fcd | 1470 | static int acpi_video_switch_output(struct acpi_video_bus *video, int event) |
1da177e4 | 1471 | { |
4be44fcd LB |
1472 | struct list_head *node, *next; |
1473 | struct acpi_video_device *dev = NULL; | |
1474 | struct acpi_video_device *dev_next = NULL; | |
1475 | struct acpi_video_device *dev_prev = NULL; | |
1da177e4 LT |
1476 | unsigned long state; |
1477 | int status = 0; | |
1478 | ||
1da177e4 LT |
1479 | |
1480 | list_for_each_safe(node, next, &video->video_device_list) { | |
7334571f | 1481 | dev = container_of(node, struct acpi_video_device, entry); |
1da177e4 | 1482 | status = acpi_video_device_get_state(dev, &state); |
4be44fcd LB |
1483 | if (state & 0x2) { |
1484 | dev_next = | |
1485 | container_of(node->next, struct acpi_video_device, | |
1486 | entry); | |
1487 | dev_prev = | |
1488 | container_of(node->prev, struct acpi_video_device, | |
1489 | entry); | |
1da177e4 LT |
1490 | goto out; |
1491 | } | |
1492 | } | |
1493 | dev_next = container_of(node->next, struct acpi_video_device, entry); | |
1494 | dev_prev = container_of(node->prev, struct acpi_video_device, entry); | |
4be44fcd | 1495 | out: |
1da177e4 LT |
1496 | switch (event) { |
1497 | case ACPI_VIDEO_NOTIFY_CYCLE: | |
1498 | case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: | |
1499 | acpi_video_device_set_state(dev, 0); | |
1500 | acpi_video_device_set_state(dev_next, 0x80000001); | |
1501 | break; | |
1502 | case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: | |
1503 | acpi_video_device_set_state(dev, 0); | |
1504 | acpi_video_device_set_state(dev_prev, 0x80000001); | |
1505 | default: | |
1506 | break; | |
1507 | } | |
1508 | ||
d550d98d | 1509 | return status; |
1da177e4 LT |
1510 | } |
1511 | ||
4be44fcd LB |
1512 | static int |
1513 | acpi_video_get_next_level(struct acpi_video_device *device, | |
1514 | u32 level_current, u32 event) | |
1da177e4 | 1515 | { |
4be44fcd | 1516 | /*Fix me */ |
1da177e4 LT |
1517 | return level_current; |
1518 | } | |
1519 | ||
1da177e4 | 1520 | static void |
4be44fcd | 1521 | acpi_video_switch_brightness(struct acpi_video_device *device, int event) |
1da177e4 LT |
1522 | { |
1523 | unsigned long level_current, level_next; | |
1524 | acpi_video_device_lcd_get_level_current(device, &level_current); | |
1525 | level_next = acpi_video_get_next_level(device, level_current, event); | |
1526 | acpi_video_device_lcd_set_level(device, level_next); | |
1527 | } | |
1528 | ||
1529 | static int | |
4be44fcd LB |
1530 | acpi_video_bus_get_devices(struct acpi_video_bus *video, |
1531 | struct acpi_device *device) | |
1da177e4 | 1532 | { |
4be44fcd LB |
1533 | int status = 0; |
1534 | struct list_head *node, *next; | |
1da177e4 | 1535 | |
1da177e4 LT |
1536 | |
1537 | acpi_video_device_enumerate(video); | |
1538 | ||
1539 | list_for_each_safe(node, next, &device->children) { | |
4be44fcd LB |
1540 | struct acpi_device *dev = |
1541 | list_entry(node, struct acpi_device, node); | |
1da177e4 LT |
1542 | |
1543 | if (!dev) | |
1544 | continue; | |
1545 | ||
1546 | status = acpi_video_bus_get_one_device(dev, video); | |
1547 | if (ACPI_FAILURE(status)) { | |
a6fc6720 | 1548 | ACPI_EXCEPTION((AE_INFO, status, "Cant attach device")); |
1da177e4 LT |
1549 | continue; |
1550 | } | |
1551 | ||
1552 | } | |
d550d98d | 1553 | return status; |
1da177e4 LT |
1554 | } |
1555 | ||
4be44fcd | 1556 | static int acpi_video_bus_put_one_device(struct acpi_video_device *device) |
1da177e4 | 1557 | { |
031ec77b | 1558 | acpi_status status; |
1da177e4 LT |
1559 | struct acpi_video_bus *video; |
1560 | ||
1da177e4 LT |
1561 | |
1562 | if (!device || !device->video) | |
d550d98d | 1563 | return -ENOENT; |
1da177e4 LT |
1564 | |
1565 | video = device->video; | |
1566 | ||
1567 | down(&video->sem); | |
1568 | list_del(&device->entry); | |
1569 | up(&video->sem); | |
1570 | acpi_video_device_remove_fs(device->dev); | |
1571 | ||
031ec77b | 1572 | status = acpi_remove_notify_handler(device->handle, |
4be44fcd LB |
1573 | ACPI_DEVICE_NOTIFY, |
1574 | acpi_video_device_notify); | |
031ec77b | 1575 | |
d550d98d | 1576 | return 0; |
1da177e4 LT |
1577 | } |
1578 | ||
4be44fcd | 1579 | static int acpi_video_bus_put_devices(struct acpi_video_bus *video) |
1da177e4 | 1580 | { |
4be44fcd LB |
1581 | int status; |
1582 | struct list_head *node, *next; | |
1da177e4 | 1583 | |
1da177e4 LT |
1584 | |
1585 | list_for_each_safe(node, next, &video->video_device_list) { | |
4be44fcd LB |
1586 | struct acpi_video_device *data = |
1587 | list_entry(node, struct acpi_video_device, entry); | |
1da177e4 LT |
1588 | if (!data) |
1589 | continue; | |
1590 | ||
1591 | status = acpi_video_bus_put_one_device(data); | |
4be44fcd LB |
1592 | if (ACPI_FAILURE(status)) |
1593 | printk(KERN_WARNING PREFIX | |
1594 | "hhuuhhuu bug in acpi video driver.\n"); | |
1da177e4 | 1595 | |
d384ea69 | 1596 | if (data->brightness) |
973bf491 | 1597 | kfree(data->brightness->levels); |
6044ec88 | 1598 | kfree(data->brightness); |
1da177e4 LT |
1599 | kfree(data); |
1600 | } | |
1601 | ||
d550d98d | 1602 | return 0; |
1da177e4 LT |
1603 | } |
1604 | ||
1605 | /* acpi_video interface */ | |
1606 | ||
4be44fcd | 1607 | static int acpi_video_bus_start_devices(struct acpi_video_bus *video) |
1da177e4 LT |
1608 | { |
1609 | return acpi_video_bus_DOS(video, 1, 0); | |
1610 | } | |
1611 | ||
4be44fcd | 1612 | static int acpi_video_bus_stop_devices(struct acpi_video_bus *video) |
1da177e4 LT |
1613 | { |
1614 | return acpi_video_bus_DOS(video, 0, 1); | |
1615 | } | |
1616 | ||
4be44fcd | 1617 | static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) |
1da177e4 | 1618 | { |
4be44fcd LB |
1619 | struct acpi_video_bus *video = (struct acpi_video_bus *)data; |
1620 | struct acpi_device *device = NULL; | |
1da177e4 | 1621 | |
1da177e4 LT |
1622 | printk("video bus notify\n"); |
1623 | ||
1624 | if (!video) | |
d550d98d | 1625 | return; |
1da177e4 LT |
1626 | |
1627 | if (acpi_bus_get_device(handle, &device)) | |
d550d98d | 1628 | return; |
1da177e4 LT |
1629 | |
1630 | switch (event) { | |
1631 | case ACPI_VIDEO_NOTIFY_SWITCH: /* User request that a switch occur, | |
1632 | * most likely via hotkey. */ | |
1633 | acpi_bus_generate_event(device, event, 0); | |
1634 | break; | |
1635 | ||
1636 | case ACPI_VIDEO_NOTIFY_PROBE: /* User plug or remove a video | |
1637 | * connector. */ | |
1638 | acpi_video_device_enumerate(video); | |
1639 | acpi_video_device_rebind(video); | |
1640 | acpi_video_switch_output(video, event); | |
1641 | acpi_bus_generate_event(device, event, 0); | |
1642 | break; | |
1643 | ||
4be44fcd LB |
1644 | case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */ |
1645 | case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */ | |
1646 | case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */ | |
1da177e4 LT |
1647 | acpi_video_switch_output(video, event); |
1648 | acpi_bus_generate_event(device, event, 0); | |
1649 | break; | |
1650 | ||
1651 | default: | |
1652 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 1653 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
1654 | break; |
1655 | } | |
1656 | ||
d550d98d | 1657 | return; |
1da177e4 LT |
1658 | } |
1659 | ||
4be44fcd | 1660 | static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) |
1da177e4 | 1661 | { |
4be44fcd LB |
1662 | struct acpi_video_device *video_device = |
1663 | (struct acpi_video_device *)data; | |
1664 | struct acpi_device *device = NULL; | |
1da177e4 | 1665 | |
1da177e4 LT |
1666 | |
1667 | printk("video device notify\n"); | |
1668 | if (!video_device) | |
d550d98d | 1669 | return; |
1da177e4 LT |
1670 | |
1671 | if (acpi_bus_get_device(handle, &device)) | |
d550d98d | 1672 | return; |
1da177e4 LT |
1673 | |
1674 | switch (event) { | |
4be44fcd LB |
1675 | case ACPI_VIDEO_NOTIFY_SWITCH: /* change in status (cycle output device) */ |
1676 | case ACPI_VIDEO_NOTIFY_PROBE: /* change in status (output device status) */ | |
1da177e4 LT |
1677 | acpi_bus_generate_event(device, event, 0); |
1678 | break; | |
4be44fcd LB |
1679 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ |
1680 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ | |
1681 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ | |
1682 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */ | |
1683 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */ | |
1684 | acpi_video_switch_brightness(video_device, event); | |
1da177e4 LT |
1685 | acpi_bus_generate_event(device, event, 0); |
1686 | break; | |
1687 | default: | |
1688 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 1689 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
1690 | break; |
1691 | } | |
d550d98d | 1692 | return; |
1da177e4 LT |
1693 | } |
1694 | ||
4be44fcd | 1695 | static int acpi_video_bus_add(struct acpi_device *device) |
1da177e4 | 1696 | { |
4be44fcd LB |
1697 | int result = 0; |
1698 | acpi_status status = 0; | |
1699 | struct acpi_video_bus *video = NULL; | |
1da177e4 | 1700 | |
4be44fcd | 1701 | |
1da177e4 | 1702 | if (!device) |
d550d98d | 1703 | return -EINVAL; |
1da177e4 LT |
1704 | |
1705 | video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); | |
1706 | if (!video) | |
d550d98d | 1707 | return -ENOMEM; |
1da177e4 LT |
1708 | memset(video, 0, sizeof(struct acpi_video_bus)); |
1709 | ||
1710 | video->handle = device->handle; | |
1711 | strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); | |
1712 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); | |
1713 | acpi_driver_data(device) = video; | |
1714 | ||
1715 | acpi_video_bus_find_cap(video); | |
1716 | result = acpi_video_bus_check(video); | |
1717 | if (result) | |
1718 | goto end; | |
1719 | ||
1720 | result = acpi_video_bus_add_fs(device); | |
1721 | if (result) | |
1722 | goto end; | |
1723 | ||
1724 | init_MUTEX(&video->sem); | |
1725 | INIT_LIST_HEAD(&video->video_device_list); | |
1726 | ||
1727 | acpi_video_bus_get_devices(video, device); | |
1728 | acpi_video_bus_start_devices(video); | |
1729 | ||
1730 | status = acpi_install_notify_handler(video->handle, | |
4be44fcd LB |
1731 | ACPI_DEVICE_NOTIFY, |
1732 | acpi_video_bus_notify, video); | |
1da177e4 LT |
1733 | if (ACPI_FAILURE(status)) { |
1734 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
4be44fcd | 1735 | "Error installing notify handler\n")); |
973bf491 YL |
1736 | acpi_video_bus_stop_devices(video); |
1737 | acpi_video_bus_put_devices(video); | |
1738 | kfree(video->attached_array); | |
1739 | acpi_video_bus_remove_fs(device); | |
1da177e4 LT |
1740 | result = -ENODEV; |
1741 | goto end; | |
1742 | } | |
1743 | ||
1744 | printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", | |
4be44fcd LB |
1745 | ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), |
1746 | video->flags.multihead ? "yes" : "no", | |
1747 | video->flags.rom ? "yes" : "no", | |
1748 | video->flags.post ? "yes" : "no"); | |
1da177e4 | 1749 | |
4be44fcd | 1750 | end: |
973bf491 | 1751 | if (result) |
1da177e4 | 1752 | kfree(video); |
1da177e4 | 1753 | |
d550d98d | 1754 | return result; |
1da177e4 LT |
1755 | } |
1756 | ||
4be44fcd | 1757 | static int acpi_video_bus_remove(struct acpi_device *device, int type) |
1da177e4 | 1758 | { |
4be44fcd LB |
1759 | acpi_status status = 0; |
1760 | struct acpi_video_bus *video = NULL; | |
1da177e4 | 1761 | |
1da177e4 LT |
1762 | |
1763 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 1764 | return -EINVAL; |
1da177e4 | 1765 | |
4be44fcd | 1766 | video = (struct acpi_video_bus *)acpi_driver_data(device); |
1da177e4 LT |
1767 | |
1768 | acpi_video_bus_stop_devices(video); | |
1769 | ||
1770 | status = acpi_remove_notify_handler(video->handle, | |
4be44fcd LB |
1771 | ACPI_DEVICE_NOTIFY, |
1772 | acpi_video_bus_notify); | |
1da177e4 LT |
1773 | |
1774 | acpi_video_bus_put_devices(video); | |
1775 | acpi_video_bus_remove_fs(device); | |
1776 | ||
6044ec88 | 1777 | kfree(video->attached_array); |
1da177e4 LT |
1778 | kfree(video); |
1779 | ||
d550d98d | 1780 | return 0; |
1da177e4 LT |
1781 | } |
1782 | ||
1da177e4 | 1783 | static int |
4be44fcd | 1784 | acpi_video_bus_match(struct acpi_device *device, struct acpi_driver *driver) |
1da177e4 | 1785 | { |
4be44fcd LB |
1786 | acpi_handle h_dummy1; |
1787 | acpi_handle h_dummy2; | |
1788 | acpi_handle h_dummy3; | |
1da177e4 | 1789 | |
1da177e4 LT |
1790 | |
1791 | if (!device || !driver) | |
d550d98d | 1792 | return -EINVAL; |
1da177e4 LT |
1793 | |
1794 | /* Since there is no HID, CID for ACPI Video drivers, we have | |
1795 | * to check well known required nodes for each feature we support. | |
1796 | */ | |
1797 | ||
1798 | /* Does this device able to support video switching ? */ | |
1799 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) && | |
1800 | ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2))) | |
d550d98d | 1801 | return 0; |
1da177e4 LT |
1802 | |
1803 | /* Does this device able to retrieve a video ROM ? */ | |
1804 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1))) | |
d550d98d | 1805 | return 0; |
1da177e4 LT |
1806 | |
1807 | /* Does this device able to configure which video head to be POSTed ? */ | |
1808 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) && | |
1809 | ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) && | |
1810 | ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3))) | |
d550d98d | 1811 | return 0; |
1da177e4 | 1812 | |
d550d98d | 1813 | return -ENODEV; |
1da177e4 LT |
1814 | } |
1815 | ||
4be44fcd | 1816 | static int __init acpi_video_init(void) |
1da177e4 | 1817 | { |
4be44fcd | 1818 | int result = 0; |
1da177e4 | 1819 | |
1da177e4 LT |
1820 | |
1821 | /* | |
4be44fcd LB |
1822 | acpi_dbg_level = 0xFFFFFFFF; |
1823 | acpi_dbg_layer = 0x08000000; | |
1824 | */ | |
1da177e4 LT |
1825 | |
1826 | acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); | |
1827 | if (!acpi_video_dir) | |
d550d98d | 1828 | return -ENODEV; |
1da177e4 LT |
1829 | acpi_video_dir->owner = THIS_MODULE; |
1830 | ||
1831 | result = acpi_bus_register_driver(&acpi_video_bus); | |
1832 | if (result < 0) { | |
1833 | remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); | |
d550d98d | 1834 | return -ENODEV; |
1da177e4 LT |
1835 | } |
1836 | ||
d550d98d | 1837 | return 0; |
1da177e4 LT |
1838 | } |
1839 | ||
4be44fcd | 1840 | static void __exit acpi_video_exit(void) |
1da177e4 | 1841 | { |
1da177e4 LT |
1842 | |
1843 | acpi_bus_unregister_driver(&acpi_video_bus); | |
1844 | ||
1845 | remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); | |
1846 | ||
d550d98d | 1847 | return; |
1da177e4 LT |
1848 | } |
1849 | ||
1850 | module_init(acpi_video_init); | |
1851 | module_exit(acpi_video_exit); |