From nobody Mon Jan 5 11:18:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0862E784BB for ; Mon, 2 Oct 2023 15:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237827AbjJBPJo (ORCPT ); Mon, 2 Oct 2023 11:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237812AbjJBPJm (ORCPT ); Mon, 2 Oct 2023 11:09:42 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC07CB3 for ; Mon, 2 Oct 2023 08:09:37 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 3750F240028 for ; Mon, 2 Oct 2023 17:09:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1696259375; bh=eWzhFfAkBaBtNBNsW3h0GYOAtel0vXZbYosrTPRyAIg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=M1K3jd8Isj01cc4ZydVu5CnYRZHSK2IcW/uVhsJM0zXDdg2PLhxSWcC0mQ5PhBqpw Cqlv2UZ2RxScAgUjUselMGN1uWjVzblhATkLhTBomQRSi7V5Jrj4gXneFLNpFodmA1 TQlJtPLekgeCvgftPCMHLwyp1f/5CAA0Q2dthPzGJtBsWv9rU3YR0MrnjByJ5P9+xB 5U/O88fBluPnM4OUNXumrrwPcNoc14sN35vsTqeN2lHi1jxtECD1t4TrnOrgL7SODD 7uX7dIuDdGVYSP+5Eu5ZnFTnubOCfNJpmUos360aTWthFs9e6N0pt3wylWFvTO0r8C samFcCEQZVJLA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RzkrZ2m8tz9rxF; Mon, 2 Oct 2023 17:09:34 +0200 (CEST) From: Martin Kepplinger To: jikos@kernel.org, benjamin.tissoires@redhat.com, jm@lentin.co.uk, linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, stable@vger.kernel.org, Martin Kepplinger Subject: [PATCH] hid: lenovo: Resend all settings on reset_resume for compact keyboards Date: Mon, 2 Oct 2023 15:09:14 +0000 Message-Id: <20231002150914.22101-1-martink@posteo.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jamie Lentin The USB Compact Keyboard variant requires a reset_resume function to restore keyboard configuration after a suspend in some situations. Move configuration normally done on probe to lenovo_features_set_cptkbd(), then recycle this for use on reset_resume. Without, the keyboard and driver would end up in an inconsistent state, breaking middle-button scrolling amongst other problems, and twiddling sysfs values wouldn't help as the middle-button mode won't be set until the driver is reloaded. Tested on a USB and Bluetooth Thinkpad Compact Keyboard. CC: stable@vger.kernel.org Fixes: 94eefa271323 ("HID: lenovo: Use native middle-button mode for compac= t keyboards") Signed-off-by: Jamie Lentin Signed-off-by: Martin Kepplinger --- drivers/hid/hid-lenovo.c | 50 +++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index 44763c0da444..614320bff39f 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -521,6 +521,19 @@ static void lenovo_features_set_cptkbd(struct hid_devi= ce *hdev) int ret; struct lenovo_drvdata *cptkbd_data =3D hid_get_drvdata(hdev); =20 + /* + * Tell the keyboard a driver understands it, and turn F7, F9, F11 into + * regular keys + */ + ret =3D lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); + if (ret) + hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); + + /* Switch middle button to native mode */ + ret =3D lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); + if (ret) + hid_warn(hdev, "Failed to switch middle button: %d\n", ret); + ret =3D lenovo_send_cmd_cptkbd(hdev, 0x05, cptkbd_data->fn_lock); if (ret) hid_err(hdev, "Fn-lock setting failed: %d\n", ret); @@ -1126,22 +1139,6 @@ static int lenovo_probe_cptkbd(struct hid_device *hd= ev) } hid_set_drvdata(hdev, cptkbd_data); =20 - /* - * Tell the keyboard a driver understands it, and turn F7, F9, F11 into - * regular keys (Compact only) - */ - if (hdev->product =3D=3D USB_DEVICE_ID_LENOVO_CUSBKBD || - hdev->product =3D=3D USB_DEVICE_ID_LENOVO_CBTKBD) { - ret =3D lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); - if (ret) - hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); - } - - /* Switch middle button to native mode */ - ret =3D lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); - if (ret) - hid_warn(hdev, "Failed to switch middle button: %d\n", ret); - /* Set keyboard settings to known state */ cptkbd_data->middlebutton_state =3D 0; cptkbd_data->fn_lock =3D true; @@ -1264,6 +1261,24 @@ static int lenovo_probe(struct hid_device *hdev, return ret; } =20 +#ifdef CONFIG_PM +static int lenovo_reset_resume(struct hid_device *hdev) +{ + switch (hdev->product) { + case USB_DEVICE_ID_LENOVO_CUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + if (hdev->type =3D=3D HID_TYPE_USBMOUSE) + lenovo_features_set_cptkbd(hdev); + + break; + default: + break; + } + + return 0; +} +#endif + static void lenovo_remove_tpkbd(struct hid_device *hdev) { struct lenovo_drvdata *data_pointer =3D hid_get_drvdata(hdev); @@ -1380,6 +1395,9 @@ static struct hid_driver lenovo_driver =3D { .raw_event =3D lenovo_raw_event, .event =3D lenovo_event, .report_fixup =3D lenovo_report_fixup, +#ifdef CONFIG_PM + .reset_resume =3D lenovo_reset_resume, +#endif }; module_hid_driver(lenovo_driver); =20 --=20 2.39.2