Commit | Line | Data |
---|---|---|
62ec30d4 MG |
1 | /* |
2 | * HP WMI hotkeys | |
3 | * | |
4 | * Copyright (C) 2008 Red Hat <mjg@redhat.com> | |
5 | * | |
6 | * Portions based on wistron_btns.c: | |
7 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> | |
8 | * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> | |
9 | * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | */ | |
25 | ||
26 | #include <linux/kernel.h> | |
27 | #include <linux/module.h> | |
28 | #include <linux/init.h> | |
5a0e3ad6 | 29 | #include <linux/slab.h> |
62ec30d4 MG |
30 | #include <linux/types.h> |
31 | #include <linux/input.h> | |
62ec30d4 MG |
32 | #include <linux/platform_device.h> |
33 | #include <linux/acpi.h> | |
34 | #include <linux/rfkill.h> | |
35 | #include <linux/string.h> | |
36 | ||
37 | MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>"); | |
38 | MODULE_DESCRIPTION("HP laptop WMI hotkeys driver"); | |
39 | MODULE_LICENSE("GPL"); | |
40 | ||
41 | MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C"); | |
42 | MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); | |
43 | ||
44 | #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C" | |
45 | #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4" | |
46 | ||
47 | #define HPWMI_DISPLAY_QUERY 0x1 | |
48 | #define HPWMI_HDDTEMP_QUERY 0x2 | |
49 | #define HPWMI_ALS_QUERY 0x3 | |
871043bc | 50 | #define HPWMI_HARDWARE_QUERY 0x4 |
62ec30d4 | 51 | #define HPWMI_WIRELESS_QUERY 0x5 |
a8823aef | 52 | #define HPWMI_HOTKEY_QUERY 0xc |
62ec30d4 | 53 | |
a2806c6f | 54 | #define PREFIX "HP WMI: " |
1bbdfd59 | 55 | #define UNIMP "Unimplemented " |
a2806c6f | 56 | |
e5fbba85 AJ |
57 | enum hp_wmi_radio { |
58 | HPWMI_WIFI = 0, | |
59 | HPWMI_BLUETOOTH = 1, | |
60 | HPWMI_WWAN = 2, | |
61 | }; | |
62 | ||
751ae808 TR |
63 | enum hp_wmi_event_ids { |
64 | HPWMI_DOCK_EVENT = 1, | |
1bbdfd59 TR |
65 | HPWMI_PARK_HDD = 2, |
66 | HPWMI_SMART_ADAPTER = 3, | |
751ae808 TR |
67 | HPWMI_BEZEL_BUTTON = 4, |
68 | HPWMI_WIRELESS = 5, | |
1bbdfd59 TR |
69 | HPWMI_CPU_BATTERY_THROTTLE = 6, |
70 | HPWMI_LOCK_SWITCH = 7, | |
751ae808 TR |
71 | }; |
72 | ||
ea79632d | 73 | static int __devinit hp_wmi_bios_setup(struct platform_device *device); |
62ec30d4 | 74 | static int __exit hp_wmi_bios_remove(struct platform_device *device); |
8dd2b426 | 75 | static int hp_wmi_resume_handler(struct device *device); |
62ec30d4 MG |
76 | |
77 | struct bios_args { | |
78 | u32 signature; | |
79 | u32 command; | |
80 | u32 commandtype; | |
81 | u32 datasize; | |
6d96e00c | 82 | char *data; |
62ec30d4 MG |
83 | }; |
84 | ||
85 | struct bios_return { | |
86 | u32 sigpass; | |
87 | u32 return_code; | |
62ec30d4 MG |
88 | }; |
89 | ||
90 | struct key_entry { | |
91 | char type; /* See KE_* below */ | |
a8823aef | 92 | u16 code; |
62ec30d4 MG |
93 | u16 keycode; |
94 | }; | |
95 | ||
871043bc | 96 | enum { KE_KEY, KE_END }; |
62ec30d4 MG |
97 | |
98 | static struct key_entry hp_wmi_keymap[] = { | |
62ec30d4 MG |
99 | {KE_KEY, 0x02, KEY_BRIGHTNESSUP}, |
100 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, | |
a8823aef | 101 | {KE_KEY, 0x20e6, KEY_PROG1}, |
f6b2ff08 | 102 | {KE_KEY, 0x20e8, KEY_MEDIA}, |
a8823aef | 103 | {KE_KEY, 0x2142, KEY_MEDIA}, |
5c624841 | 104 | {KE_KEY, 0x213b, KEY_INFO}, |
caeacf59 | 105 | {KE_KEY, 0x2169, KEY_DIRECTION}, |
a8823aef | 106 | {KE_KEY, 0x231b, KEY_HELP}, |
62ec30d4 MG |
107 | {KE_END, 0} |
108 | }; | |
109 | ||
110 | static struct input_dev *hp_wmi_input_dev; | |
111 | static struct platform_device *hp_wmi_platform_dev; | |
112 | ||
113 | static struct rfkill *wifi_rfkill; | |
114 | static struct rfkill *bluetooth_rfkill; | |
115 | static struct rfkill *wwan_rfkill; | |
116 | ||
47145210 | 117 | static const struct dev_pm_ops hp_wmi_pm_ops = { |
8dd2b426 FP |
118 | .resume = hp_wmi_resume_handler, |
119 | .restore = hp_wmi_resume_handler, | |
120 | }; | |
121 | ||
62ec30d4 MG |
122 | static struct platform_driver hp_wmi_driver = { |
123 | .driver = { | |
8dd2b426 FP |
124 | .name = "hp-wmi", |
125 | .owner = THIS_MODULE, | |
126 | .pm = &hp_wmi_pm_ops, | |
62ec30d4 MG |
127 | }, |
128 | .probe = hp_wmi_bios_setup, | |
129 | .remove = hp_wmi_bios_remove, | |
130 | }; | |
131 | ||
6d96e00c TR |
132 | /* |
133 | * hp_wmi_perform_query | |
134 | * | |
135 | * query: The commandtype -> What should be queried | |
136 | * write: The command -> 0 read, 1 write, 3 ODM specific | |
137 | * buffer: Buffer used as input and/or output | |
138 | * buffersize: Size of buffer | |
139 | * | |
140 | * returns zero on success | |
141 | * an HP WMI query specific error code (which is positive) | |
142 | * -EINVAL if the query was not successful at all | |
143 | * -EINVAL if the output buffer size exceeds buffersize | |
144 | * | |
145 | * Note: The buffersize must at least be the maximum of the input and output | |
146 | * size. E.g. Battery info query (0x7) is defined to have 1 byte input | |
147 | * and 128 byte output. The caller would do: | |
148 | * buffer = kzalloc(128, GFP_KERNEL); | |
149 | * ret = hp_wmi_perform_query(0x7, 0, buffer, 128) | |
150 | */ | |
151 | static int hp_wmi_perform_query(int query, int write, char *buffer, | |
152 | int buffersize) | |
62ec30d4 MG |
153 | { |
154 | struct bios_return bios_return; | |
155 | acpi_status status; | |
156 | union acpi_object *obj; | |
157 | struct bios_args args = { | |
158 | .signature = 0x55434553, | |
159 | .command = write ? 0x2 : 0x1, | |
160 | .commandtype = query, | |
6d96e00c TR |
161 | .datasize = buffersize, |
162 | .data = buffer, | |
62ec30d4 MG |
163 | }; |
164 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; | |
165 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | |
166 | ||
167 | status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); | |
168 | ||
169 | obj = output.pointer; | |
170 | ||
44ef00e6 | 171 | if (!obj) |
62ec30d4 | 172 | return -EINVAL; |
44ef00e6 TR |
173 | else if (obj->type != ACPI_TYPE_BUFFER) { |
174 | kfree(obj); | |
175 | return -EINVAL; | |
176 | } | |
62ec30d4 MG |
177 | |
178 | bios_return = *((struct bios_return *)obj->buffer.pointer); | |
6d96e00c TR |
179 | |
180 | if (bios_return.return_code) { | |
181 | printk(KERN_WARNING PREFIX "Query %d returned %d\n", query, | |
182 | bios_return.return_code); | |
183 | kfree(obj); | |
184 | return bios_return.return_code; | |
185 | } | |
186 | if (obj->buffer.length - sizeof(bios_return) > buffersize) { | |
187 | kfree(obj); | |
188 | return -EINVAL; | |
189 | } | |
190 | ||
191 | memset(buffer, 0, buffersize); | |
192 | memcpy(buffer, | |
193 | ((char *)obj->buffer.pointer) + sizeof(struct bios_return), | |
194 | obj->buffer.length - sizeof(bios_return)); | |
44ef00e6 | 195 | kfree(obj); |
6d96e00c | 196 | return 0; |
62ec30d4 MG |
197 | } |
198 | ||
199 | static int hp_wmi_display_state(void) | |
200 | { | |
6d96e00c TR |
201 | int state; |
202 | int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, (char *)&state, | |
203 | sizeof(state)); | |
204 | if (ret) | |
205 | return -EINVAL; | |
206 | return state; | |
62ec30d4 MG |
207 | } |
208 | ||
209 | static int hp_wmi_hddtemp_state(void) | |
210 | { | |
6d96e00c TR |
211 | int state; |
212 | int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, (char *)&state, | |
213 | sizeof(state)); | |
214 | if (ret) | |
215 | return -EINVAL; | |
216 | return state; | |
62ec30d4 MG |
217 | } |
218 | ||
219 | static int hp_wmi_als_state(void) | |
220 | { | |
6d96e00c TR |
221 | int state; |
222 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, (char *)&state, | |
223 | sizeof(state)); | |
224 | if (ret) | |
225 | return -EINVAL; | |
226 | return state; | |
62ec30d4 MG |
227 | } |
228 | ||
229 | static int hp_wmi_dock_state(void) | |
230 | { | |
6d96e00c TR |
231 | int state; |
232 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, (char *)&state, | |
233 | sizeof(state)); | |
62ec30d4 | 234 | |
6d96e00c TR |
235 | if (ret) |
236 | return -EINVAL; | |
871043bc | 237 | |
6d96e00c | 238 | return state & 0x1; |
62ec30d4 MG |
239 | } |
240 | ||
871043bc | 241 | static int hp_wmi_tablet_state(void) |
62ec30d4 | 242 | { |
6d96e00c TR |
243 | int state; |
244 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, (char *)&state, | |
245 | sizeof(state)); | |
246 | if (ret) | |
871043bc MG |
247 | return ret; |
248 | ||
6d96e00c | 249 | return (state & 0x4) ? 1 : 0; |
62ec30d4 MG |
250 | } |
251 | ||
19d337df | 252 | static int hp_wmi_set_block(void *data, bool blocked) |
62ec30d4 | 253 | { |
e5fbba85 AJ |
254 | enum hp_wmi_radio r = (enum hp_wmi_radio) data; |
255 | int query = BIT(r + 8) | ((!blocked) << r); | |
6d96e00c | 256 | int ret; |
62ec30d4 | 257 | |
6d96e00c TR |
258 | ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, |
259 | (char *)&query, sizeof(query)); | |
260 | if (ret) | |
261 | return -EINVAL; | |
262 | return 0; | |
62ec30d4 MG |
263 | } |
264 | ||
19d337df JB |
265 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
266 | .set_block = hp_wmi_set_block, | |
267 | }; | |
62ec30d4 | 268 | |
e5fbba85 | 269 | static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) |
62ec30d4 | 270 | { |
6d96e00c TR |
271 | int wireless; |
272 | int mask; | |
273 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, | |
274 | (char *)&wireless, sizeof(wireless)); | |
275 | /* TBD: Pass error */ | |
276 | ||
277 | mask = 0x200 << (r * 8); | |
62ec30d4 | 278 | |
e5fbba85 | 279 | if (wireless & mask) |
19d337df | 280 | return false; |
62ec30d4 | 281 | else |
19d337df | 282 | return true; |
62ec30d4 MG |
283 | } |
284 | ||
e5fbba85 | 285 | static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) |
62ec30d4 | 286 | { |
6d96e00c TR |
287 | int wireless; |
288 | int mask; | |
289 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, | |
290 | (char *)&wireless, sizeof(wireless)); | |
291 | /* TBD: Pass error */ | |
292 | ||
293 | mask = 0x800 << (r * 8); | |
62ec30d4 | 294 | |
e5fbba85 | 295 | if (wireless & mask) |
19d337df | 296 | return false; |
62ec30d4 | 297 | else |
19d337df | 298 | return true; |
62ec30d4 MG |
299 | } |
300 | ||
301 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, | |
302 | char *buf) | |
303 | { | |
304 | int value = hp_wmi_display_state(); | |
305 | if (value < 0) | |
306 | return -EINVAL; | |
307 | return sprintf(buf, "%d\n", value); | |
308 | } | |
309 | ||
310 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, | |
311 | char *buf) | |
312 | { | |
313 | int value = hp_wmi_hddtemp_state(); | |
314 | if (value < 0) | |
315 | return -EINVAL; | |
316 | return sprintf(buf, "%d\n", value); | |
317 | } | |
318 | ||
319 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, | |
320 | char *buf) | |
321 | { | |
322 | int value = hp_wmi_als_state(); | |
323 | if (value < 0) | |
324 | return -EINVAL; | |
325 | return sprintf(buf, "%d\n", value); | |
326 | } | |
327 | ||
328 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, | |
329 | char *buf) | |
330 | { | |
331 | int value = hp_wmi_dock_state(); | |
332 | if (value < 0) | |
333 | return -EINVAL; | |
334 | return sprintf(buf, "%d\n", value); | |
335 | } | |
336 | ||
871043bc MG |
337 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
338 | char *buf) | |
339 | { | |
340 | int value = hp_wmi_tablet_state(); | |
341 | if (value < 0) | |
342 | return -EINVAL; | |
343 | return sprintf(buf, "%d\n", value); | |
344 | } | |
345 | ||
62ec30d4 MG |
346 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
347 | const char *buf, size_t count) | |
348 | { | |
349 | u32 tmp = simple_strtoul(buf, NULL, 10); | |
6d96e00c TR |
350 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, (char *)&tmp, |
351 | sizeof(tmp)); | |
352 | if (ret) | |
353 | return -EINVAL; | |
354 | ||
62ec30d4 MG |
355 | return count; |
356 | } | |
357 | ||
358 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); | |
359 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); | |
360 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); | |
361 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); | |
871043bc | 362 | static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); |
62ec30d4 | 363 | |
58b93995 | 364 | static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code) |
62ec30d4 MG |
365 | { |
366 | struct key_entry *key; | |
367 | ||
368 | for (key = hp_wmi_keymap; key->type != KE_END; key++) | |
369 | if (code == key->code) | |
370 | return key; | |
371 | ||
372 | return NULL; | |
373 | } | |
374 | ||
58b93995 | 375 | static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode) |
62ec30d4 MG |
376 | { |
377 | struct key_entry *key; | |
378 | ||
379 | for (key = hp_wmi_keymap; key->type != KE_END; key++) | |
380 | if (key->type == KE_KEY && keycode == key->keycode) | |
381 | return key; | |
382 | ||
383 | return NULL; | |
384 | } | |
385 | ||
58b93995 DT |
386 | static int hp_wmi_getkeycode(struct input_dev *dev, |
387 | unsigned int scancode, unsigned int *keycode) | |
62ec30d4 MG |
388 | { |
389 | struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode); | |
390 | ||
391 | if (key && key->type == KE_KEY) { | |
392 | *keycode = key->keycode; | |
393 | return 0; | |
394 | } | |
395 | ||
396 | return -EINVAL; | |
397 | } | |
398 | ||
58b93995 DT |
399 | static int hp_wmi_setkeycode(struct input_dev *dev, |
400 | unsigned int scancode, unsigned int keycode) | |
62ec30d4 MG |
401 | { |
402 | struct key_entry *key; | |
58b93995 | 403 | unsigned int old_keycode; |
62ec30d4 MG |
404 | |
405 | key = hp_wmi_get_entry_by_scancode(scancode); | |
406 | if (key && key->type == KE_KEY) { | |
407 | old_keycode = key->keycode; | |
408 | key->keycode = keycode; | |
409 | set_bit(keycode, dev->keybit); | |
410 | if (!hp_wmi_get_entry_by_keycode(old_keycode)) | |
411 | clear_bit(old_keycode, dev->keybit); | |
412 | return 0; | |
413 | } | |
414 | ||
415 | return -EINVAL; | |
416 | } | |
417 | ||
88429a10 | 418 | static void hp_wmi_notify(u32 value, void *context) |
62ec30d4 MG |
419 | { |
420 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | |
421 | static struct key_entry *key; | |
422 | union acpi_object *obj; | |
8dda6b04 | 423 | u32 event_id, event_data; |
6d96e00c | 424 | int key_code, ret; |
8dda6b04 | 425 | u32 *location; |
fda11e61 | 426 | acpi_status status; |
62ec30d4 | 427 | |
fda11e61 LB |
428 | status = wmi_get_event_data(value, &response); |
429 | if (status != AE_OK) { | |
a2806c6f | 430 | printk(KERN_INFO PREFIX "bad event status 0x%x\n", status); |
fda11e61 LB |
431 | return; |
432 | } | |
62ec30d4 MG |
433 | |
434 | obj = (union acpi_object *)response.pointer; | |
435 | ||
c4775062 TR |
436 | if (!obj) |
437 | return; | |
438 | if (obj->type != ACPI_TYPE_BUFFER) { | |
8dda6b04 TR |
439 | printk(KERN_INFO "hp-wmi: Unknown response received %d\n", |
440 | obj->type); | |
44ef00e6 | 441 | kfree(obj); |
e5fbba85 AJ |
442 | return; |
443 | } | |
444 | ||
8dda6b04 TR |
445 | /* |
446 | * Depending on ACPI version the concatenation of id and event data | |
447 | * inside _WED function will result in a 8 or 16 byte buffer. | |
448 | */ | |
449 | location = (u32 *)obj->buffer.pointer; | |
450 | if (obj->buffer.length == 8) { | |
451 | event_id = *location; | |
452 | event_data = *(location + 1); | |
453 | } else if (obj->buffer.length == 16) { | |
454 | event_id = *location; | |
455 | event_data = *(location + 2); | |
456 | } else { | |
457 | printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n", | |
458 | obj->buffer.length); | |
459 | kfree(obj); | |
460 | return; | |
461 | } | |
44ef00e6 | 462 | kfree(obj); |
8dda6b04 TR |
463 | |
464 | switch (event_id) { | |
751ae808 | 465 | case HPWMI_DOCK_EVENT: |
e5fbba85 AJ |
466 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
467 | hp_wmi_dock_state()); | |
468 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | |
469 | hp_wmi_tablet_state()); | |
470 | input_sync(hp_wmi_input_dev); | |
751ae808 | 471 | break; |
1bbdfd59 TR |
472 | case HPWMI_PARK_HDD: |
473 | break; | |
474 | case HPWMI_SMART_ADAPTER: | |
475 | break; | |
751ae808 | 476 | case HPWMI_BEZEL_BUTTON: |
6d96e00c TR |
477 | ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
478 | (char *)&key_code, | |
479 | sizeof(key_code)); | |
480 | if (ret) | |
481 | break; | |
751ae808 TR |
482 | key = hp_wmi_get_entry_by_scancode(key_code); |
483 | if (key) { | |
484 | switch (key->type) { | |
485 | case KE_KEY: | |
486 | input_report_key(hp_wmi_input_dev, | |
487 | key->keycode, 1); | |
488 | input_sync(hp_wmi_input_dev); | |
489 | input_report_key(hp_wmi_input_dev, | |
490 | key->keycode, 0); | |
491 | input_sync(hp_wmi_input_dev); | |
492 | break; | |
493 | } | |
da9a79ba | 494 | } else |
a2806c6f | 495 | printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n", |
da9a79ba | 496 | key_code); |
751ae808 TR |
497 | break; |
498 | case HPWMI_WIRELESS: | |
e5fbba85 AJ |
499 | if (wifi_rfkill) |
500 | rfkill_set_states(wifi_rfkill, | |
501 | hp_wmi_get_sw_state(HPWMI_WIFI), | |
502 | hp_wmi_get_hw_state(HPWMI_WIFI)); | |
503 | if (bluetooth_rfkill) | |
504 | rfkill_set_states(bluetooth_rfkill, | |
505 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), | |
506 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); | |
507 | if (wwan_rfkill) | |
508 | rfkill_set_states(wwan_rfkill, | |
509 | hp_wmi_get_sw_state(HPWMI_WWAN), | |
510 | hp_wmi_get_hw_state(HPWMI_WWAN)); | |
751ae808 | 511 | break; |
1bbdfd59 TR |
512 | case HPWMI_CPU_BATTERY_THROTTLE: |
513 | printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell" | |
514 | " battery event detected\n"); | |
515 | break; | |
516 | case HPWMI_LOCK_SWITCH: | |
517 | break; | |
751ae808 | 518 | default: |
8dda6b04 TR |
519 | printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n", |
520 | event_id, event_data); | |
751ae808 TR |
521 | break; |
522 | } | |
62ec30d4 MG |
523 | } |
524 | ||
525 | static int __init hp_wmi_input_setup(void) | |
526 | { | |
527 | struct key_entry *key; | |
528 | int err; | |
529 | ||
530 | hp_wmi_input_dev = input_allocate_device(); | |
bc28596a AL |
531 | if (!hp_wmi_input_dev) |
532 | return -ENOMEM; | |
62ec30d4 MG |
533 | |
534 | hp_wmi_input_dev->name = "HP WMI hotkeys"; | |
535 | hp_wmi_input_dev->phys = "wmi/input0"; | |
536 | hp_wmi_input_dev->id.bustype = BUS_HOST; | |
537 | hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode; | |
538 | hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode; | |
539 | ||
540 | for (key = hp_wmi_keymap; key->type != KE_END; key++) { | |
541 | switch (key->type) { | |
542 | case KE_KEY: | |
543 | set_bit(EV_KEY, hp_wmi_input_dev->evbit); | |
544 | set_bit(key->keycode, hp_wmi_input_dev->keybit); | |
545 | break; | |
62ec30d4 MG |
546 | } |
547 | } | |
548 | ||
871043bc MG |
549 | set_bit(EV_SW, hp_wmi_input_dev->evbit); |
550 | set_bit(SW_DOCK, hp_wmi_input_dev->swbit); | |
551 | set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); | |
552 | ||
553 | /* Set initial hardware state */ | |
554 | input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); | |
555 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | |
556 | hp_wmi_tablet_state()); | |
557 | input_sync(hp_wmi_input_dev); | |
558 | ||
62ec30d4 MG |
559 | err = input_register_device(hp_wmi_input_dev); |
560 | ||
561 | if (err) { | |
562 | input_free_device(hp_wmi_input_dev); | |
563 | return err; | |
564 | } | |
565 | ||
566 | return 0; | |
567 | } | |
568 | ||
569 | static void cleanup_sysfs(struct platform_device *device) | |
570 | { | |
571 | device_remove_file(&device->dev, &dev_attr_display); | |
572 | device_remove_file(&device->dev, &dev_attr_hddtemp); | |
573 | device_remove_file(&device->dev, &dev_attr_als); | |
574 | device_remove_file(&device->dev, &dev_attr_dock); | |
871043bc | 575 | device_remove_file(&device->dev, &dev_attr_tablet); |
62ec30d4 MG |
576 | } |
577 | ||
ea79632d | 578 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) |
62ec30d4 MG |
579 | { |
580 | int err; | |
6d96e00c TR |
581 | int wireless; |
582 | ||
583 | err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, (char *)&wireless, | |
584 | sizeof(wireless)); | |
585 | if (err) | |
586 | return err; | |
62ec30d4 MG |
587 | |
588 | err = device_create_file(&device->dev, &dev_attr_display); | |
589 | if (err) | |
590 | goto add_sysfs_error; | |
591 | err = device_create_file(&device->dev, &dev_attr_hddtemp); | |
592 | if (err) | |
593 | goto add_sysfs_error; | |
594 | err = device_create_file(&device->dev, &dev_attr_als); | |
595 | if (err) | |
596 | goto add_sysfs_error; | |
597 | err = device_create_file(&device->dev, &dev_attr_dock); | |
871043bc MG |
598 | if (err) |
599 | goto add_sysfs_error; | |
600 | err = device_create_file(&device->dev, &dev_attr_tablet); | |
62ec30d4 MG |
601 | if (err) |
602 | goto add_sysfs_error; | |
603 | ||
3f6e2f13 | 604 | if (wireless & 0x1) { |
19d337df JB |
605 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
606 | RFKILL_TYPE_WLAN, | |
607 | &hp_wmi_rfkill_ops, | |
e5fbba85 AJ |
608 | (void *) HPWMI_WIFI); |
609 | rfkill_init_sw_state(wifi_rfkill, | |
610 | hp_wmi_get_sw_state(HPWMI_WIFI)); | |
611 | rfkill_set_hw_state(wifi_rfkill, | |
612 | hp_wmi_get_hw_state(HPWMI_WIFI)); | |
fe8e4e03 LF |
613 | err = rfkill_register(wifi_rfkill); |
614 | if (err) | |
19d337df | 615 | goto register_wifi_error; |
3f6e2f13 MG |
616 | } |
617 | ||
618 | if (wireless & 0x2) { | |
19d337df JB |
619 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
620 | RFKILL_TYPE_BLUETOOTH, | |
621 | &hp_wmi_rfkill_ops, | |
e5fbba85 AJ |
622 | (void *) HPWMI_BLUETOOTH); |
623 | rfkill_init_sw_state(bluetooth_rfkill, | |
624 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); | |
625 | rfkill_set_hw_state(bluetooth_rfkill, | |
626 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); | |
fe8e4e03 | 627 | err = rfkill_register(bluetooth_rfkill); |
6989d565 | 628 | if (err) |
fe8e4e03 | 629 | goto register_bluetooth_error; |
3f6e2f13 MG |
630 | } |
631 | ||
632 | if (wireless & 0x4) { | |
19d337df JB |
633 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
634 | RFKILL_TYPE_WWAN, | |
635 | &hp_wmi_rfkill_ops, | |
e5fbba85 AJ |
636 | (void *) HPWMI_WWAN); |
637 | rfkill_init_sw_state(wwan_rfkill, | |
638 | hp_wmi_get_sw_state(HPWMI_WWAN)); | |
639 | rfkill_set_hw_state(wwan_rfkill, | |
640 | hp_wmi_get_hw_state(HPWMI_WWAN)); | |
fe8e4e03 LF |
641 | err = rfkill_register(wwan_rfkill); |
642 | if (err) | |
643 | goto register_wwan_err; | |
3f6e2f13 | 644 | } |
62ec30d4 MG |
645 | |
646 | return 0; | |
fe8e4e03 | 647 | register_wwan_err: |
19d337df | 648 | rfkill_destroy(wwan_rfkill); |
44f0606d AM |
649 | if (bluetooth_rfkill) |
650 | rfkill_unregister(bluetooth_rfkill); | |
fe8e4e03 | 651 | register_bluetooth_error: |
19d337df | 652 | rfkill_destroy(bluetooth_rfkill); |
44f0606d AM |
653 | if (wifi_rfkill) |
654 | rfkill_unregister(wifi_rfkill); | |
19d337df JB |
655 | register_wifi_error: |
656 | rfkill_destroy(wifi_rfkill); | |
62ec30d4 MG |
657 | add_sysfs_error: |
658 | cleanup_sysfs(device); | |
659 | return err; | |
660 | } | |
661 | ||
662 | static int __exit hp_wmi_bios_remove(struct platform_device *device) | |
663 | { | |
664 | cleanup_sysfs(device); | |
665 | ||
19d337df | 666 | if (wifi_rfkill) { |
3f6e2f13 | 667 | rfkill_unregister(wifi_rfkill); |
19d337df JB |
668 | rfkill_destroy(wifi_rfkill); |
669 | } | |
670 | if (bluetooth_rfkill) { | |
3f6e2f13 | 671 | rfkill_unregister(bluetooth_rfkill); |
09729f0b | 672 | rfkill_destroy(bluetooth_rfkill); |
19d337df JB |
673 | } |
674 | if (wwan_rfkill) { | |
3f6e2f13 | 675 | rfkill_unregister(wwan_rfkill); |
19d337df JB |
676 | rfkill_destroy(wwan_rfkill); |
677 | } | |
62ec30d4 MG |
678 | |
679 | return 0; | |
680 | } | |
681 | ||
8dd2b426 | 682 | static int hp_wmi_resume_handler(struct device *device) |
4c395bdd | 683 | { |
4c395bdd | 684 | /* |
871043bc MG |
685 | * Hardware state may have changed while suspended, so trigger |
686 | * input events for the current state. As this is a switch, | |
4c395bdd FP |
687 | * the input layer will only actually pass it on if the state |
688 | * changed. | |
689 | */ | |
daed9537 FP |
690 | if (hp_wmi_input_dev) { |
691 | input_report_switch(hp_wmi_input_dev, SW_DOCK, | |
692 | hp_wmi_dock_state()); | |
693 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | |
694 | hp_wmi_tablet_state()); | |
695 | input_sync(hp_wmi_input_dev); | |
696 | } | |
4c395bdd | 697 | |
e5fbba85 AJ |
698 | if (wifi_rfkill) |
699 | rfkill_set_states(wifi_rfkill, | |
700 | hp_wmi_get_sw_state(HPWMI_WIFI), | |
701 | hp_wmi_get_hw_state(HPWMI_WIFI)); | |
702 | if (bluetooth_rfkill) | |
703 | rfkill_set_states(bluetooth_rfkill, | |
704 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), | |
705 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); | |
706 | if (wwan_rfkill) | |
707 | rfkill_set_states(wwan_rfkill, | |
708 | hp_wmi_get_sw_state(HPWMI_WWAN), | |
709 | hp_wmi_get_hw_state(HPWMI_WWAN)); | |
710 | ||
4c395bdd FP |
711 | return 0; |
712 | } | |
713 | ||
62ec30d4 MG |
714 | static int __init hp_wmi_init(void) |
715 | { | |
716 | int err; | |
b096667b TR |
717 | int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); |
718 | int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); | |
62ec30d4 | 719 | |
b096667b | 720 | if (event_capable) { |
62ec30d4 MG |
721 | err = wmi_install_notify_handler(HPWMI_EVENT_GUID, |
722 | hp_wmi_notify, NULL); | |
dfec5c48 AL |
723 | if (ACPI_FAILURE(err)) |
724 | return -EINVAL; | |
725 | err = hp_wmi_input_setup(); | |
726 | if (err) { | |
727 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); | |
728 | return err; | |
729 | } | |
62ec30d4 MG |
730 | } |
731 | ||
b096667b | 732 | if (bios_capable) { |
62ec30d4 MG |
733 | err = platform_driver_register(&hp_wmi_driver); |
734 | if (err) | |
dfec5c48 | 735 | goto err_driver_reg; |
62ec30d4 MG |
736 | hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); |
737 | if (!hp_wmi_platform_dev) { | |
dfec5c48 AL |
738 | err = -ENOMEM; |
739 | goto err_device_alloc; | |
62ec30d4 | 740 | } |
dfec5c48 AL |
741 | err = platform_device_add(hp_wmi_platform_dev); |
742 | if (err) | |
743 | goto err_device_add; | |
62ec30d4 MG |
744 | } |
745 | ||
b096667b TR |
746 | if (!bios_capable && !event_capable) |
747 | return -ENODEV; | |
748 | ||
62ec30d4 | 749 | return 0; |
dfec5c48 AL |
750 | |
751 | err_device_add: | |
752 | platform_device_put(hp_wmi_platform_dev); | |
753 | err_device_alloc: | |
754 | platform_driver_unregister(&hp_wmi_driver); | |
755 | err_driver_reg: | |
756 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { | |
757 | input_unregister_device(hp_wmi_input_dev); | |
758 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); | |
759 | } | |
760 | ||
761 | return err; | |
62ec30d4 MG |
762 | } |
763 | ||
764 | static void __exit hp_wmi_exit(void) | |
765 | { | |
766 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { | |
767 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); | |
768 | input_unregister_device(hp_wmi_input_dev); | |
769 | } | |
770 | if (hp_wmi_platform_dev) { | |
97ba0af0 | 771 | platform_device_unregister(hp_wmi_platform_dev); |
62ec30d4 MG |
772 | platform_driver_unregister(&hp_wmi_driver); |
773 | } | |
774 | } | |
775 | ||
776 | module_init(hp_wmi_init); | |
777 | module_exit(hp_wmi_exit); |