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