Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for some microsoft "special" devices |
| 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
| 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 7 | * Copyright (c) 2006-2007 Jiri Kosina |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 8 | * Copyright (c) 2008 Jiri Slaby |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the Free |
| 14 | * Software Foundation; either version 2 of the License, or (at your option) |
| 15 | * any later version. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/input.h> |
| 20 | #include <linux/hid.h> |
| 21 | #include <linux/module.h> |
| 22 | |
| 23 | #include "hid-ids.h" |
| 24 | |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 25 | #define MS_HIDINPUT 0x01 |
| 26 | #define MS_ERGONOMY 0x02 |
| 27 | #define MS_PRESENTER 0x04 |
| 28 | #define MS_RDESC 0x08 |
| 29 | #define MS_NOGET 0x10 |
| 30 | #define MS_DUPLICATE_USAGES 0x20 |
Jiri Slaby | 3ccc60f | 2012-10-19 13:28:46 +0200 | [diff] [blame] | 31 | #define MS_RDESC_3K 0x40 |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 32 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 33 | static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 34 | unsigned int *rsize) |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 35 | { |
| 36 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); |
| 37 | |
Jiri Slaby | 3ccc60f | 2012-10-19 13:28:46 +0200 | [diff] [blame] | 38 | /* |
| 39 | * Microsoft Wireless Desktop Receiver (Model 1028) has |
| 40 | * 'Usage Min/Max' where it ought to have 'Physical Min/Max' |
| 41 | */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 42 | if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 && |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 43 | rdesc[559] == 0x29) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 44 | 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] | 45 | rdesc[557] = 0x35; |
| 46 | rdesc[559] = 0x45; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 47 | } |
Jiri Slaby | 3ccc60f | 2012-10-19 13:28:46 +0200 | [diff] [blame] | 48 | /* the same as above (s/usage/physical/) */ |
Jiri Slaby | 6b90466 | 2012-11-12 10:16:09 +0100 | [diff] [blame] | 49 | if ((quirks & MS_RDESC_3K) && *rsize == 106 && rdesc[94] == 0x19 && |
| 50 | rdesc[95] == 0x00 && rdesc[96] == 0x29 && |
| 51 | rdesc[97] == 0xff) { |
Jiri Slaby | 3ccc60f | 2012-10-19 13:28:46 +0200 | [diff] [blame] | 52 | rdesc[94] = 0x35; |
| 53 | rdesc[96] = 0x45; |
| 54 | } |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 55 | return rdesc; |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ |
| 59 | EV_KEY, (c)) |
| 60 | static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage, |
| 61 | unsigned long **bit, int *max) |
| 62 | { |
| 63 | struct input_dev *input = hi->input; |
| 64 | |
| 65 | switch (usage->hid & HID_USAGE) { |
| 66 | case 0xfd06: ms_map_key_clear(KEY_CHAT); break; |
| 67 | case 0xfd07: ms_map_key_clear(KEY_PHONE); break; |
| 68 | case 0xff05: |
| 69 | set_bit(EV_REP, input->evbit); |
| 70 | ms_map_key_clear(KEY_F13); |
| 71 | set_bit(KEY_F14, input->keybit); |
| 72 | set_bit(KEY_F15, input->keybit); |
| 73 | set_bit(KEY_F16, input->keybit); |
| 74 | set_bit(KEY_F17, input->keybit); |
| 75 | set_bit(KEY_F18, input->keybit); |
| 76 | default: |
| 77 | return 0; |
| 78 | } |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage, |
| 83 | unsigned long **bit, int *max) |
| 84 | { |
| 85 | set_bit(EV_REP, hi->input->evbit); |
| 86 | switch (usage->hid & HID_USAGE) { |
| 87 | case 0xfd08: ms_map_key_clear(KEY_FORWARD); break; |
| 88 | case 0xfd09: ms_map_key_clear(KEY_BACK); break; |
| 89 | case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break; |
| 90 | case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break; |
| 91 | case 0xfd0f: ms_map_key_clear(KEY_PLAY); break; |
| 92 | default: |
| 93 | return 0; |
| 94 | } |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 99 | struct hid_field *field, struct hid_usage *usage, |
| 100 | unsigned long **bit, int *max) |
| 101 | { |
| 102 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); |
| 103 | |
| 104 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) |
| 105 | return 0; |
| 106 | |
| 107 | if (quirks & MS_ERGONOMY) { |
| 108 | int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max); |
| 109 | if (ret) |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | if ((quirks & MS_PRESENTER) && |
| 114 | ms_presenter_8k_quirk(hi, usage, bit, max)) |
| 115 | return 1; |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 120 | static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 121 | struct hid_field *field, struct hid_usage *usage, |
| 122 | unsigned long **bit, int *max) |
| 123 | { |
| 124 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); |
| 125 | |
| 126 | if (quirks & MS_DUPLICATE_USAGES) |
| 127 | clear_bit(usage->code, *bit); |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 132 | static int ms_event(struct hid_device *hdev, struct hid_field *field, |
| 133 | struct hid_usage *usage, __s32 value) |
| 134 | { |
| 135 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); |
| 136 | |
| 137 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || |
| 138 | !usage->type) |
| 139 | return 0; |
| 140 | |
| 141 | /* Handling MS keyboards special buttons */ |
| 142 | if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) { |
| 143 | struct input_dev *input = field->hidinput->input; |
| 144 | static unsigned int last_key = 0; |
| 145 | unsigned int key = 0; |
| 146 | switch (value) { |
| 147 | case 0x01: key = KEY_F14; break; |
| 148 | case 0x02: key = KEY_F15; break; |
| 149 | case 0x04: key = KEY_F16; break; |
| 150 | case 0x08: key = KEY_F17; break; |
| 151 | case 0x10: key = KEY_F18; break; |
| 152 | } |
| 153 | if (key) { |
| 154 | input_event(input, usage->type, key, 1); |
| 155 | last_key = key; |
| 156 | } else |
| 157 | input_event(input, usage->type, last_key, 0); |
| 158 | |
| 159 | return 1; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 166 | { |
| 167 | unsigned long quirks = id->driver_data; |
| 168 | int ret; |
| 169 | |
| 170 | hid_set_drvdata(hdev, (void *)quirks); |
| 171 | |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 172 | if (quirks & MS_NOGET) |
| 173 | hdev->quirks |= HID_QUIRK_NOGET; |
| 174 | |
| 175 | ret = hid_parse(hdev); |
| 176 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 177 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 178 | goto err_free; |
| 179 | } |
| 180 | |
Jiri Slaby | 93c1013 | 2008-06-27 00:04:24 +0200 | [diff] [blame] | 181 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ? |
| 182 | HID_CONNECT_HIDINPUT_FORCE : 0)); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 183 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 184 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 185 | goto err_free; |
| 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | err_free: |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | static const struct hid_device_id ms_devices[] = { |
| 194 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV), |
| 195 | .driver_data = MS_HIDINPUT }, |
| 196 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K), |
| 197 | .driver_data = MS_ERGONOMY }, |
| 198 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K), |
| 199 | .driver_data = MS_ERGONOMY | MS_RDESC }, |
| 200 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB), |
| 201 | .driver_data = MS_PRESENTER }, |
Jiri Kosina | f3b83d7 | 2011-06-13 23:08:18 +0300 | [diff] [blame] | 202 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K), |
Jiri Slaby | 3ccc60f | 2012-10-19 13:28:46 +0200 | [diff] [blame] | 203 | .driver_data = MS_ERGONOMY | MS_RDESC_3K }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 204 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0), |
| 205 | .driver_data = MS_NOGET }, |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 206 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500), |
| 207 | .driver_data = MS_DUPLICATE_USAGES }, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 208 | |
| 209 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), |
| 210 | .driver_data = MS_PRESENTER }, |
| 211 | { } |
| 212 | }; |
| 213 | MODULE_DEVICE_TABLE(hid, ms_devices); |
| 214 | |
| 215 | static struct hid_driver ms_driver = { |
| 216 | .name = "microsoft", |
| 217 | .id_table = ms_devices, |
| 218 | .report_fixup = ms_report_fixup, |
| 219 | .input_mapping = ms_input_mapping, |
Ari Savolainen | 23c10be | 2011-07-11 21:42:52 +0300 | [diff] [blame] | 220 | .input_mapped = ms_input_mapped, |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 221 | .event = ms_event, |
| 222 | .probe = ms_probe, |
| 223 | }; |
| 224 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 225 | static int __init ms_init(void) |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 226 | { |
| 227 | return hid_register_driver(&ms_driver); |
| 228 | } |
| 229 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 230 | static void __exit ms_exit(void) |
Jiri Slaby | 78a849a68 | 2008-06-20 21:26:11 +0200 | [diff] [blame] | 231 | { |
| 232 | hid_unregister_driver(&ms_driver); |
| 233 | } |
| 234 | |
| 235 | module_init(ms_init); |
| 236 | module_exit(ms_exit); |
| 237 | MODULE_LICENSE("GPL"); |