Skip to content

Commit 13bb0fd

Browse files
jwrdegoedeandy-shev
authored andcommitted
platform/x86: peaq-wmi: Add new peaq-wmi driver
PEAQ is a new European OEM, I've bought one of their 2-in-1 x86 devices, which is actually quite a nice device. Under Windows it has Dolby software for "better" sound and you can select different equalizer presets using a special button. This WMI interface for this button is not really nice, as it does not do notifies (it really does not I triple checked), but since I had already figured out the entire WMI interface for this I decided to go the full mile anyway and implement a WMI based input driver for this using input_polldev since, well, we need to poll. This commit adds support for this button making it report KEY_SOUND input events. KEY_SOUND is already used in various places to switch sound into theatre mode and things like that so it seems appropriate here. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> [dvhart: minor declaration ordering and commit log typo fixes] Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
1 parent 9b4bbbd commit 13bb0fd

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

drivers/platform/x86/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,13 @@ config MSI_WMI
669669
To compile this driver as a module, choose M here: the module will
670670
be called msi-wmi.
671671

672+
config PEAQ_WMI
673+
tristate "PEAQ 2-in-1 WMI hotkey driver"
674+
depends on ACPI_WMI
675+
depends on INPUT
676+
help
677+
Say Y here if you want to support WMI-based hotkeys on PEAQ 2-in-1s.
678+
672679
config TOPSTAR_LAPTOP
673680
tristate "Topstar Laptop Extras"
674681
depends on ACPI

drivers/platform/x86/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ obj-$(CONFIG_PANASONIC_LAPTOP) += panasonic-laptop.o
3535
obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
3636
obj-$(CONFIG_ACPI_WMI) += wmi.o
3737
obj-$(CONFIG_MSI_WMI) += msi-wmi.o
38+
obj-$(CONFIG_PEAQ_WMI) += peaq-wmi.o
3839
obj-$(CONFIG_SURFACE3_WMI) += surface3-wmi.o
3940
obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o
4041

drivers/platform/x86/peaq-wmi.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* PEAQ 2-in-1 WMI hotkey driver
3+
* Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 2 as
7+
* published by the Free Software Foundation.
8+
*/
9+
10+
#include <linux/acpi.h>
11+
#include <linux/input-polldev.h>
12+
#include <linux/kernel.h>
13+
#include <linux/module.h>
14+
15+
#define PEAQ_DOLBY_BUTTON_GUID "ABBC0F6F-8EA1-11D1-00A0-C90629100000"
16+
#define PEAQ_DOLBY_BUTTON_METHOD_ID 5
17+
#define PEAQ_POLL_INTERVAL_MS 250
18+
#define PEAQ_POLL_IGNORE_MS 500
19+
#define PEAQ_POLL_MAX_MS 1000
20+
21+
MODULE_ALIAS("wmi:"PEAQ_DOLBY_BUTTON_GUID);
22+
23+
static unsigned int peaq_ignore_events_counter;
24+
static struct input_polled_dev *peaq_poll_dev;
25+
26+
/*
27+
* The Dolby button (yes really a Dolby button) causes an ACPI variable to get
28+
* set on both press and release. The WMI method checks and clears that flag.
29+
* So for a press + release we will get back One from the WMI method either once
30+
* (if polling after the release) or twice (polling between press and release).
31+
* We ignore events for 0.5s after the first event to avoid reporting 2 presses.
32+
*/
33+
static void peaq_wmi_poll(struct input_polled_dev *dev)
34+
{
35+
union acpi_object obj;
36+
acpi_status status;
37+
u32 dummy = 0;
38+
39+
struct acpi_buffer input = { sizeof(dummy), &dummy };
40+
struct acpi_buffer output = { sizeof(obj), &obj };
41+
42+
status = wmi_evaluate_method(PEAQ_DOLBY_BUTTON_GUID, 1,
43+
PEAQ_DOLBY_BUTTON_METHOD_ID,
44+
&input, &output);
45+
if (ACPI_FAILURE(status))
46+
return;
47+
48+
if (obj.type != ACPI_TYPE_INTEGER) {
49+
dev_err(&peaq_poll_dev->input->dev,
50+
"Error WMBC did not return an integer\n");
51+
return;
52+
}
53+
54+
if (peaq_ignore_events_counter && --peaq_ignore_events_counter > 0)
55+
return;
56+
57+
if (obj.integer.value) {
58+
input_event(peaq_poll_dev->input, EV_KEY, KEY_SOUND, 1);
59+
input_sync(peaq_poll_dev->input);
60+
input_event(peaq_poll_dev->input, EV_KEY, KEY_SOUND, 0);
61+
input_sync(peaq_poll_dev->input);
62+
peaq_ignore_events_counter = max(1u,
63+
PEAQ_POLL_IGNORE_MS / peaq_poll_dev->poll_interval);
64+
}
65+
}
66+
67+
static int __init peaq_wmi_init(void)
68+
{
69+
if (!wmi_has_guid(PEAQ_DOLBY_BUTTON_GUID))
70+
return -ENODEV;
71+
72+
peaq_poll_dev = input_allocate_polled_device();
73+
if (!peaq_poll_dev)
74+
return -ENOMEM;
75+
76+
peaq_poll_dev->poll = peaq_wmi_poll;
77+
peaq_poll_dev->poll_interval = PEAQ_POLL_INTERVAL_MS;
78+
peaq_poll_dev->poll_interval_max = PEAQ_POLL_MAX_MS;
79+
peaq_poll_dev->input->name = "PEAQ WMI hotkeys";
80+
peaq_poll_dev->input->phys = "wmi/input0";
81+
peaq_poll_dev->input->id.bustype = BUS_HOST;
82+
input_set_capability(peaq_poll_dev->input, EV_KEY, KEY_SOUND);
83+
84+
return input_register_polled_device(peaq_poll_dev);
85+
}
86+
87+
static void __exit peaq_wmi_exit(void)
88+
{
89+
if (!wmi_has_guid(PEAQ_DOLBY_BUTTON_GUID))
90+
return;
91+
92+
input_unregister_polled_device(peaq_poll_dev);
93+
}
94+
95+
module_init(peaq_wmi_init);
96+
module_exit(peaq_wmi_exit);
97+
98+
MODULE_DESCRIPTION("PEAQ 2-in-1 WMI hotkey driver");
99+
MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
100+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)