7 * Portions based on wistron_btns.c:
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
34 #include <linux/input.h>
35 #include <linux/input/sparse-keymap.h>
36 #include <linux/platform_device.h>
37 #include <linux/acpi.h>
38 #include <linux/rfkill.h>
39 #include <linux/string.h>
42 MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
43 MODULE_LICENSE("GPL");
45 MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
46 MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
48 #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
49 #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
53 HPWMI_BLUETOOTH = 0x1,
58 enum hp_wmi_event_ids {
59 HPWMI_DOCK_EVENT = 0x01,
60 HPWMI_PARK_HDD = 0x02,
61 HPWMI_SMART_ADAPTER = 0x03,
62 HPWMI_BEZEL_BUTTON = 0x04,
63 HPWMI_WIRELESS = 0x05,
64 HPWMI_CPU_BATTERY_THROTTLE = 0x06,
65 HPWMI_LOCK_SWITCH = 0x07,
66 HPWMI_LID_SWITCH = 0x08,
67 HPWMI_SCREEN_ROTATION = 0x09,
68 HPWMI_COOLSENSE_SYSTEM_MOBILE = 0x0A,
69 HPWMI_COOLSENSE_SYSTEM_HOT = 0x0B,
70 HPWMI_PROXIMITY_SENSOR = 0x0C,
71 HPWMI_BACKLIT_KB_BRIGHTNESS = 0x0D,
72 HPWMI_PEAKSHIFT_PERIOD = 0x0F,
73 HPWMI_BATTERY_CHARGE_PERIOD = 0x10,
84 enum hp_wmi_commandtype {
85 HPWMI_DISPLAY_QUERY = 0x01,
86 HPWMI_HDDTEMP_QUERY = 0x02,
87 HPWMI_ALS_QUERY = 0x03,
88 HPWMI_HARDWARE_QUERY = 0x04,
89 HPWMI_WIRELESS_QUERY = 0x05,
90 HPWMI_BATTERY_QUERY = 0x07,
91 HPWMI_BIOS_QUERY = 0x09,
92 HPWMI_FEATURE_QUERY = 0x0b,
93 HPWMI_HOTKEY_QUERY = 0x0c,
94 HPWMI_FEATURE2_QUERY = 0x0d,
95 HPWMI_WIRELESS2_QUERY = 0x1b,
96 HPWMI_POSTCODEERROR_QUERY = 0x2a,
105 enum hp_wmi_hardware_mask {
106 HPWMI_DOCK_MASK = 0x01,
107 HPWMI_TABLET_MASK = 0x04,
110 #define BIOS_ARGS_INIT(write, ctype, size) \
111 (struct bios_args) { .signature = 0x55434553, \
112 .command = (write) ? 0x2 : 0x1, \
113 .commandtype = (ctype), \
114 .datasize = (size), \
122 enum hp_return_value {
123 HPWMI_RET_WRONG_SIGNATURE = 0x02,
124 HPWMI_RET_UNKNOWN_COMMAND = 0x03,
125 HPWMI_RET_UNKNOWN_CMDTYPE = 0x04,
126 HPWMI_RET_INVALID_PARAMETERS = 0x05,
129 enum hp_wireless2_bits {
130 HPWMI_POWER_STATE = 0x01,
131 HPWMI_POWER_SOFT = 0x02,
132 HPWMI_POWER_BIOS = 0x04,
133 HPWMI_POWER_HARD = 0x08,
136 #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \
137 != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD))
138 #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
140 struct bios_rfkill2_device_state {
145 u16 subsys_vendor_id;
146 u16 subsys_product_id;
152 /* 7 devices fit into the 128 byte buffer */
153 #define HPWMI_MAX_RFKILL2_DEVICES 7
155 struct bios_rfkill2_state {
159 struct bios_rfkill2_device_state device[HPWMI_MAX_RFKILL2_DEVICES];
162 static const struct key_entry hp_wmi_keymap[] = {
163 { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } },
164 { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } },
165 { KE_KEY, 0x20e6, { KEY_PROG1 } },
166 { KE_KEY, 0x20e8, { KEY_MEDIA } },
167 { KE_KEY, 0x2142, { KEY_MEDIA } },
168 { KE_KEY, 0x213b, { KEY_INFO } },
169 { KE_KEY, 0x2169, { KEY_ROTATE_DISPLAY } },
170 { KE_KEY, 0x216a, { KEY_SETUP } },
171 { KE_KEY, 0x231b, { KEY_HELP } },
175 static struct input_dev *hp_wmi_input_dev;
176 static struct platform_device *hp_wmi_platform_dev;
178 static struct rfkill *wifi_rfkill;
179 static struct rfkill *bluetooth_rfkill;
180 static struct rfkill *wwan_rfkill;
182 struct rfkill2_device {
185 struct rfkill *rfkill;
188 static int rfkill2_count;
189 static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];
192 * hp_wmi_perform_query
194 * query: The commandtype (enum hp_wmi_commandtype)
195 * write: The command (enum hp_wmi_command)
196 * buffer: Buffer used as input and/or output
197 * insize: Size of input buffer
198 * outsize: Size of output buffer
200 * returns zero on success
201 * an HP WMI query specific error code (which is positive)
202 * -EINVAL if the query was not successful at all
203 * -EINVAL if the output buffer size exceeds buffersize
205 * Note: The buffersize must at least be the maximum of the input and output
206 * size. E.g. Battery info query is defined to have 1 byte input
207 * and 128 byte output. The caller would do:
208 * buffer = kzalloc(128, GFP_KERNEL);
209 * ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ, buffer, 1, 128)
211 static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
212 void *buffer, int insize, int outsize)
214 struct bios_return *bios_return;
216 union acpi_object *obj;
217 struct bios_args args = {
218 .signature = 0x55434553,
220 .commandtype = query,
224 struct acpi_buffer input = { sizeof(struct bios_args), &args };
225 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
228 if (WARN_ON(insize > sizeof(args.data)))
230 memcpy(&args.data, buffer, insize);
232 wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
234 obj = output.pointer;
239 if (obj->type != ACPI_TYPE_BUFFER) {
244 bios_return = (struct bios_return *)obj->buffer.pointer;
245 ret = bios_return->return_code;
248 if (ret != HPWMI_RET_UNKNOWN_CMDTYPE)
249 pr_warn("query 0x%x returned error 0x%x\n", query, ret);
253 /* Ignore output data of zero size */
257 actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return)));
258 memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize);
259 memset(buffer + actual_outsize, 0, outsize - actual_outsize);
266 static int hp_wmi_read_int(int query)
270 ret = hp_wmi_perform_query(query, HPWMI_READ, &val,
271 sizeof(val), sizeof(val));
274 return ret < 0 ? ret : -EINVAL;
279 static int hp_wmi_hw_state(int mask)
281 int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY);
289 static int __init hp_wmi_bios_2008_later(void)
292 int ret = hp_wmi_perform_query(HPWMI_FEATURE_QUERY, HPWMI_READ, &state,
293 sizeof(state), sizeof(state));
297 return (ret == HPWMI_RET_UNKNOWN_CMDTYPE) ? 0 : -ENXIO;
300 static int __init hp_wmi_bios_2009_later(void)
303 int ret = hp_wmi_perform_query(HPWMI_FEATURE2_QUERY, HPWMI_READ, &state,
304 sizeof(state), sizeof(state));
308 return (ret == HPWMI_RET_UNKNOWN_CMDTYPE) ? 0 : -ENXIO;
311 static int __init hp_wmi_enable_hotkeys(void)
314 int ret = hp_wmi_perform_query(HPWMI_BIOS_QUERY, HPWMI_WRITE, &value,
317 return ret <= 0 ? ret : -EINVAL;
320 static int hp_wmi_set_block(void *data, bool blocked)
322 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
323 int query = BIT(r + 8) | ((!blocked) << r);
326 ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE,
327 &query, sizeof(query), 0);
329 return ret <= 0 ? ret : -EINVAL;
332 static const struct rfkill_ops hp_wmi_rfkill_ops = {
333 .set_block = hp_wmi_set_block,
336 static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
338 int mask = 0x200 << (r * 8);
340 int wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
342 /* TBD: Pass error */
343 WARN_ONCE(wireless < 0, "error executing HPWMI_WIRELESS_QUERY");
345 return !(wireless & mask);
348 static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
350 int mask = 0x800 << (r * 8);
352 int wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
354 /* TBD: Pass error */
355 WARN_ONCE(wireless < 0, "error executing HPWMI_WIRELESS_QUERY");
357 return !(wireless & mask);
360 static int hp_wmi_rfkill2_set_block(void *data, bool blocked)
362 int rfkill_id = (int)(long)data;
363 char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked };
366 ret = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_WRITE,
367 buffer, sizeof(buffer), 0);
369 return ret <= 0 ? ret : -EINVAL;
372 static const struct rfkill_ops hp_wmi_rfkill2_ops = {
373 .set_block = hp_wmi_rfkill2_set_block,
376 static int hp_wmi_rfkill2_refresh(void)
378 struct bios_rfkill2_state state;
381 err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state,
386 for (i = 0; i < rfkill2_count; i++) {
387 int num = rfkill2[i].num;
388 struct bios_rfkill2_device_state *devstate;
389 devstate = &state.device[num];
391 if (num >= state.count ||
392 devstate->rfkill_id != rfkill2[i].id) {
393 pr_warn("power configuration of the wireless devices unexpectedly changed\n");
397 rfkill_set_states(rfkill2[i].rfkill,
398 IS_SWBLOCKED(devstate->power),
399 IS_HWBLOCKED(devstate->power));
405 static ssize_t display_show(struct device *dev, struct device_attribute *attr,
408 int value = hp_wmi_read_int(HPWMI_DISPLAY_QUERY);
411 return sprintf(buf, "%d\n", value);
414 static ssize_t hddtemp_show(struct device *dev, struct device_attribute *attr,
417 int value = hp_wmi_read_int(HPWMI_HDDTEMP_QUERY);
420 return sprintf(buf, "%d\n", value);
423 static ssize_t als_show(struct device *dev, struct device_attribute *attr,
426 int value = hp_wmi_read_int(HPWMI_ALS_QUERY);
429 return sprintf(buf, "%d\n", value);
432 static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
435 int value = hp_wmi_hw_state(HPWMI_DOCK_MASK);
438 return sprintf(buf, "%d\n", value);
441 static ssize_t tablet_show(struct device *dev, struct device_attribute *attr,
444 int value = hp_wmi_hw_state(HPWMI_TABLET_MASK);
447 return sprintf(buf, "%d\n", value);
450 static ssize_t postcode_show(struct device *dev, struct device_attribute *attr,
453 /* Get the POST error code of previous boot failure. */
454 int value = hp_wmi_read_int(HPWMI_POSTCODEERROR_QUERY);
457 return sprintf(buf, "0x%x\n", value);
460 static ssize_t als_store(struct device *dev, struct device_attribute *attr,
461 const char *buf, size_t count)
463 u32 tmp = simple_strtoul(buf, NULL, 10);
464 int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_WRITE, &tmp,
465 sizeof(tmp), sizeof(tmp));
467 return ret < 0 ? ret : -EINVAL;
472 static ssize_t postcode_store(struct device *dev, struct device_attribute *attr,
473 const char *buf, size_t count)
475 long unsigned int tmp2;
479 ret = kstrtoul(buf, 10, &tmp2);
480 if (!ret && tmp2 != 1)
485 /* Clear the POST error code. It is kept until until cleared. */
487 ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, HPWMI_WRITE, &tmp,
488 sizeof(tmp), sizeof(tmp));
492 return ret < 0 ? ret : -EINVAL;
497 static DEVICE_ATTR_RO(display);
498 static DEVICE_ATTR_RO(hddtemp);
499 static DEVICE_ATTR_RW(als);
500 static DEVICE_ATTR_RO(dock);
501 static DEVICE_ATTR_RO(tablet);
502 static DEVICE_ATTR_RW(postcode);
504 static void hp_wmi_notify(u32 value, void *context)
506 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
507 u32 event_id, event_data;
508 union acpi_object *obj;
513 status = wmi_get_event_data(value, &response);
514 if (status != AE_OK) {
515 pr_info("bad event status 0x%x\n", status);
519 obj = (union acpi_object *)response.pointer;
523 if (obj->type != ACPI_TYPE_BUFFER) {
524 pr_info("Unknown response received %d\n", obj->type);
530 * Depending on ACPI version the concatenation of id and event data
531 * inside _WED function will result in a 8 or 16 byte buffer.
533 location = (u32 *)obj->buffer.pointer;
534 if (obj->buffer.length == 8) {
535 event_id = *location;
536 event_data = *(location + 1);
537 } else if (obj->buffer.length == 16) {
538 event_id = *location;
539 event_data = *(location + 2);
541 pr_info("Unknown buffer length %d\n", obj->buffer.length);
548 case HPWMI_DOCK_EVENT:
549 if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
550 input_report_switch(hp_wmi_input_dev, SW_DOCK,
551 hp_wmi_hw_state(HPWMI_DOCK_MASK));
552 if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
553 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
554 hp_wmi_hw_state(HPWMI_TABLET_MASK));
555 input_sync(hp_wmi_input_dev);
559 case HPWMI_SMART_ADAPTER:
561 case HPWMI_BEZEL_BUTTON:
562 key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY);
566 if (!sparse_keymap_report_event(hp_wmi_input_dev,
568 pr_info("Unknown key code - 0x%x\n", key_code);
572 hp_wmi_rfkill2_refresh();
577 rfkill_set_states(wifi_rfkill,
578 hp_wmi_get_sw_state(HPWMI_WIFI),
579 hp_wmi_get_hw_state(HPWMI_WIFI));
580 if (bluetooth_rfkill)
581 rfkill_set_states(bluetooth_rfkill,
582 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
583 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
585 rfkill_set_states(wwan_rfkill,
586 hp_wmi_get_sw_state(HPWMI_WWAN),
587 hp_wmi_get_hw_state(HPWMI_WWAN));
589 case HPWMI_CPU_BATTERY_THROTTLE:
590 pr_info("Unimplemented CPU throttle because of 3 Cell battery event detected\n");
592 case HPWMI_LOCK_SWITCH:
594 case HPWMI_LID_SWITCH:
596 case HPWMI_SCREEN_ROTATION:
598 case HPWMI_COOLSENSE_SYSTEM_MOBILE:
600 case HPWMI_COOLSENSE_SYSTEM_HOT:
602 case HPWMI_PROXIMITY_SENSOR:
604 case HPWMI_BACKLIT_KB_BRIGHTNESS:
606 case HPWMI_PEAKSHIFT_PERIOD:
608 case HPWMI_BATTERY_CHARGE_PERIOD:
611 pr_info("Unknown event_id - %d - 0x%x\n", event_id, event_data);
616 static int __init hp_wmi_input_setup(void)
621 hp_wmi_input_dev = input_allocate_device();
622 if (!hp_wmi_input_dev)
625 hp_wmi_input_dev->name = "HP WMI hotkeys";
626 hp_wmi_input_dev->phys = "wmi/input0";
627 hp_wmi_input_dev->id.bustype = BUS_HOST;
629 __set_bit(EV_SW, hp_wmi_input_dev->evbit);
632 val = hp_wmi_hw_state(HPWMI_DOCK_MASK);
634 __set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
635 input_report_switch(hp_wmi_input_dev, SW_DOCK, val);
639 val = hp_wmi_hw_state(HPWMI_TABLET_MASK);
641 __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
642 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val);
645 err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
649 /* Set initial hardware state */
650 input_sync(hp_wmi_input_dev);
652 if (!hp_wmi_bios_2009_later() && hp_wmi_bios_2008_later())
653 hp_wmi_enable_hotkeys();
655 status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
656 if (ACPI_FAILURE(status)) {
661 err = input_register_device(hp_wmi_input_dev);
663 goto err_uninstall_notifier;
667 err_uninstall_notifier:
668 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
670 input_free_device(hp_wmi_input_dev);
674 static void hp_wmi_input_destroy(void)
676 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
677 input_unregister_device(hp_wmi_input_dev);
680 static void cleanup_sysfs(struct platform_device *device)
682 device_remove_file(&device->dev, &dev_attr_display);
683 device_remove_file(&device->dev, &dev_attr_hddtemp);
684 device_remove_file(&device->dev, &dev_attr_als);
685 device_remove_file(&device->dev, &dev_attr_dock);
686 device_remove_file(&device->dev, &dev_attr_tablet);
687 device_remove_file(&device->dev, &dev_attr_postcode);
690 static int __init hp_wmi_rfkill_setup(struct platform_device *device)
694 wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
698 err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE, &wireless,
699 sizeof(wireless), 0);
703 if (wireless & 0x1) {
704 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
707 (void *) HPWMI_WIFI);
710 rfkill_init_sw_state(wifi_rfkill,
711 hp_wmi_get_sw_state(HPWMI_WIFI));
712 rfkill_set_hw_state(wifi_rfkill,
713 hp_wmi_get_hw_state(HPWMI_WIFI));
714 err = rfkill_register(wifi_rfkill);
716 goto register_wifi_error;
719 if (wireless & 0x2) {
720 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
721 RFKILL_TYPE_BLUETOOTH,
723 (void *) HPWMI_BLUETOOTH);
724 if (!bluetooth_rfkill) {
726 goto register_bluetooth_error;
728 rfkill_init_sw_state(bluetooth_rfkill,
729 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
730 rfkill_set_hw_state(bluetooth_rfkill,
731 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
732 err = rfkill_register(bluetooth_rfkill);
734 goto register_bluetooth_error;
737 if (wireless & 0x4) {
738 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
741 (void *) HPWMI_WWAN);
744 goto register_wwan_error;
746 rfkill_init_sw_state(wwan_rfkill,
747 hp_wmi_get_sw_state(HPWMI_WWAN));
748 rfkill_set_hw_state(wwan_rfkill,
749 hp_wmi_get_hw_state(HPWMI_WWAN));
750 err = rfkill_register(wwan_rfkill);
752 goto register_wwan_error;
758 rfkill_destroy(wwan_rfkill);
760 if (bluetooth_rfkill)
761 rfkill_unregister(bluetooth_rfkill);
762 register_bluetooth_error:
763 rfkill_destroy(bluetooth_rfkill);
764 bluetooth_rfkill = NULL;
766 rfkill_unregister(wifi_rfkill);
768 rfkill_destroy(wifi_rfkill);
773 static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
775 struct bios_rfkill2_state state;
778 err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state,
781 return err < 0 ? err : -EINVAL;
783 if (state.count > HPWMI_MAX_RFKILL2_DEVICES) {
784 pr_warn("unable to parse 0x1b query output\n");
788 for (i = 0; i < state.count; i++) {
789 struct rfkill *rfkill;
790 enum rfkill_type type;
792 switch (state.device[i].radio_type) {
794 type = RFKILL_TYPE_WLAN;
797 case HPWMI_BLUETOOTH:
798 type = RFKILL_TYPE_BLUETOOTH;
799 name = "hp-bluetooth";
802 type = RFKILL_TYPE_WWAN;
806 type = RFKILL_TYPE_GPS;
810 pr_warn("unknown device type 0x%x\n",
811 state.device[i].radio_type);
815 if (!state.device[i].vendor_id) {
816 pr_warn("zero device %d while %d reported\n",
821 rfkill = rfkill_alloc(name, &device->dev, type,
822 &hp_wmi_rfkill2_ops, (void *)(long)i);
828 rfkill2[rfkill2_count].id = state.device[i].rfkill_id;
829 rfkill2[rfkill2_count].num = i;
830 rfkill2[rfkill2_count].rfkill = rfkill;
832 rfkill_init_sw_state(rfkill,
833 IS_SWBLOCKED(state.device[i].power));
834 rfkill_set_hw_state(rfkill,
835 IS_HWBLOCKED(state.device[i].power));
837 if (!(state.device[i].power & HPWMI_POWER_BIOS))
838 pr_info("device %s blocked by BIOS\n", name);
840 err = rfkill_register(rfkill);
842 rfkill_destroy(rfkill);
851 for (; rfkill2_count > 0; rfkill2_count--) {
852 rfkill_unregister(rfkill2[rfkill2_count - 1].rfkill);
853 rfkill_destroy(rfkill2[rfkill2_count - 1].rfkill);
858 static int __init hp_wmi_bios_setup(struct platform_device *device)
862 /* clear detected rfkill devices */
864 bluetooth_rfkill = NULL;
868 if (hp_wmi_rfkill_setup(device))
869 hp_wmi_rfkill2_setup(device);
871 err = device_create_file(&device->dev, &dev_attr_display);
873 goto add_sysfs_error;
874 err = device_create_file(&device->dev, &dev_attr_hddtemp);
876 goto add_sysfs_error;
877 err = device_create_file(&device->dev, &dev_attr_als);
879 goto add_sysfs_error;
880 err = device_create_file(&device->dev, &dev_attr_dock);
882 goto add_sysfs_error;
883 err = device_create_file(&device->dev, &dev_attr_tablet);
885 goto add_sysfs_error;
886 err = device_create_file(&device->dev, &dev_attr_postcode);
888 goto add_sysfs_error;
892 cleanup_sysfs(device);
896 static int __exit hp_wmi_bios_remove(struct platform_device *device)
899 cleanup_sysfs(device);
901 for (i = 0; i < rfkill2_count; i++) {
902 rfkill_unregister(rfkill2[i].rfkill);
903 rfkill_destroy(rfkill2[i].rfkill);
907 rfkill_unregister(wifi_rfkill);
908 rfkill_destroy(wifi_rfkill);
910 if (bluetooth_rfkill) {
911 rfkill_unregister(bluetooth_rfkill);
912 rfkill_destroy(bluetooth_rfkill);
915 rfkill_unregister(wwan_rfkill);
916 rfkill_destroy(wwan_rfkill);
922 static int hp_wmi_resume_handler(struct device *device)
925 * Hardware state may have changed while suspended, so trigger
926 * input events for the current state. As this is a switch,
927 * the input layer will only actually pass it on if the state
930 if (hp_wmi_input_dev) {
931 if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
932 input_report_switch(hp_wmi_input_dev, SW_DOCK,
933 hp_wmi_hw_state(HPWMI_DOCK_MASK));
934 if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
935 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
936 hp_wmi_hw_state(HPWMI_TABLET_MASK));
937 input_sync(hp_wmi_input_dev);
941 hp_wmi_rfkill2_refresh();
944 rfkill_set_states(wifi_rfkill,
945 hp_wmi_get_sw_state(HPWMI_WIFI),
946 hp_wmi_get_hw_state(HPWMI_WIFI));
947 if (bluetooth_rfkill)
948 rfkill_set_states(bluetooth_rfkill,
949 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
950 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
952 rfkill_set_states(wwan_rfkill,
953 hp_wmi_get_sw_state(HPWMI_WWAN),
954 hp_wmi_get_hw_state(HPWMI_WWAN));
959 static const struct dev_pm_ops hp_wmi_pm_ops = {
960 .resume = hp_wmi_resume_handler,
961 .restore = hp_wmi_resume_handler,
964 static struct platform_driver hp_wmi_driver = {
967 .pm = &hp_wmi_pm_ops,
969 .remove = __exit_p(hp_wmi_bios_remove),
972 static int __init hp_wmi_init(void)
974 int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
975 int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
978 if (!bios_capable && !event_capable)
982 err = hp_wmi_input_setup();
988 hp_wmi_platform_dev =
989 platform_device_register_simple("hp-wmi", -1, NULL, 0);
990 if (IS_ERR(hp_wmi_platform_dev)) {
991 err = PTR_ERR(hp_wmi_platform_dev);
992 goto err_destroy_input;
995 err = platform_driver_probe(&hp_wmi_driver, hp_wmi_bios_setup);
997 goto err_unregister_device;
1002 err_unregister_device:
1003 platform_device_unregister(hp_wmi_platform_dev);
1006 hp_wmi_input_destroy();
1010 module_init(hp_wmi_init);
1012 static void __exit hp_wmi_exit(void)
1014 if (wmi_has_guid(HPWMI_EVENT_GUID))
1015 hp_wmi_input_destroy();
1017 if (hp_wmi_platform_dev) {
1018 platform_device_unregister(hp_wmi_platform_dev);
1019 platform_driver_unregister(&hp_wmi_driver);
1022 module_exit(hp_wmi_exit);