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