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