From patchwork Sun Oct 6 01:04:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11175955 X-Patchwork-Delegate: jikos@jikos.cz 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 5090215AB for ; Sun, 6 Oct 2019 01:04:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED770222C8 for ; Sun, 6 Oct 2019 01:04:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="yGvuqtfz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbfJFBEG (ORCPT ); Sat, 5 Oct 2019 21:04:06 -0400 Received: from mail-40136.protonmail.ch ([185.70.40.136]:32585 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727008AbfJFBEG (ORCPT ); Sat, 5 Oct 2019 21:04:06 -0400 Date: Sun, 06 Oct 2019 01:04:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1570323843; bh=xOf7naOIf6rDpc0khn4XCANsLt39rlB4TiL3sCEDg70=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=yGvuqtfzb4tOobTwRTNB+3m7L6HP02jRum1TsROQSWZ9wTKat9xzFemc5anAYO2im 1Ir2Df6MXJnmeqk7CgpA5nc/N/S46XsrzBg8apTdwx9JvS+6jI8XDmHxM5qkh60yWq 4lUnbH+oOvnKavkBXmM7b63U8jm9s8tVkEu0W28k= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: "benjamin.tissoires@redhat.com" , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , "lains@archlinux.org" , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v3 1/4] HID: logitech: Add MX Mice 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 several MX mice over Bluetooth. The device IDs have been copied from the libratbag device database and their features have been based on their DJ device counterparts. Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 0179f7ed77e5..85fd0c17cc2f 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -3773,6 +3773,24 @@ 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 Anywhere 2 mouse over Bluetooth */ + HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb013), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb018), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + { /* MX Anywhere 2S mouse over Bluetooth */ + HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01a), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + { /* 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, 0xb017), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + { /* MX Master 2S mouse over Bluetooth */ + HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb019), + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, {} }; From patchwork Sun Oct 6 01:04:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11175957 X-Patchwork-Delegate: jikos@jikos.cz 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 E1877195A for ; Sun, 6 Oct 2019 01:04:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5882222C8 for ; Sun, 6 Oct 2019 01:04:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="O4hOGLNf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbfJFBEY (ORCPT ); Sat, 5 Oct 2019 21:04:24 -0400 Received: from mail-40133.protonmail.ch ([185.70.40.133]:40812 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726984AbfJFBEY (ORCPT ); Sat, 5 Oct 2019 21:04:24 -0400 Date: Sun, 06 Oct 2019 01:04:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1570323859; bh=EenmT9+ylx8vIRw7BMAiWOi3ZvFwek38x/+DNgZOMEc=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=O4hOGLNfVG9gqVm9o4EGx1rNJh2PtJE2ogwUApPkqkfIBZBMTx+WDMNT17ITK5A5m VnRXpPSMRUNkdWHZfzXl03IlbAAExaDhuU/OAu8Zs6gAstLoMbZSLLrLuFz3mL1JLa NOHf/PQRoxjZcm7WgsJj1iZtLPybTFcCIVIO7noI= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: "benjamin.tissoires@redhat.com" , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , "lains@archlinux.org" , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v3 2/4] HID: logitech: Support HID++ devices without short 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 the hid-logitech-hidpp module to support devices that do not have support for Short HID++ reports. So far, it seems that Bluetooth HID++ 2.0 devices are missing short reports. This has been tested and confirmed with the MX Master and MX Master 2S and is therefore likely the case with the other Bluetooth devices. Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 37 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 85fd0c17cc2f..a0efa8a43213 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -71,6 +71,7 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_QUIRK_HIDPP_WHEELS BIT(29) #define HIDPP_QUIRK_HIDPP_EXTRA_MOUSE_BTNS BIT(30) #define HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS BIT(31) +#define HIDPP_QUIRK_CLASS_BLUETOOTH BIT(5) /* These are just aliases for now */ #define HIDPP_QUIRK_KBD_SCROLL_WHEEL HIDPP_QUIRK_HIDPP_WHEELS @@ -81,6 +82,9 @@ MODULE_PARM_DESC(disable_tap_to_click, HIDPP_QUIRK_HI_RES_SCROLL_X2120 | \ HIDPP_QUIRK_HI_RES_SCROLL_X2121) +/* Just an alias for now, may possibly be a catch-all in the future */ +#define HIDPP_QUIRK_MISSING_SHORT_REPORTS HIDPP_QUIRK_CLASS_BLUETOOTH + #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT #define HIDPP_CAPABILITY_HIDPP10_BATTERY BIT(0) @@ -340,6 +344,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 +3492,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, @@ -3775,22 +3791,29 @@ static const struct hid_device_id hidpp_devices[] = { .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS }, { /* MX Anywhere 2 mouse over Bluetooth */ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb013), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb018), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, { /* MX Anywhere 2S mouse over Bluetooth */ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01a), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, { /* MX Master mouse over Bluetooth */ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb012), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb017), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, { /* MX Master 2S mouse over Bluetooth */ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb019), - .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 }, + .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 | + HIDPP_QUIRK_CLASS_BLUETOOTH }, {} }; From patchwork Sun Oct 6 01:04:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11175959 X-Patchwork-Delegate: jikos@jikos.cz 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 DA36615AB for ; Sun, 6 Oct 2019 01:04:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B962B222CA for ; Sun, 6 Oct 2019 01:04:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="ZmB+A7gP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbfJFBEt (ORCPT ); Sat, 5 Oct 2019 21:04:49 -0400 Received: from mail-40133.protonmail.ch ([185.70.40.133]:31767 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726984AbfJFBEt (ORCPT ); Sat, 5 Oct 2019 21:04:49 -0400 Date: Sun, 06 Oct 2019 01:04:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1570323885; bh=lucdwIXyrI3acF9pa/XY2PlrAhFkzNyslqQIMc4ZvqA=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=ZmB+A7gPusQeDsS5vcpM4Rqaij4o+ROfPmEBCS02oNWn2cDnbHjjUgCXCpghxvhRs lXr88dv0H5ex3u9Tn6JLgB3ljd+BRIucAw95SzD5F4WHfMRHEkSPjiL0JhIxR1nzhV SxFlbTRfFb+3CZl75dBYx39bEdtmG1QwQfNFc9uY= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: "benjamin.tissoires@redhat.com" , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , "lains@archlinux.org" , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v3 3/4] HID: logitech: Add feature 0x0001: FeatureSet 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 0x0001 (FeatureSet) feature. This feature is used to look up the feature ID of a feature index on a device and list the total count of features on the device. I also added the hidpp20_get_features function which iterates through all feature indexes on the device and stores a map of them in features an hidpp_device struct. This function runs when an HID++ 2.0 device is probed. Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index a0efa8a43213..64ac94c581aa 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -190,6 +190,9 @@ struct hidpp_device { struct hidpp_battery battery; struct hidpp_scroll_counter vertical_wheel_counter; + + u16 *features; + u8 feature_count; }; /* HID++ 1.0 error codes */ @@ -911,6 +914,84 @@ static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp) return 0; } +/* -------------------------------------------------------------------------- */ +/* 0x0001: FeatureSet */ +/* -------------------------------------------------------------------------- */ + +#define HIDPP_PAGE_FEATURESET 0x0001 + +#define CMD_FEATURESET_GET_COUNT 0x00 +#define CMD_FEATURESET_GET_FEATURE 0x11 + +static int hidpp20_featureset_get_feature(struct hidpp_device *hidpp, + u8 featureset_index, u8 feature_index, u16 *feature_id) +{ + struct hidpp_report response; + int ret; + + ret = hidpp_send_fap_command_sync(hidpp, featureset_index, + CMD_FEATURESET_GET_FEATURE, &feature_index, 1, &response); + + if (ret) + return ret; + + *feature_id = (response.fap.params[0] << 8) | response.fap.params[1]; + + return ret; +} + +static int hidpp20_featureset_get_count(struct hidpp_device *hidpp, + u8 feature_index, u8 *count) +{ + struct hidpp_report response; + int ret; + + ret = hidpp_send_fap_command_sync(hidpp, feature_index, + CMD_FEATURESET_GET_COUNT, NULL, 0, &response); + + if (ret) + return ret; + + *count = response.fap.params[0]; + + return ret; +} + +static int hidpp20_get_features(struct hidpp_device *hidpp) +{ + int ret; + u8 featureset_index, featureset_type; + u8 i; + + hidpp->feature_count = 0; + + ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_FEATURESET, + &featureset_index, &featureset_type); + + if (ret == -ENOENT) { + hid_warn(hidpp->hid_dev, "Unable to retrieve feature set."); + return 0; + } + + if (ret) + return ret; + + ret = hidpp20_featureset_get_count(hidpp, featureset_index, + &hidpp->feature_count); + + if (ret) + return ret; + + hidpp->features = devm_kzalloc(&hidpp->hid_dev->dev, + hidpp->feature_count * sizeof(u16), GFP_KERNEL); + + for (i = 0; i < hidpp->feature_count && !ret; i++) + ret = hidpp20_featureset_get_feature(hidpp, featureset_index, + i, &(hidpp->features[i])); + + return ret; +} + /* -------------------------------------------------------------------------- */ /* 0x0005: GetDeviceNameType */ /* -------------------------------------------------------------------------- */ @@ -3625,6 +3706,17 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hidpp_overwrite_name(hdev); } + /* Cache feature indexes and IDs to check reports faster */ + if (hidpp->protocol_major >= 2) { + if (hidpp20_get_features(hidpp)) { + hid_err(hdev, "%s:hidpp20_get_features returned error\n", + __func__); + goto hid_hw_init_fail; + } + } else { + hidpp->feature_count = 0; + } + if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { ret = wtp_get_config(hidpp); if (ret) From patchwork Sun Oct 6 01:05:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mazin Rezk X-Patchwork-Id: 11175961 X-Patchwork-Delegate: jikos@jikos.cz 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 C684D112B for ; Sun, 6 Oct 2019 01:05:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A5320222CB for ; Sun, 6 Oct 2019 01:05:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="rkZ0XkGy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727126AbfJFBFT (ORCPT ); Sat, 5 Oct 2019 21:05:19 -0400 Received: from mail-40135.protonmail.ch ([185.70.40.135]:18794 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfJFBFT (ORCPT ); Sat, 5 Oct 2019 21:05:19 -0400 Date: Sun, 06 Oct 2019 01:05:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1570323916; bh=nQLWuVtTWGi9TtxUQovyksAthP1snzF6VdySnTPCXW0=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=rkZ0XkGygESKNUBeUHoKz3tecOzx4f9NuHe/XR1nnLvFdm6r+3BbNQfqYz6PTWdb/ LXOsi7ZdKE3vDgL2TZ8Kt1O30nF6XDvqM2iH1sIW2ufXBEHsxPZwBD4FWCJr96BXq3 KdrM/X4JmcRNllx68MXPjnkN8AkSZzthgh62rDjk= To: "linux-input@vger.kernel.org" From: Mazin Rezk Cc: "benjamin.tissoires@redhat.com" , "jikos@kernel.org" , "linux-kernel@vger.kernel.org" , "lains@archlinux.org" , "mnrzk@protonmail.com" Reply-To: Mazin Rezk Subject: [PATCH v3 4/4] HID: logitech: 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 makes WirelessDeviceStatus (0x1d4b) events get detected as connection events on devices with HIDPP_QUIRK_WIRELESS_DEVICE_STATUS. This quirk is currently an alias for HIDPP_QUIRK_CLASS_BLUETOOTH since the added Bluetooth devices do not support regular connect events. Signed-off-by: Mazin Rezk --- drivers/hid/hid-logitech-hidpp.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) -- 2.23.0 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 64ac94c581aa..4a6e41c2c9fc 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -84,6 +84,7 @@ MODULE_PARM_DESC(disable_tap_to_click, /* Just an alias for now, may possibly be a catch-all in the future */ #define HIDPP_QUIRK_MISSING_SHORT_REPORTS HIDPP_QUIRK_CLASS_BLUETOOTH +#define HIDPP_QUIRK_WIRELESS_DEVICE_STATUS HIDPP_QUIRK_CLASS_BLUETOOTH #define HIDPP_QUIRK_DELAYED_INIT HIDPP_QUIRK_NO_HIDINPUT @@ -406,9 +407,22 @@ 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) +#define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b + +static inline bool hidpp_report_is_connect_event(struct hidpp_device *hidpp, + struct hidpp_report *report) { - return (report->report_id == REPORT_ID_HIDPP_SHORT) && + if (hidpp->quirks & HIDPP_QUIRK_WIRELESS_DEVICE_STATUS) { + /* If feature is invalid, skip array check */ + if (report->fap.feature_index > hidpp->feature_count) + return false; + + return (hidpp->features[report->fap.feature_index] == + HIDPP_PAGE_WIRELESS_DEVICE_STATUS); + } + + return ((report->report_id == REPORT_ID_HIDPP_SHORT) || + (hidpp->quirks & HIDPP_QUIRK_MISSING_SHORT_REPORTS)) && (report->rap.sub_id == 0x41); } @@ -3159,7 +3173,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)