27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
34 #include <linux/input.h>
38 #include <linux/rfkill.h>
39 #include <linux/string.h>
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"
51 #define HPWMI_DISPLAY_QUERY 0x1
52 #define HPWMI_HDDTEMP_QUERY 0x2
53 #define HPWMI_ALS_QUERY 0x3
54 #define HPWMI_HARDWARE_QUERY 0x4
55 #define HPWMI_WIRELESS_QUERY 0x5
56 #define HPWMI_HOTKEY_QUERY 0xc
57 #define HPWMI_WIRELESS2_QUERY 0x1b
106 #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \
107 != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD))
108 #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
123 #define HPWMI_MAX_RFKILL2_DEVICES 7
132 static const struct key_entry hp_wmi_keymap[] = {
144 static struct input_dev *hp_wmi_input_dev;
147 static struct rfkill *wifi_rfkill;
148 static struct rfkill *bluetooth_rfkill;
149 static struct rfkill *wwan_rfkill;
157 static int rfkill2_count;
160 static const struct dev_pm_ops hp_wmi_pm_ops = {
161 .resume = hp_wmi_resume_handler,
162 .restore = hp_wmi_resume_handler,
169 .pm = &hp_wmi_pm_ops,
171 .probe = hp_wmi_bios_setup,
172 .remove = hp_wmi_bios_remove,
196 int insize,
int outsize)
202 .signature = 0x55434553,
203 .command = write ? 0x2 : 0x1,
204 .commandtype =
query,
227 bios_return = (
struct bios_return *)obj->
buffer.pointer;
232 pr_warn(
"query 0x%x returned error 0x%x\n", query, rc);
243 actual_outsize =
min(outsize, (
int)(obj->
buffer.length -
sizeof(*bios_return)));
244 memcpy(buffer, obj->
buffer.pointer +
sizeof(*bios_return), actual_outsize);
245 memset(buffer + actual_outsize, 0, outsize - actual_outsize);
250 static int hp_wmi_display_state(
void)
254 sizeof(state),
sizeof(state));
260 static int hp_wmi_hddtemp_state(
void)
264 sizeof(state),
sizeof(state));
270 static int hp_wmi_als_state(
void)
274 sizeof(state),
sizeof(state));
280 static int hp_wmi_dock_state(
void)
284 sizeof(state),
sizeof(state));
292 static int hp_wmi_tablet_state(
void)
296 sizeof(state),
sizeof(state));
300 return (state & 0x4) ? 1 : 0;
303 static int hp_wmi_set_block(
void *
data,
bool blocked)
306 int query =
BIT(r + 8) | ((!blocked) << r);
310 &query,
sizeof(query), 0);
316 static const struct rfkill_ops hp_wmi_rfkill_ops = {
317 .set_block = hp_wmi_set_block,
325 &wireless,
sizeof(wireless),
329 mask = 0x200 << (r * 8);
342 &wireless,
sizeof(wireless),
346 mask = 0x800 << (r * 8);
354 static int hp_wmi_rfkill2_set_block(
void *data,
bool blocked)
356 int rfkill_id = (
int)(
long)
data;
357 char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked };
360 buffer,
sizeof(buffer), 0))
365 static const struct rfkill_ops hp_wmi_rfkill2_ops = {
366 .set_block = hp_wmi_rfkill2_set_block,
369 static int hp_wmi_rfkill2_refresh(
void)
379 for (i = 0; i < rfkill2_count; i++) {
380 int num = rfkill2[
i].num;
382 devstate = &state.device[num];
384 if (num >= state.count ||
386 pr_warn(
"power configuration of the wireless devices unexpectedly changed\n");
401 int value = hp_wmi_display_state();
404 return sprintf(buf,
"%d\n", value);
410 int value = hp_wmi_hddtemp_state();
413 return sprintf(buf,
"%d\n", value);
419 int value = hp_wmi_als_state();
422 return sprintf(buf,
"%d\n", value);
428 int value = hp_wmi_dock_state();
431 return sprintf(buf,
"%d\n", value);
437 int value = hp_wmi_tablet_state();
440 return sprintf(buf,
"%d\n", value);
444 const char *buf,
size_t count)
448 sizeof(tmp),
sizeof(tmp));
461 static void hp_wmi_notify(
u32 value,
void *
context)
466 int key_code = 0,
ret;
471 if (status !=
AE_OK) {
472 pr_info(
"bad event status 0x%x\n", status);
481 pr_info(
"Unknown response received %d\n", obj->
type);
493 event_data = *(location + 1);
494 }
else if (obj->
buffer.length == 16) {
496 event_data = *(location + 2);
506 input_report_switch(hp_wmi_input_dev,
SW_DOCK,
507 hp_wmi_dock_state());
509 hp_wmi_tablet_state());
510 input_sync(hp_wmi_input_dev);
524 if (!sparse_keymap_report_event(hp_wmi_input_dev,
526 pr_info(
"Unknown key code - 0x%x\n", key_code);
530 hp_wmi_rfkill2_refresh();
538 if (bluetooth_rfkill)
548 pr_info(
"Unimplemented CPU throttle because of 3 Cell battery event detected\n");
553 pr_info(
"Unknown event_id - %d - 0x%x\n", event_id, event_data);
558 static int __init hp_wmi_input_setup(
void)
563 hp_wmi_input_dev = input_allocate_device();
564 if (!hp_wmi_input_dev)
567 hp_wmi_input_dev->name =
"HP WMI hotkeys";
568 hp_wmi_input_dev->phys =
"wmi/input0";
569 hp_wmi_input_dev->id.bustype =
BUS_HOST;
575 err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap,
NULL);
580 input_report_switch(hp_wmi_input_dev,
SW_DOCK, hp_wmi_dock_state());
582 hp_wmi_tablet_state());
583 input_sync(hp_wmi_input_dev);
588 goto err_free_keymap;
591 err = input_register_device(hp_wmi_input_dev);
593 goto err_uninstall_notifier;
597 err_uninstall_notifier:
600 sparse_keymap_free(hp_wmi_input_dev);
602 input_free_device(hp_wmi_input_dev);
606 static void hp_wmi_input_destroy(
void)
609 sparse_keymap_free(hp_wmi_input_dev);
610 input_unregister_device(hp_wmi_input_dev);
628 sizeof(wireless),
sizeof(wireless));
632 if (wireless & 0x1) {
645 goto register_wifi_error;
648 if (wireless & 0x2) {
653 if (!bluetooth_rfkill) {
655 goto register_wifi_error;
663 goto register_bluetooth_error;
666 if (wireless & 0x4) {
673 goto register_bluetooth_error;
681 goto register_wwan_err;
688 if (bluetooth_rfkill)
690 register_bluetooth_error:
692 bluetooth_rfkill =
NULL;
711 pr_warn(
"unable to parse 0x1b query output\n");
715 for (i = 0; i < state.count; i++) {
719 switch (state.device[i].radio_type) {
726 name =
"hp-bluetooth";
733 pr_warn(
"unknown device type 0x%x\n",
734 state.device[i].radio_type);
738 if (!state.device[i].vendor_id) {
739 pr_warn(
"zero device %d while %d reported\n",
745 &hp_wmi_rfkill2_ops, (
void *)(
long)i);
751 rfkill2[rfkill2_count].id = state.device[
i].rfkill_id;
752 rfkill2[rfkill2_count].num =
i;
753 rfkill2[rfkill2_count].rfkill = rfkill;
761 pr_info(
"device %s blocked by BIOS\n", name);
774 for (; rfkill2_count > 0; rfkill2_count--) {
787 bluetooth_rfkill =
NULL;
791 if (hp_wmi_rfkill_setup(device))
792 hp_wmi_rfkill2_setup(device);
796 goto add_sysfs_error;
799 goto add_sysfs_error;
802 goto add_sysfs_error;
805 goto add_sysfs_error;
808 goto add_sysfs_error;
812 cleanup_sysfs(device);
819 cleanup_sysfs(device);
821 for (i = 0; i < rfkill2_count; i++) {
830 if (bluetooth_rfkill) {
842 static int hp_wmi_resume_handler(
struct device *device)
850 if (hp_wmi_input_dev) {
851 input_report_switch(hp_wmi_input_dev,
SW_DOCK,
852 hp_wmi_dock_state());
854 hp_wmi_tablet_state());
855 input_sync(hp_wmi_input_dev);
859 hp_wmi_rfkill2_refresh();
865 if (bluetooth_rfkill)
877 static int __init hp_wmi_init(
void)
884 err = hp_wmi_input_setup();
894 if (!hp_wmi_platform_dev) {
896 goto err_device_alloc;
903 if (!bios_capable && !event_capable)
914 hp_wmi_input_destroy();
919 static void __exit hp_wmi_exit(
void)
922 hp_wmi_input_destroy();
924 if (hp_wmi_platform_dev) {