Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 2 | /* |
Filipe Laíns | c08ce25 | 2020-01-12 23:50:09 +0000 | [diff] [blame] | 3 | * HID driver for Logitech receivers |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2011 Logitech |
| 6 | */ |
| 7 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 8 | |
| 9 | |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/hid.h> |
| 12 | #include <linux/module.h> |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 13 | #include <linux/kfifo.h> |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 14 | #include <linux/delay.h> |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 15 | #include <linux/usb.h> /* For to_usb_interface for kvm extra intf check */ |
Jonathan Nieder | 44d27f7 | 2012-05-11 16:17:16 +0200 | [diff] [blame] | 16 | #include <asm/unaligned.h> |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 17 | #include "hid-ids.h" |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 18 | |
Filipe Laíns | 8c9d734 | 2020-01-15 20:18:11 +0000 | [diff] [blame] | 19 | #define DJ_MAX_PAIRED_DEVICES 7 |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 20 | #define DJ_MAX_NUMBER_NOTIFS 8 |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 21 | #define DJ_RECEIVER_INDEX 0 |
| 22 | #define DJ_DEVICE_INDEX_MIN 1 |
Filipe Laíns | 8c9d734 | 2020-01-15 20:18:11 +0000 | [diff] [blame] | 23 | #define DJ_DEVICE_INDEX_MAX 7 |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 24 | |
| 25 | #define DJREPORT_SHORT_LENGTH 15 |
| 26 | #define DJREPORT_LONG_LENGTH 32 |
| 27 | |
| 28 | #define REPORT_ID_DJ_SHORT 0x20 |
| 29 | #define REPORT_ID_DJ_LONG 0x21 |
| 30 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 31 | #define REPORT_ID_HIDPP_SHORT 0x10 |
| 32 | #define REPORT_ID_HIDPP_LONG 0x11 |
Hans de Goede | 3a9a2c8 | 2019-06-14 10:20:27 +0200 | [diff] [blame] | 33 | #define REPORT_ID_HIDPP_VERY_LONG 0x12 |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 34 | |
| 35 | #define HIDPP_REPORT_SHORT_LENGTH 7 |
| 36 | #define HIDPP_REPORT_LONG_LENGTH 20 |
| 37 | |
| 38 | #define HIDPP_RECEIVER_INDEX 0xff |
| 39 | |
| 40 | #define REPORT_TYPE_RFREPORT_FIRST 0x01 |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 41 | #define REPORT_TYPE_RFREPORT_LAST 0x1F |
| 42 | |
| 43 | /* Command Switch to DJ mode */ |
| 44 | #define REPORT_TYPE_CMD_SWITCH 0x80 |
| 45 | #define CMD_SWITCH_PARAM_DEVBITFIELD 0x00 |
| 46 | #define CMD_SWITCH_PARAM_TIMEOUT_SECONDS 0x01 |
| 47 | #define TIMEOUT_NO_KEEPALIVE 0x00 |
| 48 | |
| 49 | /* Command to Get the list of Paired devices */ |
| 50 | #define REPORT_TYPE_CMD_GET_PAIRED_DEVICES 0x81 |
| 51 | |
| 52 | /* Device Paired Notification */ |
| 53 | #define REPORT_TYPE_NOTIF_DEVICE_PAIRED 0x41 |
| 54 | #define SPFUNCTION_MORE_NOTIF_EXPECTED 0x01 |
| 55 | #define SPFUNCTION_DEVICE_LIST_EMPTY 0x02 |
| 56 | #define DEVICE_PAIRED_PARAM_SPFUNCTION 0x00 |
| 57 | #define DEVICE_PAIRED_PARAM_EQUAD_ID_LSB 0x01 |
| 58 | #define DEVICE_PAIRED_PARAM_EQUAD_ID_MSB 0x02 |
| 59 | #define DEVICE_PAIRED_RF_REPORT_TYPE 0x03 |
| 60 | |
| 61 | /* Device Un-Paired Notification */ |
| 62 | #define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x40 |
| 63 | |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 64 | /* Connection Status Notification */ |
| 65 | #define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42 |
| 66 | #define CONNECTION_STATUS_PARAM_STATUS 0x00 |
| 67 | #define STATUS_LINKLOSS 0x01 |
| 68 | |
| 69 | /* Error Notification */ |
| 70 | #define REPORT_TYPE_NOTIF_ERROR 0x7F |
| 71 | #define NOTIF_ERROR_PARAM_ETYPE 0x00 |
| 72 | #define ETYPE_KEEPALIVE_TIMEOUT 0x01 |
| 73 | |
| 74 | /* supported DJ HID && RF report types */ |
| 75 | #define REPORT_TYPE_KEYBOARD 0x01 |
| 76 | #define REPORT_TYPE_MOUSE 0x02 |
| 77 | #define REPORT_TYPE_CONSUMER_CONTROL 0x03 |
| 78 | #define REPORT_TYPE_SYSTEM_CONTROL 0x04 |
| 79 | #define REPORT_TYPE_MEDIA_CENTER 0x08 |
| 80 | #define REPORT_TYPE_LEDS 0x0E |
| 81 | |
| 82 | /* RF Report types bitfield */ |
Benjamin Tissoires | a17dd1f | 2019-04-20 13:21:45 +0200 | [diff] [blame] | 83 | #define STD_KEYBOARD BIT(1) |
| 84 | #define STD_MOUSE BIT(2) |
| 85 | #define MULTIMEDIA BIT(3) |
| 86 | #define POWER_KEYS BIT(4) |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 87 | #define KBD_MOUSE BIT(5) |
Benjamin Tissoires | a17dd1f | 2019-04-20 13:21:45 +0200 | [diff] [blame] | 88 | #define MEDIA_CENTER BIT(8) |
| 89 | #define KBD_LEDS BIT(14) |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 90 | /* Fake (bitnr > NUMBER_OF_HID_REPORTS) bit to track HID++ capability */ |
| 91 | #define HIDPP BIT_ULL(63) |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 92 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 93 | /* HID++ Device Connected Notification */ |
| 94 | #define REPORT_TYPE_NOTIF_DEVICE_CONNECTED 0x41 |
| 95 | #define HIDPP_PARAM_PROTO_TYPE 0x00 |
| 96 | #define HIDPP_PARAM_DEVICE_INFO 0x01 |
| 97 | #define HIDPP_PARAM_EQUAD_LSB 0x02 |
| 98 | #define HIDPP_PARAM_EQUAD_MSB 0x03 |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 99 | #define HIDPP_PARAM_27MHZ_DEVID 0x03 |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 100 | #define HIDPP_DEVICE_TYPE_MASK GENMASK(3, 0) |
| 101 | #define HIDPP_LINK_STATUS_MASK BIT(6) |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 102 | #define HIDPP_MANUFACTURER_MASK BIT(7) |
Hans de Goede | 7383354 | 2021-04-04 20:56:09 +0200 | [diff] [blame] | 103 | #define HIDPP_27MHZ_SECURE_MASK BIT(7) |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 104 | |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 105 | #define HIDPP_DEVICE_TYPE_KEYBOARD 1 |
| 106 | #define HIDPP_DEVICE_TYPE_MOUSE 2 |
| 107 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 108 | #define HIDPP_SET_REGISTER 0x80 |
Benjamin Tissoires | c034041 | 2019-04-20 13:21:46 +0200 | [diff] [blame] | 109 | #define HIDPP_GET_LONG_REGISTER 0x83 |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 110 | #define HIDPP_REG_CONNECTION_STATE 0x02 |
Benjamin Tissoires | c034041 | 2019-04-20 13:21:46 +0200 | [diff] [blame] | 111 | #define HIDPP_REG_PAIRING_INFORMATION 0xB5 |
| 112 | #define HIDPP_PAIRING_INFORMATION 0x20 |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 113 | #define HIDPP_FAKE_DEVICE_ARRIVAL 0x02 |
| 114 | |
| 115 | enum recvr_type { |
| 116 | recvr_type_dj, |
| 117 | recvr_type_hidpp, |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 118 | recvr_type_gaming_hidpp, |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 119 | recvr_type_mouse_only, |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 120 | recvr_type_27mhz, |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 121 | recvr_type_bluetooth, |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 122 | recvr_type_dinovo, |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 123 | }; |
Benjamin Tissoires | c034041 | 2019-04-20 13:21:46 +0200 | [diff] [blame] | 124 | |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 125 | struct dj_report { |
| 126 | u8 report_id; |
| 127 | u8 device_index; |
| 128 | u8 report_type; |
| 129 | u8 report_params[DJREPORT_SHORT_LENGTH - 3]; |
| 130 | }; |
| 131 | |
Benjamin Tissoires | 7bb56a5 | 2019-04-20 13:21:44 +0200 | [diff] [blame] | 132 | struct hidpp_event { |
| 133 | u8 report_id; |
| 134 | u8 device_index; |
| 135 | u8 sub_id; |
| 136 | u8 params[HIDPP_REPORT_LONG_LENGTH - 3U]; |
| 137 | } __packed; |
| 138 | |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 139 | struct dj_receiver_dev { |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 140 | struct hid_device *mouse; |
| 141 | struct hid_device *keyboard; |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 142 | struct hid_device *hidpp; |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 143 | struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES + |
| 144 | DJ_DEVICE_INDEX_MIN]; |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 145 | struct list_head list; |
| 146 | struct kref kref; |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 147 | struct work_struct work; |
| 148 | struct kfifo notif_fifo; |
Hans de Goede | b6aeedd | 2019-04-20 13:21:53 +0200 | [diff] [blame] | 149 | unsigned long last_query; /* in jiffies */ |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 150 | bool ready; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 151 | enum recvr_type type; |
| 152 | unsigned int unnumbered_application; |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 153 | spinlock_t lock; |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | struct dj_device { |
| 157 | struct hid_device *hdev; |
| 158 | struct dj_receiver_dev *dj_receiver_dev; |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 159 | u64 reports_supported; |
Benjamin Tissoires | 8cb3746 | 2014-09-30 13:18:26 -0400 | [diff] [blame] | 160 | u8 device_index; |
| 161 | }; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 162 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 163 | #define WORKITEM_TYPE_EMPTY 0 |
| 164 | #define WORKITEM_TYPE_PAIRED 1 |
| 165 | #define WORKITEM_TYPE_UNPAIRED 2 |
| 166 | #define WORKITEM_TYPE_UNKNOWN 255 |
| 167 | |
| 168 | struct dj_workitem { |
| 169 | u8 type; /* WORKITEM_TYPE_* */ |
| 170 | u8 device_index; |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 171 | u8 device_type; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 172 | u8 quad_id_msb; |
| 173 | u8 quad_id_lsb; |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 174 | u64 reports_supported; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 177 | /* Keyboard descriptor (1) */ |
| 178 | static const char kbd_descriptor[] = { |
| 179 | 0x05, 0x01, /* USAGE_PAGE (generic Desktop) */ |
| 180 | 0x09, 0x06, /* USAGE (Keyboard) */ |
| 181 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 182 | 0x85, 0x01, /* REPORT_ID (1) */ |
| 183 | 0x95, 0x08, /* REPORT_COUNT (8) */ |
| 184 | 0x75, 0x01, /* REPORT_SIZE (1) */ |
| 185 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ |
| 186 | 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ |
| 187 | 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ |
| 188 | 0x19, 0xE0, /* USAGE_MINIMUM (Left Control) */ |
| 189 | 0x29, 0xE7, /* USAGE_MAXIMUM (Right GUI) */ |
| 190 | 0x81, 0x02, /* INPUT (Data,Var,Abs) */ |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 191 | 0x95, 0x06, /* REPORT_COUNT (6) */ |
| 192 | 0x75, 0x08, /* REPORT_SIZE (8) */ |
| 193 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ |
| 194 | 0x26, 0xFF, 0x00, /* LOGICAL_MAXIMUM (255) */ |
| 195 | 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ |
| 196 | 0x19, 0x00, /* USAGE_MINIMUM (no event) */ |
| 197 | 0x2A, 0xFF, 0x00, /* USAGE_MAXIMUM (reserved) */ |
| 198 | 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ |
Benjamin Tissoires | 0e40d35 | 2014-02-05 16:33:17 -0500 | [diff] [blame] | 199 | 0x85, 0x0e, /* REPORT_ID (14) */ |
| 200 | 0x05, 0x08, /* USAGE PAGE (LED page) */ |
| 201 | 0x95, 0x05, /* REPORT COUNT (5) */ |
| 202 | 0x75, 0x01, /* REPORT SIZE (1) */ |
| 203 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ |
| 204 | 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ |
| 205 | 0x19, 0x01, /* USAGE MINIMUM (1) */ |
| 206 | 0x29, 0x05, /* USAGE MAXIMUM (5) */ |
| 207 | 0x91, 0x02, /* OUTPUT (Data, Variable, Absolute) */ |
| 208 | 0x95, 0x01, /* REPORT COUNT (1) */ |
| 209 | 0x75, 0x03, /* REPORT SIZE (3) */ |
| 210 | 0x91, 0x01, /* OUTPUT (Constant) */ |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 211 | 0xC0 |
| 212 | }; |
| 213 | |
| 214 | /* Mouse descriptor (2) */ |
| 215 | static const char mse_descriptor[] = { |
| 216 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
| 217 | 0x09, 0x02, /* USAGE (Mouse) */ |
| 218 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 219 | 0x85, 0x02, /* REPORT_ID = 2 */ |
| 220 | 0x09, 0x01, /* USAGE (pointer) */ |
| 221 | 0xA1, 0x00, /* COLLECTION (physical) */ |
| 222 | 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
| 223 | 0x19, 0x01, /* USAGE_MIN (1) */ |
| 224 | 0x29, 0x10, /* USAGE_MAX (16) */ |
| 225 | 0x15, 0x00, /* LOGICAL_MIN (0) */ |
| 226 | 0x25, 0x01, /* LOGICAL_MAX (1) */ |
| 227 | 0x95, 0x10, /* REPORT_COUNT (16) */ |
| 228 | 0x75, 0x01, /* REPORT_SIZE (1) */ |
| 229 | 0x81, 0x02, /* INPUT (data var abs) */ |
| 230 | 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
| 231 | 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */ |
| 232 | 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */ |
| 233 | 0x75, 0x0C, /* REPORT_SIZE (12) */ |
| 234 | 0x95, 0x02, /* REPORT_COUNT (2) */ |
| 235 | 0x09, 0x30, /* USAGE (X) */ |
| 236 | 0x09, 0x31, /* USAGE (Y) */ |
| 237 | 0x81, 0x06, /* INPUT */ |
| 238 | 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
| 239 | 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
| 240 | 0x75, 0x08, /* REPORT_SIZE (8) */ |
| 241 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 242 | 0x09, 0x38, /* USAGE (wheel) */ |
| 243 | 0x81, 0x06, /* INPUT */ |
| 244 | 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
| 245 | 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
| 246 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 247 | 0x81, 0x06, /* INPUT */ |
| 248 | 0xC0, /* END_COLLECTION */ |
| 249 | 0xC0, /* END_COLLECTION */ |
| 250 | }; |
| 251 | |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 252 | /* Mouse descriptor (2) for 27 MHz receiver, only 8 buttons */ |
| 253 | static const char mse_27mhz_descriptor[] = { |
| 254 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
| 255 | 0x09, 0x02, /* USAGE (Mouse) */ |
| 256 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 257 | 0x85, 0x02, /* REPORT_ID = 2 */ |
| 258 | 0x09, 0x01, /* USAGE (pointer) */ |
| 259 | 0xA1, 0x00, /* COLLECTION (physical) */ |
| 260 | 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
| 261 | 0x19, 0x01, /* USAGE_MIN (1) */ |
| 262 | 0x29, 0x08, /* USAGE_MAX (8) */ |
| 263 | 0x15, 0x00, /* LOGICAL_MIN (0) */ |
| 264 | 0x25, 0x01, /* LOGICAL_MAX (1) */ |
| 265 | 0x95, 0x08, /* REPORT_COUNT (8) */ |
| 266 | 0x75, 0x01, /* REPORT_SIZE (1) */ |
| 267 | 0x81, 0x02, /* INPUT (data var abs) */ |
| 268 | 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
| 269 | 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */ |
| 270 | 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */ |
| 271 | 0x75, 0x0C, /* REPORT_SIZE (12) */ |
| 272 | 0x95, 0x02, /* REPORT_COUNT (2) */ |
| 273 | 0x09, 0x30, /* USAGE (X) */ |
| 274 | 0x09, 0x31, /* USAGE (Y) */ |
| 275 | 0x81, 0x06, /* INPUT */ |
| 276 | 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
| 277 | 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
| 278 | 0x75, 0x08, /* REPORT_SIZE (8) */ |
| 279 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 280 | 0x09, 0x38, /* USAGE (wheel) */ |
| 281 | 0x81, 0x06, /* INPUT */ |
| 282 | 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
| 283 | 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
| 284 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 285 | 0x81, 0x06, /* INPUT */ |
| 286 | 0xC0, /* END_COLLECTION */ |
| 287 | 0xC0, /* END_COLLECTION */ |
| 288 | }; |
| 289 | |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 290 | /* Mouse descriptor (2) for Bluetooth receiver, low-res hwheel, 12 buttons */ |
| 291 | static const char mse_bluetooth_descriptor[] = { |
| 292 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
| 293 | 0x09, 0x02, /* USAGE (Mouse) */ |
| 294 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 295 | 0x85, 0x02, /* REPORT_ID = 2 */ |
| 296 | 0x09, 0x01, /* USAGE (pointer) */ |
| 297 | 0xA1, 0x00, /* COLLECTION (physical) */ |
| 298 | 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
| 299 | 0x19, 0x01, /* USAGE_MIN (1) */ |
| 300 | 0x29, 0x08, /* USAGE_MAX (8) */ |
| 301 | 0x15, 0x00, /* LOGICAL_MIN (0) */ |
| 302 | 0x25, 0x01, /* LOGICAL_MAX (1) */ |
| 303 | 0x95, 0x08, /* REPORT_COUNT (8) */ |
| 304 | 0x75, 0x01, /* REPORT_SIZE (1) */ |
| 305 | 0x81, 0x02, /* INPUT (data var abs) */ |
| 306 | 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
| 307 | 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */ |
| 308 | 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */ |
| 309 | 0x75, 0x0C, /* REPORT_SIZE (12) */ |
| 310 | 0x95, 0x02, /* REPORT_COUNT (2) */ |
| 311 | 0x09, 0x30, /* USAGE (X) */ |
| 312 | 0x09, 0x31, /* USAGE (Y) */ |
| 313 | 0x81, 0x06, /* INPUT */ |
| 314 | 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
| 315 | 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
| 316 | 0x75, 0x08, /* REPORT_SIZE (8) */ |
| 317 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 318 | 0x09, 0x38, /* USAGE (wheel) */ |
| 319 | 0x81, 0x06, /* INPUT */ |
| 320 | 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
| 321 | 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
| 322 | 0x15, 0xF9, /* LOGICAL_MIN (-7) */ |
| 323 | 0x25, 0x07, /* LOGICAL_MAX (7) */ |
| 324 | 0x75, 0x04, /* REPORT_SIZE (4) */ |
| 325 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 326 | 0x81, 0x06, /* INPUT */ |
| 327 | 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
| 328 | 0x19, 0x09, /* USAGE_MIN (9) */ |
| 329 | 0x29, 0x0C, /* USAGE_MAX (12) */ |
| 330 | 0x15, 0x00, /* LOGICAL_MIN (0) */ |
| 331 | 0x25, 0x01, /* LOGICAL_MAX (1) */ |
| 332 | 0x75, 0x01, /* REPORT_SIZE (1) */ |
| 333 | 0x95, 0x04, /* REPORT_COUNT (4) */ |
Hans de Goede | eec231e | 2020-11-14 10:45:31 +0100 | [diff] [blame] | 334 | 0x81, 0x02, /* INPUT (Data,Var,Abs) */ |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 335 | 0xC0, /* END_COLLECTION */ |
| 336 | 0xC0, /* END_COLLECTION */ |
| 337 | }; |
| 338 | |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 339 | /* Mouse descriptor (5) for Bluetooth receiver, normal-res hwheel, 8 buttons */ |
| 340 | static const char mse5_bluetooth_descriptor[] = { |
| 341 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
| 342 | 0x09, 0x02, /* Usage (Mouse) */ |
| 343 | 0xa1, 0x01, /* Collection (Application) */ |
| 344 | 0x85, 0x05, /* Report ID (5) */ |
| 345 | 0x09, 0x01, /* Usage (Pointer) */ |
| 346 | 0xa1, 0x00, /* Collection (Physical) */ |
| 347 | 0x05, 0x09, /* Usage Page (Button) */ |
| 348 | 0x19, 0x01, /* Usage Minimum (1) */ |
| 349 | 0x29, 0x08, /* Usage Maximum (8) */ |
| 350 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 351 | 0x25, 0x01, /* Logical Maximum (1) */ |
| 352 | 0x95, 0x08, /* Report Count (8) */ |
| 353 | 0x75, 0x01, /* Report Size (1) */ |
| 354 | 0x81, 0x02, /* Input (Data,Var,Abs) */ |
| 355 | 0x05, 0x01, /* Usage Page (Generic Desktop) */ |
| 356 | 0x16, 0x01, 0xf8, /* Logical Minimum (-2047) */ |
| 357 | 0x26, 0xff, 0x07, /* Logical Maximum (2047) */ |
| 358 | 0x75, 0x0c, /* Report Size (12) */ |
| 359 | 0x95, 0x02, /* Report Count (2) */ |
| 360 | 0x09, 0x30, /* Usage (X) */ |
| 361 | 0x09, 0x31, /* Usage (Y) */ |
| 362 | 0x81, 0x06, /* Input (Data,Var,Rel) */ |
| 363 | 0x15, 0x81, /* Logical Minimum (-127) */ |
| 364 | 0x25, 0x7f, /* Logical Maximum (127) */ |
| 365 | 0x75, 0x08, /* Report Size (8) */ |
| 366 | 0x95, 0x01, /* Report Count (1) */ |
| 367 | 0x09, 0x38, /* Usage (Wheel) */ |
| 368 | 0x81, 0x06, /* Input (Data,Var,Rel) */ |
| 369 | 0x05, 0x0c, /* Usage Page (Consumer Devices) */ |
| 370 | 0x0a, 0x38, 0x02, /* Usage (AC Pan) */ |
| 371 | 0x15, 0x81, /* Logical Minimum (-127) */ |
| 372 | 0x25, 0x7f, /* Logical Maximum (127) */ |
| 373 | 0x75, 0x08, /* Report Size (8) */ |
| 374 | 0x95, 0x01, /* Report Count (1) */ |
| 375 | 0x81, 0x06, /* Input (Data,Var,Rel) */ |
| 376 | 0xc0, /* End Collection */ |
| 377 | 0xc0, /* End Collection */ |
| 378 | }; |
| 379 | |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 380 | /* Gaming Mouse descriptor (2) */ |
| 381 | static const char mse_high_res_descriptor[] = { |
| 382 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
| 383 | 0x09, 0x02, /* USAGE (Mouse) */ |
| 384 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 385 | 0x85, 0x02, /* REPORT_ID = 2 */ |
| 386 | 0x09, 0x01, /* USAGE (pointer) */ |
| 387 | 0xA1, 0x00, /* COLLECTION (physical) */ |
| 388 | 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
| 389 | 0x19, 0x01, /* USAGE_MIN (1) */ |
| 390 | 0x29, 0x10, /* USAGE_MAX (16) */ |
| 391 | 0x15, 0x00, /* LOGICAL_MIN (0) */ |
| 392 | 0x25, 0x01, /* LOGICAL_MAX (1) */ |
| 393 | 0x95, 0x10, /* REPORT_COUNT (16) */ |
| 394 | 0x75, 0x01, /* REPORT_SIZE (1) */ |
| 395 | 0x81, 0x02, /* INPUT (data var abs) */ |
| 396 | 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
| 397 | 0x16, 0x01, 0x80, /* LOGICAL_MIN (-32767) */ |
| 398 | 0x26, 0xFF, 0x7F, /* LOGICAL_MAX (32767) */ |
| 399 | 0x75, 0x10, /* REPORT_SIZE (16) */ |
| 400 | 0x95, 0x02, /* REPORT_COUNT (2) */ |
| 401 | 0x09, 0x30, /* USAGE (X) */ |
| 402 | 0x09, 0x31, /* USAGE (Y) */ |
| 403 | 0x81, 0x06, /* INPUT */ |
| 404 | 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
| 405 | 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
| 406 | 0x75, 0x08, /* REPORT_SIZE (8) */ |
| 407 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 408 | 0x09, 0x38, /* USAGE (wheel) */ |
| 409 | 0x81, 0x06, /* INPUT */ |
| 410 | 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
| 411 | 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
| 412 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 413 | 0x81, 0x06, /* INPUT */ |
| 414 | 0xC0, /* END_COLLECTION */ |
| 415 | 0xC0, /* END_COLLECTION */ |
| 416 | }; |
| 417 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 418 | /* Consumer Control descriptor (3) */ |
| 419 | static const char consumer_descriptor[] = { |
| 420 | 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */ |
| 421 | 0x09, 0x01, /* USAGE (Consumer Control) */ |
| 422 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 423 | 0x85, 0x03, /* REPORT_ID = 3 */ |
| 424 | 0x75, 0x10, /* REPORT_SIZE (16) */ |
| 425 | 0x95, 0x02, /* REPORT_COUNT (2) */ |
| 426 | 0x15, 0x01, /* LOGICAL_MIN (1) */ |
Olivier Gay | 5b6cc12 | 2019-07-29 19:21:52 +0200 | [diff] [blame] | 427 | 0x26, 0xFF, 0x02, /* LOGICAL_MAX (767) */ |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 428 | 0x19, 0x01, /* USAGE_MIN (1) */ |
Olivier Gay | 5b6cc12 | 2019-07-29 19:21:52 +0200 | [diff] [blame] | 429 | 0x2A, 0xFF, 0x02, /* USAGE_MAX (767) */ |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 430 | 0x81, 0x00, /* INPUT (Data Ary Abs) */ |
| 431 | 0xC0, /* END_COLLECTION */ |
| 432 | }; /* */ |
| 433 | |
| 434 | /* System control descriptor (4) */ |
| 435 | static const char syscontrol_descriptor[] = { |
| 436 | 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
| 437 | 0x09, 0x80, /* USAGE (System Control) */ |
| 438 | 0xA1, 0x01, /* COLLECTION (Application) */ |
| 439 | 0x85, 0x04, /* REPORT_ID = 4 */ |
| 440 | 0x75, 0x02, /* REPORT_SIZE (2) */ |
| 441 | 0x95, 0x01, /* REPORT_COUNT (1) */ |
| 442 | 0x15, 0x01, /* LOGICAL_MIN (1) */ |
| 443 | 0x25, 0x03, /* LOGICAL_MAX (3) */ |
| 444 | 0x09, 0x82, /* USAGE (System Sleep) */ |
| 445 | 0x09, 0x81, /* USAGE (System Power Down) */ |
| 446 | 0x09, 0x83, /* USAGE (System Wake Up) */ |
| 447 | 0x81, 0x60, /* INPUT (Data Ary Abs NPrf Null) */ |
| 448 | 0x75, 0x06, /* REPORT_SIZE (6) */ |
| 449 | 0x81, 0x03, /* INPUT (Cnst Var Abs) */ |
| 450 | 0xC0, /* END_COLLECTION */ |
| 451 | }; |
| 452 | |
| 453 | /* Media descriptor (8) */ |
| 454 | static const char media_descriptor[] = { |
| 455 | 0x06, 0xbc, 0xff, /* Usage Page 0xffbc */ |
| 456 | 0x09, 0x88, /* Usage 0x0088 */ |
| 457 | 0xa1, 0x01, /* BeginCollection */ |
| 458 | 0x85, 0x08, /* Report ID 8 */ |
| 459 | 0x19, 0x01, /* Usage Min 0x0001 */ |
| 460 | 0x29, 0xff, /* Usage Max 0x00ff */ |
| 461 | 0x15, 0x01, /* Logical Min 1 */ |
| 462 | 0x26, 0xff, 0x00, /* Logical Max 255 */ |
| 463 | 0x75, 0x08, /* Report Size 8 */ |
| 464 | 0x95, 0x01, /* Report Count 1 */ |
| 465 | 0x81, 0x00, /* Input */ |
| 466 | 0xc0, /* EndCollection */ |
| 467 | }; /* */ |
| 468 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 469 | /* HIDPP descriptor */ |
| 470 | static const char hidpp_descriptor[] = { |
| 471 | 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */ |
| 472 | 0x09, 0x01, /* Usage (Vendor Usage 1) */ |
| 473 | 0xa1, 0x01, /* Collection (Application) */ |
| 474 | 0x85, 0x10, /* Report ID (16) */ |
| 475 | 0x75, 0x08, /* Report Size (8) */ |
| 476 | 0x95, 0x06, /* Report Count (6) */ |
| 477 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 478 | 0x26, 0xff, 0x00, /* Logical Maximum (255) */ |
| 479 | 0x09, 0x01, /* Usage (Vendor Usage 1) */ |
| 480 | 0x81, 0x00, /* Input (Data,Arr,Abs) */ |
| 481 | 0x09, 0x01, /* Usage (Vendor Usage 1) */ |
| 482 | 0x91, 0x00, /* Output (Data,Arr,Abs) */ |
| 483 | 0xc0, /* End Collection */ |
| 484 | 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */ |
| 485 | 0x09, 0x02, /* Usage (Vendor Usage 2) */ |
| 486 | 0xa1, 0x01, /* Collection (Application) */ |
| 487 | 0x85, 0x11, /* Report ID (17) */ |
| 488 | 0x75, 0x08, /* Report Size (8) */ |
| 489 | 0x95, 0x13, /* Report Count (19) */ |
| 490 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 491 | 0x26, 0xff, 0x00, /* Logical Maximum (255) */ |
| 492 | 0x09, 0x02, /* Usage (Vendor Usage 2) */ |
| 493 | 0x81, 0x00, /* Input (Data,Arr,Abs) */ |
| 494 | 0x09, 0x02, /* Usage (Vendor Usage 2) */ |
| 495 | 0x91, 0x00, /* Output (Data,Arr,Abs) */ |
| 496 | 0xc0, /* End Collection */ |
| 497 | 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */ |
| 498 | 0x09, 0x04, /* Usage (Vendor Usage 0x04) */ |
| 499 | 0xa1, 0x01, /* Collection (Application) */ |
| 500 | 0x85, 0x20, /* Report ID (32) */ |
| 501 | 0x75, 0x08, /* Report Size (8) */ |
| 502 | 0x95, 0x0e, /* Report Count (14) */ |
| 503 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 504 | 0x26, 0xff, 0x00, /* Logical Maximum (255) */ |
| 505 | 0x09, 0x41, /* Usage (Vendor Usage 0x41) */ |
| 506 | 0x81, 0x00, /* Input (Data,Arr,Abs) */ |
| 507 | 0x09, 0x41, /* Usage (Vendor Usage 0x41) */ |
| 508 | 0x91, 0x00, /* Output (Data,Arr,Abs) */ |
| 509 | 0x85, 0x21, /* Report ID (33) */ |
| 510 | 0x95, 0x1f, /* Report Count (31) */ |
| 511 | 0x15, 0x00, /* Logical Minimum (0) */ |
| 512 | 0x26, 0xff, 0x00, /* Logical Maximum (255) */ |
| 513 | 0x09, 0x42, /* Usage (Vendor Usage 0x42) */ |
| 514 | 0x81, 0x00, /* Input (Data,Arr,Abs) */ |
| 515 | 0x09, 0x42, /* Usage (Vendor Usage 0x42) */ |
| 516 | 0x91, 0x00, /* Output (Data,Arr,Abs) */ |
| 517 | 0xc0, /* End Collection */ |
| 518 | }; |
| 519 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 520 | /* Maximum size of all defined hid reports in bytes (including report id) */ |
| 521 | #define MAX_REPORT_SIZE 8 |
| 522 | |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 523 | /* Make sure all descriptors are present here */ |
| 524 | #define MAX_RDESC_SIZE \ |
| 525 | (sizeof(kbd_descriptor) + \ |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 526 | sizeof(mse_bluetooth_descriptor) + \ |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 527 | sizeof(mse5_bluetooth_descriptor) + \ |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 528 | sizeof(consumer_descriptor) + \ |
| 529 | sizeof(syscontrol_descriptor) + \ |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 530 | sizeof(media_descriptor) + \ |
| 531 | sizeof(hidpp_descriptor)) |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 532 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 533 | /* Number of possible hid report types that can be created by this driver. |
| 534 | * |
| 535 | * Right now, RF report types have the same report types (or report id's) |
| 536 | * than the hid report created from those RF reports. In the future |
| 537 | * this doesnt have to be true. |
| 538 | * |
| 539 | * For instance, RF report type 0x01 which has a size of 8 bytes, corresponds |
| 540 | * to hid report id 0x01, this is standard keyboard. Same thing applies to mice |
| 541 | * reports and consumer control, etc. If a new RF report is created, it doesn't |
| 542 | * has to have the same report id as its corresponding hid report, so an |
| 543 | * translation may have to take place for future report types. |
| 544 | */ |
| 545 | #define NUMBER_OF_HID_REPORTS 32 |
| 546 | static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = { |
| 547 | [1] = 8, /* Standard keyboard */ |
| 548 | [2] = 8, /* Standard mouse */ |
| 549 | [3] = 5, /* Consumer control */ |
| 550 | [4] = 2, /* System control */ |
| 551 | [8] = 2, /* Media Center */ |
| 552 | }; |
| 553 | |
| 554 | |
| 555 | #define LOGITECH_DJ_INTERFACE_NUMBER 0x02 |
| 556 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 557 | static struct hid_ll_driver logi_dj_ll_driver; |
| 558 | |
Nestor Lopez Casado | c63e0e3 | 2013-07-18 06:21:30 -0700 | [diff] [blame] | 559 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev); |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 560 | static void delayedwork_callback(struct work_struct *work); |
| 561 | |
| 562 | static LIST_HEAD(dj_hdev_list); |
| 563 | static DEFINE_MUTEX(dj_hdev_list_lock); |
| 564 | |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 565 | static bool recvr_type_is_bluetooth(enum recvr_type type) |
| 566 | { |
| 567 | return type == recvr_type_bluetooth || type == recvr_type_dinovo; |
| 568 | } |
| 569 | |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 570 | /* |
| 571 | * dj/HID++ receivers are really a single logical entity, but for BIOS/Windows |
| 572 | * compatibility they have multiple USB interfaces. On HID++ receivers we need |
| 573 | * to listen for input reports on both interfaces. The functions below are used |
| 574 | * to create a single struct dj_receiver_dev for all interfaces belonging to |
| 575 | * a single USB-device / receiver. |
| 576 | */ |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 577 | static struct dj_receiver_dev *dj_find_receiver_dev(struct hid_device *hdev, |
| 578 | enum recvr_type type) |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 579 | { |
| 580 | struct dj_receiver_dev *djrcv_dev; |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 581 | char sep; |
| 582 | |
| 583 | /* |
| 584 | * The bluetooth receiver contains a built-in hub and has separate |
| 585 | * USB-devices for the keyboard and mouse interfaces. |
| 586 | */ |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 587 | sep = recvr_type_is_bluetooth(type) ? '.' : '/'; |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 588 | |
| 589 | /* Try to find an already-probed interface from the same device */ |
| 590 | list_for_each_entry(djrcv_dev, &dj_hdev_list, list) { |
| 591 | if (djrcv_dev->mouse && |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 592 | hid_compare_device_paths(hdev, djrcv_dev->mouse, sep)) { |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 593 | kref_get(&djrcv_dev->kref); |
| 594 | return djrcv_dev; |
| 595 | } |
| 596 | if (djrcv_dev->keyboard && |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 597 | hid_compare_device_paths(hdev, djrcv_dev->keyboard, sep)) { |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 598 | kref_get(&djrcv_dev->kref); |
| 599 | return djrcv_dev; |
| 600 | } |
| 601 | if (djrcv_dev->hidpp && |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 602 | hid_compare_device_paths(hdev, djrcv_dev->hidpp, sep)) { |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 603 | kref_get(&djrcv_dev->kref); |
| 604 | return djrcv_dev; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | return NULL; |
| 609 | } |
| 610 | |
| 611 | static void dj_release_receiver_dev(struct kref *kref) |
| 612 | { |
| 613 | struct dj_receiver_dev *djrcv_dev = container_of(kref, struct dj_receiver_dev, kref); |
| 614 | |
| 615 | list_del(&djrcv_dev->list); |
| 616 | kfifo_free(&djrcv_dev->notif_fifo); |
| 617 | kfree(djrcv_dev); |
| 618 | } |
| 619 | |
| 620 | static void dj_put_receiver_dev(struct hid_device *hdev) |
| 621 | { |
| 622 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
| 623 | |
| 624 | mutex_lock(&dj_hdev_list_lock); |
| 625 | |
| 626 | if (djrcv_dev->mouse == hdev) |
| 627 | djrcv_dev->mouse = NULL; |
| 628 | if (djrcv_dev->keyboard == hdev) |
| 629 | djrcv_dev->keyboard = NULL; |
| 630 | if (djrcv_dev->hidpp == hdev) |
| 631 | djrcv_dev->hidpp = NULL; |
| 632 | |
| 633 | kref_put(&djrcv_dev->kref, dj_release_receiver_dev); |
| 634 | |
| 635 | mutex_unlock(&dj_hdev_list_lock); |
| 636 | } |
| 637 | |
| 638 | static struct dj_receiver_dev *dj_get_receiver_dev(struct hid_device *hdev, |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 639 | enum recvr_type type, |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 640 | unsigned int application, |
| 641 | bool is_hidpp) |
| 642 | { |
| 643 | struct dj_receiver_dev *djrcv_dev; |
| 644 | |
| 645 | mutex_lock(&dj_hdev_list_lock); |
| 646 | |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 647 | djrcv_dev = dj_find_receiver_dev(hdev, type); |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 648 | if (!djrcv_dev) { |
| 649 | djrcv_dev = kzalloc(sizeof(*djrcv_dev), GFP_KERNEL); |
| 650 | if (!djrcv_dev) |
| 651 | goto out; |
| 652 | |
| 653 | INIT_WORK(&djrcv_dev->work, delayedwork_callback); |
| 654 | spin_lock_init(&djrcv_dev->lock); |
| 655 | if (kfifo_alloc(&djrcv_dev->notif_fifo, |
| 656 | DJ_MAX_NUMBER_NOTIFS * sizeof(struct dj_workitem), |
| 657 | GFP_KERNEL)) { |
| 658 | kfree(djrcv_dev); |
| 659 | djrcv_dev = NULL; |
| 660 | goto out; |
| 661 | } |
| 662 | kref_init(&djrcv_dev->kref); |
| 663 | list_add_tail(&djrcv_dev->list, &dj_hdev_list); |
Hans de Goede | b6aeedd | 2019-04-20 13:21:53 +0200 | [diff] [blame] | 664 | djrcv_dev->last_query = jiffies; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 665 | djrcv_dev->type = type; |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | if (application == HID_GD_KEYBOARD) |
| 669 | djrcv_dev->keyboard = hdev; |
| 670 | if (application == HID_GD_MOUSE) |
| 671 | djrcv_dev->mouse = hdev; |
| 672 | if (is_hidpp) |
| 673 | djrcv_dev->hidpp = hdev; |
| 674 | |
| 675 | hid_set_drvdata(hdev, djrcv_dev); |
| 676 | out: |
| 677 | mutex_unlock(&dj_hdev_list_lock); |
| 678 | return djrcv_dev; |
| 679 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 680 | |
| 681 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 682 | struct dj_workitem *workitem) |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 683 | { |
| 684 | /* Called in delayed work context */ |
| 685 | struct dj_device *dj_dev; |
| 686 | unsigned long flags; |
| 687 | |
| 688 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 689 | dj_dev = djrcv_dev->paired_dj_devices[workitem->device_index]; |
| 690 | djrcv_dev->paired_dj_devices[workitem->device_index] = NULL; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 691 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 692 | |
| 693 | if (dj_dev != NULL) { |
| 694 | hid_destroy_device(dj_dev->hdev); |
| 695 | kfree(dj_dev); |
| 696 | } else { |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 697 | hid_err(djrcv_dev->hidpp, "%s: can't destroy a NULL device\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 698 | __func__); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 703 | struct dj_workitem *workitem) |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 704 | { |
| 705 | /* Called in delayed work context */ |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 706 | struct hid_device *djrcv_hdev = djrcv_dev->hidpp; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 707 | struct hid_device *dj_hiddev; |
| 708 | struct dj_device *dj_dev; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 709 | u8 device_index = workitem->device_index; |
Hans de Goede | f41d766 | 2019-04-20 13:21:50 +0200 | [diff] [blame] | 710 | unsigned long flags; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 711 | |
| 712 | /* Device index goes from 1 to 6, we need 3 bytes to store the |
| 713 | * semicolon, the index, and a null terminator |
| 714 | */ |
| 715 | unsigned char tmpstr[3]; |
| 716 | |
Hans de Goede | f41d766 | 2019-04-20 13:21:50 +0200 | [diff] [blame] | 717 | /* We are the only one ever adding a device, no need to lock */ |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 718 | if (djrcv_dev->paired_dj_devices[device_index]) { |
Nestor Lopez Casado | c63e0e3 | 2013-07-18 06:21:30 -0700 | [diff] [blame] | 719 | /* The device is already known. No need to reallocate it. */ |
| 720 | dbg_hid("%s: device is already known\n", __func__); |
| 721 | return; |
| 722 | } |
| 723 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 724 | dj_hiddev = hid_allocate_device(); |
| 725 | if (IS_ERR(dj_hiddev)) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 726 | hid_err(djrcv_hdev, "%s: hid_allocate_dev failed\n", __func__); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 727 | return; |
| 728 | } |
| 729 | |
| 730 | dj_hiddev->ll_driver = &logi_dj_ll_driver; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 731 | |
| 732 | dj_hiddev->dev.parent = &djrcv_hdev->dev; |
| 733 | dj_hiddev->bus = BUS_USB; |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 734 | dj_hiddev->vendor = djrcv_hdev->vendor; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 735 | dj_hiddev->product = (workitem->quad_id_msb << 8) | |
| 736 | workitem->quad_id_lsb; |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 737 | if (workitem->device_type) { |
| 738 | const char *type_str = "Device"; |
| 739 | |
| 740 | switch (workitem->device_type) { |
| 741 | case 0x01: type_str = "Keyboard"; break; |
| 742 | case 0x02: type_str = "Mouse"; break; |
| 743 | case 0x03: type_str = "Numpad"; break; |
| 744 | case 0x04: type_str = "Presenter"; break; |
| 745 | case 0x07: type_str = "Remote Control"; break; |
| 746 | case 0x08: type_str = "Trackball"; break; |
| 747 | case 0x09: type_str = "Touchpad"; break; |
| 748 | } |
| 749 | snprintf(dj_hiddev->name, sizeof(dj_hiddev->name), |
| 750 | "Logitech Wireless %s PID:%04x", |
| 751 | type_str, dj_hiddev->product); |
| 752 | } else { |
| 753 | snprintf(dj_hiddev->name, sizeof(dj_hiddev->name), |
Filipe Laíns | c08ce25 | 2020-01-12 23:50:09 +0000 | [diff] [blame] | 754 | "Logitech Wireless Device PID:%04x", |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 755 | dj_hiddev->product); |
| 756 | } |
Benjamin Tissoires | d610274 | 2014-09-30 13:18:25 -0400 | [diff] [blame] | 757 | |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 758 | if (djrcv_dev->type == recvr_type_27mhz) |
| 759 | dj_hiddev->group = HID_GROUP_LOGITECH_27MHZ_DEVICE; |
| 760 | else |
| 761 | dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 762 | |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 763 | memcpy(dj_hiddev->phys, djrcv_hdev->phys, sizeof(djrcv_hdev->phys)); |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 764 | snprintf(tmpstr, sizeof(tmpstr), ":%d", device_index); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 765 | strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys)); |
| 766 | |
| 767 | dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL); |
| 768 | |
| 769 | if (!dj_dev) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 770 | hid_err(djrcv_hdev, "%s: failed allocating dj_dev\n", __func__); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 771 | goto dj_device_allocate_fail; |
| 772 | } |
| 773 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 774 | dj_dev->reports_supported = workitem->reports_supported; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 775 | dj_dev->hdev = dj_hiddev; |
| 776 | dj_dev->dj_receiver_dev = djrcv_dev; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 777 | dj_dev->device_index = device_index; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 778 | dj_hiddev->driver_data = dj_dev; |
| 779 | |
Hans de Goede | f41d766 | 2019-04-20 13:21:50 +0200 | [diff] [blame] | 780 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 781 | djrcv_dev->paired_dj_devices[device_index] = dj_dev; |
Hans de Goede | f41d766 | 2019-04-20 13:21:50 +0200 | [diff] [blame] | 782 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 783 | |
| 784 | if (hid_add_device(dj_hiddev)) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 785 | hid_err(djrcv_hdev, "%s: failed adding dj_device\n", __func__); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 786 | goto hid_add_device_fail; |
| 787 | } |
| 788 | |
| 789 | return; |
| 790 | |
| 791 | hid_add_device_fail: |
Hans de Goede | f41d766 | 2019-04-20 13:21:50 +0200 | [diff] [blame] | 792 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 793 | djrcv_dev->paired_dj_devices[device_index] = NULL; |
Hans de Goede | f41d766 | 2019-04-20 13:21:50 +0200 | [diff] [blame] | 794 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 795 | kfree(dj_dev); |
| 796 | dj_device_allocate_fail: |
| 797 | hid_destroy_device(dj_hiddev); |
| 798 | } |
| 799 | |
| 800 | static void delayedwork_callback(struct work_struct *work) |
| 801 | { |
| 802 | struct dj_receiver_dev *djrcv_dev = |
| 803 | container_of(work, struct dj_receiver_dev, work); |
| 804 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 805 | struct dj_workitem workitem; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 806 | unsigned long flags; |
| 807 | int count; |
Nestor Lopez Casado | c63e0e3 | 2013-07-18 06:21:30 -0700 | [diff] [blame] | 808 | int retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 809 | |
| 810 | dbg_hid("%s\n", __func__); |
| 811 | |
| 812 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
| 813 | |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 814 | /* |
| 815 | * Since we attach to multiple interfaces, we may get scheduled before |
| 816 | * we are bound to the HID++ interface, catch this. |
| 817 | */ |
| 818 | if (!djrcv_dev->ready) { |
| 819 | pr_warn("%s: delayedwork queued before hidpp interface was enumerated\n", |
| 820 | __func__); |
| 821 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 822 | return; |
| 823 | } |
| 824 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 825 | count = kfifo_out(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 826 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 827 | if (count != sizeof(workitem)) { |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 828 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 829 | return; |
| 830 | } |
| 831 | |
Hans de Goede | e316aa6 | 2019-04-20 13:22:01 +0200 | [diff] [blame] | 832 | if (!kfifo_is_empty(&djrcv_dev->notif_fifo)) |
| 833 | schedule_work(&djrcv_dev->work); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 834 | |
| 835 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 836 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 837 | switch (workitem.type) { |
| 838 | case WORKITEM_TYPE_PAIRED: |
| 839 | logi_dj_recv_add_djhid_device(djrcv_dev, &workitem); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 840 | break; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 841 | case WORKITEM_TYPE_UNPAIRED: |
| 842 | logi_dj_recv_destroy_djhid_device(djrcv_dev, &workitem); |
| 843 | break; |
| 844 | case WORKITEM_TYPE_UNKNOWN: |
| 845 | retval = logi_dj_recv_query_paired_devices(djrcv_dev); |
| 846 | if (retval) { |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 847 | hid_err(djrcv_dev->hidpp, "%s: logi_dj_recv_query_paired_devices error: %d\n", |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 848 | __func__, retval); |
| 849 | } |
| 850 | break; |
| 851 | case WORKITEM_TYPE_EMPTY: |
| 852 | dbg_hid("%s: device list is empty\n", __func__); |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | |
Hans de Goede | b6aeedd | 2019-04-20 13:21:53 +0200 | [diff] [blame] | 857 | /* |
| 858 | * Sometimes we receive reports for which we do not have a paired dj_device |
| 859 | * associated with the device_index or report-type to forward the report to. |
| 860 | * This means that the original "device paired" notification corresponding |
| 861 | * to the dj_device never arrived to this driver. Possible reasons for this are: |
| 862 | * 1) hid-core discards all packets coming from a device during probe(). |
| 863 | * 2) if the receiver is plugged into a KVM switch then the pairing reports |
| 864 | * are only forwarded to it if the focus is on this PC. |
| 865 | * This function deals with this by re-asking the receiver for the list of |
| 866 | * connected devices in the delayed work callback. |
| 867 | * This function MUST be called with djrcv->lock held. |
| 868 | */ |
| 869 | static void logi_dj_recv_queue_unknown_work(struct dj_receiver_dev *djrcv_dev) |
| 870 | { |
| 871 | struct dj_workitem workitem = { .type = WORKITEM_TYPE_UNKNOWN }; |
| 872 | |
Chris Packham | 53ed4cf | 2020-05-26 11:02:01 +1200 | [diff] [blame] | 873 | /* Rate limit queries done because of unhandled reports to 2/sec */ |
Hans de Goede | b6aeedd | 2019-04-20 13:21:53 +0200 | [diff] [blame] | 874 | if (time_before(jiffies, djrcv_dev->last_query + HZ / 2)) |
| 875 | return; |
| 876 | |
| 877 | kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
| 878 | schedule_work(&djrcv_dev->work); |
| 879 | } |
| 880 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 881 | static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev, |
| 882 | struct dj_report *dj_report) |
| 883 | { |
| 884 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
| 885 | struct dj_workitem workitem = { |
| 886 | .device_index = dj_report->device_index, |
| 887 | }; |
| 888 | |
| 889 | switch (dj_report->report_type) { |
| 890 | case REPORT_TYPE_NOTIF_DEVICE_PAIRED: |
| 891 | workitem.type = WORKITEM_TYPE_PAIRED; |
| 892 | if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] & |
| 893 | SPFUNCTION_DEVICE_LIST_EMPTY) { |
| 894 | workitem.type = WORKITEM_TYPE_EMPTY; |
| 895 | break; |
| 896 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 897 | fallthrough; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 898 | case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED: |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 899 | workitem.quad_id_msb = |
| 900 | dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB]; |
| 901 | workitem.quad_id_lsb = |
| 902 | dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB]; |
| 903 | workitem.reports_supported = get_unaligned_le32( |
| 904 | dj_report->report_params + |
| 905 | DEVICE_PAIRED_RF_REPORT_TYPE); |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 906 | workitem.reports_supported |= HIDPP; |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 907 | if (dj_report->report_type == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED) |
| 908 | workitem.type = WORKITEM_TYPE_UNPAIRED; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 909 | break; |
| 910 | default: |
Hans de Goede | b6aeedd | 2019-04-20 13:21:53 +0200 | [diff] [blame] | 911 | logi_dj_recv_queue_unknown_work(djrcv_dev); |
| 912 | return; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 913 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 914 | |
Benjamin Tissoires | 4fcad95 | 2019-04-20 13:21:48 +0200 | [diff] [blame] | 915 | kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
Hans de Goede | e316aa6 | 2019-04-20 13:22:01 +0200 | [diff] [blame] | 916 | schedule_work(&djrcv_dev->work); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 917 | } |
| 918 | |
Hans de Goede | ee5e584 | 2020-11-02 14:36:56 +0100 | [diff] [blame] | 919 | /* |
| 920 | * Some quad/bluetooth keyboards have a builtin touchpad in this case we see |
| 921 | * only 1 paired device with a device_type of REPORT_TYPE_KEYBOARD. For the |
| 922 | * touchpad to work we must also forward mouse input reports to the dj_hiddev |
| 923 | * created for the keyboard (instead of forwarding them to a second paired |
| 924 | * device with a device_type of REPORT_TYPE_MOUSE as we normally would). |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 925 | * |
| 926 | * On Dinovo receivers the keyboard's touchpad and an optional paired actual |
| 927 | * mouse send separate input reports, INPUT(2) aka STD_MOUSE for the mouse |
| 928 | * and INPUT(5) aka KBD_MOUSE for the keyboard's touchpad. |
| 929 | * |
| 930 | * On MX5x00 receivers (which can also be paired with a Dinovo keyboard) |
| 931 | * INPUT(2) is used for both an optional paired actual mouse and for the |
| 932 | * keyboard's touchpad. |
Hans de Goede | ee5e584 | 2020-11-02 14:36:56 +0100 | [diff] [blame] | 933 | */ |
| 934 | static const u16 kbd_builtin_touchpad_ids[] = { |
| 935 | 0xb309, /* Dinovo Edge */ |
Hans de Goede | b4c00e7 | 2020-11-14 22:20:56 +0100 | [diff] [blame] | 936 | 0xb30c, /* Dinovo Mini */ |
Hans de Goede | ee5e584 | 2020-11-02 14:36:56 +0100 | [diff] [blame] | 937 | }; |
| 938 | |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 939 | static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev, |
| 940 | struct hidpp_event *hidpp_report, |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 941 | struct dj_workitem *workitem) |
| 942 | { |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 943 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
Hans de Goede | ee5e584 | 2020-11-02 14:36:56 +0100 | [diff] [blame] | 944 | int i, id; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 945 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 946 | workitem->type = WORKITEM_TYPE_PAIRED; |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 947 | workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & |
| 948 | HIDPP_DEVICE_TYPE_MASK; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 949 | workitem->quad_id_msb = hidpp_report->params[HIDPP_PARAM_EQUAD_MSB]; |
| 950 | workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_EQUAD_LSB]; |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 951 | switch (workitem->device_type) { |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 952 | case REPORT_TYPE_KEYBOARD: |
| 953 | workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA | |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 954 | POWER_KEYS | MEDIA_CENTER | |
| 955 | HIDPP; |
Hans de Goede | ee5e584 | 2020-11-02 14:36:56 +0100 | [diff] [blame] | 956 | id = (workitem->quad_id_msb << 8) | workitem->quad_id_lsb; |
| 957 | for (i = 0; i < ARRAY_SIZE(kbd_builtin_touchpad_ids); i++) { |
| 958 | if (id == kbd_builtin_touchpad_ids[i]) { |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 959 | if (djrcv_dev->type == recvr_type_dinovo) |
| 960 | workitem->reports_supported |= KBD_MOUSE; |
| 961 | else |
| 962 | workitem->reports_supported |= STD_MOUSE; |
Hans de Goede | ee5e584 | 2020-11-02 14:36:56 +0100 | [diff] [blame] | 963 | break; |
| 964 | } |
| 965 | } |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 966 | break; |
| 967 | case REPORT_TYPE_MOUSE: |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 968 | workitem->reports_supported |= STD_MOUSE | HIDPP; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 969 | if (djrcv_dev->type == recvr_type_mouse_only) |
| 970 | workitem->reports_supported |= MULTIMEDIA; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | } |
| 974 | |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 975 | static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev, |
| 976 | struct hidpp_event *hidpp_report, |
| 977 | struct dj_workitem *workitem) |
| 978 | { |
| 979 | workitem->type = WORKITEM_TYPE_PAIRED; |
| 980 | workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID]; |
| 981 | switch (hidpp_report->device_index) { |
| 982 | case 1: /* Index 1 is always a mouse */ |
| 983 | case 2: /* Index 2 is always a mouse */ |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 984 | workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE; |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 985 | workitem->reports_supported |= STD_MOUSE | HIDPP; |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 986 | break; |
| 987 | case 3: /* Index 3 is always the keyboard */ |
Hans de Goede | 7383354 | 2021-04-04 20:56:09 +0200 | [diff] [blame] | 988 | if (hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & HIDPP_27MHZ_SECURE_MASK) { |
| 989 | hid_info(hdev, "Keyboard connection is encrypted\n"); |
| 990 | } else { |
| 991 | hid_warn(hdev, "Keyboard events are send over the air in plain-text / unencrypted\n"); |
| 992 | hid_warn(hdev, "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n"); |
| 993 | } |
| 994 | fallthrough; |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 995 | case 4: /* Index 4 is used for an optional separate numpad */ |
Hans de Goede | de76b1d | 2019-04-20 13:22:00 +0200 | [diff] [blame] | 996 | workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD; |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 997 | workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA | |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 998 | POWER_KEYS | HIDPP; |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 999 | break; |
| 1000 | default: |
| 1001 | hid_warn(hdev, "%s: unexpected device-index %d", __func__, |
| 1002 | hidpp_report->device_index); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1006 | static void logi_hidpp_recv_queue_notif(struct hid_device *hdev, |
| 1007 | struct hidpp_event *hidpp_report) |
| 1008 | { |
| 1009 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
| 1010 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
| 1011 | const char *device_type = "UNKNOWN"; |
| 1012 | struct dj_workitem workitem = { |
| 1013 | .type = WORKITEM_TYPE_EMPTY, |
| 1014 | .device_index = hidpp_report->device_index, |
| 1015 | }; |
| 1016 | |
| 1017 | switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) { |
| 1018 | case 0x01: |
| 1019 | device_type = "Bluetooth"; |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 1020 | /* Bluetooth connect packet contents is the same as (e)QUAD */ |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1021 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 1022 | if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & |
| 1023 | HIDPP_MANUFACTURER_MASK)) { |
| 1024 | hid_info(hdev, "Non Logitech device connected on slot %d\n", |
| 1025 | hidpp_report->device_index); |
| 1026 | workitem.reports_supported &= ~HIDPP; |
| 1027 | } |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1028 | break; |
| 1029 | case 0x02: |
| 1030 | device_type = "27 Mhz"; |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 1031 | logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1032 | break; |
| 1033 | case 0x03: |
| 1034 | device_type = "QUAD or eQUAD"; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1035 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1036 | break; |
| 1037 | case 0x04: |
| 1038 | device_type = "eQUAD step 4 DJ"; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1039 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1040 | break; |
| 1041 | case 0x05: |
| 1042 | device_type = "DFU Lite"; |
| 1043 | break; |
| 1044 | case 0x06: |
| 1045 | device_type = "eQUAD step 4 Lite"; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1046 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1047 | break; |
| 1048 | case 0x07: |
| 1049 | device_type = "eQUAD step 4 Gaming"; |
Benjamin Tissoires | 992ff2c | 2019-08-12 18:08:04 +0200 | [diff] [blame] | 1050 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Filipe Laíns | ef07c11 | 2021-02-05 14:34:44 +0000 | [diff] [blame] | 1051 | workitem.reports_supported |= STD_KEYBOARD; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1052 | break; |
| 1053 | case 0x08: |
| 1054 | device_type = "eQUAD step 4 for gamepads"; |
| 1055 | break; |
| 1056 | case 0x0a: |
| 1057 | device_type = "eQUAD nano Lite"; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1058 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1059 | break; |
| 1060 | case 0x0c: |
Filipe Laíns | 5722f33 | 2019-07-30 13:24:57 +0100 | [diff] [blame] | 1061 | device_type = "eQUAD Lightspeed 1"; |
| 1062 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
| 1063 | workitem.reports_supported |= STD_KEYBOARD; |
| 1064 | break; |
| 1065 | case 0x0d: |
Filipe Laíns | fab3a95 | 2021-01-23 18:02:20 +0000 | [diff] [blame] | 1066 | device_type = "eQUAD Lightspeed 1.1"; |
| 1067 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
| 1068 | workitem.reports_supported |= STD_KEYBOARD; |
| 1069 | break; |
| 1070 | case 0x0f: |
| 1071 | device_type = "eQUAD Lightspeed 1.2"; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1072 | logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 1073 | workitem.reports_supported |= STD_KEYBOARD; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1074 | break; |
| 1075 | } |
| 1076 | |
Filipe Laíns | 8c9d734 | 2020-01-15 20:18:11 +0000 | [diff] [blame] | 1077 | /* custom receiver device (eg. powerplay) */ |
| 1078 | if (hidpp_report->device_index == 7) { |
| 1079 | workitem.reports_supported |= HIDPP; |
| 1080 | } |
| 1081 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1082 | if (workitem.type == WORKITEM_TYPE_EMPTY) { |
| 1083 | hid_warn(hdev, |
| 1084 | "unusable device of type %s (0x%02x) connected on slot %d", |
| 1085 | device_type, |
| 1086 | hidpp_report->params[HIDPP_PARAM_PROTO_TYPE], |
| 1087 | hidpp_report->device_index); |
| 1088 | return; |
| 1089 | } |
| 1090 | |
| 1091 | hid_info(hdev, "device of type %s (0x%02x) connected on slot %d", |
| 1092 | device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE], |
| 1093 | hidpp_report->device_index); |
| 1094 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1095 | kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
Hans de Goede | e316aa6 | 2019-04-20 13:22:01 +0200 | [diff] [blame] | 1096 | schedule_work(&djrcv_dev->work); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1099 | static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, |
| 1100 | struct dj_report *dj_report) |
| 1101 | { |
| 1102 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
| 1103 | unsigned int i; |
| 1104 | u8 reportbuffer[MAX_REPORT_SIZE]; |
| 1105 | struct dj_device *djdev; |
| 1106 | |
| 1107 | djdev = djrcv_dev->paired_dj_devices[dj_report->device_index]; |
| 1108 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1109 | memset(reportbuffer, 0, sizeof(reportbuffer)); |
| 1110 | |
| 1111 | for (i = 0; i < NUMBER_OF_HID_REPORTS; i++) { |
| 1112 | if (djdev->reports_supported & (1 << i)) { |
| 1113 | reportbuffer[0] = i; |
| 1114 | if (hid_input_report(djdev->hdev, |
| 1115 | HID_INPUT_REPORT, |
| 1116 | reportbuffer, |
| 1117 | hid_reportid_size_map[i], 1)) { |
| 1118 | dbg_hid("hid_input_report error sending null " |
| 1119 | "report\n"); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | |
Benjamin Tissoires | 8389823 | 2019-04-20 13:21:43 +0200 | [diff] [blame] | 1125 | static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev, |
| 1126 | struct dj_report *dj_report) |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1127 | { |
| 1128 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
| 1129 | struct dj_device *dj_device; |
| 1130 | |
| 1131 | dj_device = djrcv_dev->paired_dj_devices[dj_report->device_index]; |
| 1132 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1133 | if ((dj_report->report_type > ARRAY_SIZE(hid_reportid_size_map) - 1) || |
| 1134 | (hid_reportid_size_map[dj_report->report_type] == 0)) { |
| 1135 | dbg_hid("invalid report type:%x\n", dj_report->report_type); |
| 1136 | return; |
| 1137 | } |
| 1138 | |
| 1139 | if (hid_input_report(dj_device->hdev, |
| 1140 | HID_INPUT_REPORT, &dj_report->report_type, |
| 1141 | hid_reportid_size_map[dj_report->report_type], 1)) { |
| 1142 | dbg_hid("hid_input_report error\n"); |
| 1143 | } |
| 1144 | } |
| 1145 | |
Benjamin Tissoires | 8389823 | 2019-04-20 13:21:43 +0200 | [diff] [blame] | 1146 | static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data, |
| 1147 | int size) |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1148 | { |
| 1149 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
| 1150 | if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1)) |
| 1151 | dbg_hid("hid_input_report error\n"); |
| 1152 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1153 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1154 | static void logi_dj_recv_forward_input_report(struct hid_device *hdev, |
| 1155 | u8 *data, int size) |
| 1156 | { |
| 1157 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
| 1158 | struct dj_device *dj_dev; |
| 1159 | unsigned long flags; |
| 1160 | u8 report = data[0]; |
| 1161 | int i; |
| 1162 | |
| 1163 | if (report > REPORT_TYPE_RFREPORT_LAST) { |
Colin Ian King | 640d4ea | 2019-04-26 14:16:31 +0100 | [diff] [blame] | 1164 | hid_err(hdev, "Unexpected input report number %d\n", report); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1165 | return; |
| 1166 | } |
| 1167 | |
| 1168 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
| 1169 | for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) { |
| 1170 | dj_dev = djrcv_dev->paired_dj_devices[i]; |
| 1171 | if (dj_dev && (dj_dev->reports_supported & BIT(report))) { |
| 1172 | logi_dj_recv_forward_report(dj_dev, data, size); |
| 1173 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 1174 | return; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | logi_dj_recv_queue_unknown_work(djrcv_dev); |
| 1179 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 1180 | |
| 1181 | dbg_hid("No dj-devs handling input report number %d\n", report); |
| 1182 | } |
| 1183 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1184 | static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev, |
| 1185 | struct dj_report *dj_report) |
| 1186 | { |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 1187 | struct hid_device *hdev = djrcv_dev->hidpp; |
Benjamin Tissoires | dcd9006 | 2013-03-05 17:09:00 +0100 | [diff] [blame] | 1188 | struct hid_report *report; |
| 1189 | struct hid_report_enum *output_report_enum; |
| 1190 | u8 *data = (u8 *)(&dj_report->device_index); |
Kees Cook | 297502a | 2013-09-11 21:56:56 +0200 | [diff] [blame] | 1191 | unsigned int i; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1192 | |
Benjamin Tissoires | dcd9006 | 2013-03-05 17:09:00 +0100 | [diff] [blame] | 1193 | output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT]; |
| 1194 | report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT]; |
| 1195 | |
| 1196 | if (!report) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1197 | hid_err(hdev, "%s: unable to find dj report\n", __func__); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1198 | return -ENODEV; |
| 1199 | } |
| 1200 | |
Kees Cook | 297502a | 2013-09-11 21:56:56 +0200 | [diff] [blame] | 1201 | for (i = 0; i < DJREPORT_SHORT_LENGTH - 1; i++) |
Benjamin Tissoires | dcd9006 | 2013-03-05 17:09:00 +0100 | [diff] [blame] | 1202 | report->field[0]->value[i] = data[i]; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1203 | |
Jiri Kosina | 83a44ac | 2013-03-09 10:58:13 +0100 | [diff] [blame] | 1204 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
Benjamin Tissoires | dcd9006 | 2013-03-05 17:09:00 +0100 | [diff] [blame] | 1205 | |
| 1206 | return 0; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1207 | } |
| 1208 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1209 | static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev) |
| 1210 | { |
Colin Ian King | 39d21e7 | 2019-05-10 14:10:39 +0100 | [diff] [blame] | 1211 | static const u8 template[] = { |
| 1212 | REPORT_ID_HIDPP_SHORT, |
| 1213 | HIDPP_RECEIVER_INDEX, |
| 1214 | HIDPP_SET_REGISTER, |
| 1215 | HIDPP_REG_CONNECTION_STATE, |
| 1216 | HIDPP_FAKE_DEVICE_ARRIVAL, |
| 1217 | 0x00, 0x00 |
| 1218 | }; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1219 | u8 *hidpp_report; |
| 1220 | int retval; |
| 1221 | |
| 1222 | hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL); |
| 1223 | if (!hidpp_report) |
| 1224 | return -ENOMEM; |
| 1225 | |
| 1226 | retval = hid_hw_raw_request(djrcv_dev->hidpp, |
| 1227 | REPORT_ID_HIDPP_SHORT, |
| 1228 | hidpp_report, sizeof(template), |
| 1229 | HID_OUTPUT_REPORT, |
| 1230 | HID_REQ_SET_REPORT); |
| 1231 | |
| 1232 | kfree(hidpp_report); |
Hans de Goede | 6fb08f1 | 2019-07-29 17:50:36 +0200 | [diff] [blame] | 1233 | return (retval < 0) ? retval : 0; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1236 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev) |
| 1237 | { |
Marc Dionne | d8dc349 | 2012-06-01 18:12:14 -0400 | [diff] [blame] | 1238 | struct dj_report *dj_report; |
| 1239 | int retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1240 | |
Hans de Goede | b6aeedd | 2019-04-20 13:21:53 +0200 | [diff] [blame] | 1241 | djrcv_dev->last_query = jiffies; |
| 1242 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1243 | if (djrcv_dev->type != recvr_type_dj) |
| 1244 | return logi_dj_recv_query_hidpp_devices(djrcv_dev); |
| 1245 | |
Alan Cox | 8a55ade | 2012-09-04 15:10:08 +0100 | [diff] [blame] | 1246 | dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); |
Marc Dionne | d8dc349 | 2012-06-01 18:12:14 -0400 | [diff] [blame] | 1247 | if (!dj_report) |
| 1248 | return -ENOMEM; |
| 1249 | dj_report->report_id = REPORT_ID_DJ_SHORT; |
Mazin Rezk | 7f02bb6 | 2020-07-05 02:48:17 +0000 | [diff] [blame] | 1250 | dj_report->device_index = HIDPP_RECEIVER_INDEX; |
Marc Dionne | d8dc349 | 2012-06-01 18:12:14 -0400 | [diff] [blame] | 1251 | dj_report->report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES; |
| 1252 | retval = logi_dj_recv_send_report(djrcv_dev, dj_report); |
| 1253 | kfree(dj_report); |
| 1254 | return retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
Nestor Lopez Casado | c63e0e3 | 2013-07-18 06:21:30 -0700 | [diff] [blame] | 1257 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1258 | static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, |
| 1259 | unsigned timeout) |
| 1260 | { |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 1261 | struct hid_device *hdev = djrcv_dev->hidpp; |
Marc Dionne | d8dc349 | 2012-06-01 18:12:14 -0400 | [diff] [blame] | 1262 | struct dj_report *dj_report; |
Benjamin Tissoires | 6a9ddc8 | 2014-09-30 13:18:31 -0400 | [diff] [blame] | 1263 | u8 *buf; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1264 | int retval = 0; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1265 | |
Alan Cox | 8a55ade | 2012-09-04 15:10:08 +0100 | [diff] [blame] | 1266 | dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); |
Marc Dionne | d8dc349 | 2012-06-01 18:12:14 -0400 | [diff] [blame] | 1267 | if (!dj_report) |
| 1268 | return -ENOMEM; |
Benjamin Tisssoires | 42c22db | 2014-01-08 17:18:45 -0500 | [diff] [blame] | 1269 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1270 | if (djrcv_dev->type == recvr_type_dj) { |
| 1271 | dj_report->report_id = REPORT_ID_DJ_SHORT; |
Mazin Rezk | 7f02bb6 | 2020-07-05 02:48:17 +0000 | [diff] [blame] | 1272 | dj_report->device_index = HIDPP_RECEIVER_INDEX; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1273 | dj_report->report_type = REPORT_TYPE_CMD_SWITCH; |
| 1274 | dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F; |
| 1275 | dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] = |
| 1276 | (u8)timeout; |
| 1277 | |
| 1278 | retval = logi_dj_recv_send_report(djrcv_dev, dj_report); |
| 1279 | |
| 1280 | /* |
| 1281 | * Ugly sleep to work around a USB 3.0 bug when the receiver is |
| 1282 | * still processing the "switch-to-dj" command while we send an |
| 1283 | * other command. |
| 1284 | * 50 msec should gives enough time to the receiver to be ready. |
| 1285 | */ |
| 1286 | msleep(50); |
| 1287 | } |
Benjamin Tisssoires | 42c22db | 2014-01-08 17:18:45 -0500 | [diff] [blame] | 1288 | |
Benjamin Tissoires | 6a9ddc8 | 2014-09-30 13:18:31 -0400 | [diff] [blame] | 1289 | /* |
| 1290 | * Magical bits to set up hidpp notifications when the dj devices |
| 1291 | * are connected/disconnected. |
| 1292 | * |
| 1293 | * We can reuse dj_report because HIDPP_REPORT_SHORT_LENGTH is smaller |
| 1294 | * than DJREPORT_SHORT_LENGTH. |
| 1295 | */ |
| 1296 | buf = (u8 *)dj_report; |
| 1297 | |
| 1298 | memset(buf, 0, HIDPP_REPORT_SHORT_LENGTH); |
| 1299 | |
| 1300 | buf[0] = REPORT_ID_HIDPP_SHORT; |
Mazin Rezk | 7f02bb6 | 2020-07-05 02:48:17 +0000 | [diff] [blame] | 1301 | buf[1] = HIDPP_RECEIVER_INDEX; |
Benjamin Tissoires | 6a9ddc8 | 2014-09-30 13:18:31 -0400 | [diff] [blame] | 1302 | buf[2] = 0x80; |
| 1303 | buf[3] = 0x00; |
| 1304 | buf[4] = 0x00; |
| 1305 | buf[5] = 0x09; |
| 1306 | buf[6] = 0x00; |
| 1307 | |
| 1308 | hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf, |
| 1309 | HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT, |
| 1310 | HID_REQ_SET_REPORT); |
| 1311 | |
| 1312 | kfree(dj_report); |
Marc Dionne | d8dc349 | 2012-06-01 18:12:14 -0400 | [diff] [blame] | 1313 | return retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | static int logi_dj_ll_open(struct hid_device *hid) |
| 1318 | { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1319 | dbg_hid("%s: %s\n", __func__, hid->phys); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1320 | return 0; |
| 1321 | |
| 1322 | } |
| 1323 | |
| 1324 | static void logi_dj_ll_close(struct hid_device *hid) |
| 1325 | { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1326 | dbg_hid("%s: %s\n", __func__, hid->phys); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1327 | } |
| 1328 | |
Benjamin Tissoires | 8dba302 | 2017-03-27 16:59:21 +0200 | [diff] [blame] | 1329 | /* |
| 1330 | * Register 0xB5 is "pairing information". It is solely intended for the |
| 1331 | * receiver, so do not overwrite the device index. |
| 1332 | */ |
Benjamin Tissoires | c034041 | 2019-04-20 13:21:46 +0200 | [diff] [blame] | 1333 | static u8 unifying_pairing_query[] = { REPORT_ID_HIDPP_SHORT, |
| 1334 | HIDPP_RECEIVER_INDEX, |
| 1335 | HIDPP_GET_LONG_REGISTER, |
| 1336 | HIDPP_REG_PAIRING_INFORMATION }; |
| 1337 | static u8 unifying_pairing_answer[] = { REPORT_ID_HIDPP_LONG, |
| 1338 | HIDPP_RECEIVER_INDEX, |
| 1339 | HIDPP_GET_LONG_REGISTER, |
| 1340 | HIDPP_REG_PAIRING_INFORMATION }; |
Benjamin Tissoires | 3379782 | 2014-09-30 13:18:30 -0400 | [diff] [blame] | 1341 | |
Benjamin Tissoires | bd27e20 | 2014-02-10 12:58:53 -0500 | [diff] [blame] | 1342 | static int logi_dj_ll_raw_request(struct hid_device *hid, |
| 1343 | unsigned char reportnum, __u8 *buf, |
| 1344 | size_t count, unsigned char report_type, |
| 1345 | int reqtype) |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1346 | { |
Benjamin Tissoires | 0e40d35 | 2014-02-05 16:33:17 -0500 | [diff] [blame] | 1347 | struct dj_device *djdev = hid->driver_data; |
| 1348 | struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev; |
| 1349 | u8 *out_buf; |
| 1350 | int ret; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1351 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1352 | if ((buf[0] == REPORT_ID_HIDPP_SHORT) || |
Hans de Goede | 3a9a2c8 | 2019-06-14 10:20:27 +0200 | [diff] [blame] | 1353 | (buf[0] == REPORT_ID_HIDPP_LONG) || |
| 1354 | (buf[0] == REPORT_ID_HIDPP_VERY_LONG)) { |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1355 | if (count < 2) |
| 1356 | return -EINVAL; |
| 1357 | |
Benjamin Tissoires | 3379782 | 2014-09-30 13:18:30 -0400 | [diff] [blame] | 1358 | /* special case where we should not overwrite |
| 1359 | * the device_index */ |
Benjamin Tissoires | 8dba302 | 2017-03-27 16:59:21 +0200 | [diff] [blame] | 1360 | if (count == 7 && !memcmp(buf, unifying_pairing_query, |
| 1361 | sizeof(unifying_pairing_query))) |
| 1362 | buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1); |
Benjamin Tissoires | 3379782 | 2014-09-30 13:18:30 -0400 | [diff] [blame] | 1363 | else |
| 1364 | buf[1] = djdev->device_index; |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 1365 | return hid_hw_raw_request(djrcv_dev->hidpp, reportnum, buf, |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1366 | count, report_type, reqtype); |
| 1367 | } |
| 1368 | |
Benjamin Tissoires | 0e40d35 | 2014-02-05 16:33:17 -0500 | [diff] [blame] | 1369 | if (buf[0] != REPORT_TYPE_LEDS) |
| 1370 | return -EINVAL; |
| 1371 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1372 | if (djrcv_dev->type != recvr_type_dj && count >= 2) { |
| 1373 | if (!djrcv_dev->keyboard) { |
| 1374 | hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n"); |
| 1375 | return 0; |
| 1376 | } |
| 1377 | /* usbhid overrides the report ID and ignores the first byte */ |
| 1378 | return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count, |
| 1379 | report_type, reqtype); |
| 1380 | } |
| 1381 | |
Benjamin Tissoires | 0e40d35 | 2014-02-05 16:33:17 -0500 | [diff] [blame] | 1382 | out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC); |
| 1383 | if (!out_buf) |
| 1384 | return -ENOMEM; |
| 1385 | |
Jiri Kosina | 51217e6 | 2014-08-21 09:56:47 -0500 | [diff] [blame] | 1386 | if (count > DJREPORT_SHORT_LENGTH - 2) |
Benjamin Tissoires | 0e40d35 | 2014-02-05 16:33:17 -0500 | [diff] [blame] | 1387 | count = DJREPORT_SHORT_LENGTH - 2; |
| 1388 | |
| 1389 | out_buf[0] = REPORT_ID_DJ_SHORT; |
| 1390 | out_buf[1] = djdev->device_index; |
| 1391 | memcpy(out_buf + 2, buf, count); |
| 1392 | |
Hans de Goede | 0ee7554 | 2019-04-20 13:21:51 +0200 | [diff] [blame] | 1393 | ret = hid_hw_raw_request(djrcv_dev->hidpp, out_buf[0], out_buf, |
Benjamin Tissoires | bd27e20 | 2014-02-10 12:58:53 -0500 | [diff] [blame] | 1394 | DJREPORT_SHORT_LENGTH, report_type, reqtype); |
Benjamin Tissoires | 0e40d35 | 2014-02-05 16:33:17 -0500 | [diff] [blame] | 1395 | |
| 1396 | kfree(out_buf); |
| 1397 | return ret; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Dan Carpenter | 6d60332 | 2013-10-19 12:08:59 +0300 | [diff] [blame] | 1400 | static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size) |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 1401 | { |
Dan Carpenter | 6d60332 | 2013-10-19 12:08:59 +0300 | [diff] [blame] | 1402 | memcpy(rdesc + *rsize, data, size); |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 1403 | *rsize += size; |
| 1404 | } |
| 1405 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1406 | static int logi_dj_ll_parse(struct hid_device *hid) |
| 1407 | { |
| 1408 | struct dj_device *djdev = hid->driver_data; |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 1409 | unsigned int rsize = 0; |
| 1410 | char *rdesc; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1411 | int retval; |
| 1412 | |
| 1413 | dbg_hid("%s\n", __func__); |
| 1414 | |
| 1415 | djdev->hdev->version = 0x0111; |
| 1416 | djdev->hdev->country = 0x00; |
| 1417 | |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 1418 | rdesc = kmalloc(MAX_RDESC_SIZE, GFP_KERNEL); |
| 1419 | if (!rdesc) |
| 1420 | return -ENOMEM; |
| 1421 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1422 | if (djdev->reports_supported & STD_KEYBOARD) { |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1423 | dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1424 | __func__, djdev->reports_supported); |
Dan Carpenter | 6d60332 | 2013-10-19 12:08:59 +0300 | [diff] [blame] | 1425 | rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor)); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | if (djdev->reports_supported & STD_MOUSE) { |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1429 | dbg_hid("%s: sending a mouse descriptor, reports_supported: %llx\n", |
| 1430 | __func__, djdev->reports_supported); |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1431 | if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp || |
| 1432 | djdev->dj_receiver_dev->type == recvr_type_mouse_only) |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 1433 | rdcat(rdesc, &rsize, mse_high_res_descriptor, |
| 1434 | sizeof(mse_high_res_descriptor)); |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 1435 | else if (djdev->dj_receiver_dev->type == recvr_type_27mhz) |
| 1436 | rdcat(rdesc, &rsize, mse_27mhz_descriptor, |
| 1437 | sizeof(mse_27mhz_descriptor)); |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 1438 | else if (recvr_type_is_bluetooth(djdev->dj_receiver_dev->type)) |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 1439 | rdcat(rdesc, &rsize, mse_bluetooth_descriptor, |
| 1440 | sizeof(mse_bluetooth_descriptor)); |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 1441 | else |
| 1442 | rdcat(rdesc, &rsize, mse_descriptor, |
| 1443 | sizeof(mse_descriptor)); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 1446 | if (djdev->reports_supported & KBD_MOUSE) { |
| 1447 | dbg_hid("%s: sending a kbd-mouse descriptor, reports_supported: %llx\n", |
| 1448 | __func__, djdev->reports_supported); |
| 1449 | rdcat(rdesc, &rsize, mse5_bluetooth_descriptor, |
| 1450 | sizeof(mse5_bluetooth_descriptor)); |
| 1451 | } |
| 1452 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1453 | if (djdev->reports_supported & MULTIMEDIA) { |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1454 | dbg_hid("%s: sending a multimedia report descriptor: %llx\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1455 | __func__, djdev->reports_supported); |
Dan Carpenter | 6d60332 | 2013-10-19 12:08:59 +0300 | [diff] [blame] | 1456 | rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor)); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | if (djdev->reports_supported & POWER_KEYS) { |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1460 | dbg_hid("%s: sending a power keys report descriptor: %llx\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1461 | __func__, djdev->reports_supported); |
Dan Carpenter | 6d60332 | 2013-10-19 12:08:59 +0300 | [diff] [blame] | 1462 | rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor)); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | if (djdev->reports_supported & MEDIA_CENTER) { |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1466 | dbg_hid("%s: sending a media center report descriptor: %llx\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1467 | __func__, djdev->reports_supported); |
Dan Carpenter | 6d60332 | 2013-10-19 12:08:59 +0300 | [diff] [blame] | 1468 | rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor)); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | if (djdev->reports_supported & KBD_LEDS) { |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1472 | dbg_hid("%s: need to send kbd leds report descriptor: %llx\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1473 | __func__, djdev->reports_supported); |
| 1474 | } |
| 1475 | |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1476 | if (djdev->reports_supported & HIDPP) { |
Filipe Laíns | 630dd6e | 2020-01-13 19:23:00 +0000 | [diff] [blame] | 1477 | dbg_hid("%s: sending a HID++ descriptor, reports_supported: %llx\n", |
| 1478 | __func__, djdev->reports_supported); |
Hans de Goede | 6d3c3f0 | 2019-04-20 13:22:02 +0200 | [diff] [blame] | 1479 | rdcat(rdesc, &rsize, hidpp_descriptor, |
| 1480 | sizeof(hidpp_descriptor)); |
| 1481 | } |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1482 | |
Henrik Rydberg | 2a039bf | 2012-04-22 14:21:39 +0200 | [diff] [blame] | 1483 | retval = hid_parse_report(hid, rdesc, rsize); |
| 1484 | kfree(rdesc); |
| 1485 | |
| 1486 | return retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1487 | } |
| 1488 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1489 | static int logi_dj_ll_start(struct hid_device *hid) |
| 1490 | { |
| 1491 | dbg_hid("%s\n", __func__); |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
| 1495 | static void logi_dj_ll_stop(struct hid_device *hid) |
| 1496 | { |
| 1497 | dbg_hid("%s\n", __func__); |
| 1498 | } |
| 1499 | |
Hans de Goede | 622d97c | 2021-05-29 17:14:23 +0200 | [diff] [blame] | 1500 | static bool logi_dj_ll_may_wakeup(struct hid_device *hid) |
| 1501 | { |
| 1502 | struct dj_device *djdev = hid->driver_data; |
| 1503 | struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev; |
| 1504 | |
| 1505 | return hid_hw_may_wakeup(djrcv_dev->hidpp); |
| 1506 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1507 | |
| 1508 | static struct hid_ll_driver logi_dj_ll_driver = { |
| 1509 | .parse = logi_dj_ll_parse, |
| 1510 | .start = logi_dj_ll_start, |
| 1511 | .stop = logi_dj_ll_stop, |
| 1512 | .open = logi_dj_ll_open, |
| 1513 | .close = logi_dj_ll_close, |
Benjamin Tissoires | bd27e20 | 2014-02-10 12:58:53 -0500 | [diff] [blame] | 1514 | .raw_request = logi_dj_ll_raw_request, |
Hans de Goede | 622d97c | 2021-05-29 17:14:23 +0200 | [diff] [blame] | 1515 | .may_wakeup = logi_dj_ll_may_wakeup, |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1516 | }; |
| 1517 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1518 | static int logi_dj_dj_event(struct hid_device *hdev, |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1519 | struct hid_report *report, u8 *data, |
| 1520 | int size) |
| 1521 | { |
| 1522 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
| 1523 | struct dj_report *dj_report = (struct dj_report *) data; |
| 1524 | unsigned long flags; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1525 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1526 | /* |
| 1527 | * Here we receive all data coming from iface 2, there are 3 cases: |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1528 | * |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1529 | * 1) Data is intended for this driver i. e. data contains arrival, |
| 1530 | * departure, etc notifications, in which case we queue them for delayed |
| 1531 | * processing by the work queue. We return 1 to hid-core as no further |
| 1532 | * processing is required from it. |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1533 | * |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1534 | * 2) Data informs a connection change, if the change means rf link |
| 1535 | * loss, then we must send a null report to the upper layer to discard |
| 1536 | * potentially pressed keys that may be repeated forever by the input |
| 1537 | * layer. Return 1 to hid-core as no further processing is required. |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1538 | * |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1539 | * 3) Data is an actual input event from a paired DJ device in which |
| 1540 | * case we forward it to the correct hid device (via hid_input_report() |
| 1541 | * ) and return 1 so hid-core does not anything else with it. |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1542 | */ |
Benjamin Tissoires | 5abfe85 | 2014-08-22 16:16:05 -0400 | [diff] [blame] | 1543 | |
Jiri Kosina | ad3e14d | 2014-08-21 09:57:17 -0500 | [diff] [blame] | 1544 | if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) || |
| 1545 | (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) { |
Benjamin Tissoires | 5abfe85 | 2014-08-22 16:16:05 -0400 | [diff] [blame] | 1546 | /* |
| 1547 | * Device index is wrong, bail out. |
| 1548 | * This driver can ignore safely the receiver notifications, |
| 1549 | * so ignore those reports too. |
| 1550 | */ |
| 1551 | if (dj_report->device_index != DJ_RECEIVER_INDEX) |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1552 | hid_err(hdev, "%s: invalid device index:%d\n", |
Jiri Kosina | ad3e14d | 2014-08-21 09:57:17 -0500 | [diff] [blame] | 1553 | __func__, dj_report->device_index); |
| 1554 | return false; |
| 1555 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1556 | |
| 1557 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
Benjamin Tissoires | 368d4e59 | 2014-08-22 16:16:06 -0400 | [diff] [blame] | 1558 | |
| 1559 | if (!djrcv_dev->paired_dj_devices[dj_report->device_index]) { |
| 1560 | /* received an event for an unknown device, bail out */ |
| 1561 | logi_dj_recv_queue_notification(djrcv_dev, dj_report); |
| 1562 | goto out; |
| 1563 | } |
| 1564 | |
Benjamin Tissoires | 5abfe85 | 2014-08-22 16:16:05 -0400 | [diff] [blame] | 1565 | switch (dj_report->report_type) { |
| 1566 | case REPORT_TYPE_NOTIF_DEVICE_PAIRED: |
Benjamin Tissoires | 368d4e59 | 2014-08-22 16:16:06 -0400 | [diff] [blame] | 1567 | /* pairing notifications are handled above the switch */ |
| 1568 | break; |
Benjamin Tissoires | 5abfe85 | 2014-08-22 16:16:05 -0400 | [diff] [blame] | 1569 | case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED: |
| 1570 | logi_dj_recv_queue_notification(djrcv_dev, dj_report); |
| 1571 | break; |
| 1572 | case REPORT_TYPE_NOTIF_CONNECTION_STATUS: |
| 1573 | if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] == |
| 1574 | STATUS_LINKLOSS) { |
| 1575 | logi_dj_recv_forward_null_report(djrcv_dev, dj_report); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1576 | } |
Benjamin Tissoires | 5abfe85 | 2014-08-22 16:16:05 -0400 | [diff] [blame] | 1577 | break; |
| 1578 | default: |
Benjamin Tissoires | 8389823 | 2019-04-20 13:21:43 +0200 | [diff] [blame] | 1579 | logi_dj_recv_forward_dj(djrcv_dev, dj_report); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1580 | } |
Benjamin Tissoires | 368d4e59 | 2014-08-22 16:16:06 -0400 | [diff] [blame] | 1581 | |
| 1582 | out: |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1583 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 1584 | |
Benjamin Tissoires | 5abfe85 | 2014-08-22 16:16:05 -0400 | [diff] [blame] | 1585 | return true; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1586 | } |
| 1587 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1588 | static int logi_dj_hidpp_event(struct hid_device *hdev, |
| 1589 | struct hid_report *report, u8 *data, |
| 1590 | int size) |
| 1591 | { |
| 1592 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
Benjamin Tissoires | 7bb56a5 | 2019-04-20 13:21:44 +0200 | [diff] [blame] | 1593 | struct hidpp_event *hidpp_report = (struct hidpp_event *) data; |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1594 | struct dj_device *dj_dev; |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1595 | unsigned long flags; |
Benjamin Tissoires | 7bb56a5 | 2019-04-20 13:21:44 +0200 | [diff] [blame] | 1596 | u8 device_index = hidpp_report->device_index; |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1597 | |
Benjamin Tissoires | 3379782 | 2014-09-30 13:18:30 -0400 | [diff] [blame] | 1598 | if (device_index == HIDPP_RECEIVER_INDEX) { |
| 1599 | /* special case were the device wants to know its unifying |
| 1600 | * name */ |
| 1601 | if (size == HIDPP_REPORT_LONG_LENGTH && |
Benjamin Tissoires | 8dba302 | 2017-03-27 16:59:21 +0200 | [diff] [blame] | 1602 | !memcmp(data, unifying_pairing_answer, |
| 1603 | sizeof(unifying_pairing_answer))) |
Benjamin Tissoires | 3379782 | 2014-09-30 13:18:30 -0400 | [diff] [blame] | 1604 | device_index = (data[4] & 0x0F) + 1; |
| 1605 | else |
| 1606 | return false; |
| 1607 | } |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1608 | |
| 1609 | /* |
| 1610 | * Data is from the HID++ collection, in this case, we forward the |
| 1611 | * data to the corresponding child dj device and return 0 to hid-core |
| 1612 | * so he data also goes to the hidraw device of the receiver. This |
| 1613 | * allows a user space application to implement the full HID++ routing |
| 1614 | * via the receiver. |
| 1615 | */ |
| 1616 | |
| 1617 | if ((device_index < DJ_DEVICE_INDEX_MIN) || |
| 1618 | (device_index > DJ_DEVICE_INDEX_MAX)) { |
| 1619 | /* |
| 1620 | * Device index is wrong, bail out. |
| 1621 | * This driver can ignore safely the receiver notifications, |
| 1622 | * so ignore those reports too. |
| 1623 | */ |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1624 | hid_err(hdev, "%s: invalid device index:%d\n", __func__, |
| 1625 | hidpp_report->device_index); |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1626 | return false; |
| 1627 | } |
| 1628 | |
| 1629 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
| 1630 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1631 | dj_dev = djrcv_dev->paired_dj_devices[device_index]; |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 1632 | |
| 1633 | /* |
| 1634 | * With 27 MHz receivers, we do not get an explicit unpair event, |
| 1635 | * remove the old device if the user has paired a *different* device. |
| 1636 | */ |
| 1637 | if (djrcv_dev->type == recvr_type_27mhz && dj_dev && |
| 1638 | hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED && |
| 1639 | hidpp_report->params[HIDPP_PARAM_PROTO_TYPE] == 0x02 && |
| 1640 | hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID] != |
| 1641 | dj_dev->hdev->product) { |
| 1642 | struct dj_workitem workitem = { |
| 1643 | .device_index = hidpp_report->device_index, |
| 1644 | .type = WORKITEM_TYPE_UNPAIRED, |
| 1645 | }; |
| 1646 | kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
| 1647 | /* logi_hidpp_recv_queue_notif will queue the work */ |
| 1648 | dj_dev = NULL; |
| 1649 | } |
| 1650 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1651 | if (dj_dev) { |
| 1652 | logi_dj_recv_forward_report(dj_dev, data, size); |
| 1653 | } else { |
| 1654 | if (hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED) |
| 1655 | logi_hidpp_recv_queue_notif(hdev, hidpp_report); |
| 1656 | else |
| 1657 | logi_dj_recv_queue_unknown_work(djrcv_dev); |
| 1658 | } |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1659 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1660 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 1661 | |
| 1662 | return false; |
| 1663 | } |
| 1664 | |
| 1665 | static int logi_dj_raw_event(struct hid_device *hdev, |
| 1666 | struct hid_report *report, u8 *data, |
| 1667 | int size) |
| 1668 | { |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1669 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1670 | dbg_hid("%s, size:%d\n", __func__, size); |
| 1671 | |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1672 | if (!djrcv_dev) |
| 1673 | return 0; |
| 1674 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1675 | if (!hdev->report_enum[HID_INPUT_REPORT].numbered) { |
| 1676 | |
| 1677 | if (djrcv_dev->unnumbered_application == HID_GD_KEYBOARD) { |
| 1678 | /* |
| 1679 | * For the keyboard, we can reuse the same report by |
| 1680 | * using the second byte which is constant in the USB |
| 1681 | * HID report descriptor. |
| 1682 | */ |
| 1683 | data[1] = data[0]; |
| 1684 | data[0] = REPORT_TYPE_KEYBOARD; |
| 1685 | |
| 1686 | logi_dj_recv_forward_input_report(hdev, data, size); |
| 1687 | |
| 1688 | /* restore previous state */ |
| 1689 | data[0] = data[1]; |
| 1690 | data[1] = 0; |
| 1691 | } |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1692 | /* |
| 1693 | * Mouse-only receivers send unnumbered mouse data. The 27 MHz |
| 1694 | * receiver uses 6 byte packets, the nano receiver 8 bytes. |
| 1695 | */ |
Hans de Goede | 1f944ac | 2019-04-20 13:21:57 +0200 | [diff] [blame] | 1696 | if (djrcv_dev->unnumbered_application == HID_GD_MOUSE && |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1697 | size <= 8) { |
| 1698 | u8 mouse_report[9]; |
Hans de Goede | 1f944ac | 2019-04-20 13:21:57 +0200 | [diff] [blame] | 1699 | |
| 1700 | /* Prepend report id */ |
| 1701 | mouse_report[0] = REPORT_TYPE_MOUSE; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1702 | memcpy(mouse_report + 1, data, size); |
| 1703 | logi_dj_recv_forward_input_report(hdev, mouse_report, |
| 1704 | size + 1); |
Hans de Goede | 1f944ac | 2019-04-20 13:21:57 +0200 | [diff] [blame] | 1705 | } |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1706 | |
| 1707 | return false; |
| 1708 | } |
| 1709 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1710 | switch (data[0]) { |
| 1711 | case REPORT_ID_DJ_SHORT: |
Peter Wu | f254ae9 | 2014-12-16 16:55:21 +0100 | [diff] [blame] | 1712 | if (size != DJREPORT_SHORT_LENGTH) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1713 | hid_err(hdev, "Short DJ report bad size (%d)", size); |
Peter Wu | f254ae9 | 2014-12-16 16:55:21 +0100 | [diff] [blame] | 1714 | return false; |
| 1715 | } |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1716 | return logi_dj_dj_event(hdev, report, data, size); |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 1717 | case REPORT_ID_DJ_LONG: |
| 1718 | if (size != DJREPORT_LONG_LENGTH) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1719 | hid_err(hdev, "Long DJ report bad size (%d)", size); |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 1720 | return false; |
| 1721 | } |
| 1722 | return logi_dj_dj_event(hdev, report, data, size); |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1723 | case REPORT_ID_HIDPP_SHORT: |
Peter Wu | f254ae9 | 2014-12-16 16:55:21 +0100 | [diff] [blame] | 1724 | if (size != HIDPP_REPORT_SHORT_LENGTH) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1725 | hid_err(hdev, "Short HID++ report bad size (%d)", size); |
Peter Wu | f254ae9 | 2014-12-16 16:55:21 +0100 | [diff] [blame] | 1726 | return false; |
| 1727 | } |
| 1728 | return logi_dj_hidpp_event(hdev, report, data, size); |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1729 | case REPORT_ID_HIDPP_LONG: |
Peter Wu | f254ae9 | 2014-12-16 16:55:21 +0100 | [diff] [blame] | 1730 | if (size != HIDPP_REPORT_LONG_LENGTH) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1731 | hid_err(hdev, "Long HID++ report bad size (%d)", size); |
Peter Wu | f254ae9 | 2014-12-16 16:55:21 +0100 | [diff] [blame] | 1732 | return false; |
| 1733 | } |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1734 | return logi_dj_hidpp_event(hdev, report, data, size); |
| 1735 | } |
| 1736 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1737 | logi_dj_recv_forward_input_report(hdev, data, size); |
| 1738 | |
Benjamin Tissoires | 925f0f3 | 2014-09-30 13:18:29 -0400 | [diff] [blame] | 1739 | return false; |
| 1740 | } |
| 1741 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1742 | static int logi_dj_probe(struct hid_device *hdev, |
| 1743 | const struct hid_device_id *id) |
| 1744 | { |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1745 | struct hid_report_enum *rep_enum; |
| 1746 | struct hid_report *rep; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1747 | struct dj_receiver_dev *djrcv_dev; |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1748 | struct usb_interface *intf; |
| 1749 | unsigned int no_dj_interfaces = 0; |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1750 | bool has_hidpp = false; |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1751 | unsigned long flags; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1752 | int retval; |
| 1753 | |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1754 | /* |
| 1755 | * Call to usbhid to fetch the HID descriptors of the current |
| 1756 | * interface subsequently call to the hid/hid-core to parse the |
| 1757 | * fetched descriptors. |
| 1758 | */ |
| 1759 | retval = hid_parse(hdev); |
| 1760 | if (retval) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1761 | hid_err(hdev, "%s: parse failed\n", __func__); |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1762 | return retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1763 | } |
| 1764 | |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1765 | /* |
| 1766 | * Some KVMs add an extra interface for e.g. mouse emulation. If we |
| 1767 | * treat these as logitech-dj interfaces then this causes input events |
| 1768 | * reported through this extra interface to not be reported correctly. |
| 1769 | * To avoid this, we treat these as generic-hid devices. |
| 1770 | */ |
| 1771 | switch (id->driver_data) { |
| 1772 | case recvr_type_dj: no_dj_interfaces = 3; break; |
| 1773 | case recvr_type_hidpp: no_dj_interfaces = 2; break; |
| 1774 | case recvr_type_gaming_hidpp: no_dj_interfaces = 3; break; |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1775 | case recvr_type_mouse_only: no_dj_interfaces = 2; break; |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1776 | case recvr_type_27mhz: no_dj_interfaces = 2; break; |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 1777 | case recvr_type_bluetooth: no_dj_interfaces = 2; break; |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 1778 | case recvr_type_dinovo: no_dj_interfaces = 2; break; |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1779 | } |
Greg Kroah-Hartman | f83baa0 | 2021-12-01 19:35:01 +0100 | [diff] [blame] | 1780 | if (hid_is_usb(hdev)) { |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1781 | intf = to_usb_interface(hdev->dev.parent); |
| 1782 | if (intf && intf->altsetting->desc.bInterfaceNumber >= |
| 1783 | no_dj_interfaces) { |
| 1784 | hdev->quirks |= HID_QUIRK_INPUT_PER_APP; |
| 1785 | return hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 1786 | } |
| 1787 | } |
| 1788 | |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1789 | rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; |
| 1790 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1791 | /* no input reports, bail out */ |
| 1792 | if (list_empty(&rep_enum->report_list)) |
| 1793 | return -ENODEV; |
| 1794 | |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1795 | /* |
| 1796 | * Check for the HID++ application. |
| 1797 | * Note: we should theoretically check for HID++ and DJ |
| 1798 | * collections, but this will do. |
| 1799 | */ |
| 1800 | list_for_each_entry(rep, &rep_enum->report_list, list) { |
| 1801 | if (rep->application == 0xff000001) |
| 1802 | has_hidpp = true; |
| 1803 | } |
| 1804 | |
| 1805 | /* |
| 1806 | * Ignore interfaces without DJ/HID++ collection, they will not carry |
| 1807 | * any data, dont create any hid_device for them. |
| 1808 | */ |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1809 | if (!has_hidpp && id->driver_data == recvr_type_dj) |
Benjamin Tissoires | 82c0beb | 2019-04-20 13:21:47 +0200 | [diff] [blame] | 1810 | return -ENODEV; |
| 1811 | |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1812 | /* get the current application attached to the node */ |
| 1813 | rep = list_first_entry(&rep_enum->report_list, struct hid_report, list); |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1814 | djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data, |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1815 | rep->application, has_hidpp); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1816 | if (!djrcv_dev) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1817 | hid_err(hdev, "%s: dj_get_receiver_dev failed\n", __func__); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1818 | return -ENOMEM; |
| 1819 | } |
Kees Cook | 297502a | 2013-09-11 21:56:56 +0200 | [diff] [blame] | 1820 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1821 | if (!rep_enum->numbered) |
| 1822 | djrcv_dev->unnumbered_application = rep->application; |
| 1823 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1824 | /* Starts the usb device and connects to upper interfaces hiddev and |
| 1825 | * hidraw */ |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1826 | retval = hid_hw_start(hdev, HID_CONNECT_HIDRAW|HID_CONNECT_HIDDEV); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1827 | if (retval) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1828 | hid_err(hdev, "%s: hid_hw_start returned error\n", __func__); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1829 | goto hid_hw_start_fail; |
| 1830 | } |
| 1831 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1832 | if (has_hidpp) { |
| 1833 | retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); |
| 1834 | if (retval < 0) { |
| 1835 | hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n", |
| 1836 | __func__, retval); |
| 1837 | goto switch_to_dj_mode_fail; |
| 1838 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /* This is enabling the polling urb on the IN endpoint */ |
Benjamin Tissoires | ddf7540 | 2013-07-12 11:01:02 +0200 | [diff] [blame] | 1842 | retval = hid_hw_open(hdev); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1843 | if (retval < 0) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1844 | hid_err(hdev, "%s: hid_hw_open returned error:%d\n", |
Benjamin Tissoires | ddf7540 | 2013-07-12 11:01:02 +0200 | [diff] [blame] | 1845 | __func__, retval); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1846 | goto llopen_failed; |
| 1847 | } |
| 1848 | |
Andrew de los Reyes | a9dd22b7 | 2013-02-18 09:20:22 -0800 | [diff] [blame] | 1849 | /* Allow incoming packets to arrive: */ |
| 1850 | hid_device_io_start(hdev); |
| 1851 | |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1852 | if (has_hidpp) { |
| 1853 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
| 1854 | djrcv_dev->ready = true; |
| 1855 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 1856 | retval = logi_dj_recv_query_paired_devices(djrcv_dev); |
| 1857 | if (retval < 0) { |
| 1858 | hid_err(hdev, "%s: logi_dj_recv_query_paired_devices error:%d\n", |
| 1859 | __func__, retval); |
Hans de Goede | 8ccff28 | 2019-08-25 17:35:42 +0200 | [diff] [blame] | 1860 | /* |
| 1861 | * This can happen with a KVM, let the probe succeed, |
| 1862 | * logi_dj_recv_queue_unknown_work will retry later. |
| 1863 | */ |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1864 | } |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1865 | } |
| 1866 | |
Hans de Goede | 8ccff28 | 2019-08-25 17:35:42 +0200 | [diff] [blame] | 1867 | return 0; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1868 | |
| 1869 | llopen_failed: |
| 1870 | switch_to_dj_mode_fail: |
| 1871 | hid_hw_stop(hdev); |
| 1872 | |
| 1873 | hid_hw_start_fail: |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1874 | dj_put_receiver_dev(hdev); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1875 | return retval; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | #ifdef CONFIG_PM |
| 1879 | static int logi_dj_reset_resume(struct hid_device *hdev) |
| 1880 | { |
| 1881 | int retval; |
| 1882 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
| 1883 | |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1884 | if (!djrcv_dev || djrcv_dev->hidpp != hdev) |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1885 | return 0; |
| 1886 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1887 | retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); |
| 1888 | if (retval < 0) { |
Hans de Goede | aca22a3 | 2019-04-20 13:21:58 +0200 | [diff] [blame] | 1889 | hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n", |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1890 | __func__, retval); |
| 1891 | } |
| 1892 | |
| 1893 | return 0; |
| 1894 | } |
| 1895 | #endif |
| 1896 | |
| 1897 | static void logi_dj_remove(struct hid_device *hdev) |
| 1898 | { |
| 1899 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
| 1900 | struct dj_device *dj_dev; |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1901 | unsigned long flags; |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1902 | int i; |
| 1903 | |
| 1904 | dbg_hid("%s\n", __func__); |
| 1905 | |
Hans de Goede | da12b22 | 2019-04-20 13:21:59 +0200 | [diff] [blame] | 1906 | if (!djrcv_dev) |
| 1907 | return hid_hw_stop(hdev); |
| 1908 | |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1909 | /* |
| 1910 | * This ensures that if the work gets requeued from another |
| 1911 | * interface of the same receiver it will be a no-op. |
| 1912 | */ |
| 1913 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
| 1914 | djrcv_dev->ready = false; |
| 1915 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
| 1916 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1917 | cancel_work_sync(&djrcv_dev->work); |
| 1918 | |
Benjamin Tissoires | ddf7540 | 2013-07-12 11:01:02 +0200 | [diff] [blame] | 1919 | hid_hw_close(hdev); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1920 | hid_hw_stop(hdev); |
| 1921 | |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1922 | /* |
| 1923 | * For proper operation we need access to all interfaces, so we destroy |
| 1924 | * the paired devices when we're unbound from any interface. |
| 1925 | * |
| 1926 | * Note we may still be bound to other interfaces, sharing the same |
| 1927 | * djrcv_dev, so we need locking here. |
| 1928 | */ |
Nestor Lopez Casado | 844580f | 2011-09-20 15:59:03 +0200 | [diff] [blame] | 1929 | for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) { |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1930 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1931 | dj_dev = djrcv_dev->paired_dj_devices[i]; |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1932 | djrcv_dev->paired_dj_devices[i] = NULL; |
| 1933 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1934 | if (dj_dev != NULL) { |
| 1935 | hid_destroy_device(dj_dev->hdev); |
| 1936 | kfree(dj_dev); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | |
Hans de Goede | a1d97cc | 2019-04-20 13:21:52 +0200 | [diff] [blame] | 1940 | dj_put_receiver_dev(hdev); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1941 | } |
| 1942 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 1943 | static const struct hid_device_id logi_dj_receivers[] = { |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1944 | { /* Logitech unifying receiver (0xc52b) */ |
| 1945 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1946 | USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER), |
| 1947 | .driver_data = recvr_type_dj}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1948 | { /* Logitech unifying receiver (0xc532) */ |
| 1949 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1950 | USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2), |
| 1951 | .driver_data = recvr_type_dj}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1952 | |
| 1953 | { /* Logitech Nano mouse only receiver (0xc52f) */ |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1954 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1955 | USB_DEVICE_ID_LOGITECH_NANO_RECEIVER), |
Hans de Goede | 3ed224e | 2019-06-05 14:44:08 +0200 | [diff] [blame] | 1956 | .driver_data = recvr_type_mouse_only}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1957 | { /* Logitech Nano (non DJ) receiver (0xc534) */ |
Hans de Goede | 74808f9 | 2019-04-20 13:21:54 +0200 | [diff] [blame] | 1958 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1959 | USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2), |
| 1960 | .driver_data = recvr_type_hidpp}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1961 | |
Benjamin Tissoires | 992ff2c | 2019-08-12 18:08:04 +0200 | [diff] [blame] | 1962 | { /* Logitech G700(s) receiver (0xc531) */ |
| 1963 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1964 | USB_DEVICE_ID_LOGITECH_G700_RECEIVER), |
Benjamin Tissoires | 992ff2c | 2019-08-12 18:08:04 +0200 | [diff] [blame] | 1965 | .driver_data = recvr_type_gaming_hidpp}, |
Filipe Laíns | e400071 | 2021-01-04 20:47:17 +0000 | [diff] [blame] | 1966 | { /* Logitech G602 receiver (0xc537) */ |
| 1967 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1968 | 0xc537), |
| 1969 | .driver_data = recvr_type_gaming_hidpp}, |
Filipe Laíns | 600ea54 | 2019-07-16 08:36:21 +0100 | [diff] [blame] | 1970 | { /* Logitech lightspeed receiver (0xc539) */ |
Benjamin Tissoires | f5fb57a | 2019-04-20 13:21:55 +0200 | [diff] [blame] | 1971 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Filipe Laíns | 5722f33 | 2019-07-30 13:24:57 +0100 | [diff] [blame] | 1972 | USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1), |
| 1973 | .driver_data = recvr_type_gaming_hidpp}, |
Filipe Laíns | d79f7ba | 2019-07-16 08:37:47 +0100 | [diff] [blame] | 1974 | { /* Logitech powerplay receiver (0xc53a) */ |
| 1975 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1976 | USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY), |
| 1977 | .driver_data = recvr_type_gaming_hidpp}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1978 | { /* Logitech lightspeed receiver (0xc53f) */ |
| 1979 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1980 | USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1), |
| 1981 | .driver_data = recvr_type_gaming_hidpp}, |
| 1982 | |
| 1983 | { /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */ |
| 1984 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER), |
| 1985 | .driver_data = recvr_type_27mhz}, |
Hans de Goede | c9121cf | 2019-04-20 13:21:56 +0200 | [diff] [blame] | 1986 | { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */ |
| 1987 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1988 | USB_DEVICE_ID_S510_RECEIVER_2), |
| 1989 | .driver_data = recvr_type_27mhz}, |
Hans de Goede | 1f944ac | 2019-04-20 13:21:57 +0200 | [diff] [blame] | 1990 | { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */ |
| 1991 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 1992 | USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER), |
| 1993 | .driver_data = recvr_type_27mhz}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1994 | |
| 1995 | { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. (0xc70e) */ |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 1996 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1997 | USB_DEVICE_ID_MX5000_RECEIVER_KBD_DEV), |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 1998 | .driver_data = recvr_type_bluetooth}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 1999 | { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. (0xc70a) */ |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 2000 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 2001 | USB_DEVICE_ID_MX5000_RECEIVER_MOUSE_DEV), |
Hans de Goede | f2113c3 | 2019-04-20 13:22:03 +0200 | [diff] [blame] | 2002 | .driver_data = recvr_type_bluetooth}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 2003 | { /* Logitech MX5500 HID++ / bluetooth receiver keyboard intf. (0xc71b) */ |
Hans de Goede | b9a94fb | 2019-04-28 21:25:51 +0200 | [diff] [blame] | 2004 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 2005 | USB_DEVICE_ID_MX5500_RECEIVER_KBD_DEV), |
Hans de Goede | b9a94fb | 2019-04-28 21:25:51 +0200 | [diff] [blame] | 2006 | .driver_data = recvr_type_bluetooth}, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 2007 | { /* Logitech MX5500 HID++ / bluetooth receiver mouse intf. (0xc71c) */ |
Hans de Goede | b9a94fb | 2019-04-28 21:25:51 +0200 | [diff] [blame] | 2008 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
Hans de Goede | 751cb65 | 2021-02-04 21:56:16 +0100 | [diff] [blame] | 2009 | USB_DEVICE_ID_MX5500_RECEIVER_MOUSE_DEV), |
Hans de Goede | b9a94fb | 2019-04-28 21:25:51 +0200 | [diff] [blame] | 2010 | .driver_data = recvr_type_bluetooth}, |
Hans de Goede | 434f770 | 2021-02-04 21:56:17 +0100 | [diff] [blame] | 2011 | |
| 2012 | { /* Logitech Dinovo Edge HID++ / bluetooth receiver keyboard intf. (0xc713) */ |
| 2013 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 2014 | USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_KBD_DEV), |
| 2015 | .driver_data = recvr_type_dinovo}, |
| 2016 | { /* Logitech Dinovo Edge HID++ / bluetooth receiver mouse intf. (0xc714) */ |
| 2017 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 2018 | USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_MOUSE_DEV), |
| 2019 | .driver_data = recvr_type_dinovo}, |
| 2020 | { /* Logitech DiNovo Mini HID++ / bluetooth receiver mouse intf. (0xc71e) */ |
| 2021 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 2022 | USB_DEVICE_ID_DINOVO_MINI_RECEIVER_KBD_DEV), |
| 2023 | .driver_data = recvr_type_dinovo}, |
| 2024 | { /* Logitech DiNovo Mini HID++ / bluetooth receiver keyboard intf. (0xc71f) */ |
| 2025 | HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
| 2026 | USB_DEVICE_ID_DINOVO_MINI_RECEIVER_MOUSE_DEV), |
| 2027 | .driver_data = recvr_type_dinovo}, |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 2028 | {} |
| 2029 | }; |
| 2030 | |
| 2031 | MODULE_DEVICE_TABLE(hid, logi_dj_receivers); |
| 2032 | |
| 2033 | static struct hid_driver logi_djreceiver_driver = { |
| 2034 | .name = "logitech-djreceiver", |
| 2035 | .id_table = logi_dj_receivers, |
| 2036 | .probe = logi_dj_probe, |
| 2037 | .remove = logi_dj_remove, |
| 2038 | .raw_event = logi_dj_raw_event, |
| 2039 | #ifdef CONFIG_PM |
| 2040 | .reset_resume = logi_dj_reset_resume, |
| 2041 | #endif |
| 2042 | }; |
| 2043 | |
Benjamin Tissoires | ab94e56 | 2014-09-30 13:18:28 -0400 | [diff] [blame] | 2044 | module_hid_driver(logi_djreceiver_driver); |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 2045 | |
Nestor Lopez Casado | 534a7b8 | 2011-09-15 11:34:49 +0200 | [diff] [blame] | 2046 | MODULE_LICENSE("GPL"); |
| 2047 | MODULE_AUTHOR("Logitech"); |
| 2048 | MODULE_AUTHOR("Nestor Lopez Casado"); |
| 2049 | MODULE_AUTHOR("nlopezcasad@logitech.com"); |