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, | |
27663c58 | 330 | unsigned long long *level); |
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 ZR |
347 | |
348 | if (acpi_video_device_lcd_get_level_current(vd, &cur_level)) | |
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 | |
c8890f90 ZR |
417 | if (acpi_video_device_lcd_get_level_current(video, &level)) |
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, |
27663c58 | 612 | unsigned long long *level) |
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 | } | |
636 | /* BQC returned an invalid level. Stop using it. */ | |
637 | ACPI_WARNING((AE_INFO, "%s returned an invalid level", | |
638 | buf)); | |
639 | device->cap._BQC = device->cap._BCQ = 0; | |
c8890f90 ZR |
640 | } else { |
641 | /* Fixme: | |
642 | * should we return an error or ignore this failure? | |
643 | * dev->brightness->curr is a cached value which stores | |
644 | * the correct current backlight level in most cases. | |
645 | * ACPI video backlight still works w/ buggy _BQC. | |
646 | * http://bugzilla.kernel.org/show_bug.cgi?id=12233 | |
647 | */ | |
c60d638e ZR |
648 | ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf)); |
649 | device->cap._BQC = device->cap._BCQ = 0; | |
c8890f90 ZR |
650 | } |
651 | } | |
652 | ||
4500ca8e | 653 | *level = device->brightness->curr; |
c8890f90 | 654 | return 0; |
1da177e4 LT |
655 | } |
656 | ||
657 | static int | |
4be44fcd LB |
658 | acpi_video_device_EDID(struct acpi_video_device *device, |
659 | union acpi_object **edid, ssize_t length) | |
1da177e4 | 660 | { |
4be44fcd LB |
661 | int status; |
662 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
663 | union acpi_object *obj; | |
664 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
665 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 666 | |
1da177e4 LT |
667 | |
668 | *edid = NULL; | |
669 | ||
670 | if (!device) | |
d550d98d | 671 | return -ENODEV; |
1da177e4 LT |
672 | if (length == 128) |
673 | arg0.integer.value = 1; | |
674 | else if (length == 256) | |
675 | arg0.integer.value = 2; | |
676 | else | |
d550d98d | 677 | return -EINVAL; |
1da177e4 | 678 | |
90130268 | 679 | status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); |
1da177e4 | 680 | if (ACPI_FAILURE(status)) |
d550d98d | 681 | return -ENODEV; |
1da177e4 | 682 | |
50dd0969 | 683 | obj = buffer.pointer; |
1da177e4 LT |
684 | |
685 | if (obj && obj->type == ACPI_TYPE_BUFFER) | |
686 | *edid = obj; | |
687 | else { | |
6468463a | 688 | printk(KERN_ERR PREFIX "Invalid _DDC data\n"); |
1da177e4 LT |
689 | status = -EFAULT; |
690 | kfree(obj); | |
691 | } | |
692 | ||
d550d98d | 693 | return status; |
1da177e4 LT |
694 | } |
695 | ||
1da177e4 LT |
696 | /* bus */ |
697 | ||
698 | static int | |
4be44fcd | 699 | acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option) |
1da177e4 | 700 | { |
4be44fcd | 701 | int status; |
27663c58 | 702 | unsigned long long tmp; |
4be44fcd LB |
703 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
704 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 705 | |
1da177e4 LT |
706 | |
707 | arg0.integer.value = option; | |
708 | ||
90130268 | 709 | status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp); |
1da177e4 | 710 | if (ACPI_SUCCESS(status)) |
4be44fcd | 711 | status = tmp ? (-EINVAL) : (AE_OK); |
1da177e4 | 712 | |
d550d98d | 713 | return status; |
1da177e4 LT |
714 | } |
715 | ||
716 | static int | |
27663c58 | 717 | acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id) |
1da177e4 LT |
718 | { |
719 | int status; | |
720 | ||
90130268 | 721 | status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id); |
1da177e4 | 722 | |
d550d98d | 723 | return status; |
1da177e4 LT |
724 | } |
725 | ||
726 | static int | |
4be44fcd | 727 | acpi_video_bus_POST_options(struct acpi_video_bus *video, |
27663c58 | 728 | unsigned long long *options) |
1da177e4 | 729 | { |
4be44fcd | 730 | int status; |
1da177e4 | 731 | |
90130268 | 732 | status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options); |
1da177e4 LT |
733 | *options &= 3; |
734 | ||
d550d98d | 735 | return status; |
1da177e4 LT |
736 | } |
737 | ||
738 | /* | |
739 | * Arg: | |
740 | * video : video bus device pointer | |
741 | * bios_flag : | |
742 | * 0. The system BIOS should NOT automatically switch(toggle) | |
743 | * the active display output. | |
744 | * 1. The system BIOS should automatically switch (toggle) the | |
98fb8fe1 | 745 | * active display output. No switch event. |
1da177e4 LT |
746 | * 2. The _DGS value should be locked. |
747 | * 3. The system BIOS should not automatically switch (toggle) the | |
748 | * active display output, but instead generate the display switch | |
749 | * event notify code. | |
750 | * lcd_flag : | |
751 | * 0. The system BIOS should automatically control the brightness level | |
98fb8fe1 | 752 | * of the LCD when the power changes from AC to DC |
1da177e4 | 753 | * 1. The system BIOS should NOT automatically control the brightness |
98fb8fe1 | 754 | * level of the LCD when the power changes from AC to DC. |
1da177e4 LT |
755 | * Return Value: |
756 | * -1 wrong arg. | |
757 | */ | |
758 | ||
759 | static int | |
4be44fcd | 760 | acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) |
1da177e4 | 761 | { |
4be44fcd LB |
762 | acpi_integer status = 0; |
763 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
764 | struct acpi_object_list args = { 1, &arg0 }; | |
1da177e4 | 765 | |
1da177e4 | 766 | |
4be44fcd | 767 | if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) { |
1da177e4 LT |
768 | status = -1; |
769 | goto Failed; | |
770 | } | |
771 | arg0.integer.value = (lcd_flag << 2) | bios_flag; | |
772 | video->dos_setting = arg0.integer.value; | |
90130268 | 773 | acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL); |
1da177e4 | 774 | |
4be44fcd | 775 | Failed: |
d550d98d | 776 | return status; |
1da177e4 LT |
777 | } |
778 | ||
935e5f29 ZR |
779 | /* |
780 | * Simple comparison function used to sort backlight levels. | |
781 | */ | |
782 | ||
783 | static int | |
784 | acpi_video_cmp_level(const void *a, const void *b) | |
785 | { | |
786 | return *(int *)a - *(int *)b; | |
787 | } | |
788 | ||
1da177e4 LT |
789 | /* |
790 | * Arg: | |
791 | * device : video output device (LCD, CRT, ..) | |
792 | * | |
793 | * Return Value: | |
469778c1 JJ |
794 | * Maximum brightness level |
795 | * | |
796 | * Allocate and initialize device->brightness. | |
797 | */ | |
798 | ||
799 | static int | |
800 | acpi_video_init_brightness(struct acpi_video_device *device) | |
801 | { | |
802 | union acpi_object *obj = NULL; | |
d32f6947 | 803 | int i, max_level = 0, count = 0, level_ac_battery = 0; |
1a7c618a | 804 | unsigned long long level, level_old; |
469778c1 JJ |
805 | union acpi_object *o; |
806 | struct acpi_video_device_brightness *br = NULL; | |
1a7c618a | 807 | int result = -EINVAL; |
469778c1 JJ |
808 | |
809 | if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { | |
810 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " | |
811 | "LCD brightness level\n")); | |
812 | goto out; | |
813 | } | |
814 | ||
815 | if (obj->package.count < 2) | |
816 | goto out; | |
817 | ||
818 | br = kzalloc(sizeof(*br), GFP_KERNEL); | |
819 | if (!br) { | |
820 | printk(KERN_ERR "can't allocate memory\n"); | |
1a7c618a | 821 | result = -ENOMEM; |
469778c1 JJ |
822 | goto out; |
823 | } | |
824 | ||
d32f6947 | 825 | br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels), |
469778c1 | 826 | GFP_KERNEL); |
1a7c618a ZR |
827 | if (!br->levels) { |
828 | result = -ENOMEM; | |
469778c1 | 829 | goto out_free; |
1a7c618a | 830 | } |
469778c1 JJ |
831 | |
832 | for (i = 0; i < obj->package.count; i++) { | |
833 | o = (union acpi_object *)&obj->package.elements[i]; | |
834 | if (o->type != ACPI_TYPE_INTEGER) { | |
835 | printk(KERN_ERR PREFIX "Invalid data\n"); | |
836 | continue; | |
837 | } | |
838 | br->levels[count] = (u32) o->integer.value; | |
839 | ||
840 | if (br->levels[count] > max_level) | |
841 | max_level = br->levels[count]; | |
842 | count++; | |
843 | } | |
844 | ||
d32f6947 ZR |
845 | /* |
846 | * some buggy BIOS don't export the levels | |
847 | * when machine is on AC/Battery in _BCL package. | |
848 | * In this case, the first two elements in _BCL packages | |
849 | * are also supported brightness levels that OS should take care of. | |
850 | */ | |
90af2cf6 ZR |
851 | for (i = 2; i < count; i++) { |
852 | if (br->levels[i] == br->levels[0]) | |
d32f6947 | 853 | level_ac_battery++; |
90af2cf6 ZR |
854 | if (br->levels[i] == br->levels[1]) |
855 | level_ac_battery++; | |
856 | } | |
d32f6947 ZR |
857 | |
858 | if (level_ac_battery < 2) { | |
859 | level_ac_battery = 2 - level_ac_battery; | |
860 | br->flags._BCL_no_ac_battery_levels = 1; | |
861 | for (i = (count - 1 + level_ac_battery); i >= 2; i--) | |
862 | br->levels[i] = br->levels[i - level_ac_battery]; | |
863 | count += level_ac_battery; | |
864 | } else if (level_ac_battery > 2) | |
865 | ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n")); | |
866 | ||
d80fb99f ZR |
867 | /* Check if the _BCL package is in a reversed order */ |
868 | if (max_level == br->levels[2]) { | |
869 | br->flags._BCL_reversed = 1; | |
870 | sort(&br->levels[2], count - 2, sizeof(br->levels[2]), | |
871 | acpi_video_cmp_level, NULL); | |
872 | } else if (max_level != br->levels[count - 1]) | |
873 | ACPI_ERROR((AE_INFO, | |
874 | "Found unordered _BCL package\n")); | |
469778c1 JJ |
875 | |
876 | br->count = count; | |
877 | device->brightness = br; | |
1a7c618a ZR |
878 | |
879 | /* Check the input/output of _BQC/_BCL/_BCM */ | |
880 | if ((max_level < 100) && (max_level <= (count - 2))) | |
881 | br->flags._BCL_use_index = 1; | |
882 | ||
883 | /* | |
884 | * _BCM is always consistent with _BCL, | |
885 | * at least for all the laptops we have ever seen. | |
886 | */ | |
887 | br->flags._BCM_use_index = br->flags._BCL_use_index; | |
888 | ||
889 | /* _BQC uses INDEX while _BCL uses VALUE in some laptops */ | |
90c53ca4 | 890 | br->curr = level = max_level; |
e047cca6 ZR |
891 | |
892 | if (!device->cap._BQC) | |
893 | goto set_level; | |
894 | ||
1a7c618a ZR |
895 | result = acpi_video_device_lcd_get_level_current(device, &level_old); |
896 | if (result) | |
897 | goto out_free_levels; | |
898 | ||
e047cca6 ZR |
899 | /* |
900 | * Set the level to maximum and check if _BQC uses indexed value | |
901 | */ | |
902 | result = acpi_video_device_lcd_set_level(device, max_level); | |
1a7c618a ZR |
903 | if (result) |
904 | goto out_free_levels; | |
905 | ||
906 | result = acpi_video_device_lcd_get_level_current(device, &level); | |
907 | if (result) | |
908 | goto out_free_levels; | |
909 | ||
e047cca6 ZR |
910 | br->flags._BQC_use_index = (level == max_level ? 0 : 1); |
911 | ||
90c53ca4 ZR |
912 | if (!br->flags._BQC_use_index) { |
913 | /* | |
914 | * Set the backlight to the initial state. | |
915 | * On some buggy laptops, _BQC returns an uninitialized value | |
916 | * when invoked for the first time, i.e. level_old is invalid. | |
917 | * set the backlight to max_level in this case | |
918 | */ | |
919 | for (i = 2; i < br->count; i++) | |
920 | if (level_old == br->levels[i]) | |
921 | level = level_old; | |
e047cca6 | 922 | goto set_level; |
90c53ca4 | 923 | } |
e047cca6 ZR |
924 | |
925 | if (br->flags._BCL_reversed) | |
926 | level_old = (br->count - 1) - level_old; | |
90c53ca4 | 927 | level = br->levels[level_old]; |
e047cca6 ZR |
928 | |
929 | set_level: | |
90c53ca4 | 930 | result = acpi_video_device_lcd_set_level(device, level); |
e047cca6 ZR |
931 | if (result) |
932 | goto out_free_levels; | |
1a7c618a | 933 | |
d32f6947 ZR |
934 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
935 | "found %d brightness levels\n", count - 2)); | |
469778c1 | 936 | kfree(obj); |
1a7c618a | 937 | return result; |
469778c1 JJ |
938 | |
939 | out_free_levels: | |
940 | kfree(br->levels); | |
941 | out_free: | |
942 | kfree(br); | |
943 | out: | |
944 | device->brightness = NULL; | |
945 | kfree(obj); | |
1a7c618a | 946 | return result; |
469778c1 JJ |
947 | } |
948 | ||
949 | /* | |
950 | * Arg: | |
951 | * device : video output device (LCD, CRT, ..) | |
952 | * | |
953 | * Return Value: | |
1da177e4 LT |
954 | * None |
955 | * | |
98fb8fe1 | 956 | * Find out all required AML methods defined under the output |
1da177e4 LT |
957 | * device. |
958 | */ | |
959 | ||
4be44fcd | 960 | static void acpi_video_device_find_cap(struct acpi_video_device *device) |
1da177e4 | 961 | { |
1da177e4 | 962 | acpi_handle h_dummy1; |
1da177e4 | 963 | |
90130268 | 964 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) { |
1da177e4 LT |
965 | device->cap._ADR = 1; |
966 | } | |
90130268 | 967 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) { |
4be44fcd | 968 | device->cap._BCL = 1; |
1da177e4 | 969 | } |
90130268 | 970 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) { |
4be44fcd | 971 | device->cap._BCM = 1; |
1da177e4 | 972 | } |
2f3d000a YL |
973 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1))) |
974 | device->cap._BQC = 1; | |
c60d638e ZR |
975 | else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ", |
976 | &h_dummy1))) { | |
977 | printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n"); | |
978 | device->cap._BCQ = 1; | |
979 | } | |
980 | ||
90130268 | 981 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) { |
4be44fcd | 982 | device->cap._DDC = 1; |
1da177e4 | 983 | } |
90130268 | 984 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) { |
1da177e4 LT |
985 | device->cap._DCS = 1; |
986 | } | |
90130268 | 987 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) { |
1da177e4 LT |
988 | device->cap._DGS = 1; |
989 | } | |
90130268 | 990 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) { |
1da177e4 LT |
991 | device->cap._DSS = 1; |
992 | } | |
993 | ||
1a7c618a | 994 | if (acpi_video_backlight_support()) { |
702ed512 | 995 | int result; |
2f3d000a YL |
996 | static int count = 0; |
997 | char *name; | |
1a7c618a ZR |
998 | |
999 | result = acpi_video_init_brightness(device); | |
1000 | if (result) | |
1001 | return; | |
2f3d000a YL |
1002 | name = kzalloc(MAX_NAME_LEN, GFP_KERNEL); |
1003 | if (!name) | |
1004 | return; | |
1005 | ||
2f3d000a | 1006 | sprintf(name, "acpi_video%d", count++); |
2f3d000a | 1007 | device->backlight = backlight_device_register(name, |
599a52d1 | 1008 | NULL, device, &acpi_backlight_ops); |
2f3d000a | 1009 | kfree(name); |
e01ce79b ZR |
1010 | if (IS_ERR(device->backlight)) |
1011 | return; | |
1012 | device->backlight->props.max_brightness = device->brightness->count-3; | |
702ed512 | 1013 | |
056c308d ZR |
1014 | result = sysfs_create_link(&device->backlight->dev.kobj, |
1015 | &device->dev->dev.kobj, "device"); | |
1016 | if (result) | |
1017 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | |
1018 | ||
4a703a8f | 1019 | device->cooling_dev = thermal_cooling_device_register("LCD", |
702ed512 | 1020 | device->dev, &video_cooling_ops); |
4a703a8f | 1021 | if (IS_ERR(device->cooling_dev)) { |
4b4fe3b6 | 1022 | /* |
4a703a8f | 1023 | * Set cooling_dev to NULL so we don't crash trying to |
4b4fe3b6 DT |
1024 | * free it. |
1025 | * Also, why the hell we are returning early and | |
1026 | * not attempt to register video output if cooling | |
1027 | * device registration failed? | |
1028 | * -- dtor | |
1029 | */ | |
4a703a8f | 1030 | device->cooling_dev = NULL; |
43ff39f2 | 1031 | return; |
4b4fe3b6 | 1032 | } |
43ff39f2 | 1033 | |
fc3a8828 | 1034 | dev_info(&device->dev->dev, "registered as cooling_device%d\n", |
4a703a8f | 1035 | device->cooling_dev->id); |
9030062f | 1036 | result = sysfs_create_link(&device->dev->dev.kobj, |
4a703a8f | 1037 | &device->cooling_dev->device.kobj, |
9030062f JL |
1038 | "thermal_cooling"); |
1039 | if (result) | |
1040 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | |
4a703a8f | 1041 | result = sysfs_create_link(&device->cooling_dev->device.kobj, |
9030062f JL |
1042 | &device->dev->dev.kobj, "device"); |
1043 | if (result) | |
1044 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | |
1045 | ||
2f3d000a | 1046 | } |
c3d6de69 TR |
1047 | |
1048 | if (acpi_video_display_switch_support()) { | |
1049 | ||
1050 | if (device->cap._DCS && device->cap._DSS) { | |
1051 | static int count; | |
1052 | char *name; | |
1053 | name = kzalloc(MAX_NAME_LEN, GFP_KERNEL); | |
1054 | if (!name) | |
1055 | return; | |
1056 | sprintf(name, "acpi_video%d", count++); | |
1057 | device->output_dev = video_output_register(name, | |
1058 | NULL, device, &acpi_output_properties); | |
1059 | kfree(name); | |
1060 | } | |
23b0f015 | 1061 | } |
1da177e4 LT |
1062 | } |
1063 | ||
1064 | /* | |
1065 | * Arg: | |
1066 | * device : video output device (VGA) | |
1067 | * | |
1068 | * Return Value: | |
1069 | * None | |
1070 | * | |
98fb8fe1 | 1071 | * Find out all required AML methods defined under the video bus device. |
1da177e4 LT |
1072 | */ |
1073 | ||
4be44fcd | 1074 | static void acpi_video_bus_find_cap(struct acpi_video_bus *video) |
1da177e4 | 1075 | { |
4be44fcd | 1076 | acpi_handle h_dummy1; |
1da177e4 | 1077 | |
90130268 | 1078 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) { |
1da177e4 LT |
1079 | video->cap._DOS = 1; |
1080 | } | |
90130268 | 1081 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) { |
1da177e4 LT |
1082 | video->cap._DOD = 1; |
1083 | } | |
90130268 | 1084 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) { |
1da177e4 LT |
1085 | video->cap._ROM = 1; |
1086 | } | |
90130268 | 1087 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) { |
1da177e4 LT |
1088 | video->cap._GPD = 1; |
1089 | } | |
90130268 | 1090 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) { |
1da177e4 LT |
1091 | video->cap._SPD = 1; |
1092 | } | |
90130268 | 1093 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) { |
1da177e4 LT |
1094 | video->cap._VPO = 1; |
1095 | } | |
1096 | } | |
1097 | ||
1098 | /* | |
1099 | * Check whether the video bus device has required AML method to | |
1100 | * support the desired features | |
1101 | */ | |
1102 | ||
4be44fcd | 1103 | static int acpi_video_bus_check(struct acpi_video_bus *video) |
1da177e4 | 1104 | { |
4be44fcd | 1105 | acpi_status status = -ENOENT; |
1e4cffe7 | 1106 | struct pci_dev *dev; |
1da177e4 LT |
1107 | |
1108 | if (!video) | |
d550d98d | 1109 | return -EINVAL; |
1da177e4 | 1110 | |
1e4cffe7 | 1111 | dev = acpi_get_pci_dev(video->device->handle); |
22c13f9d TR |
1112 | if (!dev) |
1113 | return -ENODEV; | |
1e4cffe7 | 1114 | pci_dev_put(dev); |
22c13f9d | 1115 | |
1da177e4 LT |
1116 | /* Since there is no HID, CID and so on for VGA driver, we have |
1117 | * to check well known required nodes. | |
1118 | */ | |
1119 | ||
98fb8fe1 | 1120 | /* Does this device support video switching? */ |
3a1151e3 SB |
1121 | if (video->cap._DOS || video->cap._DOD) { |
1122 | if (!video->cap._DOS) { | |
1123 | printk(KERN_WARNING FW_BUG | |
1124 | "ACPI(%s) defines _DOD but not _DOS\n", | |
1125 | acpi_device_bid(video->device)); | |
1126 | } | |
1da177e4 LT |
1127 | video->flags.multihead = 1; |
1128 | status = 0; | |
1129 | } | |
1130 | ||
98fb8fe1 | 1131 | /* Does this device support retrieving a video ROM? */ |
4be44fcd | 1132 | if (video->cap._ROM) { |
1da177e4 LT |
1133 | video->flags.rom = 1; |
1134 | status = 0; | |
1135 | } | |
1136 | ||
98fb8fe1 | 1137 | /* Does this device support configuring which video device to POST? */ |
4be44fcd | 1138 | if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { |
1da177e4 LT |
1139 | video->flags.post = 1; |
1140 | status = 0; | |
1141 | } | |
1142 | ||
d550d98d | 1143 | return status; |
1da177e4 LT |
1144 | } |
1145 | ||
1146 | /* -------------------------------------------------------------------------- | |
1147 | FS Interface (/proc) | |
1148 | -------------------------------------------------------------------------- */ | |
1149 | ||
4be44fcd | 1150 | static struct proc_dir_entry *acpi_video_dir; |
1da177e4 LT |
1151 | |
1152 | /* video devices */ | |
1153 | ||
4be44fcd | 1154 | static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1155 | { |
50dd0969 | 1156 | struct acpi_video_device *dev = seq->private; |
1da177e4 | 1157 | |
1da177e4 LT |
1158 | |
1159 | if (!dev) | |
1160 | goto end; | |
1161 | ||
1162 | seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id); | |
1163 | seq_printf(seq, "type: "); | |
1164 | if (dev->flags.crt) | |
1165 | seq_printf(seq, "CRT\n"); | |
1166 | else if (dev->flags.lcd) | |
1167 | seq_printf(seq, "LCD\n"); | |
1168 | else if (dev->flags.tvout) | |
1169 | seq_printf(seq, "TVOUT\n"); | |
82cae999 RZ |
1170 | else if (dev->flags.dvi) |
1171 | seq_printf(seq, "DVI\n"); | |
1da177e4 LT |
1172 | else |
1173 | seq_printf(seq, "UNKNOWN\n"); | |
1174 | ||
4be44fcd | 1175 | seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no"); |
1da177e4 | 1176 | |
4be44fcd | 1177 | end: |
d550d98d | 1178 | return 0; |
1da177e4 LT |
1179 | } |
1180 | ||
1181 | static int | |
4be44fcd | 1182 | acpi_video_device_info_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1183 | { |
1184 | return single_open(file, acpi_video_device_info_seq_show, | |
1185 | PDE(inode)->data); | |
1186 | } | |
1187 | ||
4be44fcd | 1188 | static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1189 | { |
4be44fcd | 1190 | int status; |
50dd0969 | 1191 | struct acpi_video_device *dev = seq->private; |
27663c58 | 1192 | unsigned long long state; |
1da177e4 | 1193 | |
1da177e4 LT |
1194 | |
1195 | if (!dev) | |
1196 | goto end; | |
1197 | ||
1198 | status = acpi_video_device_get_state(dev, &state); | |
1199 | seq_printf(seq, "state: "); | |
1200 | if (ACPI_SUCCESS(status)) | |
27663c58 | 1201 | seq_printf(seq, "0x%02llx\n", state); |
1da177e4 LT |
1202 | else |
1203 | seq_printf(seq, "<not supported>\n"); | |
1204 | ||
1205 | status = acpi_video_device_query(dev, &state); | |
1206 | seq_printf(seq, "query: "); | |
1207 | if (ACPI_SUCCESS(status)) | |
27663c58 | 1208 | seq_printf(seq, "0x%02llx\n", state); |
1da177e4 LT |
1209 | else |
1210 | seq_printf(seq, "<not supported>\n"); | |
1211 | ||
4be44fcd | 1212 | end: |
d550d98d | 1213 | return 0; |
1da177e4 LT |
1214 | } |
1215 | ||
1216 | static int | |
4be44fcd | 1217 | acpi_video_device_state_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1218 | { |
1219 | return single_open(file, acpi_video_device_state_seq_show, | |
1220 | PDE(inode)->data); | |
1221 | } | |
1222 | ||
1223 | static ssize_t | |
4be44fcd LB |
1224 | acpi_video_device_write_state(struct file *file, |
1225 | const char __user * buffer, | |
1226 | size_t count, loff_t * data) | |
1da177e4 | 1227 | { |
4be44fcd | 1228 | int status; |
50dd0969 JE |
1229 | struct seq_file *m = file->private_data; |
1230 | struct acpi_video_device *dev = m->private; | |
4be44fcd LB |
1231 | char str[12] = { 0 }; |
1232 | u32 state = 0; | |
1da177e4 | 1233 | |
1da177e4 | 1234 | |
52a2b11c | 1235 | if (!dev || count >= sizeof(str)) |
d550d98d | 1236 | return -EINVAL; |
1da177e4 LT |
1237 | |
1238 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 1239 | return -EFAULT; |
1da177e4 LT |
1240 | |
1241 | str[count] = 0; | |
1242 | state = simple_strtoul(str, NULL, 0); | |
4be44fcd | 1243 | state &= ((1ul << 31) | (1ul << 30) | (1ul << 0)); |
1da177e4 LT |
1244 | |
1245 | status = acpi_video_device_set_state(dev, state); | |
1246 | ||
1247 | if (status) | |
d550d98d | 1248 | return -EFAULT; |
1da177e4 | 1249 | |
d550d98d | 1250 | return count; |
1da177e4 LT |
1251 | } |
1252 | ||
1253 | static int | |
4be44fcd | 1254 | acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1255 | { |
50dd0969 | 1256 | struct acpi_video_device *dev = seq->private; |
4be44fcd | 1257 | int i; |
1da177e4 | 1258 | |
1da177e4 LT |
1259 | |
1260 | if (!dev || !dev->brightness) { | |
1261 | seq_printf(seq, "<not supported>\n"); | |
d550d98d | 1262 | return 0; |
1da177e4 LT |
1263 | } |
1264 | ||
1265 | seq_printf(seq, "levels: "); | |
0a3db1ce | 1266 | for (i = 2; i < dev->brightness->count; i++) |
1da177e4 LT |
1267 | seq_printf(seq, " %d", dev->brightness->levels[i]); |
1268 | seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr); | |
1269 | ||
d550d98d | 1270 | return 0; |
1da177e4 LT |
1271 | } |
1272 | ||
1273 | static int | |
4be44fcd | 1274 | acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1275 | { |
1276 | return single_open(file, acpi_video_device_brightness_seq_show, | |
1277 | PDE(inode)->data); | |
1278 | } | |
1279 | ||
1280 | static ssize_t | |
4be44fcd LB |
1281 | acpi_video_device_write_brightness(struct file *file, |
1282 | const char __user * buffer, | |
1283 | size_t count, loff_t * data) | |
1da177e4 | 1284 | { |
50dd0969 JE |
1285 | struct seq_file *m = file->private_data; |
1286 | struct acpi_video_device *dev = m->private; | |
c88c5786 | 1287 | char str[5] = { 0 }; |
4be44fcd LB |
1288 | unsigned int level = 0; |
1289 | int i; | |
1da177e4 | 1290 | |
1da177e4 | 1291 | |
52a2b11c | 1292 | if (!dev || !dev->brightness || count >= sizeof(str)) |
d550d98d | 1293 | return -EINVAL; |
1da177e4 LT |
1294 | |
1295 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 1296 | return -EFAULT; |
1da177e4 LT |
1297 | |
1298 | str[count] = 0; | |
1299 | level = simple_strtoul(str, NULL, 0); | |
4be44fcd | 1300 | |
1da177e4 | 1301 | if (level > 100) |
d550d98d | 1302 | return -EFAULT; |
1da177e4 | 1303 | |
98fb8fe1 | 1304 | /* validate through the list of available levels */ |
0a3db1ce | 1305 | for (i = 2; i < dev->brightness->count; i++) |
1da177e4 | 1306 | if (level == dev->brightness->levels[i]) { |
24450c7a ZR |
1307 | if (!acpi_video_device_lcd_set_level(dev, level)) |
1308 | return count; | |
1da177e4 LT |
1309 | break; |
1310 | } | |
1311 | ||
24450c7a | 1312 | return -EINVAL; |
1da177e4 LT |
1313 | } |
1314 | ||
4be44fcd | 1315 | static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1316 | { |
50dd0969 | 1317 | struct acpi_video_device *dev = seq->private; |
4be44fcd LB |
1318 | int status; |
1319 | int i; | |
1320 | union acpi_object *edid = NULL; | |
1da177e4 | 1321 | |
1da177e4 LT |
1322 | |
1323 | if (!dev) | |
1324 | goto out; | |
1325 | ||
4be44fcd | 1326 | status = acpi_video_device_EDID(dev, &edid, 128); |
1da177e4 | 1327 | if (ACPI_FAILURE(status)) { |
4be44fcd | 1328 | status = acpi_video_device_EDID(dev, &edid, 256); |
1da177e4 LT |
1329 | } |
1330 | ||
1331 | if (ACPI_FAILURE(status)) { | |
1332 | goto out; | |
1333 | } | |
1334 | ||
1335 | if (edid && edid->type == ACPI_TYPE_BUFFER) { | |
1336 | for (i = 0; i < edid->buffer.length; i++) | |
1337 | seq_putc(seq, edid->buffer.pointer[i]); | |
1338 | } | |
1339 | ||
4be44fcd | 1340 | out: |
1da177e4 LT |
1341 | if (!edid) |
1342 | seq_printf(seq, "<not supported>\n"); | |
1343 | else | |
1344 | kfree(edid); | |
1345 | ||
d550d98d | 1346 | return 0; |
1da177e4 LT |
1347 | } |
1348 | ||
1349 | static int | |
4be44fcd | 1350 | acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1351 | { |
1352 | return single_open(file, acpi_video_device_EDID_seq_show, | |
1353 | PDE(inode)->data); | |
1354 | } | |
1355 | ||
4be44fcd | 1356 | static int acpi_video_device_add_fs(struct acpi_device *device) |
1da177e4 | 1357 | { |
251cb0bc | 1358 | struct proc_dir_entry *entry, *device_dir; |
1da177e4 LT |
1359 | struct acpi_video_device *vid_dev; |
1360 | ||
50dd0969 | 1361 | vid_dev = acpi_driver_data(device); |
1da177e4 | 1362 | if (!vid_dev) |
d550d98d | 1363 | return -ENODEV; |
1da177e4 | 1364 | |
251cb0bc DT |
1365 | device_dir = proc_mkdir(acpi_device_bid(device), |
1366 | vid_dev->video->dir); | |
1367 | if (!device_dir) | |
1368 | return -ENOMEM; | |
1369 | ||
1da177e4 | 1370 | /* 'info' [R] */ |
e0066c4e | 1371 | entry = proc_create_data("info", S_IRUGO, device_dir, |
cf7acfab | 1372 | &acpi_video_device_info_fops, acpi_driver_data(device)); |
1da177e4 | 1373 | if (!entry) |
251cb0bc | 1374 | goto err_remove_dir; |
1da177e4 LT |
1375 | |
1376 | /* 'state' [R/W] */ | |
cf7acfab | 1377 | entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR, |
e0066c4e | 1378 | device_dir, |
cf7acfab DL |
1379 | &acpi_video_device_state_fops, |
1380 | acpi_driver_data(device)); | |
1da177e4 | 1381 | if (!entry) |
251cb0bc | 1382 | goto err_remove_info; |
1da177e4 LT |
1383 | |
1384 | /* 'brightness' [R/W] */ | |
cf7acfab | 1385 | entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR, |
e0066c4e | 1386 | device_dir, |
cf7acfab DL |
1387 | &acpi_video_device_brightness_fops, |
1388 | acpi_driver_data(device)); | |
1da177e4 | 1389 | if (!entry) |
251cb0bc | 1390 | goto err_remove_state; |
1da177e4 LT |
1391 | |
1392 | /* 'EDID' [R] */ | |
e0066c4e | 1393 | entry = proc_create_data("EDID", S_IRUGO, device_dir, |
cf7acfab DL |
1394 | &acpi_video_device_EDID_fops, |
1395 | acpi_driver_data(device)); | |
1da177e4 | 1396 | if (!entry) |
251cb0bc | 1397 | goto err_remove_brightness; |
1da177e4 | 1398 | |
e0066c4e AD |
1399 | acpi_device_dir(device) = device_dir; |
1400 | ||
d550d98d | 1401 | return 0; |
251cb0bc DT |
1402 | |
1403 | err_remove_brightness: | |
1404 | remove_proc_entry("brightness", device_dir); | |
1405 | err_remove_state: | |
1406 | remove_proc_entry("state", device_dir); | |
1407 | err_remove_info: | |
1408 | remove_proc_entry("info", device_dir); | |
1409 | err_remove_dir: | |
1410 | remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir); | |
1411 | return -ENOMEM; | |
1da177e4 LT |
1412 | } |
1413 | ||
4be44fcd | 1414 | static int acpi_video_device_remove_fs(struct acpi_device *device) |
1da177e4 LT |
1415 | { |
1416 | struct acpi_video_device *vid_dev; | |
251cb0bc | 1417 | struct proc_dir_entry *device_dir; |
1da177e4 | 1418 | |
50dd0969 | 1419 | vid_dev = acpi_driver_data(device); |
1da177e4 | 1420 | if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) |
d550d98d | 1421 | return -ENODEV; |
1da177e4 | 1422 | |
251cb0bc DT |
1423 | device_dir = acpi_device_dir(device); |
1424 | if (device_dir) { | |
1425 | remove_proc_entry("info", device_dir); | |
1426 | remove_proc_entry("state", device_dir); | |
1427 | remove_proc_entry("brightness", device_dir); | |
1428 | remove_proc_entry("EDID", device_dir); | |
4be44fcd | 1429 | remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir); |
1da177e4 LT |
1430 | acpi_device_dir(device) = NULL; |
1431 | } | |
1432 | ||
d550d98d | 1433 | return 0; |
1da177e4 LT |
1434 | } |
1435 | ||
1da177e4 | 1436 | /* video bus */ |
4be44fcd | 1437 | static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1438 | { |
50dd0969 | 1439 | struct acpi_video_bus *video = seq->private; |
1da177e4 | 1440 | |
1da177e4 LT |
1441 | |
1442 | if (!video) | |
1443 | goto end; | |
1444 | ||
1445 | seq_printf(seq, "Switching heads: %s\n", | |
4be44fcd | 1446 | video->flags.multihead ? "yes" : "no"); |
1da177e4 | 1447 | seq_printf(seq, "Video ROM: %s\n", |
4be44fcd | 1448 | video->flags.rom ? "yes" : "no"); |
1da177e4 | 1449 | seq_printf(seq, "Device to be POSTed on boot: %s\n", |
4be44fcd | 1450 | video->flags.post ? "yes" : "no"); |
1da177e4 | 1451 | |
4be44fcd | 1452 | end: |
d550d98d | 1453 | return 0; |
1da177e4 LT |
1454 | } |
1455 | ||
4be44fcd | 1456 | static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 1457 | { |
4be44fcd LB |
1458 | return single_open(file, acpi_video_bus_info_seq_show, |
1459 | PDE(inode)->data); | |
1da177e4 LT |
1460 | } |
1461 | ||
4be44fcd | 1462 | static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1463 | { |
50dd0969 | 1464 | struct acpi_video_bus *video = seq->private; |
1da177e4 | 1465 | |
1da177e4 LT |
1466 | |
1467 | if (!video) | |
1468 | goto end; | |
1469 | ||
96b2dd1f | 1470 | printk(KERN_INFO PREFIX "Please implement %s\n", __func__); |
1da177e4 LT |
1471 | seq_printf(seq, "<TODO>\n"); |
1472 | ||
4be44fcd | 1473 | end: |
d550d98d | 1474 | return 0; |
1da177e4 LT |
1475 | } |
1476 | ||
4be44fcd | 1477 | static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1478 | { |
1479 | return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data); | |
1480 | } | |
1481 | ||
4be44fcd | 1482 | static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1483 | { |
50dd0969 | 1484 | struct acpi_video_bus *video = seq->private; |
27663c58 | 1485 | unsigned long long options; |
4be44fcd | 1486 | int status; |
1da177e4 | 1487 | |
1da177e4 LT |
1488 | |
1489 | if (!video) | |
1490 | goto end; | |
1491 | ||
1492 | status = acpi_video_bus_POST_options(video, &options); | |
1493 | if (ACPI_SUCCESS(status)) { | |
1494 | if (!(options & 1)) { | |
4be44fcd LB |
1495 | printk(KERN_WARNING PREFIX |
1496 | "The motherboard VGA device is not listed as a possible POST device.\n"); | |
1497 | printk(KERN_WARNING PREFIX | |
98fb8fe1 | 1498 | "This indicates a BIOS bug. Please contact the manufacturer.\n"); |
1da177e4 | 1499 | } |
4d939155 | 1500 | printk(KERN_WARNING "%llx\n", options); |
98fb8fe1 | 1501 | seq_printf(seq, "can POST: <integrated video>"); |
1da177e4 LT |
1502 | if (options & 2) |
1503 | seq_printf(seq, " <PCI video>"); | |
1504 | if (options & 4) | |
1505 | seq_printf(seq, " <AGP video>"); | |
1506 | seq_putc(seq, '\n'); | |
1507 | } else | |
1508 | seq_printf(seq, "<not supported>\n"); | |
4be44fcd | 1509 | end: |
d550d98d | 1510 | return 0; |
1da177e4 LT |
1511 | } |
1512 | ||
1513 | static int | |
4be44fcd | 1514 | acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 1515 | { |
4be44fcd LB |
1516 | return single_open(file, acpi_video_bus_POST_info_seq_show, |
1517 | PDE(inode)->data); | |
1da177e4 LT |
1518 | } |
1519 | ||
4be44fcd | 1520 | static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1521 | { |
50dd0969 | 1522 | struct acpi_video_bus *video = seq->private; |
4be44fcd | 1523 | int status; |
27663c58 | 1524 | unsigned long long id; |
1da177e4 | 1525 | |
1da177e4 LT |
1526 | |
1527 | if (!video) | |
1528 | goto end; | |
1529 | ||
4be44fcd | 1530 | status = acpi_video_bus_get_POST(video, &id); |
1da177e4 LT |
1531 | if (!ACPI_SUCCESS(status)) { |
1532 | seq_printf(seq, "<not supported>\n"); | |
1533 | goto end; | |
1534 | } | |
98fb8fe1 | 1535 | seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]); |
1da177e4 | 1536 | |
4be44fcd | 1537 | end: |
d550d98d | 1538 | return 0; |
1da177e4 LT |
1539 | } |
1540 | ||
4be44fcd | 1541 | static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset) |
1da177e4 | 1542 | { |
50dd0969 | 1543 | struct acpi_video_bus *video = seq->private; |
1da177e4 | 1544 | |
1da177e4 | 1545 | |
4be44fcd | 1546 | seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting); |
1da177e4 | 1547 | |
d550d98d | 1548 | return 0; |
1da177e4 LT |
1549 | } |
1550 | ||
4be44fcd | 1551 | static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file) |
1da177e4 | 1552 | { |
4be44fcd LB |
1553 | return single_open(file, acpi_video_bus_POST_seq_show, |
1554 | PDE(inode)->data); | |
1da177e4 LT |
1555 | } |
1556 | ||
4be44fcd | 1557 | static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file) |
1da177e4 LT |
1558 | { |
1559 | return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data); | |
1560 | } | |
1561 | ||
1562 | static ssize_t | |
4be44fcd LB |
1563 | acpi_video_bus_write_POST(struct file *file, |
1564 | const char __user * buffer, | |
1565 | size_t count, loff_t * data) | |
1da177e4 | 1566 | { |
4be44fcd | 1567 | int status; |
50dd0969 JE |
1568 | struct seq_file *m = file->private_data; |
1569 | struct acpi_video_bus *video = m->private; | |
4be44fcd | 1570 | char str[12] = { 0 }; |
27663c58 | 1571 | unsigned long long opt, options; |
1da177e4 | 1572 | |
1da177e4 | 1573 | |
52a2b11c | 1574 | if (!video || count >= sizeof(str)) |
d550d98d | 1575 | return -EINVAL; |
1da177e4 LT |
1576 | |
1577 | status = acpi_video_bus_POST_options(video, &options); | |
1578 | if (!ACPI_SUCCESS(status)) | |
d550d98d | 1579 | return -EINVAL; |
1da177e4 LT |
1580 | |
1581 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 1582 | return -EFAULT; |
1da177e4 LT |
1583 | |
1584 | str[count] = 0; | |
1585 | opt = strtoul(str, NULL, 0); | |
1586 | if (opt > 3) | |
d550d98d | 1587 | return -EFAULT; |
1da177e4 | 1588 | |
98fb8fe1 | 1589 | /* just in case an OEM 'forgot' the motherboard... */ |
1da177e4 LT |
1590 | options |= 1; |
1591 | ||
1592 | if (options & (1ul << opt)) { | |
4be44fcd | 1593 | status = acpi_video_bus_set_POST(video, opt); |
1da177e4 | 1594 | if (!ACPI_SUCCESS(status)) |
d550d98d | 1595 | return -EFAULT; |
1da177e4 LT |
1596 | |
1597 | } | |
1598 | ||
d550d98d | 1599 | return count; |
1da177e4 LT |
1600 | } |
1601 | ||
1602 | static ssize_t | |
4be44fcd LB |
1603 | acpi_video_bus_write_DOS(struct file *file, |
1604 | const char __user * buffer, | |
1605 | size_t count, loff_t * data) | |
1da177e4 | 1606 | { |
4be44fcd | 1607 | int status; |
50dd0969 JE |
1608 | struct seq_file *m = file->private_data; |
1609 | struct acpi_video_bus *video = m->private; | |
4be44fcd LB |
1610 | char str[12] = { 0 }; |
1611 | unsigned long opt; | |
1da177e4 | 1612 | |
1da177e4 | 1613 | |
52a2b11c | 1614 | if (!video || count >= sizeof(str)) |
d550d98d | 1615 | return -EINVAL; |
1da177e4 LT |
1616 | |
1617 | if (copy_from_user(str, buffer, count)) | |
d550d98d | 1618 | return -EFAULT; |
1da177e4 LT |
1619 | |
1620 | str[count] = 0; | |
1621 | opt = strtoul(str, NULL, 0); | |
1622 | if (opt > 7) | |
d550d98d | 1623 | return -EFAULT; |
1da177e4 | 1624 | |
4be44fcd | 1625 | status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2); |
1da177e4 LT |
1626 | |
1627 | if (!ACPI_SUCCESS(status)) | |
d550d98d | 1628 | return -EFAULT; |
1da177e4 | 1629 | |
d550d98d | 1630 | return count; |
1da177e4 LT |
1631 | } |
1632 | ||
4be44fcd | 1633 | static int acpi_video_bus_add_fs(struct acpi_device *device) |
1da177e4 | 1634 | { |
251cb0bc DT |
1635 | struct acpi_video_bus *video = acpi_driver_data(device); |
1636 | struct proc_dir_entry *device_dir; | |
1637 | struct proc_dir_entry *entry; | |
1da177e4 | 1638 | |
251cb0bc DT |
1639 | device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir); |
1640 | if (!device_dir) | |
1641 | return -ENOMEM; | |
1da177e4 | 1642 | |
1da177e4 | 1643 | /* 'info' [R] */ |
e0066c4e | 1644 | entry = proc_create_data("info", S_IRUGO, device_dir, |
cf7acfab DL |
1645 | &acpi_video_bus_info_fops, |
1646 | acpi_driver_data(device)); | |
1da177e4 | 1647 | if (!entry) |
251cb0bc | 1648 | goto err_remove_dir; |
1da177e4 LT |
1649 | |
1650 | /* 'ROM' [R] */ | |
e0066c4e | 1651 | entry = proc_create_data("ROM", S_IRUGO, device_dir, |
cf7acfab DL |
1652 | &acpi_video_bus_ROM_fops, |
1653 | acpi_driver_data(device)); | |
1da177e4 | 1654 | if (!entry) |
251cb0bc | 1655 | goto err_remove_info; |
1da177e4 LT |
1656 | |
1657 | /* 'POST_info' [R] */ | |
e0066c4e | 1658 | entry = proc_create_data("POST_info", S_IRUGO, device_dir, |
cf7acfab DL |
1659 | &acpi_video_bus_POST_info_fops, |
1660 | acpi_driver_data(device)); | |
1da177e4 | 1661 | if (!entry) |
251cb0bc | 1662 | goto err_remove_rom; |
1da177e4 LT |
1663 | |
1664 | /* 'POST' [R/W] */ | |
08acd4f8 | 1665 | entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR, |
e0066c4e | 1666 | device_dir, |
cf7acfab DL |
1667 | &acpi_video_bus_POST_fops, |
1668 | acpi_driver_data(device)); | |
1da177e4 | 1669 | if (!entry) |
251cb0bc | 1670 | goto err_remove_post_info; |
1da177e4 LT |
1671 | |
1672 | /* 'DOS' [R/W] */ | |
08acd4f8 | 1673 | entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR, |
e0066c4e | 1674 | device_dir, |
cf7acfab DL |
1675 | &acpi_video_bus_DOS_fops, |
1676 | acpi_driver_data(device)); | |
1da177e4 | 1677 | if (!entry) |
251cb0bc | 1678 | goto err_remove_post; |
1da177e4 | 1679 | |
251cb0bc | 1680 | video->dir = acpi_device_dir(device) = device_dir; |
d550d98d | 1681 | return 0; |
251cb0bc DT |
1682 | |
1683 | err_remove_post: | |
1684 | remove_proc_entry("POST", device_dir); | |
1685 | err_remove_post_info: | |
1686 | remove_proc_entry("POST_info", device_dir); | |
1687 | err_remove_rom: | |
1688 | remove_proc_entry("ROM", device_dir); | |
1689 | err_remove_info: | |
1690 | remove_proc_entry("info", device_dir); | |
1691 | err_remove_dir: | |
1692 | remove_proc_entry(acpi_device_bid(device), acpi_video_dir); | |
1693 | return -ENOMEM; | |
1da177e4 LT |
1694 | } |
1695 | ||
4be44fcd | 1696 | static int acpi_video_bus_remove_fs(struct acpi_device *device) |
1da177e4 | 1697 | { |
251cb0bc DT |
1698 | struct proc_dir_entry *device_dir = acpi_device_dir(device); |
1699 | ||
1700 | if (device_dir) { | |
1701 | remove_proc_entry("info", device_dir); | |
1702 | remove_proc_entry("ROM", device_dir); | |
1703 | remove_proc_entry("POST_info", device_dir); | |
1704 | remove_proc_entry("POST", device_dir); | |
1705 | remove_proc_entry("DOS", device_dir); | |
4be44fcd | 1706 | remove_proc_entry(acpi_device_bid(device), acpi_video_dir); |
1da177e4 LT |
1707 | acpi_device_dir(device) = NULL; |
1708 | } | |
1709 | ||
d550d98d | 1710 | return 0; |
1da177e4 LT |
1711 | } |
1712 | ||
1713 | /* -------------------------------------------------------------------------- | |
1714 | Driver Interface | |
1715 | -------------------------------------------------------------------------- */ | |
1716 | ||
1717 | /* device interface */ | |
82cae999 RZ |
1718 | static struct acpi_video_device_attrib* |
1719 | acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id) | |
1720 | { | |
78eed028 DT |
1721 | struct acpi_video_enumerated_device *ids; |
1722 | int i; | |
1723 | ||
1724 | for (i = 0; i < video->attached_count; i++) { | |
1725 | ids = &video->attached_array[i]; | |
1726 | if ((ids->value.int_val & 0xffff) == device_id) | |
1727 | return &ids->value.attrib; | |
1728 | } | |
82cae999 | 1729 | |
82cae999 RZ |
1730 | return NULL; |
1731 | } | |
1da177e4 LT |
1732 | |
1733 | static int | |
4be44fcd LB |
1734 | acpi_video_bus_get_one_device(struct acpi_device *device, |
1735 | struct acpi_video_bus *video) | |
1da177e4 | 1736 | { |
27663c58 | 1737 | unsigned long long device_id; |
973bf491 | 1738 | int status; |
4be44fcd | 1739 | struct acpi_video_device *data; |
82cae999 | 1740 | struct acpi_video_device_attrib* attribute; |
1da177e4 LT |
1741 | |
1742 | if (!device || !video) | |
d550d98d | 1743 | return -EINVAL; |
1da177e4 | 1744 | |
4be44fcd LB |
1745 | status = |
1746 | acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); | |
1da177e4 LT |
1747 | if (ACPI_SUCCESS(status)) { |
1748 | ||
36bcbec7 | 1749 | data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL); |
1da177e4 | 1750 | if (!data) |
d550d98d | 1751 | return -ENOMEM; |
1da177e4 | 1752 | |
1da177e4 LT |
1753 | strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); |
1754 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); | |
db89b4f0 | 1755 | device->driver_data = data; |
1da177e4 LT |
1756 | |
1757 | data->device_id = device_id; | |
1758 | data->video = video; | |
1759 | data->dev = device; | |
1760 | ||
82cae999 RZ |
1761 | attribute = acpi_video_get_device_attr(video, device_id); |
1762 | ||
1763 | if((attribute != NULL) && attribute->device_id_scheme) { | |
1764 | switch (attribute->display_type) { | |
1765 | case ACPI_VIDEO_DISPLAY_CRT: | |
1766 | data->flags.crt = 1; | |
1767 | break; | |
1768 | case ACPI_VIDEO_DISPLAY_TV: | |
1769 | data->flags.tvout = 1; | |
1770 | break; | |
1771 | case ACPI_VIDEO_DISPLAY_DVI: | |
1772 | data->flags.dvi = 1; | |
1773 | break; | |
1774 | case ACPI_VIDEO_DISPLAY_LCD: | |
1775 | data->flags.lcd = 1; | |
1776 | break; | |
1777 | default: | |
1778 | data->flags.unknown = 1; | |
1779 | break; | |
1780 | } | |
1781 | if(attribute->bios_can_detect) | |
1782 | data->flags.bios = 1; | |
1783 | } else | |
1da177e4 | 1784 | data->flags.unknown = 1; |
4be44fcd | 1785 | |
1da177e4 LT |
1786 | acpi_video_device_bind(video, data); |
1787 | acpi_video_device_find_cap(data); | |
1788 | ||
90130268 | 1789 | status = acpi_install_notify_handler(device->handle, |
4be44fcd LB |
1790 | ACPI_DEVICE_NOTIFY, |
1791 | acpi_video_device_notify, | |
1792 | data); | |
1da177e4 | 1793 | if (ACPI_FAILURE(status)) { |
55ac9a01 LM |
1794 | printk(KERN_ERR PREFIX |
1795 | "Error installing notify handler\n"); | |
973bf491 YL |
1796 | if(data->brightness) |
1797 | kfree(data->brightness->levels); | |
1798 | kfree(data->brightness); | |
1799 | kfree(data); | |
1800 | return -ENODEV; | |
1da177e4 LT |
1801 | } |
1802 | ||
bbac81f5 | 1803 | mutex_lock(&video->device_list_lock); |
1da177e4 | 1804 | list_add_tail(&data->entry, &video->video_device_list); |
bbac81f5 | 1805 | mutex_unlock(&video->device_list_lock); |
1da177e4 LT |
1806 | |
1807 | acpi_video_device_add_fs(device); | |
1808 | ||
d550d98d | 1809 | return 0; |
1da177e4 LT |
1810 | } |
1811 | ||
d550d98d | 1812 | return -ENOENT; |
1da177e4 LT |
1813 | } |
1814 | ||
1815 | /* | |
1816 | * Arg: | |
1817 | * video : video bus device | |
1818 | * | |
1819 | * Return: | |
1820 | * none | |
1821 | * | |
1822 | * Enumerate the video device list of the video bus, | |
1823 | * bind the ids with the corresponding video devices | |
1824 | * under the video bus. | |
4be44fcd | 1825 | */ |
1da177e4 | 1826 | |
4be44fcd | 1827 | static void acpi_video_device_rebind(struct acpi_video_bus *video) |
1da177e4 | 1828 | { |
ff102ea9 DT |
1829 | struct acpi_video_device *dev; |
1830 | ||
bbac81f5 | 1831 | mutex_lock(&video->device_list_lock); |
ff102ea9 DT |
1832 | |
1833 | list_for_each_entry(dev, &video->video_device_list, entry) | |
4be44fcd | 1834 | acpi_video_device_bind(video, dev); |
ff102ea9 | 1835 | |
bbac81f5 | 1836 | mutex_unlock(&video->device_list_lock); |
1da177e4 LT |
1837 | } |
1838 | ||
1839 | /* | |
1840 | * Arg: | |
1841 | * video : video bus device | |
1842 | * device : video output device under the video | |
1843 | * bus | |
1844 | * | |
1845 | * Return: | |
1846 | * none | |
1847 | * | |
1848 | * Bind the ids with the corresponding video devices | |
1849 | * under the video bus. | |
4be44fcd | 1850 | */ |
1da177e4 LT |
1851 | |
1852 | static void | |
4be44fcd LB |
1853 | acpi_video_device_bind(struct acpi_video_bus *video, |
1854 | struct acpi_video_device *device) | |
1da177e4 | 1855 | { |
78eed028 | 1856 | struct acpi_video_enumerated_device *ids; |
4be44fcd | 1857 | int i; |
1da177e4 | 1858 | |
78eed028 DT |
1859 | for (i = 0; i < video->attached_count; i++) { |
1860 | ids = &video->attached_array[i]; | |
1861 | if (device->device_id == (ids->value.int_val & 0xffff)) { | |
1862 | ids->bind_info = device; | |
1da177e4 LT |
1863 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i)); |
1864 | } | |
1865 | } | |
1da177e4 LT |
1866 | } |
1867 | ||
1868 | /* | |
1869 | * Arg: | |
1870 | * video : video bus device | |
1871 | * | |
1872 | * Return: | |
1873 | * < 0 : error | |
1874 | * | |
1875 | * Call _DOD to enumerate all devices attached to display adapter | |
1876 | * | |
4be44fcd | 1877 | */ |
1da177e4 LT |
1878 | |
1879 | static int acpi_video_device_enumerate(struct acpi_video_bus *video) | |
1880 | { | |
4be44fcd LB |
1881 | int status; |
1882 | int count; | |
1883 | int i; | |
78eed028 | 1884 | struct acpi_video_enumerated_device *active_list; |
4be44fcd LB |
1885 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
1886 | union acpi_object *dod = NULL; | |
1887 | union acpi_object *obj; | |
1da177e4 | 1888 | |
90130268 | 1889 | status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); |
1da177e4 | 1890 | if (!ACPI_SUCCESS(status)) { |
a6fc6720 | 1891 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD")); |
d550d98d | 1892 | return status; |
1da177e4 LT |
1893 | } |
1894 | ||
50dd0969 | 1895 | dod = buffer.pointer; |
1da177e4 | 1896 | if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { |
a6fc6720 | 1897 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data")); |
1da177e4 LT |
1898 | status = -EFAULT; |
1899 | goto out; | |
1900 | } | |
1901 | ||
1902 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n", | |
4be44fcd | 1903 | dod->package.count)); |
1da177e4 | 1904 | |
78eed028 DT |
1905 | active_list = kcalloc(1 + dod->package.count, |
1906 | sizeof(struct acpi_video_enumerated_device), | |
1907 | GFP_KERNEL); | |
1908 | if (!active_list) { | |
1da177e4 LT |
1909 | status = -ENOMEM; |
1910 | goto out; | |
1911 | } | |
1912 | ||
1913 | count = 0; | |
1914 | for (i = 0; i < dod->package.count; i++) { | |
50dd0969 | 1915 | obj = &dod->package.elements[i]; |
1da177e4 LT |
1916 | |
1917 | if (obj->type != ACPI_TYPE_INTEGER) { | |
78eed028 DT |
1918 | printk(KERN_ERR PREFIX |
1919 | "Invalid _DOD data in element %d\n", i); | |
1920 | continue; | |
1da177e4 | 1921 | } |
78eed028 DT |
1922 | |
1923 | active_list[count].value.int_val = obj->integer.value; | |
1924 | active_list[count].bind_info = NULL; | |
4be44fcd LB |
1925 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i, |
1926 | (int)obj->integer.value)); | |
1da177e4 LT |
1927 | count++; |
1928 | } | |
1da177e4 | 1929 | |
6044ec88 | 1930 | kfree(video->attached_array); |
4be44fcd | 1931 | |
78eed028 | 1932 | video->attached_array = active_list; |
1da177e4 | 1933 | video->attached_count = count; |
78eed028 DT |
1934 | |
1935 | out: | |
02438d87 | 1936 | kfree(buffer.pointer); |
d550d98d | 1937 | return status; |
1da177e4 LT |
1938 | } |
1939 | ||
4be44fcd LB |
1940 | static int |
1941 | acpi_video_get_next_level(struct acpi_video_device *device, | |
1942 | u32 level_current, u32 event) | |
1da177e4 | 1943 | { |
63f0edfc | 1944 | int min, max, min_above, max_below, i, l, delta = 255; |
f4715189 TT |
1945 | max = max_below = 0; |
1946 | min = min_above = 255; | |
63f0edfc | 1947 | /* Find closest level to level_current */ |
0a3db1ce | 1948 | for (i = 2; i < device->brightness->count; i++) { |
63f0edfc AS |
1949 | l = device->brightness->levels[i]; |
1950 | if (abs(l - level_current) < abs(delta)) { | |
1951 | delta = l - level_current; | |
1952 | if (!delta) | |
1953 | break; | |
1954 | } | |
1955 | } | |
1956 | /* Ajust level_current to closest available level */ | |
1957 | level_current += delta; | |
0a3db1ce | 1958 | for (i = 2; i < device->brightness->count; i++) { |
f4715189 TT |
1959 | l = device->brightness->levels[i]; |
1960 | if (l < min) | |
1961 | min = l; | |
1962 | if (l > max) | |
1963 | max = l; | |
1964 | if (l < min_above && l > level_current) | |
1965 | min_above = l; | |
1966 | if (l > max_below && l < level_current) | |
1967 | max_below = l; | |
1968 | } | |
1969 | ||
1970 | switch (event) { | |
1971 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: | |
1972 | return (level_current < max) ? min_above : min; | |
1973 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: | |
1974 | return (level_current < max) ? min_above : max; | |
1975 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: | |
1976 | return (level_current > min) ? max_below : min; | |
1977 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: | |
1978 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: | |
1979 | return 0; | |
1980 | default: | |
1981 | return level_current; | |
1982 | } | |
1da177e4 LT |
1983 | } |
1984 | ||
c8890f90 | 1985 | static int |
4be44fcd | 1986 | acpi_video_switch_brightness(struct acpi_video_device *device, int event) |
1da177e4 | 1987 | { |
27663c58 | 1988 | unsigned long long level_current, level_next; |
c8890f90 ZR |
1989 | int result = -EINVAL; |
1990 | ||
28c32e99 ZR |
1991 | /* no warning message if acpi_backlight=vendor is used */ |
1992 | if (!acpi_video_backlight_support()) | |
1993 | return 0; | |
1994 | ||
469778c1 | 1995 | if (!device->brightness) |
c8890f90 ZR |
1996 | goto out; |
1997 | ||
1998 | result = acpi_video_device_lcd_get_level_current(device, | |
1999 | &level_current); | |
2000 | if (result) | |
2001 | goto out; | |
2002 | ||
1da177e4 | 2003 | level_next = acpi_video_get_next_level(device, level_current, event); |
c8890f90 | 2004 | |
24450c7a | 2005 | result = acpi_video_device_lcd_set_level(device, level_next); |
c8890f90 | 2006 | |
36342742 MG |
2007 | if (!result) |
2008 | backlight_force_update(device->backlight, | |
2009 | BACKLIGHT_UPDATE_HOTKEY); | |
2010 | ||
c8890f90 ZR |
2011 | out: |
2012 | if (result) | |
2013 | printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); | |
2014 | ||
2015 | return result; | |
1da177e4 LT |
2016 | } |
2017 | ||
2018 | static int | |
4be44fcd LB |
2019 | acpi_video_bus_get_devices(struct acpi_video_bus *video, |
2020 | struct acpi_device *device) | |
1da177e4 | 2021 | { |
4be44fcd | 2022 | int status = 0; |
ff102ea9 | 2023 | struct acpi_device *dev; |
1da177e4 LT |
2024 | |
2025 | acpi_video_device_enumerate(video); | |
2026 | ||
ff102ea9 | 2027 | list_for_each_entry(dev, &device->children, node) { |
1da177e4 LT |
2028 | |
2029 | status = acpi_video_bus_get_one_device(dev, video); | |
2030 | if (ACPI_FAILURE(status)) { | |
55ac9a01 LM |
2031 | printk(KERN_WARNING PREFIX |
2032 | "Cant attach device"); | |
1da177e4 LT |
2033 | continue; |
2034 | } | |
1da177e4 | 2035 | } |
d550d98d | 2036 | return status; |
1da177e4 LT |
2037 | } |
2038 | ||
4be44fcd | 2039 | static int acpi_video_bus_put_one_device(struct acpi_video_device *device) |
1da177e4 | 2040 | { |
031ec77b | 2041 | acpi_status status; |
1da177e4 LT |
2042 | struct acpi_video_bus *video; |
2043 | ||
1da177e4 LT |
2044 | |
2045 | if (!device || !device->video) | |
d550d98d | 2046 | return -ENOENT; |
1da177e4 LT |
2047 | |
2048 | video = device->video; | |
2049 | ||
1da177e4 LT |
2050 | acpi_video_device_remove_fs(device->dev); |
2051 | ||
90130268 | 2052 | status = acpi_remove_notify_handler(device->dev->handle, |
4be44fcd LB |
2053 | ACPI_DEVICE_NOTIFY, |
2054 | acpi_video_device_notify); | |
e29b3ee3 KP |
2055 | if (device->backlight) { |
2056 | sysfs_remove_link(&device->backlight->dev.kobj, "device"); | |
2057 | backlight_device_unregister(device->backlight); | |
2058 | device->backlight = NULL; | |
2059 | } | |
4a703a8f | 2060 | if (device->cooling_dev) { |
702ed512 ZR |
2061 | sysfs_remove_link(&device->dev->dev.kobj, |
2062 | "thermal_cooling"); | |
4a703a8f | 2063 | sysfs_remove_link(&device->cooling_dev->device.kobj, |
702ed512 | 2064 | "device"); |
4a703a8f DT |
2065 | thermal_cooling_device_unregister(device->cooling_dev); |
2066 | device->cooling_dev = NULL; | |
702ed512 | 2067 | } |
23b0f015 | 2068 | video_output_unregister(device->output_dev); |
ff102ea9 | 2069 | |
d550d98d | 2070 | return 0; |
1da177e4 LT |
2071 | } |
2072 | ||
4be44fcd | 2073 | static int acpi_video_bus_put_devices(struct acpi_video_bus *video) |
1da177e4 | 2074 | { |
4be44fcd | 2075 | int status; |
ff102ea9 | 2076 | struct acpi_video_device *dev, *next; |
1da177e4 | 2077 | |
bbac81f5 | 2078 | mutex_lock(&video->device_list_lock); |
1da177e4 | 2079 | |
ff102ea9 | 2080 | list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { |
1da177e4 | 2081 | |
ff102ea9 | 2082 | status = acpi_video_bus_put_one_device(dev); |
4be44fcd LB |
2083 | if (ACPI_FAILURE(status)) |
2084 | printk(KERN_WARNING PREFIX | |
2085 | "hhuuhhuu bug in acpi video driver.\n"); | |
1da177e4 | 2086 | |
ff102ea9 DT |
2087 | if (dev->brightness) { |
2088 | kfree(dev->brightness->levels); | |
2089 | kfree(dev->brightness); | |
2090 | } | |
2091 | list_del(&dev->entry); | |
2092 | kfree(dev); | |
1da177e4 LT |
2093 | } |
2094 | ||
bbac81f5 | 2095 | mutex_unlock(&video->device_list_lock); |
ff102ea9 | 2096 | |
d550d98d | 2097 | return 0; |
1da177e4 LT |
2098 | } |
2099 | ||
2100 | /* acpi_video interface */ | |
2101 | ||
4be44fcd | 2102 | static int acpi_video_bus_start_devices(struct acpi_video_bus *video) |
1da177e4 | 2103 | { |
a21101c4 | 2104 | return acpi_video_bus_DOS(video, 0, 0); |
1da177e4 LT |
2105 | } |
2106 | ||
4be44fcd | 2107 | static int acpi_video_bus_stop_devices(struct acpi_video_bus *video) |
1da177e4 LT |
2108 | { |
2109 | return acpi_video_bus_DOS(video, 0, 1); | |
2110 | } | |
2111 | ||
7015558f | 2112 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event) |
1da177e4 | 2113 | { |
7015558f | 2114 | struct acpi_video_bus *video = acpi_driver_data(device); |
e9dab196 LY |
2115 | struct input_dev *input; |
2116 | int keycode; | |
2117 | ||
1da177e4 | 2118 | if (!video) |
d550d98d | 2119 | return; |
1da177e4 | 2120 | |
e9dab196 | 2121 | input = video->input; |
1da177e4 LT |
2122 | |
2123 | switch (event) { | |
98fb8fe1 | 2124 | case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch, |
1da177e4 | 2125 | * most likely via hotkey. */ |
14e04fb3 | 2126 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 | 2127 | keycode = KEY_SWITCHVIDEOMODE; |
1da177e4 LT |
2128 | break; |
2129 | ||
98fb8fe1 | 2130 | case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video |
1da177e4 LT |
2131 | * connector. */ |
2132 | acpi_video_device_enumerate(video); | |
2133 | acpi_video_device_rebind(video); | |
14e04fb3 | 2134 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 | 2135 | keycode = KEY_SWITCHVIDEOMODE; |
1da177e4 LT |
2136 | break; |
2137 | ||
4be44fcd | 2138 | case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */ |
25c87f7f | 2139 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 LY |
2140 | keycode = KEY_SWITCHVIDEOMODE; |
2141 | break; | |
4be44fcd | 2142 | case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */ |
25c87f7f | 2143 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 LY |
2144 | keycode = KEY_VIDEO_NEXT; |
2145 | break; | |
4be44fcd | 2146 | case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */ |
14e04fb3 | 2147 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 | 2148 | keycode = KEY_VIDEO_PREV; |
1da177e4 LT |
2149 | break; |
2150 | ||
2151 | default: | |
e9dab196 | 2152 | keycode = KEY_UNKNOWN; |
1da177e4 | 2153 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4be44fcd | 2154 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
2155 | break; |
2156 | } | |
2157 | ||
7761f638 | 2158 | acpi_notifier_call_chain(device, event, 0); |
e9dab196 LY |
2159 | input_report_key(input, keycode, 1); |
2160 | input_sync(input); | |
2161 | input_report_key(input, keycode, 0); | |
2162 | input_sync(input); | |
2163 | ||
d550d98d | 2164 | return; |
1da177e4 LT |
2165 | } |
2166 | ||
4be44fcd | 2167 | static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) |
1da177e4 | 2168 | { |
50dd0969 | 2169 | struct acpi_video_device *video_device = data; |
4be44fcd | 2170 | struct acpi_device *device = NULL; |
e9dab196 LY |
2171 | struct acpi_video_bus *bus; |
2172 | struct input_dev *input; | |
2173 | int keycode; | |
1da177e4 | 2174 | |
1da177e4 | 2175 | if (!video_device) |
d550d98d | 2176 | return; |
1da177e4 | 2177 | |
e6afa0de | 2178 | device = video_device->dev; |
e9dab196 LY |
2179 | bus = video_device->video; |
2180 | input = bus->input; | |
1da177e4 LT |
2181 | |
2182 | switch (event) { | |
4be44fcd | 2183 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ |
8a681a4d ZR |
2184 | if (brightness_switch_enabled) |
2185 | acpi_video_switch_brightness(video_device, event); | |
14e04fb3 | 2186 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 LY |
2187 | keycode = KEY_BRIGHTNESS_CYCLE; |
2188 | break; | |
4be44fcd | 2189 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ |
8a681a4d ZR |
2190 | if (brightness_switch_enabled) |
2191 | acpi_video_switch_brightness(video_device, event); | |
25c87f7f | 2192 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 LY |
2193 | keycode = KEY_BRIGHTNESSUP; |
2194 | break; | |
4be44fcd | 2195 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ |
8a681a4d ZR |
2196 | if (brightness_switch_enabled) |
2197 | acpi_video_switch_brightness(video_device, event); | |
25c87f7f | 2198 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 LY |
2199 | keycode = KEY_BRIGHTNESSDOWN; |
2200 | break; | |
4be44fcd | 2201 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */ |
8a681a4d ZR |
2202 | if (brightness_switch_enabled) |
2203 | acpi_video_switch_brightness(video_device, event); | |
25c87f7f | 2204 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 LY |
2205 | keycode = KEY_BRIGHTNESS_ZERO; |
2206 | break; | |
4be44fcd | 2207 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */ |
8a681a4d ZR |
2208 | if (brightness_switch_enabled) |
2209 | acpi_video_switch_brightness(video_device, event); | |
14e04fb3 | 2210 | acpi_bus_generate_proc_event(device, event, 0); |
e9dab196 | 2211 | keycode = KEY_DISPLAY_OFF; |
1da177e4 LT |
2212 | break; |
2213 | default: | |
e9dab196 | 2214 | keycode = KEY_UNKNOWN; |
1da177e4 | 2215 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
4be44fcd | 2216 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
2217 | break; |
2218 | } | |
e9dab196 | 2219 | |
7761f638 | 2220 | acpi_notifier_call_chain(device, event, 0); |
e9dab196 LY |
2221 | input_report_key(input, keycode, 1); |
2222 | input_sync(input); | |
2223 | input_report_key(input, keycode, 0); | |
2224 | input_sync(input); | |
2225 | ||
d550d98d | 2226 | return; |
1da177e4 LT |
2227 | } |
2228 | ||
e6d9da1d | 2229 | static int instance; |
863c1490 MG |
2230 | static int acpi_video_resume(struct acpi_device *device) |
2231 | { | |
2232 | struct acpi_video_bus *video; | |
2233 | struct acpi_video_device *video_device; | |
2234 | int i; | |
2235 | ||
2236 | if (!device || !acpi_driver_data(device)) | |
2237 | return -EINVAL; | |
2238 | ||
2239 | video = acpi_driver_data(device); | |
2240 | ||
2241 | for (i = 0; i < video->attached_count; i++) { | |
2242 | video_device = video->attached_array[i].bind_info; | |
2243 | if (video_device && video_device->backlight) | |
2244 | acpi_video_set_brightness(video_device->backlight); | |
2245 | } | |
2246 | return AE_OK; | |
2247 | } | |
2248 | ||
c504f8cb ZR |
2249 | static acpi_status |
2250 | acpi_video_bus_match(acpi_handle handle, u32 level, void *context, | |
2251 | void **return_value) | |
2252 | { | |
2253 | struct acpi_device *device = context; | |
2254 | struct acpi_device *sibling; | |
2255 | int result; | |
2256 | ||
2257 | if (handle == device->handle) | |
2258 | return AE_CTRL_TERMINATE; | |
2259 | ||
2260 | result = acpi_bus_get_device(handle, &sibling); | |
2261 | if (result) | |
2262 | return AE_OK; | |
2263 | ||
2264 | if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME)) | |
2265 | return AE_ALREADY_EXISTS; | |
2266 | ||
2267 | return AE_OK; | |
2268 | } | |
2269 | ||
4be44fcd | 2270 | static int acpi_video_bus_add(struct acpi_device *device) |
1da177e4 | 2271 | { |
f51e8391 | 2272 | struct acpi_video_bus *video; |
e9dab196 | 2273 | struct input_dev *input; |
f51e8391 | 2274 | int error; |
c504f8cb ZR |
2275 | acpi_status status; |
2276 | ||
2277 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, | |
2278 | device->parent->handle, 1, | |
2279 | acpi_video_bus_match, NULL, | |
2280 | device, NULL); | |
2281 | if (status == AE_ALREADY_EXISTS) { | |
2282 | printk(KERN_WARNING FW_BUG | |
2283 | "Duplicate ACPI video bus devices for the" | |
2284 | " same VGA controller, please try module " | |
2285 | "parameter \"video.allow_duplicates=1\"" | |
2286 | "if the current driver doesn't work.\n"); | |
2287 | if (!allow_duplicates) | |
2288 | return -ENODEV; | |
2289 | } | |
1da177e4 | 2290 | |
36bcbec7 | 2291 | video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); |
1da177e4 | 2292 | if (!video) |
d550d98d | 2293 | return -ENOMEM; |
1da177e4 | 2294 | |
e6d9da1d ZR |
2295 | /* a hack to fix the duplicate name "VID" problem on T61 */ |
2296 | if (!strcmp(device->pnp.bus_id, "VID")) { | |
2297 | if (instance) | |
2298 | device->pnp.bus_id[3] = '0' + instance; | |
2299 | instance ++; | |
2300 | } | |
f3b39f13 ZY |
2301 | /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */ |
2302 | if (!strcmp(device->pnp.bus_id, "VGA")) { | |
2303 | if (instance) | |
2304 | device->pnp.bus_id[3] = '0' + instance; | |
2305 | instance++; | |
2306 | } | |
e6d9da1d | 2307 | |
e6afa0de | 2308 | video->device = device; |
1da177e4 LT |
2309 | strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); |
2310 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); | |
db89b4f0 | 2311 | device->driver_data = video; |
1da177e4 LT |
2312 | |
2313 | acpi_video_bus_find_cap(video); | |
f51e8391 DT |
2314 | error = acpi_video_bus_check(video); |
2315 | if (error) | |
2316 | goto err_free_video; | |
1da177e4 | 2317 | |
f51e8391 DT |
2318 | error = acpi_video_bus_add_fs(device); |
2319 | if (error) | |
2320 | goto err_free_video; | |
1da177e4 | 2321 | |
bbac81f5 | 2322 | mutex_init(&video->device_list_lock); |
1da177e4 LT |
2323 | INIT_LIST_HEAD(&video->video_device_list); |
2324 | ||
2325 | acpi_video_bus_get_devices(video, device); | |
2326 | acpi_video_bus_start_devices(video); | |
2327 | ||
e9dab196 | 2328 | video->input = input = input_allocate_device(); |
f51e8391 DT |
2329 | if (!input) { |
2330 | error = -ENOMEM; | |
7015558f | 2331 | goto err_stop_video; |
f51e8391 | 2332 | } |
e9dab196 LY |
2333 | |
2334 | snprintf(video->phys, sizeof(video->phys), | |
2335 | "%s/video/input0", acpi_device_hid(video->device)); | |
2336 | ||
2337 | input->name = acpi_device_name(video->device); | |
2338 | input->phys = video->phys; | |
2339 | input->id.bustype = BUS_HOST; | |
2340 | input->id.product = 0x06; | |
91c05c66 | 2341 | input->dev.parent = &device->dev; |
e9dab196 LY |
2342 | input->evbit[0] = BIT(EV_KEY); |
2343 | set_bit(KEY_SWITCHVIDEOMODE, input->keybit); | |
2344 | set_bit(KEY_VIDEO_NEXT, input->keybit); | |
2345 | set_bit(KEY_VIDEO_PREV, input->keybit); | |
2346 | set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); | |
2347 | set_bit(KEY_BRIGHTNESSUP, input->keybit); | |
2348 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); | |
2349 | set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); | |
2350 | set_bit(KEY_DISPLAY_OFF, input->keybit); | |
2351 | set_bit(KEY_UNKNOWN, input->keybit); | |
e9dab196 | 2352 | |
f51e8391 DT |
2353 | error = input_register_device(input); |
2354 | if (error) | |
2355 | goto err_free_input_dev; | |
e9dab196 | 2356 | |
1da177e4 | 2357 | printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", |
4be44fcd LB |
2358 | ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), |
2359 | video->flags.multihead ? "yes" : "no", | |
2360 | video->flags.rom ? "yes" : "no", | |
2361 | video->flags.post ? "yes" : "no"); | |
1da177e4 | 2362 | |
f51e8391 DT |
2363 | return 0; |
2364 | ||
2365 | err_free_input_dev: | |
2366 | input_free_device(input); | |
f51e8391 DT |
2367 | err_stop_video: |
2368 | acpi_video_bus_stop_devices(video); | |
2369 | acpi_video_bus_put_devices(video); | |
2370 | kfree(video->attached_array); | |
2371 | acpi_video_bus_remove_fs(device); | |
2372 | err_free_video: | |
2373 | kfree(video); | |
db89b4f0 | 2374 | device->driver_data = NULL; |
1da177e4 | 2375 | |
f51e8391 | 2376 | return error; |
1da177e4 LT |
2377 | } |
2378 | ||
4be44fcd | 2379 | static int acpi_video_bus_remove(struct acpi_device *device, int type) |
1da177e4 | 2380 | { |
4be44fcd | 2381 | struct acpi_video_bus *video = NULL; |
1da177e4 | 2382 | |
1da177e4 LT |
2383 | |
2384 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 2385 | return -EINVAL; |
1da177e4 | 2386 | |
50dd0969 | 2387 | video = acpi_driver_data(device); |
1da177e4 LT |
2388 | |
2389 | acpi_video_bus_stop_devices(video); | |
1da177e4 LT |
2390 | acpi_video_bus_put_devices(video); |
2391 | acpi_video_bus_remove_fs(device); | |
2392 | ||
e9dab196 | 2393 | input_unregister_device(video->input); |
6044ec88 | 2394 | kfree(video->attached_array); |
1da177e4 LT |
2395 | kfree(video); |
2396 | ||
d550d98d | 2397 | return 0; |
1da177e4 LT |
2398 | } |
2399 | ||
74a365b3 MG |
2400 | static int __init intel_opregion_present(void) |
2401 | { | |
2402 | #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE) | |
2403 | struct pci_dev *dev = NULL; | |
2404 | u32 address; | |
2405 | ||
2406 | for_each_pci_dev(dev) { | |
2407 | if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) | |
2408 | continue; | |
2409 | if (dev->vendor != PCI_VENDOR_ID_INTEL) | |
2410 | continue; | |
2411 | pci_read_config_dword(dev, 0xfc, &address); | |
2412 | if (!address) | |
2413 | continue; | |
2414 | return 1; | |
2415 | } | |
2416 | #endif | |
2417 | return 0; | |
2418 | } | |
2419 | ||
2420 | int acpi_video_register(void) | |
1da177e4 | 2421 | { |
4be44fcd | 2422 | int result = 0; |
86e437f0 ZY |
2423 | if (register_count) { |
2424 | /* | |
2425 | * if the function of acpi_video_register is already called, | |
2426 | * don't register the acpi_vide_bus again and return no error. | |
2427 | */ | |
2428 | return 0; | |
2429 | } | |
1da177e4 | 2430 | |
1da177e4 LT |
2431 | acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); |
2432 | if (!acpi_video_dir) | |
d550d98d | 2433 | return -ENODEV; |
1da177e4 LT |
2434 | |
2435 | result = acpi_bus_register_driver(&acpi_video_bus); | |
2436 | if (result < 0) { | |
2437 | remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); | |
d550d98d | 2438 | return -ENODEV; |
1da177e4 LT |
2439 | } |
2440 | ||
86e437f0 ZY |
2441 | /* |
2442 | * When the acpi_video_bus is loaded successfully, increase | |
2443 | * the counter reference. | |
2444 | */ | |
2445 | register_count = 1; | |
2446 | ||
d550d98d | 2447 | return 0; |
1da177e4 | 2448 | } |
74a365b3 MG |
2449 | EXPORT_SYMBOL(acpi_video_register); |
2450 | ||
86e437f0 ZY |
2451 | void acpi_video_unregister(void) |
2452 | { | |
2453 | if (!register_count) { | |
2454 | /* | |
2455 | * If the acpi video bus is already unloaded, don't | |
2456 | * unload it again and return directly. | |
2457 | */ | |
2458 | return; | |
2459 | } | |
2460 | acpi_bus_unregister_driver(&acpi_video_bus); | |
2461 | ||
2462 | remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); | |
2463 | ||
2464 | register_count = 0; | |
2465 | ||
2466 | return; | |
2467 | } | |
2468 | EXPORT_SYMBOL(acpi_video_unregister); | |
2469 | ||
74a365b3 MG |
2470 | /* |
2471 | * This is kind of nasty. Hardware using Intel chipsets may require | |
2472 | * the video opregion code to be run first in order to initialise | |
2473 | * state before any ACPI video calls are made. To handle this we defer | |
2474 | * registration of the video class until the opregion code has run. | |
2475 | */ | |
2476 | ||
2477 | static int __init acpi_video_init(void) | |
2478 | { | |
45cb50e6 ZR |
2479 | dmi_check_system(video_dmi_table); |
2480 | ||
74a365b3 MG |
2481 | if (intel_opregion_present()) |
2482 | return 0; | |
2483 | ||
2484 | return acpi_video_register(); | |
2485 | } | |
1da177e4 | 2486 | |
86e437f0 | 2487 | static void __exit acpi_video_exit(void) |
1da177e4 | 2488 | { |
86e437f0 | 2489 | acpi_video_unregister(); |
1da177e4 | 2490 | |
d550d98d | 2491 | return; |
1da177e4 LT |
2492 | } |
2493 | ||
2494 | module_init(acpi_video_init); | |
2495 | module_exit(acpi_video_exit); |