From patchwork Mon Oct 2 15:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kepplinger X-Patchwork-Id: 147349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1518377vqb; Mon, 2 Oct 2023 08:53:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxedIK0iPobba9UK2mewjY5tfM5+ex1BsBfcSuYoVh9wWgSh3qF0whPIkoNyrydlkkmB+f X-Received: by 2002:a05:6871:71f:b0:1c8:39a6:77a9 with SMTP id f31-20020a056871071f00b001c839a677a9mr12024342oap.31.1696262005079; Mon, 02 Oct 2023 08:53:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696262005; cv=none; d=google.com; s=arc-20160816; b=vG+FcGLMTW931QTczDNVdIcLQxuRikAJf0G9CBV/abkvzIkcEO0VaLUlnvAjHbxKVB fUhVzRI7s4bZLFGYaoEjIuKxPuewUefD9cZn4yd38V5HPsh0fALB7w6cVMk2f3AeLEfA weqkaj9l56fyk1uTs+4JTCiENKU9YjgEfA+bETG2FIbov9fyzzBfAerzEMGWtpN1G6r5 Rxp25pUk3BFdub/eGRbSr2OQRqmXqCWIccBvZ2qkVneHzLhf3z6SxyvUJet9jwbXeJk5 BsLSVwNdADbP+q2j0tFhfGN27E3LHZuLnWIR+3fKlTeMHEPAcoZV3bodrOq2qEAHCo0C P1sw== 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.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id x23-20020a631717000000b00570a4303746si26826345pgl.560.2023.10.02.08.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:53:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; 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.32 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 agentk.vger.email (Postfix) with ESMTP id A8A6880BD52D; Mon, 2 Oct 2023 08:09:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237855AbjJBPJn (ORCPT + 18 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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 08:09:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778659628028735008 X-GMAIL-MSGID: 1778659628028735008 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);