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