Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1497299rdb; Mon, 2 Oct 2023 11:16:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/IuGxJXoKs0RWXlaacLN6a1piqWVWTClBK2ZuU3lAAU9oAaDg7euHNgrHgDsrvg3gh+8V X-Received: by 2002:a05:6e02:214a:b0:350:f392:2448 with SMTP id d10-20020a056e02214a00b00350f3922448mr15005904ilv.23.1696270574637; Mon, 02 Oct 2023 11:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696270574; cv=none; d=google.com; s=arc-20160816; b=j3uHVnraNYhdKXz2vb64juiqW20T0yrv1df3N0C0PNaItgz396bQNqTVGiuecELzAg Wfh6NGDvcQAyJzMWISEUVT7K6YQZ9VcbsKUGzj0Da2EvdM+Xaf0iBfXRA/NU190HAwB8 phRnuOz/J6zhdGXrIPKEDGEZCZ/Fbc9t+3m0vUM+V5E9zNt4tfopPWrZ2iZubwdq7iIk M+s8DRHpGePqeB0wE/DyXprmQHPp7ukcloIor0RRTstd95pesl5LqVebmrUeTvyeNJc1 fpwLIEyCceFm/c3aBBym7TNg2fMZgt39svjGxZllq/5J2y4ETws844ZuPeWpqLf6Jkbt +X3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=EmDb9O/DSGUF0Mu629y2HdcLE1RSKe6tW0JbCn1YxeU=; fh=eJmZWbRMEzx1pOcTmZz1pLwsVhrqSV0/4p4dDnrveAk=; b=yfF+/teQo58NXMCak0XbG1K5E2kDL9ug1UMeXtpzxkcPQD9sHlrx3rOHoy8UwDNxmG gYgqUx3av3X6aekzZLjfrS8DAkgUnu27ZeV7mz/pL0QpJ+15gFQMRhVnZEPn7DUIDUIC glLQE8UopJ0plXo9lhdqBs5rJ2BOiRvoaE0ldiwNbaAJa35F+opWXaQR3iRBuCP0wB50 dfCTkyrhZMmv9XwrBDqJQ+9Cmv0hYxH1f7XBrrfUIlpQXSA30smzGVgzAevzWdVY7L80 Q/zW1pWPKu7HhoGjiwD+m6W2UBN5k6hs8q41bGAMUQLqXHr7DDNsfniRAXkqEqgvi89m khaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=M1K3jd8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.de Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q16-20020a656850000000b0056b4065299esi27796602pgt.621.2023.10.02.11.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 11:16:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=M1K3jd8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8CEE48091C46; Mon, 2 Oct 2023 08:09:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237799AbjJBPJn (ORCPT + 99 others); Mon, 2 Oct 2023 11:09:43 -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: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 08:09:51 -0700 (PDT) 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 compact 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_device *hdev) int ret; struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); + /* + * Tell the keyboard a driver understands it, and turn F7, F9, F11 into + * regular keys + */ + ret = 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 = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); + if (ret) + hid_warn(hdev, "Failed to switch middle button: %d\n", ret); + ret = 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 *hdev) } hid_set_drvdata(hdev, cptkbd_data); - /* - * Tell the keyboard a driver understands it, and turn F7, F9, F11 into - * regular keys (Compact only) - */ - if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD || - hdev->product == USB_DEVICE_ID_LENOVO_CBTKBD) { - ret = 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 = 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 = 0; cptkbd_data->fn_lock = true; @@ -1264,6 +1261,24 @@ static int lenovo_probe(struct hid_device *hdev, return ret; } +#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 == 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 = hid_get_drvdata(hdev); @@ -1380,6 +1395,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_reset_resume, +#endif }; module_hid_driver(lenovo_driver); -- 2.39.2