]>
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; | |
83 | u32 data; | |
84 | }; | |
85 | ||
86 | struct bios_return { | |
87 | u32 sigpass; | |
88 | u32 return_code; | |
89 | u32 value; | |
90 | }; | |
91 | ||
92 | struct key_entry { | |
93 | char type; /* See KE_* below */ | |
a8823aef | 94 | u16 code; |
62ec30d4 MG |
95 | u16 keycode; |
96 | }; | |
97 | ||
871043bc | 98 | enum { KE_KEY, KE_END }; |
62ec30d4 MG |
99 | |
100 | static struct key_entry hp_wmi_keymap[] = { | |
62ec30d4 MG |
101 | {KE_KEY, 0x02, KEY_BRIGHTNESSUP}, |
102 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, | |
a8823aef | 103 | {KE_KEY, 0x20e6, KEY_PROG1}, |
f6b2ff08 | 104 | {KE_KEY, 0x20e8, KEY_MEDIA}, |
a8823aef | 105 | {KE_KEY, 0x2142, KEY_MEDIA}, |
5c624841 | 106 | {KE_KEY, 0x213b, KEY_INFO}, |
caeacf59 | 107 | {KE_KEY, 0x2169, KEY_DIRECTION}, |
a8823aef | 108 | {KE_KEY, 0x231b, KEY_HELP}, |
62ec30d4 MG |
109 | {KE_END, 0} |
110 | }; | |
111 | ||
112 | static struct input_dev *hp_wmi_input_dev; | |
113 | static struct platform_device *hp_wmi_platform_dev; | |
114 | ||
115 | static struct rfkill *wifi_rfkill; | |
116 | static struct rfkill *bluetooth_rfkill; | |
117 | static struct rfkill *wwan_rfkill; | |
118 | ||
47145210 | 119 | static const struct dev_pm_ops hp_wmi_pm_ops = { |
8dd2b426 FP |
120 | .resume = hp_wmi_resume_handler, |
121 | .restore = hp_wmi_resume_handler, | |
122 | }; | |
123 | ||
62ec30d4 MG |
124 | static struct platform_driver hp_wmi_driver = { |
125 | .driver = { | |
8dd2b426 FP |
126 | .name = "hp-wmi", |
127 | .owner = THIS_MODULE, | |
128 | .pm = &hp_wmi_pm_ops, | |
62ec30d4 MG |
129 | }, |
130 | .probe = hp_wmi_bios_setup, | |
131 | .remove = hp_wmi_bios_remove, | |
132 | }; | |
133 | ||
134 | static int hp_wmi_perform_query(int query, int write, int value) | |
135 | { | |
136 | struct bios_return bios_return; | |
137 | acpi_status status; | |
138 | union acpi_object *obj; | |
139 | struct bios_args args = { | |
140 | .signature = 0x55434553, | |
141 | .command = write ? 0x2 : 0x1, | |
142 | .commandtype = query, | |
143 | .datasize = write ? 0x4 : 0, | |
144 | .data = value, | |
145 | }; | |
146 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; | |
147 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | |
148 | ||
149 | status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); | |
150 | ||
151 | obj = output.pointer; | |
152 | ||
44ef00e6 | 153 | if (!obj) |
62ec30d4 | 154 | return -EINVAL; |
44ef00e6 TR |
155 | else if (obj->type != ACPI_TYPE_BUFFER) { |
156 | kfree(obj); | |
157 | return -EINVAL; | |
158 | } | |
62ec30d4 MG |
159 | |
160 | bios_return = *((struct bios_return *)obj->buffer.pointer); | |
44ef00e6 | 161 | kfree(obj); |
62ec30d4 MG |
162 | if (bios_return.return_code > 0) |
163 | return bios_return.return_code * -1; | |
164 | else | |
165 | return bios_return.value; | |
166 | } | |
167 | ||
168 | static int hp_wmi_display_state(void) | |
169 | { | |
170 | return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0); | |
171 | } | |
172 | ||
173 | static int hp_wmi_hddtemp_state(void) | |
174 | { | |
175 | return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0); | |
176 | } | |
177 | ||
178 | static int hp_wmi_als_state(void) | |
179 | { | |
180 | return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0); | |
181 | } | |
182 | ||
183 | static int hp_wmi_dock_state(void) | |
184 | { | |
871043bc | 185 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0); |
62ec30d4 | 186 | |
871043bc MG |
187 | if (ret < 0) |
188 | return ret; | |
189 | ||
190 | return ret & 0x1; | |
62ec30d4 MG |
191 | } |
192 | ||
871043bc | 193 | static int hp_wmi_tablet_state(void) |
62ec30d4 | 194 | { |
871043bc MG |
195 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0); |
196 | ||
197 | if (ret < 0) | |
198 | return ret; | |
199 | ||
200 | return (ret & 0x4) ? 1 : 0; | |
62ec30d4 MG |
201 | } |
202 | ||
19d337df | 203 | static int hp_wmi_set_block(void *data, bool blocked) |
62ec30d4 | 204 | { |
e5fbba85 AJ |
205 | enum hp_wmi_radio r = (enum hp_wmi_radio) data; |
206 | int query = BIT(r + 8) | ((!blocked) << r); | |
62ec30d4 | 207 | |
19d337df | 208 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); |
62ec30d4 MG |
209 | } |
210 | ||
19d337df JB |
211 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
212 | .set_block = hp_wmi_set_block, | |
213 | }; | |
62ec30d4 | 214 | |
e5fbba85 | 215 | static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) |
62ec30d4 MG |
216 | { |
217 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | |
e5fbba85 | 218 | int mask = 0x200 << (r * 8); |
62ec30d4 | 219 | |
e5fbba85 | 220 | if (wireless & mask) |
19d337df | 221 | return false; |
62ec30d4 | 222 | else |
19d337df | 223 | return true; |
62ec30d4 MG |
224 | } |
225 | ||
e5fbba85 | 226 | static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) |
62ec30d4 MG |
227 | { |
228 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); | |
e5fbba85 | 229 | int mask = 0x800 << (r * 8); |
62ec30d4 | 230 | |
e5fbba85 | 231 | if (wireless & mask) |
19d337df | 232 | return false; |
62ec30d4 | 233 | else |
19d337df | 234 | return true; |
62ec30d4 MG |
235 | } |
236 | ||
237 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, | |
238 | char *buf) | |
239 | { | |
240 | int value = hp_wmi_display_state(); | |
241 | if (value < 0) | |
242 | return -EINVAL; | |
243 | return sprintf(buf, "%d\n", value); | |
244 | } | |
245 | ||
246 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, | |
247 | char *buf) | |
248 | { | |
249 | int value = hp_wmi_hddtemp_state(); | |
250 | if (value < 0) | |
251 | return -EINVAL; | |
252 | return sprintf(buf, "%d\n", value); | |
253 | } | |
254 | ||
255 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, | |
256 | char *buf) | |
257 | { | |
258 | int value = hp_wmi_als_state(); | |
259 | if (value < 0) | |
260 | return -EINVAL; | |
261 | return sprintf(buf, "%d\n", value); | |
262 | } | |
263 | ||
264 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, | |
265 | char *buf) | |
266 | { | |
267 | int value = hp_wmi_dock_state(); | |
268 | if (value < 0) | |
269 | return -EINVAL; | |
270 | return sprintf(buf, "%d\n", value); | |
271 | } | |
272 | ||
871043bc MG |
273 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
274 | char *buf) | |
275 | { | |
276 | int value = hp_wmi_tablet_state(); | |
277 | if (value < 0) | |
278 | return -EINVAL; | |
279 | return sprintf(buf, "%d\n", value); | |
280 | } | |
281 | ||
62ec30d4 MG |
282 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
283 | const char *buf, size_t count) | |
284 | { | |
285 | u32 tmp = simple_strtoul(buf, NULL, 10); | |
286 | hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp); | |
287 | return count; | |
288 | } | |
289 | ||
290 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); | |
291 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); | |
292 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); | |
293 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); | |
871043bc | 294 | static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); |
62ec30d4 | 295 | |
58b93995 | 296 | static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code) |
62ec30d4 MG |
297 | { |
298 | struct key_entry *key; | |
299 | ||
300 | for (key = hp_wmi_keymap; key->type != KE_END; key++) | |
301 | if (code == key->code) | |
302 | return key; | |
303 | ||
304 | return NULL; | |
305 | } | |
306 | ||
58b93995 | 307 | static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode) |
62ec30d4 MG |
308 | { |
309 | struct key_entry *key; | |
310 | ||
311 | for (key = hp_wmi_keymap; key->type != KE_END; key++) | |
312 | if (key->type == KE_KEY && keycode == key->keycode) | |
313 | return key; | |
314 | ||
315 | return NULL; | |
316 | } | |
317 | ||
58b93995 DT |
318 | static int hp_wmi_getkeycode(struct input_dev *dev, |
319 | unsigned int scancode, unsigned int *keycode) | |
62ec30d4 MG |
320 | { |
321 | struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode); | |
322 | ||
323 | if (key && key->type == KE_KEY) { | |
324 | *keycode = key->keycode; | |
325 | return 0; | |
326 | } | |
327 | ||
328 | return -EINVAL; | |
329 | } | |
330 | ||
58b93995 DT |
331 | static int hp_wmi_setkeycode(struct input_dev *dev, |
332 | unsigned int scancode, unsigned int keycode) | |
62ec30d4 MG |
333 | { |
334 | struct key_entry *key; | |
58b93995 | 335 | unsigned int old_keycode; |
62ec30d4 MG |
336 | |
337 | key = hp_wmi_get_entry_by_scancode(scancode); | |
338 | if (key && key->type == KE_KEY) { | |
339 | old_keycode = key->keycode; | |
340 | key->keycode = keycode; | |
341 | set_bit(keycode, dev->keybit); | |
342 | if (!hp_wmi_get_entry_by_keycode(old_keycode)) | |
343 | clear_bit(old_keycode, dev->keybit); | |
344 | return 0; | |
345 | } | |
346 | ||
347 | return -EINVAL; | |
348 | } | |
349 | ||
88429a10 | 350 | static void hp_wmi_notify(u32 value, void *context) |
62ec30d4 MG |
351 | { |
352 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | |
353 | static struct key_entry *key; | |
354 | union acpi_object *obj; | |
8dda6b04 TR |
355 | u32 event_id, event_data; |
356 | int key_code; | |
357 | u32 *location; | |
fda11e61 | 358 | acpi_status status; |
62ec30d4 | 359 | |
fda11e61 LB |
360 | status = wmi_get_event_data(value, &response); |
361 | if (status != AE_OK) { | |
a2806c6f | 362 | printk(KERN_INFO PREFIX "bad event status 0x%x\n", status); |
fda11e61 LB |
363 | return; |
364 | } | |
62ec30d4 MG |
365 | |
366 | obj = (union acpi_object *)response.pointer; | |
367 | ||
8dda6b04 TR |
368 | if (obj || obj->type != ACPI_TYPE_BUFFER) { |
369 | printk(KERN_INFO "hp-wmi: Unknown response received %d\n", | |
370 | obj->type); | |
44ef00e6 | 371 | kfree(obj); |
e5fbba85 AJ |
372 | return; |
373 | } | |
374 | ||
8dda6b04 TR |
375 | /* |
376 | * Depending on ACPI version the concatenation of id and event data | |
377 | * inside _WED function will result in a 8 or 16 byte buffer. | |
378 | */ | |
379 | location = (u32 *)obj->buffer.pointer; | |
380 | if (obj->buffer.length == 8) { | |
381 | event_id = *location; | |
382 | event_data = *(location + 1); | |
383 | } else if (obj->buffer.length == 16) { | |
384 | event_id = *location; | |
385 | event_data = *(location + 2); | |
386 | } else { | |
387 | printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n", | |
388 | obj->buffer.length); | |
389 | kfree(obj); | |
390 | return; | |
391 | } | |
44ef00e6 | 392 | kfree(obj); |
8dda6b04 TR |
393 | |
394 | switch (event_id) { | |
751ae808 | 395 | case HPWMI_DOCK_EVENT: |
e5fbba85 AJ |
396 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
397 | hp_wmi_dock_state()); | |
398 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | |
399 | hp_wmi_tablet_state()); | |
400 | input_sync(hp_wmi_input_dev); | |
751ae808 | 401 | break; |
1bbdfd59 TR |
402 | case HPWMI_PARK_HDD: |
403 | break; | |
404 | case HPWMI_SMART_ADAPTER: | |
405 | break; | |
751ae808 TR |
406 | case HPWMI_BEZEL_BUTTON: |
407 | key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, | |
408 | 0); | |
409 | key = hp_wmi_get_entry_by_scancode(key_code); | |
410 | if (key) { | |
411 | switch (key->type) { | |
412 | case KE_KEY: | |
413 | input_report_key(hp_wmi_input_dev, | |
414 | key->keycode, 1); | |
415 | input_sync(hp_wmi_input_dev); | |
416 | input_report_key(hp_wmi_input_dev, | |
417 | key->keycode, 0); | |
418 | input_sync(hp_wmi_input_dev); | |
419 | break; | |
420 | } | |
da9a79ba | 421 | } else |
a2806c6f | 422 | printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n", |
da9a79ba | 423 | key_code); |
751ae808 TR |
424 | break; |
425 | case HPWMI_WIRELESS: | |
e5fbba85 AJ |
426 | if (wifi_rfkill) |
427 | rfkill_set_states(wifi_rfkill, | |
428 | hp_wmi_get_sw_state(HPWMI_WIFI), | |
429 | hp_wmi_get_hw_state(HPWMI_WIFI)); | |
430 | if (bluetooth_rfkill) | |
431 | rfkill_set_states(bluetooth_rfkill, | |
432 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), | |
433 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); | |
434 | if (wwan_rfkill) | |
435 | rfkill_set_states(wwan_rfkill, | |
436 | hp_wmi_get_sw_state(HPWMI_WWAN), | |
437 | hp_wmi_get_hw_state(HPWMI_WWAN)); | |
751ae808 | 438 | break; |
1bbdfd59 TR |
439 | case HPWMI_CPU_BATTERY_THROTTLE: |
440 | printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell" | |
441 | " battery event detected\n"); | |
442 | break; | |
443 | case HPWMI_LOCK_SWITCH: | |
444 | break; | |
751ae808 | 445 | default: |
8dda6b04 TR |
446 | printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n", |
447 | event_id, event_data); | |
751ae808 TR |
448 | break; |
449 | } | |
62ec30d4 MG |
450 | } |
451 | ||
452 | static int __init hp_wmi_input_setup(void) | |
453 | { | |
454 | struct key_entry *key; | |
455 | int err; | |
456 | ||
457 | hp_wmi_input_dev = input_allocate_device(); | |
458 | ||
459 | hp_wmi_input_dev->name = "HP WMI hotkeys"; | |
460 | hp_wmi_input_dev->phys = "wmi/input0"; | |
461 | hp_wmi_input_dev->id.bustype = BUS_HOST; | |
462 | hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode; | |
463 | hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode; | |
464 | ||
465 | for (key = hp_wmi_keymap; key->type != KE_END; key++) { | |
466 | switch (key->type) { | |
467 | case KE_KEY: | |
468 | set_bit(EV_KEY, hp_wmi_input_dev->evbit); | |
469 | set_bit(key->keycode, hp_wmi_input_dev->keybit); | |
470 | break; | |
62ec30d4 MG |
471 | } |
472 | } | |
473 | ||
871043bc MG |
474 | set_bit(EV_SW, hp_wmi_input_dev->evbit); |
475 | set_bit(SW_DOCK, hp_wmi_input_dev->swbit); | |
476 | set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); | |
477 | ||
478 | /* Set initial hardware state */ | |
479 | input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); | |
480 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | |
481 | hp_wmi_tablet_state()); | |
482 | input_sync(hp_wmi_input_dev); | |
483 | ||
62ec30d4 MG |
484 | err = input_register_device(hp_wmi_input_dev); |
485 | ||
486 | if (err) { | |
487 | input_free_device(hp_wmi_input_dev); | |
488 | return err; | |
489 | } | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | static void cleanup_sysfs(struct platform_device *device) | |
495 | { | |
496 | device_remove_file(&device->dev, &dev_attr_display); | |
497 | device_remove_file(&device->dev, &dev_attr_hddtemp); | |
498 | device_remove_file(&device->dev, &dev_attr_als); | |
499 | device_remove_file(&device->dev, &dev_attr_dock); | |
871043bc | 500 | device_remove_file(&device->dev, &dev_attr_tablet); |
62ec30d4 MG |
501 | } |
502 | ||
ea79632d | 503 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) |
62ec30d4 MG |
504 | { |
505 | int err; | |
3f6e2f13 | 506 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
62ec30d4 MG |
507 | |
508 | err = device_create_file(&device->dev, &dev_attr_display); | |
509 | if (err) | |
510 | goto add_sysfs_error; | |
511 | err = device_create_file(&device->dev, &dev_attr_hddtemp); | |
512 | if (err) | |
513 | goto add_sysfs_error; | |
514 | err = device_create_file(&device->dev, &dev_attr_als); | |
515 | if (err) | |
516 | goto add_sysfs_error; | |
517 | err = device_create_file(&device->dev, &dev_attr_dock); | |
871043bc MG |
518 | if (err) |
519 | goto add_sysfs_error; | |
520 | err = device_create_file(&device->dev, &dev_attr_tablet); | |
62ec30d4 MG |
521 | if (err) |
522 | goto add_sysfs_error; | |
523 | ||
3f6e2f13 | 524 | if (wireless & 0x1) { |
19d337df JB |
525 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
526 | RFKILL_TYPE_WLAN, | |
527 | &hp_wmi_rfkill_ops, | |
e5fbba85 AJ |
528 | (void *) HPWMI_WIFI); |
529 | rfkill_init_sw_state(wifi_rfkill, | |
530 | hp_wmi_get_sw_state(HPWMI_WIFI)); | |
531 | rfkill_set_hw_state(wifi_rfkill, | |
532 | hp_wmi_get_hw_state(HPWMI_WIFI)); | |
fe8e4e03 LF |
533 | err = rfkill_register(wifi_rfkill); |
534 | if (err) | |
19d337df | 535 | goto register_wifi_error; |
3f6e2f13 MG |
536 | } |
537 | ||
538 | if (wireless & 0x2) { | |
19d337df JB |
539 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
540 | RFKILL_TYPE_BLUETOOTH, | |
541 | &hp_wmi_rfkill_ops, | |
e5fbba85 AJ |
542 | (void *) HPWMI_BLUETOOTH); |
543 | rfkill_init_sw_state(bluetooth_rfkill, | |
544 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); | |
545 | rfkill_set_hw_state(bluetooth_rfkill, | |
546 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); | |
fe8e4e03 | 547 | err = rfkill_register(bluetooth_rfkill); |
6989d565 | 548 | if (err) |
fe8e4e03 | 549 | goto register_bluetooth_error; |
3f6e2f13 MG |
550 | } |
551 | ||
552 | if (wireless & 0x4) { | |
19d337df JB |
553 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
554 | RFKILL_TYPE_WWAN, | |
555 | &hp_wmi_rfkill_ops, | |
e5fbba85 AJ |
556 | (void *) HPWMI_WWAN); |
557 | rfkill_init_sw_state(wwan_rfkill, | |
558 | hp_wmi_get_sw_state(HPWMI_WWAN)); | |
559 | rfkill_set_hw_state(wwan_rfkill, | |
560 | hp_wmi_get_hw_state(HPWMI_WWAN)); | |
fe8e4e03 LF |
561 | err = rfkill_register(wwan_rfkill); |
562 | if (err) | |
563 | goto register_wwan_err; | |
3f6e2f13 | 564 | } |
62ec30d4 MG |
565 | |
566 | return 0; | |
fe8e4e03 | 567 | register_wwan_err: |
19d337df | 568 | rfkill_destroy(wwan_rfkill); |
44f0606d AM |
569 | if (bluetooth_rfkill) |
570 | rfkill_unregister(bluetooth_rfkill); | |
fe8e4e03 | 571 | register_bluetooth_error: |
19d337df | 572 | rfkill_destroy(bluetooth_rfkill); |
44f0606d AM |
573 | if (wifi_rfkill) |
574 | rfkill_unregister(wifi_rfkill); | |
19d337df JB |
575 | register_wifi_error: |
576 | rfkill_destroy(wifi_rfkill); | |
62ec30d4 MG |
577 | add_sysfs_error: |
578 | cleanup_sysfs(device); | |
579 | return err; | |
580 | } | |
581 | ||
582 | static int __exit hp_wmi_bios_remove(struct platform_device *device) | |
583 | { | |
584 | cleanup_sysfs(device); | |
585 | ||
19d337df | 586 | if (wifi_rfkill) { |
3f6e2f13 | 587 | rfkill_unregister(wifi_rfkill); |
19d337df JB |
588 | rfkill_destroy(wifi_rfkill); |
589 | } | |
590 | if (bluetooth_rfkill) { | |
3f6e2f13 | 591 | rfkill_unregister(bluetooth_rfkill); |
09729f0b | 592 | rfkill_destroy(bluetooth_rfkill); |
19d337df JB |
593 | } |
594 | if (wwan_rfkill) { | |
3f6e2f13 | 595 | rfkill_unregister(wwan_rfkill); |
19d337df JB |
596 | rfkill_destroy(wwan_rfkill); |
597 | } | |
62ec30d4 MG |
598 | |
599 | return 0; | |
600 | } | |
601 | ||
8dd2b426 | 602 | static int hp_wmi_resume_handler(struct device *device) |
4c395bdd | 603 | { |
4c395bdd | 604 | /* |
871043bc MG |
605 | * Hardware state may have changed while suspended, so trigger |
606 | * input events for the current state. As this is a switch, | |
4c395bdd FP |
607 | * the input layer will only actually pass it on if the state |
608 | * changed. | |
609 | */ | |
daed9537 FP |
610 | if (hp_wmi_input_dev) { |
611 | input_report_switch(hp_wmi_input_dev, SW_DOCK, | |
612 | hp_wmi_dock_state()); | |
613 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, | |
614 | hp_wmi_tablet_state()); | |
615 | input_sync(hp_wmi_input_dev); | |
616 | } | |
4c395bdd | 617 | |
e5fbba85 AJ |
618 | if (wifi_rfkill) |
619 | rfkill_set_states(wifi_rfkill, | |
620 | hp_wmi_get_sw_state(HPWMI_WIFI), | |
621 | hp_wmi_get_hw_state(HPWMI_WIFI)); | |
622 | if (bluetooth_rfkill) | |
623 | rfkill_set_states(bluetooth_rfkill, | |
624 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), | |
625 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); | |
626 | if (wwan_rfkill) | |
627 | rfkill_set_states(wwan_rfkill, | |
628 | hp_wmi_get_sw_state(HPWMI_WWAN), | |
629 | hp_wmi_get_hw_state(HPWMI_WWAN)); | |
630 | ||
4c395bdd FP |
631 | return 0; |
632 | } | |
633 | ||
62ec30d4 MG |
634 | static int __init hp_wmi_init(void) |
635 | { | |
636 | int err; | |
637 | ||
638 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { | |
639 | err = wmi_install_notify_handler(HPWMI_EVENT_GUID, | |
640 | hp_wmi_notify, NULL); | |
f2772575 | 641 | if (ACPI_SUCCESS(err)) |
62ec30d4 MG |
642 | hp_wmi_input_setup(); |
643 | } | |
644 | ||
645 | if (wmi_has_guid(HPWMI_BIOS_GUID)) { | |
646 | err = platform_driver_register(&hp_wmi_driver); | |
647 | if (err) | |
648 | return 0; | |
649 | hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); | |
650 | if (!hp_wmi_platform_dev) { | |
651 | platform_driver_unregister(&hp_wmi_driver); | |
652 | return 0; | |
653 | } | |
654 | platform_device_add(hp_wmi_platform_dev); | |
655 | } | |
656 | ||
657 | return 0; | |
658 | } | |
659 | ||
660 | static void __exit hp_wmi_exit(void) | |
661 | { | |
662 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { | |
663 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); | |
664 | input_unregister_device(hp_wmi_input_dev); | |
665 | } | |
666 | if (hp_wmi_platform_dev) { | |
667 | platform_device_del(hp_wmi_platform_dev); | |
668 | platform_driver_unregister(&hp_wmi_driver); | |
669 | } | |
670 | } | |
671 | ||
672 | module_init(hp_wmi_init); | |
673 | module_exit(hp_wmi_exit); |