1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2008 Red Hat <mjg@redhat.com>
6 * Copyright (C) 2010, 2011 Anssi Hannula <anssi.hannula@iki.fi>
8 * Portions based on wistron_btns.c:
9 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
10 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
11 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/types.h>
21 #include <linux/input.h>
22 #include <linux/input/sparse-keymap.h>
23 #include <linux/platform_device.h>
24 #include <linux/acpi.h>
25 #include <linux/rfkill.h>
26 #include <linux/string.h>
28 MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
29 MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
30 MODULE_LICENSE("GPL");
32 MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
33 MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
35 static int enable_tablet_mode_sw = -1;
36 module_param(enable_tablet_mode_sw, int, 0444);
37 MODULE_PARM_DESC(enable_tablet_mode_sw, "Enable SW_TABLET_MODE reporting (-1=auto, 0=no, 1=yes)");
39 #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
40 #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
44 HPWMI_BLUETOOTH = 0x1,
49 enum hp_wmi_event_ids {
50 HPWMI_DOCK_EVENT = 0x01,
51 HPWMI_PARK_HDD = 0x02,
52 HPWMI_SMART_ADAPTER = 0x03,
53 HPWMI_BEZEL_BUTTON = 0x04,
54 HPWMI_WIRELESS = 0x05,
55 HPWMI_CPU_BATTERY_THROTTLE = 0x06,
56 HPWMI_LOCK_SWITCH = 0x07,
57 HPWMI_LID_SWITCH = 0x08,
58 HPWMI_SCREEN_ROTATION = 0x09,
59 HPWMI_COOLSENSE_SYSTEM_MOBILE = 0x0A,
60 HPWMI_COOLSENSE_SYSTEM_HOT = 0x0B,
61 HPWMI_PROXIMITY_SENSOR = 0x0C,
62 HPWMI_BACKLIT_KB_BRIGHTNESS = 0x0D,
63 HPWMI_PEAKSHIFT_PERIOD = 0x0F,
64 HPWMI_BATTERY_CHARGE_PERIOD = 0x10,
65 HPWMI_SANITIZATION_MODE = 0x17,
76 enum hp_wmi_commandtype {
77 HPWMI_DISPLAY_QUERY = 0x01,
78 HPWMI_HDDTEMP_QUERY = 0x02,
79 HPWMI_ALS_QUERY = 0x03,
80 HPWMI_HARDWARE_QUERY = 0x04,
81 HPWMI_WIRELESS_QUERY = 0x05,
82 HPWMI_BATTERY_QUERY = 0x07,
83 HPWMI_BIOS_QUERY = 0x09,
84 HPWMI_FEATURE_QUERY = 0x0b,
85 HPWMI_HOTKEY_QUERY = 0x0c,
86 HPWMI_FEATURE2_QUERY = 0x0d,
87 HPWMI_WIRELESS2_QUERY = 0x1b,
88 HPWMI_POSTCODEERROR_QUERY = 0x2a,
89 HPWMI_THERMAL_POLICY_QUERY = 0x4c,
98 enum hp_wmi_hardware_mask {
99 HPWMI_DOCK_MASK = 0x01,
100 HPWMI_TABLET_MASK = 0x04,
108 enum hp_return_value {
109 HPWMI_RET_WRONG_SIGNATURE = 0x02,
110 HPWMI_RET_UNKNOWN_COMMAND = 0x03,
111 HPWMI_RET_UNKNOWN_CMDTYPE = 0x04,
112 HPWMI_RET_INVALID_PARAMETERS = 0x05,
115 enum hp_wireless2_bits {
116 HPWMI_POWER_STATE = 0x01,
117 HPWMI_POWER_SOFT = 0x02,
118 HPWMI_POWER_BIOS = 0x04,
119 HPWMI_POWER_HARD = 0x08,
120 HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
123 #define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
124 #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
126 struct bios_rfkill2_device_state {
131 u16 subsys_vendor_id;
132 u16 subsys_product_id;
138 /* 7 devices fit into the 128 byte buffer */
139 #define HPWMI_MAX_RFKILL2_DEVICES 7
141 struct bios_rfkill2_state {
145 struct bios_rfkill2_device_state device[HPWMI_MAX_RFKILL2_DEVICES];
148 static const struct key_entry hp_wmi_keymap[] = {
149 { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } },
150 { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } },
151 { KE_KEY, 0x20e6, { KEY_PROG1 } },
152 { KE_KEY, 0x20e8, { KEY_MEDIA } },
153 { KE_KEY, 0x2142, { KEY_MEDIA } },
154 { KE_KEY, 0x213b, { KEY_INFO } },
155 { KE_KEY, 0x2169, { KEY_ROTATE_DISPLAY } },
156 { KE_KEY, 0x216a, { KEY_SETUP } },
157 { KE_KEY, 0x231b, { KEY_HELP } },
161 static struct input_dev *hp_wmi_input_dev;
162 static struct platform_device *hp_wmi_platform_dev;
164 static struct rfkill *wifi_rfkill;
165 static struct rfkill *bluetooth_rfkill;
166 static struct rfkill *wwan_rfkill;
168 struct rfkill2_device {
171 struct rfkill *rfkill;
174 static int rfkill2_count;
175 static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];
177 /* map output size to the corresponding WMI method id */
178 static inline int encode_outsize_for_pvsz(int outsize)
194 * hp_wmi_perform_query
196 * query: The commandtype (enum hp_wmi_commandtype)
197 * write: The command (enum hp_wmi_command)
198 * buffer: Buffer used as input and/or output
199 * insize: Size of input buffer
200 * outsize: Size of output buffer
202 * returns zero on success
203 * an HP WMI query specific error code (which is positive)
204 * -EINVAL if the query was not successful at all
205 * -EINVAL if the output buffer size exceeds buffersize
207 * Note: The buffersize must at least be the maximum of the input and output
208 * size. E.g. Battery info query is defined to have 1 byte input
209 * and 128 byte output. The caller would do:
210 * buffer = kzalloc(128, GFP_KERNEL);
211 * ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ, buffer, 1, 128)
213 static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
214 void *buffer, int insize, int outsize)
217 struct bios_return *bios_return;
219 union acpi_object *obj;
220 struct bios_args args = {
221 .signature = 0x55434553,
223 .commandtype = query,
227 struct acpi_buffer input = { sizeof(struct bios_args), &args };
228 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
231 mid = encode_outsize_for_pvsz(outsize);
232 if (WARN_ON(mid < 0))
235 if (WARN_ON(insize > sizeof(args.data)))
237 memcpy(&args.data[0], buffer, insize);
239 wmi_evaluate_method(HPWMI_BIOS_GUID, 0, mid, &input, &output);
241 obj = output.pointer;
246 if (obj->type != ACPI_TYPE_BUFFER) {
251 bios_return = (struct bios_return *)obj->buffer.pointer;
252 ret = bios_return->return_code;
255 if (ret != HPWMI_RET_UNKNOWN_COMMAND &&
256 ret != HPWMI_RET_UNKNOWN_CMDTYPE)
257 pr_warn("query 0x%x returned error 0x%x\n", query, ret);
261 /* Ignore output data of zero size */
265 actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return)));
266 memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize);
267 memset(buffer + actual_outsize, 0, outsize - actual_outsize);
274 static int hp_wmi_read_int(int query)
278 ret = hp_wmi_perform_query(query, HPWMI_READ, &val,
279 sizeof(val), sizeof(val));
282 return ret < 0 ? ret : -EINVAL;
287 static int hp_wmi_hw_state(int mask)
289 int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY);
294 return !!(state & mask);
297 static int __init hp_wmi_bios_2008_later(void)
300 int ret = hp_wmi_perform_query(HPWMI_FEATURE_QUERY, HPWMI_READ, &state,
301 sizeof(state), sizeof(state));
305 return (ret == HPWMI_RET_UNKNOWN_CMDTYPE) ? 0 : -ENXIO;
308 static int __init hp_wmi_bios_2009_later(void)
311 int ret = hp_wmi_perform_query(HPWMI_FEATURE2_QUERY, HPWMI_READ, &state,
312 sizeof(state), sizeof(state));
316 return (ret == HPWMI_RET_UNKNOWN_CMDTYPE) ? 0 : -ENXIO;
319 static int __init hp_wmi_enable_hotkeys(void)
322 int ret = hp_wmi_perform_query(HPWMI_BIOS_QUERY, HPWMI_WRITE, &value,
325 return ret <= 0 ? ret : -EINVAL;
328 static int hp_wmi_set_block(void *data, bool blocked)
330 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
331 int query = BIT(r + 8) | ((!blocked) << r);
334 ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE,
335 &query, sizeof(query), 0);
337 return ret <= 0 ? ret : -EINVAL;
340 static const struct rfkill_ops hp_wmi_rfkill_ops = {
341 .set_block = hp_wmi_set_block,
344 static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
346 int mask = 0x200 << (r * 8);
348 int wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
350 /* TBD: Pass error */
351 WARN_ONCE(wireless < 0, "error executing HPWMI_WIRELESS_QUERY");
353 return !(wireless & mask);
356 static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
358 int mask = 0x800 << (r * 8);
360 int wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
362 /* TBD: Pass error */
363 WARN_ONCE(wireless < 0, "error executing HPWMI_WIRELESS_QUERY");
365 return !(wireless & mask);
368 static int hp_wmi_rfkill2_set_block(void *data, bool blocked)
370 int rfkill_id = (int)(long)data;
371 char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked };
374 ret = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_WRITE,
375 buffer, sizeof(buffer), 0);
377 return ret <= 0 ? ret : -EINVAL;
380 static const struct rfkill_ops hp_wmi_rfkill2_ops = {
381 .set_block = hp_wmi_rfkill2_set_block,
384 static int hp_wmi_rfkill2_refresh(void)
386 struct bios_rfkill2_state state;
389 err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state,
390 sizeof(state), sizeof(state));
394 for (i = 0; i < rfkill2_count; i++) {
395 int num = rfkill2[i].num;
396 struct bios_rfkill2_device_state *devstate;
397 devstate = &state.device[num];
399 if (num >= state.count ||
400 devstate->rfkill_id != rfkill2[i].id) {
401 pr_warn("power configuration of the wireless devices unexpectedly changed\n");
405 rfkill_set_states(rfkill2[i].rfkill,
406 IS_SWBLOCKED(devstate->power),
407 IS_HWBLOCKED(devstate->power));
413 static ssize_t display_show(struct device *dev, struct device_attribute *attr,
416 int value = hp_wmi_read_int(HPWMI_DISPLAY_QUERY);
419 return sprintf(buf, "%d\n", value);
422 static ssize_t hddtemp_show(struct device *dev, struct device_attribute *attr,
425 int value = hp_wmi_read_int(HPWMI_HDDTEMP_QUERY);
428 return sprintf(buf, "%d\n", value);
431 static ssize_t als_show(struct device *dev, struct device_attribute *attr,
434 int value = hp_wmi_read_int(HPWMI_ALS_QUERY);
437 return sprintf(buf, "%d\n", value);
440 static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
443 int value = hp_wmi_hw_state(HPWMI_DOCK_MASK);
446 return sprintf(buf, "%d\n", value);
449 static ssize_t tablet_show(struct device *dev, struct device_attribute *attr,
452 int value = hp_wmi_hw_state(HPWMI_TABLET_MASK);
455 return sprintf(buf, "%d\n", value);
458 static ssize_t postcode_show(struct device *dev, struct device_attribute *attr,
461 /* Get the POST error code of previous boot failure. */
462 int value = hp_wmi_read_int(HPWMI_POSTCODEERROR_QUERY);
465 return sprintf(buf, "0x%x\n", value);
468 static ssize_t als_store(struct device *dev, struct device_attribute *attr,
469 const char *buf, size_t count)
474 ret = kstrtou32(buf, 10, &tmp);
478 ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_WRITE, &tmp,
479 sizeof(tmp), sizeof(tmp));
481 return ret < 0 ? ret : -EINVAL;
486 static ssize_t postcode_store(struct device *dev, struct device_attribute *attr,
487 const char *buf, size_t count)
493 ret = kstrtobool(buf, &clear);
500 /* Clear the POST error code. It is kept until until cleared. */
501 ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, HPWMI_WRITE, &tmp,
502 sizeof(tmp), sizeof(tmp));
504 return ret < 0 ? ret : -EINVAL;
509 static DEVICE_ATTR_RO(display);
510 static DEVICE_ATTR_RO(hddtemp);
511 static DEVICE_ATTR_RW(als);
512 static DEVICE_ATTR_RO(dock);
513 static DEVICE_ATTR_RO(tablet);
514 static DEVICE_ATTR_RW(postcode);
516 static struct attribute *hp_wmi_attrs[] = {
517 &dev_attr_display.attr,
518 &dev_attr_hddtemp.attr,
521 &dev_attr_tablet.attr,
522 &dev_attr_postcode.attr,
525 ATTRIBUTE_GROUPS(hp_wmi);
527 static void hp_wmi_notify(u32 value, void *context)
529 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
530 u32 event_id, event_data;
531 union acpi_object *obj;
536 status = wmi_get_event_data(value, &response);
537 if (status != AE_OK) {
538 pr_info("bad event status 0x%x\n", status);
542 obj = (union acpi_object *)response.pointer;
546 if (obj->type != ACPI_TYPE_BUFFER) {
547 pr_info("Unknown response received %d\n", obj->type);
553 * Depending on ACPI version the concatenation of id and event data
554 * inside _WED function will result in a 8 or 16 byte buffer.
556 location = (u32 *)obj->buffer.pointer;
557 if (obj->buffer.length == 8) {
558 event_id = *location;
559 event_data = *(location + 1);
560 } else if (obj->buffer.length == 16) {
561 event_id = *location;
562 event_data = *(location + 2);
564 pr_info("Unknown buffer length %d\n", obj->buffer.length);
571 case HPWMI_DOCK_EVENT:
572 if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
573 input_report_switch(hp_wmi_input_dev, SW_DOCK,
574 hp_wmi_hw_state(HPWMI_DOCK_MASK));
575 if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
576 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
577 hp_wmi_hw_state(HPWMI_TABLET_MASK));
578 input_sync(hp_wmi_input_dev);
582 case HPWMI_SMART_ADAPTER:
584 case HPWMI_BEZEL_BUTTON:
585 key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY);
589 if (!sparse_keymap_report_event(hp_wmi_input_dev,
591 pr_info("Unknown key code - 0x%x\n", key_code);
595 hp_wmi_rfkill2_refresh();
600 rfkill_set_states(wifi_rfkill,
601 hp_wmi_get_sw_state(HPWMI_WIFI),
602 hp_wmi_get_hw_state(HPWMI_WIFI));
603 if (bluetooth_rfkill)
604 rfkill_set_states(bluetooth_rfkill,
605 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
606 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
608 rfkill_set_states(wwan_rfkill,
609 hp_wmi_get_sw_state(HPWMI_WWAN),
610 hp_wmi_get_hw_state(HPWMI_WWAN));
612 case HPWMI_CPU_BATTERY_THROTTLE:
613 pr_info("Unimplemented CPU throttle because of 3 Cell battery event detected\n");
615 case HPWMI_LOCK_SWITCH:
617 case HPWMI_LID_SWITCH:
619 case HPWMI_SCREEN_ROTATION:
621 case HPWMI_COOLSENSE_SYSTEM_MOBILE:
623 case HPWMI_COOLSENSE_SYSTEM_HOT:
625 case HPWMI_PROXIMITY_SENSOR:
627 case HPWMI_BACKLIT_KB_BRIGHTNESS:
629 case HPWMI_PEAKSHIFT_PERIOD:
631 case HPWMI_BATTERY_CHARGE_PERIOD:
633 case HPWMI_SANITIZATION_MODE:
636 pr_info("Unknown event_id - %d - 0x%x\n", event_id, event_data);
641 static int __init hp_wmi_input_setup(void)
646 hp_wmi_input_dev = input_allocate_device();
647 if (!hp_wmi_input_dev)
650 hp_wmi_input_dev->name = "HP WMI hotkeys";
651 hp_wmi_input_dev->phys = "wmi/input0";
652 hp_wmi_input_dev->id.bustype = BUS_HOST;
654 __set_bit(EV_SW, hp_wmi_input_dev->evbit);
657 val = hp_wmi_hw_state(HPWMI_DOCK_MASK);
659 __set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
660 input_report_switch(hp_wmi_input_dev, SW_DOCK, val);
664 if (enable_tablet_mode_sw > 0) {
665 val = hp_wmi_hw_state(HPWMI_TABLET_MASK);
667 __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
668 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val);
672 err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
676 /* Set initial hardware state */
677 input_sync(hp_wmi_input_dev);
679 if (!hp_wmi_bios_2009_later() && hp_wmi_bios_2008_later())
680 hp_wmi_enable_hotkeys();
682 status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
683 if (ACPI_FAILURE(status)) {
688 err = input_register_device(hp_wmi_input_dev);
690 goto err_uninstall_notifier;
694 err_uninstall_notifier:
695 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
697 input_free_device(hp_wmi_input_dev);
701 static void hp_wmi_input_destroy(void)
703 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
704 input_unregister_device(hp_wmi_input_dev);
707 static int __init hp_wmi_rfkill_setup(struct platform_device *device)
711 wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
715 err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE, &wireless,
716 sizeof(wireless), 0);
720 if (wireless & 0x1) {
721 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
724 (void *) HPWMI_WIFI);
727 rfkill_init_sw_state(wifi_rfkill,
728 hp_wmi_get_sw_state(HPWMI_WIFI));
729 rfkill_set_hw_state(wifi_rfkill,
730 hp_wmi_get_hw_state(HPWMI_WIFI));
731 err = rfkill_register(wifi_rfkill);
733 goto register_wifi_error;
736 if (wireless & 0x2) {
737 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
738 RFKILL_TYPE_BLUETOOTH,
740 (void *) HPWMI_BLUETOOTH);
741 if (!bluetooth_rfkill) {
743 goto register_bluetooth_error;
745 rfkill_init_sw_state(bluetooth_rfkill,
746 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
747 rfkill_set_hw_state(bluetooth_rfkill,
748 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
749 err = rfkill_register(bluetooth_rfkill);
751 goto register_bluetooth_error;
754 if (wireless & 0x4) {
755 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
758 (void *) HPWMI_WWAN);
761 goto register_wwan_error;
763 rfkill_init_sw_state(wwan_rfkill,
764 hp_wmi_get_sw_state(HPWMI_WWAN));
765 rfkill_set_hw_state(wwan_rfkill,
766 hp_wmi_get_hw_state(HPWMI_WWAN));
767 err = rfkill_register(wwan_rfkill);
769 goto register_wwan_error;
775 rfkill_destroy(wwan_rfkill);
777 if (bluetooth_rfkill)
778 rfkill_unregister(bluetooth_rfkill);
779 register_bluetooth_error:
780 rfkill_destroy(bluetooth_rfkill);
781 bluetooth_rfkill = NULL;
783 rfkill_unregister(wifi_rfkill);
785 rfkill_destroy(wifi_rfkill);
790 static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
792 struct bios_rfkill2_state state;
795 err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, HPWMI_READ, &state,
796 sizeof(state), sizeof(state));
798 return err < 0 ? err : -EINVAL;
800 if (state.count > HPWMI_MAX_RFKILL2_DEVICES) {
801 pr_warn("unable to parse 0x1b query output\n");
805 for (i = 0; i < state.count; i++) {
806 struct rfkill *rfkill;
807 enum rfkill_type type;
809 switch (state.device[i].radio_type) {
811 type = RFKILL_TYPE_WLAN;
814 case HPWMI_BLUETOOTH:
815 type = RFKILL_TYPE_BLUETOOTH;
816 name = "hp-bluetooth";
819 type = RFKILL_TYPE_WWAN;
823 type = RFKILL_TYPE_GPS;
827 pr_warn("unknown device type 0x%x\n",
828 state.device[i].radio_type);
832 if (!state.device[i].vendor_id) {
833 pr_warn("zero device %d while %d reported\n",
838 rfkill = rfkill_alloc(name, &device->dev, type,
839 &hp_wmi_rfkill2_ops, (void *)(long)i);
845 rfkill2[rfkill2_count].id = state.device[i].rfkill_id;
846 rfkill2[rfkill2_count].num = i;
847 rfkill2[rfkill2_count].rfkill = rfkill;
849 rfkill_init_sw_state(rfkill,
850 IS_SWBLOCKED(state.device[i].power));
851 rfkill_set_hw_state(rfkill,
852 IS_HWBLOCKED(state.device[i].power));
854 if (!(state.device[i].power & HPWMI_POWER_BIOS))
855 pr_info("device %s blocked by BIOS\n", name);
857 err = rfkill_register(rfkill);
859 rfkill_destroy(rfkill);
868 for (; rfkill2_count > 0; rfkill2_count--) {
869 rfkill_unregister(rfkill2[rfkill2_count - 1].rfkill);
870 rfkill_destroy(rfkill2[rfkill2_count - 1].rfkill);
875 static int thermal_policy_setup(struct platform_device *device)
879 tp = hp_wmi_read_int(HPWMI_THERMAL_POLICY_QUERY);
884 * call thermal policy write command to ensure that the firmware correctly
885 * sets the OEM variables for the DPTF
887 err = hp_wmi_perform_query(HPWMI_THERMAL_POLICY_QUERY, HPWMI_WRITE, &tp,
895 static int __init hp_wmi_bios_setup(struct platform_device *device)
897 /* clear detected rfkill devices */
899 bluetooth_rfkill = NULL;
903 if (hp_wmi_rfkill_setup(device))
904 hp_wmi_rfkill2_setup(device);
906 thermal_policy_setup(device);
911 static int __exit hp_wmi_bios_remove(struct platform_device *device)
915 for (i = 0; i < rfkill2_count; i++) {
916 rfkill_unregister(rfkill2[i].rfkill);
917 rfkill_destroy(rfkill2[i].rfkill);
921 rfkill_unregister(wifi_rfkill);
922 rfkill_destroy(wifi_rfkill);
924 if (bluetooth_rfkill) {
925 rfkill_unregister(bluetooth_rfkill);
926 rfkill_destroy(bluetooth_rfkill);
929 rfkill_unregister(wwan_rfkill);
930 rfkill_destroy(wwan_rfkill);
936 static int hp_wmi_resume_handler(struct device *device)
939 * Hardware state may have changed while suspended, so trigger
940 * input events for the current state. As this is a switch,
941 * the input layer will only actually pass it on if the state
944 if (hp_wmi_input_dev) {
945 if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
946 input_report_switch(hp_wmi_input_dev, SW_DOCK,
947 hp_wmi_hw_state(HPWMI_DOCK_MASK));
948 if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
949 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
950 hp_wmi_hw_state(HPWMI_TABLET_MASK));
951 input_sync(hp_wmi_input_dev);
955 hp_wmi_rfkill2_refresh();
958 rfkill_set_states(wifi_rfkill,
959 hp_wmi_get_sw_state(HPWMI_WIFI),
960 hp_wmi_get_hw_state(HPWMI_WIFI));
961 if (bluetooth_rfkill)
962 rfkill_set_states(bluetooth_rfkill,
963 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
964 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
966 rfkill_set_states(wwan_rfkill,
967 hp_wmi_get_sw_state(HPWMI_WWAN),
968 hp_wmi_get_hw_state(HPWMI_WWAN));
973 static const struct dev_pm_ops hp_wmi_pm_ops = {
974 .resume = hp_wmi_resume_handler,
975 .restore = hp_wmi_resume_handler,
978 static struct platform_driver hp_wmi_driver = {
981 .pm = &hp_wmi_pm_ops,
982 .dev_groups = hp_wmi_groups,
984 .remove = __exit_p(hp_wmi_bios_remove),
987 static int __init hp_wmi_init(void)
989 int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
990 int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
993 if (!bios_capable && !event_capable)
997 err = hp_wmi_input_setup();
1003 hp_wmi_platform_dev =
1004 platform_device_register_simple("hp-wmi", -1, NULL, 0);
1005 if (IS_ERR(hp_wmi_platform_dev)) {
1006 err = PTR_ERR(hp_wmi_platform_dev);
1007 goto err_destroy_input;
1010 err = platform_driver_probe(&hp_wmi_driver, hp_wmi_bios_setup);
1012 goto err_unregister_device;
1017 err_unregister_device:
1018 platform_device_unregister(hp_wmi_platform_dev);
1021 hp_wmi_input_destroy();
1025 module_init(hp_wmi_init);
1027 static void __exit hp_wmi_exit(void)
1029 if (wmi_has_guid(HPWMI_EVENT_GUID))
1030 hp_wmi_input_destroy();
1032 if (hp_wmi_platform_dev) {
1033 platform_device_unregister(hp_wmi_platform_dev);
1034 platform_driver_unregister(&hp_wmi_driver);
1037 module_exit(hp_wmi_exit);