Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2693428ybg; Sat, 19 Oct 2019 21:42:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZ6cESprVwCNche4jowk8YBdr7JKKlZmqz9+WV4SsOxm4R8kyOyezL2/UWDMSJ5EgxIf3A X-Received: by 2002:a05:6402:68b:: with SMTP id f11mr17527850edy.173.1571546578655; Sat, 19 Oct 2019 21:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571546578; cv=none; d=google.com; s=arc-20160816; b=zGAK9juT3z1EO+P8PzX0oWVUas5I1TXwUBXVemp9YIVDLfJbgOgaszsRSFdYogfJps G7+EcbqRXarIUueUnPCqrD9Ls18bHhp4+d5GEaryu67e2w/gSQGgYEuba/Mnx7jzmCvJ Aaf4mZYJYiQvDR8cqQvS+CU845VVz4P3+PK/19W+C9XA6sE0iyexSJXlIKZWUX2Byi+y 6SojcxdQZvO9MuYqUt1fNCQDIUSXyI/kxmSWXiMFWcQuxaIyadkSyI/L3XXoMsJnUkwu VbFVKUeWfGez5eqkm29vZoSAM1HraF25fca1qxhctzLtuRBzkBw2XfKlDrk0r1CMmGyq JQsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :feedback-id:message-id:subject:reply-to:cc:from:to:dkim-signature :date; bh=pSC4pHYQ/b0tWo3cI9DVOG3uVTnNvIMp2IARbyO1L0c=; b=bjIS9juWSsmguN3okVgDq6qqudwpR622dPSvN+QoMPTf/FAWU+GkOtjdn5I6KgnB7D H/kQXm2gQ7x0EVd8kymyRPfge3n8ew6uK/6YqMCIJL34fUl1p6pZSlVdea/Zn3hX434K jxhuTdbemTv06PmwU0hXezeQ50uAk3C2ZhshBm1ntGr5nYA9H0rjHy3+8q20ZA02rouV N4ioMQs6ik2f3E59zi+5wPUphxCKuR01ltKWBQNa9AHGmjoh/wcOgEFTbRShUf7p1ikD ncAmE33/ELGMur5f7GGzk/zTEtMgLIkN1FMFTQQu8UP63KjLR4D41quj0xTORL7I0tlq D09Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=default header.b=HLqHuelq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d17si6540740edv.76.2019.10.19.21.42.35; Sat, 19 Oct 2019 21:42:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=default header.b=HLqHuelq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726217AbfJTEl0 (ORCPT + 99 others); Sun, 20 Oct 2019 00:41:26 -0400 Received: from mail-40130.protonmail.ch ([185.70.40.130]:17218 "EHLO mail-40130.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbfJTElZ (ORCPT ); Sun, 20 Oct 2019 00:41:25 -0400 Date: Sun, 20 Oct 2019 04:41:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1571546481; bh=pSC4pHYQ/b0tWo3cI9DVOG3uVTnNvIMp2IARbyO1L0c=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=HLqHuelqidevexwLmaUmJ7xcW0Y54D3jC7gmKp7PKPOcU4v9Syua0Fv/9Zl3sZ6Pg 8wJG93rdbxFyP0MYqPMYBtqa3Y4LnjrX9c7Lou2BfbAVuaEV1bVJHF0qyIHw0Otx+p U3mFKxVlPhEAOaRO4zXTX8roR1/1J+Om7UqXC5Fc= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: Benjamin Tissoires , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , =?UTF-8?Q?Filipe_La=C3=ADns?= , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v7 1/3] HID: logitech-hidpp: Support translations from short to long reports Message-ID: Feedback-ID: 18B_FC5q-t32TXzMsVp9BgkgrdNH3iwklfW8WOrHrcxZA0WRj7JodCh5VXKxs6A3OaiHK0QNd8wi3SImKex8yQ==:Ext:ProtonMail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch allows short reports to be translated into long reports. hidpp_validate_device now returns a u8 instead of a bool which represents the supported reports. The corresponding bits (i.e. HIDPP_REPORT_*_SUPPORTED) are set if an HID++ report is supported. If a short report is being sent and the device does not support it, it is instead sent as a long report. Thanks, Mazin Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hi= dpp.c index e9bba282f9c1..ee604b17514f 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -49,6 +49,10 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_REPORT_LONG_LENGTH=09=0920 #define HIDPP_REPORT_VERY_LONG_MAX_LENGTH=0964 +#define HIDPP_REPORT_SHORT_SUPPORTED=09=09BIT(0) +#define HIDPP_REPORT_LONG_SUPPORTED=09=09BIT(1) +#define HIDPP_REPORT_VERY_LONG_SUPPORTED=09BIT(2) + #define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS=090x03 #define HIDPP_SUB_ID_ROLLER=09=09=090x05 #define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS=09=090x06 @@ -183,6 +187,7 @@ struct hidpp_device { =09unsigned long quirks; =09unsigned long capabilities; +=09u8 supported_reports; =09struct hidpp_battery battery; =09struct hidpp_scroll_counter vertical_wheel_counter; @@ -340,6 +345,11 @@ static int hidpp_send_rap_command_sync(struct hidpp_de= vice *hidpp_dev, =09struct hidpp_report *message; =09int ret, max_count; +=09/* Send as long report if short reports are not supported. */ +=09if (report_id =3D=3D REPORT_ID_HIDPP_SHORT && +=09 !(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED)) +=09=09report_id =3D REPORT_ID_HIDPP_LONG; + =09switch (report_id) { =09case REPORT_ID_HIDPP_SHORT: =09=09max_count =3D HIDPP_REPORT_SHORT_LENGTH - 4; @@ -3458,10 +3468,11 @@ static int hidpp_get_report_length(struct hid_devic= e *hdev, int id) =09return report->field[0]->report_count + 1; } -static bool hidpp_validate_device(struct hid_device *hdev) +static u8 hidpp_validate_device(struct hid_device *hdev) { =09struct hidpp_device *hidpp =3D hid_get_drvdata(hdev); -=09int id, report_length, supported_reports =3D 0; +=09int id, report_length; +=09u8 supported_reports =3D 0; =09id =3D REPORT_ID_HIDPP_SHORT; =09report_length =3D hidpp_get_report_length(hdev, id); @@ -3469,7 +3480,7 @@ static bool hidpp_validate_device(struct hid_device *= hdev) =09=09if (report_length < HIDPP_REPORT_SHORT_LENGTH) =09=09=09goto bad_device; -=09=09supported_reports++; +=09=09supported_reports |=3D HIDPP_REPORT_SHORT_SUPPORTED; =09} =09id =3D REPORT_ID_HIDPP_LONG; @@ -3478,7 +3489,7 @@ static bool hidpp_validate_device(struct hid_device *= hdev) =09=09if (report_length < HIDPP_REPORT_LONG_LENGTH) =09=09=09goto bad_device; -=09=09supported_reports++; +=09=09supported_reports |=3D HIDPP_REPORT_LONG_SUPPORTED; =09} =09id =3D REPORT_ID_HIDPP_VERY_LONG; @@ -3488,7 +3499,7 @@ static bool hidpp_validate_device(struct hid_device *= hdev) =09=09 report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH) =09=09=09goto bad_device; -=09=09supported_reports++; +=09=09supported_reports |=3D HIDPP_REPORT_VERY_LONG_SUPPORTED; =09=09hidpp->very_long_report_length =3D report_length; =09} @@ -3536,7 +3547,9 @@ static int hidpp_probe(struct hid_device *hdev, const= struct hid_device_id *id) =09/* =09 * Make sure the device is HID++ capable, otherwise treat as generic HI= D =09 */ -=09if (!hidpp_validate_device(hdev)) { +=09hidpp->supported_reports =3D hidpp_validate_device(hdev); + +=09if (!hidpp->supported_reports) { =09=09hid_set_drvdata(hdev, NULL); =09=09devm_kfree(&hdev->dev, hidpp); =09=09return hid_hw_start(hdev, HID_CONNECT_DEFAULT); -- 2.23.0