Skip to content

Commit 0da0a63

Browse files
Mazin Rezkbentiss
authored andcommitted
HID: logitech-hidpp: Support WirelessDeviceStatus connect events
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. Signed-off-by: Mazin Rezk <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent c2a9327 commit 0da0a63

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

drivers/hid/hid-logitech-hidpp.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ struct hidpp_device {
191191

192192
struct hidpp_battery battery;
193193
struct hidpp_scroll_counter vertical_wheel_counter;
194+
195+
u8 wireless_feature_index;
194196
};
195197

196198
/* HID++ 1.0 error codes */
@@ -403,10 +405,13 @@ static inline bool hidpp_match_error(struct hidpp_report *question,
403405
(answer->fap.params[0] == question->fap.funcindex_clientid);
404406
}
405407

406-
static inline bool hidpp_report_is_connect_event(struct hidpp_report *report)
408+
static inline bool hidpp_report_is_connect_event(struct hidpp_device *hidpp,
409+
struct hidpp_report *report)
407410
{
408-
return (report->report_id == REPORT_ID_HIDPP_SHORT) &&
409-
(report->rap.sub_id == 0x41);
411+
return (hidpp->wireless_feature_index &&
412+
(report->fap.feature_index == hidpp->wireless_feature_index)) ||
413+
((report->report_id == REPORT_ID_HIDPP_SHORT) &&
414+
(report->rap.sub_id == 0x41));
410415
}
411416

412417
/**
@@ -1286,6 +1291,24 @@ static int hidpp_battery_get_property(struct power_supply *psy,
12861291
return ret;
12871292
}
12881293

1294+
/* -------------------------------------------------------------------------- */
1295+
/* 0x1d4b: Wireless device status */
1296+
/* -------------------------------------------------------------------------- */
1297+
#define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b
1298+
1299+
static int hidpp_set_wireless_feature_index(struct hidpp_device *hidpp)
1300+
{
1301+
u8 feature_type;
1302+
int ret;
1303+
1304+
ret = hidpp_root_get_feature(hidpp,
1305+
HIDPP_PAGE_WIRELESS_DEVICE_STATUS,
1306+
&hidpp->wireless_feature_index,
1307+
&feature_type);
1308+
1309+
return ret;
1310+
}
1311+
12891312
/* -------------------------------------------------------------------------- */
12901313
/* 0x2120: Hi-resolution scrolling */
12911314
/* -------------------------------------------------------------------------- */
@@ -3101,7 +3124,7 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
31013124
}
31023125
}
31033126

3104-
if (unlikely(hidpp_report_is_connect_event(report))) {
3127+
if (unlikely(hidpp_report_is_connect_event(hidpp, report))) {
31053128
atomic_set(&hidpp->connected,
31063129
!(report->rap.params[0] & (1 << 6)));
31073130
if (schedule_work(&hidpp->work) == 0)
@@ -3652,6 +3675,14 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
36523675
hidpp_overwrite_name(hdev);
36533676
}
36543677

3678+
if (connected && hidpp->protocol_major >= 2) {
3679+
ret = hidpp_set_wireless_feature_index(hidpp);
3680+
if (ret == -ENOENT)
3681+
hidpp->wireless_feature_index = 0;
3682+
else if (ret)
3683+
goto hid_hw_init_fail;
3684+
}
3685+
36553686
if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
36563687
ret = wtp_get_config(hidpp);
36573688
if (ret)

0 commit comments

Comments
 (0)