Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 2 | /* |
| 3 | * HID driver for some microsoft "special" devices |
| 4 | * |
| 5 | * Copyright (c) 1999 Andreas Gal |
| 6 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 7 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 8 | * Copyright (c) 2006-2007 Jiri Kosina |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 9 | * Copyright (c) 2008 Jiri Slaby |
| 10 | */ |
| 11 | |
| 12 | /* |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/input.h> |
| 17 | #include <linux/hid.h> |
| 18 | #include <linux/module.h> |
| 19 | |
| 20 | #include "hid-ids.h" |
| 21 | |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 22 | #define MS_HIDINPUT BIT(0) |
| 23 | #define MS_ERGONOMY BIT(1) |
| 24 | #define MS_PRESENTER BIT(2) |
| 25 | #define MS_RDESC BIT(3) |
| 26 | #define MS_NOGET BIT(4) |
| 27 | #define MS_DUPLICATE_USAGES BIT(5) |
| 28 | #define MS_SURFACE_DIAL BIT(6) |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 29 | #define MS_QUIRK_FF BIT(7) |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 30 | |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 31 | struct ms_data { |
| 32 | unsigned long quirks; |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 33 | struct hid_device *hdev; |
| 34 | struct work_struct ff_worker; |
| 35 | __u8 strong; |
| 36 | __u8 weak; |
| 37 | void *output_report_dmabuf; |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 40 | #define XB1S_FF_REPORT 3 |
| 41 | #define ENABLE_WEAK BIT(0) |
| 42 | #define ENABLE_STRONG BIT(1) |
| 43 | |
| 44 | enum { |
| 45 | MAGNITUDE_STRONG = 2, |
| 46 | MAGNITUDE_WEAK, |
| 47 | MAGNITUDE_NUM |
| 48 | }; |
| 49 | |
| 50 | struct xb1s_ff_report { |
| 51 | __u8 report_id; |
| 52 | __u8 enable; |
| 53 | __u8 magnitude[MAGNITUDE_NUM]; |
| 54 | __u8 duration_10ms; |
| 55 | __u8 start_delay_10ms; |
| 56 | __u8 loop_count; |
| 57 | } __packed; |
| 58 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 59 | static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 60 | unsigned int *rsize) |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 61 | { |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 62 | struct ms_data *ms = hid_get_drvdata(hdev); |
| 63 | unsigned long quirks = ms->quirks; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 64 | |
Jiri Slaby | 3ccc60f | 2012-10-19 13:28:46 +0200 | [diff] [blame] | 65 | /* |
| 66 | * Microsoft Wireless Desktop Receiver (Model 1028) has |
| 67 | * 'Usage Min/Max' where it ought to have 'Physical Min/Max' |
| 68 | */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 69 | if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 && |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 70 | rdesc[559] == 0x29) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 71 | hid_info(hdev, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n"); |
Jiri Kosina | 0fb21de | 2009-01-14 03:03:21 +0100 | [diff] [blame] | 72 | rdesc[557] = 0x35; |
| 73 | rdesc[559] = 0x45; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 74 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 75 | return rdesc; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 79 | EV_KEY, (c)) |
| 80 | static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage, |
| 81 | unsigned long **bit, int *max) |
| 82 | { |
| 83 | struct input_dev *input = hi->input; |
| 84 | |
Hans de Goede | 34e75dc | 2014-01-29 17:57:44 +0100 | [diff] [blame] | 85 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { |
| 86 | switch (usage->hid & HID_USAGE) { |
| 87 | /* |
| 88 | * Microsoft uses these 2 reserved usage ids for 2 keys on |
| 89 | * the MS office kb labelled "Office Home" and "Task Pane". |
| 90 | */ |
| 91 | case 0x29d: |
| 92 | ms_map_key_clear(KEY_PROG1); |
| 93 | return 1; |
| 94 | case 0x29e: |
| 95 | ms_map_key_clear(KEY_PROG2); |
| 96 | return 1; |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
Hans de Goede | aac59f6 | 2014-01-29 17:57:42 +0100 | [diff] [blame] | 101 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) |
| 102 | return 0; |
| 103 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 104 | switch (usage->hid & HID_USAGE) { |
| 105 | case 0xfd06: ms_map_key_clear(KEY_CHAT); break; |
| 106 | case 0xfd07: ms_map_key_clear(KEY_PHONE); break; |
Hans de Goede | 3faed1a | 2014-01-29 17:57:43 +0100 | [diff] [blame] | 107 | case 0xff00: |
| 108 | /* Special keypad keys */ |
| 109 | ms_map_key_clear(KEY_KPEQUAL); |
| 110 | set_bit(KEY_KPLEFTPAREN, input->keybit); |
| 111 | set_bit(KEY_KPRIGHTPAREN, input->keybit); |
| 112 | break; |
| 113 | case 0xff01: |
| 114 | /* Scroll wheel */ |
| 115 | hid_map_usage_clear(hi, usage, bit, max, EV_REL, REL_WHEEL); |
| 116 | break; |
| 117 | case 0xff02: |
| 118 | /* |
| 119 | * This byte contains a copy of the modifier keys byte of a |
| 120 | * standard hid keyboard report, as send by interface 0 |
| 121 | * (this usage is found on interface 1). |
| 122 | * |
| 123 | * This byte only gets send when another key in the same report |
| 124 | * changes state, and as such is useless, ignore it. |
| 125 | */ |
| 126 | return -1; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 127 | case 0xff05: |
| 128 | set_bit(EV_REP, input->evbit); |
| 129 | ms_map_key_clear(KEY_F13); |
| 130 | set_bit(KEY_F14, input->keybit); |
| 131 | set_bit(KEY_F15, input->keybit); |
| 132 | set_bit(KEY_F16, input->keybit); |
| 133 | set_bit(KEY_F17, input->keybit); |
| 134 | set_bit(KEY_F18, input->keybit); |
Jiri Kosina | b2b98ea | 2013-12-15 18:25:26 +0100 | [diff] [blame] | 135 | break; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 136 | default: |
| 137 | return 0; |
| 138 | } |
| 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage, |
| 143 | unsigned long **bit, int *max) |
| 144 | { |
Hans de Goede | aac59f6 | 2014-01-29 17:57:42 +0100 | [diff] [blame] | 145 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) |
| 146 | return 0; |
| 147 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 148 | set_bit(EV_REP, hi->input->evbit); |
| 149 | switch (usage->hid & HID_USAGE) { |
| 150 | case 0xfd08: ms_map_key_clear(KEY_FORWARD); break; |
| 151 | case 0xfd09: ms_map_key_clear(KEY_BACK); break; |
| 152 | case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break; |
| 153 | case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break; |
| 154 | case 0xfd0f: ms_map_key_clear(KEY_PLAY); break; |
| 155 | default: |
| 156 | return 0; |
| 157 | } |
| 158 | return 1; |
| 159 | } |
| 160 | |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 161 | static int ms_surface_dial_quirk(struct hid_input *hi, struct hid_field *field, |
| 162 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 163 | { |
| 164 | switch (usage->hid & HID_USAGE_PAGE) { |
| 165 | case 0xff070000: |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 166 | case HID_UP_DIGITIZER: |
| 167 | /* ignore those axis */ |
| 168 | return -1; |
| 169 | case HID_UP_GENDESK: |
| 170 | switch (usage->hid) { |
| 171 | case HID_GD_X: |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 172 | case HID_GD_Y: |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 173 | case HID_GD_RFKILL_BTN: |
| 174 | /* ignore those axis */ |
| 175 | return -1; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 182 | static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 183 | struct hid_field *field, struct hid_usage *usage, |
| 184 | unsigned long **bit, int *max) |
| 185 | { |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 186 | struct ms_data *ms = hid_get_drvdata(hdev); |
| 187 | unsigned long quirks = ms->quirks; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 188 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 189 | if (quirks & MS_ERGONOMY) { |
| 190 | int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max); |
| 191 | if (ret) |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | if ((quirks & MS_PRESENTER) && |
| 196 | ms_presenter_8k_quirk(hi, usage, bit, max)) |
| 197 | return 1; |
| 198 | |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 199 | if (quirks & MS_SURFACE_DIAL) { |
| 200 | int ret = ms_surface_dial_quirk(hi, field, usage, bit, max); |
| 201 | |
| 202 | if (ret) |
| 203 | return ret; |
| 204 | } |
| 205 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 209 | static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 210 | struct hid_field *field, struct hid_usage *usage, |
| 211 | unsigned long **bit, int *max) |
| 212 | { |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 213 | struct ms_data *ms = hid_get_drvdata(hdev); |
| 214 | unsigned long quirks = ms->quirks; |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 215 | |
| 216 | if (quirks & MS_DUPLICATE_USAGES) |
| 217 | clear_bit(usage->code, *bit); |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 222 | static int ms_event(struct hid_device *hdev, struct hid_field *field, |
| 223 | struct hid_usage *usage, __s32 value) |
| 224 | { |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 225 | struct ms_data *ms = hid_get_drvdata(hdev); |
| 226 | unsigned long quirks = ms->quirks; |
Hans de Goede | 3faed1a | 2014-01-29 17:57:43 +0100 | [diff] [blame] | 227 | struct input_dev *input; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 228 | |
| 229 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || |
| 230 | !usage->type) |
| 231 | return 0; |
| 232 | |
Hans de Goede | 3faed1a | 2014-01-29 17:57:43 +0100 | [diff] [blame] | 233 | input = field->hidinput->input; |
| 234 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 235 | /* Handling MS keyboards special buttons */ |
Hans de Goede | 3faed1a | 2014-01-29 17:57:43 +0100 | [diff] [blame] | 236 | if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff00)) { |
| 237 | /* Special keypad keys */ |
| 238 | input_report_key(input, KEY_KPEQUAL, value & 0x01); |
| 239 | input_report_key(input, KEY_KPLEFTPAREN, value & 0x02); |
| 240 | input_report_key(input, KEY_KPRIGHTPAREN, value & 0x04); |
| 241 | return 1; |
| 242 | } |
| 243 | |
| 244 | if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff01)) { |
| 245 | /* Scroll wheel */ |
| 246 | int step = ((value & 0x60) >> 5) + 1; |
| 247 | |
| 248 | switch (value & 0x1f) { |
| 249 | case 0x01: |
| 250 | input_report_rel(input, REL_WHEEL, step); |
| 251 | break; |
| 252 | case 0x1f: |
| 253 | input_report_rel(input, REL_WHEEL, -step); |
| 254 | break; |
| 255 | } |
| 256 | return 1; |
| 257 | } |
| 258 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 259 | if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) { |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 260 | static unsigned int last_key = 0; |
| 261 | unsigned int key = 0; |
| 262 | switch (value) { |
| 263 | case 0x01: key = KEY_F14; break; |
| 264 | case 0x02: key = KEY_F15; break; |
| 265 | case 0x04: key = KEY_F16; break; |
| 266 | case 0x08: key = KEY_F17; break; |
| 267 | case 0x10: key = KEY_F18; break; |
| 268 | } |
| 269 | if (key) { |
| 270 | input_event(input, usage->type, key, 1); |
| 271 | last_key = key; |
| 272 | } else |
| 273 | input_event(input, usage->type, last_key, 0); |
| 274 | |
| 275 | return 1; |
| 276 | } |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 281 | static void ms_ff_worker(struct work_struct *work) |
| 282 | { |
| 283 | struct ms_data *ms = container_of(work, struct ms_data, ff_worker); |
| 284 | struct hid_device *hdev = ms->hdev; |
| 285 | struct xb1s_ff_report *r = ms->output_report_dmabuf; |
| 286 | int ret; |
| 287 | |
| 288 | memset(r, 0, sizeof(*r)); |
| 289 | |
| 290 | r->report_id = XB1S_FF_REPORT; |
| 291 | r->enable = ENABLE_WEAK | ENABLE_STRONG; |
| 292 | /* |
| 293 | * Specifying maximum duration and maximum loop count should |
| 294 | * cover maximum duration of a single effect, which is 65536 |
| 295 | * ms |
| 296 | */ |
| 297 | r->duration_10ms = U8_MAX; |
| 298 | r->loop_count = U8_MAX; |
| 299 | r->magnitude[MAGNITUDE_STRONG] = ms->strong; /* left actuator */ |
| 300 | r->magnitude[MAGNITUDE_WEAK] = ms->weak; /* right actuator */ |
| 301 | |
| 302 | ret = hid_hw_output_report(hdev, (__u8 *)r, sizeof(*r)); |
Dan Elkouby | 8bb3537 | 2019-09-06 14:06:44 +0300 | [diff] [blame] | 303 | if (ret < 0) |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 304 | hid_warn(hdev, "failed to send FF report\n"); |
| 305 | } |
| 306 | |
| 307 | static int ms_play_effect(struct input_dev *dev, void *data, |
| 308 | struct ff_effect *effect) |
| 309 | { |
| 310 | struct hid_device *hid = input_get_drvdata(dev); |
| 311 | struct ms_data *ms = hid_get_drvdata(hid); |
| 312 | |
| 313 | if (effect->type != FF_RUMBLE) |
| 314 | return 0; |
| 315 | |
| 316 | /* |
| 317 | * Magnitude is 0..100 so scale the 16-bit input here |
| 318 | */ |
| 319 | ms->strong = ((u32) effect->u.rumble.strong_magnitude * 100) / U16_MAX; |
| 320 | ms->weak = ((u32) effect->u.rumble.weak_magnitude * 100) / U16_MAX; |
| 321 | |
| 322 | schedule_work(&ms->ff_worker); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static int ms_init_ff(struct hid_device *hdev) |
| 327 | { |
Alan Stern | d9d4b1e | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 328 | struct hid_input *hidinput; |
| 329 | struct input_dev *input_dev; |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 330 | struct ms_data *ms = hid_get_drvdata(hdev); |
| 331 | |
Alan Stern | d9d4b1e | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 332 | if (list_empty(&hdev->inputs)) { |
| 333 | hid_err(hdev, "no inputs found\n"); |
| 334 | return -ENODEV; |
| 335 | } |
| 336 | hidinput = list_entry(hdev->inputs.next, struct hid_input, list); |
| 337 | input_dev = hidinput->input; |
| 338 | |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 339 | if (!(ms->quirks & MS_QUIRK_FF)) |
| 340 | return 0; |
| 341 | |
| 342 | ms->hdev = hdev; |
| 343 | INIT_WORK(&ms->ff_worker, ms_ff_worker); |
| 344 | |
| 345 | ms->output_report_dmabuf = devm_kzalloc(&hdev->dev, |
| 346 | sizeof(struct xb1s_ff_report), |
| 347 | GFP_KERNEL); |
| 348 | if (ms->output_report_dmabuf == NULL) |
| 349 | return -ENOMEM; |
| 350 | |
| 351 | input_set_capability(input_dev, EV_FF, FF_RUMBLE); |
| 352 | return input_ff_create_memless(input_dev, NULL, ms_play_effect); |
| 353 | } |
| 354 | |
| 355 | static void ms_remove_ff(struct hid_device *hdev) |
| 356 | { |
| 357 | struct ms_data *ms = hid_get_drvdata(hdev); |
| 358 | |
| 359 | if (!(ms->quirks & MS_QUIRK_FF)) |
| 360 | return; |
| 361 | |
| 362 | cancel_work_sync(&ms->ff_worker); |
| 363 | } |
| 364 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 365 | static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 366 | { |
| 367 | unsigned long quirks = id->driver_data; |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 368 | struct ms_data *ms; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 369 | int ret; |
| 370 | |
Andrey Smirnov | f2d3b62 | 2018-08-15 19:44:09 -0700 | [diff] [blame] | 371 | ms = devm_kzalloc(&hdev->dev, sizeof(*ms), GFP_KERNEL); |
| 372 | if (ms == NULL) |
| 373 | return -ENOMEM; |
| 374 | |
| 375 | ms->quirks = quirks; |
| 376 | |
| 377 | hid_set_drvdata(hdev, ms); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 378 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 379 | if (quirks & MS_NOGET) |
| 380 | hdev->quirks |= HID_QUIRK_NOGET; |
| 381 | |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 382 | if (quirks & MS_SURFACE_DIAL) |
| 383 | hdev->quirks |= HID_QUIRK_INPUT_PER_APP; |
| 384 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 385 | ret = hid_parse(hdev); |
| 386 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 387 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 388 | goto err_free; |
| 389 | } |
| 390 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 391 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ? |
| 392 | HID_CONNECT_HIDINPUT_FORCE : 0)); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 393 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 394 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 395 | goto err_free; |
| 396 | } |
| 397 | |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 398 | ret = ms_init_ff(hdev); |
| 399 | if (ret) |
| 400 | hid_err(hdev, "could not initialize ff, continuing anyway"); |
| 401 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 402 | return 0; |
| 403 | err_free: |
| 404 | return ret; |
| 405 | } |
| 406 | |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 407 | static void ms_remove(struct hid_device *hdev) |
| 408 | { |
| 409 | hid_hw_stop(hdev); |
| 410 | ms_remove_ff(hdev); |
| 411 | } |
| 412 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 413 | static const struct hid_device_id ms_devices[] = { |
| 414 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV), |
| 415 | .driver_data = MS_HIDINPUT }, |
Hans de Goede | 3faed1a | 2014-01-29 17:57:43 +0100 | [diff] [blame] | 416 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB), |
| 417 | .driver_data = MS_ERGONOMY }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 418 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K), |
| 419 | .driver_data = MS_ERGONOMY }, |
Adam Jiang | 89759e2 | 2013-04-29 13:27:31 +0900 | [diff] [blame] | 420 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP), |
| 421 | .driver_data = MS_ERGONOMY }, |
Jakub Sitnicki | ef567cf | 2015-02-21 20:51:08 +0100 | [diff] [blame] | 422 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE7K), |
| 423 | .driver_data = MS_ERGONOMY }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 424 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K), |
| 425 | .driver_data = MS_ERGONOMY | MS_RDESC }, |
| 426 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB), |
| 427 | .driver_data = MS_PRESENTER }, |
Jiri Kosina | f3b83d7 | 2011-06-13 23:08:18 +0300 | [diff] [blame] | 428 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K), |
Michel Hermier | 52dc085 | 2016-09-20 19:50:51 +0200 | [diff] [blame] | 429 | .driver_data = MS_ERGONOMY }, |
Alistair Leslie-Hughes | c847a89 | 2016-04-04 20:51:40 +1000 | [diff] [blame] | 430 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K), |
| 431 | .driver_data = MS_ERGONOMY }, |
| 432 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600), |
| 433 | .driver_data = MS_ERGONOMY }, |
| 434 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1), |
| 435 | .driver_data = MS_ERGONOMY }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 436 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0), |
| 437 | .driver_data = MS_NOGET }, |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 438 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500), |
| 439 | .driver_data = MS_DUPLICATE_USAGES }, |
Raimund Roth | 18eec2c | 2015-06-08 11:11:38 +0200 | [diff] [blame] | 440 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER), |
| 441 | .driver_data = MS_HIDINPUT }, |
Slava Bacherikov | f9a82c2 | 2016-03-11 18:57:24 +0200 | [diff] [blame] | 442 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD), |
| 443 | .driver_data = MS_ERGONOMY}, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 444 | |
| 445 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), |
| 446 | .driver_data = MS_PRESENTER }, |
Benjamin Tissoires | 30576c5 | 2018-07-13 16:13:51 +0200 | [diff] [blame] | 447 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, 0x091B), |
| 448 | .driver_data = MS_SURFACE_DIAL }, |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 449 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_XBOX_ONE_S_CONTROLLER), |
| 450 | .driver_data = MS_QUIRK_FF }, |
Nicholas Miell | 724a419 | 2020-08-28 21:14:29 -0700 | [diff] [blame] | 451 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_8BITDO_SN30_PRO_PLUS), |
| 452 | .driver_data = MS_QUIRK_FF }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 453 | { } |
| 454 | }; |
| 455 | MODULE_DEVICE_TABLE(hid, ms_devices); |
| 456 | |
| 457 | static struct hid_driver ms_driver = { |
| 458 | .name = "microsoft", |
| 459 | .id_table = ms_devices, |
| 460 | .report_fixup = ms_report_fixup, |
| 461 | .input_mapping = ms_input_mapping, |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 462 | .input_mapped = ms_input_mapped, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 463 | .event = ms_event, |
| 464 | .probe = ms_probe, |
Andrey Smirnov | 73c5b25 | 2018-08-15 19:44:10 -0700 | [diff] [blame] | 465 | .remove = ms_remove, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 466 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 467 | module_hid_driver(ms_driver); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 468 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 469 | MODULE_LICENSE("GPL"); |