From patchwork Sun Oct 20 04:41:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11200575 X-Patchwork-Delegate: benjamin.tissoires@redhat.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E569C112C for ; Sun, 20 Oct 2019 04:41:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3F5A222C2 for ; Sun, 20 Oct 2019 04:41:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="HLqHuelq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726190AbfJTElY (ORCPT ); Sun, 20 Oct 2019 00:41:24 -0400 Received: from mail-40135.protonmail.ch ([185.70.40.135]:63056 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfJTElY (ORCPT ); Sun, 20 Oct 2019 00:41:24 -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?Fi?= =?utf-8?q?lipe_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 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-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@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(-) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.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 20 #define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64 +#define HIDPP_REPORT_SHORT_SUPPORTED BIT(0) +#define HIDPP_REPORT_LONG_SUPPORTED BIT(1) +#define HIDPP_REPORT_VERY_LONG_SUPPORTED BIT(2) + #define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03 #define HIDPP_SUB_ID_ROLLER 0x05 #define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06 @@ -183,6 +187,7 @@ struct hidpp_device { unsigned long quirks; unsigned long capabilities; + u8 supported_reports; struct hidpp_battery battery; struct hidpp_scroll_counter vertical_wheel_counter; @@ -340,6 +345,11 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev, struct hidpp_report *message; int ret, max_count; + /* Send as long report if short reports are not supported. */ + if (report_id == REPORT_ID_HIDPP_SHORT && + !(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED)) + report_id = REPORT_ID_HIDPP_LONG; + switch (report_id) { case REPORT_ID_HIDPP_SHORT: max_count = HIDPP_REPORT_SHORT_LENGTH - 4; @@ -3458,10 +3468,11 @@ static int hidpp_get_report_length(struct hid_device *hdev, int id) return report->field[0]->report_count + 1; } -static bool hidpp_validate_device(struct hid_device *hdev) +static u8 hidpp_validate_device(struct hid_device *hdev) { struct hidpp_device *hidpp = hid_get_drvdata(hdev); - int id, report_length, supported_reports = 0; + int id, report_length; + u8 supported_reports = 0; id = REPORT_ID_HIDPP_SHORT; report_length = hidpp_get_report_length(hdev, id); @@ -3469,7 +3480,7 @@ static bool hidpp_validate_device(struct hid_device *hdev) if (report_length < HIDPP_REPORT_SHORT_LENGTH) goto bad_device; - supported_reports++; + supported_reports |= HIDPP_REPORT_SHORT_SUPPORTED; } id = REPORT_ID_HIDPP_LONG; @@ -3478,7 +3489,7 @@ static bool hidpp_validate_device(struct hid_device *hdev) if (report_length < HIDPP_REPORT_LONG_LENGTH) goto bad_device; - supported_reports++; + supported_reports |= HIDPP_REPORT_LONG_SUPPORTED; } id = REPORT_ID_HIDPP_VERY_LONG; @@ -3488,7 +3499,7 @@ static bool hidpp_validate_device(struct hid_device *hdev) report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH) goto bad_device; - supported_reports++; + supported_reports |= HIDPP_REPORT_VERY_LONG_SUPPORTED; hidpp->very_long_report_length = report_length; } @@ -3536,7 +3547,9 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) /* * Make sure the device is HID++ capable, otherwise treat as generic HID */ - if (!hidpp_validate_device(hdev)) { + hidpp->supported_reports = hidpp_validate_device(hdev); + + if (!hidpp->supported_reports) { hid_set_drvdata(hdev, NULL); devm_kfree(&hdev->dev, hidpp); return hid_hw_start(hdev, HID_CONNECT_DEFAULT); From patchwork Sun Oct 20 04:42:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11200577 X-Patchwork-Delegate: benjamin.tissoires@redhat.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 940401390 for ; Sun, 20 Oct 2019 04:42:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72E2F222C3 for ; Sun, 20 Oct 2019 04:42:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="gay1OAs7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbfJTEmb (ORCPT ); Sun, 20 Oct 2019 00:42:31 -0400 Received: from mail-40135.protonmail.ch ([185.70.40.135]:27579 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725875AbfJTEmb (ORCPT ); Sun, 20 Oct 2019 00:42:31 -0400 Date: Sun, 20 Oct 2019 04:42:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1571546549; bh=rgii3XUlaS68qqkAmx2Qld1DLClAKGeLVprB87vVEQU=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=gay1OAs75jFWqXk3c+0DpAK3UdcZKtoPKt7Ijh6OEUhOvAFHa6hed5MrqvbvgNJoG DQlLvhPhfufAeec9z76xeqKKAcMf/4RK6rLSweLHhzGI6Jh/70X30X7alSlpy6EfTR c2SLTHw+NlBhd0P5HQj2YAOOKg1DXGysWsdATL8Q= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: Benjamin Tissoires , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , =?utf-8?q?Fi?= =?utf-8?q?lipe_La=C3=ADns?= , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v7 2/3] HID: logitech-hidpp: Support MX Master (b012, b01e) over Bluetooth Message-ID: Feedback-ID: 18B_FC5q-t32TXzMsVp9BgkgrdNH3iwklfW8WOrHrcxZA0WRj7JodCh5VXKxs6A3OaiHK0QNd8wi3SImKex8yQ==:Ext:ProtonMail MIME-Version: 1.0 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-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This patch adds support for the MX Master over Bluetooth (b012, b01e). I have only added the devices that have been tested, so the 0xb017 variant of the MX Master needs to be added once it is tested. Since this patch series adds support for Bluetooth LE devices in general, other Bluetooth LE devices should also be added later Thanks, Mazin Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index ee604b17514f..19b315e4e91b 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -3792,6 +3792,11 @@ static const struct hid_device_id hidpp_devices[] = { { /* MX5500 keyboard over Bluetooth */ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b), .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS }, + { /* MX Master mouse over Bluetooth */ + HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb012), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, {} }; From patchwork Sun Oct 20 04:43:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11200579 X-Patchwork-Delegate: benjamin.tissoires@redhat.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CB07112C for ; Sun, 20 Oct 2019 04:43:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B8EF222C2 for ; Sun, 20 Oct 2019 04:43:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="Ae+uASa1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725851AbfJTEns (ORCPT ); Sun, 20 Oct 2019 00:43:48 -0400 Received: from mail-40135.protonmail.ch ([185.70.40.135]:21481 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfJTEns (ORCPT ); Sun, 20 Oct 2019 00:43:48 -0400 Date: Sun, 20 Oct 2019 04:43:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1571546624; bh=me06rsc5KXNlQ4iY9NIZI/enKgYjtNZr73xM+bjnrSM=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=Ae+uASa1gzFHwBDO6MMsmBdfe4Ogsb6RvWy+1pPFf12Wg2bAuRP9NYx0/4CGfmD43 n5yJ9legDRb+X6r/Qors5cRuF3CUctOIQuZOuZZZZPPUbvL70w1COzXabKKU40VnDW cAPjLhguJNmHb1pu8IOSBPEtTwYwVk5fDYoUepzM= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: Benjamin Tissoires , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , =?utf-8?q?Fi?= =?utf-8?q?lipe_La=C3=ADns?= , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v7 3/3] HID: logitech-hidpp: Support WirelessDeviceStatus connect events Message-ID: Feedback-ID: 18B_FC5q-t32TXzMsVp9BgkgrdNH3iwklfW8WOrHrcxZA0WRj7JodCh5VXKxs6A3OaiHK0QNd8wi3SImKex8yQ==:Ext:ProtonMail MIME-Version: 1.0 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-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This patch allows hidpp_report_is_connect_event to support WirelessDeviceStatus connect events. The WirelessDeviceStatus feature index is stored in hidpp_device when probed. The connect event's fap feature_index is compared against it if the device supports it. Thanks, Mazin Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 19b315e4e91b..c8b23568d0b1 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -191,6 +191,8 @@ struct hidpp_device { struct hidpp_battery battery; struct hidpp_scroll_counter vertical_wheel_counter; + + u8 wireless_feature_index; }; /* HID++ 1.0 error codes */ @@ -403,10 +405,13 @@ static inline bool hidpp_match_error(struct hidpp_report *question, (answer->fap.params[0] == question->fap.funcindex_clientid); } -static inline bool hidpp_report_is_connect_event(struct hidpp_report *report) +static inline bool hidpp_report_is_connect_event(struct hidpp_device *hidpp, + struct hidpp_report *report) { - return (report->report_id == REPORT_ID_HIDPP_SHORT) && - (report->rap.sub_id == 0x41); + return (hidpp->wireless_feature_index && + (report->fap.feature_index == hidpp->wireless_feature_index)) || + ((report->report_id == REPORT_ID_HIDPP_SHORT) && + (report->rap.sub_id == 0x41)); } /** @@ -1283,6 +1288,24 @@ static int hidpp_battery_get_property(struct power_supply *psy, return ret; } +/* -------------------------------------------------------------------------- */ +/* 0x1d4b: Wireless device status */ +/* -------------------------------------------------------------------------- */ +#define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b + +static int hidpp_set_wireless_feature_index(struct hidpp_device *hidpp) +{ + u8 feature_type; + int ret; + + ret = hidpp_root_get_feature(hidpp, + HIDPP_PAGE_WIRELESS_DEVICE_STATUS, + &hidpp->wireless_feature_index, + &feature_type); + + return ret; +} + /* -------------------------------------------------------------------------- */ /* 0x2120: Hi-resolution scrolling */ /* -------------------------------------------------------------------------- */ @@ -3078,7 +3101,7 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, } } - if (unlikely(hidpp_report_is_connect_event(report))) { + if (unlikely(hidpp_report_is_connect_event(hidpp, report))) { atomic_set(&hidpp->connected, !(report->rap.params[0] & (1 << 6))); if (schedule_work(&hidpp->work) == 0) @@ -3628,6 +3651,14 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hidpp_overwrite_name(hdev); } + if (connected && hidpp->protocol_major >= 2) { + ret = hidpp_set_wireless_feature_index(hidpp); + if (ret == -ENOENT) + hidpp->wireless_feature_index = 0; + else if (ret) + goto hid_hw_init_fail; + } + if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { ret = wtp_get_config(hidpp); if (ret)