Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / platform / x86 / hp-wireless.c
blob12c31fd5d5ae25e25416a5ba1ca587f377c3100c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Airplane mode button for HP & Xiaomi laptops
5 * Copyright (C) 2014-2017 Alex Hung <alex.hung@canonical.com>
6 */
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/input.h>
12 #include <linux/platform_device.h>
13 #include <linux/acpi.h>
14 #include <acpi/acpi_bus.h>
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Alex Hung");
18 MODULE_ALIAS("acpi*:HPQ6001:*");
19 MODULE_ALIAS("acpi*:WSTADEF:*");
21 static struct input_dev *hpwl_input_dev;
23 static const struct acpi_device_id hpwl_ids[] = {
24 {"HPQ6001", 0},
25 {"WSTADEF", 0},
26 {"", 0},
29 static int hp_wireless_input_setup(void)
31 int err;
33 hpwl_input_dev = input_allocate_device();
34 if (!hpwl_input_dev)
35 return -ENOMEM;
37 hpwl_input_dev->name = "HP Wireless hotkeys";
38 hpwl_input_dev->phys = "hpq6001/input0";
39 hpwl_input_dev->id.bustype = BUS_HOST;
40 hpwl_input_dev->evbit[0] = BIT(EV_KEY);
41 set_bit(KEY_RFKILL, hpwl_input_dev->keybit);
43 err = input_register_device(hpwl_input_dev);
44 if (err)
45 goto err_free_dev;
47 return 0;
49 err_free_dev:
50 input_free_device(hpwl_input_dev);
51 return err;
54 static void hp_wireless_input_destroy(void)
56 input_unregister_device(hpwl_input_dev);
59 static void hpwl_notify(struct acpi_device *acpi_dev, u32 event)
61 if (event != 0x80) {
62 pr_info("Received unknown event (0x%x)\n", event);
63 return;
66 input_report_key(hpwl_input_dev, KEY_RFKILL, 1);
67 input_sync(hpwl_input_dev);
68 input_report_key(hpwl_input_dev, KEY_RFKILL, 0);
69 input_sync(hpwl_input_dev);
72 static int hpwl_add(struct acpi_device *device)
74 int err;
76 err = hp_wireless_input_setup();
77 if (err)
78 pr_err("Failed to setup hp wireless hotkeys\n");
80 return err;
83 static int hpwl_remove(struct acpi_device *device)
85 hp_wireless_input_destroy();
86 return 0;
89 static struct acpi_driver hpwl_driver = {
90 .name = "hp-wireless",
91 .owner = THIS_MODULE,
92 .ids = hpwl_ids,
93 .ops = {
94 .add = hpwl_add,
95 .remove = hpwl_remove,
96 .notify = hpwl_notify,
100 module_acpi_driver(hpwl_driver);