Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2 | /* |
Dmitry Torokhov | 4104d13 | 2007-05-07 16:16:29 -0400 | [diff] [blame] | 3 | * drivers/input/tablet/wacom.h |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 4 | * |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 5 | * USB Wacom tablet support |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Copyright (c) 2000-2004 Vojtech Pavlik <vojtech@ucw.cz> |
| 8 | * Copyright (c) 2000 Andreas Bach Aaen <abach@stofanet.dk> |
| 9 | * Copyright (c) 2000 Clifford Wolf <clifford@clifford.at> |
| 10 | * Copyright (c) 2000 Sam Mosel <sam.mosel@computer.org> |
| 11 | * Copyright (c) 2000 James E. Blair <corvus@gnu.org> |
| 12 | * Copyright (c) 2000 Daniel Egger <egger@suse.de> |
| 13 | * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com> |
| 14 | * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be> |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 15 | * Copyright (c) 2002-2011 Ping Cheng <pingc@wacom.com> |
Benjamin Tissoires | 1c3c523 | 2014-08-06 14:04:23 -0700 | [diff] [blame] | 16 | * Copyright (c) 2014 Benjamin Tissoires <benjamin.tissoires@redhat.com> |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 17 | * |
| 18 | * ChangeLog: |
| 19 | * v0.1 (vp) - Initial release |
| 20 | * v0.2 (aba) - Support for all buttons / combinations |
| 21 | * v0.3 (vp) - Support for Intuos added |
| 22 | * v0.4 (sm) - Support for more Intuos models, menustrip |
| 23 | * relative mode, proximity. |
| 24 | * v0.5 (vp) - Big cleanup, nifty features removed, |
| 25 | * they belong in userspace |
| 26 | * v1.8 (vp) - Submit URB only when operating, moved to CVS, |
| 27 | * use input_report_key instead of report_btn and |
| 28 | * other cleanups |
| 29 | * v1.11 (vp) - Add URB ->dev setting for new kernels |
| 30 | * v1.11 (jb) - Add support for the 4D Mouse & Lens |
| 31 | * v1.12 (de) - Add support for two more inking pen IDs |
| 32 | * v1.14 (vp) - Use new USB device id probing scheme. |
| 33 | * Fix Wacom Graphire mouse wheel |
| 34 | * v1.18 (vp) - Fix mouse wheel direction |
| 35 | * Make mouse relative |
| 36 | * v1.20 (fl) - Report tool id for Intuos devices |
| 37 | * - Multi tools support |
| 38 | * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...) |
| 39 | * - Add PL models support |
| 40 | * - Fix Wacom Graphire mouse wheel again |
| 41 | * v1.21 (vp) - Removed protocol descriptions |
| 42 | * - Added MISC_SERIAL for tool serial numbers |
| 43 | * (gb) - Identify version on module load. |
| 44 | * v1.21.1 (fl) - added Graphire2 support |
| 45 | * v1.21.2 (fl) - added Intuos2 support |
| 46 | * - added all the PL ids |
| 47 | * v1.21.3 (fl) - added another eraser id from Neil Okamoto |
| 48 | * - added smooth filter for Graphire from Peri Hankey |
| 49 | * - added PenPartner support from Olaf van Es |
| 50 | * - new tool ids from Ole Martin Bjoerndalen |
| 51 | * v1.29 (pc) - Add support for more tablets |
| 52 | * - Fix pressure reporting |
| 53 | * v1.30 (vp) - Merge 2.4 and 2.5 drivers |
| 54 | * - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse |
| 55 | * - Cleanups here and there |
| 56 | * v1.30.1 (pi) - Added Graphire3 support |
| 57 | * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ... |
| 58 | * v1.43 (pc) - Added support for Cintiq 21UX |
| 59 | * - Fixed a Graphire bug |
| 60 | * - Merged wacom_intuos3_irq into wacom_intuos_irq |
| 61 | * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc. |
| 62 | * - Report Device IDs |
| 63 | * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19 |
| 64 | * - Minor data report fix |
| 65 | * v1.46 (pc) - Split wacom.c into wacom_sys.c and wacom_wac.c, |
| 66 | * - where wacom_sys.c deals with system specific code, |
Ping Cheng | 7ecfbfd | 2007-06-14 23:32:48 -0400 | [diff] [blame] | 67 | * - and wacom_wac.c deals with Wacom specific code |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 68 | * - Support Intuos3 4x6 |
Ping Cheng | 7ecfbfd | 2007-06-14 23:32:48 -0400 | [diff] [blame] | 69 | * v1.47 (pc) - Added support for Bamboo |
Ping Cheng | 0e1763f | 2008-03-13 16:46:46 -0400 | [diff] [blame] | 70 | * v1.48 (pc) - Added support for Bamboo1, BambooFun, and Cintiq 12WX |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 71 | * v1.49 (pc) - Added support for USB Tablet PC (0x90, 0x93, and 0x9A) |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 72 | * v1.50 (pc) - Fixed a TabletPC touch bug in 2.6.28 |
Ping Cheng | 6f660f1 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 73 | * v1.51 (pc) - Added support for Intuos4 |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 74 | * v1.52 (pc) - Query Wacom data upon system resume |
Ping Cheng | ee54500 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 75 | * - add defines for features->type |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 76 | * - add new devices (0x9F, 0xE2, and 0XE3) |
Benjamin Tissoires | 1c3c523 | 2014-08-06 14:04:23 -0700 | [diff] [blame] | 77 | * v2.00 (bt) - conversion to a HID driver |
| 78 | * - integration of the Bluetooth devices |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 79 | */ |
| 80 | |
| 81 | /* |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 82 | */ |
| 83 | #ifndef WACOM_H |
| 84 | #define WACOM_H |
| 85 | #include <linux/kernel.h> |
| 86 | #include <linux/slab.h> |
| 87 | #include <linux/module.h> |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 88 | #include <linux/mod_devicetable.h> |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 89 | #include <linux/hid.h> |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 90 | #include <linux/kfifo.h> |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 91 | #include <linux/leds.h> |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 92 | #include <linux/usb/input.h> |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 93 | #include <linux/power_supply.h> |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 94 | #include <asm/unaligned.h> |
| 95 | |
| 96 | /* |
| 97 | * Version Information |
| 98 | */ |
Benjamin Tissoires | 1c3c523 | 2014-08-06 14:04:23 -0700 | [diff] [blame] | 99 | #define DRIVER_VERSION "v2.00" |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 100 | #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 101 | #define DRIVER_DESC "USB Wacom tablet driver" |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 102 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 103 | #define USB_VENDOR_ID_WACOM 0x056a |
Ajay Ramaswamy | 7b4b306 | 2010-12-23 01:19:39 -0800 | [diff] [blame] | 104 | #define USB_VENDOR_ID_LENOVO 0x17ef |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 105 | |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 106 | enum wacom_worker { |
| 107 | WACOM_WORKER_WIRELESS, |
| 108 | WACOM_WORKER_BATTERY, |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 109 | WACOM_WORKER_REMOTE, |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 110 | WACOM_WORKER_MODE_CHANGE, |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 113 | struct wacom; |
| 114 | |
| 115 | struct wacom_led { |
| 116 | struct led_classdev cdev; |
| 117 | struct led_trigger trigger; |
| 118 | struct wacom *wacom; |
| 119 | unsigned int group; |
| 120 | unsigned int id; |
| 121 | u8 llv; |
| 122 | u8 hlv; |
| 123 | bool held; |
| 124 | }; |
| 125 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 126 | struct wacom_group_leds { |
| 127 | u8 select; /* status led selector (0..3) */ |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 128 | struct wacom_led *leds; |
| 129 | unsigned int count; |
Benjamin Tissoires | 589e506 | 2016-07-13 18:06:11 +0200 | [diff] [blame] | 130 | struct device *dev; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 131 | }; |
| 132 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 133 | struct wacom_battery { |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 134 | struct wacom *wacom; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 135 | struct power_supply_desc bat_desc; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 136 | struct power_supply *battery; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 137 | char bat_name[WACOM_NAME_MAX]; |
Jason Gerecke | 16e4598 | 2017-04-28 09:25:33 -0700 | [diff] [blame] | 138 | int bat_status; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 139 | int battery_capacity; |
| 140 | int bat_charging; |
| 141 | int bat_connected; |
| 142 | int ps_connected; |
| 143 | }; |
| 144 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 145 | struct wacom_remote { |
| 146 | spinlock_t remote_lock; |
| 147 | struct kfifo remote_fifo; |
| 148 | struct kobject *remote_dir; |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 149 | struct { |
| 150 | struct attribute_group group; |
| 151 | u32 serial; |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 152 | struct input_dev *input; |
| 153 | bool registered; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 154 | struct wacom_battery battery; |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 155 | } remotes[WACOM_MAX_REMOTES]; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 156 | }; |
| 157 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 158 | struct wacom { |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 159 | struct usb_device *usbdev; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 160 | struct usb_interface *intf; |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 161 | struct wacom_wac wacom_wac; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 162 | struct hid_device *hdev; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 163 | struct mutex lock; |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 164 | struct work_struct wireless_work; |
| 165 | struct work_struct battery_work; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 166 | struct work_struct remote_work; |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 167 | struct delayed_work init_work; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 168 | struct wacom_remote *remote; |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 169 | struct work_struct mode_change_work; |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 170 | bool generic_has_leds; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 171 | struct wacom_leds { |
| 172 | struct wacom_group_leds *groups; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 173 | unsigned int count; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 174 | u8 llv; /* status led brightness no button (1..127) */ |
| 175 | u8 hlv; /* status led brightness button pressed (1..127) */ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 176 | u8 img_lum; /* OLED matrix display brightness */ |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 177 | u8 max_llv; /* maximum brightness of LED (llv) */ |
| 178 | u8 max_hlv; /* maximum brightness of LED (hlv) */ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 179 | } led; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 180 | struct wacom_battery battery; |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 181 | bool resources; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 184 | static inline void wacom_schedule_work(struct wacom_wac *wacom_wac, |
| 185 | enum wacom_worker which) |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 186 | { |
| 187 | struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 188 | |
| 189 | switch (which) { |
| 190 | case WACOM_WORKER_WIRELESS: |
| 191 | schedule_work(&wacom->wireless_work); |
| 192 | break; |
| 193 | case WACOM_WORKER_BATTERY: |
| 194 | schedule_work(&wacom->battery_work); |
| 195 | break; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 196 | case WACOM_WORKER_REMOTE: |
| 197 | schedule_work(&wacom->remote_work); |
| 198 | break; |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 199 | case WACOM_WORKER_MODE_CHANGE: |
| 200 | schedule_work(&wacom->mode_change_work); |
| 201 | break; |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 202 | } |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Jason Gerecke | ff479731 | 2019-11-06 11:59:46 -0800 | [diff] [blame] | 205 | /* |
| 206 | * Convert a signed 32-bit integer to an unsigned n-bit integer. Undoes |
| 207 | * the normally-helpful work of 'hid_snto32' for fields that use signed |
| 208 | * ranges for questionable reasons. |
| 209 | */ |
| 210 | static inline __u32 wacom_s32tou(s32 value, __u8 n) |
| 211 | { |
| 212 | switch (n) { |
| 213 | case 8: return ((__u8)value); |
| 214 | case 16: return ((__u16)value); |
| 215 | case 32: return ((__u32)value); |
| 216 | } |
| 217 | return value & (1 << (n - 1)) ? value & (~(~0U << n)) : value; |
| 218 | } |
| 219 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 220 | extern const struct hid_device_id wacom_ids[]; |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 221 | |
Dmitry Torokhov | 95dd3b3 | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 222 | void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); |
Ping Cheng | 42f4f27 | 2015-04-15 16:53:54 -0700 | [diff] [blame] | 223 | void wacom_setup_device_quirks(struct wacom *wacom); |
Jason Gerecke | 2636a3f | 2015-06-15 18:01:44 -0700 | [diff] [blame] | 224 | int wacom_setup_pen_input_capabilities(struct input_dev *input_dev, |
| 225 | struct wacom_wac *wacom_wac); |
| 226 | int wacom_setup_touch_input_capabilities(struct input_dev *input_dev, |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 227 | struct wacom_wac *wacom_wac); |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 228 | int wacom_setup_pad_input_capabilities(struct input_dev *input_dev, |
| 229 | struct wacom_wac *wacom_wac); |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 230 | void wacom_wac_usage_mapping(struct hid_device *hdev, |
| 231 | struct hid_field *field, struct hid_usage *usage); |
Ping Cheng | 354a329 | 2016-12-08 22:03:27 -0800 | [diff] [blame] | 232 | void wacom_wac_event(struct hid_device *hdev, struct hid_field *field, |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 233 | struct hid_usage *usage, __s32 value); |
| 234 | void wacom_wac_report(struct hid_device *hdev, struct hid_report *report); |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 235 | void wacom_battery_work(struct work_struct *work); |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 236 | enum led_brightness wacom_leds_brightness_get(struct wacom_led *led); |
| 237 | struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group, |
| 238 | unsigned int id); |
| 239 | struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur); |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 240 | int wacom_equivalent_usage(int usage); |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 241 | int wacom_initialize_leds(struct wacom *wacom); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 242 | #endif |