[PATCH] platform/x86: hp-wmi: Add periodic tablet mode poll
Илья Мухамадеев <[email protected]>
| Newsgroups | org.kernel.vger.platform-driver-x86 |
|---|---|
| Message-ID | <[email protected]> |
Greetings!
Some HP convertible laptops (e.g., ProBook x360 series) do not generate
ACPI events when switching between laptop and tablet mode, causing the
input subsystem to never receive SW_TABLET_MODE notifications.
Add a periodic delayed work that polls the tablet mode state every
second and reports changes via input_report_switch(). Track the last
known state to avoid sending duplicate events, and clean up the work
queue on module removal.
---
drivers/platform/x86/hp/hp-wmi.c | 37 +++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/hp/hp-wmi.c
b/drivers/platform/x86/hp/hp-wmi.c
index 8ba286ed8721..4a4d57fa6d29 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -460,6 +460,8 @@ static struct notifier_block platform_power_source_nb;
static enum platform_profile_option active_platform_profile;
static bool platform_profile_support;
static bool zero_insize_support;
+static int last_tablet_state = -1;
+static struct delayed_work tablet_mode_work;
static struct rfkill *wifi_rfkill;
static struct rfkill *bluetooth_rfkill;
@@ -1176,9 +1178,14 @@ static void hp_wmi_notify(union acpi_object *obj,
void *context)
if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
input_report_switch(hp_wmi_input_dev, SW_DOCK,
hp_wmi_get_dock_state());
- if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
- input_report_switch(hp_wmi_input_dev,
SW_TABLET_MODE,
- hp_wmi_get_tablet_mode());
+ if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) {
+ int tablet = hp_wmi_get_tablet_mode();
+ if (tablet >= 0) {
+ last_tablet_state = tablet;
+ input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
+ tablet);
+ }
+ }
input_sync(hp_wmi_input_dev);
break;
case HPWMI_PARK_HDD:
@@ -1271,6 +1278,24 @@ static void hp_wmi_notify(union acpi_object *obj,
void *context)
}
}
+/*
+ * Periodically poll tablet mode state and send input events if changed.
+ * This works around missing ACPI events on some HP laptops.
+ */
+static void hp_wmi_tablet_mode_work_handler(struct work_struct *work)
+{
+ int cur = hp_wmi_get_tablet_mode();
+ if (cur >= 0 && cur != last_tablet_state) {
+ last_tablet_state = cur;
+ if (hp_wmi_input_dev && test_bit(SW_TABLET_MODE,
hp_wmi_input_dev->swbit)) {
+ input_report_switch(hp_wmi_input_dev,
SW_TABLET_MODE, cur);
+ input_sync(hp_wmi_input_dev);
+ pr_debug("Tablet mode changed to %d\n", cur);
+ }
+ }
+ schedule_delayed_work(&tablet_mode_work, msecs_to_jiffies(1000));
+}
+
static int __init hp_wmi_input_setup(void)
{
acpi_status status;
@@ -1298,6 +1323,10 @@ static int __init hp_wmi_input_setup(void)
if (!(val < 0)) {
__set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, val);
+ last_tablet_state = val;
+ INIT_DELAYED_WORK(&tablet_mode_work,
+ hp_wmi_tablet_mode_work_handler);
+ schedule_delayed_work(&tablet_mode_work,
msecs_to_jiffies(1000));
}
err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
@@ -1331,6 +1360,8 @@ static int __init hp_wmi_input_setup(void)
static void hp_wmi_input_destroy(void)
{
+ cancel_delayed_work_sync(&tablet_mode_work);
+ last_tablet_state = -1;
wmi_remove_notify_handler(HPWMI_EVENT_GUID);
input_unregister_device(hp_wmi_input_dev);
}
--
2.50.1