blob: d6ea5e998fb88769c73007b86eac594d06d8c919 [file] [log] [blame]
Alex Hung54290fa2014-01-16 17:50:31 +08001/*
Alex Hung05aa43c2017-04-06 17:32:16 +01002 * Airplane mode button for HP & Xiaomi laptops
Alex Hung54290fa2014-01-16 17:50:31 +08003 *
Alex Hung05aa43c2017-04-06 17:32:16 +01004 * Copyright (C) 2014-2017 Alex Hung <alex.hung@canonical.com>
Alex Hung54290fa2014-01-16 17:50:31 +08005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/input.h>
25#include <linux/platform_device.h>
26#include <linux/acpi.h>
27#include <acpi/acpi_bus.h>
28
29MODULE_LICENSE("GPL");
30MODULE_AUTHOR("Alex Hung");
31MODULE_ALIAS("acpi*:HPQ6001:*");
Alex Hung05aa43c2017-04-06 17:32:16 +010032MODULE_ALIAS("acpi*:WSTADEF:*");
Alex Hung54290fa2014-01-16 17:50:31 +080033
34static struct input_dev *hpwl_input_dev;
35
36static const struct acpi_device_id hpwl_ids[] = {
37 {"HPQ6001", 0},
Alex Hung05aa43c2017-04-06 17:32:16 +010038 {"WSTADEF", 0},
Alex Hung54290fa2014-01-16 17:50:31 +080039 {"", 0},
40};
41
42static int hp_wireless_input_setup(void)
43{
44 int err;
45
46 hpwl_input_dev = input_allocate_device();
47 if (!hpwl_input_dev)
48 return -ENOMEM;
49
50 hpwl_input_dev->name = "HP Wireless hotkeys";
51 hpwl_input_dev->phys = "hpq6001/input0";
52 hpwl_input_dev->id.bustype = BUS_HOST;
53 hpwl_input_dev->evbit[0] = BIT(EV_KEY);
54 set_bit(KEY_RFKILL, hpwl_input_dev->keybit);
55
56 err = input_register_device(hpwl_input_dev);
57 if (err)
58 goto err_free_dev;
59
60 return 0;
61
62err_free_dev:
63 input_free_device(hpwl_input_dev);
64 return err;
65}
66
67static void hp_wireless_input_destroy(void)
68{
69 input_unregister_device(hpwl_input_dev);
70}
71
72static void hpwl_notify(struct acpi_device *acpi_dev, u32 event)
73{
74 if (event != 0x80) {
75 pr_info("Received unknown event (0x%x)\n", event);
76 return;
77 }
78
79 input_report_key(hpwl_input_dev, KEY_RFKILL, 1);
80 input_sync(hpwl_input_dev);
81 input_report_key(hpwl_input_dev, KEY_RFKILL, 0);
82 input_sync(hpwl_input_dev);
83}
84
85static int hpwl_add(struct acpi_device *device)
86{
87 int err;
88
89 err = hp_wireless_input_setup();
Giedrius Statkeviciusabe0b772014-11-29 00:14:27 +020090 if (err)
91 pr_err("Failed to setup hp wireless hotkeys\n");
92
Alex Hung54290fa2014-01-16 17:50:31 +080093 return err;
94}
95
96static int hpwl_remove(struct acpi_device *device)
97{
98 hp_wireless_input_destroy();
99 return 0;
100}
101
102static struct acpi_driver hpwl_driver = {
103 .name = "hp-wireless",
104 .owner = THIS_MODULE,
105 .ids = hpwl_ids,
106 .ops = {
107 .add = hpwl_add,
108 .remove = hpwl_remove,
109 .notify = hpwl_notify,
110 },
111};
112
Andy Shevchenko0b8dba12017-04-19 22:27:31 +0300113module_acpi_driver(hpwl_driver);