Message ID | 20230925102302.13094-2-martink@posteo.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1196190vqu; Mon, 25 Sep 2023 06:06:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFELzfMME4iKw8MfOaRFkV4527UU8nDPl+a+oSSJHaAEM/BPp5sN1t4RGKPCP/Bxj8VILG+ X-Received: by 2002:a05:6a20:9148:b0:15e:dc75:66a7 with SMTP id x8-20020a056a20914800b0015edc7566a7mr2578650pzc.24.1695647173019; Mon, 25 Sep 2023 06:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695647173; cv=none; d=google.com; s=arc-20160816; b=0EoIQd5ZBvbFMaeKG3s5AWCJ3NU8KyyAn6RTyyUMHc70l11m0X7oVirsXS1Aooy2Q6 rtfAn5x/LiRp+I4vMzj6aT7+m8hvas5zB7tB2H1HyP9TcexnNNChhnJewXLBhQMWVgmY /VzvleX/fo8IVcWBlA27Jor483H5mXRROfJBfgDLcNvTo9iFvY+x4jdadRlF89MtZQiw 99WJ1HC3DsnHjLstaVU2kLOcPg+KLwhDpv+SrcE/OfoOUzNbpTFoSvpYI7M52mCLPq0w Ddz6OlOb/BdResyTyEOqA7Q8EO9wUKzXFy/YBC1Qp1OJ5vYyulKeDo+kRiTrwVLdwOkT 0bXA== 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=y5EUvVVhUGA66jNVm1D326U+HxU2r2colsmzEUTdisM=; fh=Y8NTCuHDNQUi1Y7edzN1WOu8jwcMKdKWGbAHrwF7W6M=; b=qYfnEATAllk367Ej2Ek5TpJ1UGY5gRZwcvmPpe1uiTquiZTwJRRRNDde382MlVAgLp b1I014YpaF0u2axANAjKmSihVCKyGk+Xms9tSdN/tKpqUGR63HrXNE05bV1cO2x7c2RV n5EKyXBceZ7X0CyF/2i+2RwAbWMp4TbZZ1rG/MK4w7TS+I2/iAOcV8ByWk6Dj7hmdU6p +njADPY/Z7bLDLrCRT8ndlVymxdQowsk0pfTnkvTkN81ycXLcjGph6CtTv/DlVvQdWD4 6QWM86AKtsUMPi9rzRTUsyXVA7jKKayKgbJxWS6hkikUfsmg9RbeDERfZWabRyWJ3wZ5 lOOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=P3BF8txZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id v70-20020a638949000000b00577a9ed62edsi10149647pgd.419.2023.09.25.06.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 06:06:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=P3BF8txZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 36DE18048C3D; Mon, 25 Sep 2023 03:24:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229582AbjIYKXr (ORCPT <rfc822;pusanteemu@gmail.com> + 29 others); Mon, 25 Sep 2023 06:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbjIYKXm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 25 Sep 2023 06:23:42 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D24FC6 for <linux-kernel@vger.kernel.org>; Mon, 25 Sep 2023 03:23:34 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 1C2EA240105 for <linux-kernel@vger.kernel.org>; Mon, 25 Sep 2023 12:23:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1695637413; bh=qC78CqDCUu8hI+DPLtNoWHc11J1C/tPhLY2OSTqPzUQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=P3BF8txZo6VhO3S1KXPUHAl2EPHvegZDbdGRNTch0zV+4gR7duOE3Qc60z/u8KPd5 EJpMy5yv5pGmQZutRc+zpkkvHO1uyWbn55cOWu732XFmusx5rCsiDDEnGT6v0xFngb f0plb2qlkwDooAjnRvKE0o83JuMbBa6RlYzAecxa8d5A3O96PG0oHbhLpm4bZcmh1t NTa9vCmxRDzNaDQCo7P/8oP7+InCdJDa/DtqZOPL0dweTKDExDZr6MDzLfpANqOSBv U9asjzVrwKfP6sr8fJmFVKE7b0jK6L3Nvp+nrP/iHP708WfLXTFFulUwIYWQ8kiH+l Cdtgh/HGmejHA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RvJqk4dwxz6v7m; Mon, 25 Sep 2023 12:23:30 +0200 (CEST) From: Martin Kepplinger <martink@posteo.de> 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 <martink@posteo.de> Subject: [RFC PATCH 2/2] hid: lenovo: move type checks to lenovo_features_set_cptkbd() Date: Mon, 25 Sep 2023 10:23:02 +0000 Message-Id: <20230925102302.13094-2-martink@posteo.de> In-Reply-To: <20230925102302.13094-1-martink@posteo.de> References: <140b721bc345a846863a37ebf17c3174@lentin.co.uk> <20230925102302.13094-1-martink@posteo.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 25 Sep 2023 03:24:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778014930018451509 X-GMAIL-MSGID: 1778014930018451509 |
Series |
[RFC,1/2] hid: lenovo: Resend all settings on reset_resume for compact keyboards
|
|
Commit Message
Martin Kepplinger
Sept. 25, 2023, 10:23 a.m. UTC
These custom commands will be sent to both the USB keyboard & mouse
devices but only the mouse will respond. Avoid sending known-useless
messages by always prepending the filter before sending them.
Suggested-by: Jamie Lentin <jm@lentin.co.uk>
Signed-off-by: Martin Kepplinger <martink@posteo.de>
---
drivers/hid/hid-lenovo.c | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
Comments
On 2023-09-25 11:23, Martin Kepplinger wrote: > These custom commands will be sent to both the USB keyboard & mouse > devices but only the mouse will respond. Avoid sending known-useless > messages by always prepending the filter before sending them. > > Suggested-by: Jamie Lentin <jm@lentin.co.uk> > Signed-off-by: Martin Kepplinger <martink@posteo.de> > --- > drivers/hid/hid-lenovo.c | 27 +++++++++------------------ > 1 file changed, 9 insertions(+), 18 deletions(-) > > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c > index 29aa6d372bad..922f3e5462f4 100644 > --- a/drivers/hid/hid-lenovo.c > +++ b/drivers/hid/hid-lenovo.c > @@ -521,6 +521,14 @@ static void lenovo_features_set_cptkbd(struct > hid_device *hdev) > int ret; > struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); > > + /* All the custom action happens on the USBMOUSE device for USB */ > + 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; > + } > + > /* > * Tell the keyboard a driver understands it, and turn F7, F9, F11 > into > * regular keys > @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct hid_device > *hdev) > int ret; > struct lenovo_drvdata *cptkbd_data; > > - /* All the custom action happens on the USBMOUSE device for USB */ > - 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; > - } > - I like the idea of doing it once then forgetting about it, but removing this will mean that the "keyboard half" will have it's own set of non-functional sysfs parameters I think? Currently:- # evtest . . . /dev/input/event10: ThinkPad Compact Bluetooth Keyboard with TrackPoint /dev/input/event11: Lenovo ThinkPad Compact USB Keyboard with TrackPoint /dev/input/event12: Lenovo ThinkPad Compact USB Keyboard with TrackPoint # ls -1 /sys/class/input/event*/device/device/fn_lock /sys/class/input/event10/device/device/fn_lock /sys/class/input/event12/device/device/fn_lock (note 11 is missing.) I think the easiest (but ugly) thing to do is to copy-paste this lump of code to the top of lenovo_reset_resume. Cheers, > cptkbd_data = devm_kzalloc(&hdev->dev, > sizeof(*cptkbd_data), > GFP_KERNEL); > @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct hid_device *hdev, > #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; > - } > + lenovo_features_set_cptkbd(hdev); > > return 0; > }
Am Mittwoch, dem 27.09.2023 um 09:19 +0100 schrieb Jamie Lentin: > On 2023-09-25 11:23, Martin Kepplinger wrote: > > These custom commands will be sent to both the USB keyboard & mouse > > devices but only the mouse will respond. Avoid sending known- > > useless > > messages by always prepending the filter before sending them. > > > > Suggested-by: Jamie Lentin <jm@lentin.co.uk> > > Signed-off-by: Martin Kepplinger <martink@posteo.de> > > --- > > drivers/hid/hid-lenovo.c | 27 +++++++++------------------ > > 1 file changed, 9 insertions(+), 18 deletions(-) > > > > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c > > index 29aa6d372bad..922f3e5462f4 100644 > > --- a/drivers/hid/hid-lenovo.c > > +++ b/drivers/hid/hid-lenovo.c > > @@ -521,6 +521,14 @@ static void lenovo_features_set_cptkbd(struct > > hid_device *hdev) > > int ret; > > struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); > > > > + /* All the custom action happens on the USBMOUSE device for > > USB */ > > + 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; > > + } > > + > > /* > > * Tell the keyboard a driver understands it, and turn F7, > > F9, F11 > > into > > * regular keys > > @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct > > hid_device > > *hdev) > > int ret; > > struct lenovo_drvdata *cptkbd_data; > > > > - /* All the custom action happens on the USBMOUSE device for > > USB */ > > - 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; > > - } > > - > > I like the idea of doing it once then forgetting about it, but > removing > this will mean that the "keyboard half" will have it's own set of > non-functional sysfs parameters I think? Currently:- > > # evtest > . . . > /dev/input/event10: ThinkPad Compact Bluetooth Keyboard with > TrackPoint > /dev/input/event11: Lenovo ThinkPad Compact USB Keyboard with > TrackPoint > /dev/input/event12: Lenovo ThinkPad Compact USB Keyboard with > TrackPoint > > # ls -1 /sys/class/input/event*/device/device/fn_lock > /sys/class/input/event10/device/device/fn_lock > /sys/class/input/event12/device/device/fn_lock > > (note 11 is missing.) > > I think the easiest (but ugly) thing to do is to copy-paste this lump > of > code to the top of lenovo_reset_resume. > Cheers, > > > cptkbd_data = devm_kzalloc(&hdev->dev, > > sizeof(*cptkbd_data), > > GFP_KERNEL); > > @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct hid_device > > *hdev, > > #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; > > - } > > + lenovo_features_set_cptkbd(hdev); ok. ignore my change (this whole patch) and look at your addition here, don't you already make sure only the mouse-part gets the messages? you just write switch()case instead of if(); what do you think is missing here? thanks, martin > > > > return 0; > > }
On 2023-09-27 12:20, Martin Kepplinger wrote: > Am Mittwoch, dem 27.09.2023 um 09:19 +0100 schrieb Jamie Lentin: >> On 2023-09-25 11:23, Martin Kepplinger wrote: >> > These custom commands will be sent to both the USB keyboard & mouse >> > devices but only the mouse will respond. Avoid sending known- >> > useless >> > messages by always prepending the filter before sending them. >> > >> > Suggested-by: Jamie Lentin <jm@lentin.co.uk> >> > Signed-off-by: Martin Kepplinger <martink@posteo.de> >> > --- >> > drivers/hid/hid-lenovo.c | 27 +++++++++------------------ >> > 1 file changed, 9 insertions(+), 18 deletions(-) >> > >> > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c >> > index 29aa6d372bad..922f3e5462f4 100644 >> > --- a/drivers/hid/hid-lenovo.c >> > +++ b/drivers/hid/hid-lenovo.c >> > @@ -521,6 +521,14 @@ static void lenovo_features_set_cptkbd(struct >> > hid_device *hdev) >> > int ret; >> > struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); >> > >> > + /* All the custom action happens on the USBMOUSE device for >> > USB */ >> > + 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; >> > + } >> > + >> > /* >> > * Tell the keyboard a driver understands it, and turn F7, >> > F9, F11 >> > into >> > * regular keys >> > @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct >> > hid_device >> > *hdev) >> > int ret; >> > struct lenovo_drvdata *cptkbd_data; >> > >> > - /* All the custom action happens on the USBMOUSE device for >> > USB */ >> > - 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; >> > - } >> > - >> >> I like the idea of doing it once then forgetting about it, but >> removing >> this will mean that the "keyboard half" will have it's own set of >> non-functional sysfs parameters I think? Currently:- >> >> # evtest >> . . . >> /dev/input/event10: ThinkPad Compact Bluetooth Keyboard with >> TrackPoint >> /dev/input/event11: Lenovo ThinkPad Compact USB Keyboard with >> TrackPoint >> /dev/input/event12: Lenovo ThinkPad Compact USB Keyboard with >> TrackPoint >> >> # ls -1 /sys/class/input/event*/device/device/fn_lock >> /sys/class/input/event10/device/device/fn_lock >> /sys/class/input/event12/device/device/fn_lock >> >> (note 11 is missing.) >> >> I think the easiest (but ugly) thing to do is to copy-paste this lump >> of >> code to the top of lenovo_reset_resume. >> Cheers, >> >> > cptkbd_data = devm_kzalloc(&hdev->dev, >> > sizeof(*cptkbd_data), >> > GFP_KERNEL); >> > @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct hid_device >> > *hdev, >> > #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; >> > - } >> > + lenovo_features_set_cptkbd(hdev); > > ok. ignore my change (this whole patch) and look at your addition here, > don't you already make sure only the mouse-part gets the messages? you > just write switch()case instead of if(); what do you think is missing > here? Correct, this switch statement() that you're removing in this patch already does exactly this, so replacing it with the if()-and-return-early block would result in equivalent code (ignoring the Trackpoint keyboard II). That suggestion wasn't the most helpful of mine, sorry! The reason I originally used a switch here is for symmetry with lenovo_probe(), lenovo_remove(), etc. It might some day be useful to add something like: case USB_DEVICE_ID_LENOVO_X1_TAB: lenovo_reset_resume_tp10ubkbd(hdev); break; ...to the switch. For completeness, lenovo_reset_resume() should probably call a separate lenovo_reset_resume_cptkbd() that does the work. For just 3 lines of code it didn't seem worth it at the time though. Cheers, > > thanks, > martin > >> > >> > return 0; >> > }
Am Donnerstag, dem 28.09.2023 um 22:06 +0100 schrieb Jamie Lentin: > On 2023-09-27 12:20, Martin Kepplinger wrote: > > Am Mittwoch, dem 27.09.2023 um 09:19 +0100 schrieb Jamie Lentin: > > > On 2023-09-25 11:23, Martin Kepplinger wrote: > > > > These custom commands will be sent to both the USB keyboard & > > > > mouse > > > > devices but only the mouse will respond. Avoid sending known- > > > > useless > > > > messages by always prepending the filter before sending them. > > > > > > > > Suggested-by: Jamie Lentin <jm@lentin.co.uk> > > > > Signed-off-by: Martin Kepplinger <martink@posteo.de> > > > > --- > > > > drivers/hid/hid-lenovo.c | 27 +++++++++------------------ > > > > 1 file changed, 9 insertions(+), 18 deletions(-) > > > > > > > > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid- > > > > lenovo.c > > > > index 29aa6d372bad..922f3e5462f4 100644 > > > > --- a/drivers/hid/hid-lenovo.c > > > > +++ b/drivers/hid/hid-lenovo.c > > > > @@ -521,6 +521,14 @@ static void > > > > lenovo_features_set_cptkbd(struct > > > > hid_device *hdev) > > > > int ret; > > > > struct lenovo_drvdata *cptkbd_data = > > > > hid_get_drvdata(hdev); > > > > > > > > + /* All the custom action happens on the USBMOUSE device > > > > for > > > > USB */ > > > > + 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; > > > > + } > > > > + > > > > /* > > > > * Tell the keyboard a driver understands it, and turn > > > > F7, > > > > F9, F11 > > > > into > > > > * regular keys > > > > @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct > > > > hid_device > > > > *hdev) > > > > int ret; > > > > struct lenovo_drvdata *cptkbd_data; > > > > > > > > - /* All the custom action happens on the USBMOUSE device > > > > for > > > > USB */ > > > > - 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; > > > > - } > > > > - > > > > > > I like the idea of doing it once then forgetting about it, but > > > removing > > > this will mean that the "keyboard half" will have it's own set of > > > non-functional sysfs parameters I think? Currently:- > > > > > > # evtest > > > . . . > > > /dev/input/event10: ThinkPad Compact Bluetooth Keyboard with > > > TrackPoint > > > /dev/input/event11: Lenovo ThinkPad Compact USB Keyboard with > > > TrackPoint > > > /dev/input/event12: Lenovo ThinkPad Compact USB Keyboard with > > > TrackPoint > > > > > > # ls -1 /sys/class/input/event*/device/device/fn_lock > > > /sys/class/input/event10/device/device/fn_lock > > > /sys/class/input/event12/device/device/fn_lock > > > > > > (note 11 is missing.) > > > > > > I think the easiest (but ugly) thing to do is to copy-paste this > > > lump > > > of > > > code to the top of lenovo_reset_resume. > > > Cheers, > > > > > > > cptkbd_data = devm_kzalloc(&hdev->dev, > > > > sizeof(*cptkbd_data), > > > > GFP_KERNEL); > > > > @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct > > > > hid_device > > > > *hdev, > > > > #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; > > > > - } > > > > + lenovo_features_set_cptkbd(hdev); > > > > ok. ignore my change (this whole patch) and look at your addition > > here, > > don't you already make sure only the mouse-part gets the messages? > > you > > just write switch()case instead of if(); what do you think is > > missing > > here? > > Correct, this switch statement() that you're removing in this patch > already does exactly this, so replacing it with the > if()-and-return-early block would result in equivalent code (ignoring > the Trackpoint keyboard II). That suggestion wasn't the most helpful > of > mine, sorry! > > The reason I originally used a switch here is for symmetry with > lenovo_probe(), lenovo_remove(), etc. It might some day be useful to > add > something like: > > case USB_DEVICE_ID_LENOVO_X1_TAB: > lenovo_reset_resume_tp10ubkbd(hdev); > break; > > ...to the switch. For completeness, lenovo_reset_resume() should > probably call a separate lenovo_reset_resume_cptkbd() that does the > work. For just 3 lines of code it didn't seem worth it at the time > though. > > Cheers, ok your original patch seems to basically be a valid first fix. Should I send it on your behalf (with you as author) or do you want to send it yourself? Let's get this fixed :) thanks, martin
On 2023-09-30 10:26, Martin Kepplinger wrote: > Am Donnerstag, dem 28.09.2023 um 22:06 +0100 schrieb Jamie Lentin: >> On 2023-09-27 12:20, Martin Kepplinger wrote: >> > Am Mittwoch, dem 27.09.2023 um 09:19 +0100 schrieb Jamie Lentin: >> > > On 2023-09-25 11:23, Martin Kepplinger wrote: >> > > > These custom commands will be sent to both the USB keyboard & >> > > > mouse >> > > > devices but only the mouse will respond. Avoid sending known- >> > > > useless >> > > > messages by always prepending the filter before sending them. >> > > > >> > > > Suggested-by: Jamie Lentin <jm@lentin.co.uk> >> > > > Signed-off-by: Martin Kepplinger <martink@posteo.de> >> > > > --- >> > > > drivers/hid/hid-lenovo.c | 27 +++++++++------------------ >> > > > 1 file changed, 9 insertions(+), 18 deletions(-) >> > > > >> > > > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid- >> > > > lenovo.c >> > > > index 29aa6d372bad..922f3e5462f4 100644 >> > > > --- a/drivers/hid/hid-lenovo.c >> > > > +++ b/drivers/hid/hid-lenovo.c >> > > > @@ -521,6 +521,14 @@ static void >> > > > lenovo_features_set_cptkbd(struct >> > > > hid_device *hdev) >> > > > int ret; >> > > > struct lenovo_drvdata *cptkbd_data = >> > > > hid_get_drvdata(hdev); >> > > > >> > > > + /* All the custom action happens on the USBMOUSE device >> > > > for >> > > > USB */ >> > > > + 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; >> > > > + } >> > > > + >> > > > /* >> > > > * Tell the keyboard a driver understands it, and turn >> > > > F7, >> > > > F9, F11 >> > > > into >> > > > * regular keys >> > > > @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct >> > > > hid_device >> > > > *hdev) >> > > > int ret; >> > > > struct lenovo_drvdata *cptkbd_data; >> > > > >> > > > - /* All the custom action happens on the USBMOUSE device >> > > > for >> > > > USB */ >> > > > - 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; >> > > > - } >> > > > - >> > > >> > > I like the idea of doing it once then forgetting about it, but >> > > removing >> > > this will mean that the "keyboard half" will have it's own set of >> > > non-functional sysfs parameters I think? Currently:- >> > > >> > > # evtest >> > > . . . >> > > /dev/input/event10: ThinkPad Compact Bluetooth Keyboard with >> > > TrackPoint >> > > /dev/input/event11: Lenovo ThinkPad Compact USB Keyboard with >> > > TrackPoint >> > > /dev/input/event12: Lenovo ThinkPad Compact USB Keyboard with >> > > TrackPoint >> > > >> > > # ls -1 /sys/class/input/event*/device/device/fn_lock >> > > /sys/class/input/event10/device/device/fn_lock >> > > /sys/class/input/event12/device/device/fn_lock >> > > >> > > (note 11 is missing.) >> > > >> > > I think the easiest (but ugly) thing to do is to copy-paste this >> > > lump >> > > of >> > > code to the top of lenovo_reset_resume. >> > > Cheers, >> > > >> > > > cptkbd_data = devm_kzalloc(&hdev->dev, >> > > > sizeof(*cptkbd_data), >> > > > GFP_KERNEL); >> > > > @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct >> > > > hid_device >> > > > *hdev, >> > > > #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; >> > > > - } >> > > > + lenovo_features_set_cptkbd(hdev); >> > >> > ok. ignore my change (this whole patch) and look at your addition >> > here, >> > don't you already make sure only the mouse-part gets the messages? >> > you >> > just write switch()case instead of if(); what do you think is >> > missing >> > here? >> >> Correct, this switch statement() that you're removing in this patch >> already does exactly this, so replacing it with the >> if()-and-return-early block would result in equivalent code (ignoring >> the Trackpoint keyboard II). That suggestion wasn't the most helpful >> of >> mine, sorry! >> >> The reason I originally used a switch here is for symmetry with >> lenovo_probe(), lenovo_remove(), etc. It might some day be useful to >> add >> something like: >> >> case USB_DEVICE_ID_LENOVO_X1_TAB: >> lenovo_reset_resume_tp10ubkbd(hdev); >> break; >> >> ...to the switch. For completeness, lenovo_reset_resume() should >> probably call a separate lenovo_reset_resume_cptkbd() that does the >> work. For just 3 lines of code it didn't seem worth it at the time >> though. >> >> Cheers, > > ok your original patch seems to basically be a valid first fix. Should > I send it on your behalf (with you as author) or do you want to send it > yourself? Let's get this fixed :) If it's working for you and you don't mind, feel free send it on my behalf. I don't have the hardware to test the patch currently. Thanks! > > thanks, > martin
diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index 29aa6d372bad..922f3e5462f4 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -521,6 +521,14 @@ static void lenovo_features_set_cptkbd(struct hid_device *hdev) int ret; struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); + /* All the custom action happens on the USBMOUSE device for USB */ + 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; + } + /* * Tell the keyboard a driver understands it, and turn F7, F9, F11 into * regular keys @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct hid_device *hdev) int ret; struct lenovo_drvdata *cptkbd_data; - /* All the custom action happens on the USBMOUSE device for USB */ - 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; - } - cptkbd_data = devm_kzalloc(&hdev->dev, sizeof(*cptkbd_data), GFP_KERNEL); @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct hid_device *hdev, #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; - } + lenovo_features_set_cptkbd(hdev); return 0; }