Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid

Pull HID updates from Jiri Kosina:

- touch_max detection improvements and quirk handling fixes in wacom
driver from Jason Gerecke and Ping Cheng

- Palm rejection from Dmitry Torokhov and _dial support from Benjamin
Tissoires for hid-multitouch driver

- Low voltage support for i2c-hid driver from Stephen Boyd

- Guitar-Hero support from Nicolas Adenis-Lamarre

- other assorted small fixes and device ID additions

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: (40 commits)
HID: intel_ish-hid: tx_buf memory leak on probe/remove
HID: intel-ish-hid: Prevent loading of driver on Mehlow
HID: cougar: Add support for the Cougar 500k Gaming Keyboard
HID: cougar: make compare_device_paths reusable
HID: intel-ish-hid: remove redundant variable num_frags
HID: multitouch: handle palm for touchscreens
HID: multitouch: touchscreens also use confidence reports
HID: multitouch: report MT_TOOL_PALM for non-confident touches
HID: microsoft: support the Surface Dial
HID: core: do not upper bound the collection stack
HID: input: enable Totem on the Dell Canvas 27
HID: multitouch: remove one copy of values
HID: multitouch: ditch mt_report_id
HID: multitouch: store a per application quirks value
HID: multitouch: Store per collection multitouch data
HID: multitouch: make sure the static list of class is not changed
input: add MT_TOOL_DIAL
HID: elan: Add support for touchpad on the Toshiba Click Mini L9W
HID: elan: Add USB-id for HP x2 10-n000nd touchpad
HID: elan: Add a flag for selecting if the touchpad has a LED
...

+1828 -752
+2 -1
Documentation/devicetree/bindings/input/hid-over-i2c.txt
··· 25 25 26 26 - compatible: 27 27 * "wacom,w9013" (Wacom W9013 digitizer). Supports: 28 - - vdd-supply 28 + - vdd-supply (3.3V) 29 + - vddl-supply (1.8V) 29 30 - post-power-on-delay-ms 30 31 31 32 - vdd-supply: phandle of the regulator that provides the supply voltage.
+6 -6
Documentation/input/multi-touch-protocol.rst
··· 310 310 ABS_MT_TOOL_TYPE 311 311 The type of approaching tool. A lot of kernel drivers cannot distinguish 312 312 between different tool types, such as a finger or a pen. In such cases, the 313 - event should be omitted. The protocol currently supports MT_TOOL_FINGER, 314 - MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_. For type B devices, this event is 315 - handled by input core; drivers should instead use 316 - input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may change over 317 - time while still touching the device, because the firmware may not be able 318 - to determine which tool is being used when it first appears. 313 + event should be omitted. The protocol currently mainly supports 314 + MT_TOOL_FINGER, MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_. 315 + For type B devices, this event is handled by input core; drivers should 316 + instead use input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may 317 + change over time while still touching the device, because the firmware may 318 + not be able to determine which tool is being used when it first appears. 319 319 320 320 ABS_MT_BLOB_ID 321 321 The BLOB_ID groups several packets together into one arbitrarily shaped
+10
drivers/hid/Kconfig
··· 207 207 - Vengeance K90 208 208 - Scimitar PRO RGB 209 209 210 + config HID_COUGAR 211 + tristate "Cougar devices" 212 + depends on HID 213 + help 214 + Support for Cougar devices that are not fully compliant with the 215 + HID standard. 216 + 217 + Supported devices: 218 + - Cougar 500k Gaming Keyboard 219 + 210 220 config HID_PRODIKEYS 211 221 tristate "Prodikeys PC-MIDI Keyboard support" 212 222 depends on HID && SND
+1
drivers/hid/Makefile
··· 35 35 obj-$(CONFIG_HID_CHICONY) += hid-chicony.o 36 36 obj-$(CONFIG_HID_CMEDIA) += hid-cmedia.o 37 37 obj-$(CONFIG_HID_CORSAIR) += hid-corsair.o 38 + obj-$(CONFIG_HID_COUGAR) += hid-cougar.o 38 39 obj-$(CONFIG_HID_CP2112) += hid-cp2112.o 39 40 obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o 40 41 obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o
+37 -3
drivers/hid/hid-core.c
··· 128 128 129 129 usage = parser->local.usage[0]; 130 130 131 - if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { 132 - hid_err(parser->device, "collection stack overflow\n"); 133 - return -EINVAL; 131 + if (parser->collection_stack_ptr == parser->collection_stack_size) { 132 + unsigned int *collection_stack; 133 + unsigned int new_size = parser->collection_stack_size + 134 + HID_COLLECTION_STACK_SIZE; 135 + 136 + collection_stack = krealloc(parser->collection_stack, 137 + new_size * sizeof(unsigned int), 138 + GFP_KERNEL); 139 + if (!collection_stack) 140 + return -ENOMEM; 141 + 142 + parser->collection_stack = collection_stack; 143 + parser->collection_stack_size = new_size; 134 144 } 135 145 136 146 if (parser->device->maxcollection == parser->device->collection_size) { ··· 850 840 break; 851 841 } 852 842 843 + kfree(parser->collection_stack); 853 844 vfree(parser); 854 845 return 0; 855 846 } ··· 1949 1938 1950 1939 return hid_match_device(hdev, hdrv) != NULL; 1951 1940 } 1941 + 1942 + /** 1943 + * hid_compare_device_paths - check if both devices share the same path 1944 + * @hdev_a: hid device 1945 + * @hdev_b: hid device 1946 + * @separator: char to use as separator 1947 + * 1948 + * Check if two devices share the same path up to the last occurrence of 1949 + * the separator char. Both paths must exist (i.e., zero-length paths 1950 + * don't match). 1951 + */ 1952 + bool hid_compare_device_paths(struct hid_device *hdev_a, 1953 + struct hid_device *hdev_b, char separator) 1954 + { 1955 + int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys; 1956 + int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys; 1957 + 1958 + if (n1 != n2 || n1 <= 0 || n2 <= 0) 1959 + return false; 1960 + 1961 + return !strncmp(hdev_a->phys, hdev_b->phys, n1); 1962 + } 1963 + EXPORT_SYMBOL_GPL(hid_compare_device_paths); 1952 1964 1953 1965 static int hid_device_probe(struct device *dev) 1954 1966 {
+312
drivers/hid/hid-cougar.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * HID driver for Cougar 500k Gaming Keyboard 4 + * 5 + * Copyright (c) 2018 Daniel M. Lambea <dmlambea@gmail.com> 6 + */ 7 + 8 + #include <linux/hid.h> 9 + #include <linux/module.h> 10 + 11 + #include "hid-ids.h" 12 + 13 + MODULE_AUTHOR("Daniel M. Lambea <dmlambea@gmail.com>"); 14 + MODULE_DESCRIPTION("Cougar 500k Gaming Keyboard"); 15 + MODULE_LICENSE("GPL"); 16 + MODULE_INFO(key_mappings, "G1-G6 are mapped to F13-F18"); 17 + 18 + static int cougar_g6_is_space = 1; 19 + module_param_named(g6_is_space, cougar_g6_is_space, int, 0600); 20 + MODULE_PARM_DESC(g6_is_space, 21 + "If set, G6 programmable key sends SPACE instead of F18 (0=off, 1=on) (default=1)"); 22 + 23 + 24 + #define COUGAR_VENDOR_USAGE 0xff00ff00 25 + 26 + #define COUGAR_FIELD_CODE 1 27 + #define COUGAR_FIELD_ACTION 2 28 + 29 + #define COUGAR_KEY_G1 0x83 30 + #define COUGAR_KEY_G2 0x84 31 + #define COUGAR_KEY_G3 0x85 32 + #define COUGAR_KEY_G4 0x86 33 + #define COUGAR_KEY_G5 0x87 34 + #define COUGAR_KEY_G6 0x78 35 + #define COUGAR_KEY_FN 0x0d 36 + #define COUGAR_KEY_MR 0x6f 37 + #define COUGAR_KEY_M1 0x80 38 + #define COUGAR_KEY_M2 0x81 39 + #define COUGAR_KEY_M3 0x82 40 + #define COUGAR_KEY_LEDS 0x67 41 + #define COUGAR_KEY_LOCK 0x6e 42 + 43 + 44 + /* Default key mappings. The special key COUGAR_KEY_G6 is defined first 45 + * because it is more frequent to use the spacebar rather than any other 46 + * special keys. Depending on the value of the parameter 'g6_is_space', 47 + * the mapping will be updated in the probe function. 48 + */ 49 + static unsigned char cougar_mapping[][2] = { 50 + { COUGAR_KEY_G6, KEY_SPACE }, 51 + { COUGAR_KEY_G1, KEY_F13 }, 52 + { COUGAR_KEY_G2, KEY_F14 }, 53 + { COUGAR_KEY_G3, KEY_F15 }, 54 + { COUGAR_KEY_G4, KEY_F16 }, 55 + { COUGAR_KEY_G5, KEY_F17 }, 56 + { COUGAR_KEY_LOCK, KEY_SCREENLOCK }, 57 + /* The following keys are handled by the hardware itself, so no special 58 + * treatment is required: 59 + { COUGAR_KEY_FN, KEY_RESERVED }, 60 + { COUGAR_KEY_MR, KEY_RESERVED }, 61 + { COUGAR_KEY_M1, KEY_RESERVED }, 62 + { COUGAR_KEY_M2, KEY_RESERVED }, 63 + { COUGAR_KEY_M3, KEY_RESERVED }, 64 + { COUGAR_KEY_LEDS, KEY_RESERVED }, 65 + */ 66 + { 0, 0 }, 67 + }; 68 + 69 + struct cougar_shared { 70 + struct list_head list; 71 + struct kref kref; 72 + bool enabled; 73 + struct hid_device *dev; 74 + struct input_dev *input; 75 + }; 76 + 77 + struct cougar { 78 + bool special_intf; 79 + struct cougar_shared *shared; 80 + }; 81 + 82 + static LIST_HEAD(cougar_udev_list); 83 + static DEFINE_MUTEX(cougar_udev_list_lock); 84 + 85 + static void cougar_fix_g6_mapping(struct hid_device *hdev) 86 + { 87 + int i; 88 + 89 + for (i = 0; cougar_mapping[i][0]; i++) { 90 + if (cougar_mapping[i][0] == COUGAR_KEY_G6) { 91 + cougar_mapping[i][1] = 92 + cougar_g6_is_space ? KEY_SPACE : KEY_F18; 93 + hid_info(hdev, "G6 mapped to %s\n", 94 + cougar_g6_is_space ? "space" : "F18"); 95 + return; 96 + } 97 + } 98 + hid_warn(hdev, "no mapping defined for G6/spacebar"); 99 + } 100 + 101 + /* 102 + * Constant-friendly rdesc fixup for mouse interface 103 + */ 104 + static __u8 *cougar_report_fixup(struct hid_device *hdev, __u8 *rdesc, 105 + unsigned int *rsize) 106 + { 107 + if (rdesc[2] == 0x09 && rdesc[3] == 0x02 && 108 + (rdesc[115] | rdesc[116] << 8) >= HID_MAX_USAGES) { 109 + hid_info(hdev, 110 + "usage count exceeds max: fixing up report descriptor\n"); 111 + rdesc[115] = ((HID_MAX_USAGES-1) & 0xff); 112 + rdesc[116] = ((HID_MAX_USAGES-1) >> 8); 113 + } 114 + return rdesc; 115 + } 116 + 117 + static struct cougar_shared *cougar_get_shared_data(struct hid_device *hdev) 118 + { 119 + struct cougar_shared *shared; 120 + 121 + /* Try to find an already-probed interface from the same device */ 122 + list_for_each_entry(shared, &cougar_udev_list, list) { 123 + if (hid_compare_device_paths(hdev, shared->dev, '/')) { 124 + kref_get(&shared->kref); 125 + return shared; 126 + } 127 + } 128 + return NULL; 129 + } 130 + 131 + static void cougar_release_shared_data(struct kref *kref) 132 + { 133 + struct cougar_shared *shared = container_of(kref, 134 + struct cougar_shared, kref); 135 + 136 + mutex_lock(&cougar_udev_list_lock); 137 + list_del(&shared->list); 138 + mutex_unlock(&cougar_udev_list_lock); 139 + 140 + kfree(shared); 141 + } 142 + 143 + static void cougar_remove_shared_data(void *resource) 144 + { 145 + struct cougar *cougar = resource; 146 + 147 + if (cougar->shared) { 148 + kref_put(&cougar->shared->kref, cougar_release_shared_data); 149 + cougar->shared = NULL; 150 + } 151 + } 152 + 153 + /* 154 + * Bind the device group's shared data to this cougar struct. 155 + * If no shared data exists for this group, create and initialize it. 156 + */ 157 + static int cougar_bind_shared_data(struct hid_device *hdev, struct cougar *cougar) 158 + { 159 + struct cougar_shared *shared; 160 + int error = 0; 161 + 162 + mutex_lock(&cougar_udev_list_lock); 163 + 164 + shared = cougar_get_shared_data(hdev); 165 + if (!shared) { 166 + shared = kzalloc(sizeof(*shared), GFP_KERNEL); 167 + if (!shared) { 168 + error = -ENOMEM; 169 + goto out; 170 + } 171 + 172 + kref_init(&shared->kref); 173 + shared->dev = hdev; 174 + list_add_tail(&shared->list, &cougar_udev_list); 175 + } 176 + 177 + cougar->shared = shared; 178 + 179 + error = devm_add_action(&hdev->dev, cougar_remove_shared_data, cougar); 180 + if (error) { 181 + mutex_unlock(&cougar_udev_list_lock); 182 + cougar_remove_shared_data(cougar); 183 + return error; 184 + } 185 + 186 + out: 187 + mutex_unlock(&cougar_udev_list_lock); 188 + return error; 189 + } 190 + 191 + static int cougar_probe(struct hid_device *hdev, 192 + const struct hid_device_id *id) 193 + { 194 + struct cougar *cougar; 195 + struct hid_input *next, *hidinput = NULL; 196 + unsigned int connect_mask; 197 + int error; 198 + 199 + cougar = devm_kzalloc(&hdev->dev, sizeof(*cougar), GFP_KERNEL); 200 + if (!cougar) 201 + return -ENOMEM; 202 + hid_set_drvdata(hdev, cougar); 203 + 204 + error = hid_parse(hdev); 205 + if (error) { 206 + hid_err(hdev, "parse failed\n"); 207 + goto fail; 208 + } 209 + 210 + if (hdev->collection->usage == COUGAR_VENDOR_USAGE) { 211 + cougar->special_intf = true; 212 + connect_mask = HID_CONNECT_HIDRAW; 213 + } else 214 + connect_mask = HID_CONNECT_DEFAULT; 215 + 216 + error = hid_hw_start(hdev, connect_mask); 217 + if (error) { 218 + hid_err(hdev, "hw start failed\n"); 219 + goto fail; 220 + } 221 + 222 + error = cougar_bind_shared_data(hdev, cougar); 223 + if (error) 224 + goto fail_stop_and_cleanup; 225 + 226 + /* The custom vendor interface will use the hid_input registered 227 + * for the keyboard interface, in order to send translated key codes 228 + * to it. 229 + */ 230 + if (hdev->collection->usage == HID_GD_KEYBOARD) { 231 + cougar_fix_g6_mapping(hdev); 232 + list_for_each_entry_safe(hidinput, next, &hdev->inputs, list) { 233 + if (hidinput->registered && hidinput->input != NULL) { 234 + cougar->shared->input = hidinput->input; 235 + cougar->shared->enabled = true; 236 + break; 237 + } 238 + } 239 + } else if (hdev->collection->usage == COUGAR_VENDOR_USAGE) { 240 + error = hid_hw_open(hdev); 241 + if (error) 242 + goto fail_stop_and_cleanup; 243 + } 244 + return 0; 245 + 246 + fail_stop_and_cleanup: 247 + hid_hw_stop(hdev); 248 + fail: 249 + hid_set_drvdata(hdev, NULL); 250 + return error; 251 + } 252 + 253 + /* 254 + * Convert events from vendor intf to input key events 255 + */ 256 + static int cougar_raw_event(struct hid_device *hdev, struct hid_report *report, 257 + u8 *data, int size) 258 + { 259 + struct cougar *cougar; 260 + unsigned char code, action; 261 + int i; 262 + 263 + cougar = hid_get_drvdata(hdev); 264 + if (!cougar->special_intf || !cougar->shared || 265 + !cougar->shared->input || !cougar->shared->enabled) 266 + return 0; 267 + 268 + code = data[COUGAR_FIELD_CODE]; 269 + action = data[COUGAR_FIELD_ACTION]; 270 + for (i = 0; cougar_mapping[i][0]; i++) { 271 + if (code == cougar_mapping[i][0]) { 272 + input_event(cougar->shared->input, EV_KEY, 273 + cougar_mapping[i][1], action); 274 + input_sync(cougar->shared->input); 275 + return 0; 276 + } 277 + } 278 + hid_warn(hdev, "unmapped special key code %x: ignoring\n", code); 279 + return 0; 280 + } 281 + 282 + static void cougar_remove(struct hid_device *hdev) 283 + { 284 + struct cougar *cougar = hid_get_drvdata(hdev); 285 + 286 + if (cougar) { 287 + /* Stop the vendor intf to process more events */ 288 + if (cougar->shared) 289 + cougar->shared->enabled = false; 290 + if (cougar->special_intf) 291 + hid_hw_close(hdev); 292 + } 293 + hid_hw_stop(hdev); 294 + } 295 + 296 + static struct hid_device_id cougar_id_table[] = { 297 + { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR, 298 + USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD) }, 299 + {} 300 + }; 301 + MODULE_DEVICE_TABLE(hid, cougar_id_table); 302 + 303 + static struct hid_driver cougar_driver = { 304 + .name = "cougar", 305 + .id_table = cougar_id_table, 306 + .report_fixup = cougar_report_fixup, 307 + .probe = cougar_probe, 308 + .remove = cougar_remove, 309 + .raw_event = cougar_raw_event, 310 + }; 311 + 312 + module_hid_driver(cougar_driver);
+182 -53
drivers/hid/hid-elan.c
··· 19 19 20 20 #include "hid-ids.h" 21 21 22 + #define ELAN_MT_I2C 0x5d 22 23 #define ELAN_SINGLE_FINGER 0x81 23 24 #define ELAN_MT_FIRST_FINGER 0x82 24 25 #define ELAN_MT_SECOND_FINGER 0x83 25 26 #define ELAN_INPUT_REPORT_SIZE 8 27 + #define ELAN_I2C_REPORT_SIZE 32 28 + #define ELAN_FINGER_DATA_LEN 5 29 + #define ELAN_MAX_FINGERS 5 30 + #define ELAN_MAX_PRESSURE 255 31 + #define ELAN_TP_USB_INTF 1 32 + 33 + #define ELAN_FEATURE_REPORT 0x0d 34 + #define ELAN_FEATURE_SIZE 5 35 + #define ELAN_PARAM_MAX_X 6 36 + #define ELAN_PARAM_MAX_Y 7 37 + #define ELAN_PARAM_RES 8 26 38 27 39 #define ELAN_MUTE_LED_REPORT 0xBC 28 40 #define ELAN_LED_REPORT_SIZE 8 29 41 30 - struct elan_touchpad_settings { 31 - u8 max_fingers; 32 - u16 max_x; 33 - u16 max_y; 34 - u8 max_area_x; 35 - u8 max_area_y; 36 - u8 max_w; 37 - int usb_bInterfaceNumber; 38 - }; 42 + #define ELAN_HAS_LED BIT(0) 39 43 40 44 struct elan_drvdata { 41 45 struct input_dev *input; 42 46 u8 prev_report[ELAN_INPUT_REPORT_SIZE]; 43 47 struct led_classdev mute_led; 44 48 u8 mute_led_state; 45 - struct elan_touchpad_settings *settings; 49 + u16 max_x; 50 + u16 max_y; 51 + u16 res_x; 52 + u16 res_y; 46 53 }; 47 54 48 55 static int is_not_elan_touchpad(struct hid_device *hdev) 49 56 { 50 - struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 51 - struct elan_drvdata *drvdata = hid_get_drvdata(hdev); 57 + if (hdev->bus == BUS_USB) { 58 + struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 52 59 53 - return (intf->altsetting->desc.bInterfaceNumber != drvdata->settings->usb_bInterfaceNumber); 60 + return (intf->altsetting->desc.bInterfaceNumber != 61 + ELAN_TP_USB_INTF); 62 + } 63 + 64 + return 0; 54 65 } 55 66 56 67 static int elan_input_mapping(struct hid_device *hdev, struct hid_input *hi, ··· 73 62 74 63 if (field->report->id == ELAN_SINGLE_FINGER || 75 64 field->report->id == ELAN_MT_FIRST_FINGER || 76 - field->report->id == ELAN_MT_SECOND_FINGER) 65 + field->report->id == ELAN_MT_SECOND_FINGER || 66 + field->report->id == ELAN_MT_I2C) 77 67 return -1; 78 68 79 69 return 0; 70 + } 71 + 72 + static int elan_get_device_param(struct hid_device *hdev, 73 + unsigned char *dmabuf, unsigned char param) 74 + { 75 + int ret; 76 + 77 + dmabuf[0] = ELAN_FEATURE_REPORT; 78 + dmabuf[1] = 0x05; 79 + dmabuf[2] = 0x03; 80 + dmabuf[3] = param; 81 + dmabuf[4] = 0x01; 82 + 83 + ret = hid_hw_raw_request(hdev, ELAN_FEATURE_REPORT, dmabuf, 84 + ELAN_FEATURE_SIZE, HID_FEATURE_REPORT, 85 + HID_REQ_SET_REPORT); 86 + if (ret != ELAN_FEATURE_SIZE) { 87 + hid_err(hdev, "Set report error for parm %d: %d\n", param, ret); 88 + return ret; 89 + } 90 + 91 + ret = hid_hw_raw_request(hdev, ELAN_FEATURE_REPORT, dmabuf, 92 + ELAN_FEATURE_SIZE, HID_FEATURE_REPORT, 93 + HID_REQ_GET_REPORT); 94 + if (ret != ELAN_FEATURE_SIZE) { 95 + hid_err(hdev, "Get report error for parm %d: %d\n", param, ret); 96 + return ret; 97 + } 98 + 99 + return 0; 100 + } 101 + 102 + static unsigned int elan_convert_res(char val) 103 + { 104 + /* 105 + * (value from firmware) * 10 + 790 = dpi 106 + * dpi * 10 / 254 = dots/mm 107 + */ 108 + return (val * 10 + 790) * 10 / 254; 109 + } 110 + 111 + static int elan_get_device_params(struct hid_device *hdev) 112 + { 113 + struct elan_drvdata *drvdata = hid_get_drvdata(hdev); 114 + unsigned char *dmabuf; 115 + int ret; 116 + 117 + dmabuf = kmalloc(ELAN_FEATURE_SIZE, GFP_KERNEL); 118 + if (!dmabuf) 119 + return -ENOMEM; 120 + 121 + ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_MAX_X); 122 + if (ret) 123 + goto err; 124 + 125 + drvdata->max_x = (dmabuf[4] << 8) | dmabuf[3]; 126 + 127 + ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_MAX_Y); 128 + if (ret) 129 + goto err; 130 + 131 + drvdata->max_y = (dmabuf[4] << 8) | dmabuf[3]; 132 + 133 + ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_RES); 134 + if (ret) 135 + goto err; 136 + 137 + drvdata->res_x = elan_convert_res(dmabuf[3]); 138 + drvdata->res_y = elan_convert_res(dmabuf[4]); 139 + 140 + err: 141 + kfree(dmabuf); 142 + return ret; 80 143 } 81 144 82 145 static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) ··· 161 76 162 77 if (is_not_elan_touchpad(hdev)) 163 78 return 0; 79 + 80 + ret = elan_get_device_params(hdev); 81 + if (ret) 82 + return ret; 164 83 165 84 input = devm_input_allocate_device(&hdev->dev); 166 85 if (!input) ··· 179 90 input->id.version = hdev->version; 180 91 input->dev.parent = &hdev->dev; 181 92 182 - input_set_abs_params(input, ABS_MT_POSITION_X, 0, 183 - drvdata->settings->max_x, 0, 0); 184 - input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 185 - drvdata->settings->max_y, 0, 0); 186 - input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 187 - drvdata->settings->max_fingers, 0, 0); 188 - input_set_abs_params(input, ABS_TOOL_WIDTH, 0, 189 - drvdata->settings->max_w, 0, 0); 93 + input_set_abs_params(input, ABS_MT_POSITION_X, 0, drvdata->max_x, 94 + 0, 0); 95 + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, drvdata->max_y, 96 + 0, 0); 97 + input_set_abs_params(input, ABS_MT_PRESSURE, 0, ELAN_MAX_PRESSURE, 98 + 0, 0); 190 99 191 100 __set_bit(BTN_LEFT, input->keybit); 192 101 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); 193 102 194 - ret = input_mt_init_slots(input, drvdata->settings->max_fingers, 195 - INPUT_MT_POINTER); 103 + ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER); 196 104 if (ret) { 197 105 hid_err(hdev, "Failed to init elan MT slots: %d\n", ret); 198 106 return ret; 199 107 } 108 + 109 + input_abs_set_res(input, ABS_X, drvdata->res_x); 110 + input_abs_set_res(input, ABS_Y, drvdata->res_y); 200 111 201 112 ret = input_register_device(input); 202 113 if (ret) { ··· 215 126 unsigned int slot_num) 216 127 { 217 128 struct input_dev *input = drvdata->input; 218 - int x, y, w; 129 + int x, y, p; 219 130 220 131 bool active = !!data; 221 132 ··· 223 134 input_mt_report_slot_state(input, MT_TOOL_FINGER, active); 224 135 if (active) { 225 136 x = ((data[0] & 0xF0) << 4) | data[1]; 226 - y = drvdata->settings->max_y - 137 + y = drvdata->max_y - 227 138 (((data[0] & 0x07) << 8) | data[2]); 228 - w = data[4]; 139 + p = data[4]; 229 140 230 141 input_report_abs(input, ABS_MT_POSITION_X, x); 231 142 input_report_abs(input, ABS_MT_POSITION_Y, y); 232 - input_report_abs(input, ABS_TOOL_WIDTH, w); 143 + input_report_abs(input, ABS_MT_PRESSURE, p); 233 144 } 234 145 } 235 146 236 - static void elan_report_input(struct elan_drvdata *drvdata, u8 *data) 147 + static void elan_usb_report_input(struct elan_drvdata *drvdata, u8 *data) 237 148 { 238 149 int i; 239 150 struct input_dev *input = drvdata->input; ··· 251 162 * byte 5: x8 x7 x6 x5 x4 x3 x2 x1 252 163 * byte 6: y8 y7 y6 y5 y4 y3 y2 y1 253 164 * byte 7: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 254 - * byte 8: w8 w7 w6 w5 w4 w3 w2 w1 165 + * byte 8: p8 p7 p6 p5 p4 p3 p2 p1 255 166 * 256 167 * packet structure for ELAN_MT_SECOND_FINGER: 257 168 * ··· 260 171 * byte 3: x8 x7 x6 x5 x4 x3 x2 x1 261 172 * byte 4: y8 y7 y6 y5 y4 y3 y2 y1 262 173 * byte 5: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 263 - * byte 6: w8 w7 w6 w5 w4 w3 w2 w1 174 + * byte 6: p8 p7 p6 p5 p4 p3 p2 p1 264 175 * byte 7: 0 0 0 0 0 0 0 0 265 176 * byte 8: 0 0 0 0 0 0 0 0 266 177 * 267 178 * f5-f1: finger touch bits 268 179 * L: clickpad button 269 - * sy / sx: not sure yet, but this looks like rectangular 270 - * area for finger 271 - * w: looks like finger width 180 + * sy / sx: finger width / height expressed in traces, the total number 181 + * of traces can be queried by doing a HID_REQ_SET_REPORT 182 + * { 0x0d, 0x05, 0x03, 0x05, 0x01 } followed by a GET, in the 183 + * returned buf, buf[3]=no-x-traces, buf[4]=no-y-traces. 184 + * p: pressure 272 185 */ 273 186 274 187 if (data[0] == ELAN_SINGLE_FINGER) { 275 - for (i = 0; i < drvdata->settings->max_fingers; i++) { 188 + for (i = 0; i < ELAN_MAX_FINGERS; i++) { 276 189 if (data[2] & BIT(i + 3)) 277 190 elan_report_mt_slot(drvdata, data + 3, i); 278 191 else ··· 301 210 if (prev_report[0] != ELAN_MT_FIRST_FINGER) 302 211 return; 303 212 304 - for (i = 0; i < drvdata->settings->max_fingers; i++) { 213 + for (i = 0; i < ELAN_MAX_FINGERS; i++) { 305 214 if (prev_report[2] & BIT(i + 3)) { 306 215 if (!first) { 307 216 first = 1; ··· 320 229 input_sync(input); 321 230 } 322 231 232 + static void elan_i2c_report_input(struct elan_drvdata *drvdata, u8 *data) 233 + { 234 + struct input_dev *input = drvdata->input; 235 + u8 *finger_data; 236 + int i; 237 + 238 + /* 239 + * Elan MT touchpads in i2c mode send finger data in the same format 240 + * as in USB mode, but then with all fingers in a single packet. 241 + * 242 + * packet structure for ELAN_MT_I2C: 243 + * 244 + * byte 1: 1 0 0 1 1 1 0 1 // 0x5d 245 + * byte 2: f5 f4 f3 f2 f1 0 0 L 246 + * byte 3: x12 x11 x10 x9 0? y11 y10 y9 247 + * byte 4: x8 x7 x6 x5 x4 x3 x2 x1 248 + * byte 5: y8 y7 y6 y5 y4 y3 y2 y1 249 + * byte 6: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 250 + * byte 7: p8 p7 p6 p5 p4 p3 p2 p1 251 + * byte 8-12: Same as byte 3-7 for second finger down 252 + * byte 13-17: Same as byte 3-7 for third finger down 253 + * byte 18-22: Same as byte 3-7 for fourth finger down 254 + * byte 23-27: Same as byte 3-7 for fifth finger down 255 + */ 256 + 257 + finger_data = data + 2; 258 + for (i = 0; i < ELAN_MAX_FINGERS; i++) { 259 + if (data[1] & BIT(i + 3)) { 260 + elan_report_mt_slot(drvdata, finger_data, i); 261 + finger_data += ELAN_FINGER_DATA_LEN; 262 + } else { 263 + elan_report_mt_slot(drvdata, NULL, i); 264 + } 265 + } 266 + 267 + input_report_key(input, BTN_LEFT, data[1] & 0x01); 268 + input_mt_sync_frame(input); 269 + input_sync(input); 270 + } 271 + 323 272 static int elan_raw_event(struct hid_device *hdev, 324 273 struct hid_report *report, u8 *data, int size) 325 274 { ··· 372 241 data[0] == ELAN_MT_FIRST_FINGER || 373 242 data[0] == ELAN_MT_SECOND_FINGER) { 374 243 if (size == ELAN_INPUT_REPORT_SIZE) { 375 - elan_report_input(drvdata, data); 244 + elan_usb_report_input(drvdata, data); 376 245 return 1; 377 246 } 247 + } 248 + 249 + if (data[0] == ELAN_MT_I2C && size == ELAN_I2C_REPORT_SIZE) { 250 + elan_i2c_report_input(drvdata, data); 251 + return 1; 378 252 } 379 253 380 254 return 0; ··· 479 343 if (!drvdata) 480 344 return -ENOMEM; 481 345 482 - drvdata->settings = (struct elan_touchpad_settings *)id->driver_data; 483 346 hid_set_drvdata(hdev, drvdata); 484 347 485 348 ret = hid_parse(hdev); ··· 506 371 if (ret) 507 372 goto err; 508 373 509 - ret = elan_init_mute_led(hdev); 510 - if (ret) 511 - goto err; 374 + if (id->driver_data & ELAN_HAS_LED) { 375 + ret = elan_init_mute_led(hdev); 376 + if (ret) 377 + goto err; 378 + } 512 379 513 380 return 0; 514 381 err: ··· 523 386 hid_hw_stop(hdev); 524 387 } 525 388 526 - static const struct elan_touchpad_settings hp_x2_10_touchpad_data = { 527 - .max_fingers = 5, 528 - .max_x = 2930, 529 - .max_y = 1250, 530 - .max_area_x = 15, 531 - .max_area_y = 15, 532 - .max_w = 255, 533 - .usb_bInterfaceNumber = 1, 534 - }; 535 - 536 389 static const struct hid_device_id elan_devices[] = { 390 + { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2), 391 + .driver_data = ELAN_HAS_LED }, 537 392 { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2_10_COVER), 538 - (kernel_ulong_t)&hp_x2_10_touchpad_data}, 393 + .driver_data = ELAN_HAS_LED }, 394 + { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_TOSHIBA_CLICK_L9W) }, 539 395 { } 540 396 }; 541 - 542 397 MODULE_DEVICE_TABLE(hid, elan_devices); 543 398 544 399 static struct hid_driver elan_driver = {
+5
drivers/hid/hid-ids.h
··· 369 369 #define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001 0xa001 370 370 371 371 #define USB_VENDOR_ID_ELAN 0x04f3 372 + #define USB_DEVICE_ID_TOSHIBA_CLICK_L9W 0x0401 373 + #define USB_DEVICE_ID_HP_X2 0x074d 372 374 #define USB_DEVICE_ID_HP_X2_10_COVER 0x0755 373 375 374 376 #define USB_VENDOR_ID_ELECOM 0x056e ··· 1002 1000 1003 1001 #define USB_VENDOR_ID_SINO_LITE 0x1345 1004 1002 #define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x3008 1003 + 1004 + #define USB_VENDOR_ID_SOLID_YEAR 0x060b 1005 + #define USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD 0x500a 1005 1006 1006 1007 #define USB_VENDOR_ID_SOUNDGRAPH 0x15c2 1007 1008 #define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034
+3
drivers/hid/hid-input.c
··· 1550 1550 case HID_GD_WIRELESS_RADIO_CTLS: 1551 1551 suffix = "Wireless Radio Control"; 1552 1552 break; 1553 + case HID_GD_SYSTEM_MULTIAXIS: 1554 + suffix = "System Multi Axis"; 1555 + break; 1553 1556 default: 1554 1557 break; 1555 1558 }
+43 -6
drivers/hid/hid-microsoft.c
··· 22 22 23 23 #include "hid-ids.h" 24 24 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 25 + #define MS_HIDINPUT BIT(0) 26 + #define MS_ERGONOMY BIT(1) 27 + #define MS_PRESENTER BIT(2) 28 + #define MS_RDESC BIT(3) 29 + #define MS_NOGET BIT(4) 30 + #define MS_DUPLICATE_USAGES BIT(5) 31 + #define MS_SURFACE_DIAL BIT(6) 31 32 32 33 static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, 33 34 unsigned int *rsize) ··· 131 130 return 1; 132 131 } 133 132 133 + static int ms_surface_dial_quirk(struct hid_input *hi, struct hid_field *field, 134 + struct hid_usage *usage, unsigned long **bit, int *max) 135 + { 136 + switch (usage->hid & HID_USAGE_PAGE) { 137 + case 0xff070000: 138 + /* fall-through */ 139 + case HID_UP_DIGITIZER: 140 + /* ignore those axis */ 141 + return -1; 142 + case HID_UP_GENDESK: 143 + switch (usage->hid) { 144 + case HID_GD_X: 145 + /* fall-through */ 146 + case HID_GD_Y: 147 + /* fall-through */ 148 + case HID_GD_RFKILL_BTN: 149 + /* ignore those axis */ 150 + return -1; 151 + } 152 + } 153 + 154 + return 0; 155 + } 156 + 134 157 static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, 135 158 struct hid_field *field, struct hid_usage *usage, 136 159 unsigned long **bit, int *max) ··· 170 145 if ((quirks & MS_PRESENTER) && 171 146 ms_presenter_8k_quirk(hi, usage, bit, max)) 172 147 return 1; 148 + 149 + if (quirks & MS_SURFACE_DIAL) { 150 + int ret = ms_surface_dial_quirk(hi, field, usage, bit, max); 151 + 152 + if (ret) 153 + return ret; 154 + } 173 155 174 156 return 0; 175 157 } ··· 261 229 if (quirks & MS_NOGET) 262 230 hdev->quirks |= HID_QUIRK_NOGET; 263 231 232 + if (quirks & MS_SURFACE_DIAL) 233 + hdev->quirks |= HID_QUIRK_INPUT_PER_APP; 234 + 264 235 ret = hid_parse(hdev); 265 236 if (ret) { 266 237 hid_err(hdev, "parse failed\n"); ··· 316 281 317 282 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), 318 283 .driver_data = MS_PRESENTER }, 284 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, 0x091B), 285 + .driver_data = MS_SURFACE_DIAL }, 319 286 { } 320 287 }; 321 288 MODULE_DEVICE_TABLE(hid, ms_devices);
+601 -396
drivers/hid/hid-multitouch.c
··· 28 28 */ 29 29 30 30 /* 31 - * This driver is regularly tested thanks to the tool hid-test[1]. 32 - * This tool relies on hid-replay[2] and a database of hid devices[3]. 31 + * This driver is regularly tested thanks to the test suite in hid-tools[1]. 33 32 * Please run these regression tests before patching this module so that 34 33 * your patch won't break existing known devices. 35 34 * 36 - * [1] https://github.com/bentiss/hid-test 37 - * [2] https://github.com/bentiss/hid-replay 38 - * [3] https://github.com/bentiss/hid-devices 35 + * [1] https://gitlab.freedesktop.org/libevdev/hid-tools 39 36 */ 40 37 41 38 #include <linux/device.h> ··· 87 90 #define MT_IO_FLAGS_ACTIVE_SLOTS 1 88 91 #define MT_IO_FLAGS_PENDING_SLOTS 2 89 92 90 - struct mt_slot { 91 - __s32 x, y, cx, cy, p, w, h, a; 92 - __s32 contactid; /* the device ContactID assigned to this slot */ 93 - bool touch_state; /* is the touch valid? */ 94 - bool inrange_state; /* is the finger in proximity of the sensor? */ 95 - bool confidence_state; /* is the touch made by a finger? */ 96 - bool has_azimuth; /* the contact reports azimuth */ 93 + static const bool mtrue = true; /* default for true */ 94 + static const bool mfalse; /* default for false */ 95 + static const __s32 mzero; /* default for 0 */ 96 + 97 + #define DEFAULT_TRUE ((void *)&mtrue) 98 + #define DEFAULT_FALSE ((void *)&mfalse) 99 + #define DEFAULT_ZERO ((void *)&mzero) 100 + 101 + struct mt_usages { 102 + struct list_head list; 103 + __s32 *x, *y, *cx, *cy, *p, *w, *h, *a; 104 + __s32 *contactid; /* the device ContactID assigned to this slot */ 105 + bool *tip_state; /* is the touch valid? */ 106 + bool *inrange_state; /* is the finger in proximity of the sensor? */ 107 + bool *confidence_state; /* is the touch made by a finger? */ 108 + }; 109 + 110 + struct mt_application { 111 + struct list_head list; 112 + unsigned int application; 113 + struct list_head mt_usages; /* mt usages list */ 114 + 115 + __s32 quirks; 116 + 117 + __s32 *scantime; /* scantime reported */ 118 + __s32 scantime_logical_max; /* max value for raw scantime */ 119 + 120 + __s32 *raw_cc; /* contact count in the report */ 121 + int left_button_state; /* left button state */ 122 + unsigned int mt_flags; /* flags to pass to input-mt */ 123 + 124 + unsigned long *pending_palm_slots; /* slots where we reported palm 125 + * and need to release */ 126 + 127 + __u8 num_received; /* how many contacts we received */ 128 + __u8 num_expected; /* expected last contact index */ 129 + __u8 buttons_count; /* number of physical buttons per touchpad */ 130 + __u8 touches_by_report; /* how many touches are present in one report: 131 + * 1 means we should use a serial protocol 132 + * > 1 means hybrid (multitouch) protocol 133 + */ 134 + 135 + __s32 dev_time; /* the scan time provided by the device */ 136 + unsigned long jiffies; /* the frame's jiffies */ 137 + int timestamp; /* the timestamp to be sent */ 138 + int prev_scantime; /* scantime reported previously */ 139 + 140 + bool have_contact_count; 97 141 }; 98 142 99 143 struct mt_class { ··· 149 111 bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ 150 112 }; 151 113 152 - struct mt_fields { 153 - unsigned usages[HID_MAX_FIELDS]; 154 - unsigned int length; 114 + struct mt_report_data { 115 + struct list_head list; 116 + struct hid_report *report; 117 + struct mt_application *application; 118 + bool is_mt_collection; 155 119 }; 156 120 157 121 struct mt_device { 158 - struct mt_slot curdata; /* placeholder of incoming data */ 159 122 struct mt_class mtclass; /* our mt device class */ 160 123 struct timer_list release_timer; /* to release sticky fingers */ 161 124 struct hid_device *hdev; /* hid_device we're attached to */ 162 - struct mt_fields *fields; /* temporary placeholder for storing the 163 - multitouch fields */ 164 125 unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ 165 - int cc_index; /* contact count field index in the report */ 166 - int cc_value_index; /* contact count value index in the field */ 167 - int scantime_index; /* scantime field index in the report */ 168 - int scantime_val_index; /* scantime value index in the field */ 169 - int prev_scantime; /* scantime reported in the previous packet */ 170 - int left_button_state; /* left button state */ 171 - unsigned last_slot_field; /* the last field of a slot */ 172 - unsigned mt_report_id; /* the report ID of the multitouch device */ 173 126 __u8 inputmode_value; /* InputMode HID feature value */ 174 - __u8 num_received; /* how many contacts we received */ 175 - __u8 num_expected; /* expected last contact index */ 176 127 __u8 maxcontacts; 177 - __u8 touches_by_report; /* how many touches are present in one report: 178 - * 1 means we should use a serial protocol 179 - * > 1 means hybrid (multitouch) protocol */ 180 - __u8 buttons_count; /* number of physical buttons per touchpad */ 181 128 bool is_buttonpad; /* is this device a button pad? */ 182 129 bool serial_maybe; /* need to check for serial protocol */ 183 - bool curvalid; /* is the current contact valid? */ 184 - unsigned mt_flags; /* flags to pass to input-mt */ 185 - __s32 dev_time; /* the scan time provided by the device */ 186 - unsigned long jiffies; /* the frame's jiffies */ 187 - int timestamp; /* the timestamp to be sent */ 130 + 131 + struct list_head applications; 132 + struct list_head reports; 188 133 }; 189 134 190 - static void mt_post_parse_default_settings(struct mt_device *td); 191 - static void mt_post_parse(struct mt_device *td); 135 + static void mt_post_parse_default_settings(struct mt_device *td, 136 + struct mt_application *app); 137 + static void mt_post_parse(struct mt_device *td, struct mt_application *app); 192 138 193 139 /* classes of device behavior */ 194 140 #define MT_CLS_DEFAULT 0x0001 ··· 225 203 * to a valid contact that was just read. 226 204 */ 227 205 228 - static int cypress_compute_slot(struct mt_device *td) 206 + static int cypress_compute_slot(struct mt_application *application, 207 + struct mt_usages *slot) 229 208 { 230 - if (td->curdata.contactid != 0 || td->num_received == 0) 231 - return td->curdata.contactid; 209 + if (*slot->contactid != 0 || application->num_received == 0) 210 + return *slot->contactid; 232 211 else 233 212 return -1; 234 213 } 235 214 236 - static struct mt_class mt_classes[] = { 215 + static const struct mt_class mt_classes[] = { 237 216 { .name = MT_CLS_DEFAULT, 238 217 .quirks = MT_QUIRK_ALWAYS_VALID | 239 218 MT_QUIRK_CONTACT_CNT_ACCURATE }, ··· 376 353 { 377 354 struct hid_device *hdev = to_hid_device(dev); 378 355 struct mt_device *td = hid_get_drvdata(hdev); 356 + struct mt_application *application; 379 357 380 358 unsigned long val; 381 359 ··· 385 361 386 362 td->mtclass.quirks = val; 387 363 388 - if (td->cc_index < 0) 389 - td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 364 + list_for_each_entry(application, &td->applications, list) { 365 + application->quirks = val; 366 + if (!application->have_contact_count) 367 + application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 368 + } 390 369 391 370 return count; 392 371 } ··· 484 457 input_abs_set_res(input, code, hidinput_calc_abs_res(field, code)); 485 458 } 486 459 487 - static void mt_store_field(struct hid_usage *usage, struct mt_device *td, 488 - struct hid_input *hi) 460 + static struct mt_usages *mt_allocate_usage(struct hid_device *hdev, 461 + struct mt_application *application) 489 462 { 490 - struct mt_fields *f = td->fields; 463 + struct mt_usages *usage; 491 464 492 - if (f->length >= HID_MAX_FIELDS) 465 + usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL); 466 + if (!usage) 467 + return NULL; 468 + 469 + /* set some defaults so we do not need to check for null pointers */ 470 + usage->x = DEFAULT_ZERO; 471 + usage->y = DEFAULT_ZERO; 472 + usage->cx = DEFAULT_ZERO; 473 + usage->cy = DEFAULT_ZERO; 474 + usage->p = DEFAULT_ZERO; 475 + usage->w = DEFAULT_ZERO; 476 + usage->h = DEFAULT_ZERO; 477 + usage->a = DEFAULT_ZERO; 478 + usage->contactid = DEFAULT_ZERO; 479 + usage->tip_state = DEFAULT_FALSE; 480 + usage->inrange_state = DEFAULT_FALSE; 481 + usage->confidence_state = DEFAULT_TRUE; 482 + 483 + list_add_tail(&usage->list, &application->mt_usages); 484 + 485 + return usage; 486 + } 487 + 488 + static struct mt_application *mt_allocate_application(struct mt_device *td, 489 + unsigned int application) 490 + { 491 + struct mt_application *mt_application; 492 + 493 + mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application), 494 + GFP_KERNEL); 495 + if (!mt_application) 496 + return NULL; 497 + 498 + mt_application->application = application; 499 + INIT_LIST_HEAD(&mt_application->mt_usages); 500 + 501 + if (application == HID_DG_TOUCHSCREEN) 502 + mt_application->mt_flags |= INPUT_MT_DIRECT; 503 + 504 + /* 505 + * Model touchscreens providing buttons as touchpads. 506 + */ 507 + if (application == HID_DG_TOUCHPAD) { 508 + mt_application->mt_flags |= INPUT_MT_POINTER; 509 + td->inputmode_value = MT_INPUTMODE_TOUCHPAD; 510 + } 511 + 512 + mt_application->scantime = DEFAULT_ZERO; 513 + mt_application->raw_cc = DEFAULT_ZERO; 514 + mt_application->quirks = td->mtclass.quirks; 515 + 516 + list_add_tail(&mt_application->list, &td->applications); 517 + 518 + return mt_application; 519 + } 520 + 521 + static struct mt_application *mt_find_application(struct mt_device *td, 522 + unsigned int application) 523 + { 524 + struct mt_application *tmp, *mt_application = NULL; 525 + 526 + list_for_each_entry(tmp, &td->applications, list) { 527 + if (application == tmp->application) { 528 + mt_application = tmp; 529 + break; 530 + } 531 + } 532 + 533 + if (!mt_application) 534 + mt_application = mt_allocate_application(td, application); 535 + 536 + return mt_application; 537 + } 538 + 539 + static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, 540 + struct hid_report *report) 541 + { 542 + struct mt_report_data *rdata; 543 + struct hid_field *field; 544 + int r, n; 545 + 546 + rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL); 547 + if (!rdata) 548 + return NULL; 549 + 550 + rdata->report = report; 551 + rdata->application = mt_find_application(td, report->application); 552 + 553 + if (!rdata->application) { 554 + devm_kfree(&td->hdev->dev, rdata); 555 + return NULL; 556 + } 557 + 558 + for (r = 0; r < report->maxfield; r++) { 559 + field = report->field[r]; 560 + 561 + if (!(HID_MAIN_ITEM_VARIABLE & field->flags)) 562 + continue; 563 + 564 + for (n = 0; n < field->report_count; n++) { 565 + if (field->usage[n].hid == HID_DG_CONTACTID) 566 + rdata->is_mt_collection = true; 567 + } 568 + } 569 + 570 + list_add_tail(&rdata->list, &td->reports); 571 + 572 + return rdata; 573 + } 574 + 575 + static struct mt_report_data *mt_find_report_data(struct mt_device *td, 576 + struct hid_report *report) 577 + { 578 + struct mt_report_data *tmp, *rdata = NULL; 579 + 580 + list_for_each_entry(tmp, &td->reports, list) { 581 + if (report == tmp->report) { 582 + rdata = tmp; 583 + break; 584 + } 585 + } 586 + 587 + if (!rdata) 588 + rdata = mt_allocate_report_data(td, report); 589 + 590 + return rdata; 591 + } 592 + 593 + static void mt_store_field(struct hid_device *hdev, 594 + struct mt_application *application, 595 + __s32 *value, 596 + size_t offset) 597 + { 598 + struct mt_usages *usage; 599 + __s32 **target; 600 + 601 + if (list_empty(&application->mt_usages)) 602 + usage = mt_allocate_usage(hdev, application); 603 + else 604 + usage = list_last_entry(&application->mt_usages, 605 + struct mt_usages, 606 + list); 607 + 608 + if (!usage) 493 609 return; 494 610 495 - f->usages[f->length++] = usage->hid; 611 + target = (__s32 **)((char *)usage + offset); 612 + 613 + /* the value has already been filled, create a new slot */ 614 + if (*target != DEFAULT_TRUE && 615 + *target != DEFAULT_FALSE && 616 + *target != DEFAULT_ZERO) { 617 + usage = mt_allocate_usage(hdev, application); 618 + if (!usage) 619 + return; 620 + 621 + target = (__s32 **)((char *)usage + offset); 622 + } 623 + 624 + *target = value; 496 625 } 626 + 627 + #define MT_STORE_FIELD(__name) \ 628 + mt_store_field(hdev, app, \ 629 + &field->value[usage->usage_index], \ 630 + offsetof(struct mt_usages, __name)) 497 631 498 632 static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, 499 633 struct hid_field *field, struct hid_usage *usage, 500 - unsigned long **bit, int *max) 634 + unsigned long **bit, int *max, struct mt_application *app) 501 635 { 502 636 struct mt_device *td = hid_get_drvdata(hdev); 503 637 struct mt_class *cls = &td->mtclass; 504 638 int code; 505 639 struct hid_usage *prev_usage = NULL; 506 640 507 - if (field->application == HID_DG_TOUCHSCREEN) 508 - td->mt_flags |= INPUT_MT_DIRECT; 509 - 510 641 /* 511 642 * Model touchscreens providing buttons as touchpads. 512 643 */ 513 - if (field->application == HID_DG_TOUCHPAD || 644 + if (field->application == HID_DG_TOUCHSCREEN && 514 645 (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { 515 - td->mt_flags |= INPUT_MT_POINTER; 646 + app->mt_flags |= INPUT_MT_POINTER; 516 647 td->inputmode_value = MT_INPUTMODE_TOUCHPAD; 517 648 } 518 649 519 650 /* count the buttons on touchpads */ 520 651 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) 521 - td->buttons_count++; 652 + app->buttons_count++; 522 653 523 654 if (usage->usage_index) 524 655 prev_usage = &field->usage[usage->usage_index - 1]; ··· 687 502 switch (usage->hid) { 688 503 case HID_GD_X: 689 504 if (prev_usage && (prev_usage->hid == usage->hid)) { 690 - hid_map_usage(hi, usage, bit, max, 691 - EV_ABS, ABS_MT_TOOL_X); 692 - set_abs(hi->input, ABS_MT_TOOL_X, field, 693 - cls->sn_move); 505 + code = ABS_MT_TOOL_X; 506 + MT_STORE_FIELD(cx); 694 507 } else { 695 - hid_map_usage(hi, usage, bit, max, 696 - EV_ABS, ABS_MT_POSITION_X); 697 - set_abs(hi->input, ABS_MT_POSITION_X, field, 698 - cls->sn_move); 508 + code = ABS_MT_POSITION_X; 509 + MT_STORE_FIELD(x); 699 510 } 700 511 701 - mt_store_field(usage, td, hi); 512 + set_abs(hi->input, code, field, cls->sn_move); 513 + 514 + /* 515 + * A system multi-axis that exports X and Y has a high 516 + * chance of being used directly on a surface 517 + */ 518 + if (field->application == HID_GD_SYSTEM_MULTIAXIS) { 519 + __set_bit(INPUT_PROP_DIRECT, 520 + hi->input->propbit); 521 + input_set_abs_params(hi->input, 522 + ABS_MT_TOOL_TYPE, 523 + MT_TOOL_DIAL, 524 + MT_TOOL_DIAL, 0, 0); 525 + } 526 + 702 527 return 1; 703 528 case HID_GD_Y: 704 529 if (prev_usage && (prev_usage->hid == usage->hid)) { 705 - hid_map_usage(hi, usage, bit, max, 706 - EV_ABS, ABS_MT_TOOL_Y); 707 - set_abs(hi->input, ABS_MT_TOOL_Y, field, 708 - cls->sn_move); 530 + code = ABS_MT_TOOL_Y; 531 + MT_STORE_FIELD(cy); 709 532 } else { 710 - hid_map_usage(hi, usage, bit, max, 711 - EV_ABS, ABS_MT_POSITION_Y); 712 - set_abs(hi->input, ABS_MT_POSITION_Y, field, 713 - cls->sn_move); 533 + code = ABS_MT_POSITION_Y; 534 + MT_STORE_FIELD(y); 714 535 } 715 536 716 - mt_store_field(usage, td, hi); 537 + set_abs(hi->input, code, field, cls->sn_move); 538 + 717 539 return 1; 718 540 } 719 541 return 0; ··· 728 536 case HID_UP_DIGITIZER: 729 537 switch (usage->hid) { 730 538 case HID_DG_INRANGE: 731 - if (cls->quirks & MT_QUIRK_HOVERING) { 732 - hid_map_usage(hi, usage, bit, max, 733 - EV_ABS, ABS_MT_DISTANCE); 539 + if (app->quirks & MT_QUIRK_HOVERING) { 734 540 input_set_abs_params(hi->input, 735 541 ABS_MT_DISTANCE, 0, 1, 0, 0); 736 542 } 737 - mt_store_field(usage, td, hi); 543 + MT_STORE_FIELD(inrange_state); 738 544 return 1; 739 545 case HID_DG_CONFIDENCE: 740 546 if ((cls->name == MT_CLS_WIN_8 || 741 547 cls->name == MT_CLS_WIN_8_DUAL) && 742 - field->application == HID_DG_TOUCHPAD) 743 - cls->quirks |= MT_QUIRK_CONFIDENCE; 744 - mt_store_field(usage, td, hi); 548 + (field->application == HID_DG_TOUCHPAD || 549 + field->application == HID_DG_TOUCHSCREEN)) 550 + app->quirks |= MT_QUIRK_CONFIDENCE; 551 + 552 + if (app->quirks & MT_QUIRK_CONFIDENCE) 553 + input_set_abs_params(hi->input, 554 + ABS_MT_TOOL_TYPE, 555 + MT_TOOL_FINGER, 556 + MT_TOOL_PALM, 0, 0); 557 + 558 + MT_STORE_FIELD(confidence_state); 745 559 return 1; 746 560 case HID_DG_TIPSWITCH: 747 - hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); 748 - input_set_capability(hi->input, EV_KEY, BTN_TOUCH); 749 - mt_store_field(usage, td, hi); 561 + if (field->application != HID_GD_SYSTEM_MULTIAXIS) 562 + input_set_capability(hi->input, 563 + EV_KEY, BTN_TOUCH); 564 + MT_STORE_FIELD(tip_state); 750 565 return 1; 751 566 case HID_DG_CONTACTID: 752 - mt_store_field(usage, td, hi); 753 - td->touches_by_report++; 754 - td->mt_report_id = field->report->id; 567 + MT_STORE_FIELD(contactid); 568 + app->touches_by_report++; 755 569 return 1; 756 570 case HID_DG_WIDTH: 757 - hid_map_usage(hi, usage, bit, max, 758 - EV_ABS, ABS_MT_TOUCH_MAJOR); 759 - if (!(cls->quirks & MT_QUIRK_NO_AREA)) 571 + if (!(app->quirks & MT_QUIRK_NO_AREA)) 760 572 set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, 761 573 cls->sn_width); 762 - mt_store_field(usage, td, hi); 574 + MT_STORE_FIELD(w); 763 575 return 1; 764 576 case HID_DG_HEIGHT: 765 - hid_map_usage(hi, usage, bit, max, 766 - EV_ABS, ABS_MT_TOUCH_MINOR); 767 - if (!(cls->quirks & MT_QUIRK_NO_AREA)) { 577 + if (!(app->quirks & MT_QUIRK_NO_AREA)) { 768 578 set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, 769 579 cls->sn_height); 770 580 ··· 779 585 input_set_abs_params(hi->input, 780 586 ABS_MT_ORIENTATION, 0, 1, 0, 0); 781 587 } 782 - mt_store_field(usage, td, hi); 588 + MT_STORE_FIELD(h); 783 589 return 1; 784 590 case HID_DG_TIPPRESSURE: 785 - hid_map_usage(hi, usage, bit, max, 786 - EV_ABS, ABS_MT_PRESSURE); 787 591 set_abs(hi->input, ABS_MT_PRESSURE, field, 788 592 cls->sn_pressure); 789 - mt_store_field(usage, td, hi); 593 + MT_STORE_FIELD(p); 790 594 return 1; 791 595 case HID_DG_SCANTIME: 792 - hid_map_usage(hi, usage, bit, max, 793 - EV_MSC, MSC_TIMESTAMP); 794 596 input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); 795 - /* Ignore if indexes are out of bounds. */ 796 - if (field->index >= field->report->maxfield || 797 - usage->usage_index >= field->report_count) 798 - return 1; 799 - td->scantime_index = field->index; 800 - td->scantime_val_index = usage->usage_index; 801 - /* 802 - * We don't set td->last_slot_field as scan time is 803 - * global to the report. 804 - */ 597 + app->scantime = &field->value[usage->usage_index]; 598 + app->scantime_logical_max = field->logical_maximum; 805 599 return 1; 806 600 case HID_DG_CONTACTCOUNT: 807 - /* Ignore if indexes are out of bounds. */ 808 - if (field->index >= field->report->maxfield || 809 - usage->usage_index >= field->report_count) 810 - return 1; 811 - td->cc_index = field->index; 812 - td->cc_value_index = usage->usage_index; 601 + app->have_contact_count = true; 602 + app->raw_cc = &field->value[usage->usage_index]; 813 603 return 1; 814 604 case HID_DG_AZIMUTH: 815 - hid_map_usage(hi, usage, bit, max, 816 - EV_ABS, ABS_MT_ORIENTATION); 817 605 /* 818 606 * Azimuth has the range of [0, MAX) representing a full 819 607 * revolution. Set ABS_MT_ORIENTATION to a quarter of ··· 806 630 field->logical_maximum / 4, 807 631 cls->sn_move ? 808 632 field->logical_maximum / cls->sn_move : 0, 0); 809 - mt_store_field(usage, td, hi); 633 + MT_STORE_FIELD(a); 810 634 return 1; 811 635 case HID_DG_CONTACTMAX: 812 - /* we don't set td->last_slot_field as contactcount and 813 - * contact max are global to the report */ 636 + /* contact max are global to the report */ 814 637 return -1; 815 638 case HID_DG_TOUCH: 816 639 /* Legacy devices use TIPSWITCH and not TOUCH. ··· 825 650 * MS PTP spec says that external buttons left and right have 826 651 * usages 2 and 3. 827 652 */ 828 - if ((cls->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 653 + if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 829 654 field->application == HID_DG_TOUCHPAD && 830 655 (usage->hid & HID_USAGE) > 1) 831 656 code--; 657 + 658 + if (field->application == HID_GD_SYSTEM_MULTIAXIS) 659 + code = BTN_0 + ((usage->hid - 1) & HID_USAGE); 660 + 832 661 hid_map_usage(hi, usage, bit, max, EV_KEY, code); 833 662 input_set_capability(hi->input, EV_KEY, code); 834 663 return 1; ··· 845 666 return 0; 846 667 } 847 668 848 - static int mt_compute_slot(struct mt_device *td, struct input_dev *input) 669 + static int mt_compute_slot(struct mt_device *td, struct mt_application *app, 670 + struct mt_usages *slot, 671 + struct input_dev *input) 849 672 { 850 - __s32 quirks = td->mtclass.quirks; 673 + __s32 quirks = app->quirks; 851 674 852 675 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) 853 - return td->curdata.contactid; 676 + return *slot->contactid; 854 677 855 678 if (quirks & MT_QUIRK_CYPRESS) 856 - return cypress_compute_slot(td); 679 + return cypress_compute_slot(app, slot); 857 680 858 681 if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) 859 - return td->num_received; 682 + return app->num_received; 860 683 861 684 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) 862 - return td->curdata.contactid - 1; 685 + return *slot->contactid - 1; 863 686 864 - return input_mt_get_slot_by_key(input, td->curdata.contactid); 687 + return input_mt_get_slot_by_key(input, *slot->contactid); 865 688 } 866 689 867 - /* 868 - * this function is called when a whole contact has been processed, 869 - * so that it can assign it to a slot and store the data there 870 - */ 871 - static void mt_complete_slot(struct mt_device *td, struct input_dev *input) 690 + static void mt_release_pending_palms(struct mt_device *td, 691 + struct mt_application *app, 692 + struct input_dev *input) 872 693 { 873 - if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && 874 - td->num_received >= td->num_expected) 875 - return; 694 + int slotnum; 695 + bool need_sync = false; 876 696 877 - if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) { 878 - int active; 879 - int slotnum = mt_compute_slot(td, input); 880 - struct mt_slot *s = &td->curdata; 881 - struct input_mt *mt = input->mt; 882 - 883 - if (slotnum < 0 || slotnum >= td->maxcontacts) 884 - return; 885 - 886 - if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { 887 - struct input_mt_slot *slot = &mt->slots[slotnum]; 888 - if (input_mt_is_active(slot) && 889 - input_mt_is_used(mt, slot)) 890 - return; 891 - } 892 - 893 - if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE)) 894 - s->confidence_state = true; 895 - active = (s->touch_state || s->inrange_state) && 896 - s->confidence_state; 697 + for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) { 698 + clear_bit(slotnum, app->pending_palm_slots); 897 699 898 700 input_mt_slot(input, slotnum); 899 - input_mt_report_slot_state(input, MT_TOOL_FINGER, active); 900 - if (active) { 901 - /* this finger is in proximity of the sensor */ 902 - int wide = (s->w > s->h); 903 - int major = max(s->w, s->h); 904 - int minor = min(s->w, s->h); 905 - int orientation = wide; 701 + input_mt_report_slot_state(input, MT_TOOL_PALM, false); 906 702 907 - if (s->has_azimuth) 908 - orientation = s->a; 909 - 910 - /* 911 - * divided by two to match visual scale of touch 912 - * for devices with this quirk 913 - */ 914 - if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { 915 - major = major >> 1; 916 - minor = minor >> 1; 917 - } 918 - 919 - input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); 920 - input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); 921 - input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx); 922 - input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy); 923 - input_event(input, EV_ABS, ABS_MT_DISTANCE, 924 - !s->touch_state); 925 - input_event(input, EV_ABS, ABS_MT_ORIENTATION, 926 - orientation); 927 - input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); 928 - input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); 929 - input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); 930 - 931 - set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); 932 - } 703 + need_sync = true; 933 704 } 934 705 935 - td->num_received++; 706 + if (need_sync) { 707 + input_mt_sync_frame(input); 708 + input_sync(input); 709 + } 936 710 } 937 711 938 712 /* 939 713 * this function is called when a whole packet has been received and processed, 940 714 * so that it can decide what to send to the input layer. 941 715 */ 942 - static void mt_sync_frame(struct mt_device *td, struct input_dev *input) 716 + static void mt_sync_frame(struct mt_device *td, struct mt_application *app, 717 + struct input_dev *input) 943 718 { 944 - if (td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) 945 - input_event(input, EV_KEY, BTN_LEFT, td->left_button_state); 719 + if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) 720 + input_event(input, EV_KEY, BTN_LEFT, app->left_button_state); 946 721 947 722 input_mt_sync_frame(input); 948 - input_event(input, EV_MSC, MSC_TIMESTAMP, td->timestamp); 723 + input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp); 949 724 input_sync(input); 950 - td->num_received = 0; 951 - td->left_button_state = 0; 725 + 726 + mt_release_pending_palms(td, app, input); 727 + 728 + app->num_received = 0; 729 + app->left_button_state = 0; 730 + 952 731 if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) 953 732 set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); 954 733 else ··· 914 777 clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); 915 778 } 916 779 917 - static int mt_compute_timestamp(struct mt_device *td, struct hid_field *field, 918 - __s32 value) 780 + static int mt_compute_timestamp(struct mt_application *app, __s32 value) 919 781 { 920 - long delta = value - td->dev_time; 921 - unsigned long jdelta = jiffies_to_usecs(jiffies - td->jiffies); 782 + long delta = value - app->prev_scantime; 783 + unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies); 922 784 923 - td->jiffies = jiffies; 924 - td->dev_time = value; 785 + app->jiffies = jiffies; 925 786 926 787 if (delta < 0) 927 - delta += field->logical_maximum; 788 + delta += app->scantime_logical_max; 928 789 929 790 /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */ 930 791 delta *= 100; ··· 931 796 /* No data received for a while, resync the timestamp. */ 932 797 return 0; 933 798 else 934 - return td->timestamp + delta; 799 + return app->timestamp + delta; 935 800 } 936 801 937 802 static int mt_touch_event(struct hid_device *hid, struct hid_field *field, ··· 944 809 return 1; 945 810 } 946 811 947 - static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, 948 - struct hid_usage *usage, __s32 value, 949 - bool first_packet) 812 + static int mt_process_slot(struct mt_device *td, struct input_dev *input, 813 + struct mt_application *app, 814 + struct mt_usages *slot) 950 815 { 951 - struct mt_device *td = hid_get_drvdata(hid); 952 - __s32 quirks = td->mtclass.quirks; 953 - struct input_dev *input = field->hidinput->input; 816 + struct input_mt *mt = input->mt; 817 + __s32 quirks = app->quirks; 818 + bool valid = true; 819 + bool confidence_state = true; 820 + bool inrange_state = false; 821 + int active; 822 + int slotnum; 823 + int tool = MT_TOOL_FINGER; 954 824 955 - if (hid->claimed & HID_CLAIMED_INPUT) { 956 - switch (usage->hid) { 957 - case HID_DG_INRANGE: 958 - if (quirks & MT_QUIRK_VALID_IS_INRANGE) 959 - td->curvalid = value; 960 - if (quirks & MT_QUIRK_HOVERING) 961 - td->curdata.inrange_state = value; 962 - break; 963 - case HID_DG_TIPSWITCH: 964 - if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 965 - td->curvalid = value; 966 - td->curdata.touch_state = value; 967 - break; 968 - case HID_DG_CONFIDENCE: 969 - if (quirks & MT_QUIRK_CONFIDENCE) 970 - td->curdata.confidence_state = value; 971 - if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) 972 - td->curvalid = value; 973 - break; 974 - case HID_DG_CONTACTID: 975 - td->curdata.contactid = value; 976 - break; 977 - case HID_DG_TIPPRESSURE: 978 - td->curdata.p = value; 979 - break; 980 - case HID_GD_X: 981 - if (usage->code == ABS_MT_TOOL_X) 982 - td->curdata.cx = value; 983 - else 984 - td->curdata.x = value; 985 - break; 986 - case HID_GD_Y: 987 - if (usage->code == ABS_MT_TOOL_Y) 988 - td->curdata.cy = value; 989 - else 990 - td->curdata.y = value; 991 - break; 992 - case HID_DG_WIDTH: 993 - td->curdata.w = value; 994 - break; 995 - case HID_DG_HEIGHT: 996 - td->curdata.h = value; 997 - break; 998 - case HID_DG_SCANTIME: 999 - td->timestamp = mt_compute_timestamp(td, field, value); 1000 - break; 1001 - case HID_DG_CONTACTCOUNT: 1002 - break; 1003 - case HID_DG_AZIMUTH: 825 + if (!slot) 826 + return -EINVAL; 827 + 828 + if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && 829 + app->num_received >= app->num_expected) 830 + return -EAGAIN; 831 + 832 + if (!(quirks & MT_QUIRK_ALWAYS_VALID)) { 833 + if (quirks & MT_QUIRK_VALID_IS_INRANGE) 834 + valid = *slot->inrange_state; 835 + if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 836 + valid = *slot->tip_state; 837 + if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) 838 + valid = *slot->confidence_state; 839 + 840 + if (!valid) 841 + return 0; 842 + } 843 + 844 + slotnum = mt_compute_slot(td, app, slot, input); 845 + if (slotnum < 0 || slotnum >= td->maxcontacts) 846 + return 0; 847 + 848 + if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { 849 + struct input_mt_slot *i_slot = &mt->slots[slotnum]; 850 + 851 + if (input_mt_is_active(i_slot) && 852 + input_mt_is_used(mt, i_slot)) 853 + return -EAGAIN; 854 + } 855 + 856 + if (quirks & MT_QUIRK_CONFIDENCE) 857 + confidence_state = *slot->confidence_state; 858 + 859 + if (quirks & MT_QUIRK_HOVERING) 860 + inrange_state = *slot->inrange_state; 861 + 862 + active = *slot->tip_state || inrange_state; 863 + 864 + if (app->application == HID_GD_SYSTEM_MULTIAXIS) 865 + tool = MT_TOOL_DIAL; 866 + else if (unlikely(!confidence_state)) { 867 + tool = MT_TOOL_PALM; 868 + if (!active && 869 + input_mt_is_active(&mt->slots[slotnum])) { 870 + /* 871 + * The non-confidence was reported for 872 + * previously valid contact that is also no 873 + * longer valid. We can't simply report 874 + * lift-off as userspace will not be aware 875 + * of non-confidence, so we need to split 876 + * it into 2 events: active MT_TOOL_PALM 877 + * and a separate liftoff. 878 + */ 879 + active = true; 880 + set_bit(slotnum, app->pending_palm_slots); 881 + } 882 + } 883 + 884 + input_mt_slot(input, slotnum); 885 + input_mt_report_slot_state(input, tool, active); 886 + if (active) { 887 + /* this finger is in proximity of the sensor */ 888 + int wide = (*slot->w > *slot->h); 889 + int major = max(*slot->w, *slot->h); 890 + int minor = min(*slot->w, *slot->h); 891 + int orientation = wide; 892 + int max_azimuth; 893 + int azimuth; 894 + 895 + if (slot->a != DEFAULT_ZERO) { 1004 896 /* 1005 897 * Azimuth is counter-clockwise and ranges from [0, MAX) 1006 898 * (a full revolution). Convert it to clockwise ranging ··· 1038 876 * out of range to [-MAX/2, MAX/2] to report an upside 1039 877 * down ellipsis. 1040 878 */ 1041 - if (value > field->logical_maximum / 2) 1042 - value -= field->logical_maximum; 1043 - td->curdata.a = -value; 1044 - td->curdata.has_azimuth = true; 1045 - break; 1046 - case HID_DG_TOUCH: 1047 - /* do nothing */ 1048 - break; 1049 - 1050 - default: 1051 - /* 1052 - * For Win8 PTP touchpads we should only look at 1053 - * non finger/touch events in the first_packet of 1054 - * a (possible) multi-packet frame. 1055 - */ 1056 - if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 1057 - !first_packet) 1058 - return; 1059 - 1060 - /* 1061 - * For Win8 PTP touchpads we map both the clickpad click 1062 - * and any "external" left buttons to BTN_LEFT if a 1063 - * device claims to have both we need to report 1 for 1064 - * BTN_LEFT if either is pressed, so we or all values 1065 - * together and report the result in mt_sync_frame(). 1066 - */ 1067 - if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 1068 - usage->type == EV_KEY && usage->code == BTN_LEFT) { 1069 - td->left_button_state |= value; 1070 - return; 1071 - } 1072 - 1073 - if (usage->type) 1074 - input_event(input, usage->type, usage->code, 1075 - value); 1076 - return; 879 + azimuth = *slot->a; 880 + max_azimuth = input_abs_get_max(input, 881 + ABS_MT_ORIENTATION); 882 + if (azimuth > max_azimuth * 2) 883 + azimuth -= max_azimuth * 4; 884 + orientation = -azimuth; 1077 885 } 1078 886 1079 - if (usage->usage_index + 1 == field->report_count) { 1080 - /* we only take into account the last report. */ 1081 - if (usage->hid == td->last_slot_field) 1082 - mt_complete_slot(td, field->hidinput->input); 887 + if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { 888 + /* 889 + * divided by two to match visual scale of touch 890 + * for devices with this quirk 891 + */ 892 + major = major >> 1; 893 + minor = minor >> 1; 1083 894 } 1084 895 896 + input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); 897 + input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); 898 + input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); 899 + input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); 900 + input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); 901 + input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); 902 + input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); 903 + input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); 904 + input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); 905 + 906 + set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); 1085 907 } 908 + 909 + return 0; 1086 910 } 1087 911 1088 - static void mt_touch_report(struct hid_device *hid, struct hid_report *report) 912 + static void mt_process_mt_event(struct hid_device *hid, 913 + struct mt_application *app, 914 + struct hid_field *field, 915 + struct hid_usage *usage, 916 + __s32 value, 917 + bool first_packet) 918 + { 919 + __s32 quirks = app->quirks; 920 + struct input_dev *input = field->hidinput->input; 921 + 922 + if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT)) 923 + return; 924 + 925 + if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) { 926 + 927 + /* 928 + * For Win8 PTP touchpads we should only look at 929 + * non finger/touch events in the first_packet of a 930 + * (possible) multi-packet frame. 931 + */ 932 + if (!first_packet) 933 + return; 934 + 935 + /* 936 + * For Win8 PTP touchpads we map both the clickpad click 937 + * and any "external" left buttons to BTN_LEFT if a 938 + * device claims to have both we need to report 1 for 939 + * BTN_LEFT if either is pressed, so we or all values 940 + * together and report the result in mt_sync_frame(). 941 + */ 942 + if (usage->type == EV_KEY && usage->code == BTN_LEFT) { 943 + app->left_button_state |= value; 944 + return; 945 + } 946 + } 947 + 948 + input_event(input, usage->type, usage->code, value); 949 + } 950 + 951 + static void mt_touch_report(struct hid_device *hid, 952 + struct mt_report_data *rdata) 1089 953 { 1090 954 struct mt_device *td = hid_get_drvdata(hid); 955 + struct hid_report *report = rdata->report; 956 + struct mt_application *app = rdata->application; 1091 957 struct hid_field *field; 958 + struct input_dev *input; 959 + struct mt_usages *slot; 1092 960 bool first_packet; 1093 961 unsigned count; 1094 - int r, n, scantime = 0; 962 + int r, n; 963 + int scantime = 0; 964 + int contact_count = -1; 1095 965 1096 966 /* sticky fingers release in progress, abort */ 1097 967 if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) 1098 968 return; 1099 969 970 + scantime = *app->scantime; 971 + app->timestamp = mt_compute_timestamp(app, scantime); 972 + if (app->raw_cc != DEFAULT_ZERO) 973 + contact_count = *app->raw_cc; 974 + 1100 975 /* 1101 976 * Includes multi-packet support where subsequent 1102 977 * packets are sent with zero contactcount. 1103 978 */ 1104 - if (td->scantime_index >= 0) { 1105 - field = report->field[td->scantime_index]; 1106 - scantime = field->value[td->scantime_val_index]; 1107 - } 1108 - if (td->cc_index >= 0) { 1109 - struct hid_field *field = report->field[td->cc_index]; 1110 - int value = field->value[td->cc_value_index]; 1111 - 979 + if (contact_count >= 0) { 1112 980 /* 1113 981 * For Win8 PTPs the first packet (td->num_received == 0) may 1114 982 * have a contactcount of 0 if there only is a button event. ··· 1146 954 * of a possible multi-packet frame be checking that the 1147 955 * timestamp has changed. 1148 956 */ 1149 - if ((td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 1150 - td->num_received == 0 && td->prev_scantime != scantime) 1151 - td->num_expected = value; 957 + if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && 958 + app->num_received == 0 && 959 + app->prev_scantime != scantime) 960 + app->num_expected = contact_count; 1152 961 /* A non 0 contact count always indicates a first packet */ 1153 - else if (value) 1154 - td->num_expected = value; 962 + else if (contact_count) 963 + app->num_expected = contact_count; 1155 964 } 1156 - td->prev_scantime = scantime; 965 + app->prev_scantime = scantime; 1157 966 1158 - first_packet = td->num_received == 0; 967 + first_packet = app->num_received == 0; 968 + 969 + input = report->field[0]->hidinput->input; 970 + 971 + list_for_each_entry(slot, &app->mt_usages, list) { 972 + if (!mt_process_slot(td, input, app, slot)) 973 + app->num_received++; 974 + } 975 + 1159 976 for (r = 0; r < report->maxfield; r++) { 1160 977 field = report->field[r]; 1161 978 count = field->report_count; ··· 1173 972 continue; 1174 973 1175 974 for (n = 0; n < count; n++) 1176 - mt_process_mt_event(hid, field, &field->usage[n], 1177 - field->value[n], first_packet); 975 + mt_process_mt_event(hid, app, field, 976 + &field->usage[n], field->value[n], 977 + first_packet); 1178 978 } 1179 979 1180 - if (td->num_received >= td->num_expected) 1181 - mt_sync_frame(td, report->field[0]->hidinput->input); 980 + if (app->num_received >= app->num_expected) 981 + mt_sync_frame(td, app, input); 1182 982 1183 983 /* 1184 984 * Windows 8 specs says 2 things: ··· 1199 997 * only affect laggish machines and the ones that have a firmware 1200 998 * defect. 1201 999 */ 1202 - if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) { 1000 + if (app->quirks & MT_QUIRK_STICKY_FINGERS) { 1203 1001 if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags)) 1204 1002 mod_timer(&td->release_timer, 1205 1003 jiffies + msecs_to_jiffies(100)); ··· 1211 1009 } 1212 1010 1213 1011 static int mt_touch_input_configured(struct hid_device *hdev, 1214 - struct hid_input *hi) 1012 + struct hid_input *hi, 1013 + struct mt_application *app) 1215 1014 { 1216 1015 struct mt_device *td = hid_get_drvdata(hdev); 1217 1016 struct mt_class *cls = &td->mtclass; ··· 1222 1019 if (!td->maxcontacts) 1223 1020 td->maxcontacts = MT_DEFAULT_MAXCONTACT; 1224 1021 1225 - mt_post_parse(td); 1022 + mt_post_parse(td, app); 1226 1023 if (td->serial_maybe) 1227 - mt_post_parse_default_settings(td); 1024 + mt_post_parse_default_settings(td, app); 1228 1025 1229 1026 if (cls->is_indirect) 1230 - td->mt_flags |= INPUT_MT_POINTER; 1027 + app->mt_flags |= INPUT_MT_POINTER; 1231 1028 1232 - if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 1233 - td->mt_flags |= INPUT_MT_DROP_UNUSED; 1029 + if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 1030 + app->mt_flags |= INPUT_MT_DROP_UNUSED; 1234 1031 1235 1032 /* check for clickpads */ 1236 - if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1)) 1033 + if ((app->mt_flags & INPUT_MT_POINTER) && 1034 + (app->buttons_count == 1)) 1237 1035 td->is_buttonpad = true; 1238 1036 1239 1037 if (td->is_buttonpad) 1240 1038 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); 1241 1039 1242 - ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); 1040 + app->pending_palm_slots = devm_kcalloc(&hi->input->dev, 1041 + BITS_TO_LONGS(td->maxcontacts), 1042 + sizeof(long), 1043 + GFP_KERNEL); 1044 + if (!app->pending_palm_slots) 1045 + return -ENOMEM; 1046 + 1047 + ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags); 1243 1048 if (ret) 1244 1049 return ret; 1245 1050 1246 - td->mt_flags = 0; 1051 + app->mt_flags = 0; 1247 1052 return 0; 1248 1053 } 1249 1054 ··· 1262 1051 unsigned long **bit, int *max) 1263 1052 { 1264 1053 struct mt_device *td = hid_get_drvdata(hdev); 1054 + struct mt_application *application; 1055 + struct mt_report_data *rdata; 1056 + 1057 + rdata = mt_find_report_data(td, field->report); 1058 + if (!rdata) { 1059 + hid_err(hdev, "failed to allocate data for report\n"); 1060 + return 0; 1061 + } 1062 + 1063 + application = rdata->application; 1265 1064 1266 1065 /* 1267 1066 * If mtclass.export_all_inputs is not set, only map fields from ··· 1287 1066 field->application != HID_GD_SYSTEM_CONTROL && 1288 1067 field->application != HID_CP_CONSUMER_CONTROL && 1289 1068 field->application != HID_GD_WIRELESS_RADIO_CTLS && 1069 + field->application != HID_GD_SYSTEM_MULTIAXIS && 1290 1070 !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && 1291 - td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP)) 1071 + application->quirks & MT_QUIRK_ASUS_CUSTOM_UP)) 1292 1072 return -1; 1293 1073 1294 1074 /* ··· 1298 1076 * map usages to input keys. 1299 1077 */ 1300 1078 if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && 1301 - td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP && 1079 + application->quirks & MT_QUIRK_ASUS_CUSTOM_UP && 1302 1080 (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) { 1303 1081 set_bit(EV_REP, hi->input->evbit); 1304 1082 if (field->flags & HID_MAIN_ITEM_VARIABLE) ··· 1315 1093 return 1; 1316 1094 } 1317 1095 1318 - /* 1319 - * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" 1320 - * for the stylus. 1321 - * The check for mt_report_id ensures we don't process 1322 - * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical 1323 - * collection, but within the report ID. 1324 - */ 1325 - if (field->physical == HID_DG_STYLUS) 1326 - return 0; 1327 - else if ((field->physical == 0) && 1328 - (field->report->id != td->mt_report_id) && 1329 - (td->mt_report_id != -1)) 1330 - return 0; 1331 - 1332 - if (field->application == HID_DG_TOUCHSCREEN || 1333 - field->application == HID_DG_TOUCHPAD) 1334 - return mt_touch_input_mapping(hdev, hi, field, usage, bit, max); 1096 + if (rdata->is_mt_collection) 1097 + return mt_touch_input_mapping(hdev, hi, field, usage, bit, max, 1098 + application); 1335 1099 1336 1100 /* let hid-core decide for the others */ 1337 1101 return 0; ··· 1327 1119 struct hid_field *field, struct hid_usage *usage, 1328 1120 unsigned long **bit, int *max) 1329 1121 { 1330 - /* 1331 - * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" 1332 - * for the stylus. 1333 - */ 1334 - if (field->physical == HID_DG_STYLUS) 1335 - return 0; 1122 + struct mt_device *td = hid_get_drvdata(hdev); 1123 + struct mt_report_data *rdata; 1336 1124 1337 - if (field->application == HID_DG_TOUCHSCREEN || 1338 - field->application == HID_DG_TOUCHPAD) { 1125 + rdata = mt_find_report_data(td, field->report); 1126 + if (rdata && rdata->is_mt_collection) { 1339 1127 /* We own these mappings, tell hid-input to ignore them */ 1340 1128 return -1; 1341 1129 } ··· 1344 1140 struct hid_usage *usage, __s32 value) 1345 1141 { 1346 1142 struct mt_device *td = hid_get_drvdata(hid); 1143 + struct mt_report_data *rdata; 1347 1144 1348 - if (field->report->id == td->mt_report_id) 1145 + rdata = mt_find_report_data(td, field->report); 1146 + if (rdata && rdata->is_mt_collection) 1349 1147 return mt_touch_event(hid, field, usage, value); 1350 1148 1351 1149 return 0; ··· 1357 1151 { 1358 1152 struct mt_device *td = hid_get_drvdata(hid); 1359 1153 struct hid_field *field = report->field[0]; 1154 + struct mt_report_data *rdata; 1360 1155 1361 1156 if (!(hid->claimed & HID_CLAIMED_INPUT)) 1362 1157 return; 1363 1158 1364 - if (report->id == td->mt_report_id) 1365 - return mt_touch_report(hid, report); 1159 + rdata = mt_find_report_data(td, report); 1160 + if (rdata && rdata->is_mt_collection) 1161 + return mt_touch_report(hid, rdata); 1366 1162 1367 1163 if (field && field->hidinput && field->hidinput->input) 1368 1164 input_sync(field->hidinput->input); ··· 1405 1197 return true; 1406 1198 1407 1199 case HID_DG_CONTACTMAX: 1408 - if (td->mtclass.maxcontacts) { 1200 + if (cls->maxcontacts) { 1409 1201 max = min_t(int, field->logical_maximum, 1410 - td->mtclass.maxcontacts); 1202 + cls->maxcontacts); 1411 1203 if (field->value[index] != max) { 1412 1204 field->value[index] = max; 1413 1205 return true; ··· 1467 1259 } 1468 1260 } 1469 1261 1470 - static void mt_post_parse_default_settings(struct mt_device *td) 1262 + static void mt_post_parse_default_settings(struct mt_device *td, 1263 + struct mt_application *app) 1471 1264 { 1472 - __s32 quirks = td->mtclass.quirks; 1265 + __s32 quirks = app->quirks; 1473 1266 1474 1267 /* unknown serial device needs special quirks */ 1475 - if (td->touches_by_report == 1) { 1268 + if (list_is_singular(&app->mt_usages)) { 1476 1269 quirks |= MT_QUIRK_ALWAYS_VALID; 1477 1270 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP; 1478 1271 quirks &= ~MT_QUIRK_VALID_IS_INRANGE; ··· 1481 1272 quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 1482 1273 } 1483 1274 1484 - td->mtclass.quirks = quirks; 1275 + app->quirks = quirks; 1485 1276 } 1486 1277 1487 - static void mt_post_parse(struct mt_device *td) 1278 + static void mt_post_parse(struct mt_device *td, struct mt_application *app) 1488 1279 { 1489 - struct mt_fields *f = td->fields; 1490 - struct mt_class *cls = &td->mtclass; 1491 - 1492 - if (td->touches_by_report > 0) { 1493 - int field_count_per_touch = f->length / td->touches_by_report; 1494 - td->last_slot_field = f->usages[field_count_per_touch - 1]; 1495 - } 1496 - 1497 - if (td->cc_index < 0) 1498 - cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 1280 + if (!app->have_contact_count) 1281 + app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; 1499 1282 } 1500 1283 1501 1284 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) ··· 1496 1295 char *name; 1497 1296 const char *suffix = NULL; 1498 1297 unsigned int application = 0; 1298 + struct mt_report_data *rdata; 1299 + struct mt_application *mt_application = NULL; 1499 1300 struct hid_report *report; 1500 1301 int ret; 1501 1302 1502 1303 list_for_each_entry(report, &hi->reports, hidinput_list) { 1503 1304 application = report->application; 1504 - if (report->id == td->mt_report_id) { 1505 - ret = mt_touch_input_configured(hdev, hi); 1305 + rdata = mt_find_report_data(td, report); 1306 + if (!rdata) { 1307 + hid_err(hdev, "failed to allocate data for report\n"); 1308 + return -ENOMEM; 1309 + } 1310 + 1311 + mt_application = rdata->application; 1312 + 1313 + if (rdata->is_mt_collection) { 1314 + ret = mt_touch_input_configured(hdev, hi, 1315 + mt_application); 1506 1316 if (ret) 1507 1317 return ret; 1508 1318 } ··· 1539 1327 case HID_GD_SYSTEM_CONTROL: 1540 1328 case HID_CP_CONSUMER_CONTROL: 1541 1329 case HID_GD_WIRELESS_RADIO_CTLS: 1330 + case HID_GD_SYSTEM_MULTIAXIS: 1542 1331 /* already handled by hid core */ 1543 1332 break; 1544 1333 case HID_DG_TOUCHSCREEN: ··· 1603 1390 static void mt_release_contacts(struct hid_device *hid) 1604 1391 { 1605 1392 struct hid_input *hidinput; 1393 + struct mt_application *application; 1606 1394 struct mt_device *td = hid_get_drvdata(hid); 1607 1395 1608 1396 list_for_each_entry(hidinput, &hid->inputs, list) { ··· 1623 1409 } 1624 1410 } 1625 1411 1626 - td->num_received = 0; 1412 + list_for_each_entry(application, &td->applications, list) { 1413 + application->num_received = 0; 1414 + } 1627 1415 } 1628 1416 1629 1417 static void mt_expired_timeout(struct timer_list *t) ··· 1648 1432 { 1649 1433 int ret, i; 1650 1434 struct mt_device *td; 1651 - struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 1435 + const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 1652 1436 1653 1437 for (i = 0; mt_classes[i].name ; i++) { 1654 1438 if (id->driver_data == mt_classes[i].name) { ··· 1665 1449 td->hdev = hdev; 1666 1450 td->mtclass = *mtclass; 1667 1451 td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; 1668 - td->cc_index = -1; 1669 - td->scantime_index = -1; 1670 - td->mt_report_id = -1; 1671 1452 hid_set_drvdata(hdev, td); 1672 1453 1673 - td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields), 1674 - GFP_KERNEL); 1675 - if (!td->fields) { 1676 - dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); 1677 - return -ENOMEM; 1678 - } 1454 + INIT_LIST_HEAD(&td->applications); 1455 + INIT_LIST_HEAD(&td->reports); 1679 1456 1680 1457 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) 1681 1458 td->serial_maybe = true; ··· 1704 1495 hdev->name); 1705 1496 1706 1497 mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); 1707 - 1708 - /* release .fields memory as it is not used anymore */ 1709 - devm_kfree(&hdev->dev, td->fields); 1710 - td->fields = NULL; 1711 1498 1712 1499 return 0; 1713 1500 }
+2
drivers/hid/hid-ntrig.c
··· 955 955 956 956 ret = sysfs_create_group(&hdev->dev.kobj, 957 957 &ntrig_attribute_group); 958 + if (ret) 959 + hid_err(hdev, "cannot create sysfs group\n"); 958 960 959 961 return 0; 960 962 err_free:
+1 -25
drivers/hid/hid-redragon.c
··· 44 44 return rdesc; 45 45 } 46 46 47 - static int redragon_probe(struct hid_device *dev, 48 - const struct hid_device_id *id) 49 - { 50 - int ret; 51 - 52 - ret = hid_parse(dev); 53 - if (ret) { 54 - hid_err(dev, "parse failed\n"); 55 - return ret; 56 - } 57 - 58 - /* do not register unused input device */ 59 - if (dev->maxapplication == 1) 60 - return 0; 61 - 62 - ret = hid_hw_start(dev, HID_CONNECT_DEFAULT); 63 - if (ret) { 64 - hid_err(dev, "hw start failed\n"); 65 - return ret; 66 - } 67 - 68 - return 0; 69 - } 70 47 static const struct hid_device_id redragon_devices[] = { 71 48 {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)}, 72 49 {} ··· 54 77 static struct hid_driver redragon_driver = { 55 78 .name = "redragon", 56 79 .id_table = redragon_devices, 57 - .report_fixup = redragon_report_fixup, 58 - .probe = redragon_probe 80 + .report_fixup = redragon_report_fixup 59 81 }; 60 82 61 83 module_hid_driver(redragon_driver);
+28 -136
drivers/hid/hid-sony.c
··· 1353 1353 char *name; 1354 1354 int ret; 1355 1355 1356 - sc->touchpad = input_allocate_device(); 1356 + sc->touchpad = devm_input_allocate_device(&sc->hdev->dev); 1357 1357 if (!sc->touchpad) 1358 1358 return -ENOMEM; 1359 1359 ··· 1370 1370 * DS4 compatible non-Sony devices with different names. 1371 1371 */ 1372 1372 name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); 1373 - name = kzalloc(name_sz, GFP_KERNEL); 1374 - if (!name) { 1375 - ret = -ENOMEM; 1376 - goto err; 1377 - } 1373 + name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); 1374 + if (!name) 1375 + return -ENOMEM; 1378 1376 snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); 1379 1377 sc->touchpad->name = name; 1380 1378 ··· 1401 1403 1402 1404 ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); 1403 1405 if (ret < 0) 1404 - goto err; 1406 + return ret; 1405 1407 1406 1408 ret = input_register_device(sc->touchpad); 1407 1409 if (ret < 0) 1408 - goto err; 1410 + return ret; 1409 1411 1410 1412 return 0; 1411 - 1412 - err: 1413 - kfree(sc->touchpad->name); 1414 - sc->touchpad->name = NULL; 1415 - 1416 - input_free_device(sc->touchpad); 1417 - sc->touchpad = NULL; 1418 - 1419 - return ret; 1420 - } 1421 - 1422 - static void sony_unregister_touchpad(struct sony_sc *sc) 1423 - { 1424 - if (!sc->touchpad) 1425 - return; 1426 - 1427 - kfree(sc->touchpad->name); 1428 - sc->touchpad->name = NULL; 1429 - 1430 - input_unregister_device(sc->touchpad); 1431 - sc->touchpad = NULL; 1432 1413 } 1433 1414 1434 1415 static int sony_register_sensors(struct sony_sc *sc) ··· 1417 1440 int ret; 1418 1441 int range; 1419 1442 1420 - sc->sensor_dev = input_allocate_device(); 1443 + sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev); 1421 1444 if (!sc->sensor_dev) 1422 1445 return -ENOMEM; 1423 1446 ··· 1434 1457 * DS4 compatible non-Sony devices with different names. 1435 1458 */ 1436 1459 name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); 1437 - name = kzalloc(name_sz, GFP_KERNEL); 1438 - if (!name) { 1439 - ret = -ENOMEM; 1440 - goto err; 1441 - } 1460 + name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); 1461 + if (!name) 1462 + return -ENOMEM; 1442 1463 snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); 1443 1464 sc->sensor_dev->name = name; 1444 1465 ··· 1478 1503 1479 1504 ret = input_register_device(sc->sensor_dev); 1480 1505 if (ret < 0) 1481 - goto err; 1506 + return ret; 1482 1507 1483 1508 return 0; 1484 - 1485 - err: 1486 - kfree(sc->sensor_dev->name); 1487 - sc->sensor_dev->name = NULL; 1488 - 1489 - input_free_device(sc->sensor_dev); 1490 - sc->sensor_dev = NULL; 1491 - 1492 - return ret; 1493 1509 } 1494 - 1495 - static void sony_unregister_sensors(struct sony_sc *sc) 1496 - { 1497 - if (!sc->sensor_dev) 1498 - return; 1499 - 1500 - kfree(sc->sensor_dev->name); 1501 - sc->sensor_dev->name = NULL; 1502 - 1503 - input_unregister_device(sc->sensor_dev); 1504 - sc->sensor_dev = NULL; 1505 - } 1506 - 1507 1510 1508 1511 /* 1509 1512 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller ··· 1940 1987 return 0; 1941 1988 } 1942 1989 1943 - static void sony_leds_remove(struct sony_sc *sc) 1944 - { 1945 - struct led_classdev *led; 1946 - int n; 1947 - 1948 - BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); 1949 - 1950 - for (n = 0; n < sc->led_count; n++) { 1951 - led = sc->leds[n]; 1952 - sc->leds[n] = NULL; 1953 - if (!led) 1954 - continue; 1955 - led_classdev_unregister(led); 1956 - kfree(led); 1957 - } 1958 - 1959 - sc->led_count = 0; 1960 - } 1961 - 1962 1990 static int sony_leds_init(struct sony_sc *sc) 1963 1991 { 1964 1992 struct hid_device *hdev = sc->hdev; ··· 2012 2078 if (use_ds4_names) 2013 2079 name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; 2014 2080 2015 - led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); 2081 + led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); 2016 2082 if (!led) { 2017 2083 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); 2018 - ret = -ENOMEM; 2019 - goto error_leds; 2084 + return -ENOMEM; 2020 2085 } 2021 2086 2022 2087 name = (void *)(&led[1]); ··· 2036 2103 2037 2104 sc->leds[n] = led; 2038 2105 2039 - ret = led_classdev_register(&hdev->dev, led); 2106 + ret = devm_led_classdev_register(&hdev->dev, led); 2040 2107 if (ret) { 2041 2108 hid_err(hdev, "Failed to register LED %d\n", n); 2042 - sc->leds[n] = NULL; 2043 - kfree(led); 2044 - goto error_leds; 2109 + return ret; 2045 2110 } 2046 2111 } 2047 2112 2048 - return ret; 2049 - 2050 - error_leds: 2051 - sony_leds_remove(sc); 2052 - 2053 - return ret; 2113 + return 0; 2054 2114 } 2055 2115 2056 2116 static void sixaxis_send_output_report(struct sony_sc *sc) ··· 2202 2276 if ((sc->quirks & SIXAXIS_CONTROLLER) || 2203 2277 (sc->quirks & NAVIGATION_CONTROLLER)) 2204 2278 sc->output_report_dmabuf = 2205 - kmalloc(sizeof(union sixaxis_output_report_01), 2279 + devm_kmalloc(&sc->hdev->dev, 2280 + sizeof(union sixaxis_output_report_01), 2206 2281 GFP_KERNEL); 2207 2282 else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) 2208 - sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x11_SIZE, 2283 + sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, 2284 + DS4_OUTPUT_REPORT_0x11_SIZE, 2209 2285 GFP_KERNEL); 2210 2286 else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) 2211 - sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x05_SIZE, 2287 + sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, 2288 + DS4_OUTPUT_REPORT_0x05_SIZE, 2212 2289 GFP_KERNEL); 2213 2290 else if (sc->quirks & MOTION_CONTROLLER) 2214 - sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE, 2291 + sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, 2292 + MOTION_REPORT_0x02_SIZE, 2215 2293 GFP_KERNEL); 2216 2294 else 2217 2295 return 0; ··· 2322 2392 sc->battery_desc.get_property = sony_battery_get_property; 2323 2393 sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; 2324 2394 sc->battery_desc.use_for_apm = 0; 2325 - sc->battery_desc.name = kasprintf(GFP_KERNEL, battery_str_fmt, 2326 - sc->mac_address, sc->device_id); 2395 + sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, 2396 + battery_str_fmt, sc->mac_address, sc->device_id); 2327 2397 if (!sc->battery_desc.name) 2328 2398 return -ENOMEM; 2329 2399 2330 - sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc, 2400 + sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc, 2331 2401 &psy_cfg); 2332 2402 if (IS_ERR(sc->battery)) { 2333 2403 ret = PTR_ERR(sc->battery); 2334 2404 hid_err(hdev, "Unable to register battery device\n"); 2335 - goto err_free; 2405 + return ret; 2336 2406 } 2337 2407 2338 2408 power_supply_powers(sc->battery, &hdev->dev); 2339 2409 return 0; 2340 - 2341 - err_free: 2342 - kfree(sc->battery_desc.name); 2343 - sc->battery_desc.name = NULL; 2344 - return ret; 2345 - } 2346 - 2347 - static void sony_battery_remove(struct sony_sc *sc) 2348 - { 2349 - if (!sc->battery_desc.name) 2350 - return; 2351 - 2352 - power_supply_unregister(sc->battery); 2353 - kfree(sc->battery_desc.name); 2354 - sc->battery_desc.name = NULL; 2355 2410 } 2356 2411 2357 2412 /* ··· 2794 2879 device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); 2795 2880 if (sc->hw_version) 2796 2881 device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); 2797 - if (sc->quirks & SONY_LED_SUPPORT) 2798 - sony_leds_remove(sc); 2799 - if (sc->quirks & SONY_BATTERY_SUPPORT) 2800 - sony_battery_remove(sc); 2801 - if (sc->touchpad) 2802 - sony_unregister_touchpad(sc); 2803 - if (sc->sensor_dev) 2804 - sony_unregister_sensors(sc); 2805 2882 sony_cancel_work_sync(sc); 2806 - kfree(sc->output_report_dmabuf); 2807 2883 sony_remove_dev_list(sc); 2808 2884 sony_release_device_id(sc); 2809 2885 hid_hw_stop(hdev); ··· 2871 2965 2872 2966 hid_hw_close(hdev); 2873 2967 2874 - if (sc->quirks & SONY_LED_SUPPORT) 2875 - sony_leds_remove(sc); 2876 - 2877 - if (sc->quirks & SONY_BATTERY_SUPPORT) 2878 - sony_battery_remove(sc); 2879 - 2880 - if (sc->touchpad) 2881 - sony_unregister_touchpad(sc); 2882 - 2883 - if (sc->sensor_dev) 2884 - sony_unregister_sensors(sc); 2885 - 2886 2968 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) 2887 2969 device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); 2888 2970 ··· 2881 2987 device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); 2882 2988 2883 2989 sony_cancel_work_sync(sc); 2884 - 2885 - kfree(sc->output_report_dmabuf); 2886 2990 2887 2991 sony_remove_dev_list(sc); 2888 2992
+14
drivers/hid/hid-wiimote-core.c
··· 455 455 return WIIMOTE_EXT_BALANCE_BOARD; 456 456 if (rmem[4] == 0x01 && rmem[5] == 0x20) 457 457 return WIIMOTE_EXT_PRO_CONTROLLER; 458 + if (rmem[0] == 0x01 && rmem[1] == 0x00 && 459 + rmem[4] == 0x01 && rmem[5] == 0x03) 460 + return WIIMOTE_EXT_DRUMS; 461 + if (rmem[0] == 0x00 && rmem[1] == 0x00 && 462 + rmem[4] == 0x01 && rmem[5] == 0x03) 463 + return WIIMOTE_EXT_GUITAR; 458 464 459 465 return WIIMOTE_EXT_UNKNOWN; 460 466 } ··· 494 488 /* map MP with correct pass-through mode */ 495 489 switch (exttype) { 496 490 case WIIMOTE_EXT_CLASSIC_CONTROLLER: 491 + case WIIMOTE_EXT_DRUMS: 492 + case WIIMOTE_EXT_GUITAR: 497 493 wmem = 0x07; 498 494 break; 499 495 case WIIMOTE_EXT_NUNCHUK: ··· 1083 1075 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller", 1084 1076 [WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board", 1085 1077 [WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller", 1078 + [WIIMOTE_EXT_DRUMS] = "Nintendo Wii Drums", 1079 + [WIIMOTE_EXT_GUITAR] = "Nintendo Wii Guitar", 1086 1080 }; 1087 1081 1088 1082 /* ··· 1670 1660 return sprintf(buf, "balanceboard\n"); 1671 1661 case WIIMOTE_EXT_PRO_CONTROLLER: 1672 1662 return sprintf(buf, "procontroller\n"); 1663 + case WIIMOTE_EXT_DRUMS: 1664 + return sprintf(buf, "drums\n"); 1665 + case WIIMOTE_EXT_GUITAR: 1666 + return sprintf(buf, "guitar\n"); 1673 1667 case WIIMOTE_EXT_UNKNOWN: 1674 1668 /* fallthrough */ 1675 1669 default:
+440
drivers/hid/hid-wiimote-modules.c
··· 1950 1950 }; 1951 1951 1952 1952 /* 1953 + * Drums 1954 + * Guitar-Hero, Rock-Band and other games came bundled with drums which can 1955 + * be plugged as extension to a Wiimote. Drum-reports are still not entirely 1956 + * figured out, but the most important information is known. 1957 + * We create a separate device for drums and report all information via this 1958 + * input device. 1959 + */ 1960 + 1961 + static inline void wiimod_drums_report_pressure(struct wiimote_data *wdata, 1962 + __u8 none, __u8 which, 1963 + __u8 pressure, __u8 onoff, 1964 + __u8 *store, __u16 code, 1965 + __u8 which_code) 1966 + { 1967 + static const __u8 default_pressure = 3; 1968 + 1969 + if (!none && which == which_code) { 1970 + *store = pressure; 1971 + input_report_abs(wdata->extension.input, code, *store); 1972 + } else if (onoff != !!*store) { 1973 + *store = onoff ? default_pressure : 0; 1974 + input_report_abs(wdata->extension.input, code, *store); 1975 + } 1976 + } 1977 + 1978 + static void wiimod_drums_in_ext(struct wiimote_data *wdata, const __u8 *ext) 1979 + { 1980 + __u8 pressure, which, none, hhp, sx, sy; 1981 + __u8 o, r, y, g, b, bass, bm, bp; 1982 + 1983 + /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 1984 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 1985 + * 1 | 0 | 0 | SX <5:0> | 1986 + * 2 | 0 | 0 | SY <5:0> | 1987 + * -----+-----+-----+-----------------------------+-----+ 1988 + * 3 | HPP | NON | WHICH <5:1> | ? | 1989 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 1990 + * 4 | SOFT <7:5> | 0 | 1 | 1 | 0 | ? | 1991 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 1992 + * 5 | ? | 1 | 1 | B- | 1 | B+ | 1 | ? | 1993 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 1994 + * 6 | O | R | Y | G | B | BSS | 1 | 1 | 1995 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 1996 + * All buttons are 0 if pressed 1997 + * 1998 + * With Motion+ enabled, the following bits will get invalid: 1999 + * Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 2000 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2001 + * 1 | 0 | 0 | SX <5:1> |XXXXX| 2002 + * 2 | 0 | 0 | SY <5:1> |XXXXX| 2003 + * -----+-----+-----+-----------------------------+-----+ 2004 + * 3 | HPP | NON | WHICH <5:1> | ? | 2005 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2006 + * 4 | SOFT <7:5> | 0 | 1 | 1 | 0 | ? | 2007 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2008 + * 5 | ? | 1 | 1 | B- | 1 | B+ | 1 |XXXXX| 2009 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2010 + * 6 | O | R | Y | G | B | BSS |XXXXX|XXXXX| 2011 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2012 + */ 2013 + 2014 + pressure = 7 - (ext[3] >> 5); 2015 + which = (ext[2] >> 1) & 0x1f; 2016 + none = !!(ext[2] & 0x40); 2017 + hhp = !(ext[2] & 0x80); 2018 + sx = ext[0] & 0x3f; 2019 + sy = ext[1] & 0x3f; 2020 + o = !(ext[5] & 0x80); 2021 + r = !(ext[5] & 0x40); 2022 + y = !(ext[5] & 0x20); 2023 + g = !(ext[5] & 0x10); 2024 + b = !(ext[5] & 0x08); 2025 + bass = !(ext[5] & 0x04); 2026 + bm = !(ext[4] & 0x10); 2027 + bp = !(ext[4] & 0x04); 2028 + 2029 + if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { 2030 + sx &= 0x3e; 2031 + sy &= 0x3e; 2032 + } 2033 + 2034 + wiimod_drums_report_pressure(wdata, none, which, pressure, 2035 + o, &wdata->state.pressure_drums[0], 2036 + ABS_HAT2Y, 0x0e); 2037 + wiimod_drums_report_pressure(wdata, none, which, pressure, 2038 + r, &wdata->state.pressure_drums[1], 2039 + ABS_HAT0X, 0x19); 2040 + wiimod_drums_report_pressure(wdata, none, which, pressure, 2041 + y, &wdata->state.pressure_drums[2], 2042 + ABS_HAT2X, 0x11); 2043 + wiimod_drums_report_pressure(wdata, none, which, pressure, 2044 + g, &wdata->state.pressure_drums[3], 2045 + ABS_HAT1X, 0x12); 2046 + wiimod_drums_report_pressure(wdata, none, which, pressure, 2047 + b, &wdata->state.pressure_drums[4], 2048 + ABS_HAT0Y, 0x0f); 2049 + 2050 + /* Bass shares pressure with hi-hat (set via hhp) */ 2051 + wiimod_drums_report_pressure(wdata, none, hhp ? 0xff : which, pressure, 2052 + bass, &wdata->state.pressure_drums[5], 2053 + ABS_HAT3X, 0x1b); 2054 + /* Hi-hat has no on/off values, just pressure. Force to off/0. */ 2055 + wiimod_drums_report_pressure(wdata, none, hhp ? which : 0xff, pressure, 2056 + 0, &wdata->state.pressure_drums[6], 2057 + ABS_HAT3Y, 0x0e); 2058 + 2059 + input_report_abs(wdata->extension.input, ABS_X, sx - 0x20); 2060 + input_report_abs(wdata->extension.input, ABS_Y, sy - 0x20); 2061 + 2062 + input_report_key(wdata->extension.input, BTN_START, bp); 2063 + input_report_key(wdata->extension.input, BTN_SELECT, bm); 2064 + 2065 + input_sync(wdata->extension.input); 2066 + } 2067 + 2068 + static int wiimod_drums_open(struct input_dev *dev) 2069 + { 2070 + struct wiimote_data *wdata = input_get_drvdata(dev); 2071 + unsigned long flags; 2072 + 2073 + spin_lock_irqsave(&wdata->state.lock, flags); 2074 + wdata->state.flags |= WIIPROTO_FLAG_EXT_USED; 2075 + wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); 2076 + spin_unlock_irqrestore(&wdata->state.lock, flags); 2077 + 2078 + return 0; 2079 + } 2080 + 2081 + static void wiimod_drums_close(struct input_dev *dev) 2082 + { 2083 + struct wiimote_data *wdata = input_get_drvdata(dev); 2084 + unsigned long flags; 2085 + 2086 + spin_lock_irqsave(&wdata->state.lock, flags); 2087 + wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED; 2088 + wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); 2089 + spin_unlock_irqrestore(&wdata->state.lock, flags); 2090 + } 2091 + 2092 + static int wiimod_drums_probe(const struct wiimod_ops *ops, 2093 + struct wiimote_data *wdata) 2094 + { 2095 + int ret; 2096 + 2097 + wdata->extension.input = input_allocate_device(); 2098 + if (!wdata->extension.input) 2099 + return -ENOMEM; 2100 + 2101 + input_set_drvdata(wdata->extension.input, wdata); 2102 + wdata->extension.input->open = wiimod_drums_open; 2103 + wdata->extension.input->close = wiimod_drums_close; 2104 + wdata->extension.input->dev.parent = &wdata->hdev->dev; 2105 + wdata->extension.input->id.bustype = wdata->hdev->bus; 2106 + wdata->extension.input->id.vendor = wdata->hdev->vendor; 2107 + wdata->extension.input->id.product = wdata->hdev->product; 2108 + wdata->extension.input->id.version = wdata->hdev->version; 2109 + wdata->extension.input->name = WIIMOTE_NAME " Drums"; 2110 + 2111 + set_bit(EV_KEY, wdata->extension.input->evbit); 2112 + set_bit(BTN_START, wdata->extension.input->keybit); 2113 + set_bit(BTN_SELECT, wdata->extension.input->keybit); 2114 + 2115 + set_bit(EV_ABS, wdata->extension.input->evbit); 2116 + set_bit(ABS_X, wdata->extension.input->absbit); 2117 + set_bit(ABS_Y, wdata->extension.input->absbit); 2118 + set_bit(ABS_HAT0X, wdata->extension.input->absbit); 2119 + set_bit(ABS_HAT0Y, wdata->extension.input->absbit); 2120 + set_bit(ABS_HAT1X, wdata->extension.input->absbit); 2121 + set_bit(ABS_HAT2X, wdata->extension.input->absbit); 2122 + set_bit(ABS_HAT2Y, wdata->extension.input->absbit); 2123 + set_bit(ABS_HAT3X, wdata->extension.input->absbit); 2124 + set_bit(ABS_HAT3Y, wdata->extension.input->absbit); 2125 + input_set_abs_params(wdata->extension.input, 2126 + ABS_X, -32, 31, 1, 1); 2127 + input_set_abs_params(wdata->extension.input, 2128 + ABS_Y, -32, 31, 1, 1); 2129 + input_set_abs_params(wdata->extension.input, 2130 + ABS_HAT0X, 0, 7, 0, 0); 2131 + input_set_abs_params(wdata->extension.input, 2132 + ABS_HAT0Y, 0, 7, 0, 0); 2133 + input_set_abs_params(wdata->extension.input, 2134 + ABS_HAT1X, 0, 7, 0, 0); 2135 + input_set_abs_params(wdata->extension.input, 2136 + ABS_HAT2X, 0, 7, 0, 0); 2137 + input_set_abs_params(wdata->extension.input, 2138 + ABS_HAT2Y, 0, 7, 0, 0); 2139 + input_set_abs_params(wdata->extension.input, 2140 + ABS_HAT3X, 0, 7, 0, 0); 2141 + input_set_abs_params(wdata->extension.input, 2142 + ABS_HAT3Y, 0, 7, 0, 0); 2143 + 2144 + ret = input_register_device(wdata->extension.input); 2145 + if (ret) 2146 + goto err_free; 2147 + 2148 + return 0; 2149 + 2150 + err_free: 2151 + input_free_device(wdata->extension.input); 2152 + wdata->extension.input = NULL; 2153 + return ret; 2154 + } 2155 + 2156 + static void wiimod_drums_remove(const struct wiimod_ops *ops, 2157 + struct wiimote_data *wdata) 2158 + { 2159 + if (!wdata->extension.input) 2160 + return; 2161 + 2162 + input_unregister_device(wdata->extension.input); 2163 + wdata->extension.input = NULL; 2164 + } 2165 + 2166 + static const struct wiimod_ops wiimod_drums = { 2167 + .flags = 0, 2168 + .arg = 0, 2169 + .probe = wiimod_drums_probe, 2170 + .remove = wiimod_drums_remove, 2171 + .in_ext = wiimod_drums_in_ext, 2172 + }; 2173 + 2174 + /* 2175 + * Guitar 2176 + * Guitar-Hero, Rock-Band and other games came bundled with guitars which can 2177 + * be plugged as extension to a Wiimote. 2178 + * We create a separate device for guitars and report all information via this 2179 + * input device. 2180 + */ 2181 + 2182 + enum wiimod_guitar_keys { 2183 + WIIMOD_GUITAR_KEY_G, 2184 + WIIMOD_GUITAR_KEY_R, 2185 + WIIMOD_GUITAR_KEY_Y, 2186 + WIIMOD_GUITAR_KEY_B, 2187 + WIIMOD_GUITAR_KEY_O, 2188 + WIIMOD_GUITAR_KEY_UP, 2189 + WIIMOD_GUITAR_KEY_DOWN, 2190 + WIIMOD_GUITAR_KEY_PLUS, 2191 + WIIMOD_GUITAR_KEY_MINUS, 2192 + WIIMOD_GUITAR_KEY_NUM, 2193 + }; 2194 + 2195 + static const __u16 wiimod_guitar_map[] = { 2196 + BTN_1, /* WIIMOD_GUITAR_KEY_G */ 2197 + BTN_2, /* WIIMOD_GUITAR_KEY_R */ 2198 + BTN_3, /* WIIMOD_GUITAR_KEY_Y */ 2199 + BTN_4, /* WIIMOD_GUITAR_KEY_B */ 2200 + BTN_5, /* WIIMOD_GUITAR_KEY_O */ 2201 + BTN_DPAD_UP, /* WIIMOD_GUITAR_KEY_UP */ 2202 + BTN_DPAD_DOWN, /* WIIMOD_GUITAR_KEY_DOWN */ 2203 + BTN_START, /* WIIMOD_GUITAR_KEY_PLUS */ 2204 + BTN_SELECT, /* WIIMOD_GUITAR_KEY_MINUS */ 2205 + }; 2206 + 2207 + static void wiimod_guitar_in_ext(struct wiimote_data *wdata, const __u8 *ext) 2208 + { 2209 + __u8 sx, sy, tb, wb, bd, bm, bp, bo, br, bb, bg, by, bu; 2210 + 2211 + /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 2212 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2213 + * 1 | 0 | 0 | SX <5:0> | 2214 + * 2 | 0 | 0 | SY <5:0> | 2215 + * -----+-----+-----+-----+-----------------------------+ 2216 + * 3 | 0 | 0 | 0 | TB <4:0> | 2217 + * -----+-----+-----+-----+-----------------------------+ 2218 + * 4 | 0 | 0 | 0 | WB <4:0> | 2219 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2220 + * 5 | 1 | BD | 1 | B- | 1 | B+ | 1 | 1 | 2221 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2222 + * 6 | BO | BR | BB | BG | BY | 1 | 1 | BU | 2223 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2224 + * All buttons are 0 if pressed 2225 + * 2226 + * With Motion+ enabled, it will look like this: 2227 + * Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 2228 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2229 + * 1 | 0 | 0 | SX <5:1> | BU | 2230 + * 2 | 0 | 0 | SY <5:1> | 1 | 2231 + * -----+-----+-----+-----+-----------------------+-----+ 2232 + * 3 | 0 | 0 | 0 | TB <4:0> | 2233 + * -----+-----+-----+-----+-----------------------------+ 2234 + * 4 | 0 | 0 | 0 | WB <4:0> | 2235 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2236 + * 5 | 1 | BD | 1 | B- | 1 | B+ | 1 |XXXXX| 2237 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2238 + * 6 | BO | BR | BB | BG | BY | 1 |XXXXX|XXXXX| 2239 + * -----+-----+-----+-----+-----+-----+-----+-----+-----+ 2240 + */ 2241 + 2242 + sx = ext[0] & 0x3f; 2243 + sy = ext[1] & 0x3f; 2244 + tb = ext[2] & 0x1f; 2245 + wb = ext[3] & 0x1f; 2246 + bd = !(ext[4] & 0x40); 2247 + bm = !(ext[4] & 0x10); 2248 + bp = !(ext[4] & 0x04); 2249 + bo = !(ext[5] & 0x80); 2250 + br = !(ext[5] & 0x40); 2251 + bb = !(ext[5] & 0x20); 2252 + bg = !(ext[5] & 0x10); 2253 + by = !(ext[5] & 0x08); 2254 + bu = !(ext[5] & 0x01); 2255 + 2256 + if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { 2257 + bu = !(ext[0] & 0x01); 2258 + sx &= 0x3e; 2259 + sy &= 0x3e; 2260 + } 2261 + 2262 + input_report_abs(wdata->extension.input, ABS_X, sx - 0x20); 2263 + input_report_abs(wdata->extension.input, ABS_Y, sy - 0x20); 2264 + input_report_abs(wdata->extension.input, ABS_HAT0X, tb); 2265 + input_report_abs(wdata->extension.input, ABS_HAT1X, wb - 0x10); 2266 + 2267 + input_report_key(wdata->extension.input, 2268 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_G], 2269 + bg); 2270 + input_report_key(wdata->extension.input, 2271 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_R], 2272 + br); 2273 + input_report_key(wdata->extension.input, 2274 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_Y], 2275 + by); 2276 + input_report_key(wdata->extension.input, 2277 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_B], 2278 + bb); 2279 + input_report_key(wdata->extension.input, 2280 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_O], 2281 + bo); 2282 + input_report_key(wdata->extension.input, 2283 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_UP], 2284 + bu); 2285 + input_report_key(wdata->extension.input, 2286 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_DOWN], 2287 + bd); 2288 + input_report_key(wdata->extension.input, 2289 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_PLUS], 2290 + bp); 2291 + input_report_key(wdata->extension.input, 2292 + wiimod_guitar_map[WIIMOD_GUITAR_KEY_MINUS], 2293 + bm); 2294 + 2295 + input_sync(wdata->extension.input); 2296 + } 2297 + 2298 + static int wiimod_guitar_open(struct input_dev *dev) 2299 + { 2300 + struct wiimote_data *wdata = input_get_drvdata(dev); 2301 + unsigned long flags; 2302 + 2303 + spin_lock_irqsave(&wdata->state.lock, flags); 2304 + wdata->state.flags |= WIIPROTO_FLAG_EXT_USED; 2305 + wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); 2306 + spin_unlock_irqrestore(&wdata->state.lock, flags); 2307 + 2308 + return 0; 2309 + } 2310 + 2311 + static void wiimod_guitar_close(struct input_dev *dev) 2312 + { 2313 + struct wiimote_data *wdata = input_get_drvdata(dev); 2314 + unsigned long flags; 2315 + 2316 + spin_lock_irqsave(&wdata->state.lock, flags); 2317 + wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED; 2318 + wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); 2319 + spin_unlock_irqrestore(&wdata->state.lock, flags); 2320 + } 2321 + 2322 + static int wiimod_guitar_probe(const struct wiimod_ops *ops, 2323 + struct wiimote_data *wdata) 2324 + { 2325 + int ret, i; 2326 + 2327 + wdata->extension.input = input_allocate_device(); 2328 + if (!wdata->extension.input) 2329 + return -ENOMEM; 2330 + 2331 + input_set_drvdata(wdata->extension.input, wdata); 2332 + wdata->extension.input->open = wiimod_guitar_open; 2333 + wdata->extension.input->close = wiimod_guitar_close; 2334 + wdata->extension.input->dev.parent = &wdata->hdev->dev; 2335 + wdata->extension.input->id.bustype = wdata->hdev->bus; 2336 + wdata->extension.input->id.vendor = wdata->hdev->vendor; 2337 + wdata->extension.input->id.product = wdata->hdev->product; 2338 + wdata->extension.input->id.version = wdata->hdev->version; 2339 + wdata->extension.input->name = WIIMOTE_NAME " Guitar"; 2340 + 2341 + set_bit(EV_KEY, wdata->extension.input->evbit); 2342 + for (i = 0; i < WIIMOD_GUITAR_KEY_NUM; ++i) 2343 + set_bit(wiimod_guitar_map[i], 2344 + wdata->extension.input->keybit); 2345 + 2346 + set_bit(EV_ABS, wdata->extension.input->evbit); 2347 + set_bit(ABS_X, wdata->extension.input->absbit); 2348 + set_bit(ABS_Y, wdata->extension.input->absbit); 2349 + set_bit(ABS_HAT0X, wdata->extension.input->absbit); 2350 + set_bit(ABS_HAT1X, wdata->extension.input->absbit); 2351 + input_set_abs_params(wdata->extension.input, 2352 + ABS_X, -32, 31, 1, 1); 2353 + input_set_abs_params(wdata->extension.input, 2354 + ABS_Y, -32, 31, 1, 1); 2355 + input_set_abs_params(wdata->extension.input, 2356 + ABS_HAT0X, 0, 0x1f, 1, 1); 2357 + input_set_abs_params(wdata->extension.input, 2358 + ABS_HAT1X, 0, 0x0f, 1, 1); 2359 + 2360 + ret = input_register_device(wdata->extension.input); 2361 + if (ret) 2362 + goto err_free; 2363 + 2364 + return 0; 2365 + 2366 + err_free: 2367 + input_free_device(wdata->extension.input); 2368 + wdata->extension.input = NULL; 2369 + return ret; 2370 + } 2371 + 2372 + static void wiimod_guitar_remove(const struct wiimod_ops *ops, 2373 + struct wiimote_data *wdata) 2374 + { 2375 + if (!wdata->extension.input) 2376 + return; 2377 + 2378 + input_unregister_device(wdata->extension.input); 2379 + wdata->extension.input = NULL; 2380 + } 2381 + 2382 + static const struct wiimod_ops wiimod_guitar = { 2383 + .flags = 0, 2384 + .arg = 0, 2385 + .probe = wiimod_guitar_probe, 2386 + .remove = wiimod_guitar_remove, 2387 + .in_ext = wiimod_guitar_in_ext, 2388 + }; 2389 + 2390 + /* 1953 2391 * Builtin Motion Plus 1954 2392 * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which 1955 2393 * disables polling for Motion-Plus. This should be set only for devices which ··· 2639 2201 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic, 2640 2202 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard, 2641 2203 [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro, 2204 + [WIIMOTE_EXT_DRUMS] = &wiimod_drums, 2205 + [WIIMOTE_EXT_GUITAR] = &wiimod_guitar, 2642 2206 };
+3
drivers/hid/hid-wiimote.h
··· 89 89 WIIMOTE_EXT_CLASSIC_CONTROLLER, 90 90 WIIMOTE_EXT_BALANCE_BOARD, 91 91 WIIMOTE_EXT_PRO_CONTROLLER, 92 + WIIMOTE_EXT_DRUMS, 93 + WIIMOTE_EXT_GUITAR, 92 94 WIIMOTE_EXT_NUM, 93 95 }; 94 96 ··· 139 137 /* calibration/cache data */ 140 138 __u16 calib_bboard[4][3]; 141 139 __s16 calib_pro_sticks[4]; 140 + __u8 pressure_drums[7]; 142 141 __u8 cache_rumble; 143 142 }; 144 143
+27 -30
drivers/hid/i2c-hid/i2c-hid.c
··· 1002 1002 return client->irq; 1003 1003 } 1004 1004 1005 - ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); 1005 + ihid = devm_kzalloc(&client->dev, sizeof(*ihid), GFP_KERNEL); 1006 1006 if (!ihid) 1007 1007 return -ENOMEM; 1008 1008 1009 1009 if (client->dev.of_node) { 1010 1010 ret = i2c_hid_of_probe(client, &ihid->pdata); 1011 1011 if (ret) 1012 - goto err; 1012 + return ret; 1013 1013 } else if (!platform_data) { 1014 1014 ret = i2c_hid_acpi_pdata(client, &ihid->pdata); 1015 1015 if (ret) 1016 - goto err; 1016 + return ret; 1017 1017 } else { 1018 1018 ihid->pdata = *platform_data; 1019 1019 } ··· 1021 1021 /* Parse platform agnostic common properties from ACPI / device tree */ 1022 1022 i2c_hid_fwnode_probe(client, &ihid->pdata); 1023 1023 1024 - ihid->pdata.supply = devm_regulator_get(&client->dev, "vdd"); 1025 - if (IS_ERR(ihid->pdata.supply)) { 1026 - ret = PTR_ERR(ihid->pdata.supply); 1027 - if (ret != -EPROBE_DEFER) 1028 - dev_err(&client->dev, "Failed to get regulator: %d\n", 1029 - ret); 1030 - goto err; 1031 - } 1024 + ihid->pdata.supplies[0].supply = "vdd"; 1025 + ihid->pdata.supplies[1].supply = "vddl"; 1032 1026 1033 - ret = regulator_enable(ihid->pdata.supply); 1034 - if (ret < 0) { 1035 - dev_err(&client->dev, "Failed to enable regulator: %d\n", 1036 - ret); 1037 - goto err; 1038 - } 1027 + ret = devm_regulator_bulk_get(&client->dev, 1028 + ARRAY_SIZE(ihid->pdata.supplies), 1029 + ihid->pdata.supplies); 1030 + if (ret) 1031 + return ret; 1032 + 1033 + ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies), 1034 + ihid->pdata.supplies); 1035 + if (ret < 0) 1036 + return ret; 1037 + 1039 1038 if (ihid->pdata.post_power_delay_ms) 1040 1039 msleep(ihid->pdata.post_power_delay_ms); 1041 1040 ··· 1121 1122 pm_runtime_disable(&client->dev); 1122 1123 1123 1124 err_regulator: 1124 - regulator_disable(ihid->pdata.supply); 1125 - 1126 - err: 1125 + regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), 1126 + ihid->pdata.supplies); 1127 1127 i2c_hid_free_buffers(ihid); 1128 - kfree(ihid); 1129 1128 return ret; 1130 1129 } 1131 1130 ··· 1145 1148 if (ihid->bufsize) 1146 1149 i2c_hid_free_buffers(ihid); 1147 1150 1148 - regulator_disable(ihid->pdata.supply); 1149 - 1150 - kfree(ihid); 1151 + regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), 1152 + ihid->pdata.supplies); 1151 1153 1152 1154 return 0; 1153 1155 } ··· 1197 1201 hid_warn(hid, "Failed to enable irq wake: %d\n", 1198 1202 wake_status); 1199 1203 } else { 1200 - ret = regulator_disable(ihid->pdata.supply); 1201 - if (ret < 0) 1202 - hid_warn(hid, "Failed to disable supply: %d\n", ret); 1204 + regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), 1205 + ihid->pdata.supplies); 1203 1206 } 1204 1207 1205 1208 return 0; ··· 1213 1218 int wake_status; 1214 1219 1215 1220 if (!device_may_wakeup(&client->dev)) { 1216 - ret = regulator_enable(ihid->pdata.supply); 1217 - if (ret < 0) 1218 - hid_warn(hid, "Failed to enable supply: %d\n", ret); 1221 + ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies), 1222 + ihid->pdata.supplies); 1223 + if (ret) 1224 + hid_warn(hid, "Failed to enable supplies: %d\n", ret); 1225 + 1219 1226 if (ihid->pdata.post_power_delay_ms) 1220 1227 msleep(ihid->pdata.post_power_delay_ms); 1221 1228 } else if (ihid->irq_wake_enabled) {
+6 -3
drivers/hid/intel-ish-hid/ipc/ipc.c
··· 907 907 struct ishtp_device *dev; 908 908 int i; 909 909 910 - dev = kzalloc(sizeof(struct ishtp_device) + sizeof(struct ish_hw), 911 - GFP_KERNEL); 910 + dev = devm_kzalloc(&pdev->dev, 911 + sizeof(struct ishtp_device) + sizeof(struct ish_hw), 912 + GFP_KERNEL); 912 913 if (!dev) 913 914 return NULL; 914 915 ··· 926 925 for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) { 927 926 struct wr_msg_ctl_info *tx_buf; 928 927 929 - tx_buf = kzalloc(sizeof(struct wr_msg_ctl_info), GFP_KERNEL); 928 + tx_buf = devm_kzalloc(&pdev->dev, 929 + sizeof(struct wr_msg_ctl_info), 930 + GFP_KERNEL); 930 931 if (!tx_buf) { 931 932 /* 932 933 * IPC buffers may be limited or not available
+11 -2
drivers/hid/intel-ish-hid/ipc/pci-ish.c
··· 95 95 return 0; 96 96 } 97 97 98 + static const struct pci_device_id ish_invalid_pci_ids[] = { 99 + /* Mehlow platform special pci ids */ 100 + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xA309)}, 101 + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xA30A)}, 102 + {} 103 + }; 104 + 98 105 /** 99 106 * ish_probe() - PCI driver probe callback 100 107 * @pdev: pci device ··· 116 109 struct ishtp_device *dev; 117 110 struct ish_hw *hw; 118 111 int ret; 112 + 113 + /* Check for invalid platforms for ISH support */ 114 + if (pci_dev_present(ish_invalid_pci_ids)) 115 + return -ENODEV; 119 116 120 117 /* enable pci dev */ 121 118 ret = pci_enable_device(pdev); ··· 183 172 free_irq(pdev->irq, dev); 184 173 free_device: 185 174 pci_iounmap(pdev, hw->mem_addr); 186 - kfree(dev); 187 175 release_regions: 188 176 pci_release_regions(pdev); 189 177 disable_device: ··· 212 202 pci_release_regions(pdev); 213 203 pci_clear_master(pdev); 214 204 pci_disable_device(pdev); 215 - kfree(ishtp_dev); 216 205 } 217 206 218 207 static struct device __maybe_unused *ish_resume_device;
-2
drivers/hid/intel-ish-hid/ishtp/hbm.c
··· 298 298 struct ishtp_msg_hdr *ishtp_hdr = &hdr; 299 299 const size_t len = sizeof(struct hbm_flow_control); 300 300 int rv; 301 - unsigned int num_frags; 302 301 unsigned long flags; 303 302 304 303 spin_lock_irqsave(&cl->fc_spinlock, flags); ··· 313 314 return 0; 314 315 } 315 316 316 - num_frags = cl->recv_msg_num_frags; 317 317 cl->recv_msg_num_frags = 0; 318 318 319 319 rv = ishtp_write_message(dev, ishtp_hdr, data);
+4 -3
drivers/hid/usbhid/hid-core.c
··· 480 480 { 481 481 struct hid_device *hid = urb->context; 482 482 struct usbhid_device *usbhid = hid->driver_data; 483 + unsigned long flags; 483 484 int unplug = 0, status = urb->status; 484 485 485 486 switch (status) { ··· 502 501 hid_warn(urb->dev, "ctrl urb status %d received\n", status); 503 502 } 504 503 505 - spin_lock(&usbhid->lock); 504 + spin_lock_irqsave(&usbhid->lock, flags); 506 505 507 506 if (unplug) { 508 507 usbhid->ctrltail = usbhid->ctrlhead; ··· 512 511 if (usbhid->ctrlhead != usbhid->ctrltail && 513 512 hid_submit_ctrl(hid) == 0) { 514 513 /* Successfully submitted next urb in queue */ 515 - spin_unlock(&usbhid->lock); 514 + spin_unlock_irqrestore(&usbhid->lock, flags); 516 515 return; 517 516 } 518 517 } 519 518 520 519 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); 521 - spin_unlock(&usbhid->lock); 520 + spin_unlock_irqrestore(&usbhid->lock, flags); 522 521 usb_autopm_put_interface_async(usbhid->intf); 523 522 wake_up(&usbhid->wait); 524 523 }
+59 -64
drivers/hid/wacom_sys.c
··· 210 210 return hidinput_calc_abs_res(&field, ABS_X); 211 211 } 212 212 213 + static void wacom_hid_usage_quirk(struct hid_device *hdev, 214 + struct hid_field *field, struct hid_usage *usage) 215 + { 216 + struct wacom *wacom = hid_get_drvdata(hdev); 217 + struct wacom_features *features = &wacom->wacom_wac.features; 218 + unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); 219 + 220 + /* 221 + * The Dell Canvas 27 needs to be switched to its vendor-defined 222 + * report to provide the best resolution. 223 + */ 224 + if (hdev->vendor == USB_VENDOR_ID_WACOM && 225 + hdev->product == 0x4200 && 226 + field->application == HID_UP_MSVENDOR) { 227 + wacom->wacom_wac.mode_report = field->report->id; 228 + wacom->wacom_wac.mode_value = 2; 229 + } 230 + 231 + /* 232 + * ISDv4 devices which predate HID's adoption of the 233 + * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its 234 + * position instead. We can accurately detect if a 235 + * usage with that value should be HID_DG_BARRELSWITCH2 236 + * based on the surrounding usages, which have remained 237 + * constant across generations. 238 + */ 239 + if (features->type == HID_GENERIC && 240 + usage->hid == 0x000D0000 && 241 + field->application == HID_DG_PEN && 242 + field->physical == HID_DG_STYLUS) { 243 + int i = usage->usage_index; 244 + 245 + if (i-4 >= 0 && i+1 < field->maxusage && 246 + field->usage[i-4].hid == HID_DG_TIPSWITCH && 247 + field->usage[i-3].hid == HID_DG_BARRELSWITCH && 248 + field->usage[i-2].hid == HID_DG_ERASER && 249 + field->usage[i-1].hid == HID_DG_INVERT && 250 + field->usage[i+1].hid == HID_DG_INRANGE) { 251 + usage->hid = HID_DG_BARRELSWITCH2; 252 + } 253 + } 254 + 255 + /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ 256 + if (hdev->vendor == USB_VENDOR_ID_WACOM && 257 + hdev->product == 0x0358 && 258 + WACOM_PEN_FIELD(field) && 259 + equivalent_usage == HID_GD_Y) { 260 + field->logical_maximum = 43200; 261 + } 262 + } 263 + 213 264 static void wacom_feature_mapping(struct hid_device *hdev, 214 265 struct hid_field *field, struct hid_usage *usage) 215 266 { ··· 271 220 u8 *data; 272 221 int ret; 273 222 u32 n; 223 + 224 + wacom_hid_usage_quirk(hdev, field, usage); 274 225 275 226 switch (equivalent_usage) { 276 227 case HID_DG_CONTACTMAX: ··· 353 300 kfree(data); 354 301 break; 355 302 } 356 - 357 - if (hdev->vendor == USB_VENDOR_ID_WACOM && 358 - hdev->product == 0x4200 /* Dell Canvas 27 */ && 359 - field->application == HID_UP_MSVENDOR) { 360 - wacom->wacom_wac.mode_report = field->report->id; 361 - wacom->wacom_wac.mode_value = 2; 362 - } 363 303 } 364 304 365 305 /* ··· 394 348 struct wacom_features *features = &wacom->wacom_wac.features; 395 349 bool finger = WACOM_FINGER_FIELD(field); 396 350 bool pen = WACOM_PEN_FIELD(field); 351 + unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); 397 352 398 353 /* 399 354 * Requiring Stylus Usage will ignore boot mouse ··· 408 361 else 409 362 return; 410 363 411 - /* 412 - * Bamboo models do not support HID_DG_CONTACTMAX. 413 - * And, Bamboo Pen only descriptor contains touch. 414 - */ 415 - if (features->type > BAMBOO_PT) { 416 - /* ISDv4 touch devices at least supports one touch point */ 417 - if (finger && !features->touch_max) 418 - features->touch_max = 1; 419 - } 364 + wacom_hid_usage_quirk(hdev, field, usage); 420 365 421 - /* 422 - * ISDv4 devices which predate HID's adoption of the 423 - * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its 424 - * position instead. We can accurately detect if a 425 - * usage with that value should be HID_DG_BARRELSWITCH2 426 - * based on the surrounding usages, which have remained 427 - * constant across generations. 428 - */ 429 - if (features->type == HID_GENERIC && 430 - usage->hid == 0x000D0000 && 431 - field->application == HID_DG_PEN && 432 - field->physical == HID_DG_STYLUS) { 433 - int i = usage->usage_index; 434 - 435 - if (i-4 >= 0 && i+1 < field->maxusage && 436 - field->usage[i-4].hid == HID_DG_TIPSWITCH && 437 - field->usage[i-3].hid == HID_DG_BARRELSWITCH && 438 - field->usage[i-2].hid == HID_DG_ERASER && 439 - field->usage[i-1].hid == HID_DG_INVERT && 440 - field->usage[i+1].hid == HID_DG_INRANGE) { 441 - usage->hid = HID_DG_BARRELSWITCH2; 442 - } 443 - } 444 - 445 - /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ 446 - if (hdev->vendor == USB_VENDOR_ID_WACOM && 447 - hdev->product == 0x0358 && 448 - WACOM_PEN_FIELD(field) && 449 - wacom_equivalent_usage(usage->hid) == HID_GD_Y) { 450 - field->logical_maximum = 43200; 451 - } 452 - 453 - switch (usage->hid) { 366 + switch (equivalent_usage) { 454 367 case HID_GD_X: 455 368 features->x_max = field->logical_maximum; 456 369 if (finger) { ··· 710 703 static LIST_HEAD(wacom_udev_list); 711 704 static DEFINE_MUTEX(wacom_udev_list_lock); 712 705 713 - static bool compare_device_paths(struct hid_device *hdev_a, 714 - struct hid_device *hdev_b, char separator) 715 - { 716 - int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys; 717 - int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys; 718 - 719 - if (n1 != n2 || n1 <= 0 || n2 <= 0) 720 - return false; 721 - 722 - return !strncmp(hdev_a->phys, hdev_b->phys, n1); 723 - } 724 - 725 706 static bool wacom_are_sibling(struct hid_device *hdev, 726 707 struct hid_device *sibling) 727 708 { ··· 732 737 * the same physical parent device path. 733 738 */ 734 739 if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) { 735 - if (!compare_device_paths(hdev, sibling, '/')) 740 + if (!hid_compare_device_paths(hdev, sibling, '/')) 736 741 return false; 737 742 } else { 738 - if (!compare_device_paths(hdev, sibling, '.')) 743 + if (!hid_compare_device_paths(hdev, sibling, '.')) 739 744 return false; 740 745 } 741 746 ··· 782 787 783 788 /* Try to find an already-probed interface from the same device */ 784 789 list_for_each_entry(data, &wacom_udev_list, list) { 785 - if (compare_device_paths(hdev, data->dev, '/')) { 790 + if (hid_compare_device_paths(hdev, data->dev, '/')) { 786 791 kref_get(&data->kref); 787 792 return data; 788 793 }
+10 -10
drivers/hid/wacom_wac.c
··· 4357 4357 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE }; 4358 4358 static const struct wacom_features wacom_features_0x90 = 4359 4359 { "Wacom ISDv4 90", 26202, 16325, 255, 0, 4360 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4360 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */ 4361 4361 static const struct wacom_features wacom_features_0x93 = 4362 4362 { "Wacom ISDv4 93", 26202, 16325, 255, 0, 4363 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4363 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 }; 4364 4364 static const struct wacom_features wacom_features_0x97 = 4365 4365 { "Wacom ISDv4 97", 26202, 16325, 511, 0, 4366 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4366 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */ 4367 4367 static const struct wacom_features wacom_features_0x9A = 4368 4368 { "Wacom ISDv4 9A", 26202, 16325, 255, 0, 4369 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4369 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 }; 4370 4370 static const struct wacom_features wacom_features_0x9F = 4371 4371 { "Wacom ISDv4 9F", 26202, 16325, 255, 0, 4372 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4372 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 }; 4373 4373 static const struct wacom_features wacom_features_0xE2 = 4374 4374 { "Wacom ISDv4 E2", 26202, 16325, 255, 0, 4375 4375 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 }; ··· 4384 4384 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 }; 4385 4385 static const struct wacom_features wacom_features_0xEC = 4386 4386 { "Wacom ISDv4 EC", 25710, 14500, 255, 0, 4387 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4387 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */ 4388 4388 static const struct wacom_features wacom_features_0xED = 4389 4389 { "Wacom ISDv4 ED", 26202, 16325, 255, 0, 4390 - TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4390 + TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 }; 4391 4391 static const struct wacom_features wacom_features_0xEF = 4392 4392 { "Wacom ISDv4 EF", 26202, 16325, 255, 0, 4393 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4393 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */ 4394 4394 static const struct wacom_features wacom_features_0x100 = 4395 4395 { "Wacom ISDv4 100", 26202, 16325, 255, 0, 4396 4396 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; ··· 4408 4408 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4409 4409 static const struct wacom_features wacom_features_0x116 = 4410 4410 { "Wacom ISDv4 116", 26202, 16325, 255, 0, 4411 - TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4411 + TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 }; 4412 4412 static const struct wacom_features wacom_features_0x12C = 4413 4413 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0, 4414 - TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 4414 + TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */ 4415 4415 static const struct wacom_features wacom_features_0x4001 = 4416 4416 { "Wacom ISDv4 4001", 26202, 16325, 255, 0, 4417 4417 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
+13 -4
include/linux/hid.h
··· 190 190 * http://www.usb.org/developers/hidpage/HUTRR40RadioHIDUsagesFinal.pdf 191 191 */ 192 192 #define HID_GD_WIRELESS_RADIO_CTLS 0x0001000c 193 + /* 194 + * System Multi-Axis, see: 195 + * http://www.usb.org/developers/hidpage/HUTRR62_-_Generic_Desktop_CA_for_System_Multi-Axis_Controllers.txt 196 + */ 197 + #define HID_GD_SYSTEM_MULTIAXIS 0x0001000e 198 + 193 199 #define HID_GD_X 0x00010030 194 200 #define HID_GD_Y 0x00010031 195 201 #define HID_GD_Z 0x00010032 ··· 644 638 struct hid_parser { 645 639 struct hid_global global; 646 640 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE]; 647 - unsigned global_stack_ptr; 641 + unsigned int global_stack_ptr; 648 642 struct hid_local local; 649 - unsigned collection_stack[HID_COLLECTION_STACK_SIZE]; 650 - unsigned collection_stack_ptr; 643 + unsigned int *collection_stack; 644 + unsigned int collection_stack_ptr; 645 + unsigned int collection_stack_size; 651 646 struct hid_device *device; 652 - unsigned scan_flags; 647 + unsigned int scan_flags; 653 648 }; 654 649 655 650 struct hid_class_descriptor { ··· 901 894 const struct hid_device_id *id); 902 895 const struct hid_device_id *hid_match_device(struct hid_device *hdev, 903 896 struct hid_driver *hdrv); 897 + bool hid_compare_device_paths(struct hid_device *hdev_a, 898 + struct hid_device *hdev_b, char separator); 904 899 s32 hid_snto32(__u32 value, unsigned n); 905 900 __u32 hid_field_extract(const struct hid_device *hid, __u8 *report, 906 901 unsigned offset, unsigned n);
+3 -4
include/linux/platform_data/i2c-hid.h
··· 12 12 #ifndef __LINUX_I2C_HID_H 13 13 #define __LINUX_I2C_HID_H 14 14 15 + #include <linux/regulator/consumer.h> 15 16 #include <linux/types.h> 16 - 17 - struct regulator; 18 17 19 18 /** 20 19 * struct i2chid_platform_data - used by hid over i2c implementation. 21 20 * @hid_descriptor_address: i2c register where the HID descriptor is stored. 22 - * @supply: regulator for powering on the device. 21 + * @supplies: regulators for powering on the device. 23 22 * @post_power_delay_ms: delay after powering on before device is usable. 24 23 * 25 24 * Note that it is the responsibility of the platform driver (or the acpi 5.0 ··· 34 35 */ 35 36 struct i2c_hid_platform_data { 36 37 u16 hid_descriptor_address; 37 - struct regulator *supply; 38 + struct regulator_bulk_data supplies[2]; 38 39 int post_power_delay_ms; 39 40 }; 40 41
+5 -4
include/uapi/linux/input.h
··· 270 270 /* 271 271 * MT_TOOL types 272 272 */ 273 - #define MT_TOOL_FINGER 0 274 - #define MT_TOOL_PEN 1 275 - #define MT_TOOL_PALM 2 276 - #define MT_TOOL_MAX 2 273 + #define MT_TOOL_FINGER 0x00 274 + #define MT_TOOL_PEN 0x01 275 + #define MT_TOOL_PALM 0x02 276 + #define MT_TOOL_DIAL 0x0a 277 + #define MT_TOOL_MAX 0x0f 277 278 278 279 /* 279 280 * Values describing the status of a force-feedback effect