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