Skip to content

Commit c2a9327

Browse files
Mazin Rezkbentiss
authored andcommitted
HID: logitech-hidpp: Support translations from short to long reports
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. This patch also introduces support for the MX Master (b01e and b012). Signed-off-by: Mazin Rezk <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent d004701 commit c2a9327

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

drivers/hid/hid-logitech-hidpp.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ MODULE_PARM_DESC(disable_tap_to_click,
4949
#define HIDPP_REPORT_LONG_LENGTH 20
5050
#define HIDPP_REPORT_VERY_LONG_MAX_LENGTH 64
5151

52+
#define HIDPP_REPORT_SHORT_SUPPORTED BIT(0)
53+
#define HIDPP_REPORT_LONG_SUPPORTED BIT(1)
54+
#define HIDPP_REPORT_VERY_LONG_SUPPORTED BIT(2)
55+
5256
#define HIDPP_SUB_ID_CONSUMER_VENDOR_KEYS 0x03
5357
#define HIDPP_SUB_ID_ROLLER 0x05
5458
#define HIDPP_SUB_ID_MOUSE_EXTRA_BTNS 0x06
@@ -183,6 +187,7 @@ struct hidpp_device {
183187

184188
unsigned long quirks;
185189
unsigned long capabilities;
190+
u8 supported_reports;
186191

187192
struct hidpp_battery battery;
188193
struct hidpp_scroll_counter vertical_wheel_counter;
@@ -340,6 +345,11 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
340345
struct hidpp_report *message;
341346
int ret, max_count;
342347

348+
/* Send as long report if short reports are not supported. */
349+
if (report_id == REPORT_ID_HIDPP_SHORT &&
350+
!(hidpp_dev->supported_reports & HIDPP_REPORT_SHORT_SUPPORTED))
351+
report_id = REPORT_ID_HIDPP_LONG;
352+
343353
switch (report_id) {
344354
case REPORT_ID_HIDPP_SHORT:
345355
max_count = HIDPP_REPORT_SHORT_LENGTH - 4;
@@ -3481,18 +3491,19 @@ static int hidpp_get_report_length(struct hid_device *hdev, int id)
34813491
return report->field[0]->report_count + 1;
34823492
}
34833493

3484-
static bool hidpp_validate_device(struct hid_device *hdev)
3494+
static u8 hidpp_validate_device(struct hid_device *hdev)
34853495
{
34863496
struct hidpp_device *hidpp = hid_get_drvdata(hdev);
3487-
int id, report_length, supported_reports = 0;
3497+
int id, report_length;
3498+
u8 supported_reports = 0;
34883499

34893500
id = REPORT_ID_HIDPP_SHORT;
34903501
report_length = hidpp_get_report_length(hdev, id);
34913502
if (report_length) {
34923503
if (report_length < HIDPP_REPORT_SHORT_LENGTH)
34933504
goto bad_device;
34943505

3495-
supported_reports++;
3506+
supported_reports |= HIDPP_REPORT_SHORT_SUPPORTED;
34963507
}
34973508

34983509
id = REPORT_ID_HIDPP_LONG;
@@ -3501,7 +3512,7 @@ static bool hidpp_validate_device(struct hid_device *hdev)
35013512
if (report_length < HIDPP_REPORT_LONG_LENGTH)
35023513
goto bad_device;
35033514

3504-
supported_reports++;
3515+
supported_reports |= HIDPP_REPORT_LONG_SUPPORTED;
35053516
}
35063517

35073518
id = REPORT_ID_HIDPP_VERY_LONG;
@@ -3511,7 +3522,7 @@ static bool hidpp_validate_device(struct hid_device *hdev)
35113522
report_length > HIDPP_REPORT_VERY_LONG_MAX_LENGTH)
35123523
goto bad_device;
35133524

3514-
supported_reports++;
3525+
supported_reports |= HIDPP_REPORT_VERY_LONG_SUPPORTED;
35153526
hidpp->very_long_report_length = report_length;
35163527
}
35173528

@@ -3560,7 +3571,9 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
35603571
/*
35613572
* Make sure the device is HID++ capable, otherwise treat as generic HID
35623573
*/
3563-
if (!hidpp_validate_device(hdev)) {
3574+
hidpp->supported_reports = hidpp_validate_device(hdev);
3575+
3576+
if (!hidpp->supported_reports) {
35643577
hid_set_drvdata(hdev, NULL);
35653578
devm_kfree(&hdev->dev, hidpp);
35663579
return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
@@ -3808,6 +3821,11 @@ static const struct hid_device_id hidpp_devices[] = {
38083821
{ /* MX5500 keyboard over Bluetooth */
38093822
HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b),
38103823
.driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
3824+
{ /* MX Master mouse over Bluetooth */
3825+
HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb012),
3826+
.driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
3827+
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e),
3828+
.driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
38113829
{}
38123830
};
38133831

0 commit comments

Comments
 (0)