hp-wmi: make rfkill initialization failure non-fatal
[deliverable/linux.git] / drivers / platform / x86 / hp-wmi.c
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>
29 #include <linux/slab.h>
30 #include <linux/types.h>
31 #include <linux/input.h>
32 #include <linux/input/sparse-keymap.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
51 #define HPWMI_HARDWARE_QUERY 0x4
52 #define HPWMI_WIRELESS_QUERY 0x5
53 #define HPWMI_HOTKEY_QUERY 0xc
54
55 #define PREFIX "HP WMI: "
56 #define UNIMP "Unimplemented "
57
58 enum hp_wmi_radio {
59 HPWMI_WIFI = 0,
60 HPWMI_BLUETOOTH = 1,
61 HPWMI_WWAN = 2,
62 };
63
64 enum hp_wmi_event_ids {
65 HPWMI_DOCK_EVENT = 1,
66 HPWMI_PARK_HDD = 2,
67 HPWMI_SMART_ADAPTER = 3,
68 HPWMI_BEZEL_BUTTON = 4,
69 HPWMI_WIRELESS = 5,
70 HPWMI_CPU_BATTERY_THROTTLE = 6,
71 HPWMI_LOCK_SWITCH = 7,
72 };
73
74 static int __devinit hp_wmi_bios_setup(struct platform_device *device);
75 static int __exit hp_wmi_bios_remove(struct platform_device *device);
76 static int hp_wmi_resume_handler(struct device *device);
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 };
90
91 enum hp_return_value {
92 HPWMI_RET_WRONG_SIGNATURE = 0x02,
93 HPWMI_RET_UNKNOWN_COMMAND = 0x03,
94 HPWMI_RET_UNKNOWN_CMDTYPE = 0x04,
95 HPWMI_RET_INVALID_PARAMETERS = 0x05,
96 };
97
98 static const struct key_entry hp_wmi_keymap[] = {
99 { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } },
100 { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } },
101 { KE_KEY, 0x20e6, { KEY_PROG1 } },
102 { KE_KEY, 0x20e8, { KEY_MEDIA } },
103 { KE_KEY, 0x2142, { KEY_MEDIA } },
104 { KE_KEY, 0x213b, { KEY_INFO } },
105 { KE_KEY, 0x2169, { KEY_DIRECTION } },
106 { KE_KEY, 0x231b, { KEY_HELP } },
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
117 static const struct dev_pm_ops hp_wmi_pm_ops = {
118 .resume = hp_wmi_resume_handler,
119 .restore = hp_wmi_resume_handler,
120 };
121
122 static struct platform_driver hp_wmi_driver = {
123 .driver = {
124 .name = "hp-wmi",
125 .owner = THIS_MODULE,
126 .pm = &hp_wmi_pm_ops,
127 },
128 .probe = hp_wmi_bios_setup,
129 .remove = hp_wmi_bios_remove,
130 };
131
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 * insize: Size of input buffer
139 * outsize: Size of output 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, 1, 128)
151 */
152 static int hp_wmi_perform_query(int query, int write, void *buffer,
153 int insize, int outsize)
154 {
155 struct bios_return *bios_return;
156 int actual_outsize;
157 union acpi_object *obj;
158 struct bios_args args = {
159 .signature = 0x55434553,
160 .command = write ? 0x2 : 0x1,
161 .commandtype = query,
162 .datasize = insize,
163 .data = 0,
164 };
165 struct acpi_buffer input = { sizeof(struct bios_args), &args };
166 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
167
168 if (WARN_ON(insize > sizeof(args.data)))
169 return -EINVAL;
170 memcpy(&args.data, buffer, insize);
171
172 wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
173
174 obj = output.pointer;
175
176 if (!obj)
177 return -EINVAL;
178 else if (obj->type != ACPI_TYPE_BUFFER) {
179 kfree(obj);
180 return -EINVAL;
181 }
182
183 bios_return = (struct bios_return *)obj->buffer.pointer;
184
185 if (bios_return->return_code) {
186 if (bios_return->return_code != HPWMI_RET_UNKNOWN_CMDTYPE)
187 printk(KERN_WARNING PREFIX "query 0x%x returned "
188 "error 0x%x\n",
189 query, bios_return->return_code);
190 kfree(obj);
191 return bios_return->return_code;
192 }
193
194 if (!outsize) {
195 /* ignore output data */
196 kfree(obj);
197 return 0;
198 }
199
200 actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return)));
201 memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize);
202 memset(buffer + actual_outsize, 0, outsize - actual_outsize);
203 kfree(obj);
204 return 0;
205 }
206
207 static int hp_wmi_display_state(void)
208 {
209 int state = 0;
210 int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state,
211 sizeof(state), sizeof(state));
212 if (ret)
213 return -EINVAL;
214 return state;
215 }
216
217 static int hp_wmi_hddtemp_state(void)
218 {
219 int state = 0;
220 int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state,
221 sizeof(state), sizeof(state));
222 if (ret)
223 return -EINVAL;
224 return state;
225 }
226
227 static int hp_wmi_als_state(void)
228 {
229 int state = 0;
230 int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state,
231 sizeof(state), sizeof(state));
232 if (ret)
233 return -EINVAL;
234 return state;
235 }
236
237 static int hp_wmi_dock_state(void)
238 {
239 int state = 0;
240 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
241 sizeof(state), sizeof(state));
242
243 if (ret)
244 return -EINVAL;
245
246 return state & 0x1;
247 }
248
249 static int hp_wmi_tablet_state(void)
250 {
251 int state = 0;
252 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
253 sizeof(state), sizeof(state));
254 if (ret)
255 return ret;
256
257 return (state & 0x4) ? 1 : 0;
258 }
259
260 static int hp_wmi_set_block(void *data, bool blocked)
261 {
262 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
263 int query = BIT(r + 8) | ((!blocked) << r);
264 int ret;
265
266 ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1,
267 &query, sizeof(query), 0);
268 if (ret)
269 return -EINVAL;
270 return 0;
271 }
272
273 static const struct rfkill_ops hp_wmi_rfkill_ops = {
274 .set_block = hp_wmi_set_block,
275 };
276
277 static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
278 {
279 int wireless = 0;
280 int mask;
281 hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0,
282 &wireless, sizeof(wireless),
283 sizeof(wireless));
284 /* TBD: Pass error */
285
286 mask = 0x200 << (r * 8);
287
288 if (wireless & mask)
289 return false;
290 else
291 return true;
292 }
293
294 static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
295 {
296 int wireless = 0;
297 int mask;
298 hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0,
299 &wireless, sizeof(wireless),
300 sizeof(wireless));
301 /* TBD: Pass error */
302
303 mask = 0x800 << (r * 8);
304
305 if (wireless & mask)
306 return false;
307 else
308 return true;
309 }
310
311 static ssize_t show_display(struct device *dev, struct device_attribute *attr,
312 char *buf)
313 {
314 int value = hp_wmi_display_state();
315 if (value < 0)
316 return -EINVAL;
317 return sprintf(buf, "%d\n", value);
318 }
319
320 static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
321 char *buf)
322 {
323 int value = hp_wmi_hddtemp_state();
324 if (value < 0)
325 return -EINVAL;
326 return sprintf(buf, "%d\n", value);
327 }
328
329 static ssize_t show_als(struct device *dev, struct device_attribute *attr,
330 char *buf)
331 {
332 int value = hp_wmi_als_state();
333 if (value < 0)
334 return -EINVAL;
335 return sprintf(buf, "%d\n", value);
336 }
337
338 static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
339 char *buf)
340 {
341 int value = hp_wmi_dock_state();
342 if (value < 0)
343 return -EINVAL;
344 return sprintf(buf, "%d\n", value);
345 }
346
347 static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
348 char *buf)
349 {
350 int value = hp_wmi_tablet_state();
351 if (value < 0)
352 return -EINVAL;
353 return sprintf(buf, "%d\n", value);
354 }
355
356 static ssize_t set_als(struct device *dev, struct device_attribute *attr,
357 const char *buf, size_t count)
358 {
359 u32 tmp = simple_strtoul(buf, NULL, 10);
360 int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp,
361 sizeof(tmp), sizeof(tmp));
362 if (ret)
363 return -EINVAL;
364
365 return count;
366 }
367
368 static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
369 static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
370 static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
371 static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
372 static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
373
374 static void hp_wmi_notify(u32 value, void *context)
375 {
376 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
377 union acpi_object *obj;
378 u32 event_id, event_data;
379 int key_code = 0, ret;
380 u32 *location;
381 acpi_status status;
382
383 status = wmi_get_event_data(value, &response);
384 if (status != AE_OK) {
385 printk(KERN_INFO PREFIX "bad event status 0x%x\n", status);
386 return;
387 }
388
389 obj = (union acpi_object *)response.pointer;
390
391 if (!obj)
392 return;
393 if (obj->type != ACPI_TYPE_BUFFER) {
394 printk(KERN_INFO "hp-wmi: Unknown response received %d\n",
395 obj->type);
396 kfree(obj);
397 return;
398 }
399
400 /*
401 * Depending on ACPI version the concatenation of id and event data
402 * inside _WED function will result in a 8 or 16 byte buffer.
403 */
404 location = (u32 *)obj->buffer.pointer;
405 if (obj->buffer.length == 8) {
406 event_id = *location;
407 event_data = *(location + 1);
408 } else if (obj->buffer.length == 16) {
409 event_id = *location;
410 event_data = *(location + 2);
411 } else {
412 printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n",
413 obj->buffer.length);
414 kfree(obj);
415 return;
416 }
417 kfree(obj);
418
419 switch (event_id) {
420 case HPWMI_DOCK_EVENT:
421 input_report_switch(hp_wmi_input_dev, SW_DOCK,
422 hp_wmi_dock_state());
423 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
424 hp_wmi_tablet_state());
425 input_sync(hp_wmi_input_dev);
426 break;
427 case HPWMI_PARK_HDD:
428 break;
429 case HPWMI_SMART_ADAPTER:
430 break;
431 case HPWMI_BEZEL_BUTTON:
432 ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
433 &key_code,
434 sizeof(key_code),
435 sizeof(key_code));
436 if (ret)
437 break;
438
439 if (!sparse_keymap_report_event(hp_wmi_input_dev,
440 key_code, 1, true))
441 printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n",
442 key_code);
443 break;
444 case HPWMI_WIRELESS:
445 if (wifi_rfkill)
446 rfkill_set_states(wifi_rfkill,
447 hp_wmi_get_sw_state(HPWMI_WIFI),
448 hp_wmi_get_hw_state(HPWMI_WIFI));
449 if (bluetooth_rfkill)
450 rfkill_set_states(bluetooth_rfkill,
451 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
452 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
453 if (wwan_rfkill)
454 rfkill_set_states(wwan_rfkill,
455 hp_wmi_get_sw_state(HPWMI_WWAN),
456 hp_wmi_get_hw_state(HPWMI_WWAN));
457 break;
458 case HPWMI_CPU_BATTERY_THROTTLE:
459 printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell"
460 " battery event detected\n");
461 break;
462 case HPWMI_LOCK_SWITCH:
463 break;
464 default:
465 printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n",
466 event_id, event_data);
467 break;
468 }
469 }
470
471 static int __init hp_wmi_input_setup(void)
472 {
473 acpi_status status;
474 int err;
475
476 hp_wmi_input_dev = input_allocate_device();
477 if (!hp_wmi_input_dev)
478 return -ENOMEM;
479
480 hp_wmi_input_dev->name = "HP WMI hotkeys";
481 hp_wmi_input_dev->phys = "wmi/input0";
482 hp_wmi_input_dev->id.bustype = BUS_HOST;
483
484 __set_bit(EV_SW, hp_wmi_input_dev->evbit);
485 __set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
486 __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
487
488 err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
489 if (err)
490 goto err_free_dev;
491
492 /* Set initial hardware state */
493 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
494 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
495 hp_wmi_tablet_state());
496 input_sync(hp_wmi_input_dev);
497
498 status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
499 if (ACPI_FAILURE(status)) {
500 err = -EIO;
501 goto err_free_keymap;
502 }
503
504 err = input_register_device(hp_wmi_input_dev);
505 if (err)
506 goto err_uninstall_notifier;
507
508 return 0;
509
510 err_uninstall_notifier:
511 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
512 err_free_keymap:
513 sparse_keymap_free(hp_wmi_input_dev);
514 err_free_dev:
515 input_free_device(hp_wmi_input_dev);
516 return err;
517 }
518
519 static void hp_wmi_input_destroy(void)
520 {
521 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
522 sparse_keymap_free(hp_wmi_input_dev);
523 input_unregister_device(hp_wmi_input_dev);
524 }
525
526 static void cleanup_sysfs(struct platform_device *device)
527 {
528 device_remove_file(&device->dev, &dev_attr_display);
529 device_remove_file(&device->dev, &dev_attr_hddtemp);
530 device_remove_file(&device->dev, &dev_attr_als);
531 device_remove_file(&device->dev, &dev_attr_dock);
532 device_remove_file(&device->dev, &dev_attr_tablet);
533 }
534
535 static int __devinit hp_wmi_rfkill_setup(struct platform_device *device)
536 {
537 int err;
538 int wireless = 0;
539
540 err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless,
541 sizeof(wireless), sizeof(wireless));
542 if (err)
543 return err;
544
545 if (wireless & 0x1) {
546 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
547 RFKILL_TYPE_WLAN,
548 &hp_wmi_rfkill_ops,
549 (void *) HPWMI_WIFI);
550 rfkill_init_sw_state(wifi_rfkill,
551 hp_wmi_get_sw_state(HPWMI_WIFI));
552 rfkill_set_hw_state(wifi_rfkill,
553 hp_wmi_get_hw_state(HPWMI_WIFI));
554 err = rfkill_register(wifi_rfkill);
555 if (err)
556 goto register_wifi_error;
557 }
558
559 if (wireless & 0x2) {
560 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
561 RFKILL_TYPE_BLUETOOTH,
562 &hp_wmi_rfkill_ops,
563 (void *) HPWMI_BLUETOOTH);
564 rfkill_init_sw_state(bluetooth_rfkill,
565 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
566 rfkill_set_hw_state(bluetooth_rfkill,
567 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
568 err = rfkill_register(bluetooth_rfkill);
569 if (err)
570 goto register_bluetooth_error;
571 }
572
573 if (wireless & 0x4) {
574 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
575 RFKILL_TYPE_WWAN,
576 &hp_wmi_rfkill_ops,
577 (void *) HPWMI_WWAN);
578 rfkill_init_sw_state(wwan_rfkill,
579 hp_wmi_get_sw_state(HPWMI_WWAN));
580 rfkill_set_hw_state(wwan_rfkill,
581 hp_wmi_get_hw_state(HPWMI_WWAN));
582 err = rfkill_register(wwan_rfkill);
583 if (err)
584 goto register_wwan_err;
585 }
586
587 return 0;
588 register_wwan_err:
589 rfkill_destroy(wwan_rfkill);
590 wwan_rfkill = NULL;
591 if (bluetooth_rfkill)
592 rfkill_unregister(bluetooth_rfkill);
593 register_bluetooth_error:
594 rfkill_destroy(bluetooth_rfkill);
595 bluetooth_rfkill = NULL;
596 if (wifi_rfkill)
597 rfkill_unregister(wifi_rfkill);
598 register_wifi_error:
599 rfkill_destroy(wifi_rfkill);
600 wifi_rfkill = NULL;
601 return err;
602 }
603
604 static int __devinit hp_wmi_bios_setup(struct platform_device *device)
605 {
606 int err;
607
608 /* clear detected rfkill devices */
609 wifi_rfkill = NULL;
610 bluetooth_rfkill = NULL;
611 wwan_rfkill = NULL;
612
613 hp_wmi_rfkill_setup(device);
614
615 err = device_create_file(&device->dev, &dev_attr_display);
616 if (err)
617 goto add_sysfs_error;
618 err = device_create_file(&device->dev, &dev_attr_hddtemp);
619 if (err)
620 goto add_sysfs_error;
621 err = device_create_file(&device->dev, &dev_attr_als);
622 if (err)
623 goto add_sysfs_error;
624 err = device_create_file(&device->dev, &dev_attr_dock);
625 if (err)
626 goto add_sysfs_error;
627 err = device_create_file(&device->dev, &dev_attr_tablet);
628 if (err)
629 goto add_sysfs_error;
630 return 0;
631
632 add_sysfs_error:
633 cleanup_sysfs(device);
634 return err;
635 }
636
637 static int __exit hp_wmi_bios_remove(struct platform_device *device)
638 {
639 cleanup_sysfs(device);
640
641 if (wifi_rfkill) {
642 rfkill_unregister(wifi_rfkill);
643 rfkill_destroy(wifi_rfkill);
644 }
645 if (bluetooth_rfkill) {
646 rfkill_unregister(bluetooth_rfkill);
647 rfkill_destroy(bluetooth_rfkill);
648 }
649 if (wwan_rfkill) {
650 rfkill_unregister(wwan_rfkill);
651 rfkill_destroy(wwan_rfkill);
652 }
653
654 return 0;
655 }
656
657 static int hp_wmi_resume_handler(struct device *device)
658 {
659 /*
660 * Hardware state may have changed while suspended, so trigger
661 * input events for the current state. As this is a switch,
662 * the input layer will only actually pass it on if the state
663 * changed.
664 */
665 if (hp_wmi_input_dev) {
666 input_report_switch(hp_wmi_input_dev, SW_DOCK,
667 hp_wmi_dock_state());
668 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
669 hp_wmi_tablet_state());
670 input_sync(hp_wmi_input_dev);
671 }
672
673 if (wifi_rfkill)
674 rfkill_set_states(wifi_rfkill,
675 hp_wmi_get_sw_state(HPWMI_WIFI),
676 hp_wmi_get_hw_state(HPWMI_WIFI));
677 if (bluetooth_rfkill)
678 rfkill_set_states(bluetooth_rfkill,
679 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
680 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
681 if (wwan_rfkill)
682 rfkill_set_states(wwan_rfkill,
683 hp_wmi_get_sw_state(HPWMI_WWAN),
684 hp_wmi_get_hw_state(HPWMI_WWAN));
685
686 return 0;
687 }
688
689 static int __init hp_wmi_init(void)
690 {
691 int err;
692 int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
693 int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
694
695 if (event_capable) {
696 err = hp_wmi_input_setup();
697 if (err)
698 return err;
699 }
700
701 if (bios_capable) {
702 err = platform_driver_register(&hp_wmi_driver);
703 if (err)
704 goto err_driver_reg;
705 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
706 if (!hp_wmi_platform_dev) {
707 err = -ENOMEM;
708 goto err_device_alloc;
709 }
710 err = platform_device_add(hp_wmi_platform_dev);
711 if (err)
712 goto err_device_add;
713 }
714
715 if (!bios_capable && !event_capable)
716 return -ENODEV;
717
718 return 0;
719
720 err_device_add:
721 platform_device_put(hp_wmi_platform_dev);
722 err_device_alloc:
723 platform_driver_unregister(&hp_wmi_driver);
724 err_driver_reg:
725 if (event_capable)
726 hp_wmi_input_destroy();
727
728 return err;
729 }
730
731 static void __exit hp_wmi_exit(void)
732 {
733 if (wmi_has_guid(HPWMI_EVENT_GUID))
734 hp_wmi_input_destroy();
735
736 if (hp_wmi_platform_dev) {
737 platform_device_unregister(hp_wmi_platform_dev);
738 platform_driver_unregister(&hp_wmi_driver);
739 }
740 }
741
742 module_init(hp_wmi_init);
743 module_exit(hp_wmi_exit);
This page took 0.047939 seconds and 5 git commands to generate.