From patchwork Mon Sep 25 10:23:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kepplinger X-Patchwork-Id: 144404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1169553vqu; Mon, 25 Sep 2023 05:24:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUZPBXZ0Cux3MuG01jlXUYux0yTmXVZwx3/+rDq5Rg9NSO1UNRsURVqUGTSkbOXP+Ht+Ex X-Received: by 2002:a05:6870:470c:b0:1be:dbd2:2bfe with SMTP id b12-20020a056870470c00b001bedbd22bfemr8670826oaq.57.1695644644214; Mon, 25 Sep 2023 05:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695644644; cv=none; d=google.com; s=arc-20160816; b=f63Xd9cK9V9yxgYLNTn4/lKjw3OxSbuKAOgC2BVNtGecWLlXtkoTgXUOa9kgraDjjv tAsLb4G0NfQzaN6RMjZ8+Ug9QwDSwH/7NIlgiAiY6rhyCbcz/a5H79K+S5NDhzGNbynd 6FjAv+giinZEvGZMAPkMJK4/gutIYHKMYnIXQzMufsniqq9n1mFt8n7+hx1JjW36x3cm MAqXJiPh4vPuGi27BcCnCgSZZQaa+RTMJVUEv5DOIYruUw3+wkNRfqvDS9suSWbcWJ8k 1WDbOMcX2NRbcqxxtiwP5t5l1dEdHbLYiIRGs5bDY4eF/0zuaQHnFlS9Df6rI7BDZLZI r6qQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mgGkAgCS+LVGdJEpTQqah6zHLX8Gs2dbQWlPnS7z5yw=; fh=Y8NTCuHDNQUi1Y7edzN1WOu8jwcMKdKWGbAHrwF7W6M=; b=A7MKfTe94RJRiKwzndzsL4+ndfqPiV04ic2Xm1DjemgtgIZkajw08Wd0PA5lkvQFId o9vD4foOgTJc9sywak0cv6q6OrSHOXam9CGqx/dDmc0c0nnk31cLroYdHyDCHeZYTQct 54nPpyEay7eBRglh86QmdsdIvXWaWwTSZOHi3Ed1GayAv4+DVxHtXvQ//CA9tNZLUvvI z3Xf1aNECfOykDwpcJf8/Zn5JHKSW7W7smhYv0qNxnL57D4s3MHjYMhc9FWgFGxZQ5MH qw9la5voMVRRveU2PjRceAdxJTH2rn3ca63U+yurmgGObU75tSUMVpIAcxWYetQ0b5Q4 lBzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=n5CfrwIi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bx37-20020a056a02052500b005656cec81f5si11396699pgb.268.2023.09.25.05.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 05:24:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=n5CfrwIi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id A6C238126726; Mon, 25 Sep 2023 03:24:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbjIYKXo (ORCPT + 29 others); Mon, 25 Sep 2023 06:23:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbjIYKXm (ORCPT ); Mon, 25 Sep 2023 06:23:42 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3B0106 for ; Mon, 25 Sep 2023 03:23:34 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id CAAB8240027 for ; Mon, 25 Sep 2023 12:23:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1695637412; bh=CzIIBHhlGAUxGhgWQf9eNBaRxB1SQS0JeVLGWV4aCTg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=n5CfrwIijMTHzdteJC4xWcCmgA2fo9KTVN4hHrrDqh/yQ7LMtmhAAEcLAoiRbPXQs RKUlkchun4xmXQLgzUPYNQovwROlI2vu1JPB0RnLGuE9pXa/Z2dXyxIBeWy5yXuPaK w4BkLU0EKMvt2o7Mh6W79+pPtiqhjnkq1uvds/4qVoiKzIUaiaVHdEAOJ/bgDy2yUs 9VVVckyy1rrYqCVN4UTGZg6VUIwe/fMy5ckaDmU0K2xOFDIIfar0OIB+NOOstCy/Nw OXKpzzGS5536T7M0mg1Owwem7hnSXNzlX45qAimt4hlM4R6w0enHqRLJpo4HpLB4++ tAOe0wdwWavMA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RvJqj5T72z6v4v; Mon, 25 Sep 2023 12:23:29 +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, Martin Kepplinger Subject: [RFC PATCH 1/2] hid: lenovo: Resend all settings on reset_resume for compact keyboards Date: Mon, 25 Sep 2023 10:23:01 +0000 Message-Id: <20230925102302.13094-1-martink@posteo.de> In-Reply-To: <140b721bc345a846863a37ebf17c3174@lentin.co.uk> References: <140b721bc345a846863a37ebf17c3174@lentin.co.uk> 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 03:24:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778012278527519256 X-GMAIL-MSGID: 1778012278527519256 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. Fixes: 94eefa271323 ("HID: lenovo: Use native middle-button mode for compact keyboards") Signed-off-by: Jamie Lentin Signed-off-by: Martin Kepplinger --- hi Jamie, thanks for sharing your patch! This works equally well for me. Is the 2nd patch what you had in mind? If so, let's create a new squashed non-RFC patch. thanks again, martin 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..29aa6d372bad 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: + 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);