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