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