Linux Input/HID development
 help / color / mirror / Atom feed
From: Jamie Lentin <jm@lentin.co.uk>
To: Martin Kepplinger <martink@posteo.de>
Cc: jikos@kernel.org, benjamin.tissoires@redhat.com,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: [PATCH] HID: lenovo: Fix middle-button behaviour for system suspend
Date: Sun, 24 Sep 2023 09:11:16 +0100	[thread overview]
Message-ID: <140b721bc345a846863a37ebf17c3174@lentin.co.uk> (raw)
In-Reply-To: <20230921092140.120533-1-martink@posteo.de>

On 2023-09-21 10:21, Martin Kepplinger wrote:
> After system suspend the middle-button mode is being reset to
> compatibility mode which simply breaks functionality for the devices
> where native mode is configured during probe().
> 
> Fix this by setting native mode in reset_resume() for the appropriate
> devices.
> 
> Fixes: 94eefa271323 ("HID: lenovo: Use native middle-button mode for
> compact keyboards")
> Signed-off-by: Martin Kepplinger <martink@posteo.de>
> ---
>  drivers/hid/hid-lenovo.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
> index 44763c0da444..d20562b9eca6 100644
> --- a/drivers/hid/hid-lenovo.c
> +++ b/drivers/hid/hid-lenovo.c
> @@ -1344,6 +1344,28 @@ static int lenovo_input_configured(struct
> hid_device *hdev,
>  	return 0;
>  }
> 
> +static int __maybe_unused lenovo_resume(struct hid_device *hdev)
> +{
> +	int ret;
> +
> +	switch (hdev->product) {
> +	case USB_DEVICE_ID_LENOVO_CUSBKBD:
> +	case USB_DEVICE_ID_LENOVO_CBTKBD:
> +	case USB_DEVICE_ID_LENOVO_TPIIUSBKBD:
> +	case USB_DEVICE_ID_LENOVO_TPIIBTKBD:
> +		/* Switch middle button to native mode again */
> +		ret = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01);

This will only reset the middle button state and not the Function key 
state, which I believe has similar problems. This was my attempt at 
solving this:

   
https://github.com/lentinj/linux/commit/f1c4e2de780abf8526bcdc9496c463f1ff4fe53b

...which should ensure everything is in a consistent state with what the 
kernel expects.

I never submitted this since sending commands was sporadically resulting 
in timeouts, although I'm fairly sure it was unrelated to this patch, 
and quite possibly a hardware problem with my keyboard. I'd be 
interested to know how you get on.

Also, the above will send the command to both the USB keyboard & mouse 
devices, only the mouse will respond. So worth prepending something 
like:

	if (((hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD) ||
	    (hdev->product == USB_DEVICE_ID_LENOVO_TPIIUSBKBD)) &&
	    hdev->type != HID_TYPE_USBMOUSE) {
		hid_dbg(hdev, "Ignoring keyboard half of device\n");
		return 0;
	}

...to avoid sending known-useless messages.

> +		if (ret)
> +			hid_warn(hdev, "Failed to switch middle button: %d\n",
> +				 ret);
> +		break;
> +	default:
> +		ret = 0;
> +		break;
> +	}
> +
> +	return ret;
> +}
> 
>  static const struct hid_device_id lenovo_devices[] = {
>  	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
> @@ -1380,6 +1402,9 @@ static struct hid_driver lenovo_driver = {
>  	.raw_event = lenovo_raw_event,
>  	.event = lenovo_event,
>  	.report_fixup = lenovo_report_fixup,
> +#ifdef CONFIG_PM
> +	.reset_resume = lenovo_resume,
> +#endif
>  };
>  module_hid_driver(lenovo_driver);

  reply	other threads:[~2023-09-24  8:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21  9:21 [PATCH] HID: lenovo: Fix middle-button behaviour for system suspend Martin Kepplinger
2023-09-24  8:11 ` Jamie Lentin [this message]
2023-09-25 10:23   ` [RFC PATCH 1/2] hid: lenovo: Resend all settings on reset_resume for compact keyboards Martin Kepplinger
2023-09-25 10:23     ` [RFC PATCH 2/2] hid: lenovo: move type checks to lenovo_features_set_cptkbd() Martin Kepplinger
2023-09-27  8:19       ` Jamie Lentin
2023-09-27 11:20         ` Martin Kepplinger
2023-09-28 21:06           ` Jamie Lentin
2023-09-30  9:26             ` Martin Kepplinger
2023-09-30  9:58               ` Jamie Lentin

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=140b721bc345a846863a37ebf17c3174@lentin.co.uk \
    --to=jm@lentin.co.uk \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martink@posteo.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox