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