All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Ilya Mukhamadeev <nicourced@altlinux.org>
Cc: Hans de Goede <hansg@kernel.org>,
	krishna.chomal108@gmail.com,  emreleno@gmail.com, edip@medip.dev,
	platform-driver-x86@vger.kernel.org,
	 LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] platform/x86/hp/hp-wmi: Add periodic tablet mode poll
Date: Wed, 16 Sep 2026 00:04:31 +0300 (EEST)	[thread overview]
Message-ID: <bea9a2be-e87f-49ab-ce94-e6ede08b5f37@linux.intel.com> (raw)
In-Reply-To: <20260812113303.106965-1-nicourced@altlinux.org>

On Wed, 12 Aug 2026, nicourced@altlinux.org wrote:

> From: Ilya Mukhamadeev <nicourced@altlinux.org>
> 
> 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(-)
> 
> diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
> index 8ba286ed8721..5fbfdde3291a 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,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.

> +				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);
>  }
> 

-- 
 i.


      reply	other threads:[~2026-09-15 21:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 11:33 [PATCH] platform/x86/hp/hp-wmi: Add periodic tablet mode poll nicourced
2026-09-15 21:04 ` Ilpo Järvinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bea9a2be-e87f-49ab-ce94-e6ede08b5f37@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=edip@medip.dev \
    --cc=emreleno@gmail.com \
    --cc=hansg@kernel.org \
    --cc=krishna.chomal108@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicourced@altlinux.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.