diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-20 18:59:01 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-08-20 18:59:01 -0400 |
| commit | 7a324b3f0535ceb0f6676fa20ca2a7b6213008cb (patch) | |
| tree | 4c03a2f9382ee8264ddbe79a60293f825364fac3 | |
| parent | 61c4fc1eaf736344904767d201b0d4f7a2ebaf79 (diff) | |
| parent | 1429b47bfe98e63421d207aaae8038809c3f90ce (diff) | |
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
...
27 files changed, 1824 insertions, 748 deletions
diff --git a/Documentation/devicetree/bindings/input/hid-over-i2c.txt b/Documentation/devicetree/bindings/input/hid-over-i2c.txt index f1cb9f8d7692..c76bafaf98d2 100644 --- a/Documentation/devicetree/bindings/input/hid-over-i2c.txt +++ b/Documentation/devicetree/bindings/input/hid-over-i2c.txt | |||
| @@ -25,7 +25,8 @@ device-specific compatible properties, which should be used in addition to the | |||
| 25 | 25 | ||
| 26 | - compatible: | 26 | - compatible: |
| 27 | * "wacom,w9013" (Wacom W9013 digitizer). Supports: | 27 | * "wacom,w9013" (Wacom W9013 digitizer). Supports: |
| 28 | - vdd-supply | 28 | - vdd-supply (3.3V) |
| 29 | - vddl-supply (1.8V) | ||
| 29 | - post-power-on-delay-ms | 30 | - post-power-on-delay-ms |
| 30 | 31 | ||
| 31 | - vdd-supply: phandle of the regulator that provides the supply voltage. | 32 | - vdd-supply: phandle of the regulator that provides the supply voltage. |
diff --git a/Documentation/input/multi-touch-protocol.rst b/Documentation/input/multi-touch-protocol.rst index b51751a0cd5d..6be70342e709 100644 --- a/Documentation/input/multi-touch-protocol.rst +++ b/Documentation/input/multi-touch-protocol.rst | |||
| @@ -310,12 +310,12 @@ ABS_MT_TOOL_Y | |||
| 310 | ABS_MT_TOOL_TYPE | 310 | ABS_MT_TOOL_TYPE |
| 311 | The type of approaching tool. A lot of kernel drivers cannot distinguish | 311 | The type of approaching tool. A lot of kernel drivers cannot distinguish |
| 312 | between different tool types, such as a finger or a pen. In such cases, the | 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, | 313 | event should be omitted. The protocol currently mainly supports |
| 314 | MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_. For type B devices, this event is | 314 | MT_TOOL_FINGER, MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_. |
| 315 | handled by input core; drivers should instead use | 315 | For type B devices, this event is handled by input core; drivers should |
| 316 | input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may change over | 316 | instead use input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may |
| 317 | time while still touching the device, because the firmware may not be able | 317 | change over time while still touching the device, because the firmware may |
| 318 | to determine which tool is being used when it first appears. | 318 | not be able to determine which tool is being used when it first appears. |
| 319 | 319 | ||
| 320 | ABS_MT_BLOB_ID | 320 | ABS_MT_BLOB_ID |
| 321 | The BLOB_ID groups several packets together into one arbitrarily shaped | 321 | The BLOB_ID groups several packets together into one arbitrarily shaped |
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index a49a10437c40..61e1953ff921 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
| @@ -207,6 +207,16 @@ config HID_CORSAIR | |||
| 207 | - Vengeance K90 | 207 | - Vengeance K90 |
| 208 | - Scimitar PRO RGB | 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 | config HID_PRODIKEYS | 220 | config HID_PRODIKEYS |
| 211 | tristate "Prodikeys PC-MIDI Keyboard support" | 221 | tristate "Prodikeys PC-MIDI Keyboard support" |
| 212 | depends on HID && SND | 222 | depends on HID && SND |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 511e1cbff768..bd7ac53b75c5 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
| @@ -35,6 +35,7 @@ obj-$(CONFIG_HID_CHERRY) += hid-cherry.o | |||
| 35 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o | 35 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o |
| 36 | obj-$(CONFIG_HID_CMEDIA) += hid-cmedia.o | 36 | obj-$(CONFIG_HID_CMEDIA) += hid-cmedia.o |
| 37 | obj-$(CONFIG_HID_CORSAIR) += hid-corsair.o | 37 | obj-$(CONFIG_HID_CORSAIR) += hid-corsair.o |
| 38 | obj-$(CONFIG_HID_COUGAR) += hid-cougar.o | ||
| 38 | obj-$(CONFIG_HID_CP2112) += hid-cp2112.o | 39 | obj-$(CONFIG_HID_CP2112) += hid-cp2112.o |
| 39 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o | 40 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o |
| 40 | obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o | 41 | obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o |
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 3942ee61bd1c..3da354af7a0a 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
| @@ -128,9 +128,19 @@ static int open_collection(struct hid_parser *parser, unsigned type) | |||
| 128 | 128 | ||
| 129 | usage = parser->local.usage[0]; | 129 | usage = parser->local.usage[0]; |
| 130 | 130 | ||
| 131 | if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { | 131 | if (parser->collection_stack_ptr == parser->collection_stack_size) { |
| 132 | hid_err(parser->device, "collection stack overflow\n"); | 132 | unsigned int *collection_stack; |
| 133 | return -EINVAL; | 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 | if (parser->device->maxcollection == parser->device->collection_size) { | 146 | if (parser->device->maxcollection == parser->device->collection_size) { |
| @@ -840,6 +850,7 @@ static int hid_scan_report(struct hid_device *hid) | |||
| 840 | break; | 850 | break; |
| 841 | } | 851 | } |
| 842 | 852 | ||
| 853 | kfree(parser->collection_stack); | ||
| 843 | vfree(parser); | 854 | vfree(parser); |
| 844 | return 0; | 855 | return 0; |
| 845 | } | 856 | } |
| @@ -1939,6 +1950,29 @@ static int hid_bus_match(struct device *dev, struct device_driver *drv) | |||
| 1939 | return hid_match_device(hdev, hdrv) != NULL; | 1950 | return hid_match_device(hdev, hdrv) != NULL; |
| 1940 | } | 1951 | } |
| 1941 | 1952 | ||
| 1953 | /** | ||
| 1954 | * hid_compare_device_paths - check if both devices share the same path | ||
| 1955 | * @hdev_a: hid device | ||
| 1956 | * @hdev_b: hid device | ||
| 1957 | * @separator: char to use as separator | ||
| 1958 | * | ||
| 1959 | * Check if two devices share the same path up to the last occurrence of | ||
| 1960 | * the separator char. Both paths must exist (i.e., zero-length paths | ||
| 1961 | * don't match). | ||
| 1962 | */ | ||
| 1963 | bool hid_compare_device_paths(struct hid_device *hdev_a, | ||
| 1964 | struct hid_device *hdev_b, char separator) | ||
| 1965 | { | ||
| 1966 | int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys; | ||
| 1967 | int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys; | ||
| 1968 | |||
| 1969 | if (n1 != n2 || n1 <= 0 || n2 <= 0) | ||
| 1970 | return false; | ||
| 1971 | |||
| 1972 | return !strncmp(hdev_a->phys, hdev_b->phys, n1); | ||
| 1973 | } | ||
| 1974 | EXPORT_SYMBOL_GPL(hid_compare_device_paths); | ||
| 1975 | |||
| 1942 | static int hid_device_probe(struct device *dev) | 1976 | static int hid_device_probe(struct device *dev) |
| 1943 | { | 1977 | { |
| 1944 | struct hid_driver *hdrv = to_hid_driver(dev->driver); | 1978 | struct hid_driver *hdrv = to_hid_driver(dev->driver); |
diff --git a/drivers/hid/hid-cougar.c b/drivers/hid/hid-cougar.c new file mode 100644 index 000000000000..ad2e87de7dc5 --- /dev/null +++ b/drivers/hid/hid-cougar.c | |||
| @@ -0,0 +1,312 @@ | |||
| 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); | ||
diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index 803a725785cf..07e26c3567eb 100644 --- a/drivers/hid/hid-elan.c +++ b/drivers/hid/hid-elan.c | |||
| @@ -19,38 +19,49 @@ | |||
| 19 | 19 | ||
| 20 | #include "hid-ids.h" | 20 | #include "hid-ids.h" |
| 21 | 21 | ||
| 22 | #define ELAN_MT_I2C 0x5d | ||
| 22 | #define ELAN_SINGLE_FINGER 0x81 | 23 | #define ELAN_SINGLE_FINGER 0x81 |
| 23 | #define ELAN_MT_FIRST_FINGER 0x82 | 24 | #define ELAN_MT_FIRST_FINGER 0x82 |
| 24 | #define ELAN_MT_SECOND_FINGER 0x83 | 25 | #define ELAN_MT_SECOND_FINGER 0x83 |
| 25 | #define ELAN_INPUT_REPORT_SIZE 8 | 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 | #define ELAN_MUTE_LED_REPORT 0xBC | 39 | #define ELAN_MUTE_LED_REPORT 0xBC |
| 28 | #define ELAN_LED_REPORT_SIZE 8 | 40 | #define ELAN_LED_REPORT_SIZE 8 |
| 29 | 41 | ||
| 30 | struct elan_touchpad_settings { | 42 | #define ELAN_HAS_LED BIT(0) |
| 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 | }; | ||
| 39 | 43 | ||
| 40 | struct elan_drvdata { | 44 | struct elan_drvdata { |
| 41 | struct input_dev *input; | 45 | struct input_dev *input; |
| 42 | u8 prev_report[ELAN_INPUT_REPORT_SIZE]; | 46 | u8 prev_report[ELAN_INPUT_REPORT_SIZE]; |
| 43 | struct led_classdev mute_led; | 47 | struct led_classdev mute_led; |
| 44 | u8 mute_led_state; | 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 | static int is_not_elan_touchpad(struct hid_device *hdev) | 55 | static int is_not_elan_touchpad(struct hid_device *hdev) |
| 49 | { | 56 | { |
| 50 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | 57 | if (hdev->bus == BUS_USB) { |
| 51 | struct elan_drvdata *drvdata = hid_get_drvdata(hdev); | 58 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 59 | |||
| 60 | return (intf->altsetting->desc.bInterfaceNumber != | ||
| 61 | ELAN_TP_USB_INTF); | ||
| 62 | } | ||
| 52 | 63 | ||
| 53 | return (intf->altsetting->desc.bInterfaceNumber != drvdata->settings->usb_bInterfaceNumber); | 64 | return 0; |
| 54 | } | 65 | } |
| 55 | 66 | ||
| 56 | static int elan_input_mapping(struct hid_device *hdev, struct hid_input *hi, | 67 | static int elan_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| @@ -62,12 +73,86 @@ static int elan_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 62 | 73 | ||
| 63 | if (field->report->id == ELAN_SINGLE_FINGER || | 74 | if (field->report->id == ELAN_SINGLE_FINGER || |
| 64 | field->report->id == ELAN_MT_FIRST_FINGER || | 75 | field->report->id == ELAN_MT_FIRST_FINGER || |
| 65 | field->report->id == ELAN_MT_SECOND_FINGER) | 76 | field->report->id == ELAN_MT_SECOND_FINGER || |
| 77 | field->report->id == ELAN_MT_I2C) | ||
| 66 | return -1; | 78 | return -1; |
| 67 | 79 | ||
| 68 | return 0; | 80 | return 0; |
| 69 | } | 81 | } |
| 70 | 82 | ||
| 83 | static int elan_get_device_param(struct hid_device *hdev, | ||
| 84 | unsigned char *dmabuf, unsigned char param) | ||
| 85 | { | ||
| 86 | int ret; | ||
| 87 | |||
| 88 | dmabuf[0] = ELAN_FEATURE_REPORT; | ||
| 89 | dmabuf[1] = 0x05; | ||
| 90 | dmabuf[2] = 0x03; | ||
| 91 | dmabuf[3] = param; | ||
| 92 | dmabuf[4] = 0x01; | ||
| 93 | |||
| 94 | ret = hid_hw_raw_request(hdev, ELAN_FEATURE_REPORT, dmabuf, | ||
| 95 | ELAN_FEATURE_SIZE, HID_FEATURE_REPORT, | ||
| 96 | HID_REQ_SET_REPORT); | ||
| 97 | if (ret != ELAN_FEATURE_SIZE) { | ||
| 98 | hid_err(hdev, "Set report error for parm %d: %d\n", param, ret); | ||
| 99 | return ret; | ||
| 100 | } | ||
| 101 | |||
| 102 | ret = hid_hw_raw_request(hdev, ELAN_FEATURE_REPORT, dmabuf, | ||
| 103 | ELAN_FEATURE_SIZE, HID_FEATURE_REPORT, | ||
| 104 | HID_REQ_GET_REPORT); | ||
| 105 | if (ret != ELAN_FEATURE_SIZE) { | ||
| 106 | hid_err(hdev, "Get report error for parm %d: %d\n", param, ret); | ||
| 107 | return ret; | ||
| 108 | } | ||
| 109 | |||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | static unsigned int elan_convert_res(char val) | ||
| 114 | { | ||
| 115 | /* | ||
| 116 | * (value from firmware) * 10 + 790 = dpi | ||
| 117 | * dpi * 10 / 254 = dots/mm | ||
| 118 | */ | ||
| 119 | return (val * 10 + 790) * 10 / 254; | ||
| 120 | } | ||
| 121 | |||
| 122 | static int elan_get_device_params(struct hid_device *hdev) | ||
| 123 | { | ||
| 124 | struct elan_drvdata *drvdata = hid_get_drvdata(hdev); | ||
| 125 | unsigned char *dmabuf; | ||
| 126 | int ret; | ||
| 127 | |||
| 128 | dmabuf = kmalloc(ELAN_FEATURE_SIZE, GFP_KERNEL); | ||
| 129 | if (!dmabuf) | ||
| 130 | return -ENOMEM; | ||
| 131 | |||
| 132 | ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_MAX_X); | ||
| 133 | if (ret) | ||
| 134 | goto err; | ||
| 135 | |||
| 136 | drvdata->max_x = (dmabuf[4] << 8) | dmabuf[3]; | ||
| 137 | |||
| 138 | ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_MAX_Y); | ||
| 139 | if (ret) | ||
| 140 | goto err; | ||
| 141 | |||
| 142 | drvdata->max_y = (dmabuf[4] << 8) | dmabuf[3]; | ||
| 143 | |||
| 144 | ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_RES); | ||
| 145 | if (ret) | ||
| 146 | goto err; | ||
| 147 | |||
| 148 | drvdata->res_x = elan_convert_res(dmabuf[3]); | ||
| 149 | drvdata->res_y = elan_convert_res(dmabuf[4]); | ||
| 150 | |||
| 151 | err: | ||
| 152 | kfree(dmabuf); | ||
| 153 | return ret; | ||
| 154 | } | ||
| 155 | |||
| 71 | static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) | 156 | static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) |
| 72 | { | 157 | { |
| 73 | int ret; | 158 | int ret; |
| @@ -77,6 +162,10 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
| 77 | if (is_not_elan_touchpad(hdev)) | 162 | if (is_not_elan_touchpad(hdev)) |
| 78 | return 0; | 163 | return 0; |
| 79 | 164 | ||
| 165 | ret = elan_get_device_params(hdev); | ||
| 166 | if (ret) | ||
| 167 | return ret; | ||
| 168 | |||
| 80 | input = devm_input_allocate_device(&hdev->dev); | 169 | input = devm_input_allocate_device(&hdev->dev); |
| 81 | if (!input) | 170 | if (!input) |
| 82 | return -ENOMEM; | 171 | return -ENOMEM; |
| @@ -90,25 +179,25 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
| 90 | input->id.version = hdev->version; | 179 | input->id.version = hdev->version; |
| 91 | input->dev.parent = &hdev->dev; | 180 | input->dev.parent = &hdev->dev; |
| 92 | 181 | ||
| 93 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, | 182 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, drvdata->max_x, |
| 94 | drvdata->settings->max_x, 0, 0); | 183 | 0, 0); |
| 95 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, | 184 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, drvdata->max_y, |
| 96 | drvdata->settings->max_y, 0, 0); | 185 | 0, 0); |
| 97 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, | 186 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, ELAN_MAX_PRESSURE, |
| 98 | drvdata->settings->max_fingers, 0, 0); | 187 | 0, 0); |
| 99 | input_set_abs_params(input, ABS_TOOL_WIDTH, 0, | ||
| 100 | drvdata->settings->max_w, 0, 0); | ||
| 101 | 188 | ||
| 102 | __set_bit(BTN_LEFT, input->keybit); | 189 | __set_bit(BTN_LEFT, input->keybit); |
| 103 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); | 190 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
| 104 | 191 | ||
| 105 | ret = input_mt_init_slots(input, drvdata->settings->max_fingers, | 192 | ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER); |
| 106 | INPUT_MT_POINTER); | ||
| 107 | if (ret) { | 193 | if (ret) { |
| 108 | hid_err(hdev, "Failed to init elan MT slots: %d\n", ret); | 194 | hid_err(hdev, "Failed to init elan MT slots: %d\n", ret); |
| 109 | return ret; | 195 | return ret; |
| 110 | } | 196 | } |
| 111 | 197 | ||
| 198 | input_abs_set_res(input, ABS_X, drvdata->res_x); | ||
| 199 | input_abs_set_res(input, ABS_Y, drvdata->res_y); | ||
| 200 | |||
| 112 | ret = input_register_device(input); | 201 | ret = input_register_device(input); |
| 113 | if (ret) { | 202 | if (ret) { |
| 114 | hid_err(hdev, "Failed to register elan input device: %d\n", | 203 | hid_err(hdev, "Failed to register elan input device: %d\n", |
| @@ -126,7 +215,7 @@ static void elan_report_mt_slot(struct elan_drvdata *drvdata, u8 *data, | |||
| 126 | unsigned int slot_num) | 215 | unsigned int slot_num) |
| 127 | { | 216 | { |
| 128 | struct input_dev *input = drvdata->input; | 217 | struct input_dev *input = drvdata->input; |
| 129 | int x, y, w; | 218 | int x, y, p; |
| 130 | 219 | ||
| 131 | bool active = !!data; | 220 | bool active = !!data; |
| 132 | 221 | ||
| @@ -134,17 +223,17 @@ static void elan_report_mt_slot(struct elan_drvdata *drvdata, u8 *data, | |||
| 134 | input_mt_report_slot_state(input, MT_TOOL_FINGER, active); | 223 | input_mt_report_slot_state(input, MT_TOOL_FINGER, active); |
| 135 | if (active) { | 224 | if (active) { |
| 136 | x = ((data[0] & 0xF0) << 4) | data[1]; | 225 | x = ((data[0] & 0xF0) << 4) | data[1]; |
| 137 | y = drvdata->settings->max_y - | 226 | y = drvdata->max_y - |
| 138 | (((data[0] & 0x07) << 8) | data[2]); | 227 | (((data[0] & 0x07) << 8) | data[2]); |
| 139 | w = data[4]; | 228 | p = data[4]; |
| 140 | 229 | ||
| 141 | input_report_abs(input, ABS_MT_POSITION_X, x); | 230 | input_report_abs(input, ABS_MT_POSITION_X, x); |
| 142 | input_report_abs(input, ABS_MT_POSITION_Y, y); | 231 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
| 143 | input_report_abs(input, ABS_TOOL_WIDTH, w); | 232 | input_report_abs(input, ABS_MT_PRESSURE, p); |
| 144 | } | 233 | } |
| 145 | } | 234 | } |
| 146 | 235 | ||
| 147 | static void elan_report_input(struct elan_drvdata *drvdata, u8 *data) | 236 | static void elan_usb_report_input(struct elan_drvdata *drvdata, u8 *data) |
| 148 | { | 237 | { |
| 149 | int i; | 238 | int i; |
| 150 | struct input_dev *input = drvdata->input; | 239 | struct input_dev *input = drvdata->input; |
| @@ -162,7 +251,7 @@ static void elan_report_input(struct elan_drvdata *drvdata, u8 *data) | |||
| 162 | * byte 5: x8 x7 x6 x5 x4 x3 x2 x1 | 251 | * byte 5: x8 x7 x6 x5 x4 x3 x2 x1 |
| 163 | * byte 6: y8 y7 y6 y5 y4 y3 y2 y1 | 252 | * byte 6: y8 y7 y6 y5 y4 y3 y2 y1 |
| 164 | * byte 7: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 | 253 | * byte 7: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 |
| 165 | * byte 8: w8 w7 w6 w5 w4 w3 w2 w1 | 254 | * byte 8: p8 p7 p6 p5 p4 p3 p2 p1 |
| 166 | * | 255 | * |
| 167 | * packet structure for ELAN_MT_SECOND_FINGER: | 256 | * packet structure for ELAN_MT_SECOND_FINGER: |
| 168 | * | 257 | * |
| @@ -171,19 +260,21 @@ static void elan_report_input(struct elan_drvdata *drvdata, u8 *data) | |||
| 171 | * byte 3: x8 x7 x6 x5 x4 x3 x2 x1 | 260 | * byte 3: x8 x7 x6 x5 x4 x3 x2 x1 |
| 172 | * byte 4: y8 y7 y6 y5 y4 y3 y2 y1 | 261 | * byte 4: y8 y7 y6 y5 y4 y3 y2 y1 |
| 173 | * byte 5: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 | 262 | * byte 5: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 |
| 174 | * byte 6: w8 w7 w6 w5 w4 w3 w2 w1 | 263 | * byte 6: p8 p7 p6 p5 p4 p3 p2 p1 |
| 175 | * byte 7: 0 0 0 0 0 0 0 0 | 264 | * byte 7: 0 0 0 0 0 0 0 0 |
| 176 | * byte 8: 0 0 0 0 0 0 0 0 | 265 | * byte 8: 0 0 0 0 0 0 0 0 |
| 177 | * | 266 | * |
| 178 | * f5-f1: finger touch bits | 267 | * f5-f1: finger touch bits |
| 179 | * L: clickpad button | 268 | * L: clickpad button |
| 180 | * sy / sx: not sure yet, but this looks like rectangular | 269 | * sy / sx: finger width / height expressed in traces, the total number |
| 181 | * area for finger | 270 | * of traces can be queried by doing a HID_REQ_SET_REPORT |
| 182 | * w: looks like finger width | 271 | * { 0x0d, 0x05, 0x03, 0x05, 0x01 } followed by a GET, in the |
| 272 | * returned buf, buf[3]=no-x-traces, buf[4]=no-y-traces. | ||
| 273 | * p: pressure | ||
| 183 | */ | 274 | */ |
| 184 | 275 | ||
| 185 | if (data[0] == ELAN_SINGLE_FINGER) { | 276 | if (data[0] == ELAN_SINGLE_FINGER) { |
| 186 | for (i = 0; i < drvdata->settings->max_fingers; i++) { | 277 | for (i = 0; i < ELAN_MAX_FINGERS; i++) { |
| 187 | if (data[2] & BIT(i + 3)) | 278 | if (data[2] & BIT(i + 3)) |
| 188 | elan_report_mt_slot(drvdata, data + 3, i); | 279 | elan_report_mt_slot(drvdata, data + 3, i); |
| 189 | else | 280 | else |
| @@ -210,7 +301,7 @@ static void elan_report_input(struct elan_drvdata *drvdata, u8 *data) | |||
| 210 | if (prev_report[0] != ELAN_MT_FIRST_FINGER) | 301 | if (prev_report[0] != ELAN_MT_FIRST_FINGER) |
| 211 | return; | 302 | return; |
| 212 | 303 | ||
| 213 | for (i = 0; i < drvdata->settings->max_fingers; i++) { | 304 | for (i = 0; i < ELAN_MAX_FINGERS; i++) { |
| 214 | if (prev_report[2] & BIT(i + 3)) { | 305 | if (prev_report[2] & BIT(i + 3)) { |
| 215 | if (!first) { | 306 | if (!first) { |
| 216 | first = 1; | 307 | first = 1; |
| @@ -229,6 +320,46 @@ static void elan_report_input(struct elan_drvdata *drvdata, u8 *data) | |||
| 229 | input_sync(input); | 320 | input_sync(input); |
| 230 | } | 321 | } |
| 231 | 322 | ||
| 323 | static void elan_i2c_report_input(struct elan_drvdata *drvdata, u8 *data) | ||
| 324 | { | ||
| 325 | struct input_dev *input = drvdata->input; | ||
| 326 | u8 *finger_data; | ||
| 327 | int i; | ||
| 328 | |||
| 329 | /* | ||
| 330 | * Elan MT touchpads in i2c mode send finger data in the same format | ||
| 331 | * as in USB mode, but then with all fingers in a single packet. | ||
| 332 | * | ||
| 333 | * packet structure for ELAN_MT_I2C: | ||
| 334 | * | ||
| 335 | * byte 1: 1 0 0 1 1 1 0 1 // 0x5d | ||
| 336 | * byte 2: f5 f4 f3 f2 f1 0 0 L | ||
| 337 | * byte 3: x12 x11 x10 x9 0? y11 y10 y9 | ||
| 338 | * byte 4: x8 x7 x6 x5 x4 x3 x2 x1 | ||
| 339 | * byte 5: y8 y7 y6 y5 y4 y3 y2 y1 | ||
| 340 | * byte 6: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1 | ||
| 341 | * byte 7: p8 p7 p6 p5 p4 p3 p2 p1 | ||
| 342 | * byte 8-12: Same as byte 3-7 for second finger down | ||
| 343 | * byte 13-17: Same as byte 3-7 for third finger down | ||
| 344 | * byte 18-22: Same as byte 3-7 for fourth finger down | ||
| 345 | * byte 23-27: Same as byte 3-7 for fifth finger down | ||
| 346 | */ | ||
| 347 | |||
| 348 | finger_data = data + 2; | ||
| 349 | for (i = 0; i < ELAN_MAX_FINGERS; i++) { | ||
| 350 | if (data[1] & BIT(i + 3)) { | ||
| 351 | elan_report_mt_slot(drvdata, finger_data, i); | ||
| 352 | finger_data += ELAN_FINGER_DATA_LEN; | ||
| 353 | } else { | ||
| 354 | elan_report_mt_slot(drvdata, NULL, i); | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 358 | input_report_key(input, BTN_LEFT, data[1] & 0x01); | ||
| 359 | input_mt_sync_frame(input); | ||
| 360 | input_sync(input); | ||
| 361 | } | ||
| 362 | |||
| 232 | static int elan_raw_event(struct hid_device *hdev, | 363 | static int elan_raw_event(struct hid_device *hdev, |
| 233 | struct hid_report *report, u8 *data, int size) | 364 | struct hid_report *report, u8 *data, int size) |
| 234 | { | 365 | { |
| @@ -241,11 +372,16 @@ static int elan_raw_event(struct hid_device *hdev, | |||
| 241 | data[0] == ELAN_MT_FIRST_FINGER || | 372 | data[0] == ELAN_MT_FIRST_FINGER || |
| 242 | data[0] == ELAN_MT_SECOND_FINGER) { | 373 | data[0] == ELAN_MT_SECOND_FINGER) { |
| 243 | if (size == ELAN_INPUT_REPORT_SIZE) { | 374 | if (size == ELAN_INPUT_REPORT_SIZE) { |
| 244 | elan_report_input(drvdata, data); | 375 | elan_usb_report_input(drvdata, data); |
| 245 | return 1; | 376 | return 1; |
| 246 | } | 377 | } |
| 247 | } | 378 | } |
| 248 | 379 | ||
| 380 | if (data[0] == ELAN_MT_I2C && size == ELAN_I2C_REPORT_SIZE) { | ||
| 381 | elan_i2c_report_input(drvdata, data); | ||
| 382 | return 1; | ||
| 383 | } | ||
| 384 | |||
| 249 | return 0; | 385 | return 0; |
| 250 | } | 386 | } |
| 251 | 387 | ||
| @@ -343,7 +479,6 @@ static int elan_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 343 | if (!drvdata) | 479 | if (!drvdata) |
| 344 | return -ENOMEM; | 480 | return -ENOMEM; |
| 345 | 481 | ||
| 346 | drvdata->settings = (struct elan_touchpad_settings *)id->driver_data; | ||
| 347 | hid_set_drvdata(hdev, drvdata); | 482 | hid_set_drvdata(hdev, drvdata); |
| 348 | 483 | ||
| 349 | ret = hid_parse(hdev); | 484 | ret = hid_parse(hdev); |
| @@ -371,9 +506,11 @@ static int elan_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 371 | if (ret) | 506 | if (ret) |
| 372 | goto err; | 507 | goto err; |
| 373 | 508 | ||
| 374 | ret = elan_init_mute_led(hdev); | 509 | if (id->driver_data & ELAN_HAS_LED) { |
| 375 | if (ret) | 510 | ret = elan_init_mute_led(hdev); |
| 376 | goto err; | 511 | if (ret) |
| 512 | goto err; | ||
| 513 | } | ||
| 377 | 514 | ||
| 378 | return 0; | 515 | return 0; |
| 379 | err: | 516 | err: |
| @@ -386,22 +523,14 @@ static void elan_remove(struct hid_device *hdev) | |||
| 386 | hid_hw_stop(hdev); | 523 | hid_hw_stop(hdev); |
| 387 | } | 524 | } |
| 388 | 525 | ||
| 389 | static const struct elan_touchpad_settings hp_x2_10_touchpad_data = { | ||
| 390 | .max_fingers = 5, | ||
| 391 | .max_x = 2930, | ||
| 392 | .max_y = 1250, | ||
| 393 | .max_area_x = 15, | ||
| 394 | .max_area_y = 15, | ||
| 395 | .max_w = 255, | ||
| 396 | .usb_bInterfaceNumber = 1, | ||
| 397 | }; | ||
| 398 | |||
| 399 | static const struct hid_device_id elan_devices[] = { | 526 | static const struct hid_device_id elan_devices[] = { |
| 527 | { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2), | ||
| 528 | .driver_data = ELAN_HAS_LED }, | ||
| 400 | { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2_10_COVER), | 529 | { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2_10_COVER), |
| 401 | (kernel_ulong_t)&hp_x2_10_touchpad_data}, | 530 | .driver_data = ELAN_HAS_LED }, |
| 531 | { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_TOSHIBA_CLICK_L9W) }, | ||
| 402 | { } | 532 | { } |
| 403 | }; | 533 | }; |
| 404 | |||
| 405 | MODULE_DEVICE_TABLE(hid, elan_devices); | 534 | MODULE_DEVICE_TABLE(hid, elan_devices); |
| 406 | 535 | ||
| 407 | static struct hid_driver elan_driver = { | 536 | static struct hid_driver elan_driver = { |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index c7981ddd8776..79bdf0c7e351 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
| @@ -369,6 +369,8 @@ | |||
| 369 | #define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001 0xa001 | 369 | #define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001 0xa001 |
| 370 | 370 | ||
| 371 | #define USB_VENDOR_ID_ELAN 0x04f3 | 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 | #define USB_DEVICE_ID_HP_X2_10_COVER 0x0755 | 374 | #define USB_DEVICE_ID_HP_X2_10_COVER 0x0755 |
| 373 | 375 | ||
| 374 | #define USB_VENDOR_ID_ELECOM 0x056e | 376 | #define USB_VENDOR_ID_ELECOM 0x056e |
| @@ -1001,6 +1003,9 @@ | |||
| 1001 | #define USB_VENDOR_ID_SINO_LITE 0x1345 | 1003 | #define USB_VENDOR_ID_SINO_LITE 0x1345 |
| 1002 | #define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x3008 | 1004 | #define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x3008 |
| 1003 | 1005 | ||
| 1006 | #define USB_VENDOR_ID_SOLID_YEAR 0x060b | ||
| 1007 | #define USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD 0x500a | ||
| 1008 | |||
| 1004 | #define USB_VENDOR_ID_SOUNDGRAPH 0x15c2 | 1009 | #define USB_VENDOR_ID_SOUNDGRAPH 0x15c2 |
| 1005 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034 | 1010 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034 |
| 1006 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST 0x0046 | 1011 | #define USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST 0x0046 |
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index ab93dd5927c3..4e94ea3e280a 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
| @@ -1550,6 +1550,9 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid, | |||
| 1550 | case HID_GD_WIRELESS_RADIO_CTLS: | 1550 | case HID_GD_WIRELESS_RADIO_CTLS: |
| 1551 | suffix = "Wireless Radio Control"; | 1551 | suffix = "Wireless Radio Control"; |
| 1552 | break; | 1552 | break; |
| 1553 | case HID_GD_SYSTEM_MULTIAXIS: | ||
| 1554 | suffix = "System Multi Axis"; | ||
| 1555 | break; | ||
| 1553 | default: | 1556 | default: |
| 1554 | break; | 1557 | break; |
| 1555 | } | 1558 | } |
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c index 96e7d3231d2f..72d983626afd 100644 --- a/drivers/hid/hid-microsoft.c +++ b/drivers/hid/hid-microsoft.c | |||
| @@ -22,12 +22,13 @@ | |||
| 22 | 22 | ||
| 23 | #include "hid-ids.h" | 23 | #include "hid-ids.h" |
| 24 | 24 | ||
| 25 | #define MS_HIDINPUT 0x01 | 25 | #define MS_HIDINPUT BIT(0) |
| 26 | #define MS_ERGONOMY 0x02 | 26 | #define MS_ERGONOMY BIT(1) |
| 27 | #define MS_PRESENTER 0x04 | 27 | #define MS_PRESENTER BIT(2) |
| 28 | #define MS_RDESC 0x08 | 28 | #define MS_RDESC BIT(3) |
| 29 | #define MS_NOGET 0x10 | 29 | #define MS_NOGET BIT(4) |
| 30 | #define MS_DUPLICATE_USAGES 0x20 | 30 | #define MS_DUPLICATE_USAGES BIT(5) |
| 31 | #define MS_SURFACE_DIAL BIT(6) | ||
| 31 | 32 | ||
| 32 | static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, | 33 | static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 33 | unsigned int *rsize) | 34 | unsigned int *rsize) |
| @@ -130,6 +131,30 @@ static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage, | |||
| 130 | return 1; | 131 | return 1; |
| 131 | } | 132 | } |
| 132 | 133 | ||
| 134 | static int ms_surface_dial_quirk(struct hid_input *hi, struct hid_field *field, | ||
| 135 | struct hid_usage *usage, unsigned long **bit, int *max) | ||
| 136 | { | ||
| 137 | switch (usage->hid & HID_USAGE_PAGE) { | ||
| 138 | case 0xff070000: | ||
| 139 | /* fall-through */ | ||
| 140 | case HID_UP_DIGITIZER: | ||
| 141 | /* ignore those axis */ | ||
| 142 | return -1; | ||
| 143 | case HID_UP_GENDESK: | ||
| 144 | switch (usage->hid) { | ||
| 145 | case HID_GD_X: | ||
| 146 | /* fall-through */ | ||
| 147 | case HID_GD_Y: | ||
| 148 | /* fall-through */ | ||
| 149 | case HID_GD_RFKILL_BTN: | ||
| 150 | /* ignore those axis */ | ||
| 151 | return -1; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | |||
| 133 | static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, | 158 | static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 134 | struct hid_field *field, struct hid_usage *usage, | 159 | struct hid_field *field, struct hid_usage *usage, |
| 135 | unsigned long **bit, int *max) | 160 | unsigned long **bit, int *max) |
| @@ -146,6 +171,13 @@ static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 146 | ms_presenter_8k_quirk(hi, usage, bit, max)) | 171 | ms_presenter_8k_quirk(hi, usage, bit, max)) |
| 147 | return 1; | 172 | return 1; |
| 148 | 173 | ||
| 174 | if (quirks & MS_SURFACE_DIAL) { | ||
| 175 | int ret = ms_surface_dial_quirk(hi, field, usage, bit, max); | ||
| 176 | |||
| 177 | if (ret) | ||
| 178 | return ret; | ||
| 179 | } | ||
| 180 | |||
| 149 | return 0; | 181 | return 0; |
| 150 | } | 182 | } |
| 151 | 183 | ||
| @@ -229,6 +261,9 @@ static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 229 | if (quirks & MS_NOGET) | 261 | if (quirks & MS_NOGET) |
| 230 | hdev->quirks |= HID_QUIRK_NOGET; | 262 | hdev->quirks |= HID_QUIRK_NOGET; |
| 231 | 263 | ||
| 264 | if (quirks & MS_SURFACE_DIAL) | ||
| 265 | hdev->quirks |= HID_QUIRK_INPUT_PER_APP; | ||
| 266 | |||
| 232 | ret = hid_parse(hdev); | 267 | ret = hid_parse(hdev); |
| 233 | if (ret) { | 268 | if (ret) { |
| 234 | hid_err(hdev, "parse failed\n"); | 269 | hid_err(hdev, "parse failed\n"); |
| @@ -281,6 +316,8 @@ static const struct hid_device_id ms_devices[] = { | |||
| 281 | 316 | ||
| 282 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), | 317 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), |
| 283 | .driver_data = MS_PRESENTER }, | 318 | .driver_data = MS_PRESENTER }, |
| 319 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, 0x091B), | ||
| 320 | .driver_data = MS_SURFACE_DIAL }, | ||
| 284 | { } | 321 | { } |
| 285 | }; | 322 | }; |
| 286 | MODULE_DEVICE_TABLE(hid, ms_devices); | 323 | MODULE_DEVICE_TABLE(hid, ms_devices); |
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 45968f7970f8..40fbb7c52723 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
| @@ -28,14 +28,11 @@ | |||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | /* | 30 | /* |
| 31 | * This driver is regularly tested thanks to the tool hid-test[1]. | 31 | * This driver is regularly tested thanks to the test suite in hid-tools[1]. |
| 32 | * This tool relies on hid-replay[2] and a database of hid devices[3]. | ||
| 33 | * Please run these regression tests before patching this module so that | 32 | * Please run these regression tests before patching this module so that |
| 34 | * your patch won't break existing known devices. | 33 | * your patch won't break existing known devices. |
| 35 | * | 34 | * |
| 36 | * [1] https://github.com/bentiss/hid-test | 35 | * [1] https://gitlab.freedesktop.org/libevdev/hid-tools |
| 37 | * [2] https://github.com/bentiss/hid-replay | ||
| 38 | * [3] https://github.com/bentiss/hid-devices | ||
| 39 | */ | 36 | */ |
| 40 | 37 | ||
| 41 | #include <linux/device.h> | 38 | #include <linux/device.h> |
| @@ -90,13 +87,54 @@ enum latency_mode { | |||
| 90 | #define MT_IO_FLAGS_ACTIVE_SLOTS 1 | 87 | #define MT_IO_FLAGS_ACTIVE_SLOTS 1 |
| 91 | #define MT_IO_FLAGS_PENDING_SLOTS 2 | 88 | #define MT_IO_FLAGS_PENDING_SLOTS 2 |
| 92 | 89 | ||
| 93 | struct mt_slot { | 90 | static const bool mtrue = true; /* default for true */ |
| 94 | __s32 x, y, cx, cy, p, w, h, a; | 91 | static const bool mfalse; /* default for false */ |
| 95 | __s32 contactid; /* the device ContactID assigned to this slot */ | 92 | static const __s32 mzero; /* default for 0 */ |
| 96 | bool touch_state; /* is the touch valid? */ | 93 | |
| 97 | bool inrange_state; /* is the finger in proximity of the sensor? */ | 94 | #define DEFAULT_TRUE ((void *)&mtrue) |
| 98 | bool confidence_state; /* is the touch made by a finger? */ | 95 | #define DEFAULT_FALSE ((void *)&mfalse) |
| 99 | bool has_azimuth; /* the contact reports azimuth */ | 96 | #define DEFAULT_ZERO ((void *)&mzero) |
| 97 | |||
| 98 | struct mt_usages { | ||
| 99 | struct list_head list; | ||
| 100 | __s32 *x, *y, *cx, *cy, *p, *w, *h, *a; | ||
| 101 | __s32 *contactid; /* the device ContactID assigned to this slot */ | ||
| 102 | bool *tip_state; /* is the touch valid? */ | ||
| 103 | bool *inrange_state; /* is the finger in proximity of the sensor? */ | ||
| 104 | bool *confidence_state; /* is the touch made by a finger? */ | ||
| 105 | }; | ||
| 106 | |||
| 107 | struct mt_application { | ||
| 108 | struct list_head list; | ||
| 109 | unsigned int application; | ||
| 110 | struct list_head mt_usages; /* mt usages list */ | ||
| 111 | |||
| 112 | __s32 quirks; | ||
| 113 | |||
| 114 | __s32 *scantime; /* scantime reported */ | ||
| 115 | __s32 scantime_logical_max; /* max value for raw scantime */ | ||
| 116 | |||
| 117 | __s32 *raw_cc; /* contact count in the report */ | ||
| 118 | int left_button_state; /* left button state */ | ||
| 119 | unsigned int mt_flags; /* flags to pass to input-mt */ | ||
| 120 | |||
| 121 | unsigned long *pending_palm_slots; /* slots where we reported palm | ||
| 122 | * and need to release */ | ||
| 123 | |||
| 124 | __u8 num_received; /* how many contacts we received */ | ||
| 125 | __u8 num_expected; /* expected last contact index */ | ||
| 126 | __u8 buttons_count; /* number of physical buttons per touchpad */ | ||
| 127 | __u8 touches_by_report; /* how many touches are present in one report: | ||
| 128 | * 1 means we should use a serial protocol | ||
| 129 | * > 1 means hybrid (multitouch) protocol | ||
| 130 | */ | ||
| 131 | |||
| 132 | __s32 dev_time; /* the scan time provided by the device */ | ||
| 133 | unsigned long jiffies; /* the frame's jiffies */ | ||
| 134 | int timestamp; /* the timestamp to be sent */ | ||
| 135 | int prev_scantime; /* scantime reported previously */ | ||
| 136 | |||
| 137 | bool have_contact_count; | ||
| 100 | }; | 138 | }; |
| 101 | 139 | ||
| 102 | struct mt_class { | 140 | struct mt_class { |
| @@ -111,46 +149,30 @@ struct mt_class { | |||
| 111 | bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ | 149 | bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ |
| 112 | }; | 150 | }; |
| 113 | 151 | ||
| 114 | struct mt_fields { | 152 | struct mt_report_data { |
| 115 | unsigned usages[HID_MAX_FIELDS]; | 153 | struct list_head list; |
| 116 | unsigned int length; | 154 | struct hid_report *report; |
| 155 | struct mt_application *application; | ||
| 156 | bool is_mt_collection; | ||
| 117 | }; | 157 | }; |
| 118 | 158 | ||
| 119 | struct mt_device { | 159 | struct mt_device { |
| 120 | struct mt_slot curdata; /* placeholder of incoming data */ | ||
| 121 | struct mt_class mtclass; /* our mt device class */ | 160 | struct mt_class mtclass; /* our mt device class */ |
| 122 | struct timer_list release_timer; /* to release sticky fingers */ | 161 | struct timer_list release_timer; /* to release sticky fingers */ |
| 123 | struct hid_device *hdev; /* hid_device we're attached to */ | 162 | struct hid_device *hdev; /* hid_device we're attached to */ |
| 124 | struct mt_fields *fields; /* temporary placeholder for storing the | ||
| 125 | multitouch fields */ | ||
| 126 | unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ | 163 | unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ |
| 127 | int cc_index; /* contact count field index in the report */ | ||
| 128 | int cc_value_index; /* contact count value index in the field */ | ||
| 129 | int scantime_index; /* scantime field index in the report */ | ||
| 130 | int scantime_val_index; /* scantime value index in the field */ | ||
| 131 | int prev_scantime; /* scantime reported in the previous packet */ | ||
| 132 | int left_button_state; /* left button state */ | ||
| 133 | unsigned last_slot_field; /* the last field of a slot */ | ||
| 134 | unsigned mt_report_id; /* the report ID of the multitouch device */ | ||
| 135 | __u8 inputmode_value; /* InputMode HID feature value */ | 164 | __u8 inputmode_value; /* InputMode HID feature value */ |
| 136 | __u8 num_received; /* how many contacts we received */ | ||
| 137 | __u8 num_expected; /* expected last contact index */ | ||
| 138 | __u8 maxcontacts; | 165 | __u8 maxcontacts; |
| 139 | __u8 touches_by_report; /* how many touches are present in one report: | ||
| 140 | * 1 means we should use a serial protocol | ||
| 141 | * > 1 means hybrid (multitouch) protocol */ | ||
| 142 | __u8 buttons_count; /* number of physical buttons per touchpad */ | ||
| 143 | bool is_buttonpad; /* is this device a button pad? */ | 166 | bool is_buttonpad; /* is this device a button pad? */ |
| 144 | bool serial_maybe; /* need to check for serial protocol */ | 167 | bool serial_maybe; /* need to check for serial protocol */ |
| 145 | bool curvalid; /* is the current contact valid? */ | 168 | |
| 146 | unsigned mt_flags; /* flags to pass to input-mt */ | 169 | struct list_head applications; |
| 147 | __s32 dev_time; /* the scan time provided by the device */ | 170 | struct list_head reports; |
| 148 | unsigned long jiffies; /* the frame's jiffies */ | ||
| 149 | int timestamp; /* the timestamp to be sent */ | ||
| 150 | }; | 171 | }; |
| 151 | 172 | ||
| 152 | static void mt_post_parse_default_settings(struct mt_device *td); | 173 | static void mt_post_parse_default_settings(struct mt_device *td, |
| 153 | static void mt_post_parse(struct mt_device *td); | 174 | struct mt_application *app); |
| 175 | static void mt_post_parse(struct mt_device *td, struct mt_application *app); | ||
| 154 | 176 | ||
| 155 | /* classes of device behavior */ | 177 | /* classes of device behavior */ |
| 156 | #define MT_CLS_DEFAULT 0x0001 | 178 | #define MT_CLS_DEFAULT 0x0001 |
| @@ -203,15 +225,16 @@ static void mt_post_parse(struct mt_device *td); | |||
| 203 | * to a valid contact that was just read. | 225 | * to a valid contact that was just read. |
| 204 | */ | 226 | */ |
| 205 | 227 | ||
| 206 | static int cypress_compute_slot(struct mt_device *td) | 228 | static int cypress_compute_slot(struct mt_application *application, |
| 229 | struct mt_usages *slot) | ||
| 207 | { | 230 | { |
| 208 | if (td->curdata.contactid != 0 || td->num_received == 0) | 231 | if (*slot->contactid != 0 || application->num_received == 0) |
| 209 | return td->curdata.contactid; | 232 | return *slot->contactid; |
| 210 | else | 233 | else |
| 211 | return -1; | 234 | return -1; |
| 212 | } | 235 | } |
| 213 | 236 | ||
| 214 | static struct mt_class mt_classes[] = { | 237 | static const struct mt_class mt_classes[] = { |
| 215 | { .name = MT_CLS_DEFAULT, | 238 | { .name = MT_CLS_DEFAULT, |
| 216 | .quirks = MT_QUIRK_ALWAYS_VALID | | 239 | .quirks = MT_QUIRK_ALWAYS_VALID | |
| 217 | MT_QUIRK_CONTACT_CNT_ACCURATE }, | 240 | MT_QUIRK_CONTACT_CNT_ACCURATE }, |
| @@ -353,6 +376,7 @@ static ssize_t mt_set_quirks(struct device *dev, | |||
| 353 | { | 376 | { |
| 354 | struct hid_device *hdev = to_hid_device(dev); | 377 | struct hid_device *hdev = to_hid_device(dev); |
| 355 | struct mt_device *td = hid_get_drvdata(hdev); | 378 | struct mt_device *td = hid_get_drvdata(hdev); |
| 379 | struct mt_application *application; | ||
| 356 | 380 | ||
| 357 | unsigned long val; | 381 | unsigned long val; |
| 358 | 382 | ||
| @@ -361,8 +385,11 @@ static ssize_t mt_set_quirks(struct device *dev, | |||
| 361 | 385 | ||
| 362 | td->mtclass.quirks = val; | 386 | td->mtclass.quirks = val; |
| 363 | 387 | ||
| 364 | if (td->cc_index < 0) | 388 | list_for_each_entry(application, &td->applications, list) { |
| 365 | td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; | 389 | application->quirks = val; |
| 390 | if (!application->have_contact_count) | ||
| 391 | application->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; | ||
| 392 | } | ||
| 366 | 393 | ||
| 367 | return count; | 394 | return count; |
| 368 | } | 395 | } |
| @@ -457,41 +484,199 @@ static void set_abs(struct input_dev *input, unsigned int code, | |||
| 457 | input_abs_set_res(input, code, hidinput_calc_abs_res(field, code)); | 484 | input_abs_set_res(input, code, hidinput_calc_abs_res(field, code)); |
| 458 | } | 485 | } |
| 459 | 486 | ||
| 460 | static void mt_store_field(struct hid_usage *usage, struct mt_device *td, | 487 | static struct mt_usages *mt_allocate_usage(struct hid_device *hdev, |
| 461 | struct hid_input *hi) | 488 | struct mt_application *application) |
| 489 | { | ||
| 490 | struct mt_usages *usage; | ||
| 491 | |||
| 492 | usage = devm_kzalloc(&hdev->dev, sizeof(*usage), GFP_KERNEL); | ||
| 493 | if (!usage) | ||
| 494 | return NULL; | ||
| 495 | |||
| 496 | /* set some defaults so we do not need to check for null pointers */ | ||
| 497 | usage->x = DEFAULT_ZERO; | ||
| 498 | usage->y = DEFAULT_ZERO; | ||
| 499 | usage->cx = DEFAULT_ZERO; | ||
| 500 | usage->cy = DEFAULT_ZERO; | ||
| 501 | usage->p = DEFAULT_ZERO; | ||
| 502 | usage->w = DEFAULT_ZERO; | ||
| 503 | usage->h = DEFAULT_ZERO; | ||
| 504 | usage->a = DEFAULT_ZERO; | ||
| 505 | usage->contactid = DEFAULT_ZERO; | ||
| 506 | usage->tip_state = DEFAULT_FALSE; | ||
| 507 | usage->inrange_state = DEFAULT_FALSE; | ||
| 508 | usage->confidence_state = DEFAULT_TRUE; | ||
| 509 | |||
| 510 | list_add_tail(&usage->list, &application->mt_usages); | ||
| 511 | |||
| 512 | return usage; | ||
| 513 | } | ||
| 514 | |||
| 515 | static struct mt_application *mt_allocate_application(struct mt_device *td, | ||
| 516 | unsigned int application) | ||
| 517 | { | ||
| 518 | struct mt_application *mt_application; | ||
| 519 | |||
| 520 | mt_application = devm_kzalloc(&td->hdev->dev, sizeof(*mt_application), | ||
| 521 | GFP_KERNEL); | ||
| 522 | if (!mt_application) | ||
| 523 | return NULL; | ||
| 524 | |||
| 525 | mt_application->application = application; | ||
| 526 | INIT_LIST_HEAD(&mt_application->mt_usages); | ||
| 527 | |||
| 528 | if (application == HID_DG_TOUCHSCREEN) | ||
| 529 | mt_application->mt_flags |= INPUT_MT_DIRECT; | ||
| 530 | |||
| 531 | /* | ||
| 532 | * Model touchscreens providing buttons as touchpads. | ||
| 533 | */ | ||
| 534 | if (application == HID_DG_TOUCHPAD) { | ||
| 535 | mt_application->mt_flags |= INPUT_MT_POINTER; | ||
| 536 | td->inputmode_value = MT_INPUTMODE_TOUCHPAD; | ||
| 537 | } | ||
| 538 | |||
| 539 | mt_application->scantime = DEFAULT_ZERO; | ||
| 540 | mt_application->raw_cc = DEFAULT_ZERO; | ||
| 541 | mt_application->quirks = td->mtclass.quirks; | ||
| 542 | |||
| 543 | list_add_tail(&mt_application->list, &td->applications); | ||
| 544 | |||
| 545 | return mt_application; | ||
| 546 | } | ||
| 547 | |||
| 548 | static struct mt_application *mt_find_application(struct mt_device *td, | ||
| 549 | unsigned int application) | ||
| 550 | { | ||
| 551 | struct mt_application *tmp, *mt_application = NULL; | ||
| 552 | |||
| 553 | list_for_each_entry(tmp, &td->applications, list) { | ||
| 554 | if (application == tmp->application) { | ||
| 555 | mt_application = tmp; | ||
| 556 | break; | ||
| 557 | } | ||
| 558 | } | ||
| 559 | |||
| 560 | if (!mt_application) | ||
| 561 | mt_application = mt_allocate_application(td, application); | ||
| 562 | |||
| 563 | return mt_application; | ||
| 564 | } | ||
| 565 | |||
| 566 | static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, | ||
| 567 | struct hid_report *report) | ||
| 568 | { | ||
| 569 | struct mt_report_data *rdata; | ||
| 570 | struct hid_field *field; | ||
| 571 | int r, n; | ||
| 572 | |||
| 573 | rdata = devm_kzalloc(&td->hdev->dev, sizeof(*rdata), GFP_KERNEL); | ||
| 574 | if (!rdata) | ||
| 575 | return NULL; | ||
| 576 | |||
| 577 | rdata->report = report; | ||
| 578 | rdata->application = mt_find_application(td, report->application); | ||
| 579 | |||
| 580 | if (!rdata->application) { | ||
| 581 | devm_kfree(&td->hdev->dev, rdata); | ||
| 582 | return NULL; | ||
| 583 | } | ||
| 584 | |||
| 585 | for (r = 0; r < report->maxfield; r++) { | ||
| 586 | field = report->field[r]; | ||
| 587 | |||
| 588 | if (!(HID_MAIN_ITEM_VARIABLE & field->flags)) | ||
| 589 | continue; | ||
| 590 | |||
| 591 | for (n = 0; n < field->report_count; n++) { | ||
| 592 | if (field->usage[n].hid == HID_DG_CONTACTID) | ||
| 593 | rdata->is_mt_collection = true; | ||
| 594 | } | ||
| 595 | } | ||
| 596 | |||
| 597 | list_add_tail(&rdata->list, &td->reports); | ||
| 598 | |||
| 599 | return rdata; | ||
| 600 | } | ||
| 601 | |||
| 602 | static struct mt_report_data *mt_find_report_data(struct mt_device *td, | ||
| 603 | struct hid_report *report) | ||
| 462 | { | 604 | { |
| 463 | struct mt_fields *f = td->fields; | 605 | struct mt_report_data *tmp, *rdata = NULL; |
| 464 | 606 | ||
| 465 | if (f->length >= HID_MAX_FIELDS) | 607 | list_for_each_entry(tmp, &td->reports, list) { |
| 608 | if (report == tmp->report) { | ||
| 609 | rdata = tmp; | ||
| 610 | break; | ||
| 611 | } | ||
| 612 | } | ||
| 613 | |||
| 614 | if (!rdata) | ||
| 615 | rdata = mt_allocate_report_data(td, report); | ||
| 616 | |||
| 617 | return rdata; | ||
| 618 | } | ||
| 619 | |||
| 620 | static void mt_store_field(struct hid_device *hdev, | ||
| 621 | struct mt_application *application, | ||
| 622 | __s32 *value, | ||
| 623 | size_t offset) | ||
| 624 | { | ||
| 625 | struct mt_usages *usage; | ||
| 626 | __s32 **target; | ||
| 627 | |||
| 628 | if (list_empty(&application->mt_usages)) | ||
| 629 | usage = mt_allocate_usage(hdev, application); | ||
| 630 | else | ||
| 631 | usage = list_last_entry(&application->mt_usages, | ||
| 632 | struct mt_usages, | ||
| 633 | list); | ||
| 634 | |||
| 635 | if (!usage) | ||
| 466 | return; | 636 | return; |
| 467 | 637 | ||
| 468 | f->usages[f->length++] = usage->hid; | 638 | target = (__s32 **)((char *)usage + offset); |
| 639 | |||
| 640 | /* the value has already been filled, create a new slot */ | ||
| 641 | if (*target != DEFAULT_TRUE && | ||
| 642 | *target != DEFAULT_FALSE && | ||
| 643 | *target != DEFAULT_ZERO) { | ||
| 644 | usage = mt_allocate_usage(hdev, application); | ||
| 645 | if (!usage) | ||
| 646 | return; | ||
| 647 | |||
| 648 | target = (__s32 **)((char *)usage + offset); | ||
| 649 | } | ||
| 650 | |||
| 651 | *target = value; | ||
| 469 | } | 652 | } |
| 470 | 653 | ||
| 654 | #define MT_STORE_FIELD(__name) \ | ||
| 655 | mt_store_field(hdev, app, \ | ||
| 656 | &field->value[usage->usage_index], \ | ||
| 657 | offsetof(struct mt_usages, __name)) | ||
| 658 | |||
| 471 | static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | 659 | static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 472 | struct hid_field *field, struct hid_usage *usage, | 660 | struct hid_field *field, struct hid_usage *usage, |
| 473 | unsigned long **bit, int *max) | 661 | unsigned long **bit, int *max, struct mt_application *app) |
| 474 | { | 662 | { |
| 475 | struct mt_device *td = hid_get_drvdata(hdev); | 663 | struct mt_device *td = hid_get_drvdata(hdev); |
| 476 | struct mt_class *cls = &td->mtclass; | 664 | struct mt_class *cls = &td->mtclass; |
| 477 | int code; | 665 | int code; |
| 478 | struct hid_usage *prev_usage = NULL; | 666 | struct hid_usage *prev_usage = NULL; |
| 479 | 667 | ||
| 480 | if (field->application == HID_DG_TOUCHSCREEN) | ||
| 481 | td->mt_flags |= INPUT_MT_DIRECT; | ||
| 482 | |||
| 483 | /* | 668 | /* |
| 484 | * Model touchscreens providing buttons as touchpads. | 669 | * Model touchscreens providing buttons as touchpads. |
| 485 | */ | 670 | */ |
| 486 | if (field->application == HID_DG_TOUCHPAD || | 671 | if (field->application == HID_DG_TOUCHSCREEN && |
| 487 | (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { | 672 | (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { |
| 488 | td->mt_flags |= INPUT_MT_POINTER; | 673 | app->mt_flags |= INPUT_MT_POINTER; |
| 489 | td->inputmode_value = MT_INPUTMODE_TOUCHPAD; | 674 | td->inputmode_value = MT_INPUTMODE_TOUCHPAD; |
| 490 | } | 675 | } |
| 491 | 676 | ||
| 492 | /* count the buttons on touchpads */ | 677 | /* count the buttons on touchpads */ |
| 493 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) | 678 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) |
| 494 | td->buttons_count++; | 679 | app->buttons_count++; |
| 495 | 680 | ||
| 496 | if (usage->usage_index) | 681 | if (usage->usage_index) |
| 497 | prev_usage = &field->usage[usage->usage_index - 1]; | 682 | prev_usage = &field->usage[usage->usage_index - 1]; |
| @@ -502,33 +687,40 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 502 | switch (usage->hid) { | 687 | switch (usage->hid) { |
| 503 | case HID_GD_X: | 688 | case HID_GD_X: |
| 504 | if (prev_usage && (prev_usage->hid == usage->hid)) { | 689 | if (prev_usage && (prev_usage->hid == usage->hid)) { |
| 505 | hid_map_usage(hi, usage, bit, max, | 690 | code = ABS_MT_TOOL_X; |
| 506 | EV_ABS, ABS_MT_TOOL_X); | 691 | MT_STORE_FIELD(cx); |
| 507 | set_abs(hi->input, ABS_MT_TOOL_X, field, | ||
| 508 | cls->sn_move); | ||
| 509 | } else { | 692 | } else { |
| 510 | hid_map_usage(hi, usage, bit, max, | 693 | code = ABS_MT_POSITION_X; |
| 511 | EV_ABS, ABS_MT_POSITION_X); | 694 | MT_STORE_FIELD(x); |
| 512 | set_abs(hi->input, ABS_MT_POSITION_X, field, | 695 | } |
| 513 | cls->sn_move); | 696 | |
| 697 | set_abs(hi->input, code, field, cls->sn_move); | ||
| 698 | |||
| 699 | /* | ||
| 700 | * A system multi-axis that exports X and Y has a high | ||
| 701 | * chance of being used directly on a surface | ||
| 702 | */ | ||
| 703 | if (field->application == HID_GD_SYSTEM_MULTIAXIS) { | ||
| 704 | __set_bit(INPUT_PROP_DIRECT, | ||
| 705 | hi->input->propbit); | ||
| 706 | input_set_abs_params(hi->input, | ||
| 707 | ABS_MT_TOOL_TYPE, | ||
| 708 | MT_TOOL_DIAL, | ||
| 709 | MT_TOOL_DIAL, 0, 0); | ||
| 514 | } | 710 | } |
| 515 | 711 | ||
| 516 | mt_store_field(usage, td, hi); | ||
| 517 | return 1; | 712 | return 1; |
| 518 | case HID_GD_Y: | 713 | case HID_GD_Y: |
| 519 | if (prev_usage && (prev_usage->hid == usage->hid)) { | 714 | if (prev_usage && (prev_usage->hid == usage->hid)) { |
| 520 | hid_map_usage(hi, usage, bit, max, | 715 | code = ABS_MT_TOOL_Y; |
| 521 | EV_ABS, ABS_MT_TOOL_Y); | 716 | MT_STORE_FIELD(cy); |
| 522 | set_abs(hi->input, ABS_MT_TOOL_Y, field, | ||
| 523 | cls->sn_move); | ||
| 524 | } else { | 717 | } else { |
| 525 | hid_map_usage(hi, usage, bit, max, | 718 | code = ABS_MT_POSITION_Y; |
| 526 | EV_ABS, ABS_MT_POSITION_Y); | 719 | MT_STORE_FIELD(y); |
| 527 | set_abs(hi->input, ABS_MT_POSITION_Y, field, | ||
| 528 | cls->sn_move); | ||
| 529 | } | 720 | } |
| 530 | 721 | ||
| 531 | mt_store_field(usage, td, hi); | 722 | set_abs(hi->input, code, field, cls->sn_move); |
| 723 | |||
| 532 | return 1; | 724 | return 1; |
| 533 | } | 725 | } |
| 534 | return 0; | 726 | return 0; |
| @@ -536,43 +728,45 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 536 | case HID_UP_DIGITIZER: | 728 | case HID_UP_DIGITIZER: |
| 537 | switch (usage->hid) { | 729 | switch (usage->hid) { |
| 538 | case HID_DG_INRANGE: | 730 | case HID_DG_INRANGE: |
| 539 | if (cls->quirks & MT_QUIRK_HOVERING) { | 731 | if (app->quirks & MT_QUIRK_HOVERING) { |
| 540 | hid_map_usage(hi, usage, bit, max, | ||
| 541 | EV_ABS, ABS_MT_DISTANCE); | ||
| 542 | input_set_abs_params(hi->input, | 732 | input_set_abs_params(hi->input, |
| 543 | ABS_MT_DISTANCE, 0, 1, 0, 0); | 733 | ABS_MT_DISTANCE, 0, 1, 0, 0); |
| 544 | } | 734 | } |
| 545 | mt_store_field(usage, td, hi); | 735 | MT_STORE_FIELD(inrange_state); |
| 546 | return 1; | 736 | return 1; |
| 547 | case HID_DG_CONFIDENCE: | 737 | case HID_DG_CONFIDENCE: |
| 548 | if ((cls->name == MT_CLS_WIN_8 || | 738 | if ((cls->name == MT_CLS_WIN_8 || |
| 549 | cls->name == MT_CLS_WIN_8_DUAL) && | 739 | cls->name == MT_CLS_WIN_8_DUAL) && |
| 550 | field->application == HID_DG_TOUCHPAD) | 740 | (field->application == HID_DG_TOUCHPAD || |
| 551 | cls->quirks |= MT_QUIRK_CONFIDENCE; | 741 | field->application == HID_DG_TOUCHSCREEN)) |
| 552 | mt_store_field(usage, td, hi); | 742 | app->quirks |= MT_QUIRK_CONFIDENCE; |
| 743 | |||
| 744 | if (app->quirks & MT_QUIRK_CONFIDENCE) | ||
| 745 | input_set_abs_params(hi->input, | ||
| 746 | ABS_MT_TOOL_TYPE, | ||
| 747 | MT_TOOL_FINGER, | ||
| 748 | MT_TOOL_PALM, 0, 0); | ||
| 749 | |||
| 750 | MT_STORE_FIELD(confidence_state); | ||
| 553 | return 1; | 751 | return 1; |
| 554 | case HID_DG_TIPSWITCH: | 752 | case HID_DG_TIPSWITCH: |
| 555 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); | 753 | if (field->application != HID_GD_SYSTEM_MULTIAXIS) |
| 556 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); | 754 | input_set_capability(hi->input, |
| 557 | mt_store_field(usage, td, hi); | 755 | EV_KEY, BTN_TOUCH); |
| 756 | MT_STORE_FIELD(tip_state); | ||
| 558 | return 1; | 757 | return 1; |
| 559 | case HID_DG_CONTACTID: | 758 | case HID_DG_CONTACTID: |
| 560 | mt_store_field(usage, td, hi); | 759 | MT_STORE_FIELD(contactid); |
| 561 | td->touches_by_report++; | 760 | app->touches_by_report++; |
| 562 | td->mt_report_id = field->report->id; | ||
| 563 | return 1; | 761 | return 1; |
| 564 | case HID_DG_WIDTH: | 762 | case HID_DG_WIDTH: |
| 565 | hid_map_usage(hi, usage, bit, max, | 763 | if (!(app->quirks & MT_QUIRK_NO_AREA)) |
| 566 | EV_ABS, ABS_MT_TOUCH_MAJOR); | ||
| 567 | if (!(cls->quirks & MT_QUIRK_NO_AREA)) | ||
| 568 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, | 764 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, |
| 569 | cls->sn_width); | 765 | cls->sn_width); |
| 570 | mt_store_field(usage, td, hi); | 766 | MT_STORE_FIELD(w); |
| 571 | return 1; | 767 | return 1; |
| 572 | case HID_DG_HEIGHT: | 768 | case HID_DG_HEIGHT: |
| 573 | hid_map_usage(hi, usage, bit, max, | 769 | if (!(app->quirks & MT_QUIRK_NO_AREA)) { |
| 574 | EV_ABS, ABS_MT_TOUCH_MINOR); | ||
| 575 | if (!(cls->quirks & MT_QUIRK_NO_AREA)) { | ||
| 576 | set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, | 770 | set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, |
| 577 | cls->sn_height); | 771 | cls->sn_height); |
| 578 | 772 | ||
| @@ -585,41 +779,23 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 585 | input_set_abs_params(hi->input, | 779 | input_set_abs_params(hi->input, |
| 586 | ABS_MT_ORIENTATION, 0, 1, 0, 0); | 780 | ABS_MT_ORIENTATION, 0, 1, 0, 0); |
| 587 | } | 781 | } |
| 588 | mt_store_field(usage, td, hi); | 782 | MT_STORE_FIELD(h); |
| 589 | return 1; | 783 | return 1; |
| 590 | case HID_DG_TIPPRESSURE: | 784 | case HID_DG_TIPPRESSURE: |
| 591 | hid_map_usage(hi, usage, bit, max, | ||
| 592 | EV_ABS, ABS_MT_PRESSURE); | ||
| 593 | set_abs(hi->input, ABS_MT_PRESSURE, field, | 785 | set_abs(hi->input, ABS_MT_PRESSURE, field, |
| 594 | cls->sn_pressure); | 786 | cls->sn_pressure); |
| 595 | mt_store_field(usage, td, hi); | 787 | MT_STORE_FIELD(p); |
| 596 | return 1; | 788 | return 1; |
| 597 | case HID_DG_SCANTIME: | 789 | case HID_DG_SCANTIME: |
| 598 | hid_map_usage(hi, usage, bit, max, | ||
| 599 | EV_MSC, MSC_TIMESTAMP); | ||
| 600 | input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); | 790 | input_set_capability(hi->input, EV_MSC, MSC_TIMESTAMP); |
| 601 | /* Ignore if indexes are out of bounds. */ | 791 | app->scantime = &field->value[usage->usage_index]; |
| 602 | if (field->index >= field->report->maxfield || | 792 | app->scantime_logical_max = field->logical_maximum; |
| 603 | usage->usage_index >= field->report_count) | ||
| 604 | return 1; | ||
| 605 | td->scantime_index = field->index; | ||
| 606 | td->scantime_val_index = usage->usage_index; | ||
| 607 | /* | ||
| 608 | * We don't set td->last_slot_field as scan time is | ||
| 609 | * global to the report. | ||
| 610 | */ | ||
| 611 | return 1; | 793 | return 1; |
| 612 | case HID_DG_CONTACTCOUNT: | 794 | case HID_DG_CONTACTCOUNT: |
| 613 | /* Ignore if indexes are out of bounds. */ | 795 | app->have_contact_count = true; |
| 614 | if (field->index >= field->report->maxfield || | 796 | app->raw_cc = &field->value[usage->usage_index]; |
| 615 | usage->usage_index >= field->report_count) | ||
| 616 | return 1; | ||
| 617 | td->cc_index = field->index; | ||
| 618 | td->cc_value_index = usage->usage_index; | ||
| 619 | return 1; | 797 | return 1; |
| 620 | case HID_DG_AZIMUTH: | 798 | case HID_DG_AZIMUTH: |
| 621 | hid_map_usage(hi, usage, bit, max, | ||
| 622 | EV_ABS, ABS_MT_ORIENTATION); | ||
| 623 | /* | 799 | /* |
| 624 | * Azimuth has the range of [0, MAX) representing a full | 800 | * Azimuth has the range of [0, MAX) representing a full |
| 625 | * revolution. Set ABS_MT_ORIENTATION to a quarter of | 801 | * revolution. Set ABS_MT_ORIENTATION to a quarter of |
| @@ -630,11 +806,10 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 630 | field->logical_maximum / 4, | 806 | field->logical_maximum / 4, |
| 631 | cls->sn_move ? | 807 | cls->sn_move ? |
| 632 | field->logical_maximum / cls->sn_move : 0, 0); | 808 | field->logical_maximum / cls->sn_move : 0, 0); |
| 633 | mt_store_field(usage, td, hi); | 809 | MT_STORE_FIELD(a); |
| 634 | return 1; | 810 | return 1; |
| 635 | case HID_DG_CONTACTMAX: | 811 | case HID_DG_CONTACTMAX: |
| 636 | /* we don't set td->last_slot_field as contactcount and | 812 | /* contact max are global to the report */ |
| 637 | * contact max are global to the report */ | ||
| 638 | return -1; | 813 | return -1; |
| 639 | case HID_DG_TOUCH: | 814 | case HID_DG_TOUCH: |
| 640 | /* Legacy devices use TIPSWITCH and not TOUCH. | 815 | /* Legacy devices use TIPSWITCH and not TOUCH. |
| @@ -650,10 +825,14 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 650 | * MS PTP spec says that external buttons left and right have | 825 | * MS PTP spec says that external buttons left and right have |
| 651 | * usages 2 and 3. | 826 | * usages 2 and 3. |
| 652 | */ | 827 | */ |
| 653 | if ((cls->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && | 828 | if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && |
| 654 | field->application == HID_DG_TOUCHPAD && | 829 | field->application == HID_DG_TOUCHPAD && |
| 655 | (usage->hid & HID_USAGE) > 1) | 830 | (usage->hid & HID_USAGE) > 1) |
| 656 | code--; | 831 | code--; |
| 832 | |||
| 833 | if (field->application == HID_GD_SYSTEM_MULTIAXIS) | ||
| 834 | code = BTN_0 + ((usage->hid - 1) & HID_USAGE); | ||
| 835 | |||
| 657 | hid_map_usage(hi, usage, bit, max, EV_KEY, code); | 836 | hid_map_usage(hi, usage, bit, max, EV_KEY, code); |
| 658 | input_set_capability(hi->input, EV_KEY, code); | 837 | input_set_capability(hi->input, EV_KEY, code); |
| 659 | return 1; | 838 | return 1; |
| @@ -666,110 +845,68 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 666 | return 0; | 845 | return 0; |
| 667 | } | 846 | } |
| 668 | 847 | ||
| 669 | static int mt_compute_slot(struct mt_device *td, struct input_dev *input) | 848 | static int mt_compute_slot(struct mt_device *td, struct mt_application *app, |
| 849 | struct mt_usages *slot, | ||
| 850 | struct input_dev *input) | ||
| 670 | { | 851 | { |
| 671 | __s32 quirks = td->mtclass.quirks; | 852 | __s32 quirks = app->quirks; |
| 672 | 853 | ||
| 673 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) | 854 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) |
| 674 | return td->curdata.contactid; | 855 | return *slot->contactid; |
| 675 | 856 | ||
| 676 | if (quirks & MT_QUIRK_CYPRESS) | 857 | if (quirks & MT_QUIRK_CYPRESS) |
| 677 | return cypress_compute_slot(td); | 858 | return cypress_compute_slot(app, slot); |
| 678 | 859 | ||
| 679 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) | 860 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTNUMBER) |
| 680 | return td->num_received; | 861 | return app->num_received; |
| 681 | 862 | ||
| 682 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) | 863 | if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE) |
| 683 | return td->curdata.contactid - 1; | 864 | return *slot->contactid - 1; |
| 684 | 865 | ||
| 685 | return input_mt_get_slot_by_key(input, td->curdata.contactid); | 866 | return input_mt_get_slot_by_key(input, *slot->contactid); |
| 686 | } | 867 | } |
| 687 | 868 | ||
| 688 | /* | 869 | static void mt_release_pending_palms(struct mt_device *td, |
| 689 | * this function is called when a whole contact has been processed, | 870 | struct mt_application *app, |
| 690 | * so that it can assign it to a slot and store the data there | 871 | struct input_dev *input) |
| 691 | */ | ||
| 692 | static void mt_complete_slot(struct mt_device *td, struct input_dev *input) | ||
| 693 | { | 872 | { |
| 694 | if ((td->mtclass.quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && | 873 | int slotnum; |
| 695 | td->num_received >= td->num_expected) | 874 | bool need_sync = false; |
| 696 | return; | ||
| 697 | |||
| 698 | if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) { | ||
| 699 | int active; | ||
| 700 | int slotnum = mt_compute_slot(td, input); | ||
| 701 | struct mt_slot *s = &td->curdata; | ||
| 702 | struct input_mt *mt = input->mt; | ||
| 703 | 875 | ||
| 704 | if (slotnum < 0 || slotnum >= td->maxcontacts) | 876 | for_each_set_bit(slotnum, app->pending_palm_slots, td->maxcontacts) { |
| 705 | return; | 877 | clear_bit(slotnum, app->pending_palm_slots); |
| 706 | |||
| 707 | if ((td->mtclass.quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { | ||
| 708 | struct input_mt_slot *slot = &mt->slots[slotnum]; | ||
| 709 | if (input_mt_is_active(slot) && | ||
| 710 | input_mt_is_used(mt, slot)) | ||
| 711 | return; | ||
| 712 | } | ||
| 713 | |||
| 714 | if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE)) | ||
| 715 | s->confidence_state = true; | ||
| 716 | active = (s->touch_state || s->inrange_state) && | ||
| 717 | s->confidence_state; | ||
| 718 | 878 | ||
| 719 | input_mt_slot(input, slotnum); | 879 | input_mt_slot(input, slotnum); |
| 720 | input_mt_report_slot_state(input, MT_TOOL_FINGER, active); | 880 | input_mt_report_slot_state(input, MT_TOOL_PALM, false); |
| 721 | if (active) { | ||
| 722 | /* this finger is in proximity of the sensor */ | ||
| 723 | int wide = (s->w > s->h); | ||
| 724 | int major = max(s->w, s->h); | ||
| 725 | int minor = min(s->w, s->h); | ||
| 726 | int orientation = wide; | ||
| 727 | 881 | ||
| 728 | if (s->has_azimuth) | 882 | need_sync = true; |
| 729 | orientation = s->a; | ||
| 730 | |||
| 731 | /* | ||
| 732 | * divided by two to match visual scale of touch | ||
| 733 | * for devices with this quirk | ||
| 734 | */ | ||
| 735 | if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { | ||
| 736 | major = major >> 1; | ||
| 737 | minor = minor >> 1; | ||
| 738 | } | ||
| 739 | |||
| 740 | input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x); | ||
| 741 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y); | ||
| 742 | input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx); | ||
| 743 | input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy); | ||
| 744 | input_event(input, EV_ABS, ABS_MT_DISTANCE, | ||
| 745 | !s->touch_state); | ||
| 746 | input_event(input, EV_ABS, ABS_MT_ORIENTATION, | ||
| 747 | orientation); | ||
| 748 | input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); | ||
| 749 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); | ||
| 750 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); | ||
| 751 | |||
| 752 | set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); | ||
| 753 | } | ||
| 754 | } | 883 | } |
| 755 | 884 | ||
| 756 | td->num_received++; | 885 | if (need_sync) { |
| 886 | input_mt_sync_frame(input); | ||
| 887 | input_sync(input); | ||
| 888 | } | ||
| 757 | } | 889 | } |
| 758 | 890 | ||
| 759 | /* | 891 | /* |
| 760 | * this function is called when a whole packet has been received and processed, | 892 | * this function is called when a whole packet has been received and processed, |
| 761 | * so that it can decide what to send to the input layer. | 893 | * so that it can decide what to send to the input layer. |
| 762 | */ | 894 | */ |
| 763 | static void mt_sync_frame(struct mt_device *td, struct input_dev *input) | 895 | static void mt_sync_frame(struct mt_device *td, struct mt_application *app, |
| 896 | struct input_dev *input) | ||
| 764 | { | 897 | { |
| 765 | if (td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) | 898 | if (app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) |
| 766 | input_event(input, EV_KEY, BTN_LEFT, td->left_button_state); | 899 | input_event(input, EV_KEY, BTN_LEFT, app->left_button_state); |
| 767 | 900 | ||
| 768 | input_mt_sync_frame(input); | 901 | input_mt_sync_frame(input); |
| 769 | input_event(input, EV_MSC, MSC_TIMESTAMP, td->timestamp); | 902 | input_event(input, EV_MSC, MSC_TIMESTAMP, app->timestamp); |
| 770 | input_sync(input); | 903 | input_sync(input); |
| 771 | td->num_received = 0; | 904 | |
| 772 | td->left_button_state = 0; | 905 | mt_release_pending_palms(td, app, input); |
| 906 | |||
| 907 | app->num_received = 0; | ||
| 908 | app->left_button_state = 0; | ||
| 909 | |||
| 773 | if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) | 910 | if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) |
| 774 | set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); | 911 | set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); |
| 775 | else | 912 | else |
| @@ -777,17 +914,15 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input) | |||
| 777 | clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); | 914 | clear_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); |
| 778 | } | 915 | } |
| 779 | 916 | ||
| 780 | static int mt_compute_timestamp(struct mt_device *td, struct hid_field *field, | 917 | static int mt_compute_timestamp(struct mt_application *app, __s32 value) |
| 781 | __s32 value) | ||
| 782 | { | 918 | { |
| 783 | long delta = value - td->dev_time; | 919 | long delta = value - app->prev_scantime; |
| 784 | unsigned long jdelta = jiffies_to_usecs(jiffies - td->jiffies); | 920 | unsigned long jdelta = jiffies_to_usecs(jiffies - app->jiffies); |
| 785 | 921 | ||
| 786 | td->jiffies = jiffies; | 922 | app->jiffies = jiffies; |
| 787 | td->dev_time = value; | ||
| 788 | 923 | ||
| 789 | if (delta < 0) | 924 | if (delta < 0) |
| 790 | delta += field->logical_maximum; | 925 | delta += app->scantime_logical_max; |
| 791 | 926 | ||
| 792 | /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */ | 927 | /* HID_DG_SCANTIME is expressed in 100us, we want it in us. */ |
| 793 | delta *= 100; | 928 | delta *= 100; |
| @@ -796,7 +931,7 @@ static int mt_compute_timestamp(struct mt_device *td, struct hid_field *field, | |||
| 796 | /* No data received for a while, resync the timestamp. */ | 931 | /* No data received for a while, resync the timestamp. */ |
| 797 | return 0; | 932 | return 0; |
| 798 | else | 933 | else |
| 799 | return td->timestamp + delta; | 934 | return app->timestamp + delta; |
| 800 | } | 935 | } |
| 801 | 936 | ||
| 802 | static int mt_touch_event(struct hid_device *hid, struct hid_field *field, | 937 | static int mt_touch_event(struct hid_device *hid, struct hid_field *field, |
| @@ -809,63 +944,90 @@ static int mt_touch_event(struct hid_device *hid, struct hid_field *field, | |||
| 809 | return 1; | 944 | return 1; |
| 810 | } | 945 | } |
| 811 | 946 | ||
| 812 | static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, | 947 | static int mt_process_slot(struct mt_device *td, struct input_dev *input, |
| 813 | struct hid_usage *usage, __s32 value, | 948 | struct mt_application *app, |
| 814 | bool first_packet) | 949 | struct mt_usages *slot) |
| 815 | { | 950 | { |
| 816 | struct mt_device *td = hid_get_drvdata(hid); | 951 | struct input_mt *mt = input->mt; |
| 817 | __s32 quirks = td->mtclass.quirks; | 952 | __s32 quirks = app->quirks; |
| 818 | struct input_dev *input = field->hidinput->input; | 953 | bool valid = true; |
| 954 | bool confidence_state = true; | ||
| 955 | bool inrange_state = false; | ||
| 956 | int active; | ||
| 957 | int slotnum; | ||
| 958 | int tool = MT_TOOL_FINGER; | ||
| 959 | |||
| 960 | if (!slot) | ||
| 961 | return -EINVAL; | ||
| 819 | 962 | ||
| 820 | if (hid->claimed & HID_CLAIMED_INPUT) { | 963 | if ((quirks & MT_QUIRK_CONTACT_CNT_ACCURATE) && |
| 821 | switch (usage->hid) { | 964 | app->num_received >= app->num_expected) |
| 822 | case HID_DG_INRANGE: | 965 | return -EAGAIN; |
| 823 | if (quirks & MT_QUIRK_VALID_IS_INRANGE) | 966 | |
| 824 | td->curvalid = value; | 967 | if (!(quirks & MT_QUIRK_ALWAYS_VALID)) { |
| 825 | if (quirks & MT_QUIRK_HOVERING) | 968 | if (quirks & MT_QUIRK_VALID_IS_INRANGE) |
| 826 | td->curdata.inrange_state = value; | 969 | valid = *slot->inrange_state; |
| 827 | break; | 970 | if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) |
| 828 | case HID_DG_TIPSWITCH: | 971 | valid = *slot->tip_state; |
| 829 | if (quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) | 972 | if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) |
| 830 | td->curvalid = value; | 973 | valid = *slot->confidence_state; |
| 831 | td->curdata.touch_state = value; | 974 | |
| 832 | break; | 975 | if (!valid) |
| 833 | case HID_DG_CONFIDENCE: | 976 | return 0; |
| 834 | if (quirks & MT_QUIRK_CONFIDENCE) | 977 | } |
| 835 | td->curdata.confidence_state = value; | 978 | |
| 836 | if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE) | 979 | slotnum = mt_compute_slot(td, app, slot, input); |
| 837 | td->curvalid = value; | 980 | if (slotnum < 0 || slotnum >= td->maxcontacts) |
| 838 | break; | 981 | return 0; |
| 839 | case HID_DG_CONTACTID: | 982 | |
| 840 | td->curdata.contactid = value; | 983 | if ((quirks & MT_QUIRK_IGNORE_DUPLICATES) && mt) { |
| 841 | break; | 984 | struct input_mt_slot *i_slot = &mt->slots[slotnum]; |
| 842 | case HID_DG_TIPPRESSURE: | 985 | |
| 843 | td->curdata.p = value; | 986 | if (input_mt_is_active(i_slot) && |
| 844 | break; | 987 | input_mt_is_used(mt, i_slot)) |
| 845 | case HID_GD_X: | 988 | return -EAGAIN; |
| 846 | if (usage->code == ABS_MT_TOOL_X) | 989 | } |
| 847 | td->curdata.cx = value; | 990 | |
| 848 | else | 991 | if (quirks & MT_QUIRK_CONFIDENCE) |
| 849 | td->curdata.x = value; | 992 | confidence_state = *slot->confidence_state; |
| 850 | break; | 993 | |
| 851 | case HID_GD_Y: | 994 | if (quirks & MT_QUIRK_HOVERING) |
| 852 | if (usage->code == ABS_MT_TOOL_Y) | 995 | inrange_state = *slot->inrange_state; |
| 853 | td->curdata.cy = value; | 996 | |
| 854 | else | 997 | active = *slot->tip_state || inrange_state; |
| 855 | td->curdata.y = value; | 998 | |
| 856 | break; | 999 | if (app->application == HID_GD_SYSTEM_MULTIAXIS) |
| 857 | case HID_DG_WIDTH: | 1000 | tool = MT_TOOL_DIAL; |
| 858 | td->curdata.w = value; | 1001 | else if (unlikely(!confidence_state)) { |
| 859 | break; | 1002 | tool = MT_TOOL_PALM; |
| 860 | case HID_DG_HEIGHT: | 1003 | if (!active && |
| 861 | td->curdata.h = value; | 1004 | input_mt_is_active(&mt->slots[slotnum])) { |
| 862 | break; | 1005 | /* |
| 863 | case HID_DG_SCANTIME: | 1006 | * The non-confidence was reported for |
| 864 | td->timestamp = mt_compute_timestamp(td, field, value); | 1007 | * previously valid contact that is also no |
| 865 | break; | 1008 | * longer valid. We can't simply report |
| 866 | case HID_DG_CONTACTCOUNT: | 1009 | * lift-off as userspace will not be aware |
| 867 | break; | 1010 | * of non-confidence, so we need to split |
| 868 | case HID_DG_AZIMUTH: | 1011 | * it into 2 events: active MT_TOOL_PALM |
| 1012 | * and a separate liftoff. | ||
| 1013 | */ | ||
| 1014 | active = true; | ||
| 1015 | set_bit(slotnum, app->pending_palm_slots); | ||
| 1016 | } | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | input_mt_slot(input, slotnum); | ||
| 1020 | input_mt_report_slot_state(input, tool, active); | ||
| 1021 | if (active) { | ||
| 1022 | /* this finger is in proximity of the sensor */ | ||
| 1023 | int wide = (*slot->w > *slot->h); | ||
| 1024 | int major = max(*slot->w, *slot->h); | ||
| 1025 | int minor = min(*slot->w, *slot->h); | ||
| 1026 | int orientation = wide; | ||
| 1027 | int max_azimuth; | ||
| 1028 | int azimuth; | ||
| 1029 | |||
| 1030 | if (slot->a != DEFAULT_ZERO) { | ||
| 869 | /* | 1031 | /* |
| 870 | * Azimuth is counter-clockwise and ranges from [0, MAX) | 1032 | * Azimuth is counter-clockwise and ranges from [0, MAX) |
| 871 | * (a full revolution). Convert it to clockwise ranging | 1033 | * (a full revolution). Convert it to clockwise ranging |
| @@ -876,77 +1038,107 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, | |||
| 876 | * out of range to [-MAX/2, MAX/2] to report an upside | 1038 | * out of range to [-MAX/2, MAX/2] to report an upside |
| 877 | * down ellipsis. | 1039 | * down ellipsis. |
| 878 | */ | 1040 | */ |
| 879 | if (value > field->logical_maximum / 2) | 1041 | azimuth = *slot->a; |
| 880 | value -= field->logical_maximum; | 1042 | max_azimuth = input_abs_get_max(input, |
| 881 | td->curdata.a = -value; | 1043 | ABS_MT_ORIENTATION); |
| 882 | td->curdata.has_azimuth = true; | 1044 | if (azimuth > max_azimuth * 2) |
| 883 | break; | 1045 | azimuth -= max_azimuth * 4; |
| 884 | case HID_DG_TOUCH: | 1046 | orientation = -azimuth; |
| 885 | /* do nothing */ | 1047 | } |
| 886 | break; | ||
| 887 | 1048 | ||
| 888 | default: | 1049 | if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { |
| 889 | /* | 1050 | /* |
| 890 | * For Win8 PTP touchpads we should only look at | 1051 | * divided by two to match visual scale of touch |
| 891 | * non finger/touch events in the first_packet of | 1052 | * for devices with this quirk |
| 892 | * a (possible) multi-packet frame. | ||
| 893 | */ | 1053 | */ |
| 894 | if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && | 1054 | major = major >> 1; |
| 895 | !first_packet) | 1055 | minor = minor >> 1; |
| 896 | return; | 1056 | } |
| 897 | 1057 | ||
| 898 | /* | 1058 | input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); |
| 899 | * For Win8 PTP touchpads we map both the clickpad click | 1059 | input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); |
| 900 | * and any "external" left buttons to BTN_LEFT if a | 1060 | input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); |
| 901 | * device claims to have both we need to report 1 for | 1061 | input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); |
| 902 | * BTN_LEFT if either is pressed, so we or all values | 1062 | input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); |
| 903 | * together and report the result in mt_sync_frame(). | 1063 | input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); |
| 904 | */ | 1064 | input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); |
| 905 | if ((quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && | 1065 | input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); |
| 906 | usage->type == EV_KEY && usage->code == BTN_LEFT) { | 1066 | input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); |
| 907 | td->left_button_state |= value; | 1067 | |
| 908 | return; | 1068 | set_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags); |
| 909 | } | 1069 | } |
| 910 | 1070 | ||
| 911 | if (usage->type) | 1071 | return 0; |
| 912 | input_event(input, usage->type, usage->code, | 1072 | } |
| 913 | value); | 1073 | |
| 1074 | static void mt_process_mt_event(struct hid_device *hid, | ||
| 1075 | struct mt_application *app, | ||
| 1076 | struct hid_field *field, | ||
| 1077 | struct hid_usage *usage, | ||
| 1078 | __s32 value, | ||
| 1079 | bool first_packet) | ||
| 1080 | { | ||
| 1081 | __s32 quirks = app->quirks; | ||
| 1082 | struct input_dev *input = field->hidinput->input; | ||
| 1083 | |||
| 1084 | if (!usage->type || !(hid->claimed & HID_CLAIMED_INPUT)) | ||
| 1085 | return; | ||
| 1086 | |||
| 1087 | if (quirks & MT_QUIRK_WIN8_PTP_BUTTONS) { | ||
| 1088 | |||
| 1089 | /* | ||
| 1090 | * For Win8 PTP touchpads we should only look at | ||
| 1091 | * non finger/touch events in the first_packet of a | ||
| 1092 | * (possible) multi-packet frame. | ||
| 1093 | */ | ||
| 1094 | if (!first_packet) | ||
| 914 | return; | 1095 | return; |
| 915 | } | ||
| 916 | 1096 | ||
| 917 | if (usage->usage_index + 1 == field->report_count) { | 1097 | /* |
| 918 | /* we only take into account the last report. */ | 1098 | * For Win8 PTP touchpads we map both the clickpad click |
| 919 | if (usage->hid == td->last_slot_field) | 1099 | * and any "external" left buttons to BTN_LEFT if a |
| 920 | mt_complete_slot(td, field->hidinput->input); | 1100 | * device claims to have both we need to report 1 for |
| 1101 | * BTN_LEFT if either is pressed, so we or all values | ||
| 1102 | * together and report the result in mt_sync_frame(). | ||
| 1103 | */ | ||
| 1104 | if (usage->type == EV_KEY && usage->code == BTN_LEFT) { | ||
| 1105 | app->left_button_state |= value; | ||
| 1106 | return; | ||
| 921 | } | 1107 | } |
| 922 | |||
| 923 | } | 1108 | } |
| 1109 | |||
| 1110 | input_event(input, usage->type, usage->code, value); | ||
| 924 | } | 1111 | } |
| 925 | 1112 | ||
| 926 | static void mt_touch_report(struct hid_device *hid, struct hid_report *report) | 1113 | static void mt_touch_report(struct hid_device *hid, |
| 1114 | struct mt_report_data *rdata) | ||
| 927 | { | 1115 | { |
| 928 | struct mt_device *td = hid_get_drvdata(hid); | 1116 | struct mt_device *td = hid_get_drvdata(hid); |
| 1117 | struct hid_report *report = rdata->report; | ||
| 1118 | struct mt_application *app = rdata->application; | ||
| 929 | struct hid_field *field; | 1119 | struct hid_field *field; |
| 1120 | struct input_dev *input; | ||
| 1121 | struct mt_usages *slot; | ||
| 930 | bool first_packet; | 1122 | bool first_packet; |
| 931 | unsigned count; | 1123 | unsigned count; |
| 932 | int r, n, scantime = 0; | 1124 | int r, n; |
| 1125 | int scantime = 0; | ||
| 1126 | int contact_count = -1; | ||
| 933 | 1127 | ||
| 934 | /* sticky fingers release in progress, abort */ | 1128 | /* sticky fingers release in progress, abort */ |
| 935 | if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) | 1129 | if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) |
| 936 | return; | 1130 | return; |
| 937 | 1131 | ||
| 1132 | scantime = *app->scantime; | ||
| 1133 | app->timestamp = mt_compute_timestamp(app, scantime); | ||
| 1134 | if (app->raw_cc != DEFAULT_ZERO) | ||
| 1135 | contact_count = *app->raw_cc; | ||
| 1136 | |||
| 938 | /* | 1137 | /* |
| 939 | * Includes multi-packet support where subsequent | 1138 | * Includes multi-packet support where subsequent |
| 940 | * packets are sent with zero contactcount. | 1139 | * packets are sent with zero contactcount. |
| 941 | */ | 1140 | */ |
| 942 | if (td->scantime_index >= 0) { | 1141 | if (contact_count >= 0) { |
| 943 | field = report->field[td->scantime_index]; | ||
| 944 | scantime = field->value[td->scantime_val_index]; | ||
| 945 | } | ||
| 946 | if (td->cc_index >= 0) { | ||
| 947 | struct hid_field *field = report->field[td->cc_index]; | ||
| 948 | int value = field->value[td->cc_value_index]; | ||
| 949 | |||
| 950 | /* | 1142 | /* |
| 951 | * For Win8 PTPs the first packet (td->num_received == 0) may | 1143 | * For Win8 PTPs the first packet (td->num_received == 0) may |
| 952 | * have a contactcount of 0 if there only is a button event. | 1144 | * have a contactcount of 0 if there only is a button event. |
| @@ -954,16 +1146,25 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) | |||
| 954 | * of a possible multi-packet frame be checking that the | 1146 | * of a possible multi-packet frame be checking that the |
| 955 | * timestamp has changed. | 1147 | * timestamp has changed. |
| 956 | */ | 1148 | */ |
| 957 | if ((td->mtclass.quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && | 1149 | if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) && |
| 958 | td->num_received == 0 && td->prev_scantime != scantime) | 1150 | app->num_received == 0 && |
| 959 | td->num_expected = value; | 1151 | app->prev_scantime != scantime) |
| 1152 | app->num_expected = contact_count; | ||
| 960 | /* A non 0 contact count always indicates a first packet */ | 1153 | /* A non 0 contact count always indicates a first packet */ |
| 961 | else if (value) | 1154 | else if (contact_count) |
| 962 | td->num_expected = value; | 1155 | app->num_expected = contact_count; |
| 1156 | } | ||
| 1157 | app->prev_scantime = scantime; | ||
| 1158 | |||
| 1159 | first_packet = app->num_received == 0; | ||
| 1160 | |||
| 1161 | input = report->field[0]->hidinput->input; | ||
| 1162 | |||
| 1163 | list_for_each_entry(slot, &app->mt_usages, list) { | ||
| 1164 | if (!mt_process_slot(td, input, app, slot)) | ||
| 1165 | app->num_received++; | ||
| 963 | } | 1166 | } |
| 964 | td->prev_scantime = scantime; | ||
| 965 | 1167 | ||
| 966 | first_packet = td->num_received == 0; | ||
| 967 | for (r = 0; r < report->maxfield; r++) { | 1168 | for (r = 0; r < report->maxfield; r++) { |
| 968 | field = report->field[r]; | 1169 | field = report->field[r]; |
| 969 | count = field->report_count; | 1170 | count = field->report_count; |
| @@ -972,12 +1173,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) | |||
| 972 | continue; | 1173 | continue; |
| 973 | 1174 | ||
| 974 | for (n = 0; n < count; n++) | 1175 | for (n = 0; n < count; n++) |
| 975 | mt_process_mt_event(hid, field, &field->usage[n], | 1176 | mt_process_mt_event(hid, app, field, |
| 976 | field->value[n], first_packet); | 1177 | &field->usage[n], field->value[n], |
| 1178 | first_packet); | ||
| 977 | } | 1179 | } |
| 978 | 1180 | ||
| 979 | if (td->num_received >= td->num_expected) | 1181 | if (app->num_received >= app->num_expected) |
| 980 | mt_sync_frame(td, report->field[0]->hidinput->input); | 1182 | mt_sync_frame(td, app, input); |
| 981 | 1183 | ||
| 982 | /* | 1184 | /* |
| 983 | * Windows 8 specs says 2 things: | 1185 | * Windows 8 specs says 2 things: |
| @@ -997,7 +1199,7 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) | |||
| 997 | * only affect laggish machines and the ones that have a firmware | 1199 | * only affect laggish machines and the ones that have a firmware |
| 998 | * defect. | 1200 | * defect. |
| 999 | */ | 1201 | */ |
| 1000 | if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) { | 1202 | if (app->quirks & MT_QUIRK_STICKY_FINGERS) { |
| 1001 | if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags)) | 1203 | if (test_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags)) |
| 1002 | mod_timer(&td->release_timer, | 1204 | mod_timer(&td->release_timer, |
| 1003 | jiffies + msecs_to_jiffies(100)); | 1205 | jiffies + msecs_to_jiffies(100)); |
| @@ -1009,7 +1211,8 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) | |||
| 1009 | } | 1211 | } |
| 1010 | 1212 | ||
| 1011 | static int mt_touch_input_configured(struct hid_device *hdev, | 1213 | static int mt_touch_input_configured(struct hid_device *hdev, |
| 1012 | struct hid_input *hi) | 1214 | struct hid_input *hi, |
| 1215 | struct mt_application *app) | ||
| 1013 | { | 1216 | { |
| 1014 | struct mt_device *td = hid_get_drvdata(hdev); | 1217 | struct mt_device *td = hid_get_drvdata(hdev); |
| 1015 | struct mt_class *cls = &td->mtclass; | 1218 | struct mt_class *cls = &td->mtclass; |
| @@ -1019,28 +1222,36 @@ static int mt_touch_input_configured(struct hid_device *hdev, | |||
| 1019 | if (!td->maxcontacts) | 1222 | if (!td->maxcontacts) |
| 1020 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; | 1223 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; |
| 1021 | 1224 | ||
| 1022 | mt_post_parse(td); | 1225 | mt_post_parse(td, app); |
| 1023 | if (td->serial_maybe) | 1226 | if (td->serial_maybe) |
| 1024 | mt_post_parse_default_settings(td); | 1227 | mt_post_parse_default_settings(td, app); |
| 1025 | 1228 | ||
| 1026 | if (cls->is_indirect) | 1229 | if (cls->is_indirect) |
| 1027 | td->mt_flags |= INPUT_MT_POINTER; | 1230 | app->mt_flags |= INPUT_MT_POINTER; |
| 1028 | 1231 | ||
| 1029 | if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) | 1232 | if (app->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) |
| 1030 | td->mt_flags |= INPUT_MT_DROP_UNUSED; | 1233 | app->mt_flags |= INPUT_MT_DROP_UNUSED; |
| 1031 | 1234 | ||
| 1032 | /* check for clickpads */ | 1235 | /* check for clickpads */ |
| 1033 | if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1)) | 1236 | if ((app->mt_flags & INPUT_MT_POINTER) && |
| 1237 | (app->buttons_count == 1)) | ||
| 1034 | td->is_buttonpad = true; | 1238 | td->is_buttonpad = true; |
| 1035 | 1239 | ||
| 1036 | if (td->is_buttonpad) | 1240 | if (td->is_buttonpad) |
| 1037 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); | 1241 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
| 1038 | 1242 | ||
| 1039 | ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); | 1243 | app->pending_palm_slots = devm_kcalloc(&hi->input->dev, |
| 1244 | BITS_TO_LONGS(td->maxcontacts), | ||
| 1245 | sizeof(long), | ||
| 1246 | GFP_KERNEL); | ||
| 1247 | if (!app->pending_palm_slots) | ||
| 1248 | return -ENOMEM; | ||
| 1249 | |||
| 1250 | ret = input_mt_init_slots(input, td->maxcontacts, app->mt_flags); | ||
| 1040 | if (ret) | 1251 | if (ret) |
| 1041 | return ret; | 1252 | return ret; |
| 1042 | 1253 | ||
| 1043 | td->mt_flags = 0; | 1254 | app->mt_flags = 0; |
| 1044 | return 0; | 1255 | return 0; |
| 1045 | } | 1256 | } |
| 1046 | 1257 | ||
| @@ -1051,6 +1262,16 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 1051 | unsigned long **bit, int *max) | 1262 | unsigned long **bit, int *max) |
| 1052 | { | 1263 | { |
| 1053 | struct mt_device *td = hid_get_drvdata(hdev); | 1264 | struct mt_device *td = hid_get_drvdata(hdev); |
| 1265 | struct mt_application *application; | ||
| 1266 | struct mt_report_data *rdata; | ||
| 1267 | |||
| 1268 | rdata = mt_find_report_data(td, field->report); | ||
| 1269 | if (!rdata) { | ||
| 1270 | hid_err(hdev, "failed to allocate data for report\n"); | ||
| 1271 | return 0; | ||
| 1272 | } | ||
| 1273 | |||
| 1274 | application = rdata->application; | ||
| 1054 | 1275 | ||
| 1055 | /* | 1276 | /* |
| 1056 | * If mtclass.export_all_inputs is not set, only map fields from | 1277 | * If mtclass.export_all_inputs is not set, only map fields from |
| @@ -1066,8 +1287,9 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 1066 | field->application != HID_GD_SYSTEM_CONTROL && | 1287 | field->application != HID_GD_SYSTEM_CONTROL && |
| 1067 | field->application != HID_CP_CONSUMER_CONTROL && | 1288 | field->application != HID_CP_CONSUMER_CONTROL && |
| 1068 | field->application != HID_GD_WIRELESS_RADIO_CTLS && | 1289 | field->application != HID_GD_WIRELESS_RADIO_CTLS && |
| 1290 | field->application != HID_GD_SYSTEM_MULTIAXIS && | ||
| 1069 | !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && | 1291 | !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && |
| 1070 | td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP)) | 1292 | application->quirks & MT_QUIRK_ASUS_CUSTOM_UP)) |
| 1071 | return -1; | 1293 | return -1; |
| 1072 | 1294 | ||
| 1073 | /* | 1295 | /* |
| @@ -1076,7 +1298,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 1076 | * map usages to input keys. | 1298 | * map usages to input keys. |
| 1077 | */ | 1299 | */ |
| 1078 | if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && | 1300 | if (field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS && |
| 1079 | td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP && | 1301 | application->quirks & MT_QUIRK_ASUS_CUSTOM_UP && |
| 1080 | (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) { | 1302 | (usage->hid & HID_USAGE_PAGE) == HID_UP_CUSTOM) { |
| 1081 | set_bit(EV_REP, hi->input->evbit); | 1303 | set_bit(EV_REP, hi->input->evbit); |
| 1082 | if (field->flags & HID_MAIN_ITEM_VARIABLE) | 1304 | if (field->flags & HID_MAIN_ITEM_VARIABLE) |
| @@ -1093,23 +1315,9 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 1093 | return 1; | 1315 | return 1; |
| 1094 | } | 1316 | } |
| 1095 | 1317 | ||
| 1096 | /* | 1318 | if (rdata->is_mt_collection) |
| 1097 | * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" | 1319 | return mt_touch_input_mapping(hdev, hi, field, usage, bit, max, |
| 1098 | * for the stylus. | 1320 | application); |
| 1099 | * The check for mt_report_id ensures we don't process | ||
| 1100 | * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical | ||
| 1101 | * collection, but within the report ID. | ||
| 1102 | */ | ||
| 1103 | if (field->physical == HID_DG_STYLUS) | ||
| 1104 | return 0; | ||
| 1105 | else if ((field->physical == 0) && | ||
| 1106 | (field->report->id != td->mt_report_id) && | ||
| 1107 | (td->mt_report_id != -1)) | ||
| 1108 | return 0; | ||
| 1109 | |||
| 1110 | if (field->application == HID_DG_TOUCHSCREEN || | ||
| 1111 | field->application == HID_DG_TOUCHPAD) | ||
| 1112 | return mt_touch_input_mapping(hdev, hi, field, usage, bit, max); | ||
| 1113 | 1321 | ||
| 1114 | /* let hid-core decide for the others */ | 1322 | /* let hid-core decide for the others */ |
| 1115 | return 0; | 1323 | return 0; |
| @@ -1119,15 +1327,11 @@ static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi, | |||
| 1119 | struct hid_field *field, struct hid_usage *usage, | 1327 | struct hid_field *field, struct hid_usage *usage, |
| 1120 | unsigned long **bit, int *max) | 1328 | unsigned long **bit, int *max) |
| 1121 | { | 1329 | { |
| 1122 | /* | 1330 | struct mt_device *td = hid_get_drvdata(hdev); |
| 1123 | * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN" | 1331 | struct mt_report_data *rdata; |
| 1124 | * for the stylus. | ||
| 1125 | */ | ||
| 1126 | if (field->physical == HID_DG_STYLUS) | ||
| 1127 | return 0; | ||
| 1128 | 1332 | ||
| 1129 | if (field->application == HID_DG_TOUCHSCREEN || | 1333 | rdata = mt_find_report_data(td, field->report); |
| 1130 | field->application == HID_DG_TOUCHPAD) { | 1334 | if (rdata && rdata->is_mt_collection) { |
| 1131 | /* We own these mappings, tell hid-input to ignore them */ | 1335 | /* We own these mappings, tell hid-input to ignore them */ |
| 1132 | return -1; | 1336 | return -1; |
| 1133 | } | 1337 | } |
| @@ -1140,8 +1344,10 @@ static int mt_event(struct hid_device *hid, struct hid_field *field, | |||
| 1140 | struct hid_usage *usage, __s32 value) | 1344 | struct hid_usage *usage, __s32 value) |
| 1141 | { | 1345 | { |
| 1142 | struct mt_device *td = hid_get_drvdata(hid); | 1346 | struct mt_device *td = hid_get_drvdata(hid); |
| 1347 | struct mt_report_data *rdata; | ||
| 1143 | 1348 | ||
| 1144 | if (field->report->id == td->mt_report_id) | 1349 | rdata = mt_find_report_data(td, field->report); |
| 1350 | if (rdata && rdata->is_mt_collection) | ||
| 1145 | return mt_touch_event(hid, field, usage, value); | 1351 | return mt_touch_event(hid, field, usage, value); |
| 1146 | 1352 | ||
| 1147 | return 0; | 1353 | return 0; |
| @@ -1151,12 +1357,14 @@ static void mt_report(struct hid_device *hid, struct hid_report *report) | |||
| 1151 | { | 1357 | { |
| 1152 | struct mt_device *td = hid_get_drvdata(hid); | 1358 | struct mt_device *td = hid_get_drvdata(hid); |
| 1153 | struct hid_field *field = report->field[0]; | 1359 | struct hid_field *field = report->field[0]; |
| 1360 | struct mt_report_data *rdata; | ||
| 1154 | 1361 | ||
| 1155 | if (!(hid->claimed & HID_CLAIMED_INPUT)) | 1362 | if (!(hid->claimed & HID_CLAIMED_INPUT)) |
| 1156 | return; | 1363 | return; |
| 1157 | 1364 | ||
| 1158 | if (report->id == td->mt_report_id) | 1365 | rdata = mt_find_report_data(td, report); |
| 1159 | return mt_touch_report(hid, report); | 1366 | if (rdata && rdata->is_mt_collection) |
| 1367 | return mt_touch_report(hid, rdata); | ||
| 1160 | 1368 | ||
| 1161 | if (field && field->hidinput && field->hidinput->input) | 1369 | if (field && field->hidinput && field->hidinput->input) |
| 1162 | input_sync(field->hidinput->input); | 1370 | input_sync(field->hidinput->input); |
| @@ -1197,9 +1405,9 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev, | |||
| 1197 | return true; | 1405 | return true; |
| 1198 | 1406 | ||
| 1199 | case HID_DG_CONTACTMAX: | 1407 | case HID_DG_CONTACTMAX: |
| 1200 | if (td->mtclass.maxcontacts) { | 1408 | if (cls->maxcontacts) { |
| 1201 | max = min_t(int, field->logical_maximum, | 1409 | max = min_t(int, field->logical_maximum, |
| 1202 | td->mtclass.maxcontacts); | 1410 | cls->maxcontacts); |
| 1203 | if (field->value[index] != max) { | 1411 | if (field->value[index] != max) { |
| 1204 | field->value[index] = max; | 1412 | field->value[index] = max; |
| 1205 | return true; | 1413 | return true; |
| @@ -1259,12 +1467,13 @@ static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency, | |||
| 1259 | } | 1467 | } |
| 1260 | } | 1468 | } |
| 1261 | 1469 | ||
| 1262 | static void mt_post_parse_default_settings(struct mt_device *td) | 1470 | static void mt_post_parse_default_settings(struct mt_device *td, |
| 1471 | struct mt_application *app) | ||
| 1263 | { | 1472 | { |
| 1264 | __s32 quirks = td->mtclass.quirks; | 1473 | __s32 quirks = app->quirks; |
| 1265 | 1474 | ||
| 1266 | /* unknown serial device needs special quirks */ | 1475 | /* unknown serial device needs special quirks */ |
| 1267 | if (td->touches_by_report == 1) { | 1476 | if (list_is_singular(&app->mt_usages)) { |
| 1268 | quirks |= MT_QUIRK_ALWAYS_VALID; | 1477 | quirks |= MT_QUIRK_ALWAYS_VALID; |
| 1269 | quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP; | 1478 | quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP; |
| 1270 | quirks &= ~MT_QUIRK_VALID_IS_INRANGE; | 1479 | quirks &= ~MT_QUIRK_VALID_IS_INRANGE; |
| @@ -1272,21 +1481,13 @@ static void mt_post_parse_default_settings(struct mt_device *td) | |||
| 1272 | quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; | 1481 | quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; |
| 1273 | } | 1482 | } |
| 1274 | 1483 | ||
| 1275 | td->mtclass.quirks = quirks; | 1484 | app->quirks = quirks; |
| 1276 | } | 1485 | } |
| 1277 | 1486 | ||
| 1278 | static void mt_post_parse(struct mt_device *td) | 1487 | static void mt_post_parse(struct mt_device *td, struct mt_application *app) |
| 1279 | { | 1488 | { |
| 1280 | struct mt_fields *f = td->fields; | 1489 | if (!app->have_contact_count) |
| 1281 | struct mt_class *cls = &td->mtclass; | 1490 | app->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; |
| 1282 | |||
| 1283 | if (td->touches_by_report > 0) { | ||
| 1284 | int field_count_per_touch = f->length / td->touches_by_report; | ||
| 1285 | td->last_slot_field = f->usages[field_count_per_touch - 1]; | ||
| 1286 | } | ||
| 1287 | |||
| 1288 | if (td->cc_index < 0) | ||
| 1289 | cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; | ||
| 1290 | } | 1491 | } |
| 1291 | 1492 | ||
| 1292 | static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) | 1493 | static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) |
| @@ -1295,13 +1496,24 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
| 1295 | char *name; | 1496 | char *name; |
| 1296 | const char *suffix = NULL; | 1497 | const char *suffix = NULL; |
| 1297 | unsigned int application = 0; | 1498 | unsigned int application = 0; |
| 1499 | struct mt_report_data *rdata; | ||
| 1500 | struct mt_application *mt_application = NULL; | ||
| 1298 | struct hid_report *report; | 1501 | struct hid_report *report; |
| 1299 | int ret; | 1502 | int ret; |
| 1300 | 1503 | ||
| 1301 | list_for_each_entry(report, &hi->reports, hidinput_list) { | 1504 | list_for_each_entry(report, &hi->reports, hidinput_list) { |
| 1302 | application = report->application; | 1505 | application = report->application; |
| 1303 | if (report->id == td->mt_report_id) { | 1506 | rdata = mt_find_report_data(td, report); |
| 1304 | ret = mt_touch_input_configured(hdev, hi); | 1507 | if (!rdata) { |
| 1508 | hid_err(hdev, "failed to allocate data for report\n"); | ||
| 1509 | return -ENOMEM; | ||
| 1510 | } | ||
| 1511 | |||
| 1512 | mt_application = rdata->application; | ||
| 1513 | |||
| 1514 | if (rdata->is_mt_collection) { | ||
| 1515 | ret = mt_touch_input_configured(hdev, hi, | ||
| 1516 | mt_application); | ||
| 1305 | if (ret) | 1517 | if (ret) |
| 1306 | return ret; | 1518 | return ret; |
| 1307 | } | 1519 | } |
| @@ -1327,6 +1539,7 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) | |||
| 1327 | case HID_GD_SYSTEM_CONTROL: | 1539 | case HID_GD_SYSTEM_CONTROL: |
| 1328 | case HID_CP_CONSUMER_CONTROL: | 1540 | case HID_CP_CONSUMER_CONTROL: |
| 1329 | case HID_GD_WIRELESS_RADIO_CTLS: | 1541 | case HID_GD_WIRELESS_RADIO_CTLS: |
| 1542 | case HID_GD_SYSTEM_MULTIAXIS: | ||
| 1330 | /* already handled by hid core */ | 1543 | /* already handled by hid core */ |
| 1331 | break; | 1544 | break; |
| 1332 | case HID_DG_TOUCHSCREEN: | 1545 | case HID_DG_TOUCHSCREEN: |
| @@ -1390,6 +1603,7 @@ static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage) | |||
| 1390 | static void mt_release_contacts(struct hid_device *hid) | 1603 | static void mt_release_contacts(struct hid_device *hid) |
| 1391 | { | 1604 | { |
| 1392 | struct hid_input *hidinput; | 1605 | struct hid_input *hidinput; |
| 1606 | struct mt_application *application; | ||
| 1393 | struct mt_device *td = hid_get_drvdata(hid); | 1607 | struct mt_device *td = hid_get_drvdata(hid); |
| 1394 | 1608 | ||
| 1395 | list_for_each_entry(hidinput, &hid->inputs, list) { | 1609 | list_for_each_entry(hidinput, &hid->inputs, list) { |
| @@ -1409,7 +1623,9 @@ static void mt_release_contacts(struct hid_device *hid) | |||
| 1409 | } | 1623 | } |
| 1410 | } | 1624 | } |
| 1411 | 1625 | ||
| 1412 | td->num_received = 0; | 1626 | list_for_each_entry(application, &td->applications, list) { |
| 1627 | application->num_received = 0; | ||
| 1628 | } | ||
| 1413 | } | 1629 | } |
| 1414 | 1630 | ||
| 1415 | static void mt_expired_timeout(struct timer_list *t) | 1631 | static void mt_expired_timeout(struct timer_list *t) |
| @@ -1432,7 +1648,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1432 | { | 1648 | { |
| 1433 | int ret, i; | 1649 | int ret, i; |
| 1434 | struct mt_device *td; | 1650 | struct mt_device *td; |
| 1435 | struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ | 1651 | const struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ |
| 1436 | 1652 | ||
| 1437 | for (i = 0; mt_classes[i].name ; i++) { | 1653 | for (i = 0; mt_classes[i].name ; i++) { |
| 1438 | if (id->driver_data == mt_classes[i].name) { | 1654 | if (id->driver_data == mt_classes[i].name) { |
| @@ -1449,17 +1665,10 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1449 | td->hdev = hdev; | 1665 | td->hdev = hdev; |
| 1450 | td->mtclass = *mtclass; | 1666 | td->mtclass = *mtclass; |
| 1451 | td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; | 1667 | td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; |
| 1452 | td->cc_index = -1; | ||
| 1453 | td->scantime_index = -1; | ||
| 1454 | td->mt_report_id = -1; | ||
| 1455 | hid_set_drvdata(hdev, td); | 1668 | hid_set_drvdata(hdev, td); |
| 1456 | 1669 | ||
| 1457 | td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields), | 1670 | INIT_LIST_HEAD(&td->applications); |
| 1458 | GFP_KERNEL); | 1671 | INIT_LIST_HEAD(&td->reports); |
| 1459 | if (!td->fields) { | ||
| 1460 | dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); | ||
| 1461 | return -ENOMEM; | ||
| 1462 | } | ||
| 1463 | 1672 | ||
| 1464 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) | 1673 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) |
| 1465 | td->serial_maybe = true; | 1674 | td->serial_maybe = true; |
| @@ -1496,10 +1705,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 1496 | 1705 | ||
| 1497 | mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); | 1706 | mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); |
| 1498 | 1707 | ||
| 1499 | /* release .fields memory as it is not used anymore */ | ||
| 1500 | devm_kfree(&hdev->dev, td->fields); | ||
| 1501 | td->fields = NULL; | ||
| 1502 | |||
| 1503 | return 0; | 1708 | return 0; |
| 1504 | } | 1709 | } |
| 1505 | 1710 | ||
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 43b1c7234316..9bc6f4867cb3 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c | |||
| @@ -955,6 +955,8 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 955 | 955 | ||
| 956 | ret = sysfs_create_group(&hdev->dev.kobj, | 956 | ret = sysfs_create_group(&hdev->dev.kobj, |
| 957 | &ntrig_attribute_group); | 957 | &ntrig_attribute_group); |
| 958 | if (ret) | ||
| 959 | hid_err(hdev, "cannot create sysfs group\n"); | ||
| 958 | 960 | ||
| 959 | return 0; | 961 | return 0; |
| 960 | err_free: | 962 | err_free: |
diff --git a/drivers/hid/hid-redragon.c b/drivers/hid/hid-redragon.c index daf59578bf93..73c9d4c4fa34 100644 --- a/drivers/hid/hid-redragon.c +++ b/drivers/hid/hid-redragon.c | |||
| @@ -44,29 +44,6 @@ static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc, | |||
| 44 | return rdesc; | 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 | static const struct hid_device_id redragon_devices[] = { | 47 | static const struct hid_device_id redragon_devices[] = { |
| 71 | {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)}, | 48 | {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)}, |
| 72 | {} | 49 | {} |
| @@ -77,8 +54,7 @@ MODULE_DEVICE_TABLE(hid, redragon_devices); | |||
| 77 | static struct hid_driver redragon_driver = { | 54 | static struct hid_driver redragon_driver = { |
| 78 | .name = "redragon", | 55 | .name = "redragon", |
| 79 | .id_table = redragon_devices, | 56 | .id_table = redragon_devices, |
| 80 | .report_fixup = redragon_report_fixup, | 57 | .report_fixup = redragon_report_fixup |
| 81 | .probe = redragon_probe | ||
| 82 | }; | 58 | }; |
| 83 | 59 | ||
| 84 | module_hid_driver(redragon_driver); | 60 | module_hid_driver(redragon_driver); |
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index e475c5073c99..9671a4bad643 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c | |||
| @@ -1353,7 +1353,7 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | |||
| 1353 | char *name; | 1353 | char *name; |
| 1354 | int ret; | 1354 | int ret; |
| 1355 | 1355 | ||
| 1356 | sc->touchpad = input_allocate_device(); | 1356 | sc->touchpad = devm_input_allocate_device(&sc->hdev->dev); |
| 1357 | if (!sc->touchpad) | 1357 | if (!sc->touchpad) |
| 1358 | return -ENOMEM; | 1358 | return -ENOMEM; |
| 1359 | 1359 | ||
| @@ -1370,11 +1370,9 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | |||
| 1370 | * DS4 compatible non-Sony devices with different names. | 1370 | * DS4 compatible non-Sony devices with different names. |
| 1371 | */ | 1371 | */ |
| 1372 | name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); | 1372 | name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); |
| 1373 | name = kzalloc(name_sz, GFP_KERNEL); | 1373 | name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); |
| 1374 | if (!name) { | 1374 | if (!name) |
| 1375 | ret = -ENOMEM; | 1375 | return -ENOMEM; |
| 1376 | goto err; | ||
| 1377 | } | ||
| 1378 | snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); | 1376 | snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); |
| 1379 | sc->touchpad->name = name; | 1377 | sc->touchpad->name = name; |
| 1380 | 1378 | ||
| @@ -1403,34 +1401,13 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | |||
| 1403 | 1401 | ||
| 1404 | ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); | 1402 | ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); |
| 1405 | if (ret < 0) | 1403 | if (ret < 0) |
| 1406 | goto err; | 1404 | return ret; |
| 1407 | 1405 | ||
| 1408 | ret = input_register_device(sc->touchpad); | 1406 | ret = input_register_device(sc->touchpad); |
| 1409 | if (ret < 0) | 1407 | if (ret < 0) |
| 1410 | goto err; | 1408 | return ret; |
| 1411 | 1409 | ||
| 1412 | return 0; | 1410 | return 0; |
| 1413 | |||
| 1414 | err: | ||
| 1415 | kfree(sc->touchpad->name); | ||
| 1416 | sc->touchpad->name = NULL; | ||
| 1417 | |||
| 1418 | input_free_device(sc->touchpad); | ||
| 1419 | sc->touchpad = NULL; | ||
| 1420 | |||
| 1421 | return ret; | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | static void sony_unregister_touchpad(struct sony_sc *sc) | ||
| 1425 | { | ||
| 1426 | if (!sc->touchpad) | ||
| 1427 | return; | ||
| 1428 | |||
| 1429 | kfree(sc->touchpad->name); | ||
| 1430 | sc->touchpad->name = NULL; | ||
| 1431 | |||
| 1432 | input_unregister_device(sc->touchpad); | ||
| 1433 | sc->touchpad = NULL; | ||
| 1434 | } | 1411 | } |
| 1435 | 1412 | ||
| 1436 | static int sony_register_sensors(struct sony_sc *sc) | 1413 | static int sony_register_sensors(struct sony_sc *sc) |
| @@ -1440,7 +1417,7 @@ static int sony_register_sensors(struct sony_sc *sc) | |||
| 1440 | int ret; | 1417 | int ret; |
| 1441 | int range; | 1418 | int range; |
| 1442 | 1419 | ||
| 1443 | sc->sensor_dev = input_allocate_device(); | 1420 | sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev); |
| 1444 | if (!sc->sensor_dev) | 1421 | if (!sc->sensor_dev) |
| 1445 | return -ENOMEM; | 1422 | return -ENOMEM; |
| 1446 | 1423 | ||
| @@ -1457,11 +1434,9 @@ static int sony_register_sensors(struct sony_sc *sc) | |||
| 1457 | * DS4 compatible non-Sony devices with different names. | 1434 | * DS4 compatible non-Sony devices with different names. |
| 1458 | */ | 1435 | */ |
| 1459 | name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); | 1436 | name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); |
| 1460 | name = kzalloc(name_sz, GFP_KERNEL); | 1437 | name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); |
| 1461 | if (!name) { | 1438 | if (!name) |
| 1462 | ret = -ENOMEM; | 1439 | return -ENOMEM; |
| 1463 | goto err; | ||
| 1464 | } | ||
| 1465 | snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); | 1440 | snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); |
| 1466 | sc->sensor_dev->name = name; | 1441 | sc->sensor_dev->name = name; |
| 1467 | 1442 | ||
| @@ -1503,33 +1478,11 @@ static int sony_register_sensors(struct sony_sc *sc) | |||
| 1503 | 1478 | ||
| 1504 | ret = input_register_device(sc->sensor_dev); | 1479 | ret = input_register_device(sc->sensor_dev); |
| 1505 | if (ret < 0) | 1480 | if (ret < 0) |
| 1506 | goto err; | 1481 | return ret; |
| 1507 | 1482 | ||
| 1508 | return 0; | 1483 | return 0; |
| 1509 | |||
| 1510 | err: | ||
| 1511 | kfree(sc->sensor_dev->name); | ||
| 1512 | sc->sensor_dev->name = NULL; | ||
| 1513 | |||
| 1514 | input_free_device(sc->sensor_dev); | ||
| 1515 | sc->sensor_dev = NULL; | ||
| 1516 | |||
| 1517 | return ret; | ||
| 1518 | } | 1484 | } |
| 1519 | 1485 | ||
| 1520 | static void sony_unregister_sensors(struct sony_sc *sc) | ||
| 1521 | { | ||
| 1522 | if (!sc->sensor_dev) | ||
| 1523 | return; | ||
| 1524 | |||
| 1525 | kfree(sc->sensor_dev->name); | ||
| 1526 | sc->sensor_dev->name = NULL; | ||
| 1527 | |||
| 1528 | input_unregister_device(sc->sensor_dev); | ||
| 1529 | sc->sensor_dev = NULL; | ||
| 1530 | } | ||
| 1531 | |||
| 1532 | |||
| 1533 | /* | 1486 | /* |
| 1534 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | 1487 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 1535 | * to "operational". Without this, the ps3 controller will not report any | 1488 | * to "operational". Without this, the ps3 controller will not report any |
| @@ -1987,25 +1940,6 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on, | |||
| 1987 | return 0; | 1940 | return 0; |
| 1988 | } | 1941 | } |
| 1989 | 1942 | ||
| 1990 | static void sony_leds_remove(struct sony_sc *sc) | ||
| 1991 | { | ||
| 1992 | struct led_classdev *led; | ||
| 1993 | int n; | ||
| 1994 | |||
| 1995 | BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); | ||
| 1996 | |||
| 1997 | for (n = 0; n < sc->led_count; n++) { | ||
| 1998 | led = sc->leds[n]; | ||
| 1999 | sc->leds[n] = NULL; | ||
| 2000 | if (!led) | ||
| 2001 | continue; | ||
| 2002 | led_classdev_unregister(led); | ||
| 2003 | kfree(led); | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | sc->led_count = 0; | ||
| 2007 | } | ||
| 2008 | |||
| 2009 | static int sony_leds_init(struct sony_sc *sc) | 1943 | static int sony_leds_init(struct sony_sc *sc) |
| 2010 | { | 1944 | { |
| 2011 | struct hid_device *hdev = sc->hdev; | 1945 | struct hid_device *hdev = sc->hdev; |
| @@ -2078,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc) | |||
| 2078 | if (use_ds4_names) | 2012 | if (use_ds4_names) |
| 2079 | name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; | 2013 | name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; |
| 2080 | 2014 | ||
| 2081 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); | 2015 | led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
| 2082 | if (!led) { | 2016 | if (!led) { |
| 2083 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); | 2017 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); |
| 2084 | ret = -ENOMEM; | 2018 | return -ENOMEM; |
| 2085 | goto error_leds; | ||
| 2086 | } | 2019 | } |
| 2087 | 2020 | ||
| 2088 | name = (void *)(&led[1]); | 2021 | name = (void *)(&led[1]); |
| @@ -2103,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc) | |||
| 2103 | 2036 | ||
| 2104 | sc->leds[n] = led; | 2037 | sc->leds[n] = led; |
| 2105 | 2038 | ||
| 2106 | ret = led_classdev_register(&hdev->dev, led); | 2039 | ret = devm_led_classdev_register(&hdev->dev, led); |
| 2107 | if (ret) { | 2040 | if (ret) { |
| 2108 | hid_err(hdev, "Failed to register LED %d\n", n); | 2041 | hid_err(hdev, "Failed to register LED %d\n", n); |
| 2109 | sc->leds[n] = NULL; | 2042 | return ret; |
| 2110 | kfree(led); | ||
| 2111 | goto error_leds; | ||
| 2112 | } | 2043 | } |
| 2113 | } | 2044 | } |
| 2114 | 2045 | ||
| 2115 | return ret; | 2046 | return 0; |
| 2116 | |||
| 2117 | error_leds: | ||
| 2118 | sony_leds_remove(sc); | ||
| 2119 | |||
| 2120 | return ret; | ||
| 2121 | } | 2047 | } |
| 2122 | 2048 | ||
| 2123 | static void sixaxis_send_output_report(struct sony_sc *sc) | 2049 | static void sixaxis_send_output_report(struct sony_sc *sc) |
| @@ -2276,16 +2202,20 @@ static int sony_allocate_output_report(struct sony_sc *sc) | |||
| 2276 | if ((sc->quirks & SIXAXIS_CONTROLLER) || | 2202 | if ((sc->quirks & SIXAXIS_CONTROLLER) || |
| 2277 | (sc->quirks & NAVIGATION_CONTROLLER)) | 2203 | (sc->quirks & NAVIGATION_CONTROLLER)) |
| 2278 | sc->output_report_dmabuf = | 2204 | sc->output_report_dmabuf = |
| 2279 | kmalloc(sizeof(union sixaxis_output_report_01), | 2205 | devm_kmalloc(&sc->hdev->dev, |
| 2206 | sizeof(union sixaxis_output_report_01), | ||
| 2280 | GFP_KERNEL); | 2207 | GFP_KERNEL); |
| 2281 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) | 2208 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) |
| 2282 | sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x11_SIZE, | 2209 | sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, |
| 2210 | DS4_OUTPUT_REPORT_0x11_SIZE, | ||
| 2283 | GFP_KERNEL); | 2211 | GFP_KERNEL); |
| 2284 | else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) | 2212 | else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) |
| 2285 | sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x05_SIZE, | 2213 | sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, |
| 2214 | DS4_OUTPUT_REPORT_0x05_SIZE, | ||
| 2286 | GFP_KERNEL); | 2215 | GFP_KERNEL); |
| 2287 | else if (sc->quirks & MOTION_CONTROLLER) | 2216 | else if (sc->quirks & MOTION_CONTROLLER) |
| 2288 | sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE, | 2217 | sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, |
| 2218 | MOTION_REPORT_0x02_SIZE, | ||
| 2289 | GFP_KERNEL); | 2219 | GFP_KERNEL); |
| 2290 | else | 2220 | else |
| 2291 | return 0; | 2221 | return 0; |
| @@ -2392,36 +2322,21 @@ static int sony_battery_probe(struct sony_sc *sc, int append_dev_id) | |||
| 2392 | sc->battery_desc.get_property = sony_battery_get_property; | 2322 | sc->battery_desc.get_property = sony_battery_get_property; |
| 2393 | sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; | 2323 | sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; |
| 2394 | sc->battery_desc.use_for_apm = 0; | 2324 | sc->battery_desc.use_for_apm = 0; |
| 2395 | sc->battery_desc.name = kasprintf(GFP_KERNEL, battery_str_fmt, | 2325 | sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, |
| 2396 | sc->mac_address, sc->device_id); | 2326 | battery_str_fmt, sc->mac_address, sc->device_id); |
| 2397 | if (!sc->battery_desc.name) | 2327 | if (!sc->battery_desc.name) |
| 2398 | return -ENOMEM; | 2328 | return -ENOMEM; |
| 2399 | 2329 | ||
| 2400 | sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc, | 2330 | sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc, |
| 2401 | &psy_cfg); | 2331 | &psy_cfg); |
| 2402 | if (IS_ERR(sc->battery)) { | 2332 | if (IS_ERR(sc->battery)) { |
| 2403 | ret = PTR_ERR(sc->battery); | 2333 | ret = PTR_ERR(sc->battery); |
| 2404 | hid_err(hdev, "Unable to register battery device\n"); | 2334 | hid_err(hdev, "Unable to register battery device\n"); |
| 2405 | goto err_free; | 2335 | return ret; |
| 2406 | } | 2336 | } |
| 2407 | 2337 | ||
| 2408 | power_supply_powers(sc->battery, &hdev->dev); | 2338 | power_supply_powers(sc->battery, &hdev->dev); |
| 2409 | return 0; | 2339 | return 0; |
| 2410 | |||
| 2411 | err_free: | ||
| 2412 | kfree(sc->battery_desc.name); | ||
| 2413 | sc->battery_desc.name = NULL; | ||
| 2414 | return ret; | ||
| 2415 | } | ||
| 2416 | |||
| 2417 | static void sony_battery_remove(struct sony_sc *sc) | ||
| 2418 | { | ||
| 2419 | if (!sc->battery_desc.name) | ||
| 2420 | return; | ||
| 2421 | |||
| 2422 | power_supply_unregister(sc->battery); | ||
| 2423 | kfree(sc->battery_desc.name); | ||
| 2424 | sc->battery_desc.name = NULL; | ||
| 2425 | } | 2340 | } |
| 2426 | 2341 | ||
| 2427 | /* | 2342 | /* |
| @@ -2879,16 +2794,7 @@ err_stop: | |||
| 2879 | device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); | 2794 | device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); |
| 2880 | if (sc->hw_version) | 2795 | if (sc->hw_version) |
| 2881 | device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); | 2796 | device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); |
| 2882 | if (sc->quirks & SONY_LED_SUPPORT) | ||
| 2883 | sony_leds_remove(sc); | ||
| 2884 | if (sc->quirks & SONY_BATTERY_SUPPORT) | ||
| 2885 | sony_battery_remove(sc); | ||
| 2886 | if (sc->touchpad) | ||
| 2887 | sony_unregister_touchpad(sc); | ||
| 2888 | if (sc->sensor_dev) | ||
| 2889 | sony_unregister_sensors(sc); | ||
| 2890 | sony_cancel_work_sync(sc); | 2797 | sony_cancel_work_sync(sc); |
| 2891 | kfree(sc->output_report_dmabuf); | ||
| 2892 | sony_remove_dev_list(sc); | 2798 | sony_remove_dev_list(sc); |
| 2893 | sony_release_device_id(sc); | 2799 | sony_release_device_id(sc); |
| 2894 | hid_hw_stop(hdev); | 2800 | hid_hw_stop(hdev); |
| @@ -2965,18 +2871,6 @@ static void sony_remove(struct hid_device *hdev) | |||
| 2965 | 2871 | ||
| 2966 | hid_hw_close(hdev); | 2872 | hid_hw_close(hdev); |
| 2967 | 2873 | ||
| 2968 | if (sc->quirks & SONY_LED_SUPPORT) | ||
| 2969 | sony_leds_remove(sc); | ||
| 2970 | |||
| 2971 | if (sc->quirks & SONY_BATTERY_SUPPORT) | ||
| 2972 | sony_battery_remove(sc); | ||
| 2973 | |||
| 2974 | if (sc->touchpad) | ||
| 2975 | sony_unregister_touchpad(sc); | ||
| 2976 | |||
| 2977 | if (sc->sensor_dev) | ||
| 2978 | sony_unregister_sensors(sc); | ||
| 2979 | |||
| 2980 | if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) | 2874 | if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) |
| 2981 | device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); | 2875 | device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); |
| 2982 | 2876 | ||
| @@ -2988,8 +2882,6 @@ static void sony_remove(struct hid_device *hdev) | |||
| 2988 | 2882 | ||
| 2989 | sony_cancel_work_sync(sc); | 2883 | sony_cancel_work_sync(sc); |
| 2990 | 2884 | ||
| 2991 | kfree(sc->output_report_dmabuf); | ||
| 2992 | |||
| 2993 | sony_remove_dev_list(sc); | 2885 | sony_remove_dev_list(sc); |
| 2994 | 2886 | ||
| 2995 | sony_release_device_id(sc); | 2887 | sony_release_device_id(sc); |
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c index 579884ebd94d..7780da4fe897 100644 --- a/drivers/hid/hid-wiimote-core.c +++ b/drivers/hid/hid-wiimote-core.c | |||
| @@ -455,6 +455,12 @@ static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem) | |||
| 455 | return WIIMOTE_EXT_BALANCE_BOARD; | 455 | return WIIMOTE_EXT_BALANCE_BOARD; |
| 456 | if (rmem[4] == 0x01 && rmem[5] == 0x20) | 456 | if (rmem[4] == 0x01 && rmem[5] == 0x20) |
| 457 | return WIIMOTE_EXT_PRO_CONTROLLER; | 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 | return WIIMOTE_EXT_UNKNOWN; | 465 | return WIIMOTE_EXT_UNKNOWN; |
| 460 | } | 466 | } |
| @@ -488,6 +494,8 @@ static bool wiimote_cmd_map_mp(struct wiimote_data *wdata, __u8 exttype) | |||
| 488 | /* map MP with correct pass-through mode */ | 494 | /* map MP with correct pass-through mode */ |
| 489 | switch (exttype) { | 495 | switch (exttype) { |
| 490 | case WIIMOTE_EXT_CLASSIC_CONTROLLER: | 496 | case WIIMOTE_EXT_CLASSIC_CONTROLLER: |
| 497 | case WIIMOTE_EXT_DRUMS: | ||
| 498 | case WIIMOTE_EXT_GUITAR: | ||
| 491 | wmem = 0x07; | 499 | wmem = 0x07; |
| 492 | break; | 500 | break; |
| 493 | case WIIMOTE_EXT_NUNCHUK: | 501 | case WIIMOTE_EXT_NUNCHUK: |
| @@ -1075,6 +1083,8 @@ static const char *wiimote_exttype_names[WIIMOTE_EXT_NUM] = { | |||
| 1075 | [WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller", | 1083 | [WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller", |
| 1076 | [WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board", | 1084 | [WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board", |
| 1077 | [WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller", | 1085 | [WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller", |
| 1086 | [WIIMOTE_EXT_DRUMS] = "Nintendo Wii Drums", | ||
| 1087 | [WIIMOTE_EXT_GUITAR] = "Nintendo Wii Guitar", | ||
| 1078 | }; | 1088 | }; |
| 1079 | 1089 | ||
| 1080 | /* | 1090 | /* |
| @@ -1660,6 +1670,10 @@ static ssize_t wiimote_ext_show(struct device *dev, | |||
| 1660 | return sprintf(buf, "balanceboard\n"); | 1670 | return sprintf(buf, "balanceboard\n"); |
| 1661 | case WIIMOTE_EXT_PRO_CONTROLLER: | 1671 | case WIIMOTE_EXT_PRO_CONTROLLER: |
| 1662 | return sprintf(buf, "procontroller\n"); | 1672 | return sprintf(buf, "procontroller\n"); |
| 1673 | case WIIMOTE_EXT_DRUMS: | ||
| 1674 | return sprintf(buf, "drums\n"); | ||
| 1675 | case WIIMOTE_EXT_GUITAR: | ||
| 1676 | return sprintf(buf, "guitar\n"); | ||
| 1663 | case WIIMOTE_EXT_UNKNOWN: | 1677 | case WIIMOTE_EXT_UNKNOWN: |
| 1664 | /* fallthrough */ | 1678 | /* fallthrough */ |
| 1665 | default: | 1679 | default: |
diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index c830ed39348f..aa72eb9a8e2f 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c | |||
| @@ -1950,6 +1950,444 @@ static const struct wiimod_ops wiimod_pro = { | |||
| 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 | * Builtin Motion Plus | 2391 | * Builtin Motion Plus |
| 1954 | * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which | 2392 | * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which |
| 1955 | * disables polling for Motion-Plus. This should be set only for devices which | 2393 | * disables polling for Motion-Plus. This should be set only for devices which |
| @@ -2201,4 +2639,6 @@ const struct wiimod_ops *wiimod_ext_table[WIIMOTE_EXT_NUM] = { | |||
| 2201 | [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic, | 2639 | [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic, |
| 2202 | [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard, | 2640 | [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard, |
| 2203 | [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro, | 2641 | [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro, |
| 2642 | [WIIMOTE_EXT_DRUMS] = &wiimod_drums, | ||
| 2643 | [WIIMOTE_EXT_GUITAR] = &wiimod_guitar, | ||
| 2204 | }; | 2644 | }; |
diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h index 510ca77fe14e..3bf3d3cc1c38 100644 --- a/drivers/hid/hid-wiimote.h +++ b/drivers/hid/hid-wiimote.h | |||
| @@ -89,6 +89,8 @@ enum wiimote_exttype { | |||
| 89 | WIIMOTE_EXT_CLASSIC_CONTROLLER, | 89 | WIIMOTE_EXT_CLASSIC_CONTROLLER, |
| 90 | WIIMOTE_EXT_BALANCE_BOARD, | 90 | WIIMOTE_EXT_BALANCE_BOARD, |
| 91 | WIIMOTE_EXT_PRO_CONTROLLER, | 91 | WIIMOTE_EXT_PRO_CONTROLLER, |
| 92 | WIIMOTE_EXT_DRUMS, | ||
| 93 | WIIMOTE_EXT_GUITAR, | ||
| 92 | WIIMOTE_EXT_NUM, | 94 | WIIMOTE_EXT_NUM, |
| 93 | }; | 95 | }; |
| 94 | 96 | ||
| @@ -137,6 +139,7 @@ struct wiimote_state { | |||
| 137 | /* calibration/cache data */ | 139 | /* calibration/cache data */ |
| 138 | __u16 calib_bboard[4][3]; | 140 | __u16 calib_bboard[4][3]; |
| 139 | __s16 calib_pro_sticks[4]; | 141 | __s16 calib_pro_sticks[4]; |
| 142 | __u8 pressure_drums[7]; | ||
| 140 | __u8 cache_rumble; | 143 | __u8 cache_rumble; |
| 141 | }; | 144 | }; |
| 142 | 145 | ||
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index eae0cb3ddec6..2ce194a84868 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c | |||
| @@ -1002,18 +1002,18 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
| 1002 | return client->irq; | 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 | if (!ihid) | 1006 | if (!ihid) |
| 1007 | return -ENOMEM; | 1007 | return -ENOMEM; |
| 1008 | 1008 | ||
| 1009 | if (client->dev.of_node) { | 1009 | if (client->dev.of_node) { |
| 1010 | ret = i2c_hid_of_probe(client, &ihid->pdata); | 1010 | ret = i2c_hid_of_probe(client, &ihid->pdata); |
| 1011 | if (ret) | 1011 | if (ret) |
| 1012 | goto err; | 1012 | return ret; |
| 1013 | } else if (!platform_data) { | 1013 | } else if (!platform_data) { |
| 1014 | ret = i2c_hid_acpi_pdata(client, &ihid->pdata); | 1014 | ret = i2c_hid_acpi_pdata(client, &ihid->pdata); |
| 1015 | if (ret) | 1015 | if (ret) |
| 1016 | goto err; | 1016 | return ret; |
| 1017 | } else { | 1017 | } else { |
| 1018 | ihid->pdata = *platform_data; | 1018 | ihid->pdata = *platform_data; |
| 1019 | } | 1019 | } |
| @@ -1021,21 +1021,20 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
| 1021 | /* Parse platform agnostic common properties from ACPI / device tree */ | 1021 | /* Parse platform agnostic common properties from ACPI / device tree */ |
| 1022 | i2c_hid_fwnode_probe(client, &ihid->pdata); | 1022 | i2c_hid_fwnode_probe(client, &ihid->pdata); |
| 1023 | 1023 | ||
| 1024 | ihid->pdata.supply = devm_regulator_get(&client->dev, "vdd"); | 1024 | ihid->pdata.supplies[0].supply = "vdd"; |
| 1025 | if (IS_ERR(ihid->pdata.supply)) { | 1025 | ihid->pdata.supplies[1].supply = "vddl"; |
| 1026 | ret = PTR_ERR(ihid->pdata.supply); | 1026 | |
| 1027 | if (ret != -EPROBE_DEFER) | 1027 | ret = devm_regulator_bulk_get(&client->dev, |
| 1028 | dev_err(&client->dev, "Failed to get regulator: %d\n", | 1028 | ARRAY_SIZE(ihid->pdata.supplies), |
| 1029 | ret); | 1029 | ihid->pdata.supplies); |
| 1030 | goto err; | 1030 | if (ret) |
| 1031 | } | 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; | ||
| 1032 | 1037 | ||
| 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 | } | ||
| 1039 | if (ihid->pdata.post_power_delay_ms) | 1038 | if (ihid->pdata.post_power_delay_ms) |
| 1040 | msleep(ihid->pdata.post_power_delay_ms); | 1039 | msleep(ihid->pdata.post_power_delay_ms); |
| 1041 | 1040 | ||
| @@ -1122,11 +1121,9 @@ err_pm: | |||
| 1122 | pm_runtime_disable(&client->dev); | 1121 | pm_runtime_disable(&client->dev); |
| 1123 | 1122 | ||
| 1124 | err_regulator: | 1123 | err_regulator: |
| 1125 | regulator_disable(ihid->pdata.supply); | 1124 | regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), |
| 1126 | 1125 | ihid->pdata.supplies); | |
| 1127 | err: | ||
| 1128 | i2c_hid_free_buffers(ihid); | 1126 | i2c_hid_free_buffers(ihid); |
| 1129 | kfree(ihid); | ||
| 1130 | return ret; | 1127 | return ret; |
| 1131 | } | 1128 | } |
| 1132 | 1129 | ||
| @@ -1148,9 +1145,8 @@ static int i2c_hid_remove(struct i2c_client *client) | |||
| 1148 | if (ihid->bufsize) | 1145 | if (ihid->bufsize) |
| 1149 | i2c_hid_free_buffers(ihid); | 1146 | i2c_hid_free_buffers(ihid); |
| 1150 | 1147 | ||
| 1151 | regulator_disable(ihid->pdata.supply); | 1148 | regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), |
| 1152 | 1149 | ihid->pdata.supplies); | |
| 1153 | kfree(ihid); | ||
| 1154 | 1150 | ||
| 1155 | return 0; | 1151 | return 0; |
| 1156 | } | 1152 | } |
| @@ -1201,9 +1197,8 @@ static int i2c_hid_suspend(struct device *dev) | |||
| 1201 | hid_warn(hid, "Failed to enable irq wake: %d\n", | 1197 | hid_warn(hid, "Failed to enable irq wake: %d\n", |
| 1202 | wake_status); | 1198 | wake_status); |
| 1203 | } else { | 1199 | } else { |
| 1204 | ret = regulator_disable(ihid->pdata.supply); | 1200 | regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), |
| 1205 | if (ret < 0) | 1201 | ihid->pdata.supplies); |
| 1206 | hid_warn(hid, "Failed to disable supply: %d\n", ret); | ||
| 1207 | } | 1202 | } |
| 1208 | 1203 | ||
| 1209 | return 0; | 1204 | return 0; |
| @@ -1218,9 +1213,11 @@ static int i2c_hid_resume(struct device *dev) | |||
| 1218 | int wake_status; | 1213 | int wake_status; |
| 1219 | 1214 | ||
| 1220 | if (!device_may_wakeup(&client->dev)) { | 1215 | if (!device_may_wakeup(&client->dev)) { |
| 1221 | ret = regulator_enable(ihid->pdata.supply); | 1216 | ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies), |
| 1222 | if (ret < 0) | 1217 | ihid->pdata.supplies); |
| 1223 | hid_warn(hid, "Failed to enable supply: %d\n", ret); | 1218 | if (ret) |
| 1219 | hid_warn(hid, "Failed to enable supplies: %d\n", ret); | ||
| 1220 | |||
| 1224 | if (ihid->pdata.post_power_delay_ms) | 1221 | if (ihid->pdata.post_power_delay_ms) |
| 1225 | msleep(ihid->pdata.post_power_delay_ms); | 1222 | msleep(ihid->pdata.post_power_delay_ms); |
| 1226 | } else if (ihid->irq_wake_enabled) { | 1223 | } else if (ihid->irq_wake_enabled) { |
diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c index 9a60ec13cb10..bfbca7ec54ce 100644 --- a/drivers/hid/intel-ish-hid/ipc/ipc.c +++ b/drivers/hid/intel-ish-hid/ipc/ipc.c | |||
| @@ -907,8 +907,9 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) | |||
| 907 | struct ishtp_device *dev; | 907 | struct ishtp_device *dev; |
| 908 | int i; | 908 | int i; |
| 909 | 909 | ||
| 910 | dev = kzalloc(sizeof(struct ishtp_device) + sizeof(struct ish_hw), | 910 | dev = devm_kzalloc(&pdev->dev, |
| 911 | GFP_KERNEL); | 911 | sizeof(struct ishtp_device) + sizeof(struct ish_hw), |
| 912 | GFP_KERNEL); | ||
| 912 | if (!dev) | 913 | if (!dev) |
| 913 | return NULL; | 914 | return NULL; |
| 914 | 915 | ||
| @@ -925,7 +926,9 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) | |||
| 925 | for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) { | 926 | for (i = 0; i < IPC_TX_FIFO_SIZE; ++i) { |
| 926 | struct wr_msg_ctl_info *tx_buf; | 927 | struct wr_msg_ctl_info *tx_buf; |
| 927 | 928 | ||
| 928 | tx_buf = kzalloc(sizeof(struct wr_msg_ctl_info), GFP_KERNEL); | 929 | tx_buf = devm_kzalloc(&pdev->dev, |
| 930 | sizeof(struct wr_msg_ctl_info), | ||
| 931 | GFP_KERNEL); | ||
| 929 | if (!tx_buf) { | 932 | if (!tx_buf) { |
| 930 | /* | 933 | /* |
| 931 | * IPC buffers may be limited or not available | 934 | * IPC buffers may be limited or not available |
diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c index a2c53ea3b5ed..050f9872f5c0 100644 --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c | |||
| @@ -95,6 +95,13 @@ static int ish_init(struct ishtp_device *dev) | |||
| 95 | return 0; | 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 | * ish_probe() - PCI driver probe callback | 106 | * ish_probe() - PCI driver probe callback |
| 100 | * @pdev: pci device | 107 | * @pdev: pci device |
| @@ -110,6 +117,10 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
| 110 | struct ish_hw *hw; | 117 | struct ish_hw *hw; |
| 111 | int ret; | 118 | int ret; |
| 112 | 119 | ||
| 120 | /* Check for invalid platforms for ISH support */ | ||
| 121 | if (pci_dev_present(ish_invalid_pci_ids)) | ||
| 122 | return -ENODEV; | ||
| 123 | |||
| 113 | /* enable pci dev */ | 124 | /* enable pci dev */ |
| 114 | ret = pci_enable_device(pdev); | 125 | ret = pci_enable_device(pdev); |
| 115 | if (ret) { | 126 | if (ret) { |
| @@ -172,7 +183,6 @@ free_irq: | |||
| 172 | free_irq(pdev->irq, dev); | 183 | free_irq(pdev->irq, dev); |
| 173 | free_device: | 184 | free_device: |
| 174 | pci_iounmap(pdev, hw->mem_addr); | 185 | pci_iounmap(pdev, hw->mem_addr); |
| 175 | kfree(dev); | ||
| 176 | release_regions: | 186 | release_regions: |
| 177 | pci_release_regions(pdev); | 187 | pci_release_regions(pdev); |
| 178 | disable_device: | 188 | disable_device: |
| @@ -202,7 +212,6 @@ static void ish_remove(struct pci_dev *pdev) | |||
| 202 | pci_release_regions(pdev); | 212 | pci_release_regions(pdev); |
| 203 | pci_clear_master(pdev); | 213 | pci_clear_master(pdev); |
| 204 | pci_disable_device(pdev); | 214 | pci_disable_device(pdev); |
| 205 | kfree(ishtp_dev); | ||
| 206 | } | 215 | } |
| 207 | 216 | ||
| 208 | static struct device __maybe_unused *ish_resume_device; | 217 | static struct device __maybe_unused *ish_resume_device; |
diff --git a/drivers/hid/intel-ish-hid/ishtp/hbm.c b/drivers/hid/intel-ish-hid/ishtp/hbm.c index ae4a69f7f2f4..8b5dd580ceec 100644 --- a/drivers/hid/intel-ish-hid/ishtp/hbm.c +++ b/drivers/hid/intel-ish-hid/ishtp/hbm.c | |||
| @@ -298,7 +298,6 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, | |||
| 298 | struct ishtp_msg_hdr *ishtp_hdr = &hdr; | 298 | struct ishtp_msg_hdr *ishtp_hdr = &hdr; |
| 299 | const size_t len = sizeof(struct hbm_flow_control); | 299 | const size_t len = sizeof(struct hbm_flow_control); |
| 300 | int rv; | 300 | int rv; |
| 301 | unsigned int num_frags; | ||
| 302 | unsigned long flags; | 301 | unsigned long flags; |
| 303 | 302 | ||
| 304 | spin_lock_irqsave(&cl->fc_spinlock, flags); | 303 | spin_lock_irqsave(&cl->fc_spinlock, flags); |
| @@ -314,7 +313,6 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, | |||
| 314 | return 0; | 313 | return 0; |
| 315 | } | 314 | } |
| 316 | 315 | ||
| 317 | num_frags = cl->recv_msg_num_frags; | ||
| 318 | cl->recv_msg_num_frags = 0; | 316 | cl->recv_msg_num_frags = 0; |
| 319 | 317 | ||
| 320 | rv = ishtp_write_message(dev, ishtp_hdr, data); | 318 | rv = ishtp_write_message(dev, ishtp_hdr, data); |
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index af0e0d061b15..11103efebbaa 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c | |||
| @@ -480,6 +480,7 @@ static void hid_ctrl(struct urb *urb) | |||
| 480 | { | 480 | { |
| 481 | struct hid_device *hid = urb->context; | 481 | struct hid_device *hid = urb->context; |
| 482 | struct usbhid_device *usbhid = hid->driver_data; | 482 | struct usbhid_device *usbhid = hid->driver_data; |
| 483 | unsigned long flags; | ||
| 483 | int unplug = 0, status = urb->status; | 484 | int unplug = 0, status = urb->status; |
| 484 | 485 | ||
| 485 | switch (status) { | 486 | switch (status) { |
| @@ -501,7 +502,7 @@ static void hid_ctrl(struct urb *urb) | |||
| 501 | hid_warn(urb->dev, "ctrl urb status %d received\n", status); | 502 | hid_warn(urb->dev, "ctrl urb status %d received\n", status); |
| 502 | } | 503 | } |
| 503 | 504 | ||
| 504 | spin_lock(&usbhid->lock); | 505 | spin_lock_irqsave(&usbhid->lock, flags); |
| 505 | 506 | ||
| 506 | if (unplug) { | 507 | if (unplug) { |
| 507 | usbhid->ctrltail = usbhid->ctrlhead; | 508 | usbhid->ctrltail = usbhid->ctrlhead; |
| @@ -511,13 +512,13 @@ static void hid_ctrl(struct urb *urb) | |||
| 511 | if (usbhid->ctrlhead != usbhid->ctrltail && | 512 | if (usbhid->ctrlhead != usbhid->ctrltail && |
| 512 | hid_submit_ctrl(hid) == 0) { | 513 | hid_submit_ctrl(hid) == 0) { |
| 513 | /* Successfully submitted next urb in queue */ | 514 | /* Successfully submitted next urb in queue */ |
| 514 | spin_unlock(&usbhid->lock); | 515 | spin_unlock_irqrestore(&usbhid->lock, flags); |
| 515 | return; | 516 | return; |
| 516 | } | 517 | } |
| 517 | } | 518 | } |
| 518 | 519 | ||
| 519 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); | 520 | clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); |
| 520 | spin_unlock(&usbhid->lock); | 521 | spin_unlock_irqrestore(&usbhid->lock, flags); |
| 521 | usb_autopm_put_interface_async(usbhid->intf); | 522 | usb_autopm_put_interface_async(usbhid->intf); |
| 522 | wake_up(&usbhid->wait); | 523 | wake_up(&usbhid->wait); |
| 523 | } | 524 | } |
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index d6797535fff9..0bdd85d486fe 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c | |||
| @@ -210,6 +210,57 @@ static int wacom_calc_hid_res(int logical_extents, int physical_extents, | |||
| 210 | return hidinput_calc_abs_res(&field, ABS_X); | 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 | static void wacom_feature_mapping(struct hid_device *hdev, | 264 | static void wacom_feature_mapping(struct hid_device *hdev, |
| 214 | struct hid_field *field, struct hid_usage *usage) | 265 | struct hid_field *field, struct hid_usage *usage) |
| 215 | { | 266 | { |
| @@ -221,6 +272,8 @@ static void wacom_feature_mapping(struct hid_device *hdev, | |||
| 221 | int ret; | 272 | int ret; |
| 222 | u32 n; | 273 | u32 n; |
| 223 | 274 | ||
| 275 | wacom_hid_usage_quirk(hdev, field, usage); | ||
| 276 | |||
| 224 | switch (equivalent_usage) { | 277 | switch (equivalent_usage) { |
| 225 | case HID_DG_CONTACTMAX: | 278 | case HID_DG_CONTACTMAX: |
| 226 | /* leave touch_max as is if predefined */ | 279 | /* leave touch_max as is if predefined */ |
| @@ -300,13 +353,6 @@ static void wacom_feature_mapping(struct hid_device *hdev, | |||
| 300 | kfree(data); | 353 | kfree(data); |
| 301 | break; | 354 | break; |
| 302 | } | 355 | } |
| 303 | |||
| 304 | if (hdev->vendor == USB_VENDOR_ID_WACOM && | ||
| 305 | hdev->product == 0x4200 /* Dell Canvas 27 */ && | ||
| 306 | field->application == HID_UP_MSVENDOR) { | ||
| 307 | wacom->wacom_wac.mode_report = field->report->id; | ||
| 308 | wacom->wacom_wac.mode_value = 2; | ||
| 309 | } | ||
| 310 | } | 356 | } |
| 311 | 357 | ||
| 312 | /* | 358 | /* |
| @@ -348,6 +394,7 @@ static void wacom_usage_mapping(struct hid_device *hdev, | |||
| 348 | struct wacom_features *features = &wacom->wacom_wac.features; | 394 | struct wacom_features *features = &wacom->wacom_wac.features; |
| 349 | bool finger = WACOM_FINGER_FIELD(field); | 395 | bool finger = WACOM_FINGER_FIELD(field); |
| 350 | bool pen = WACOM_PEN_FIELD(field); | 396 | bool pen = WACOM_PEN_FIELD(field); |
| 397 | unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); | ||
| 351 | 398 | ||
| 352 | /* | 399 | /* |
| 353 | * Requiring Stylus Usage will ignore boot mouse | 400 | * Requiring Stylus Usage will ignore boot mouse |
| @@ -361,49 +408,9 @@ static void wacom_usage_mapping(struct hid_device *hdev, | |||
| 361 | else | 408 | else |
| 362 | return; | 409 | return; |
| 363 | 410 | ||
| 364 | /* | 411 | wacom_hid_usage_quirk(hdev, field, usage); |
| 365 | * Bamboo models do not support HID_DG_CONTACTMAX. | ||
| 366 | * And, Bamboo Pen only descriptor contains touch. | ||
| 367 | */ | ||
| 368 | if (features->type > BAMBOO_PT) { | ||
| 369 | /* ISDv4 touch devices at least supports one touch point */ | ||
| 370 | if (finger && !features->touch_max) | ||
| 371 | features->touch_max = 1; | ||
| 372 | } | ||
| 373 | |||
| 374 | /* | ||
| 375 | * ISDv4 devices which predate HID's adoption of the | ||
| 376 | * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its | ||
| 377 | * position instead. We can accurately detect if a | ||
| 378 | * usage with that value should be HID_DG_BARRELSWITCH2 | ||
| 379 | * based on the surrounding usages, which have remained | ||
| 380 | * constant across generations. | ||
| 381 | */ | ||
| 382 | if (features->type == HID_GENERIC && | ||
| 383 | usage->hid == 0x000D0000 && | ||
| 384 | field->application == HID_DG_PEN && | ||
| 385 | field->physical == HID_DG_STYLUS) { | ||
| 386 | int i = usage->usage_index; | ||
| 387 | 412 | ||
| 388 | if (i-4 >= 0 && i+1 < field->maxusage && | 413 | switch (equivalent_usage) { |
| 389 | field->usage[i-4].hid == HID_DG_TIPSWITCH && | ||
| 390 | field->usage[i-3].hid == HID_DG_BARRELSWITCH && | ||
| 391 | field->usage[i-2].hid == HID_DG_ERASER && | ||
| 392 | field->usage[i-1].hid == HID_DG_INVERT && | ||
| 393 | field->usage[i+1].hid == HID_DG_INRANGE) { | ||
| 394 | usage->hid = HID_DG_BARRELSWITCH2; | ||
| 395 | } | ||
| 396 | } | ||
| 397 | |||
| 398 | /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ | ||
| 399 | if (hdev->vendor == USB_VENDOR_ID_WACOM && | ||
| 400 | hdev->product == 0x0358 && | ||
| 401 | WACOM_PEN_FIELD(field) && | ||
| 402 | wacom_equivalent_usage(usage->hid) == HID_GD_Y) { | ||
| 403 | field->logical_maximum = 43200; | ||
| 404 | } | ||
| 405 | |||
| 406 | switch (usage->hid) { | ||
| 407 | case HID_GD_X: | 414 | case HID_GD_X: |
| 408 | features->x_max = field->logical_maximum; | 415 | features->x_max = field->logical_maximum; |
| 409 | if (finger) { | 416 | if (finger) { |
| @@ -703,18 +710,6 @@ struct wacom_hdev_data { | |||
| 703 | static LIST_HEAD(wacom_udev_list); | 710 | static LIST_HEAD(wacom_udev_list); |
| 704 | static DEFINE_MUTEX(wacom_udev_list_lock); | 711 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 705 | 712 | ||
| 706 | static bool compare_device_paths(struct hid_device *hdev_a, | ||
| 707 | struct hid_device *hdev_b, char separator) | ||
| 708 | { | ||
| 709 | int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys; | ||
| 710 | int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys; | ||
| 711 | |||
| 712 | if (n1 != n2 || n1 <= 0 || n2 <= 0) | ||
| 713 | return false; | ||
| 714 | |||
| 715 | return !strncmp(hdev_a->phys, hdev_b->phys, n1); | ||
| 716 | } | ||
| 717 | |||
| 718 | static bool wacom_are_sibling(struct hid_device *hdev, | 713 | static bool wacom_are_sibling(struct hid_device *hdev, |
| 719 | struct hid_device *sibling) | 714 | struct hid_device *sibling) |
| 720 | { | 715 | { |
| @@ -737,10 +732,10 @@ static bool wacom_are_sibling(struct hid_device *hdev, | |||
| 737 | * the same physical parent device path. | 732 | * the same physical parent device path. |
| 738 | */ | 733 | */ |
| 739 | if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) { | 734 | if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) { |
| 740 | if (!compare_device_paths(hdev, sibling, '/')) | 735 | if (!hid_compare_device_paths(hdev, sibling, '/')) |
| 741 | return false; | 736 | return false; |
| 742 | } else { | 737 | } else { |
| 743 | if (!compare_device_paths(hdev, sibling, '.')) | 738 | if (!hid_compare_device_paths(hdev, sibling, '.')) |
| 744 | return false; | 739 | return false; |
| 745 | } | 740 | } |
| 746 | 741 | ||
| @@ -787,7 +782,7 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev) | |||
| 787 | 782 | ||
| 788 | /* Try to find an already-probed interface from the same device */ | 783 | /* Try to find an already-probed interface from the same device */ |
| 789 | list_for_each_entry(data, &wacom_udev_list, list) { | 784 | list_for_each_entry(data, &wacom_udev_list, list) { |
| 790 | if (compare_device_paths(hdev, data->dev, '/')) { | 785 | if (hid_compare_device_paths(hdev, data->dev, '/')) { |
| 791 | kref_get(&data->kref); | 786 | kref_get(&data->kref); |
| 792 | return data; | 787 | return data; |
| 793 | } | 788 | } |
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index ad7afa74d365..e0a06be5ef5c 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c | |||
| @@ -4357,19 +4357,19 @@ static const struct wacom_features wacom_features_0x5E = | |||
| 4357 | .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE }; | 4357 | .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE }; |
| 4358 | static const struct wacom_features wacom_features_0x90 = | 4358 | static const struct wacom_features wacom_features_0x90 = |
| 4359 | { "Wacom ISDv4 90", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0x93 = | 4361 | static const struct wacom_features wacom_features_0x93 = |
| 4362 | { "Wacom ISDv4 93", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0x97 = | 4364 | static const struct wacom_features wacom_features_0x97 = |
| 4365 | { "Wacom ISDv4 97", 26202, 16325, 511, 0, | 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 | static const struct wacom_features wacom_features_0x9A = | 4367 | static const struct wacom_features wacom_features_0x9A = |
| 4368 | { "Wacom ISDv4 9A", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0x9F = | 4370 | static const struct wacom_features wacom_features_0x9F = |
| 4371 | { "Wacom ISDv4 9F", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0xE2 = | 4373 | static const struct wacom_features wacom_features_0xE2 = |
| 4374 | { "Wacom ISDv4 E2", 26202, 16325, 255, 0, | 4374 | { "Wacom ISDv4 E2", 26202, 16325, 255, 0, |
| 4375 | TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 }; | 4375 | TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 }; |
| @@ -4384,13 +4384,13 @@ static const struct wacom_features wacom_features_0xE6 = | |||
| 4384 | TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 }; | 4384 | TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 }; |
| 4385 | static const struct wacom_features wacom_features_0xEC = | 4385 | static const struct wacom_features wacom_features_0xEC = |
| 4386 | { "Wacom ISDv4 EC", 25710, 14500, 255, 0, | 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 | static const struct wacom_features wacom_features_0xED = | 4388 | static const struct wacom_features wacom_features_0xED = |
| 4389 | { "Wacom ISDv4 ED", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0xEF = | 4391 | static const struct wacom_features wacom_features_0xEF = |
| 4392 | { "Wacom ISDv4 EF", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0x100 = | 4394 | static const struct wacom_features wacom_features_0x100 = |
| 4395 | { "Wacom ISDv4 100", 26202, 16325, 255, 0, | 4395 | { "Wacom ISDv4 100", 26202, 16325, 255, 0, |
| 4396 | MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; | 4396 | MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; |
| @@ -4408,10 +4408,10 @@ static const struct wacom_features wacom_features_0x10F = | |||
| 4408 | MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; | 4408 | MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; |
| 4409 | static const struct wacom_features wacom_features_0x116 = | 4409 | static const struct wacom_features wacom_features_0x116 = |
| 4410 | { "Wacom ISDv4 116", 26202, 16325, 255, 0, | 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 | static const struct wacom_features wacom_features_0x12C = | 4412 | static const struct wacom_features wacom_features_0x12C = |
| 4413 | { "Wacom ISDv4 12C", 27848, 15752, 2047, 0, | 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 | static const struct wacom_features wacom_features_0x4001 = | 4415 | static const struct wacom_features wacom_features_0x4001 = |
| 4416 | { "Wacom ISDv4 4001", 26202, 16325, 255, 0, | 4416 | { "Wacom ISDv4 4001", 26202, 16325, 255, 0, |
| 4417 | MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; | 4417 | MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; |
diff --git a/include/linux/hid.h b/include/linux/hid.h index 773bcb1d4044..834e6461a690 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
| @@ -190,6 +190,12 @@ struct hid_item { | |||
| 190 | * http://www.usb.org/developers/hidpage/HUTRR40RadioHIDUsagesFinal.pdf | 190 | * http://www.usb.org/developers/hidpage/HUTRR40RadioHIDUsagesFinal.pdf |
| 191 | */ | 191 | */ |
| 192 | #define HID_GD_WIRELESS_RADIO_CTLS 0x0001000c | 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 | #define HID_GD_X 0x00010030 | 199 | #define HID_GD_X 0x00010030 |
| 194 | #define HID_GD_Y 0x00010031 | 200 | #define HID_GD_Y 0x00010031 |
| 195 | #define HID_GD_Z 0x00010032 | 201 | #define HID_GD_Z 0x00010032 |
| @@ -638,12 +644,13 @@ static inline void hid_set_drvdata(struct hid_device *hdev, void *data) | |||
| 638 | struct hid_parser { | 644 | struct hid_parser { |
| 639 | struct hid_global global; | 645 | struct hid_global global; |
| 640 | struct hid_global global_stack[HID_GLOBAL_STACK_SIZE]; | 646 | struct hid_global global_stack[HID_GLOBAL_STACK_SIZE]; |
| 641 | unsigned global_stack_ptr; | 647 | unsigned int global_stack_ptr; |
| 642 | struct hid_local local; | 648 | struct hid_local local; |
| 643 | unsigned collection_stack[HID_COLLECTION_STACK_SIZE]; | 649 | unsigned int *collection_stack; |
| 644 | unsigned collection_stack_ptr; | 650 | unsigned int collection_stack_ptr; |
| 651 | unsigned int collection_stack_size; | ||
| 645 | struct hid_device *device; | 652 | struct hid_device *device; |
| 646 | unsigned scan_flags; | 653 | unsigned int scan_flags; |
| 647 | }; | 654 | }; |
| 648 | 655 | ||
| 649 | struct hid_class_descriptor { | 656 | struct hid_class_descriptor { |
| @@ -894,6 +901,8 @@ const struct hid_device_id *hid_match_id(const struct hid_device *hdev, | |||
| 894 | const struct hid_device_id *id); | 901 | const struct hid_device_id *id); |
| 895 | const struct hid_device_id *hid_match_device(struct hid_device *hdev, | 902 | const struct hid_device_id *hid_match_device(struct hid_device *hdev, |
| 896 | struct hid_driver *hdrv); | 903 | struct hid_driver *hdrv); |
| 904 | bool hid_compare_device_paths(struct hid_device *hdev_a, | ||
| 905 | struct hid_device *hdev_b, char separator); | ||
| 897 | s32 hid_snto32(__u32 value, unsigned n); | 906 | s32 hid_snto32(__u32 value, unsigned n); |
| 898 | __u32 hid_field_extract(const struct hid_device *hid, __u8 *report, | 907 | __u32 hid_field_extract(const struct hid_device *hid, __u8 *report, |
| 899 | unsigned offset, unsigned n); | 908 | unsigned offset, unsigned n); |
diff --git a/include/linux/platform_data/i2c-hid.h b/include/linux/platform_data/i2c-hid.h index 1fb088239d12..c628bb5e1061 100644 --- a/include/linux/platform_data/i2c-hid.h +++ b/include/linux/platform_data/i2c-hid.h | |||
| @@ -12,14 +12,13 @@ | |||
| 12 | #ifndef __LINUX_I2C_HID_H | 12 | #ifndef __LINUX_I2C_HID_H |
| 13 | #define __LINUX_I2C_HID_H | 13 | #define __LINUX_I2C_HID_H |
| 14 | 14 | ||
| 15 | #include <linux/regulator/consumer.h> | ||
| 15 | #include <linux/types.h> | 16 | #include <linux/types.h> |
| 16 | 17 | ||
| 17 | struct regulator; | ||
| 18 | |||
| 19 | /** | 18 | /** |
| 20 | * struct i2chid_platform_data - used by hid over i2c implementation. | 19 | * struct i2chid_platform_data - used by hid over i2c implementation. |
| 21 | * @hid_descriptor_address: i2c register where the HID descriptor is stored. | 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 | * @post_power_delay_ms: delay after powering on before device is usable. | 22 | * @post_power_delay_ms: delay after powering on before device is usable. |
| 24 | * | 23 | * |
| 25 | * Note that it is the responsibility of the platform driver (or the acpi 5.0 | 24 | * Note that it is the responsibility of the platform driver (or the acpi 5.0 |
| @@ -35,7 +34,7 @@ struct regulator; | |||
| 35 | */ | 34 | */ |
| 36 | struct i2c_hid_platform_data { | 35 | struct i2c_hid_platform_data { |
| 37 | u16 hid_descriptor_address; | 36 | u16 hid_descriptor_address; |
| 38 | struct regulator *supply; | 37 | struct regulator_bulk_data supplies[2]; |
| 39 | int post_power_delay_ms; | 38 | int post_power_delay_ms; |
| 40 | }; | 39 | }; |
| 41 | 40 | ||
diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h index 7288a7c573cc..fb78f6f500f3 100644 --- a/include/uapi/linux/input.h +++ b/include/uapi/linux/input.h | |||
| @@ -270,10 +270,11 @@ struct input_mask { | |||
| 270 | /* | 270 | /* |
| 271 | * MT_TOOL types | 271 | * MT_TOOL types |
| 272 | */ | 272 | */ |
| 273 | #define MT_TOOL_FINGER 0 | 273 | #define MT_TOOL_FINGER 0x00 |
| 274 | #define MT_TOOL_PEN 1 | 274 | #define MT_TOOL_PEN 0x01 |
| 275 | #define MT_TOOL_PALM 2 | 275 | #define MT_TOOL_PALM 0x02 |
| 276 | #define MT_TOOL_MAX 2 | 276 | #define MT_TOOL_DIAL 0x0a |
| 277 | #define MT_TOOL_MAX 0x0f | ||
| 277 | 278 | ||
| 278 | /* | 279 | /* |
| 279 | * Values describing the status of a force-feedback effect | 280 | * Values describing the status of a force-feedback effect |
