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