]>
Commit | Line | Data |
---|---|---|
745a5d21 CC |
1 | /* |
2 | * Acer WMI Laptop Extras | |
3 | * | |
4f0175dc | 4 | * Copyright (C) 2007-2009 Carlos Corbacho <[email protected]> |
745a5d21 CC |
5 | * |
6 | * Based on acer_acpi: | |
7 | * Copyright (C) 2005-2007 E.M. Smith | |
8 | * Copyright (C) 2007-2008 Carlos Corbacho <[email protected]> | |
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 | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | */ | |
24 | ||
745a5d21 CC |
25 | #include <linux/kernel.h> |
26 | #include <linux/module.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/types.h> | |
29 | #include <linux/dmi.h> | |
f2b585b4 | 30 | #include <linux/fb.h> |
745a5d21 CC |
31 | #include <linux/backlight.h> |
32 | #include <linux/leds.h> | |
33 | #include <linux/platform_device.h> | |
34 | #include <linux/acpi.h> | |
35 | #include <linux/i8042.h> | |
0606e1ab CC |
36 | #include <linux/rfkill.h> |
37 | #include <linux/workqueue.h> | |
81143522 | 38 | #include <linux/debugfs.h> |
5a0e3ad6 | 39 | #include <linux/slab.h> |
3fdca87d LCY |
40 | #include <linux/input.h> |
41 | #include <linux/input/sparse-keymap.h> | |
745a5d21 CC |
42 | |
43 | #include <acpi/acpi_drivers.h> | |
44 | ||
45 | MODULE_AUTHOR("Carlos Corbacho"); | |
46 | MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); | |
47 | MODULE_LICENSE("GPL"); | |
48 | ||
49 | #define ACER_LOGPREFIX "acer-wmi: " | |
50 | #define ACER_ERR KERN_ERR ACER_LOGPREFIX | |
51 | #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX | |
52 | #define ACER_INFO KERN_INFO ACER_LOGPREFIX | |
3fdca87d | 53 | #define ACER_WARNING KERN_WARNING ACER_LOGPREFIX |
745a5d21 | 54 | |
745a5d21 CC |
55 | /* |
56 | * Magic Number | |
57 | * Meaning is unknown - this number is required for writing to ACPI for AMW0 | |
58 | * (it's also used in acerhk when directly accessing the BIOS) | |
59 | */ | |
60 | #define ACER_AMW0_WRITE 0x9610 | |
61 | ||
62 | /* | |
63 | * Bit masks for the AMW0 interface | |
64 | */ | |
65 | #define ACER_AMW0_WIRELESS_MASK 0x35 | |
66 | #define ACER_AMW0_BLUETOOTH_MASK 0x34 | |
67 | #define ACER_AMW0_MAILLED_MASK 0x31 | |
68 | ||
69 | /* | |
70 | * Method IDs for WMID interface | |
71 | */ | |
72 | #define ACER_WMID_GET_WIRELESS_METHODID 1 | |
73 | #define ACER_WMID_GET_BLUETOOTH_METHODID 2 | |
74 | #define ACER_WMID_GET_BRIGHTNESS_METHODID 3 | |
75 | #define ACER_WMID_SET_WIRELESS_METHODID 4 | |
76 | #define ACER_WMID_SET_BLUETOOTH_METHODID 5 | |
77 | #define ACER_WMID_SET_BRIGHTNESS_METHODID 6 | |
78 | #define ACER_WMID_GET_THREEG_METHODID 10 | |
79 | #define ACER_WMID_SET_THREEG_METHODID 11 | |
80 | ||
81 | /* | |
82 | * Acer ACPI method GUIDs | |
83 | */ | |
84 | #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" | |
5753dd53 | 85 | #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C" |
bbb70607 | 86 | #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3" |
745a5d21 | 87 | #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A" |
b3c9092b | 88 | #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531" |
745a5d21 | 89 | |
3fdca87d LCY |
90 | /* |
91 | * Acer ACPI event GUIDs | |
92 | */ | |
93 | #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026" | |
94 | ||
745a5d21 CC |
95 | MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB"); |
96 | MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"); | |
3fdca87d LCY |
97 | MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026"); |
98 | ||
99 | enum acer_wmi_event_ids { | |
100 | WMID_HOTKEY_EVENT = 0x1, | |
101 | }; | |
102 | ||
103 | static const struct key_entry acer_wmi_keymap[] = { | |
104 | {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */ | |
105 | {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */ | |
106 | {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */ | |
107 | {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */ | |
108 | {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */ | |
109 | {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */ | |
110 | {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */ | |
111 | {KE_KEY, 0x82, {KEY_F22} }, /* Touch Pad On/Off */ | |
112 | {KE_END, 0} | |
113 | }; | |
114 | ||
115 | static struct input_dev *acer_wmi_input_dev; | |
116 | ||
117 | struct event_return_value { | |
118 | u8 function; | |
119 | u8 key_num; | |
120 | u16 device_state; | |
121 | u32 reserved; | |
122 | } __attribute__((packed)); | |
745a5d21 | 123 | |
b3c9092b LCY |
124 | /* |
125 | * GUID3 Get Device Status device flags | |
126 | */ | |
6c3df88f | 127 | #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */ |
b3c9092b | 128 | #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */ |
6c3df88f | 129 | #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */ |
b3c9092b | 130 | |
59ccf2f3 FLCY |
131 | struct lm_input_params { |
132 | u8 function_num; /* Function Number */ | |
133 | u16 commun_devices; /* Communication type devices default status */ | |
134 | u16 devices; /* Other type devices default status */ | |
135 | u8 lm_status; /* Launch Manager Status */ | |
136 | u16 reserved; | |
137 | } __attribute__((packed)); | |
138 | ||
139 | struct lm_return_value { | |
140 | u8 error_code; /* Error Code */ | |
141 | u8 ec_return_value; /* EC Return Value */ | |
142 | u16 reserved; | |
143 | } __attribute__((packed)); | |
144 | ||
b3c9092b LCY |
145 | struct wmid3_gds_input_param { /* Get Device Status input parameter */ |
146 | u8 function_num; /* Function Number */ | |
147 | u8 hotkey_number; /* Hotkey Number */ | |
148 | u16 devices; /* Get Device */ | |
149 | } __attribute__((packed)); | |
150 | ||
151 | struct wmid3_gds_return_value { /* Get Device Status return value*/ | |
152 | u8 error_code; /* Error Code */ | |
153 | u8 ec_return_value; /* EC Return Value */ | |
154 | u16 devices; /* Current Device Status */ | |
155 | u32 reserved; | |
156 | } __attribute__((packed)); | |
157 | ||
6c3df88f LCY |
158 | struct hotkey_function_type_aa { |
159 | u8 type; | |
160 | u8 length; | |
161 | u16 handle; | |
162 | u16 commun_func_bitmap; | |
163 | } __attribute__((packed)); | |
164 | ||
745a5d21 CC |
165 | /* |
166 | * Interface capability flags | |
167 | */ | |
168 | #define ACER_CAP_MAILLED (1<<0) | |
169 | #define ACER_CAP_WIRELESS (1<<1) | |
170 | #define ACER_CAP_BLUETOOTH (1<<2) | |
171 | #define ACER_CAP_BRIGHTNESS (1<<3) | |
172 | #define ACER_CAP_THREEG (1<<4) | |
173 | #define ACER_CAP_ANY (0xFFFFFFFF) | |
174 | ||
175 | /* | |
176 | * Interface type flags | |
177 | */ | |
178 | enum interface_flags { | |
179 | ACER_AMW0, | |
180 | ACER_AMW0_V2, | |
181 | ACER_WMID, | |
182 | }; | |
183 | ||
184 | #define ACER_DEFAULT_WIRELESS 0 | |
185 | #define ACER_DEFAULT_BLUETOOTH 0 | |
186 | #define ACER_DEFAULT_MAILLED 0 | |
187 | #define ACER_DEFAULT_THREEG 0 | |
188 | ||
189 | static int max_brightness = 0xF; | |
190 | ||
745a5d21 CC |
191 | static int mailled = -1; |
192 | static int brightness = -1; | |
193 | static int threeg = -1; | |
194 | static int force_series; | |
59ccf2f3 | 195 | static bool ec_raw_mode; |
6c3df88f | 196 | static bool has_type_aa; |
745a5d21 CC |
197 | |
198 | module_param(mailled, int, 0444); | |
745a5d21 CC |
199 | module_param(brightness, int, 0444); |
200 | module_param(threeg, int, 0444); | |
201 | module_param(force_series, int, 0444); | |
59ccf2f3 | 202 | module_param(ec_raw_mode, bool, 0444); |
745a5d21 CC |
203 | MODULE_PARM_DESC(mailled, "Set initial state of Mail LED"); |
204 | MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness"); | |
205 | MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware"); | |
206 | MODULE_PARM_DESC(force_series, "Force a different laptop series"); | |
59ccf2f3 | 207 | MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode"); |
745a5d21 CC |
208 | |
209 | struct acer_data { | |
210 | int mailled; | |
745a5d21 CC |
211 | int threeg; |
212 | int brightness; | |
213 | }; | |
214 | ||
81143522 CC |
215 | struct acer_debug { |
216 | struct dentry *root; | |
217 | struct dentry *devices; | |
218 | u32 wmid_devices; | |
219 | }; | |
220 | ||
0606e1ab CC |
221 | static struct rfkill *wireless_rfkill; |
222 | static struct rfkill *bluetooth_rfkill; | |
b3c9092b | 223 | static struct rfkill *threeg_rfkill; |
0606e1ab | 224 | |
745a5d21 CC |
225 | /* Each low-level interface must define at least some of the following */ |
226 | struct wmi_interface { | |
227 | /* The WMI device type */ | |
228 | u32 type; | |
229 | ||
230 | /* The capabilities this interface provides */ | |
231 | u32 capability; | |
232 | ||
233 | /* Private data for the current interface */ | |
234 | struct acer_data data; | |
81143522 CC |
235 | |
236 | /* debugfs entries associated with this interface */ | |
237 | struct acer_debug debug; | |
745a5d21 CC |
238 | }; |
239 | ||
240 | /* The static interface pointer, points to the currently detected interface */ | |
241 | static struct wmi_interface *interface; | |
242 | ||
243 | /* | |
244 | * Embedded Controller quirks | |
245 | * Some laptops require us to directly access the EC to either enable or query | |
246 | * features that are not available through WMI. | |
247 | */ | |
248 | ||
249 | struct quirk_entry { | |
250 | u8 wireless; | |
251 | u8 mailled; | |
9991d9f2 | 252 | s8 brightness; |
745a5d21 CC |
253 | u8 bluetooth; |
254 | }; | |
255 | ||
256 | static struct quirk_entry *quirks; | |
257 | ||
258 | static void set_quirks(void) | |
259 | { | |
83097aca AV |
260 | if (!interface) |
261 | return; | |
262 | ||
745a5d21 CC |
263 | if (quirks->mailled) |
264 | interface->capability |= ACER_CAP_MAILLED; | |
265 | ||
266 | if (quirks->brightness) | |
267 | interface->capability |= ACER_CAP_BRIGHTNESS; | |
268 | } | |
269 | ||
270 | static int dmi_matched(const struct dmi_system_id *dmi) | |
271 | { | |
272 | quirks = dmi->driver_data; | |
d53bf0f3 | 273 | return 1; |
745a5d21 CC |
274 | } |
275 | ||
276 | static struct quirk_entry quirk_unknown = { | |
277 | }; | |
278 | ||
9991d9f2 CC |
279 | static struct quirk_entry quirk_acer_aspire_1520 = { |
280 | .brightness = -1, | |
281 | }; | |
282 | ||
745a5d21 CC |
283 | static struct quirk_entry quirk_acer_travelmate_2490 = { |
284 | .mailled = 1, | |
285 | }; | |
286 | ||
287 | /* This AMW0 laptop has no bluetooth */ | |
288 | static struct quirk_entry quirk_medion_md_98300 = { | |
289 | .wireless = 1, | |
290 | }; | |
291 | ||
6f061ab5 CC |
292 | static struct quirk_entry quirk_fujitsu_amilo_li_1718 = { |
293 | .wireless = 2, | |
294 | }; | |
295 | ||
a74dd5fd CC |
296 | /* The Aspire One has a dummy ACPI-WMI interface - disable it */ |
297 | static struct dmi_system_id __devinitdata acer_blacklist[] = { | |
298 | { | |
299 | .ident = "Acer Aspire One (SSD)", | |
300 | .matches = { | |
301 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
302 | DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"), | |
303 | }, | |
304 | }, | |
305 | { | |
306 | .ident = "Acer Aspire One (HDD)", | |
307 | .matches = { | |
308 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
309 | DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"), | |
310 | }, | |
311 | }, | |
312 | {} | |
313 | }; | |
314 | ||
745a5d21 | 315 | static struct dmi_system_id acer_quirks[] = { |
9991d9f2 CC |
316 | { |
317 | .callback = dmi_matched, | |
318 | .ident = "Acer Aspire 1360", | |
319 | .matches = { | |
320 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
321 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"), | |
322 | }, | |
323 | .driver_data = &quirk_acer_aspire_1520, | |
324 | }, | |
325 | { | |
326 | .callback = dmi_matched, | |
327 | .ident = "Acer Aspire 1520", | |
328 | .matches = { | |
329 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
330 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"), | |
331 | }, | |
332 | .driver_data = &quirk_acer_aspire_1520, | |
333 | }, | |
745a5d21 CC |
334 | { |
335 | .callback = dmi_matched, | |
336 | .ident = "Acer Aspire 3100", | |
337 | .matches = { | |
338 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
339 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"), | |
340 | }, | |
341 | .driver_data = &quirk_acer_travelmate_2490, | |
342 | }, | |
ed9cfe98 CC |
343 | { |
344 | .callback = dmi_matched, | |
345 | .ident = "Acer Aspire 3610", | |
346 | .matches = { | |
347 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
348 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"), | |
349 | }, | |
350 | .driver_data = &quirk_acer_travelmate_2490, | |
351 | }, | |
745a5d21 CC |
352 | { |
353 | .callback = dmi_matched, | |
354 | .ident = "Acer Aspire 5100", | |
355 | .matches = { | |
356 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
357 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"), | |
358 | }, | |
359 | .driver_data = &quirk_acer_travelmate_2490, | |
360 | }, | |
ed9cfe98 CC |
361 | { |
362 | .callback = dmi_matched, | |
363 | .ident = "Acer Aspire 5610", | |
364 | .matches = { | |
365 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
366 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"), | |
367 | }, | |
368 | .driver_data = &quirk_acer_travelmate_2490, | |
369 | }, | |
745a5d21 CC |
370 | { |
371 | .callback = dmi_matched, | |
372 | .ident = "Acer Aspire 5630", | |
373 | .matches = { | |
374 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
375 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"), | |
376 | }, | |
377 | .driver_data = &quirk_acer_travelmate_2490, | |
378 | }, | |
379 | { | |
380 | .callback = dmi_matched, | |
381 | .ident = "Acer Aspire 5650", | |
382 | .matches = { | |
383 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
384 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"), | |
385 | }, | |
386 | .driver_data = &quirk_acer_travelmate_2490, | |
387 | }, | |
388 | { | |
389 | .callback = dmi_matched, | |
390 | .ident = "Acer Aspire 5680", | |
391 | .matches = { | |
392 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
393 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"), | |
394 | }, | |
395 | .driver_data = &quirk_acer_travelmate_2490, | |
396 | }, | |
397 | { | |
398 | .callback = dmi_matched, | |
399 | .ident = "Acer Aspire 9110", | |
400 | .matches = { | |
401 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
402 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"), | |
403 | }, | |
404 | .driver_data = &quirk_acer_travelmate_2490, | |
405 | }, | |
406 | { | |
407 | .callback = dmi_matched, | |
408 | .ident = "Acer TravelMate 2490", | |
409 | .matches = { | |
410 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
411 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"), | |
412 | }, | |
413 | .driver_data = &quirk_acer_travelmate_2490, | |
414 | }, | |
262ee35b CC |
415 | { |
416 | .callback = dmi_matched, | |
417 | .ident = "Acer TravelMate 4200", | |
418 | .matches = { | |
419 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | |
420 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"), | |
421 | }, | |
422 | .driver_data = &quirk_acer_travelmate_2490, | |
423 | }, | |
6f061ab5 CC |
424 | { |
425 | .callback = dmi_matched, | |
426 | .ident = "Fujitsu Siemens Amilo Li 1718", | |
427 | .matches = { | |
428 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), | |
429 | DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"), | |
430 | }, | |
431 | .driver_data = &quirk_fujitsu_amilo_li_1718, | |
432 | }, | |
745a5d21 CC |
433 | { |
434 | .callback = dmi_matched, | |
435 | .ident = "Medion MD 98300", | |
436 | .matches = { | |
437 | DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), | |
438 | DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"), | |
439 | }, | |
440 | .driver_data = &quirk_medion_md_98300, | |
441 | }, | |
442 | {} | |
443 | }; | |
444 | ||
445 | /* Find which quirks are needed for a particular vendor/ model pair */ | |
446 | static void find_quirks(void) | |
447 | { | |
448 | if (!force_series) { | |
449 | dmi_check_system(acer_quirks); | |
450 | } else if (force_series == 2490) { | |
451 | quirks = &quirk_acer_travelmate_2490; | |
452 | } | |
453 | ||
454 | if (quirks == NULL) | |
455 | quirks = &quirk_unknown; | |
456 | ||
457 | set_quirks(); | |
458 | } | |
459 | ||
460 | /* | |
461 | * General interface convenience methods | |
462 | */ | |
463 | ||
464 | static bool has_cap(u32 cap) | |
465 | { | |
466 | if ((interface->capability & cap) != 0) | |
467 | return 1; | |
468 | ||
469 | return 0; | |
470 | } | |
471 | ||
472 | /* | |
473 | * AMW0 (V1) interface | |
474 | */ | |
475 | struct wmab_args { | |
476 | u32 eax; | |
477 | u32 ebx; | |
478 | u32 ecx; | |
479 | u32 edx; | |
480 | }; | |
481 | ||
482 | struct wmab_ret { | |
483 | u32 eax; | |
484 | u32 ebx; | |
485 | u32 ecx; | |
486 | u32 edx; | |
487 | u32 eex; | |
488 | }; | |
489 | ||
490 | static acpi_status wmab_execute(struct wmab_args *regbuf, | |
491 | struct acpi_buffer *result) | |
492 | { | |
493 | struct acpi_buffer input; | |
494 | acpi_status status; | |
495 | input.length = sizeof(struct wmab_args); | |
496 | input.pointer = (u8 *)regbuf; | |
497 | ||
498 | status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result); | |
499 | ||
500 | return status; | |
501 | } | |
502 | ||
503 | static acpi_status AMW0_get_u32(u32 *value, u32 cap, | |
504 | struct wmi_interface *iface) | |
505 | { | |
506 | int err; | |
507 | u8 result; | |
508 | ||
509 | switch (cap) { | |
510 | case ACER_CAP_MAILLED: | |
511 | switch (quirks->mailled) { | |
512 | default: | |
513 | err = ec_read(0xA, &result); | |
514 | if (err) | |
515 | return AE_ERROR; | |
516 | *value = (result >> 7) & 0x1; | |
517 | return AE_OK; | |
518 | } | |
519 | break; | |
520 | case ACER_CAP_WIRELESS: | |
521 | switch (quirks->wireless) { | |
522 | case 1: | |
523 | err = ec_read(0x7B, &result); | |
524 | if (err) | |
525 | return AE_ERROR; | |
526 | *value = result & 0x1; | |
527 | return AE_OK; | |
6f061ab5 CC |
528 | case 2: |
529 | err = ec_read(0x71, &result); | |
530 | if (err) | |
531 | return AE_ERROR; | |
532 | *value = result & 0x1; | |
533 | return AE_OK; | |
745a5d21 CC |
534 | default: |
535 | err = ec_read(0xA, &result); | |
536 | if (err) | |
537 | return AE_ERROR; | |
538 | *value = (result >> 2) & 0x1; | |
539 | return AE_OK; | |
540 | } | |
541 | break; | |
542 | case ACER_CAP_BLUETOOTH: | |
543 | switch (quirks->bluetooth) { | |
544 | default: | |
545 | err = ec_read(0xA, &result); | |
546 | if (err) | |
547 | return AE_ERROR; | |
548 | *value = (result >> 4) & 0x1; | |
549 | return AE_OK; | |
550 | } | |
551 | break; | |
552 | case ACER_CAP_BRIGHTNESS: | |
553 | switch (quirks->brightness) { | |
554 | default: | |
555 | err = ec_read(0x83, &result); | |
556 | if (err) | |
557 | return AE_ERROR; | |
558 | *value = result; | |
559 | return AE_OK; | |
560 | } | |
561 | break; | |
562 | default: | |
08237974 | 563 | return AE_ERROR; |
745a5d21 CC |
564 | } |
565 | return AE_OK; | |
566 | } | |
567 | ||
568 | static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface) | |
569 | { | |
570 | struct wmab_args args; | |
571 | ||
572 | args.eax = ACER_AMW0_WRITE; | |
573 | args.ebx = value ? (1<<8) : 0; | |
574 | args.ecx = args.edx = 0; | |
575 | ||
576 | switch (cap) { | |
577 | case ACER_CAP_MAILLED: | |
578 | if (value > 1) | |
579 | return AE_BAD_PARAMETER; | |
580 | args.ebx |= ACER_AMW0_MAILLED_MASK; | |
581 | break; | |
582 | case ACER_CAP_WIRELESS: | |
583 | if (value > 1) | |
584 | return AE_BAD_PARAMETER; | |
585 | args.ebx |= ACER_AMW0_WIRELESS_MASK; | |
586 | break; | |
587 | case ACER_CAP_BLUETOOTH: | |
588 | if (value > 1) | |
589 | return AE_BAD_PARAMETER; | |
590 | args.ebx |= ACER_AMW0_BLUETOOTH_MASK; | |
591 | break; | |
592 | case ACER_CAP_BRIGHTNESS: | |
593 | if (value > max_brightness) | |
594 | return AE_BAD_PARAMETER; | |
595 | switch (quirks->brightness) { | |
745a5d21 | 596 | default: |
4609d029 CC |
597 | return ec_write(0x83, value); |
598 | break; | |
745a5d21 CC |
599 | } |
600 | default: | |
08237974 | 601 | return AE_ERROR; |
745a5d21 CC |
602 | } |
603 | ||
604 | /* Actually do the set */ | |
605 | return wmab_execute(&args, NULL); | |
606 | } | |
607 | ||
608 | static acpi_status AMW0_find_mailled(void) | |
609 | { | |
610 | struct wmab_args args; | |
611 | struct wmab_ret ret; | |
612 | acpi_status status = AE_OK; | |
613 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; | |
614 | union acpi_object *obj; | |
615 | ||
616 | args.eax = 0x86; | |
617 | args.ebx = args.ecx = args.edx = 0; | |
618 | ||
619 | status = wmab_execute(&args, &out); | |
620 | if (ACPI_FAILURE(status)) | |
621 | return status; | |
622 | ||
623 | obj = (union acpi_object *) out.pointer; | |
624 | if (obj && obj->type == ACPI_TYPE_BUFFER && | |
625 | obj->buffer.length == sizeof(struct wmab_ret)) { | |
626 | ret = *((struct wmab_ret *) obj->buffer.pointer); | |
627 | } else { | |
7677fbdf | 628 | kfree(out.pointer); |
745a5d21 CC |
629 | return AE_ERROR; |
630 | } | |
631 | ||
632 | if (ret.eex & 0x1) | |
633 | interface->capability |= ACER_CAP_MAILLED; | |
634 | ||
635 | kfree(out.pointer); | |
636 | ||
637 | return AE_OK; | |
638 | } | |
639 | ||
640 | static acpi_status AMW0_set_capabilities(void) | |
641 | { | |
642 | struct wmab_args args; | |
643 | struct wmab_ret ret; | |
7677fbdf | 644 | acpi_status status; |
745a5d21 CC |
645 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
646 | union acpi_object *obj; | |
647 | ||
5753dd53 CC |
648 | /* |
649 | * On laptops with this strange GUID (non Acer), normal probing doesn't | |
650 | * work. | |
651 | */ | |
652 | if (wmi_has_guid(AMW0_GUID2)) { | |
653 | interface->capability |= ACER_CAP_WIRELESS; | |
654 | return AE_OK; | |
655 | } | |
656 | ||
745a5d21 CC |
657 | args.eax = ACER_AMW0_WRITE; |
658 | args.ecx = args.edx = 0; | |
659 | ||
660 | args.ebx = 0xa2 << 8; | |
661 | args.ebx |= ACER_AMW0_WIRELESS_MASK; | |
662 | ||
663 | status = wmab_execute(&args, &out); | |
664 | if (ACPI_FAILURE(status)) | |
665 | return status; | |
666 | ||
7677fbdf | 667 | obj = out.pointer; |
745a5d21 CC |
668 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
669 | obj->buffer.length == sizeof(struct wmab_ret)) { | |
670 | ret = *((struct wmab_ret *) obj->buffer.pointer); | |
671 | } else { | |
7677fbdf AL |
672 | status = AE_ERROR; |
673 | goto out; | |
745a5d21 CC |
674 | } |
675 | ||
676 | if (ret.eax & 0x1) | |
677 | interface->capability |= ACER_CAP_WIRELESS; | |
678 | ||
679 | args.ebx = 2 << 8; | |
680 | args.ebx |= ACER_AMW0_BLUETOOTH_MASK; | |
681 | ||
7677fbdf AL |
682 | /* |
683 | * It's ok to use existing buffer for next wmab_execute call. | |
684 | * But we need to kfree(out.pointer) if next wmab_execute fail. | |
685 | */ | |
745a5d21 CC |
686 | status = wmab_execute(&args, &out); |
687 | if (ACPI_FAILURE(status)) | |
7677fbdf | 688 | goto out; |
745a5d21 CC |
689 | |
690 | obj = (union acpi_object *) out.pointer; | |
691 | if (obj && obj->type == ACPI_TYPE_BUFFER | |
692 | && obj->buffer.length == sizeof(struct wmab_ret)) { | |
693 | ret = *((struct wmab_ret *) obj->buffer.pointer); | |
694 | } else { | |
7677fbdf AL |
695 | status = AE_ERROR; |
696 | goto out; | |
745a5d21 CC |
697 | } |
698 | ||
699 | if (ret.eax & 0x1) | |
700 | interface->capability |= ACER_CAP_BLUETOOTH; | |
701 | ||
745a5d21 CC |
702 | /* |
703 | * This appears to be safe to enable, since all Wistron based laptops | |
704 | * appear to use the same EC register for brightness, even if they | |
705 | * differ for wireless, etc | |
706 | */ | |
9991d9f2 CC |
707 | if (quirks->brightness >= 0) |
708 | interface->capability |= ACER_CAP_BRIGHTNESS; | |
745a5d21 | 709 | |
7677fbdf AL |
710 | status = AE_OK; |
711 | out: | |
712 | kfree(out.pointer); | |
713 | return status; | |
745a5d21 CC |
714 | } |
715 | ||
716 | static struct wmi_interface AMW0_interface = { | |
717 | .type = ACER_AMW0, | |
718 | }; | |
719 | ||
720 | static struct wmi_interface AMW0_V2_interface = { | |
721 | .type = ACER_AMW0_V2, | |
722 | }; | |
723 | ||
724 | /* | |
725 | * New interface (The WMID interface) | |
726 | */ | |
727 | static acpi_status | |
728 | WMI_execute_u32(u32 method_id, u32 in, u32 *out) | |
729 | { | |
730 | struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) }; | |
731 | struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL }; | |
732 | union acpi_object *obj; | |
733 | u32 tmp; | |
734 | acpi_status status; | |
735 | ||
736 | status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result); | |
737 | ||
738 | if (ACPI_FAILURE(status)) | |
739 | return status; | |
740 | ||
741 | obj = (union acpi_object *) result.pointer; | |
742 | if (obj && obj->type == ACPI_TYPE_BUFFER && | |
743 | obj->buffer.length == sizeof(u32)) { | |
744 | tmp = *((u32 *) obj->buffer.pointer); | |
745 | } else { | |
746 | tmp = 0; | |
747 | } | |
748 | ||
749 | if (out) | |
750 | *out = tmp; | |
751 | ||
752 | kfree(result.pointer); | |
753 | ||
754 | return status; | |
755 | } | |
756 | ||
757 | static acpi_status WMID_get_u32(u32 *value, u32 cap, | |
758 | struct wmi_interface *iface) | |
759 | { | |
760 | acpi_status status; | |
761 | u8 tmp; | |
762 | u32 result, method_id = 0; | |
763 | ||
764 | switch (cap) { | |
765 | case ACER_CAP_WIRELESS: | |
766 | method_id = ACER_WMID_GET_WIRELESS_METHODID; | |
767 | break; | |
768 | case ACER_CAP_BLUETOOTH: | |
769 | method_id = ACER_WMID_GET_BLUETOOTH_METHODID; | |
770 | break; | |
771 | case ACER_CAP_BRIGHTNESS: | |
772 | method_id = ACER_WMID_GET_BRIGHTNESS_METHODID; | |
773 | break; | |
774 | case ACER_CAP_THREEG: | |
775 | method_id = ACER_WMID_GET_THREEG_METHODID; | |
776 | break; | |
777 | case ACER_CAP_MAILLED: | |
778 | if (quirks->mailled == 1) { | |
779 | ec_read(0x9f, &tmp); | |
780 | *value = tmp & 0x1; | |
781 | return 0; | |
782 | } | |
783 | default: | |
08237974 | 784 | return AE_ERROR; |
745a5d21 CC |
785 | } |
786 | status = WMI_execute_u32(method_id, 0, &result); | |
787 | ||
788 | if (ACPI_SUCCESS(status)) | |
789 | *value = (u8)result; | |
790 | ||
791 | return status; | |
792 | } | |
793 | ||
794 | static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface) | |
795 | { | |
796 | u32 method_id = 0; | |
797 | char param; | |
798 | ||
799 | switch (cap) { | |
800 | case ACER_CAP_BRIGHTNESS: | |
801 | if (value > max_brightness) | |
802 | return AE_BAD_PARAMETER; | |
803 | method_id = ACER_WMID_SET_BRIGHTNESS_METHODID; | |
804 | break; | |
805 | case ACER_CAP_WIRELESS: | |
806 | if (value > 1) | |
807 | return AE_BAD_PARAMETER; | |
808 | method_id = ACER_WMID_SET_WIRELESS_METHODID; | |
809 | break; | |
810 | case ACER_CAP_BLUETOOTH: | |
811 | if (value > 1) | |
812 | return AE_BAD_PARAMETER; | |
813 | method_id = ACER_WMID_SET_BLUETOOTH_METHODID; | |
814 | break; | |
815 | case ACER_CAP_THREEG: | |
816 | if (value > 1) | |
817 | return AE_BAD_PARAMETER; | |
818 | method_id = ACER_WMID_SET_THREEG_METHODID; | |
819 | break; | |
820 | case ACER_CAP_MAILLED: | |
821 | if (value > 1) | |
822 | return AE_BAD_PARAMETER; | |
823 | if (quirks->mailled == 1) { | |
824 | param = value ? 0x92 : 0x93; | |
181d683d | 825 | i8042_lock_chip(); |
745a5d21 | 826 | i8042_command(¶m, 0x1059); |
181d683d | 827 | i8042_unlock_chip(); |
745a5d21 CC |
828 | return 0; |
829 | } | |
830 | break; | |
831 | default: | |
08237974 | 832 | return AE_ERROR; |
745a5d21 CC |
833 | } |
834 | return WMI_execute_u32(method_id, (u32)value, NULL); | |
835 | } | |
836 | ||
6c3df88f LCY |
837 | static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy) |
838 | { | |
839 | struct hotkey_function_type_aa *type_aa; | |
840 | ||
841 | /* We are looking for OEM-specific Type AAh */ | |
842 | if (header->type != 0xAA) | |
843 | return; | |
844 | ||
845 | has_type_aa = true; | |
846 | type_aa = (struct hotkey_function_type_aa *) header; | |
847 | ||
848 | printk(ACER_INFO "Function bitmap for Communication Button: 0x%x\n", | |
849 | type_aa->commun_func_bitmap); | |
850 | ||
851 | if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS) | |
852 | interface->capability |= ACER_CAP_WIRELESS; | |
853 | if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG) | |
854 | interface->capability |= ACER_CAP_THREEG; | |
855 | if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH) | |
856 | interface->capability |= ACER_CAP_BLUETOOTH; | |
857 | } | |
858 | ||
745a5d21 CC |
859 | static acpi_status WMID_set_capabilities(void) |
860 | { | |
861 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; | |
862 | union acpi_object *obj; | |
863 | acpi_status status; | |
864 | u32 devices; | |
865 | ||
866 | status = wmi_query_block(WMID_GUID2, 1, &out); | |
867 | if (ACPI_FAILURE(status)) | |
868 | return status; | |
869 | ||
870 | obj = (union acpi_object *) out.pointer; | |
871 | if (obj && obj->type == ACPI_TYPE_BUFFER && | |
872 | obj->buffer.length == sizeof(u32)) { | |
873 | devices = *((u32 *) obj->buffer.pointer); | |
874 | } else { | |
66904863 | 875 | kfree(out.pointer); |
745a5d21 CC |
876 | return AE_ERROR; |
877 | } | |
878 | ||
6c3df88f LCY |
879 | dmi_walk(type_aa_dmi_decode, NULL); |
880 | if (!has_type_aa) { | |
881 | interface->capability |= ACER_CAP_WIRELESS; | |
882 | interface->capability |= ACER_CAP_THREEG; | |
883 | if (devices & 0x10) | |
884 | interface->capability |= ACER_CAP_BLUETOOTH; | |
885 | } | |
745a5d21 CC |
886 | |
887 | /* WMID always provides brightness methods */ | |
888 | interface->capability |= ACER_CAP_BRIGHTNESS; | |
889 | ||
745a5d21 CC |
890 | if (!(devices & 0x20)) |
891 | max_brightness = 0x9; | |
892 | ||
66904863 | 893 | kfree(out.pointer); |
745a5d21 CC |
894 | return status; |
895 | } | |
896 | ||
897 | static struct wmi_interface wmid_interface = { | |
898 | .type = ACER_WMID, | |
899 | }; | |
900 | ||
901 | /* | |
902 | * Generic Device (interface-independent) | |
903 | */ | |
904 | ||
905 | static acpi_status get_u32(u32 *value, u32 cap) | |
906 | { | |
08237974 | 907 | acpi_status status = AE_ERROR; |
745a5d21 CC |
908 | |
909 | switch (interface->type) { | |
910 | case ACER_AMW0: | |
911 | status = AMW0_get_u32(value, cap, interface); | |
912 | break; | |
913 | case ACER_AMW0_V2: | |
914 | if (cap == ACER_CAP_MAILLED) { | |
915 | status = AMW0_get_u32(value, cap, interface); | |
916 | break; | |
917 | } | |
918 | case ACER_WMID: | |
919 | status = WMID_get_u32(value, cap, interface); | |
920 | break; | |
921 | } | |
922 | ||
923 | return status; | |
924 | } | |
925 | ||
926 | static acpi_status set_u32(u32 value, u32 cap) | |
927 | { | |
5c742b45 CC |
928 | acpi_status status; |
929 | ||
745a5d21 CC |
930 | if (interface->capability & cap) { |
931 | switch (interface->type) { | |
932 | case ACER_AMW0: | |
933 | return AMW0_set_u32(value, cap, interface); | |
934 | case ACER_AMW0_V2: | |
5c742b45 CC |
935 | if (cap == ACER_CAP_MAILLED) |
936 | return AMW0_set_u32(value, cap, interface); | |
937 | ||
938 | /* | |
939 | * On some models, some WMID methods don't toggle | |
940 | * properly. For those cases, we want to run the AMW0 | |
941 | * method afterwards to be certain we've really toggled | |
942 | * the device state. | |
943 | */ | |
944 | if (cap == ACER_CAP_WIRELESS || | |
945 | cap == ACER_CAP_BLUETOOTH) { | |
946 | status = WMID_set_u32(value, cap, interface); | |
947 | if (ACPI_FAILURE(status)) | |
948 | return status; | |
949 | ||
950 | return AMW0_set_u32(value, cap, interface); | |
951 | } | |
745a5d21 CC |
952 | case ACER_WMID: |
953 | return WMID_set_u32(value, cap, interface); | |
954 | default: | |
955 | return AE_BAD_PARAMETER; | |
956 | } | |
957 | } | |
958 | return AE_BAD_PARAMETER; | |
959 | } | |
960 | ||
961 | static void __init acer_commandline_init(void) | |
962 | { | |
963 | /* | |
964 | * These will all fail silently if the value given is invalid, or the | |
965 | * capability isn't available on the given interface | |
966 | */ | |
967 | set_u32(mailled, ACER_CAP_MAILLED); | |
6c3df88f LCY |
968 | if (!has_type_aa) |
969 | set_u32(threeg, ACER_CAP_THREEG); | |
745a5d21 CC |
970 | set_u32(brightness, ACER_CAP_BRIGHTNESS); |
971 | } | |
972 | ||
973 | /* | |
974 | * LED device (Mail LED only, no other LEDs known yet) | |
975 | */ | |
976 | static void mail_led_set(struct led_classdev *led_cdev, | |
977 | enum led_brightness value) | |
978 | { | |
979 | set_u32(value, ACER_CAP_MAILLED); | |
980 | } | |
981 | ||
982 | static struct led_classdev mail_led = { | |
343c0042 | 983 | .name = "acer-wmi::mail", |
745a5d21 CC |
984 | .brightness_set = mail_led_set, |
985 | }; | |
986 | ||
7560e385 | 987 | static int __devinit acer_led_init(struct device *dev) |
745a5d21 CC |
988 | { |
989 | return led_classdev_register(dev, &mail_led); | |
990 | } | |
991 | ||
992 | static void acer_led_exit(void) | |
993 | { | |
994 | led_classdev_unregister(&mail_led); | |
995 | } | |
996 | ||
997 | /* | |
998 | * Backlight device | |
999 | */ | |
1000 | static struct backlight_device *acer_backlight_device; | |
1001 | ||
1002 | static int read_brightness(struct backlight_device *bd) | |
1003 | { | |
1004 | u32 value; | |
1005 | get_u32(&value, ACER_CAP_BRIGHTNESS); | |
1006 | return value; | |
1007 | } | |
1008 | ||
1009 | static int update_bl_status(struct backlight_device *bd) | |
1010 | { | |
f2b585b4 CC |
1011 | int intensity = bd->props.brightness; |
1012 | ||
1013 | if (bd->props.power != FB_BLANK_UNBLANK) | |
1014 | intensity = 0; | |
1015 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) | |
1016 | intensity = 0; | |
1017 | ||
1018 | set_u32(intensity, ACER_CAP_BRIGHTNESS); | |
1019 | ||
745a5d21 CC |
1020 | return 0; |
1021 | } | |
1022 | ||
acc2472e | 1023 | static const struct backlight_ops acer_bl_ops = { |
745a5d21 CC |
1024 | .get_brightness = read_brightness, |
1025 | .update_status = update_bl_status, | |
1026 | }; | |
1027 | ||
7560e385 | 1028 | static int __devinit acer_backlight_init(struct device *dev) |
745a5d21 | 1029 | { |
a19a6ee6 | 1030 | struct backlight_properties props; |
745a5d21 CC |
1031 | struct backlight_device *bd; |
1032 | ||
a19a6ee6 MG |
1033 | memset(&props, 0, sizeof(struct backlight_properties)); |
1034 | props.max_brightness = max_brightness; | |
1035 | bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops, | |
1036 | &props); | |
745a5d21 CC |
1037 | if (IS_ERR(bd)) { |
1038 | printk(ACER_ERR "Could not register Acer backlight device\n"); | |
1039 | acer_backlight_device = NULL; | |
1040 | return PTR_ERR(bd); | |
1041 | } | |
1042 | ||
1043 | acer_backlight_device = bd; | |
1044 | ||
f2b585b4 | 1045 | bd->props.power = FB_BLANK_UNBLANK; |
6f6ef82c | 1046 | bd->props.brightness = read_brightness(bd); |
745a5d21 CC |
1047 | backlight_update_status(bd); |
1048 | return 0; | |
1049 | } | |
1050 | ||
7560e385 | 1051 | static void acer_backlight_exit(void) |
745a5d21 CC |
1052 | { |
1053 | backlight_device_unregister(acer_backlight_device); | |
1054 | } | |
1055 | ||
b3c9092b LCY |
1056 | static acpi_status wmid3_get_device_status(u32 *value, u16 device) |
1057 | { | |
1058 | struct wmid3_gds_return_value return_value; | |
1059 | acpi_status status; | |
1060 | union acpi_object *obj; | |
1061 | struct wmid3_gds_input_param params = { | |
1062 | .function_num = 0x1, | |
1063 | .hotkey_number = 0x01, | |
1064 | .devices = device, | |
1065 | }; | |
1066 | struct acpi_buffer input = { | |
1067 | sizeof(struct wmid3_gds_input_param), | |
1068 | ¶ms | |
1069 | }; | |
1070 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | |
1071 | ||
1072 | status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output); | |
1073 | if (ACPI_FAILURE(status)) | |
1074 | return status; | |
1075 | ||
1076 | obj = output.pointer; | |
1077 | ||
1078 | if (!obj) | |
1079 | return AE_ERROR; | |
1080 | else if (obj->type != ACPI_TYPE_BUFFER) { | |
1081 | kfree(obj); | |
1082 | return AE_ERROR; | |
1083 | } | |
1084 | if (obj->buffer.length != 8) { | |
1085 | printk(ACER_WARNING "Unknown buffer length %d\n", | |
1086 | obj->buffer.length); | |
1087 | kfree(obj); | |
1088 | return AE_ERROR; | |
1089 | } | |
1090 | ||
1091 | return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); | |
1092 | kfree(obj); | |
1093 | ||
1094 | if (return_value.error_code || return_value.ec_return_value) | |
1095 | printk(ACER_WARNING "Get Device Status failed: " | |
1096 | "0x%x - 0x%x\n", return_value.error_code, | |
1097 | return_value.ec_return_value); | |
1098 | else | |
1099 | *value = !!(return_value.devices & device); | |
1100 | ||
1101 | return status; | |
1102 | } | |
1103 | ||
466449cf LCY |
1104 | static acpi_status get_device_status(u32 *value, u32 cap) |
1105 | { | |
1106 | if (wmi_has_guid(WMID_GUID3)) { | |
1107 | u16 device; | |
1108 | ||
1109 | switch (cap) { | |
1110 | case ACER_CAP_WIRELESS: | |
1111 | device = ACER_WMID3_GDS_WIRELESS; | |
1112 | break; | |
1113 | case ACER_CAP_BLUETOOTH: | |
1114 | device = ACER_WMID3_GDS_BLUETOOTH; | |
1115 | break; | |
1116 | case ACER_CAP_THREEG: | |
1117 | device = ACER_WMID3_GDS_THREEG; | |
1118 | break; | |
1119 | default: | |
1120 | return AE_ERROR; | |
1121 | } | |
1122 | return wmid3_get_device_status(value, device); | |
1123 | ||
1124 | } else { | |
1125 | return get_u32(value, cap); | |
1126 | } | |
1127 | } | |
1128 | ||
0606e1ab CC |
1129 | /* |
1130 | * Rfkill devices | |
1131 | */ | |
0606e1ab CC |
1132 | static void acer_rfkill_update(struct work_struct *ignored); |
1133 | static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update); | |
1134 | static void acer_rfkill_update(struct work_struct *ignored) | |
1135 | { | |
1136 | u32 state; | |
1137 | acpi_status status; | |
1138 | ||
1139 | status = get_u32(&state, ACER_CAP_WIRELESS); | |
1140 | if (ACPI_SUCCESS(status)) | |
a878417c | 1141 | rfkill_set_sw_state(wireless_rfkill, !state); |
0606e1ab CC |
1142 | |
1143 | if (has_cap(ACER_CAP_BLUETOOTH)) { | |
1144 | status = get_u32(&state, ACER_CAP_BLUETOOTH); | |
1145 | if (ACPI_SUCCESS(status)) | |
a878417c | 1146 | rfkill_set_sw_state(bluetooth_rfkill, !state); |
0606e1ab CC |
1147 | } |
1148 | ||
b3c9092b LCY |
1149 | if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) { |
1150 | status = wmid3_get_device_status(&state, | |
1151 | ACER_WMID3_GDS_THREEG); | |
1152 | if (ACPI_SUCCESS(status)) | |
1153 | rfkill_set_sw_state(threeg_rfkill, !state); | |
1154 | } | |
1155 | ||
ae3a1b46 | 1156 | schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); |
0606e1ab CC |
1157 | } |
1158 | ||
19d337df | 1159 | static int acer_rfkill_set(void *data, bool blocked) |
0606e1ab CC |
1160 | { |
1161 | acpi_status status; | |
19d337df | 1162 | u32 cap = (unsigned long)data; |
ed5c8ef3 | 1163 | status = set_u32(!blocked, cap); |
0606e1ab CC |
1164 | if (ACPI_FAILURE(status)) |
1165 | return -ENODEV; | |
1166 | return 0; | |
1167 | } | |
1168 | ||
19d337df JB |
1169 | static const struct rfkill_ops acer_rfkill_ops = { |
1170 | .set_block = acer_rfkill_set, | |
1171 | }; | |
1172 | ||
1173 | static struct rfkill *acer_rfkill_register(struct device *dev, | |
1174 | enum rfkill_type type, | |
1175 | char *name, u32 cap) | |
0606e1ab CC |
1176 | { |
1177 | int err; | |
0606e1ab | 1178 | struct rfkill *rfkill_dev; |
466449cf LCY |
1179 | u32 state; |
1180 | acpi_status status; | |
0606e1ab | 1181 | |
19d337df JB |
1182 | rfkill_dev = rfkill_alloc(name, dev, type, |
1183 | &acer_rfkill_ops, | |
1184 | (void *)(unsigned long)cap); | |
0606e1ab CC |
1185 | if (!rfkill_dev) |
1186 | return ERR_PTR(-ENOMEM); | |
0606e1ab | 1187 | |
466449cf LCY |
1188 | status = get_device_status(&state, cap); |
1189 | if (ACPI_SUCCESS(status)) | |
1190 | rfkill_init_sw_state(rfkill_dev, !state); | |
1191 | ||
0606e1ab CC |
1192 | err = rfkill_register(rfkill_dev); |
1193 | if (err) { | |
19d337df | 1194 | rfkill_destroy(rfkill_dev); |
0606e1ab CC |
1195 | return ERR_PTR(err); |
1196 | } | |
1197 | return rfkill_dev; | |
1198 | } | |
1199 | ||
1200 | static int acer_rfkill_init(struct device *dev) | |
1201 | { | |
1202 | wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN, | |
1203 | "acer-wireless", ACER_CAP_WIRELESS); | |
1204 | if (IS_ERR(wireless_rfkill)) | |
1205 | return PTR_ERR(wireless_rfkill); | |
1206 | ||
1207 | if (has_cap(ACER_CAP_BLUETOOTH)) { | |
1208 | bluetooth_rfkill = acer_rfkill_register(dev, | |
1209 | RFKILL_TYPE_BLUETOOTH, "acer-bluetooth", | |
1210 | ACER_CAP_BLUETOOTH); | |
1211 | if (IS_ERR(bluetooth_rfkill)) { | |
0606e1ab | 1212 | rfkill_unregister(wireless_rfkill); |
19d337df | 1213 | rfkill_destroy(wireless_rfkill); |
0606e1ab CC |
1214 | return PTR_ERR(bluetooth_rfkill); |
1215 | } | |
1216 | } | |
1217 | ||
b3c9092b LCY |
1218 | if (has_cap(ACER_CAP_THREEG)) { |
1219 | threeg_rfkill = acer_rfkill_register(dev, | |
1220 | RFKILL_TYPE_WWAN, "acer-threeg", | |
1221 | ACER_CAP_THREEG); | |
1222 | if (IS_ERR(threeg_rfkill)) { | |
1223 | rfkill_unregister(wireless_rfkill); | |
1224 | rfkill_destroy(wireless_rfkill); | |
1225 | rfkill_unregister(bluetooth_rfkill); | |
1226 | rfkill_destroy(bluetooth_rfkill); | |
1227 | return PTR_ERR(threeg_rfkill); | |
1228 | } | |
1229 | } | |
1230 | ||
ae3a1b46 | 1231 | schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); |
0606e1ab CC |
1232 | |
1233 | return 0; | |
1234 | } | |
1235 | ||
1236 | static void acer_rfkill_exit(void) | |
1237 | { | |
1238 | cancel_delayed_work_sync(&acer_rfkill_work); | |
19d337df | 1239 | |
0606e1ab | 1240 | rfkill_unregister(wireless_rfkill); |
19d337df JB |
1241 | rfkill_destroy(wireless_rfkill); |
1242 | ||
0606e1ab | 1243 | if (has_cap(ACER_CAP_BLUETOOTH)) { |
0606e1ab | 1244 | rfkill_unregister(bluetooth_rfkill); |
19d337df | 1245 | rfkill_destroy(bluetooth_rfkill); |
0606e1ab | 1246 | } |
b3c9092b LCY |
1247 | |
1248 | if (has_cap(ACER_CAP_THREEG)) { | |
1249 | rfkill_unregister(threeg_rfkill); | |
1250 | rfkill_destroy(threeg_rfkill); | |
1251 | } | |
0606e1ab CC |
1252 | return; |
1253 | } | |
1254 | ||
745a5d21 | 1255 | /* |
7d9a06de | 1256 | * sysfs interface |
745a5d21 | 1257 | */ |
7d9a06de CC |
1258 | static ssize_t show_bool_threeg(struct device *dev, |
1259 | struct device_attribute *attr, char *buf) | |
1260 | { | |
745a5d21 | 1261 | u32 result; \ |
b3c9092b LCY |
1262 | acpi_status status; |
1263 | if (wmi_has_guid(WMID_GUID3)) | |
1264 | status = wmid3_get_device_status(&result, | |
1265 | ACER_WMID3_GDS_THREEG); | |
1266 | else | |
1267 | status = get_u32(&result, ACER_CAP_THREEG); | |
7d9a06de CC |
1268 | if (ACPI_SUCCESS(status)) |
1269 | return sprintf(buf, "%u\n", result); | |
1270 | return sprintf(buf, "Read error\n"); | |
1271 | } | |
1272 | ||
1273 | static ssize_t set_bool_threeg(struct device *dev, | |
1274 | struct device_attribute *attr, const char *buf, size_t count) | |
1275 | { | |
1276 | u32 tmp = simple_strtoul(buf, NULL, 10); | |
1277 | acpi_status status = set_u32(tmp, ACER_CAP_THREEG); | |
1278 | if (ACPI_FAILURE(status)) | |
1279 | return -EINVAL; | |
1280 | return count; | |
1281 | } | |
b80b168f | 1282 | static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg, |
7d9a06de | 1283 | set_bool_threeg); |
745a5d21 | 1284 | |
745a5d21 CC |
1285 | static ssize_t show_interface(struct device *dev, struct device_attribute *attr, |
1286 | char *buf) | |
1287 | { | |
1288 | switch (interface->type) { | |
1289 | case ACER_AMW0: | |
1290 | return sprintf(buf, "AMW0\n"); | |
1291 | case ACER_AMW0_V2: | |
1292 | return sprintf(buf, "AMW0 v2\n"); | |
1293 | case ACER_WMID: | |
1294 | return sprintf(buf, "WMID\n"); | |
1295 | default: | |
1296 | return sprintf(buf, "Error!\n"); | |
1297 | } | |
1298 | } | |
1299 | ||
370525df | 1300 | static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL); |
745a5d21 | 1301 | |
3fdca87d LCY |
1302 | static void acer_wmi_notify(u32 value, void *context) |
1303 | { | |
1304 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | |
1305 | union acpi_object *obj; | |
1306 | struct event_return_value return_value; | |
1307 | acpi_status status; | |
1308 | ||
1309 | status = wmi_get_event_data(value, &response); | |
1310 | if (status != AE_OK) { | |
1311 | printk(ACER_WARNING "bad event status 0x%x\n", status); | |
1312 | return; | |
1313 | } | |
1314 | ||
1315 | obj = (union acpi_object *)response.pointer; | |
1316 | ||
1317 | if (!obj) | |
1318 | return; | |
1319 | if (obj->type != ACPI_TYPE_BUFFER) { | |
1320 | printk(ACER_WARNING "Unknown response received %d\n", | |
1321 | obj->type); | |
1322 | kfree(obj); | |
1323 | return; | |
1324 | } | |
1325 | if (obj->buffer.length != 8) { | |
1326 | printk(ACER_WARNING "Unknown buffer length %d\n", | |
1327 | obj->buffer.length); | |
1328 | kfree(obj); | |
1329 | return; | |
1330 | } | |
1331 | ||
1332 | return_value = *((struct event_return_value *)obj->buffer.pointer); | |
1333 | kfree(obj); | |
1334 | ||
1335 | switch (return_value.function) { | |
1336 | case WMID_HOTKEY_EVENT: | |
1337 | if (!sparse_keymap_report_event(acer_wmi_input_dev, | |
1338 | return_value.key_num, 1, true)) | |
1339 | printk(ACER_WARNING "Unknown key number - 0x%x\n", | |
1340 | return_value.key_num); | |
1341 | break; | |
1342 | default: | |
1343 | printk(ACER_WARNING "Unknown function number - %d - %d\n", | |
1344 | return_value.function, return_value.key_num); | |
1345 | break; | |
1346 | } | |
1347 | } | |
1348 | ||
59ccf2f3 FLCY |
1349 | static acpi_status |
1350 | wmid3_set_lm_mode(struct lm_input_params *params, | |
1351 | struct lm_return_value *return_value) | |
1352 | { | |
1353 | acpi_status status; | |
1354 | union acpi_object *obj; | |
1355 | ||
1356 | struct acpi_buffer input = { sizeof(struct lm_input_params), params }; | |
1357 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | |
1358 | ||
1359 | status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output); | |
1360 | if (ACPI_FAILURE(status)) | |
1361 | return status; | |
1362 | ||
1363 | obj = output.pointer; | |
1364 | ||
1365 | if (!obj) | |
1366 | return AE_ERROR; | |
1367 | else if (obj->type != ACPI_TYPE_BUFFER) { | |
1368 | kfree(obj); | |
1369 | return AE_ERROR; | |
1370 | } | |
1371 | if (obj->buffer.length != 4) { | |
1372 | printk(ACER_WARNING "Unknown buffer length %d\n", | |
1373 | obj->buffer.length); | |
1374 | kfree(obj); | |
1375 | return AE_ERROR; | |
1376 | } | |
1377 | ||
1378 | *return_value = *((struct lm_return_value *)obj->buffer.pointer); | |
1379 | kfree(obj); | |
1380 | ||
1381 | return status; | |
1382 | } | |
1383 | ||
1384 | static int acer_wmi_enable_ec_raw(void) | |
1385 | { | |
1386 | struct lm_return_value return_value; | |
1387 | acpi_status status; | |
1388 | struct lm_input_params params = { | |
1389 | .function_num = 0x1, | |
1390 | .commun_devices = 0xFFFF, | |
1391 | .devices = 0xFFFF, | |
1392 | .lm_status = 0x00, /* Launch Manager Deactive */ | |
1393 | }; | |
1394 | ||
1395 | status = wmid3_set_lm_mode(¶ms, &return_value); | |
1396 | ||
1397 | if (return_value.error_code || return_value.ec_return_value) | |
1398 | printk(ACER_WARNING "Enabling EC raw mode failed: " | |
1399 | "0x%x - 0x%x\n", return_value.error_code, | |
1400 | return_value.ec_return_value); | |
1401 | else | |
1402 | printk(ACER_INFO "Enabled EC raw mode"); | |
1403 | ||
1404 | return status; | |
1405 | } | |
1406 | ||
1407 | static int acer_wmi_enable_lm(void) | |
1408 | { | |
1409 | struct lm_return_value return_value; | |
1410 | acpi_status status; | |
1411 | struct lm_input_params params = { | |
1412 | .function_num = 0x1, | |
1413 | .commun_devices = 0xFFFF, | |
1414 | .devices = 0xFFFF, | |
1415 | .lm_status = 0x01, /* Launch Manager Active */ | |
1416 | }; | |
1417 | ||
1418 | status = wmid3_set_lm_mode(¶ms, &return_value); | |
1419 | ||
1420 | if (return_value.error_code || return_value.ec_return_value) | |
1421 | printk(ACER_WARNING "Enabling Launch Manager failed: " | |
1422 | "0x%x - 0x%x\n", return_value.error_code, | |
1423 | return_value.ec_return_value); | |
1424 | ||
1425 | return status; | |
1426 | } | |
1427 | ||
3fdca87d LCY |
1428 | static int __init acer_wmi_input_setup(void) |
1429 | { | |
1430 | acpi_status status; | |
1431 | int err; | |
1432 | ||
1433 | acer_wmi_input_dev = input_allocate_device(); | |
1434 | if (!acer_wmi_input_dev) | |
1435 | return -ENOMEM; | |
1436 | ||
1437 | acer_wmi_input_dev->name = "Acer WMI hotkeys"; | |
1438 | acer_wmi_input_dev->phys = "wmi/input0"; | |
1439 | acer_wmi_input_dev->id.bustype = BUS_HOST; | |
1440 | ||
1441 | err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL); | |
1442 | if (err) | |
1443 | goto err_free_dev; | |
1444 | ||
1445 | status = wmi_install_notify_handler(ACERWMID_EVENT_GUID, | |
1446 | acer_wmi_notify, NULL); | |
1447 | if (ACPI_FAILURE(status)) { | |
1448 | err = -EIO; | |
1449 | goto err_free_keymap; | |
1450 | } | |
1451 | ||
1452 | err = input_register_device(acer_wmi_input_dev); | |
1453 | if (err) | |
1454 | goto err_uninstall_notifier; | |
1455 | ||
1456 | return 0; | |
1457 | ||
1458 | err_uninstall_notifier: | |
1459 | wmi_remove_notify_handler(ACERWMID_EVENT_GUID); | |
1460 | err_free_keymap: | |
1461 | sparse_keymap_free(acer_wmi_input_dev); | |
1462 | err_free_dev: | |
1463 | input_free_device(acer_wmi_input_dev); | |
1464 | return err; | |
1465 | } | |
1466 | ||
1467 | static void acer_wmi_input_destroy(void) | |
1468 | { | |
1469 | wmi_remove_notify_handler(ACERWMID_EVENT_GUID); | |
1470 | sparse_keymap_free(acer_wmi_input_dev); | |
1471 | input_unregister_device(acer_wmi_input_dev); | |
1472 | } | |
1473 | ||
81143522 CC |
1474 | /* |
1475 | * debugfs functions | |
1476 | */ | |
1477 | static u32 get_wmid_devices(void) | |
1478 | { | |
1479 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; | |
1480 | union acpi_object *obj; | |
1481 | acpi_status status; | |
66904863 | 1482 | u32 devices = 0; |
81143522 CC |
1483 | |
1484 | status = wmi_query_block(WMID_GUID2, 1, &out); | |
1485 | if (ACPI_FAILURE(status)) | |
1486 | return 0; | |
1487 | ||
1488 | obj = (union acpi_object *) out.pointer; | |
1489 | if (obj && obj->type == ACPI_TYPE_BUFFER && | |
1490 | obj->buffer.length == sizeof(u32)) { | |
66904863 | 1491 | devices = *((u32 *) obj->buffer.pointer); |
81143522 | 1492 | } |
66904863 AL |
1493 | |
1494 | kfree(out.pointer); | |
1495 | return devices; | |
81143522 CC |
1496 | } |
1497 | ||
745a5d21 CC |
1498 | /* |
1499 | * Platform device | |
1500 | */ | |
1501 | static int __devinit acer_platform_probe(struct platform_device *device) | |
1502 | { | |
1503 | int err; | |
1504 | ||
1505 | if (has_cap(ACER_CAP_MAILLED)) { | |
1506 | err = acer_led_init(&device->dev); | |
1507 | if (err) | |
1508 | goto error_mailled; | |
1509 | } | |
1510 | ||
1511 | if (has_cap(ACER_CAP_BRIGHTNESS)) { | |
1512 | err = acer_backlight_init(&device->dev); | |
1513 | if (err) | |
1514 | goto error_brightness; | |
1515 | } | |
1516 | ||
0606e1ab | 1517 | err = acer_rfkill_init(&device->dev); |
350e3290 AW |
1518 | if (err) |
1519 | goto error_rfkill; | |
0606e1ab CC |
1520 | |
1521 | return err; | |
745a5d21 | 1522 | |
350e3290 AW |
1523 | error_rfkill: |
1524 | if (has_cap(ACER_CAP_BRIGHTNESS)) | |
1525 | acer_backlight_exit(); | |
745a5d21 | 1526 | error_brightness: |
350e3290 AW |
1527 | if (has_cap(ACER_CAP_MAILLED)) |
1528 | acer_led_exit(); | |
745a5d21 CC |
1529 | error_mailled: |
1530 | return err; | |
1531 | } | |
1532 | ||
1533 | static int acer_platform_remove(struct platform_device *device) | |
1534 | { | |
1535 | if (has_cap(ACER_CAP_MAILLED)) | |
1536 | acer_led_exit(); | |
1537 | if (has_cap(ACER_CAP_BRIGHTNESS)) | |
1538 | acer_backlight_exit(); | |
0606e1ab CC |
1539 | |
1540 | acer_rfkill_exit(); | |
745a5d21 CC |
1541 | return 0; |
1542 | } | |
1543 | ||
1544 | static int acer_platform_suspend(struct platform_device *dev, | |
1545 | pm_message_t state) | |
1546 | { | |
1547 | u32 value; | |
1548 | struct acer_data *data = &interface->data; | |
1549 | ||
1550 | if (!data) | |
1551 | return -ENOMEM; | |
1552 | ||
745a5d21 CC |
1553 | if (has_cap(ACER_CAP_MAILLED)) { |
1554 | get_u32(&value, ACER_CAP_MAILLED); | |
1555 | data->mailled = value; | |
1556 | } | |
1557 | ||
1558 | if (has_cap(ACER_CAP_BRIGHTNESS)) { | |
1559 | get_u32(&value, ACER_CAP_BRIGHTNESS); | |
1560 | data->brightness = value; | |
1561 | } | |
1562 | ||
1563 | return 0; | |
1564 | } | |
1565 | ||
1566 | static int acer_platform_resume(struct platform_device *device) | |
1567 | { | |
1568 | struct acer_data *data = &interface->data; | |
1569 | ||
1570 | if (!data) | |
1571 | return -ENOMEM; | |
1572 | ||
745a5d21 CC |
1573 | if (has_cap(ACER_CAP_MAILLED)) |
1574 | set_u32(data->mailled, ACER_CAP_MAILLED); | |
1575 | ||
1576 | if (has_cap(ACER_CAP_BRIGHTNESS)) | |
1577 | set_u32(data->brightness, ACER_CAP_BRIGHTNESS); | |
1578 | ||
1579 | return 0; | |
1580 | } | |
1581 | ||
1582 | static struct platform_driver acer_platform_driver = { | |
1583 | .driver = { | |
1584 | .name = "acer-wmi", | |
1585 | .owner = THIS_MODULE, | |
1586 | }, | |
1587 | .probe = acer_platform_probe, | |
1588 | .remove = acer_platform_remove, | |
1589 | .suspend = acer_platform_suspend, | |
1590 | .resume = acer_platform_resume, | |
1591 | }; | |
1592 | ||
1593 | static struct platform_device *acer_platform_device; | |
1594 | ||
1595 | static int remove_sysfs(struct platform_device *device) | |
1596 | { | |
745a5d21 CC |
1597 | if (has_cap(ACER_CAP_THREEG)) |
1598 | device_remove_file(&device->dev, &dev_attr_threeg); | |
1599 | ||
1600 | device_remove_file(&device->dev, &dev_attr_interface); | |
1601 | ||
1602 | return 0; | |
1603 | } | |
1604 | ||
1605 | static int create_sysfs(void) | |
1606 | { | |
1607 | int retval = -ENOMEM; | |
1608 | ||
745a5d21 CC |
1609 | if (has_cap(ACER_CAP_THREEG)) { |
1610 | retval = device_create_file(&acer_platform_device->dev, | |
1611 | &dev_attr_threeg); | |
1612 | if (retval) | |
1613 | goto error_sysfs; | |
1614 | } | |
1615 | ||
1616 | retval = device_create_file(&acer_platform_device->dev, | |
1617 | &dev_attr_interface); | |
1618 | if (retval) | |
1619 | goto error_sysfs; | |
1620 | ||
1621 | return 0; | |
1622 | ||
1623 | error_sysfs: | |
1624 | remove_sysfs(acer_platform_device); | |
1625 | return retval; | |
1626 | } | |
1627 | ||
81143522 CC |
1628 | static void remove_debugfs(void) |
1629 | { | |
1630 | debugfs_remove(interface->debug.devices); | |
1631 | debugfs_remove(interface->debug.root); | |
1632 | } | |
1633 | ||
1634 | static int create_debugfs(void) | |
1635 | { | |
1636 | interface->debug.root = debugfs_create_dir("acer-wmi", NULL); | |
1637 | if (!interface->debug.root) { | |
1638 | printk(ACER_ERR "Failed to create debugfs directory"); | |
1639 | return -ENOMEM; | |
1640 | } | |
1641 | ||
1642 | interface->debug.devices = debugfs_create_u32("devices", S_IRUGO, | |
1643 | interface->debug.root, | |
1644 | &interface->debug.wmid_devices); | |
1645 | if (!interface->debug.devices) | |
1646 | goto error_debugfs; | |
1647 | ||
1648 | return 0; | |
1649 | ||
1650 | error_debugfs: | |
39dbbb45 | 1651 | remove_debugfs(); |
81143522 CC |
1652 | return -ENOMEM; |
1653 | } | |
1654 | ||
745a5d21 CC |
1655 | static int __init acer_wmi_init(void) |
1656 | { | |
1657 | int err; | |
1658 | ||
860f0c6b | 1659 | printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n"); |
745a5d21 | 1660 | |
a74dd5fd CC |
1661 | if (dmi_check_system(acer_blacklist)) { |
1662 | printk(ACER_INFO "Blacklisted hardware detected - " | |
1663 | "not loading\n"); | |
1664 | return -ENODEV; | |
1665 | } | |
1666 | ||
9991d9f2 CC |
1667 | find_quirks(); |
1668 | ||
745a5d21 CC |
1669 | /* |
1670 | * Detect which ACPI-WMI interface we're using. | |
1671 | */ | |
1672 | if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) | |
1673 | interface = &AMW0_V2_interface; | |
1674 | ||
1675 | if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) | |
1676 | interface = &wmid_interface; | |
1677 | ||
1678 | if (wmi_has_guid(WMID_GUID2) && interface) { | |
1679 | if (ACPI_FAILURE(WMID_set_capabilities())) { | |
8d039bc7 CC |
1680 | printk(ACER_ERR "Unable to detect available WMID " |
1681 | "devices\n"); | |
745a5d21 CC |
1682 | return -ENODEV; |
1683 | } | |
1684 | } else if (!wmi_has_guid(WMID_GUID2) && interface) { | |
8d039bc7 | 1685 | printk(ACER_ERR "No WMID device detection method found\n"); |
745a5d21 CC |
1686 | return -ENODEV; |
1687 | } | |
1688 | ||
1689 | if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) { | |
1690 | interface = &AMW0_interface; | |
1691 | ||
1692 | if (ACPI_FAILURE(AMW0_set_capabilities())) { | |
8d039bc7 CC |
1693 | printk(ACER_ERR "Unable to detect available AMW0 " |
1694 | "devices\n"); | |
745a5d21 CC |
1695 | return -ENODEV; |
1696 | } | |
1697 | } | |
1698 | ||
9b963c40 CC |
1699 | if (wmi_has_guid(AMW0_GUID1)) |
1700 | AMW0_find_mailled(); | |
745a5d21 | 1701 | |
745a5d21 | 1702 | if (!interface) { |
af9902e1 | 1703 | printk(ACER_INFO "No or unsupported WMI interface, unable to " |
8d039bc7 | 1704 | "load\n"); |
745a5d21 CC |
1705 | return -ENODEV; |
1706 | } | |
1707 | ||
83097aca AV |
1708 | set_quirks(); |
1709 | ||
1ba869ec | 1710 | if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) { |
febf2d95 TR |
1711 | interface->capability &= ~ACER_CAP_BRIGHTNESS; |
1712 | printk(ACER_INFO "Brightness must be controlled by " | |
1713 | "generic video driver\n"); | |
1714 | } | |
1715 | ||
59ccf2f3 FLCY |
1716 | if (wmi_has_guid(WMID_GUID3)) { |
1717 | if (ec_raw_mode) { | |
1718 | if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) { | |
1719 | printk(ACER_ERR "Cannot enable EC raw mode\n"); | |
1720 | return -ENODEV; | |
1721 | } | |
1722 | } else if (ACPI_FAILURE(acer_wmi_enable_lm())) { | |
1723 | printk(ACER_ERR "Cannot enable Launch Manager mode\n"); | |
1724 | return -ENODEV; | |
1725 | } | |
1726 | } else if (ec_raw_mode) { | |
1727 | printk(ACER_INFO "No WMID EC raw mode enable method\n"); | |
1728 | } | |
1729 | ||
3fdca87d LCY |
1730 | if (wmi_has_guid(ACERWMID_EVENT_GUID)) { |
1731 | err = acer_wmi_input_setup(); | |
1732 | if (err) | |
1733 | return err; | |
1734 | } | |
1735 | ||
1c79632b AL |
1736 | err = platform_driver_register(&acer_platform_driver); |
1737 | if (err) { | |
745a5d21 CC |
1738 | printk(ACER_ERR "Unable to register platform driver.\n"); |
1739 | goto error_platform_register; | |
1740 | } | |
1c79632b | 1741 | |
745a5d21 | 1742 | acer_platform_device = platform_device_alloc("acer-wmi", -1); |
1c79632b AL |
1743 | if (!acer_platform_device) { |
1744 | err = -ENOMEM; | |
1745 | goto error_device_alloc; | |
1746 | } | |
1747 | ||
1748 | err = platform_device_add(acer_platform_device); | |
1749 | if (err) | |
1750 | goto error_device_add; | |
745a5d21 CC |
1751 | |
1752 | err = create_sysfs(); | |
1753 | if (err) | |
1c79632b | 1754 | goto error_create_sys; |
745a5d21 | 1755 | |
81143522 CC |
1756 | if (wmi_has_guid(WMID_GUID2)) { |
1757 | interface->debug.wmid_devices = get_wmid_devices(); | |
1758 | err = create_debugfs(); | |
1759 | if (err) | |
1c79632b | 1760 | goto error_create_debugfs; |
81143522 CC |
1761 | } |
1762 | ||
745a5d21 CC |
1763 | /* Override any initial settings with values from the commandline */ |
1764 | acer_commandline_init(); | |
1765 | ||
1766 | return 0; | |
1767 | ||
1c79632b AL |
1768 | error_create_debugfs: |
1769 | remove_sysfs(acer_platform_device); | |
1770 | error_create_sys: | |
1771 | platform_device_del(acer_platform_device); | |
1772 | error_device_add: | |
1773 | platform_device_put(acer_platform_device); | |
1774 | error_device_alloc: | |
1775 | platform_driver_unregister(&acer_platform_driver); | |
745a5d21 | 1776 | error_platform_register: |
3fdca87d LCY |
1777 | if (wmi_has_guid(ACERWMID_EVENT_GUID)) |
1778 | acer_wmi_input_destroy(); | |
1779 | ||
1c79632b | 1780 | return err; |
745a5d21 CC |
1781 | } |
1782 | ||
1783 | static void __exit acer_wmi_exit(void) | |
1784 | { | |
3fdca87d LCY |
1785 | if (wmi_has_guid(ACERWMID_EVENT_GUID)) |
1786 | acer_wmi_input_destroy(); | |
1787 | ||
745a5d21 | 1788 | remove_sysfs(acer_platform_device); |
39dbbb45 | 1789 | remove_debugfs(); |
97ba0af0 | 1790 | platform_device_unregister(acer_platform_device); |
745a5d21 CC |
1791 | platform_driver_unregister(&acer_platform_driver); |
1792 | ||
1793 | printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n"); | |
1794 | return; | |
1795 | } | |
1796 | ||
1797 | module_init(acer_wmi_init); | |
1798 | module_exit(acer_wmi_exit); |