Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2382012lqp; Sun, 24 Mar 2024 16:57:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVFsvaZfK6dWzVykWOelrAwzW/S3JMRISRYdcCPA4egfTxnnenogprz+vnEpHE6Bk1f+eoxPtSSr6GsJmNxTI+VDRXJ5gAnTVfhbfN0sA== X-Google-Smtp-Source: AGHT+IH0a0bHE5sS37q9hNeUIrguesoatsz+4+BC8jsv24KIxoV+HHtEtfw/bz/XutVCPmxIBlE5 X-Received: by 2002:a05:620a:20d5:b0:789:d583:bdc0 with SMTP id f21-20020a05620a20d500b00789d583bdc0mr5580163qka.54.1711324658825; Sun, 24 Mar 2024 16:57:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324658; cv=pass; d=google.com; s=arc-20160816; b=wx0pv7OavYMYJ25he3VZ70iGDKU+p5yT5OBp6JNEWiDspXEu6y1QGjaWC17n1MjNef ypv37Wmt1Fxf4AhXqQtTQ/yG3cRUN5wkEDDRrSiBxF2X8z3W6jVwEyDNj/NUGQRs+T/R ZM2jprG15PodI6xE9/vkEHulI3YdOvcjJWyIXNMA9ogQqvaFOhnBk1wdZBPkQYXRobyG bu7qd3x19AIhzkdL7Lg3tpPqo8n+pshqARRj0bIDNPQ+u4maQuFFyv0t4lQbuPo7WewL mbYT0OyQtHT+0u9jjaBvX+MFJBfpN4F5TFvgwyYcnT/yNW3PQoN00rCmlR4zIHjOMMGR vutA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=O5JCgnKNh3XP2c6Sp/EUXyOO4TvUK/9MMZuxOFDMiMY=; fh=vSTrMoZsxl3//Kboz4HO9SlBz9zMvttrkeApKau3fxY=; b=rAOr6899Uf5bgJsiNHM9OcIst12rg0pDUWiVH5i+JPY3CquvwJmXnjMC7YYOAjeOvy KqM72oZNNKBVCqkimQChFh90zNPmFslctw0SVAoaXCxTjOsfS+IVUvXVa092ZIR/mYgT /lbSGyYitI7mf4vZdeH9qHjL8VfUKI6fVYe5uscbSbGhS80COjWqy/UpsGQ7YpPzQwC8 nZEGbmGeQ4ENTTGQ4Av5AEixcztevcXzM0hPOGAvZe4Ila0S2ctJtYp7tiWdrGLKjMoA /d9IEdNx4g7CV1/fK6YrwgCpht99OQ/GExKTHBQF4pIHP0vEGP1+eVMGtr3v1q10So7v jaNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MpoppMnI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113268-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113268-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e19-20020a05620a209300b0078a433bacb7si4265856qka.26.2024.03.24.16.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:57:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113268-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MpoppMnI; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113268-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113268-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8A0A81C22F76 for ; Sun, 24 Mar 2024 23:57:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84A4A189A4F; Sun, 24 Mar 2024 22:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MpoppMnI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94BB8136E27; Sun, 24 Mar 2024 22:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320067; cv=none; b=Ri0C/FidlBMsq2Wj6K8Rr1NFgL4rqPWaBP5t2VAM3i7Q8gp64+bcv2Y8ANn9YpmcCokty5wBBqP8ZMwPj+buZ6EyF5rVMFmDJipc9N6zWguFKLPzzAn5tX9KMXsL19DjAzBcR0mfWo8o52hHa1L7j/LO8L9S79p+Sp6TS84nw+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320067; c=relaxed/simple; bh=k0CHCQeQYAxizY/a36oGNxW78++AXdIg+U+sNWUr7Wc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lBP6Ro4uKaD02AP6bPAFTFfQVoQ8NulSFUjne1eL5CQI8jwc3kLAtuctaHet97StccVeJqP+V7N07BJDmwJarypF1S78g4v1hLWluOQX22ta9uRe/4fR02JWT4IblXepvqS/ERnaCECirmxLyc+Q17ekZj+WL69bAepPL98Wquc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MpoppMnI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1574C433A6; Sun, 24 Mar 2024 22:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320067; bh=k0CHCQeQYAxizY/a36oGNxW78++AXdIg+U+sNWUr7Wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MpoppMnI3ik6oZcmkNQF5jofg5C0CnX1mfV0hP5o8nctMqdFu+u0wJ4RTQluNowPs SZQSqgr9oHNdcEwMDcH+1BLU6BaBCHIM0L5UeJQVuELsLLjjOcJa0BLPRLlceXt1uC l38s/aRV/jqCSta7iZO1cGv8n/kh6Nr+eL4+rB6iZ9a9Tea/wC9JhTZALt5uUvjMGY d8PyLCwT9i2iXZP0qHK9Yj2qHTbgPoNbV7ffT7DPu1NEJphCFbtuBpEMy0EYK/gOgk iycDjolvyybKOxkLGvhn9Rqhr0hB3XC9IzZYSgQjyJ3SoJadX/JKpA894uBoNnzS6k HaQojoCLQrt/Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mikhail Khvainitski , Jiri Kosina , Sasha Levin Subject: [PATCH 6.8 377/715] HID: lenovo: Add middleclick_workaround sysfs knob for cptkbd Date: Sun, 24 Mar 2024 18:29:16 -0400 Message-ID: <20240324223455.1342824-378-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Mikhail Khvainitski [ Upstream commit 2814646f76f8518326964f12ff20aaee70ba154d ] Previous attempt to autodetect well-behaving patched firmware introduced in commit 46a0a2c96f0f ("HID: lenovo: Detect quirk-free fw on cptkbd and stop applying workaround") has shown that there are false-positives on original firmware (on both 1st gen and 2nd gen keyboards) which causes the middle button click workaround to be mistakenly disabled. This commit adds explicit parameter to sysfs to control this workaround. Fixes: 46a0a2c96f0f ("HID: lenovo: Detect quirk-free fw on cptkbd and stop applying workaround") Fixes: 43527a0094c1 ("HID: lenovo: Restrict detection of patched firmware only to USB cptkbd") Signed-off-by: Mikhail Khvainitski Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-lenovo.c | 57 +++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index 149a3c74346b4..f86c1ea83a037 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -54,10 +54,10 @@ struct lenovo_drvdata { /* 0: Up * 1: Down (undecided) * 2: Scrolling - * 3: Patched firmware, disable workaround */ u8 middlebutton_state; bool fn_lock; + bool middleclick_workaround_cptkbd; }; #define map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c)) @@ -621,6 +621,36 @@ static ssize_t attr_sensitivity_store_cptkbd(struct device *dev, return count; } +static ssize_t attr_middleclick_workaround_show_cptkbd(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct hid_device *hdev = to_hid_device(dev); + struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); + + return snprintf(buf, PAGE_SIZE, "%u\n", + cptkbd_data->middleclick_workaround_cptkbd); +} + +static ssize_t attr_middleclick_workaround_store_cptkbd(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct hid_device *hdev = to_hid_device(dev); + struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); + int value; + + if (kstrtoint(buf, 10, &value)) + return -EINVAL; + if (value < 0 || value > 1) + return -EINVAL; + + cptkbd_data->middleclick_workaround_cptkbd = !!value; + + return count; +} + static struct device_attribute dev_attr_fn_lock = __ATTR(fn_lock, S_IWUSR | S_IRUGO, @@ -632,10 +662,16 @@ static struct device_attribute dev_attr_sensitivity_cptkbd = attr_sensitivity_show_cptkbd, attr_sensitivity_store_cptkbd); +static struct device_attribute dev_attr_middleclick_workaround_cptkbd = + __ATTR(middleclick_workaround, S_IWUSR | S_IRUGO, + attr_middleclick_workaround_show_cptkbd, + attr_middleclick_workaround_store_cptkbd); + static struct attribute *lenovo_attributes_cptkbd[] = { &dev_attr_fn_lock.attr, &dev_attr_sensitivity_cptkbd.attr, + &dev_attr_middleclick_workaround_cptkbd.attr, NULL }; @@ -686,23 +722,7 @@ static int lenovo_event_cptkbd(struct hid_device *hdev, { struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); - if (cptkbd_data->middlebutton_state != 3) { - /* REL_X and REL_Y events during middle button pressed - * are only possible on patched, bug-free firmware - * so set middlebutton_state to 3 - * to never apply workaround anymore - */ - if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD && - cptkbd_data->middlebutton_state == 1 && - usage->type == EV_REL && - (usage->code == REL_X || usage->code == REL_Y)) { - cptkbd_data->middlebutton_state = 3; - /* send middle button press which was hold before */ - input_event(field->hidinput->input, - EV_KEY, BTN_MIDDLE, 1); - input_sync(field->hidinput->input); - } - + if (cptkbd_data->middleclick_workaround_cptkbd) { /* "wheel" scroll events */ if (usage->type == EV_REL && (usage->code == REL_WHEEL || usage->code == REL_HWHEEL)) { @@ -1166,6 +1186,7 @@ static int lenovo_probe_cptkbd(struct hid_device *hdev) cptkbd_data->middlebutton_state = 0; cptkbd_data->fn_lock = true; cptkbd_data->sensitivity = 0x05; + cptkbd_data->middleclick_workaround_cptkbd = true; lenovo_features_set_cptkbd(hdev); ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_cptkbd); -- 2.43.0