From patchwork Mon Oct 14 18:36:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11189307 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 C9D0276 for ; Mon, 14 Oct 2019 18:36:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB3EB21721 for ; Mon, 14 Oct 2019 18:36:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="KZAvafxn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730441AbfJNSgP (ORCPT ); Mon, 14 Oct 2019 14:36:15 -0400 Received: from mail-40136.protonmail.ch ([185.70.40.136]:34977 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729610AbfJNSgP (ORCPT ); Mon, 14 Oct 2019 14:36:15 -0400 Date: Mon, 14 Oct 2019 18:36:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1571078171; bh=c8f5ffkKV2bEwQy6LxxpHQK2PcptUqivs9BKAqP8sAU=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=KZAvafxn91fdrcFyvX8LGJoyBxWZVkxtIM5VVuIKhsVoXA3TmHl+hyBeutYGJMEgr vBLcyK/5GBiXRSbjS0ZjVU9sNpvd7RagXwjlRKnji4IWfE2VYUNQi59pvqIvPFyKSj xxjYi8GsER4//GkrwV00nQ5DtM/Ykhv/H2G7pjhc= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: "benjamin.tissoires@redhat.com" , "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 v6 1/2] HID: logitech: Add MX Master 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 (b01e and b012) and also adds foundational code for other Bluetooth LE HID++ devices to be added. Some devices do not support short reports and thus have a quirk (HIDPP_QUIRK_MISSING_SHORT_REPORTS) that forces short reports to be sent as long reports. Since all Bluetooth LE HID++ devices seem to act this way, HIDPP_QUIRK_CLASS_BLUETOOTH_LE aliases this quirk. To allow for some space for future quirks, I changed the comment that defines the bits reserved for classes from 2...20 to 2..15. Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 0179f7ed77e5..997b1056850a 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -59,7 +59,8 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_QUIRK_CLASS_G920 BIT(3) #define HIDPP_QUIRK_CLASS_K750 BIT(4) -/* bits 2..20 are reserved for classes */ +/* bits 2..15 are reserved for classes */ +#define HIDPP_QUIRK_MISSING_SHORT_REPORTS BIT(20) /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */ #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22) #define HIDPP_QUIRK_NO_HIDINPUT BIT(23) @@ -81,6 +82,8 @@ MODULE_PARM_DESC(disable_tap_to_click, HIDPP_QUIRK_HI_RES_SCROLL_X2120 | \ HIDPP_QUIRK_HI_RES_SCROLL_X2121) +#define HIDPP_QUIRK_CLASS_BLUETOOTH_LE HIDPP_QUIRK_MISSING_SHORT_REPORTS + #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0) @@ -340,6 +343,12 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev, struct hidpp_report *message; int ret, max_count; + /* Force long reports on devices that do not support short reports */ + if (hidpp_dev->quirks & HIDPP_QUIRK_MISSING_SHORT_REPORTS && + report_id == REPORT_ID_HIDPP_SHORT) + report_id = REPORT_ID_HIDPP_LONG; + + switch (report_id) { case REPORT_ID_HIDPP_SHORT: max_count = HIDPP_REPORT_SHORT_LENGTH - 4; @@ -3482,6 +3491,12 @@ static bool hidpp_validate_report(struct hid_device *hdev, int id, static bool hidpp_validate_device(struct hid_device *hdev) { + struct hidpp_device *hidpp = hid_get_drvdata(hdev); + /* Skip the short report check if the device does not support it */ + if (hidpp->quirks & HIDPP_QUIRK_MISSING_SHORT_REPORTS) + return hidpp_validate_report(hdev, REPORT_ID_HIDPP_LONG, + HIDPP_REPORT_LONG_LENGTH, false); + return hidpp_validate_report(hdev, REPORT_ID_HIDPP_SHORT, HIDPP_REPORT_SHORT_LENGTH, false) && hidpp_validate_report(hdev, REPORT_ID_HIDPP_LONG, @@ -3773,6 +3788,13 @@ 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 | + HIDPP_QUIRK_CLASS_BLUETOOTH_LE }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH_LE }, {} }; From patchwork Mon Oct 14 18:36:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11189309 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 B21B513BD for ; Mon, 14 Oct 2019 18:36:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B8F221848 for ; Mon, 14 Oct 2019 18:36:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="oMUdeIsA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730717AbfJNSg2 (ORCPT ); Mon, 14 Oct 2019 14:36:28 -0400 Received: from mail-40135.protonmail.ch ([185.70.40.135]:39819 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726169AbfJNSg2 (ORCPT ); Mon, 14 Oct 2019 14:36:28 -0400 Date: Mon, 14 Oct 2019 18:36:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1571078184; bh=HlmGu1q+Sq6eE8y8EwjOQgPvCZXyiZ/Ph43h6boW/JM=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=oMUdeIsAbHtWC1ET7YqCx0SXUA6gq46ZEc+O+9NzI0GW5qdtixs7GEgrjiPkRtXLu ql89U4XZQ8Pa+ce6jph7E05LgIx8o13M36J5JmEICFPcztcSs0ORTHLG6CNMCwJZ6L ZDle2DdzfxhmoFLzAsiSUNPBkzI9ialeSagI7YIM= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: "benjamin.tissoires@redhat.com" , "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 v6 2/2] HID: logitech: Support WirelessDeviceStatus connect events Message-ID: <_1Ewv9AvBhbWTNcFOkmvCyjVph73eQIz23Plyv5ffgaWWHnmPBTbSIJhs47AnYatJsmDWu4JlMjcsKE8Cf31lvmwQipYEu47YglNfroyJtM=@protonmail.com> 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 WirelessDeviceStatus (0x1d4b) events to be detected as connection events in the hid-logitech-hidpp module. Devices with HIDPP_QUIRK_WIRELESS_DEVICE_STATUS use WirelessDeviceStatus instead of traditional connect events. Since all Bluetooth LE devices seem to act this way, HIDPP_QUIRK_CLASS_BLUETOOTH_LE aliases this quirk. Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 42 ++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 997b1056850a..9b3df57ca857 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -60,6 +60,7 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_QUIRK_CLASS_K750 BIT(4) /* bits 2..15 are reserved for classes */ +#define HIDPP_QUIRK_WIRELESS_DEVICE_STATUS BIT(19) #define HIDPP_QUIRK_MISSING_SHORT_REPORTS BIT(20) /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */ #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22) @@ -82,7 +83,8 @@ MODULE_PARM_DESC(disable_tap_to_click, HIDPP_QUIRK_HI_RES_SCROLL_X2120 | \ HIDPP_QUIRK_HI_RES_SCROLL_X2121) -#define HIDPP_QUIRK_CLASS_BLUETOOTH_LE HIDPP_QUIRK_MISSING_SHORT_REPORTS +#define HIDPP_QUIRK_CLASS_BLUETOOTH_LE (HIDPP_QUIRK_MISSING_SHORT_REPORTS | \ + HIDPP_QUIRK_WIRELESS_DEVICE_STATUS) #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT @@ -189,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 */ @@ -402,10 +406,14 @@ 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->quirks & HIDPP_QUIRK_WIRELESS_DEVICE_STATUS) && + (report->fap.feature_index == hidpp->wireless_feature_index)) || + (((report->report_id == REPORT_ID_HIDPP_SHORT) || + (hidpp->quirks & HIDPP_QUIRK_MISSING_SHORT_REPORTS)) && + (report->rap.sub_id == 0x41)); } /** @@ -1282,6 +1290,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 */ /* -------------------------------------------------------------------------- */ @@ -3077,7 +3103,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) @@ -3624,6 +3650,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hidpp_overwrite_name(hdev); } + if (connected && (hidpp->quirks & HIDPP_QUIRK_WIRELESS_DEVICE_STATUS)) { + ret = hidpp_set_wireless_feature_index(hidpp); + if (ret) + goto hid_hw_init_fail; + } + if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { ret = wtp_get_config(hidpp); if (ret)