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