Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp3778767rwj; Tue, 20 Dec 2022 01:34:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wVqKY/Ez99WgK8ZTXnGgp5LaH5dRPy+mCDQMRZFyE3nDsw9628uhdmYa+GbjEKFmqt/e3 X-Received: by 2002:a17:907:20ce:b0:7c1:6344:845 with SMTP id qq14-20020a17090720ce00b007c163440845mr31042445ejb.34.1671528872224; Tue, 20 Dec 2022 01:34:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671528872; cv=none; d=google.com; s=arc-20160816; b=VzVTnjMjwwcjez1yg0qd/E0ES3gGjmZTMQu0nG4BVMxMb4pt0JeDXoqqi4g7enRv6F zQMdhRjS4mYJ4FLKYPf733hhfeLVSJex/Fuqv7PbejjzpucNcNJkZbS7kX9yMXSbQrg9 aANdQL2u3rqFwKa6NzvGmGYv1dmv3EofL5EGaPfajyM1wrvA9gG2UcmzjX+cj1oIZuIR E81rwQT93phh6JA4dGgxSJ3RlnAK3FknLqMg8giSfUy3OV0Rljla+OFAxCZZhjaqu8k/ rZnfgxws16J9k0WrUrqKCzOJHTaTeY8JWJQc0QSW+BZDUstrJ45LVyV8VkNCI0vxmAtt l7Tg== 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; bh=yAs4cr953ahf5GRngcmeIUy0Avaj9K/QirQTmIpWJsk=; b=LnhUqArrlLLZZeW4NuTwBuyEU6rTlZuHu2Mxvz92hTyBMQ1smQEkC8a0YoOU4llpp5 c8CoMGgCSCQZSw5a7ba9DwhEx0+ULX4K2jG6H0Mpi0tTyVEm4SjKDdMFIjzU08QEahGC Fd22ZLQEWNQLwRdDg8HIvSIpVdjbmI3o7KsT1E5LKgEd6E7F52NTbYyDIf585PvO9gCg fZU3B79tnm7lU69qVMldPmOMVcpB197gRD81JxpQmTGANP/7fA/777JXwGQROjhf3D5R tlle1W3vRYRLeHZPW8LISuCtbdaweXllbCk46pujALdWBCoiBzfMixR1YwdLjKSvjYel qanA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a056402168c00b0046c24dd6f2esi9743604edv.235.2022.12.20.01.34.15; Tue, 20 Dec 2022 01:34:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233468AbiLTJW3 (ORCPT + 70 others); Tue, 20 Dec 2022 04:22:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233389AbiLTJWP (ORCPT ); Tue, 20 Dec 2022 04:22:15 -0500 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B8C4C2E; Tue, 20 Dec 2022 01:22:13 -0800 (PST) Received: (Authenticated sender: hadess@hadess.net) by mail.gandi.net (Postfix) with ESMTPSA id BCC1C1C000A; Tue, 20 Dec 2022 09:22:10 +0000 (UTC) From: Bastien Nocera To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , "Peter F . Patel-Schneider" , =?UTF-8?q?Filipe=20La=C3=ADns?= , Nestor Lopez Casado Subject: [PATCH 2/3] HID: logitech-hidpp: Don't restart communication if not necessary Date: Tue, 20 Dec 2022 10:22:06 +0100 Message-Id: <20221220092207.428640-2-hadess@hadess.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221220092207.428640-1-hadess@hadess.net> References: <20221220092207.428640-1-hadess@hadess.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, 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 Don't stop and restart communication with the device unless we need to modify the connect flags used because of a device quirk. --- drivers/hid/hid-logitech-hidpp.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 7f9187201913..b4e4a8c79c75 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4310,6 +4310,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) bool connected; unsigned int connect_mask = HID_CONNECT_DEFAULT; struct hidpp_ff_private_data data; + bool will_restart = false; /* report_fixup needs drvdata to be set before we call hid_parse */ hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); @@ -4360,6 +4361,9 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } + if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) + will_restart = true; + INIT_WORK(&hidpp->work, delayed_work_cb); mutex_init(&hidpp->send_mutex); init_waitqueue_head(&hidpp->wait); @@ -4374,7 +4378,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) * Plain USB connections need to actually call start and open * on the transport driver to allow incoming data. */ - ret = hid_hw_start(hdev, 0); + ret = hid_hw_start(hdev, will_restart ? 0 : connect_mask); if (ret) { hid_err(hdev, "hw start failed\n"); goto hid_hw_start_fail; @@ -4411,6 +4415,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hidpp->wireless_feature_index = 0; else if (ret) goto hid_hw_init_fail; + ret = 0; } if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { @@ -4425,19 +4430,21 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hidpp_connect_event(hidpp); - /* Reset the HID node state */ - hid_device_io_stop(hdev); - hid_hw_close(hdev); - hid_hw_stop(hdev); + if (will_restart) { + /* Reset the HID node state */ + hid_device_io_stop(hdev); + hid_hw_close(hdev); + hid_hw_stop(hdev); - if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) - connect_mask &= ~HID_CONNECT_HIDINPUT; + if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) + connect_mask &= ~HID_CONNECT_HIDINPUT; - /* Now export the actual inputs and hidraw nodes to the world */ - ret = hid_hw_start(hdev, connect_mask); - if (ret) { - hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); - goto hid_hw_start_fail; + /* Now export the actual inputs and hidraw nodes to the world */ + ret = hid_hw_start(hdev, connect_mask); + if (ret) { + hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); + goto hid_hw_start_fail; + } } if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { -- 2.38.1