forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/platform/x86/peaq-wmi.c
....@@ -1,15 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * PEAQ 2-in-1 WMI hotkey driver
34 * 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.
85 */
96
107 #include <linux/acpi.h>
118 #include <linux/dmi.h>
12
-#include <linux/input-polldev.h>
9
+#include <linux/input.h>
1310 #include <linux/kernel.h>
1411 #include <linux/module.h>
1512
....@@ -21,8 +18,7 @@
2118
2219 MODULE_ALIAS("wmi:"PEAQ_DOLBY_BUTTON_GUID);
2320
24
-static unsigned int peaq_ignore_events_counter;
25
-static struct input_polled_dev *peaq_poll_dev;
21
+static struct input_dev *peaq_poll_dev;
2622
2723 /*
2824 * The Dolby button (yes really a Dolby button) causes an ACPI variable to get
....@@ -31,8 +27,10 @@
3127 * (if polling after the release) or twice (polling between press and release).
3228 * We ignore events for 0.5s after the first event to avoid reporting 2 presses.
3329 */
34
-static void peaq_wmi_poll(struct input_polled_dev *dev)
30
+static void peaq_wmi_poll(struct input_dev *input_dev)
3531 {
32
+ static unsigned long last_event_time;
33
+ static bool had_events;
3634 union acpi_object obj;
3735 acpi_status status;
3836 u32 dummy = 0;
....@@ -47,22 +45,25 @@
4745 return;
4846
4947 if (obj.type != ACPI_TYPE_INTEGER) {
50
- dev_err(&peaq_poll_dev->input->dev,
48
+ dev_err(&input_dev->dev,
5149 "Error WMBC did not return an integer\n");
5250 return;
5351 }
5452
55
- if (peaq_ignore_events_counter && peaq_ignore_events_counter--)
53
+ if (!obj.integer.value)
5654 return;
5755
58
- if (obj.integer.value) {
59
- input_event(peaq_poll_dev->input, EV_KEY, KEY_SOUND, 1);
60
- input_sync(peaq_poll_dev->input);
61
- input_event(peaq_poll_dev->input, EV_KEY, KEY_SOUND, 0);
62
- input_sync(peaq_poll_dev->input);
63
- peaq_ignore_events_counter = max(1u,
64
- PEAQ_POLL_IGNORE_MS / peaq_poll_dev->poll_interval);
65
- }
56
+ if (had_events && time_before(jiffies, last_event_time +
57
+ msecs_to_jiffies(PEAQ_POLL_IGNORE_MS)))
58
+ return;
59
+
60
+ input_event(input_dev, EV_KEY, KEY_SOUND, 1);
61
+ input_sync(input_dev);
62
+ input_event(input_dev, EV_KEY, KEY_SOUND, 0);
63
+ input_sync(input_dev);
64
+
65
+ last_event_time = jiffies;
66
+ had_events = true;
6667 }
6768
6869 /* Some other devices (Shuttle XS35) use the same WMI GUID for other purposes */
....@@ -78,6 +79,8 @@
7879
7980 static int __init peaq_wmi_init(void)
8081 {
82
+ int err;
83
+
8184 /* WMI GUID is not unique, also check for a DMI match */
8285 if (!dmi_check_system(peaq_dmi_table))
8386 return -ENODEV;
....@@ -85,24 +88,36 @@
8588 if (!wmi_has_guid(PEAQ_DOLBY_BUTTON_GUID))
8689 return -ENODEV;
8790
88
- peaq_poll_dev = input_allocate_polled_device();
91
+ peaq_poll_dev = input_allocate_device();
8992 if (!peaq_poll_dev)
9093 return -ENOMEM;
9194
92
- peaq_poll_dev->poll = peaq_wmi_poll;
93
- peaq_poll_dev->poll_interval = PEAQ_POLL_INTERVAL_MS;
94
- peaq_poll_dev->poll_interval_max = PEAQ_POLL_MAX_MS;
95
- peaq_poll_dev->input->name = "PEAQ WMI hotkeys";
96
- peaq_poll_dev->input->phys = "wmi/input0";
97
- peaq_poll_dev->input->id.bustype = BUS_HOST;
98
- input_set_capability(peaq_poll_dev->input, EV_KEY, KEY_SOUND);
95
+ peaq_poll_dev->name = "PEAQ WMI hotkeys";
96
+ peaq_poll_dev->phys = "wmi/input0";
97
+ peaq_poll_dev->id.bustype = BUS_HOST;
98
+ input_set_capability(peaq_poll_dev, EV_KEY, KEY_SOUND);
9999
100
- return input_register_polled_device(peaq_poll_dev);
100
+ err = input_setup_polling(peaq_poll_dev, peaq_wmi_poll);
101
+ if (err)
102
+ goto err_out;
103
+
104
+ input_set_poll_interval(peaq_poll_dev, PEAQ_POLL_INTERVAL_MS);
105
+ input_set_max_poll_interval(peaq_poll_dev, PEAQ_POLL_MAX_MS);
106
+
107
+ err = input_register_device(peaq_poll_dev);
108
+ if (err)
109
+ goto err_out;
110
+
111
+ return 0;
112
+
113
+err_out:
114
+ input_free_device(peaq_poll_dev);
115
+ return err;
101116 }
102117
103118 static void __exit peaq_wmi_exit(void)
104119 {
105
- input_unregister_polled_device(peaq_poll_dev);
120
+ input_unregister_device(peaq_poll_dev);
106121 }
107122
108123 module_init(peaq_wmi_init);