platform/x86/hp/hp-wmi: Add periodic tablet mode poll
PATCH 1/1 platform/x86/hp/hp-wmi: Add periodic tablet mode poll
From: Ilya Mukhamadeev <[email protected]>
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 | 35 +++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
drivers/platform/x86/hp/hp-wmi.c +32 -3
@@ -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,13 @@ 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 +1277,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 +1322,9 @@ 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 +1358,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); }
Signature · 1 line
2.50.1
Ilpo Järvinen
maintainerQuoted 28 lines · On Wed, 12 Aug 2026, [email protected] wrote:
From: Ilya Mukhamadeev <[email protected]>
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_MODEnotifications.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 | 35 +++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)drivers/platform/x86/hp/hp-wmi.c +2
-0@@ -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;
drivers/platform/x86/hp/hp-wmi.c static void hp_wmi_notify(union acpi_object *obj, void *context) · line 1184
Quoted 10 lines
drivers/platform/x86/hp/hp-wmi.c +4
-3@@ -1176,9 +1178,13 @@ 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;
Couldn't this just remove the work when we've positive confirmation the events work?
--
i.
Quoted 51 lines
drivers/platform/x86/hp/hp-wmi.c +26
-0+input_report_switch (hp_wmi_input_dev,SW_TABLET_MODE , tablet); + } + }input_sync (hp_wmi_input_dev);break ;case HPWMI_PARK_HDD :@@ -1271,6 +1277,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 +1322,9 @@ 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 +1358,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); }
Signature · 1 line
i.