blob: 1c96809b51c909431255eb912d04156d7f5fd8aa [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ping Cheng3bea7332006-07-13 18:01:36 -07002/*
Dmitry Torokhov4104d132007-05-07 16:16:29 -04003 * drivers/input/tablet/wacom_wac.c
Ping Cheng3bea7332006-07-13 18:01:36 -07004 *
Ping Chengee545002009-12-15 00:35:24 -08005 * USB Wacom tablet support - Wacom specific code
Ping Cheng3bea7332006-07-13 18:01:36 -07006 */
7
8/*
Ping Cheng3bea7332006-07-13 18:01:36 -07009 */
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070010
Ping Cheng3bea7332006-07-13 18:01:36 -070011#include "wacom_wac.h"
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070012#include "wacom.h"
Henrik Rydberg47c78e82010-11-27 09:16:48 +010013#include <linux/input/mt.h>
Ping Cheng3bea7332006-07-13 18:01:36 -070014
Ping Chenge35fb8c2011-03-26 21:16:05 -070015/* resolution for penabled devices */
16#define WACOM_PL_RES 20
17#define WACOM_PENPRTN_RES 40
18#define WACOM_VOLITO_RES 50
19#define WACOM_GRAPHIRE_RES 80
20#define WACOM_INTUOS_RES 100
21#define WACOM_INTUOS3_RES 200
22
Ping Chengfa770342014-12-01 13:44:28 -080023/* Newer Cintiq and DTU have an offset between tablet and screen areas */
24#define WACOM_DTU_OFFSET 200
25#define WACOM_CINTIQ_OFFSET 400
26
Benjamin Tissoires387142b2014-08-06 13:52:56 -070027/*
28 * Scale factor relating reported contact size to logical contact area.
Jason Gerecke4e904952012-10-03 17:19:11 -070029 * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
30 */
31#define WACOM_CONTACT_AREA_SCALE 2607
32
Ping Cheng1924e052016-08-09 14:38:56 -070033static bool touch_arbitration = 1;
34module_param(touch_arbitration, bool, 0644);
35MODULE_PARM_DESC(touch_arbitration, " on (Y) off (N)");
36
Jason Gereckec7f05222015-11-30 17:13:47 -080037static void wacom_report_numbered_buttons(struct input_dev *input_dev,
38 int button_count, int mask);
39
Jason Gerecke5922e612016-10-19 18:03:51 -070040static int wacom_numbered_button_to_key(int n);
41
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -080042static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
43 int group);
Benjamin Tissoires387142b2014-08-06 13:52:56 -070044/*
45 * Percent of battery capacity for Graphire.
46 * 8th value means AC online and show 100% capacity.
47 */
48static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
49
Benjamin Tissoires81af7e62014-08-06 13:55:56 -070050/*
51 * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
52 */
53static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
54
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020055static void __wacom_notify_battery(struct wacom_battery *battery,
Jason Gerecke16e45982017-04-28 09:25:33 -070056 int bat_status, int bat_capacity,
57 bool bat_charging, bool bat_connected,
58 bool ps_connected)
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020059{
Jason Gerecke16e45982017-04-28 09:25:33 -070060 bool changed = battery->bat_status != bat_status ||
61 battery->battery_capacity != bat_capacity ||
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020062 battery->bat_charging != bat_charging ||
63 battery->bat_connected != bat_connected ||
64 battery->ps_connected != ps_connected;
65
66 if (changed) {
Jason Gerecke16e45982017-04-28 09:25:33 -070067 battery->bat_status = bat_status;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020068 battery->battery_capacity = bat_capacity;
69 battery->bat_charging = bat_charging;
70 battery->bat_connected = bat_connected;
71 battery->ps_connected = ps_connected;
72
73 if (battery->battery)
74 power_supply_changed(battery->battery);
75 }
76}
77
Jason Gerecke953f2c52015-03-06 11:47:39 -080078static void wacom_notify_battery(struct wacom_wac *wacom_wac,
Jason Gerecke16e45982017-04-28 09:25:33 -070079 int bat_status, int bat_capacity, bool bat_charging,
80 bool bat_connected, bool ps_connected)
Jason Gerecke953f2c52015-03-06 11:47:39 -080081{
82 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke953f2c52015-03-06 11:47:39 -080083
Jason Gerecke16e45982017-04-28 09:25:33 -070084 __wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
85 bat_charging, bat_connected, ps_connected);
Jason Gerecke953f2c52015-03-06 11:47:39 -080086}
87
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -070088static int wacom_penpartner_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -070089{
90 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -070091 struct input_dev *input = wacom->pen_input;
Ping Cheng3bea7332006-07-13 18:01:36 -070092
93 switch (data[0]) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -070094 case 1:
95 if (data[5] & 0x80) {
96 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
97 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -070098 input_report_key(input, wacom->tool[0], 1);
99 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700100 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
101 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700102 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
103 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
104 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700105 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700106 input_report_key(input, wacom->tool[0], 0);
107 input_report_abs(input, ABS_MISC, 0); /* report tool id */
108 input_report_abs(input, ABS_PRESSURE, -1);
109 input_report_key(input, BTN_TOUCH, 0);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700110 }
111 break;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700112
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700113 case 2:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700114 input_report_key(input, BTN_TOOL_PEN, 1);
115 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700116 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
117 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700118 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
119 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
120 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700121 break;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700122
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700123 default:
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700124 dev_dbg(input->dev.parent,
125 "%s: received unknown report #%d\n", __func__, data[0]);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700126 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700127 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700128
Ping Cheng3bea7332006-07-13 18:01:36 -0700129 return 1;
130}
131
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700132static int wacom_pl_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700133{
Jason Childse33da8a2010-02-17 22:38:31 -0800134 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700135 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700136 struct input_dev *input = wacom->pen_input;
Ping Chenge34b9d22008-05-05 11:36:41 -0400137 int prox, pressure;
Ping Cheng3bea7332006-07-13 18:01:36 -0700138
Ping Chengcad74702009-12-15 00:35:25 -0800139 if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700140 dev_dbg(input->dev.parent,
141 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700142 return 0;
143 }
144
145 prox = data[1] & 0x40;
146
Jason Gerecke025bcc12015-08-03 10:18:10 -0700147 if (!wacom->id[0]) {
148 if ((data[0] & 0x10) || (data[4] & 0x20)) {
149 wacom->tool[0] = BTN_TOOL_RUBBER;
150 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700151 }
Jason Gerecke025bcc12015-08-03 10:18:10 -0700152 else {
153 wacom->tool[0] = BTN_TOOL_PEN;
Ping Chenge34b9d22008-05-05 11:36:41 -0400154 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700155 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700156 }
157
Jason Gerecke025bcc12015-08-03 10:18:10 -0700158 /* If the eraser is in prox, STYLUS2 is always set. If we
159 * mis-detected the type and notice that STYLUS2 isn't set
160 * then force the eraser out of prox and let the pen in.
161 */
162 if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
163 input_report_key(input, BTN_TOOL_RUBBER, 0);
164 input_report_abs(input, ABS_MISC, 0);
165 input_sync(input);
166 wacom->tool[0] = BTN_TOOL_PEN;
167 wacom->id[0] = STYLUS_DEVICE_ID;
168 }
169
Jason Gerecke282e4632017-01-26 09:06:22 -0800170 if (prox) {
171 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
172 if (features->pressure_max > 255)
173 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
174 pressure += (features->pressure_max + 1) / 2;
Jason Gerecke025bcc12015-08-03 10:18:10 -0700175
Jason Gerecke282e4632017-01-26 09:06:22 -0800176 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
177 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
178 input_report_abs(input, ABS_PRESSURE, pressure);
Jason Gerecke025bcc12015-08-03 10:18:10 -0700179
Jason Gerecke282e4632017-01-26 09:06:22 -0800180 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
181 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
182 /* Only allow the stylus2 button to be reported for the pen tool. */
183 input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
184 }
Jason Gerecke025bcc12015-08-03 10:18:10 -0700185
186 if (!prox)
187 wacom->id[0] = 0;
188 input_report_key(input, wacom->tool[0], prox);
189 input_report_abs(input, ABS_MISC, wacom->id[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700190 return 1;
191}
192
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700193static int wacom_ptu_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700194{
195 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700196 struct input_dev *input = wacom->pen_input;
Ping Cheng3bea7332006-07-13 18:01:36 -0700197
Ping Chengcad74702009-12-15 00:35:25 -0800198 if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700199 dev_dbg(input->dev.parent,
200 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700201 return 0;
202 }
203
Ping Cheng3bea7332006-07-13 18:01:36 -0700204 if (data[1] & 0x04) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700205 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
206 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
Ping Chenge34b9d22008-05-05 11:36:41 -0400207 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700208 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700209 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
210 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
Ping Chenge34b9d22008-05-05 11:36:41 -0400211 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700212 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700213 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700214 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
215 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
216 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700217 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
218 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
Ping Cheng3bea7332006-07-13 18:01:36 -0700219 return 1;
220}
221
Ping Chengc8f2edc2010-06-28 01:10:51 -0700222static int wacom_dtu_irq(struct wacom_wac *wacom)
223{
Jason Gerecke74b63412014-04-19 13:50:22 -0700224 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700225 struct input_dev *input = wacom->pen_input;
Jason Gerecke74b63412014-04-19 13:50:22 -0700226 int prox = data[1] & 0x20;
Ping Chengc8f2edc2010-06-28 01:10:51 -0700227
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700228 dev_dbg(input->dev.parent,
229 "%s: received report #%d", __func__, data[0]);
Ping Chengc8f2edc2010-06-28 01:10:51 -0700230
231 if (prox) {
232 /* Going into proximity select tool */
233 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
234 if (wacom->tool[0] == BTN_TOOL_PEN)
235 wacom->id[0] = STYLUS_DEVICE_ID;
236 else
237 wacom->id[0] = ERASER_DEVICE_ID;
238 }
239 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
240 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
241 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
242 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke74b63412014-04-19 13:50:22 -0700243 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
Ping Chengc8f2edc2010-06-28 01:10:51 -0700244 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
245 if (!prox) /* out-prox */
246 wacom->id[0] = 0;
247 input_report_key(input, wacom->tool[0], prox);
248 input_report_abs(input, ABS_MISC, wacom->id[0]);
249 return 1;
250}
251
Ping Cheng497ab1f2014-01-20 20:18:04 -0800252static int wacom_dtus_irq(struct wacom_wac *wacom)
253{
Jason Gerecke073b50b2019-08-16 11:54:26 -0700254 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700255 struct input_dev *input = wacom->pen_input;
Ping Cheng497ab1f2014-01-20 20:18:04 -0800256 unsigned short prox, pressure = 0;
257
258 if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
259 dev_dbg(input->dev.parent,
260 "%s: received unknown report #%d", __func__, data[0]);
261 return 0;
262 } else if (data[0] == WACOM_REPORT_DTUSPAD) {
Benjamin Tissoires422b0312014-07-24 12:50:39 -0700263 input = wacom->pad_input;
Ping Cheng497ab1f2014-01-20 20:18:04 -0800264 input_report_key(input, BTN_0, (data[1] & 0x01));
265 input_report_key(input, BTN_1, (data[1] & 0x02));
266 input_report_key(input, BTN_2, (data[1] & 0x04));
267 input_report_key(input, BTN_3, (data[1] & 0x08));
268 input_report_abs(input, ABS_MISC,
269 data[1] & 0x0f ? PAD_DEVICE_ID : 0);
Ping Cheng497ab1f2014-01-20 20:18:04 -0800270 return 1;
271 } else {
272 prox = data[1] & 0x80;
273 if (prox) {
274 switch ((data[1] >> 3) & 3) {
275 case 1: /* Rubber */
276 wacom->tool[0] = BTN_TOOL_RUBBER;
277 wacom->id[0] = ERASER_DEVICE_ID;
278 break;
279
280 case 2: /* Pen */
281 wacom->tool[0] = BTN_TOOL_PEN;
282 wacom->id[0] = STYLUS_DEVICE_ID;
283 break;
284 }
285 }
286
287 input_report_key(input, BTN_STYLUS, data[1] & 0x20);
288 input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
289 input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
290 input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
291 pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
292 input_report_abs(input, ABS_PRESSURE, pressure);
293 input_report_key(input, BTN_TOUCH, pressure > 10);
294
295 if (!prox) /* out-prox */
296 wacom->id[0] = 0;
297 input_report_key(input, wacom->tool[0], prox);
298 input_report_abs(input, ABS_MISC, wacom->id[0]);
Ping Cheng497ab1f2014-01-20 20:18:04 -0800299 return 1;
300 }
301}
302
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700303static int wacom_graphire_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700304{
Jason Childse33da8a2010-02-17 22:38:31 -0800305 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700306 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700307 struct input_dev *input = wacom->pen_input;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700308 struct input_dev *pad_input = wacom->pad_input;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700309 int battery_capacity, ps_connected;
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700310 int prox;
Ping Cheng3b57ca02010-03-04 21:50:59 -0800311 int rw = 0;
312 int retval = 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700313
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700314 if (features->type == GRAPHIRE_BT) {
315 if (data[0] != WACOM_REPORT_PENABLED_BT) {
316 dev_dbg(input->dev.parent,
317 "%s: received unknown report #%d\n", __func__,
318 data[0]);
319 goto exit;
320 }
321 } else if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700322 dev_dbg(input->dev.parent,
323 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800324 goto exit;
Ping Cheng3bea7332006-07-13 18:01:36 -0700325 }
326
Ping Cheng3b57ca02010-03-04 21:50:59 -0800327 prox = data[1] & 0x80;
328 if (prox || wacom->id[0]) {
329 if (prox) {
330 switch ((data[1] >> 5) & 3) {
Ping Cheng3bea7332006-07-13 18:01:36 -0700331
332 case 0: /* Pen */
333 wacom->tool[0] = BTN_TOOL_PEN;
Ping Chenge34b9d22008-05-05 11:36:41 -0400334 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700335 break;
336
337 case 1: /* Rubber */
338 wacom->tool[0] = BTN_TOOL_RUBBER;
Ping Chenge34b9d22008-05-05 11:36:41 -0400339 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700340 break;
341
342 case 2: /* Mouse with wheel */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700343 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
Ping Cheng3bea7332006-07-13 18:01:36 -0700344 /* fall through */
345
346 case 3: /* Mouse without wheel */
347 wacom->tool[0] = BTN_TOOL_MOUSE;
Ping Chenge34b9d22008-05-05 11:36:41 -0400348 wacom->id[0] = CURSOR_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700349 break;
Ping Cheng3b57ca02010-03-04 21:50:59 -0800350 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700351 }
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700352 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
353 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Ping Cheng3bea7332006-07-13 18:01:36 -0700354 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700355 if (features->type == GRAPHIRE_BT)
356 input_report_abs(input, ABS_PRESSURE, data[6] |
357 (((__u16) (data[1] & 0x08)) << 5));
358 else
359 input_report_abs(input, ABS_PRESSURE, data[6] |
360 ((data[7] & 0x03) << 8));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700361 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
362 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
363 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
Dmitry Torokhovafb567e2010-04-13 23:08:58 -0700364 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700365 input_report_key(input, BTN_LEFT, data[1] & 0x01);
366 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800367 if (features->type == WACOM_G4 ||
368 features->type == WACOM_MO) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700369 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
Mike Autyd9f66c12010-08-28 20:35:17 -0700370 rw = (data[7] & 0x04) - (data[7] & 0x03);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700371 } else if (features->type == GRAPHIRE_BT) {
372 /* Compute distance between mouse and tablet */
373 rw = 44 - (data[6] >> 2);
374 rw = clamp_val(rw, 0, 31);
375 input_report_abs(input, ABS_DISTANCE, rw);
376 if (((data[1] >> 5) & 3) == 2) {
377 /* Mouse with wheel */
378 input_report_key(input, BTN_MIDDLE,
379 data[1] & 0x04);
380 rw = (data[6] & 0x01) ? -1 :
381 (data[6] & 0x02) ? 1 : 0;
382 } else {
383 rw = 0;
384 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800385 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700386 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
Mike Autyd9f66c12010-08-28 20:35:17 -0700387 rw = -(signed char)data[6];
Ping Cheng3b57ca02010-03-04 21:50:59 -0800388 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700389 input_report_rel(input, REL_WHEEL, rw);
Dmitry Torokhovafb567e2010-04-13 23:08:58 -0700390 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800391
392 if (!prox)
393 wacom->id[0] = 0;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700394 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
395 input_report_key(input, wacom->tool[0], prox);
396 input_sync(input); /* sync last event */
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800397 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700398
399 /* send pad data */
Jason Childse33da8a2010-02-17 22:38:31 -0800400 switch (features->type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700401 case WACOM_G4:
Ping Cheng3b57ca02010-03-04 21:50:59 -0800402 prox = data[7] & 0xf8;
403 if (prox || wacom->id[1]) {
Ping Chenge34b9d22008-05-05 11:36:41 -0400404 wacom->id[1] = PAD_DEVICE_ID;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700405 input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
406 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
Ping Cheng3bea7332006-07-13 18:01:36 -0700407 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
Benjamin Tissoires38138102014-07-24 12:51:03 -0700408 input_report_rel(pad_input, REL_WHEEL, rw);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800409 if (!prox)
410 wacom->id[1] = 0;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700411 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
Ping Chengab687b12010-04-05 23:07:41 -0700412 retval = 1;
Ping Cheng3bea7332006-07-13 18:01:36 -0700413 }
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400414 break;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700415
416 case WACOM_MO:
Ping Cheng3b57ca02010-03-04 21:50:59 -0800417 prox = (data[7] & 0xf8) || data[8];
418 if (prox || wacom->id[1]) {
Ping Chenge34b9d22008-05-05 11:36:41 -0400419 wacom->id[1] = PAD_DEVICE_ID;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700420 input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
421 input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
422 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
423 input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
424 input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
Ping Cheng3b57ca02010-03-04 21:50:59 -0800425 if (!prox)
426 wacom->id[1] = 0;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700427 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
Ping Cheng84460012011-07-06 18:05:43 -0700428 retval = 1;
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400429 }
430 break;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700431 case GRAPHIRE_BT:
432 prox = data[7] & 0x03;
433 if (prox || wacom->id[1]) {
434 wacom->id[1] = PAD_DEVICE_ID;
435 input_report_key(pad_input, BTN_0, (data[7] & 0x02));
436 input_report_key(pad_input, BTN_1, (data[7] & 0x01));
437 if (!prox)
438 wacom->id[1] = 0;
439 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
440 retval = 1;
441 }
442 break;
443 }
444
445 /* Store current battery capacity and power supply state */
446 if (features->type == GRAPHIRE_BT) {
447 rw = (data[7] >> 2 & 0x07);
448 battery_capacity = batcap_gr[rw];
449 ps_connected = rw == 7;
Jason Gerecke16e45982017-04-28 09:25:33 -0700450 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
451 battery_capacity, ps_connected, 1,
452 ps_connected);
Ping Cheng3bea7332006-07-13 18:01:36 -0700453 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800454exit:
455 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -0700456}
457
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500458static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
459{
460 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke0bbfe282016-01-06 13:25:53 -0800461 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500462 struct hid_report *r;
463 struct hid_report_enum *re;
464
465 re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
Jason Gerecke0bbfe282016-01-06 13:25:53 -0800466 if (features->type == INTUOSHT2)
467 r = re->report_id_hash[WACOM_REPORT_INTUOSHT2_ID];
468 else
469 r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1];
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500470 if (r) {
471 hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
472 }
473}
474
Jason Gereckefb013a02015-11-30 17:13:46 -0800475static int wacom_intuos_pad(struct wacom_wac *wacom)
476{
477 struct wacom_features *features = &wacom->features;
478 unsigned char *data = wacom->data;
479 struct input_dev *input = wacom->pad_input;
Jason Gereckec7f05222015-11-30 17:13:47 -0800480 int i;
481 int buttons = 0, nbuttons = features->numbered_buttons;
482 int keys = 0, nkeys = 0;
483 int ring1 = 0, ring2 = 0;
484 int strip1 = 0, strip2 = 0;
485 bool prox = false;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700486 bool wrench = false, keyboard = false, mute_touch = false, menu = false,
487 info = false;
Jason Gereckefb013a02015-11-30 17:13:46 -0800488
489 /* pad packets. Works as a second tool and is always in prox */
490 if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
491 data[0] == WACOM_REPORT_CINTIQPAD))
492 return 0;
493
494 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800495 buttons = (data[3] << 1) | (data[2] & 0x01);
496 ring1 = data[1];
Jason Gereckefb013a02015-11-30 17:13:46 -0800497 } else if (features->type == DTK) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800498 buttons = data[6];
Jason Gereckefb013a02015-11-30 17:13:46 -0800499 } else if (features->type == WACOM_13HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800500 buttons = (data[4] << 1) | (data[3] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800501 } else if (features->type == WACOM_24HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800502 buttons = (data[8] << 8) | data[6];
503 ring1 = data[1];
504 ring2 = data[2];
Jason Gereckefb013a02015-11-30 17:13:46 -0800505
506 /*
507 * Three "buttons" are available on the 24HD which are
508 * physically implemented as a touchstrip. Each button
509 * is approximately 3 bits wide with a 2 bit spacing.
510 * The raw touchstrip bits are stored at:
511 * ((data[3] & 0x1f) << 8) | data[4])
512 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800513 nkeys = 3;
514 keys = ((data[3] & 0x1C) ? 1<<2 : 0) |
515 ((data[4] & 0xE0) ? 1<<1 : 0) |
516 ((data[4] & 0x07) ? 1<<0 : 0);
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700517 keyboard = !!(data[4] & 0xE0);
518 info = !!(data[3] & 0x1C);
519
520 if (features->oPid) {
521 mute_touch = !!(data[4] & 0x07);
522 if (mute_touch)
523 wacom->shared->is_touch_on =
524 !wacom->shared->is_touch_on;
525 } else {
526 wrench = !!(data[4] & 0x07);
527 }
Jason Gereckefb013a02015-11-30 17:13:46 -0800528 } else if (features->type == WACOM_27QHD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800529 nkeys = 3;
530 keys = data[2] & 0x07;
Jason Gereckefb013a02015-11-30 17:13:46 -0800531
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700532 wrench = !!(data[2] & 0x01);
533 keyboard = !!(data[2] & 0x02);
534
535 if (features->oPid) {
536 mute_touch = !!(data[2] & 0x04);
537 if (mute_touch)
538 wacom->shared->is_touch_on =
539 !wacom->shared->is_touch_on;
540 } else {
541 menu = !!(data[2] & 0x04);
542 }
Jason Gereckefb013a02015-11-30 17:13:46 -0800543 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
544 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
545 input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
Jason Gereckefb013a02015-11-30 17:13:46 -0800546 } else if (features->type == CINTIQ_HYBRID) {
547 /*
548 * Do not send hardware buttons under Android. They
549 * are already sent to the system through GPIO (and
550 * have different meaning).
Jason Gereckec7f05222015-11-30 17:13:47 -0800551 *
552 * d-pad right -> data[4] & 0x10
553 * d-pad up -> data[4] & 0x20
554 * d-pad left -> data[4] & 0x40
555 * d-pad down -> data[4] & 0x80
556 * d-pad center -> data[3] & 0x01
Jason Gereckefb013a02015-11-30 17:13:46 -0800557 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800558 buttons = (data[4] << 1) | (data[3] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800559 } else if (features->type == CINTIQ_COMPANION_2) {
Aaron Armstrong Skomra693c3da2019-07-23 11:09:15 -0700560 /* d-pad right -> data[2] & 0x10
561 * d-pad up -> data[2] & 0x20
562 * d-pad left -> data[2] & 0x40
563 * d-pad down -> data[2] & 0x80
564 * d-pad center -> data[1] & 0x01
Jason Gereckec7f05222015-11-30 17:13:47 -0800565 */
Jason Gerecke0402b6b2015-12-16 13:37:36 -0800566 buttons = ((data[2] >> 4) << 7) |
Aaron Armstrong Skomra693c3da2019-07-23 11:09:15 -0700567 ((data[1] & 0x04) << 4) |
Jason Gereckec7f05222015-11-30 17:13:47 -0800568 ((data[2] & 0x0F) << 2) |
569 (data[1] & 0x03);
Jason Gereckefb013a02015-11-30 17:13:46 -0800570 } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
Jason Gereckefb013a02015-11-30 17:13:46 -0800571 /*
572 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
573 * addition to the mechanical switch. Switch data is
574 * stored in data[4], capacitive data in data[5].
Jason Gereckec7f05222015-11-30 17:13:47 -0800575 *
576 * Touch ring mode switch (data[3]) has no capacitive sensor
Jason Gereckefb013a02015-11-30 17:13:46 -0800577 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800578 buttons = (data[4] << 1) | (data[3] & 0x01);
579 ring1 = data[2];
Jason Gereckefb013a02015-11-30 17:13:46 -0800580 } else {
581 if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800582 buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) |
583 (data[6] << 1) | (data[5] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800584
585 if (features->type == WACOM_22HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800586 nkeys = 3;
587 keys = data[9] & 0x07;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700588
589 info = !!(data[9] & 0x01);
590 wrench = !!(data[9] & 0x02);
Jason Gereckefb013a02015-11-30 17:13:46 -0800591 }
592 } else {
Ping Chengce067602017-08-31 15:50:03 -0700593 buttons = ((data[6] & 0x10) << 5) |
594 ((data[5] & 0x10) << 4) |
Jason Gereckec7f05222015-11-30 17:13:47 -0800595 ((data[6] & 0x0F) << 4) |
596 (data[5] & 0x0F);
Jason Gereckefb013a02015-11-30 17:13:46 -0800597 }
Jason Gereckef73d08d2015-12-16 13:37:33 -0800598 strip1 = ((data[1] & 0x1f) << 8) | data[2];
599 strip2 = ((data[3] & 0x1f) << 8) | data[4];
Jason Gereckefb013a02015-11-30 17:13:46 -0800600 }
Jason Gereckec7f05222015-11-30 17:13:47 -0800601
Jason Gerecke073b50b2019-08-16 11:54:26 -0700602 prox = (buttons & ~(~0U << nbuttons)) | (keys & ~(~0U << nkeys)) |
Dan Carpenter8f9cfdd2015-12-09 13:22:05 +0300603 (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2;
Jason Gereckec7f05222015-11-30 17:13:47 -0800604
605 wacom_report_numbered_buttons(input, nbuttons, buttons);
606
607 for (i = 0; i < nkeys; i++)
608 input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
609
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700610 input_report_key(input, KEY_BUTTONCONFIG, wrench);
611 input_report_key(input, KEY_ONSCREEN_KEYBOARD, keyboard);
612 input_report_key(input, KEY_CONTROLPANEL, menu);
613 input_report_key(input, KEY_INFO, info);
614
615 if (wacom->shared && wacom->shared->touch_input) {
616 input_report_switch(wacom->shared->touch_input,
617 SW_MUTE_DEVICE,
618 !wacom->shared->is_touch_on);
619 input_sync(wacom->shared->touch_input);
620 }
621
Jason Gereckec7f05222015-11-30 17:13:47 -0800622 input_report_abs(input, ABS_RX, strip1);
Jason Gerecke03a0dc52015-12-16 13:37:34 -0800623 input_report_abs(input, ABS_RY, strip2);
Jason Gereckec7f05222015-11-30 17:13:47 -0800624
Jason Gereckeaaae03e2015-12-16 13:37:35 -0800625 input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0);
626 input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0);
Jason Gereckec7f05222015-11-30 17:13:47 -0800627
628 input_report_key(input, wacom->tool[1], prox ? 1 : 0);
629 input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
630
631 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
632
Jason Gereckefb013a02015-11-30 17:13:46 -0800633 return 1;
634}
635
Jason Gerecke82527da2016-10-19 18:03:47 -0700636static int wacom_intuos_id_mangle(int tool_id)
637{
638 return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
639}
640
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100641static int wacom_intuos_get_tool_type(int tool_id)
642{
643 int tool_type;
644
645 switch (tool_id) {
646 case 0x812: /* Inking pen */
647 case 0x801: /* Intuos3 Inking pen */
Jason Gerecke82527da2016-10-19 18:03:47 -0700648 case 0x12802: /* Intuos4/5 Inking Pen */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100649 case 0x012:
650 tool_type = BTN_TOOL_PENCIL;
651 break;
652
653 case 0x822: /* Pen */
654 case 0x842:
655 case 0x852:
656 case 0x823: /* Intuos3 Grip Pen */
657 case 0x813: /* Intuos3 Classic Pen */
658 case 0x885: /* Intuos3 Marker Pen */
659 case 0x802: /* Intuos4/5 13HD/24HD General Pen */
660 case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
661 case 0x8e2: /* IntuosHT2 pen */
662 case 0x022:
Jason Gerecke82527da2016-10-19 18:03:47 -0700663 case 0x10804: /* Intuos4/5 13HD/24HD Art Pen */
Jason Gerecke4e6e7d72019-02-19 17:58:56 +0000664 case 0x10842: /* MobileStudio Pro Pro Pen slim */
Jason Gerecke82527da2016-10-19 18:03:47 -0700665 case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
666 case 0x16802: /* Cintiq 13HD Pro Pen */
667 case 0x18802: /* DTH2242 Pen */
668 case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100669 tool_type = BTN_TOOL_PEN;
670 break;
671
672 case 0x832: /* Stroke pen */
673 case 0x032:
674 tool_type = BTN_TOOL_BRUSH;
675 break;
676
677 case 0x007: /* Mouse 4D and 2D */
678 case 0x09c:
679 case 0x094:
680 case 0x017: /* Intuos3 2D Mouse */
681 case 0x806: /* Intuos4 Mouse */
682 tool_type = BTN_TOOL_MOUSE;
683 break;
684
685 case 0x096: /* Lens cursor */
686 case 0x097: /* Intuos3 Lens cursor */
687 case 0x006: /* Intuos4 Lens cursor */
688 tool_type = BTN_TOOL_LENS;
689 break;
690
691 case 0x82a: /* Eraser */
Jason Gerecke9ce9a122016-11-11 15:05:52 -0800692 case 0x84a:
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100693 case 0x85a:
694 case 0x91a:
695 case 0xd1a:
696 case 0x0fa:
697 case 0x82b: /* Intuos3 Grip Pen Eraser */
698 case 0x81b: /* Intuos3 Classic Pen Eraser */
699 case 0x91b: /* Intuos3 Airbrush Eraser */
700 case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
701 case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
702 case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
Jason Gerecke82527da2016-10-19 18:03:47 -0700703 case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
704 case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
705 case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
Jason Gerecke4e6e7d72019-02-19 17:58:56 +0000706 case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
Jason Gerecke82527da2016-10-19 18:03:47 -0700707 case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
708 case 0x1880a: /* DTH2242 Eraser */
709 case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100710 tool_type = BTN_TOOL_RUBBER;
711 break;
712
713 case 0xd12:
714 case 0x912:
715 case 0x112:
716 case 0x913: /* Intuos3 Airbrush */
717 case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
Jason Gerecke82527da2016-10-19 18:03:47 -0700718 case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100719 tool_type = BTN_TOOL_AIRBRUSH;
720 break;
721
722 default: /* Unknown tool */
723 tool_type = BTN_TOOL_PEN;
724 break;
725 }
726 return tool_type;
727}
728
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -0700729static void wacom_exit_report(struct wacom_wac *wacom)
730{
731 struct input_dev *input = wacom->pen_input;
732 struct wacom_features *features = &wacom->features;
733 unsigned char *data = wacom->data;
734 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
735
736 /*
737 * Reset all states otherwise we lose the initial states
738 * when in-prox next time
739 */
740 input_report_abs(input, ABS_X, 0);
741 input_report_abs(input, ABS_Y, 0);
742 input_report_abs(input, ABS_DISTANCE, 0);
743 input_report_abs(input, ABS_TILT_X, 0);
744 input_report_abs(input, ABS_TILT_Y, 0);
745 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
746 input_report_key(input, BTN_LEFT, 0);
747 input_report_key(input, BTN_MIDDLE, 0);
748 input_report_key(input, BTN_RIGHT, 0);
749 input_report_key(input, BTN_SIDE, 0);
750 input_report_key(input, BTN_EXTRA, 0);
751 input_report_abs(input, ABS_THROTTLE, 0);
752 input_report_abs(input, ABS_RZ, 0);
753 } else {
754 input_report_abs(input, ABS_PRESSURE, 0);
755 input_report_key(input, BTN_STYLUS, 0);
756 input_report_key(input, BTN_STYLUS2, 0);
757 input_report_key(input, BTN_TOUCH, 0);
758 input_report_abs(input, ABS_WHEEL, 0);
759 if (features->type >= INTUOS3S)
760 input_report_abs(input, ABS_Z, 0);
761 }
762 input_report_key(input, wacom->tool[idx], 0);
763 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
764 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
765 wacom->id[idx] = 0;
766}
767
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700768static int wacom_intuos_inout(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700769{
Jason Childse33da8a2010-02-17 22:38:31 -0800770 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700771 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700772 struct input_dev *input = wacom->pen_input;
Ping Cheng4750f5f2016-01-08 17:15:48 -0800773 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700774
Ping Cheng4750f5f2016-01-08 17:15:48 -0800775 if (!(((data[1] & 0xfc) == 0xc0) || /* in prox */
776 ((data[1] & 0xfe) == 0x20) || /* in range */
777 ((data[1] & 0xfe) == 0x80))) /* out prox */
778 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700779
780 /* Enter report */
781 if ((data[1] & 0xfc) == 0xc0) {
782 /* serial number of the tool */
783 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
784 (data[4] << 20) + (data[5] << 12) +
785 (data[6] << 4) + (data[7] >> 4);
786
Ping Cheng493630b2010-06-22 11:21:34 -0700787 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
Jason Gerecke82527da2016-10-19 18:03:47 -0700788 ((data[7] & 0x0f) << 16) | ((data[8] & 0xf0) << 8);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700789
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100790 wacom->tool[idx] = wacom_intuos_get_tool_type(wacom->id[idx]);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700791
Ping Chengeff6ca92016-05-02 21:17:34 -0700792 wacom->shared->stylus_in_proximity = true;
Ping Cheng3bea7332006-07-13 18:01:36 -0700793 return 1;
794 }
795
Ping Chengc1b03f52016-01-08 17:16:06 -0800796 /* in Range */
797 if ((data[1] & 0xfe) == 0x20) {
Ping Cheng526d6e72016-01-08 17:16:25 -0800798 if (features->type != INTUOSHT2)
799 wacom->shared->stylus_in_proximity = true;
Ping Cheng486b9082015-02-20 14:25:58 -0800800
Ping Chengc1b03f52016-01-08 17:16:06 -0800801 /* in Range while exiting */
802 if (wacom->reporting_data) {
803 input_report_key(input, BTN_TOUCH, 0);
804 input_report_abs(input, ABS_PRESSURE, 0);
805 input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
806 return 2;
807 }
808 return 1;
Jason Gerecke4eb18302013-09-20 09:48:46 -0700809 }
810
Ping Cheng3bea7332006-07-13 18:01:36 -0700811 /* Exit report */
812 if ((data[1] & 0xfe) == 0x80) {
Ping Chengf3586d22015-03-20 14:57:00 -0700813 wacom->shared->stylus_in_proximity = false;
Ping Chengb3bd7ef2015-01-09 11:05:13 -0800814 wacom->reporting_data = false;
Jason Gereckeae584ca2012-04-03 15:50:40 -0700815
Ping Cheng373a5352015-01-09 11:04:50 -0800816 /* don't report exit if we don't know the ID */
817 if (!wacom->id[idx])
818 return 1;
819
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -0700820 wacom_exit_report(wacom);
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800821 return 2;
Ping Cheng3bea7332006-07-13 18:01:36 -0700822 }
Ping Cheng373a5352015-01-09 11:04:50 -0800823
Ping Cheng3bea7332006-07-13 18:01:36 -0700824 return 0;
825}
826
Ping Cheng1924e052016-08-09 14:38:56 -0700827static inline bool report_touch_events(struct wacom_wac *wacom)
828{
829 return (touch_arbitration ? !wacom->shared->stylus_in_proximity : 1);
830}
831
832static inline bool delay_pen_events(struct wacom_wac *wacom)
833{
834 return (wacom->shared->touch_down && touch_arbitration);
Aaron Skomra72b236d2015-08-20 16:05:17 -0700835}
836
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800837static int wacom_intuos_general(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700838{
Jason Childse33da8a2010-02-17 22:38:31 -0800839 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700840 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700841 struct input_dev *input = wacom->pen_input;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800842 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
Jason Gereckea8a09c82015-11-30 17:13:49 -0800843 unsigned char type = (data[1] >> 1) & 0x0F;
Jason Gerecke5f33f432015-11-30 17:13:51 -0800844 unsigned int x, y, distance, t;
Ping Cheng3bea7332006-07-13 18:01:36 -0700845
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800846 if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
847 data[0] != WACOM_REPORT_INTUOS_PEN)
848 return 0;
849
Ping Cheng1924e052016-08-09 14:38:56 -0700850 if (delay_pen_events(wacom))
Ping Chengc1b03f52016-01-08 17:16:06 -0800851 return 1;
852
Ping Cheng599b0822016-01-08 17:14:54 -0800853 /* don't report events if we don't know the tool ID */
854 if (!wacom->id[idx]) {
855 /* but reschedule a read of the current tool */
856 wacom_intuos_schedule_prox_event(wacom);
857 return 1;
858 }
859
Ping Cheng4750f5f2016-01-08 17:15:48 -0800860 /*
861 * don't report events for invalid data
862 */
863 /* older I4 styli don't work with new Cintiqs */
Jason Gerecke82527da2016-10-19 18:03:47 -0700864 if ((!((wacom->id[idx] >> 16) & 0x01) &&
Ping Cheng4750f5f2016-01-08 17:15:48 -0800865 (features->type == WACOM_21UX2)) ||
866 /* Only large Intuos support Lense Cursor */
867 (wacom->tool[idx] == BTN_TOOL_LENS &&
868 (features->type == INTUOS3 ||
869 features->type == INTUOS3S ||
870 features->type == INTUOS4 ||
871 features->type == INTUOS4S ||
872 features->type == INTUOS5 ||
873 features->type == INTUOS5S ||
874 features->type == INTUOSPM ||
875 features->type == INTUOSPS)) ||
876 /* Cintiq doesn't send data when RDY bit isn't set */
877 (features->type == CINTIQ && !(data[1] & 0x40)))
878 return 1;
879
Jason Gerecke5f33f432015-11-30 17:13:51 -0800880 x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
881 y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
882 distance = data[9] >> 2;
883 if (features->type < INTUOS3S) {
884 x >>= 1;
885 y >>= 1;
886 distance >>= 1;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800887 }
Jason Gereckeb72fb1d2019-08-07 14:11:55 -0700888 if (features->type == INTUOSHT2)
889 distance = features->distance_max - distance;
Jason Gerecke5f33f432015-11-30 17:13:51 -0800890 input_report_abs(input, ABS_X, x);
891 input_report_abs(input, ABS_Y, y);
892 input_report_abs(input, ABS_DISTANCE, distance);
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800893
Jason Gereckea8a09c82015-11-30 17:13:49 -0800894 switch (type) {
895 case 0x00:
896 case 0x01:
897 case 0x02:
898 case 0x03:
899 /* general pen packet */
Jason Gerecke5f33f432015-11-30 17:13:51 -0800900 t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
901 if (features->pressure_max < 2047)
902 t >>= 1;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700903 input_report_abs(input, ABS_PRESSURE, t);
Ping Chengeda01da2015-09-23 13:51:15 -0700904 if (features->type != INTUOSHT2) {
905 input_report_abs(input, ABS_TILT_X,
Jason Gereckeec5fc1c2014-11-18 16:50:08 -0800906 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
Ping Chengeda01da2015-09-23 13:51:15 -0700907 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
908 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700909 input_report_key(input, BTN_STYLUS, data[1] & 2);
910 input_report_key(input, BTN_STYLUS2, data[1] & 4);
911 input_report_key(input, BTN_TOUCH, t > 10);
Jason Gereckea8a09c82015-11-30 17:13:49 -0800912 break;
Ping Cheng3bea7332006-07-13 18:01:36 -0700913
Jason Gereckea8a09c82015-11-30 17:13:49 -0800914 case 0x0a:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800915 /* airbrush second packet */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700916 input_report_abs(input, ABS_WHEEL,
Ping Cheng3bea7332006-07-13 18:01:36 -0700917 (data[6] << 2) | ((data[7] >> 6) & 3));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700918 input_report_abs(input, ABS_TILT_X,
Jason Gereckeec5fc1c2014-11-18 16:50:08 -0800919 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
920 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
Jason Gereckea8a09c82015-11-30 17:13:49 -0800921 break;
922
923 case 0x05:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800924 /* Rotation packet */
925 if (features->type >= INTUOS3S) {
926 /* I3 marker pen rotation */
927 t = (data[6] << 3) | ((data[7] >> 5) & 7);
928 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
929 ((t-1) / 2 + 450)) : (450 - t / 2) ;
930 input_report_abs(input, ABS_Z, t);
931 } else {
Jason Gerecke571f5722015-11-30 17:13:50 -0800932 /* 4D mouse 2nd packet */
Jason Gereckea8a09c82015-11-30 17:13:49 -0800933 t = (data[6] << 3) | ((data[7] >> 5) & 7);
934 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
935 ((t - 1) / 2) : -t / 2);
936 }
937 break;
Ping Cheng3bea7332006-07-13 18:01:36 -0700938
Jason Gereckea8a09c82015-11-30 17:13:49 -0800939 case 0x04:
Jason Gerecke571f5722015-11-30 17:13:50 -0800940 /* 4D mouse 1st packet */
941 input_report_key(input, BTN_LEFT, data[8] & 0x01);
942 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
943 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
944
945 input_report_key(input, BTN_SIDE, data[8] & 0x20);
946 input_report_key(input, BTN_EXTRA, data[8] & 0x10);
947 t = (data[6] << 2) | ((data[7] >> 6) & 3);
948 input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
949 break;
950
Jason Gereckea8a09c82015-11-30 17:13:49 -0800951 case 0x06:
Jason Gerecke571f5722015-11-30 17:13:50 -0800952 /* I4 mouse */
953 input_report_key(input, BTN_LEFT, data[6] & 0x01);
954 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
955 input_report_key(input, BTN_RIGHT, data[6] & 0x04);
956 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
957 - ((data[7] & 0x40) >> 6));
958 input_report_key(input, BTN_SIDE, data[6] & 0x08);
959 input_report_key(input, BTN_EXTRA, data[6] & 0x10);
960
961 input_report_abs(input, ABS_TILT_X,
962 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
963 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
964 break;
965
Jason Gereckea8a09c82015-11-30 17:13:49 -0800966 case 0x08:
Jason Gerecke571f5722015-11-30 17:13:50 -0800967 if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
968 /* 2D mouse packet */
969 input_report_key(input, BTN_LEFT, data[8] & 0x04);
970 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
971 input_report_key(input, BTN_RIGHT, data[8] & 0x10);
972 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
973 - ((data[8] & 0x02) >> 1));
Ping Cheng3bea7332006-07-13 18:01:36 -0700974
Jason Gerecke571f5722015-11-30 17:13:50 -0800975 /* I3 2D mouse side buttons */
976 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
977 input_report_key(input, BTN_SIDE, data[8] & 0x40);
978 input_report_key(input, BTN_EXTRA, data[8] & 0x20);
Ping Cheng3bea7332006-07-13 18:01:36 -0700979 }
Jason Gereckea8a09c82015-11-30 17:13:49 -0800980 }
Jason Gerecke571f5722015-11-30 17:13:50 -0800981 else if (wacom->tool[idx] == BTN_TOOL_LENS) {
Ping Cheng3bea7332006-07-13 18:01:36 -0700982 /* Lens cursor packets */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700983 input_report_key(input, BTN_LEFT, data[8] & 0x01);
984 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
985 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
986 input_report_key(input, BTN_SIDE, data[8] & 0x10);
987 input_report_key(input, BTN_EXTRA, data[8] & 0x08);
Ping Cheng3bea7332006-07-13 18:01:36 -0700988 }
Jason Gereckea8a09c82015-11-30 17:13:49 -0800989 break;
990
Jason Gerecke571f5722015-11-30 17:13:50 -0800991 case 0x07:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800992 case 0x09:
Jason Gerecke571f5722015-11-30 17:13:50 -0800993 case 0x0b:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800994 case 0x0c:
995 case 0x0d:
996 case 0x0e:
997 case 0x0f:
998 /* unhandled */
999 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07001000 }
Ping Cheng3bea7332006-07-13 18:01:36 -07001001
Jason Gerecke82527da2016-10-19 18:03:47 -07001002 input_report_abs(input, ABS_MISC,
1003 wacom_intuos_id_mangle(wacom->id[idx])); /* report tool id */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07001004 input_report_key(input, wacom->tool[idx], 1);
1005 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
Ping Chengb3bd7ef2015-01-09 11:05:13 -08001006 wacom->reporting_data = true;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001007 return 2;
Ping Cheng3bea7332006-07-13 18:01:36 -07001008}
1009
1010static int wacom_intuos_irq(struct wacom_wac *wacom)
1011{
Ping Cheng3bea7332006-07-13 18:01:36 -07001012 unsigned char *data = wacom->data;
1013 struct input_dev *input = wacom->pen_input;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001014 int result;
Ping Cheng3bea7332006-07-13 18:01:36 -07001015
1016 if (data[0] != WACOM_REPORT_PENABLED &&
Jason Gerecke06109992015-11-30 17:13:52 -08001017 data[0] != WACOM_REPORT_INTUOS_ID1 &&
1018 data[0] != WACOM_REPORT_INTUOS_ID2 &&
Ping Cheng3bea7332006-07-13 18:01:36 -07001019 data[0] != WACOM_REPORT_INTUOSPAD &&
1020 data[0] != WACOM_REPORT_INTUOS_PEN &&
1021 data[0] != WACOM_REPORT_CINTIQ &&
1022 data[0] != WACOM_REPORT_CINTIQPAD &&
1023 data[0] != WACOM_REPORT_INTUOS5PAD) {
1024 dev_dbg(input->dev.parent,
1025 "%s: received unknown report #%d\n", __func__, data[0]);
1026 return 0;
1027 }
1028
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001029 /* process pad events */
1030 result = wacom_intuos_pad(wacom);
1031 if (result)
1032 return result;
Ping Cheng3bea7332006-07-13 18:01:36 -07001033
1034 /* process in/out prox events */
1035 result = wacom_intuos_inout(wacom);
1036 if (result)
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001037 return result - 1;
Ping Cheng3bea7332006-07-13 18:01:36 -07001038
1039 /* process general packets */
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001040 result = wacom_intuos_general(wacom);
1041 if (result)
1042 return result - 1;
Ping Cheng3bea7332006-07-13 18:01:36 -07001043
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001044 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07001045}
1046
Jason Gerecke149f6f62017-03-31 10:02:05 -07001047static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
1048{
1049 unsigned char *data = wacom_wac->data;
1050 struct input_dev *input;
1051 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1052 struct wacom_remote *remote = wacom->remote;
1053 int bat_charging, bat_percent, touch_ring_mode;
1054 __u32 serial;
1055 int i, index = -1;
1056 unsigned long flags;
1057
1058 if (data[0] != WACOM_REPORT_REMOTE) {
1059 hid_dbg(wacom->hdev, "%s: received unknown report #%d",
1060 __func__, data[0]);
1061 return 0;
1062 }
1063
1064 serial = data[3] + (data[4] << 8) + (data[5] << 16);
1065 wacom_wac->id[0] = PAD_DEVICE_ID;
1066
1067 spin_lock_irqsave(&remote->remote_lock, flags);
1068
1069 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1070 if (remote->remotes[i].serial == serial) {
1071 index = i;
1072 break;
1073 }
1074 }
1075
1076 if (index < 0 || !remote->remotes[index].registered)
1077 goto out;
1078
1079 input = remote->remotes[index].input;
1080
1081 input_report_key(input, BTN_0, (data[9] & 0x01));
1082 input_report_key(input, BTN_1, (data[9] & 0x02));
1083 input_report_key(input, BTN_2, (data[9] & 0x04));
1084 input_report_key(input, BTN_3, (data[9] & 0x08));
1085 input_report_key(input, BTN_4, (data[9] & 0x10));
1086 input_report_key(input, BTN_5, (data[9] & 0x20));
1087 input_report_key(input, BTN_6, (data[9] & 0x40));
1088 input_report_key(input, BTN_7, (data[9] & 0x80));
1089
1090 input_report_key(input, BTN_8, (data[10] & 0x01));
1091 input_report_key(input, BTN_9, (data[10] & 0x02));
1092 input_report_key(input, BTN_A, (data[10] & 0x04));
1093 input_report_key(input, BTN_B, (data[10] & 0x08));
1094 input_report_key(input, BTN_C, (data[10] & 0x10));
1095 input_report_key(input, BTN_X, (data[10] & 0x20));
1096 input_report_key(input, BTN_Y, (data[10] & 0x40));
1097 input_report_key(input, BTN_Z, (data[10] & 0x80));
1098
1099 input_report_key(input, BTN_BASE, (data[11] & 0x01));
1100 input_report_key(input, BTN_BASE2, (data[11] & 0x02));
1101
1102 if (data[12] & 0x80)
Aaron Armstrong Skomrafcf887e2019-08-16 12:00:54 -07001103 input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f) - 1);
Jason Gerecke149f6f62017-03-31 10:02:05 -07001104 else
1105 input_report_abs(input, ABS_WHEEL, 0);
1106
1107 bat_percent = data[7] & 0x7f;
1108 bat_charging = !!(data[7] & 0x80);
1109
1110 if (data[9] | data[10] | (data[11] & 0x03) | data[12])
1111 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
1112 else
1113 input_report_abs(input, ABS_MISC, 0);
1114
1115 input_event(input, EV_MSC, MSC_SERIAL, serial);
1116
1117 input_sync(input);
1118
1119 /*Which mode select (LED light) is currently on?*/
1120 touch_ring_mode = (data[11] & 0xC0) >> 6;
1121
1122 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1123 if (remote->remotes[i].serial == serial)
1124 wacom->led.groups[i].select = touch_ring_mode;
1125 }
1126
Jason Gerecke16e45982017-04-28 09:25:33 -07001127 __wacom_notify_battery(&remote->remotes[index].battery,
1128 WACOM_POWER_SUPPLY_STATUS_AUTO, bat_percent,
Jason Gerecke149f6f62017-03-31 10:02:05 -07001129 bat_charging, 1, bat_charging);
1130
1131out:
1132 spin_unlock_irqrestore(&remote->remote_lock, flags);
1133 return 0;
1134}
1135
1136static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
1137{
1138 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1139 unsigned char *data = wacom_wac->data;
1140 struct wacom_remote *remote = wacom->remote;
1141 struct wacom_remote_data remote_data;
1142 unsigned long flags;
1143 int i, ret;
1144
1145 if (data[0] != WACOM_REPORT_DEVICE_LIST)
1146 return;
1147
1148 memset(&remote_data, 0, sizeof(struct wacom_remote_data));
1149
1150 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1151 int j = i * 6;
1152 int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
1153 bool connected = data[j+2];
1154
1155 remote_data.remote[i].serial = serial;
1156 remote_data.remote[i].connected = connected;
1157 }
1158
1159 spin_lock_irqsave(&remote->remote_lock, flags);
1160
1161 ret = kfifo_in(&remote->remote_fifo, &remote_data, sizeof(remote_data));
1162 if (ret != sizeof(remote_data)) {
1163 spin_unlock_irqrestore(&remote->remote_lock, flags);
1164 hid_err(wacom->hdev, "Can't queue Remote status event.\n");
1165 return;
1166 }
1167
1168 spin_unlock_irqrestore(&remote->remote_lock, flags);
1169
1170 wacom_schedule_work(wacom_wac, WACOM_WORKER_REMOTE);
1171}
1172
Jason Gereckeb1e42792012-10-21 00:38:04 -07001173static int int_dist(int x1, int y1, int x2, int y2)
1174{
1175 int x = x2 - x1;
1176 int y = y2 - y1;
1177
1178 return int_sqrt(x*x + y*y);
1179}
1180
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001181static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
1182 unsigned char *data)
1183{
1184 memcpy(wacom->data, data, 10);
1185 wacom_intuos_irq(wacom);
1186
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001187 input_sync(wacom->pen_input);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001188 if (wacom->pad_input)
1189 input_sync(wacom->pad_input);
1190}
1191
1192static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1193{
1194 unsigned char data[WACOM_PKGLEN_MAX];
1195 int i = 1;
1196 unsigned power_raw, battery_capacity, bat_charging, ps_connected;
1197
1198 memcpy(data, wacom->data, len);
1199
1200 switch (data[0]) {
1201 case 0x04:
1202 wacom_intuos_bt_process_data(wacom, data + i);
1203 i += 10;
1204 /* fall through */
1205 case 0x03:
1206 wacom_intuos_bt_process_data(wacom, data + i);
1207 i += 10;
1208 wacom_intuos_bt_process_data(wacom, data + i);
1209 i += 10;
1210 power_raw = data[i];
1211 bat_charging = (power_raw & 0x08) ? 1 : 0;
1212 ps_connected = (power_raw & 0x10) ? 1 : 0;
1213 battery_capacity = batcap_i4[power_raw & 0x07];
Jason Gerecke16e45982017-04-28 09:25:33 -07001214 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1215 battery_capacity, bat_charging,
Jason Gerecke71fa6412015-03-11 10:25:41 -07001216 battery_capacity || bat_charging,
Jason Gerecke953f2c52015-03-06 11:47:39 -08001217 ps_connected);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001218 break;
1219 default:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001220 dev_dbg(wacom->pen_input->dev.parent,
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001221 "Unknown report: %d,%d size:%zu\n",
1222 data[0], data[1], len);
1223 return 0;
1224 }
1225 return 0;
1226}
1227
Ping Cheng7d059ed2015-03-20 14:57:21 -07001228static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1229{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001230 struct input_dev *input = wacom->touch_input;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001231 unsigned touch_max = wacom->features.touch_max;
1232 int count = 0;
1233 int i;
1234
Ping Cheng26ba61f2015-05-19 17:42:02 -07001235 if (!touch_max)
1236 return 0;
1237
Jason Gerecke71b5c472015-04-15 17:22:32 -07001238 if (touch_max == 1)
1239 return test_bit(BTN_TOUCH, input->key) &&
Ping Cheng1924e052016-08-09 14:38:56 -07001240 report_touch_events(wacom);
Ping Cheng7d059ed2015-03-20 14:57:21 -07001241
1242 for (i = 0; i < input->mt->num_slots; i++) {
1243 struct input_mt_slot *ps = &input->mt->slots[i];
1244 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1245 if (id >= 0)
1246 count++;
1247 }
1248
1249 return count;
1250}
1251
Jason Gerecke4922cd22017-01-25 12:08:37 -08001252static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1253{
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001254 int pen_frame_len, pen_frames;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001255
1256 struct input_dev *pen_input = wacom->pen_input;
1257 unsigned char *data = wacom->data;
1258 int i;
1259
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07001260 if (wacom->features.type == INTUOSP2_BT ||
1261 wacom->features.type == INTUOSP2S_BT) {
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001262 wacom->serial[0] = get_unaligned_le64(&data[99]);
1263 wacom->id[0] = get_unaligned_le16(&data[107]);
1264 pen_frame_len = 14;
1265 pen_frames = 7;
1266 } else {
1267 wacom->serial[0] = get_unaligned_le64(&data[33]);
1268 wacom->id[0] = get_unaligned_le16(&data[41]);
1269 pen_frame_len = 8;
1270 pen_frames = 4;
1271 }
1272
Jason Gerecke4922cd22017-01-25 12:08:37 -08001273 if (wacom->serial[0] >> 52 == 1) {
1274 /* Add back in missing bits of ID for non-USI pens */
1275 wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
1276 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08001277
1278 for (i = 0; i < pen_frames; i++) {
1279 unsigned char *frame = &data[i*pen_frame_len + 1];
Jason Gereckea48324d2017-02-10 16:14:07 -08001280 bool valid = frame[0] & 0x80;
1281 bool prox = frame[0] & 0x40;
1282 bool range = frame[0] & 0x20;
Jason Gerecke2cc08802019-04-24 15:12:57 -07001283 bool invert = frame[0] & 0x10;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001284
Jason Gereckea48324d2017-02-10 16:14:07 -08001285 if (!valid)
Jason Gerecke4922cd22017-01-25 12:08:37 -08001286 continue;
1287
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -07001288 if (!prox) {
1289 wacom->shared->stylus_in_proximity = false;
1290 wacom_exit_report(wacom);
1291 input_sync(pen_input);
Jason Gerecke2cc08802019-04-24 15:12:57 -07001292
1293 wacom->tool[0] = 0;
1294 wacom->id[0] = 0;
1295 wacom->serial[0] = 0;
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -07001296 return;
1297 }
Jason Gerecke2cc08802019-04-24 15:12:57 -07001298
Jason Gereckea48324d2017-02-10 16:14:07 -08001299 if (range) {
Jason Gerecke2cc08802019-04-24 15:12:57 -07001300 if (!wacom->tool[0]) { /* first in range */
1301 /* Going into range select tool */
1302 if (invert)
1303 wacom->tool[0] = BTN_TOOL_RUBBER;
1304 else if (wacom->id[0])
1305 wacom->tool[0] = wacom_intuos_get_tool_type(wacom->id[0]);
1306 else
1307 wacom->tool[0] = BTN_TOOL_PEN;
1308 }
1309
Jason Gereckea48324d2017-02-10 16:14:07 -08001310 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
1311 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001312
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07001313 if (wacom->features.type == INTUOSP2_BT ||
1314 wacom->features.type == INTUOSP2S_BT) {
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001315 /* Fix rotation alignment: userspace expects zero at left */
1316 int16_t rotation =
1317 (int16_t)get_unaligned_le16(&frame[9]);
1318 rotation += 1800/4;
1319
1320 if (rotation > 899)
1321 rotation -= 1800;
1322
1323 input_report_abs(pen_input, ABS_TILT_X,
1324 (char)frame[7]);
1325 input_report_abs(pen_input, ABS_TILT_Y,
1326 (char)frame[8]);
1327 input_report_abs(pen_input, ABS_Z, rotation);
1328 input_report_abs(pen_input, ABS_WHEEL,
1329 get_unaligned_le16(&frame[11]));
1330 }
Jason Gereckea48324d2017-02-10 16:14:07 -08001331 }
Jason Gereckee92a7be2019-04-24 15:12:58 -07001332 if (wacom->tool[0]) {
1333 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
Aaron Armstrong Skomra7cdf6e42019-08-12 11:55:52 -07001334 if (wacom->features.type == INTUOSP2_BT ||
1335 wacom->features.type == INTUOSP2S_BT) {
Jason Gereckee92a7be2019-04-24 15:12:58 -07001336 input_report_abs(pen_input, ABS_DISTANCE,
1337 range ? frame[13] : wacom->features.distance_max);
1338 } else {
1339 input_report_abs(pen_input, ABS_DISTANCE,
1340 range ? frame[7] : wacom->features.distance_max);
1341 }
1342
Jason Gereckefe7f8d72019-05-07 11:53:20 -07001343 input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x09);
Jason Gereckee92a7be2019-04-24 15:12:58 -07001344 input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02);
1345 input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04);
1346
1347 input_report_key(pen_input, wacom->tool[0], prox);
1348 input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]);
1349 input_report_abs(pen_input, ABS_MISC,
1350 wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001351 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08001352
Jason Gereckea48324d2017-02-10 16:14:07 -08001353 wacom->shared->stylus_in_proximity = prox;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001354
1355 input_sync(pen_input);
1356 }
1357}
1358
1359static void wacom_intuos_pro2_bt_touch(struct wacom_wac *wacom)
1360{
1361 const int finger_touch_len = 8;
1362 const int finger_frames = 4;
1363 const int finger_frame_len = 43;
1364
1365 struct input_dev *touch_input = wacom->touch_input;
1366 unsigned char *data = wacom->data;
1367 int num_contacts_left = 5;
1368 int i, j;
1369
1370 for (i = 0; i < finger_frames; i++) {
1371 unsigned char *frame = &data[i*finger_frame_len + 109];
1372 int current_num_contacts = frame[0] & 0x7F;
1373 int contacts_to_send;
1374
1375 if (!(frame[0] & 0x80))
1376 continue;
1377
1378 /*
1379 * First packet resets the counter since only the first
1380 * packet in series will have non-zero current_num_contacts.
1381 */
1382 if (current_num_contacts)
1383 wacom->num_contacts_left = current_num_contacts;
1384
1385 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1386
1387 for (j = 0; j < contacts_to_send; j++) {
1388 unsigned char *touch = &frame[j*finger_touch_len + 1];
1389 int slot = input_mt_get_slot_by_key(touch_input, touch[0]);
1390 int x = get_unaligned_le16(&touch[2]);
1391 int y = get_unaligned_le16(&touch[4]);
1392 int w = touch[6] * input_abs_get_res(touch_input, ABS_MT_POSITION_X);
1393 int h = touch[7] * input_abs_get_res(touch_input, ABS_MT_POSITION_Y);
1394
1395 if (slot < 0)
1396 continue;
1397
1398 input_mt_slot(touch_input, slot);
1399 input_mt_report_slot_state(touch_input, MT_TOOL_FINGER, touch[1] & 0x01);
1400 input_report_abs(touch_input, ABS_MT_POSITION_X, x);
1401 input_report_abs(touch_input, ABS_MT_POSITION_Y, y);
1402 input_report_abs(touch_input, ABS_MT_TOUCH_MAJOR, max(w, h));
1403 input_report_abs(touch_input, ABS_MT_TOUCH_MINOR, min(w, h));
1404 input_report_abs(touch_input, ABS_MT_ORIENTATION, w > h);
1405 }
1406
1407 input_mt_sync_frame(touch_input);
1408
1409 wacom->num_contacts_left -= contacts_to_send;
1410 if (wacom->num_contacts_left <= 0) {
1411 wacom->num_contacts_left = 0;
1412 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Jason Gerecke69dbdff2019-05-07 11:53:22 -07001413 input_sync(touch_input);
Jason Gerecke4922cd22017-01-25 12:08:37 -08001414 }
1415 }
1416
Jason Gerecke69dbdff2019-05-07 11:53:22 -07001417 if (wacom->num_contacts_left == 0) {
1418 // Be careful that we don't accidentally call input_sync with
1419 // only a partial set of fingers of processed
1420 input_report_switch(touch_input, SW_MUTE_DEVICE, !(data[281] >> 7));
1421 input_sync(touch_input);
1422 }
1423
Jason Gerecke4922cd22017-01-25 12:08:37 -08001424}
1425
1426static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
1427{
1428 struct input_dev *pad_input = wacom->pad_input;
1429 unsigned char *data = wacom->data;
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001430 int nbuttons = wacom->features.numbered_buttons;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001431
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001432 int expresskeys = data[282];
1433 int center = (data[281] & 0x40) >> 6;
Jason Gerecked252f4a2017-08-30 15:13:26 -07001434 int ring = data[285] & 0x7F;
1435 bool ringstatus = data[285] & 0x80;
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001436 bool prox = expresskeys || center || ringstatus;
Jason Gerecked252f4a2017-08-30 15:13:26 -07001437
1438 /* Fix touchring data: userspace expects 0 at left and increasing clockwise */
1439 ring = 71 - ring;
1440 ring += 3*72/16;
1441 if (ring > 71)
1442 ring -= 72;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001443
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001444 wacom_report_numbered_buttons(pad_input, nbuttons,
1445 expresskeys | (center << (nbuttons - 1)));
Jason Gerecke4922cd22017-01-25 12:08:37 -08001446
Jason Gerecked252f4a2017-08-30 15:13:26 -07001447 input_report_abs(pad_input, ABS_WHEEL, ringstatus ? ring : 0);
Jason Gerecke4922cd22017-01-25 12:08:37 -08001448
1449 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
1450 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
1451 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1452
1453 input_sync(pad_input);
1454}
1455
1456static void wacom_intuos_pro2_bt_battery(struct wacom_wac *wacom)
1457{
1458 unsigned char *data = wacom->data;
1459
1460 bool chg = data[284] & 0x80;
1461 int battery_status = data[284] & 0x7F;
1462
Jason Gerecke16e45982017-04-28 09:25:33 -07001463 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1464 battery_status, chg, 1, chg);
Jason Gerecke4922cd22017-01-25 12:08:37 -08001465}
1466
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001467static void wacom_intuos_gen3_bt_pad(struct wacom_wac *wacom)
1468{
1469 struct input_dev *pad_input = wacom->pad_input;
1470 unsigned char *data = wacom->data;
1471
1472 int buttons = data[44];
1473
1474 wacom_report_numbered_buttons(pad_input, 4, buttons);
1475
1476 input_report_key(pad_input, wacom->tool[1], buttons ? 1 : 0);
1477 input_report_abs(pad_input, ABS_MISC, buttons ? PAD_DEVICE_ID : 0);
1478 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1479
1480 input_sync(pad_input);
1481}
1482
1483static void wacom_intuos_gen3_bt_battery(struct wacom_wac *wacom)
1484{
1485 unsigned char *data = wacom->data;
1486
1487 bool chg = data[45] & 0x80;
1488 int battery_status = data[45] & 0x7F;
1489
1490 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1491 battery_status, chg, 1, chg);
1492}
1493
Jason Gerecke4922cd22017-01-25 12:08:37 -08001494static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
1495{
1496 unsigned char *data = wacom->data;
1497
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001498 if (data[0] != 0x80 && data[0] != 0x81) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08001499 dev_dbg(wacom->pen_input->dev.parent,
1500 "%s: received unknown report #%d\n", __func__, data[0]);
1501 return 0;
1502 }
1503
1504 wacom_intuos_pro2_bt_pen(wacom);
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07001505 if (wacom->features.type == INTUOSP2_BT ||
1506 wacom->features.type == INTUOSP2S_BT) {
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001507 wacom_intuos_pro2_bt_touch(wacom);
1508 wacom_intuos_pro2_bt_pad(wacom);
1509 wacom_intuos_pro2_bt_battery(wacom);
1510 } else {
1511 wacom_intuos_gen3_bt_pad(wacom);
1512 wacom_intuos_gen3_bt_battery(wacom);
1513 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08001514 return 0;
1515}
1516
Jason Gereckeb1e42792012-10-21 00:38:04 -07001517static int wacom_24hdt_irq(struct wacom_wac *wacom)
1518{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001519 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001520 unsigned char *data = wacom->data;
Jason Gereckeb1e42792012-10-21 00:38:04 -07001521 int i;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001522 int current_num_contacts = data[61];
Jason Gereckeb1e42792012-10-21 00:38:04 -07001523 int contacts_to_send = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001524 int num_contacts_left = 4; /* maximum contacts per packet */
1525 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1526 int y_offset = 2;
1527
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07001528 if (wacom->shared->has_mute_touch_switch &&
1529 !wacom->shared->is_touch_on) {
1530 if (!wacom->shared->touch_down)
1531 return 0;
1532 }
1533
Ping Cheng500d4162015-01-27 13:30:03 -08001534 if (wacom->features.type == WACOM_27QHDT) {
1535 current_num_contacts = data[63];
1536 num_contacts_left = 10;
1537 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1538 y_offset = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001539 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001540
1541 /*
1542 * First packet resets the counter since only the first
1543 * packet in series will have non-zero current_num_contacts.
1544 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001545 if (current_num_contacts)
Jason Gereckeb1e42792012-10-21 00:38:04 -07001546 wacom->num_contacts_left = current_num_contacts;
1547
Ping Cheng500d4162015-01-27 13:30:03 -08001548 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001549
1550 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng500d4162015-01-27 13:30:03 -08001551 int offset = (byte_per_packet * i) + 1;
Ping Cheng1924e052016-08-09 14:38:56 -07001552 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Ping Cheng02295e62013-01-04 23:56:00 -08001553 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001554
1555 if (slot < 0)
1556 continue;
1557 input_mt_slot(input, slot);
1558 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1559
1560 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001561 int t_x = get_unaligned_le16(&data[offset + 2]);
Ping Cheng500d4162015-01-27 13:30:03 -08001562 int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001563
1564 input_report_abs(input, ABS_MT_POSITION_X, t_x);
1565 input_report_abs(input, ABS_MT_POSITION_Y, t_y);
Ping Cheng500d4162015-01-27 13:30:03 -08001566
1567 if (wacom->features.type != WACOM_27QHDT) {
1568 int c_x = get_unaligned_le16(&data[offset + 4]);
1569 int c_y = get_unaligned_le16(&data[offset + 8]);
1570 int w = get_unaligned_le16(&data[offset + 10]);
1571 int h = get_unaligned_le16(&data[offset + 12]);
1572
1573 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1574 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1575 min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1576 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1577 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1578 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001579 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001580 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001581 input_mt_sync_frame(input);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001582
1583 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001584 if (wacom->num_contacts_left <= 0) {
Jason Gereckeb1e42792012-10-21 00:38:04 -07001585 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001586 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001587 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001588 return 1;
1589}
1590
Ping Cheng19635182012-04-29 21:09:18 -07001591static int wacom_mt_touch(struct wacom_wac *wacom)
1592{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001593 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001594 unsigned char *data = wacom->data;
Ping Cheng19635182012-04-29 21:09:18 -07001595 int i;
1596 int current_num_contacts = data[2];
1597 int contacts_to_send = 0;
Ping Cheng6afdc282012-11-03 12:16:15 -07001598 int x_offset = 0;
1599
1600 /* MTTPC does not support Height and Width */
Jason Gerecked51ddb22014-05-14 17:14:29 -07001601 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
Ping Cheng6afdc282012-11-03 12:16:15 -07001602 x_offset = -4;
Ping Cheng19635182012-04-29 21:09:18 -07001603
1604 /*
1605 * First packet resets the counter since only the first
1606 * packet in series will have non-zero current_num_contacts.
1607 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001608 if (current_num_contacts)
Ping Cheng19635182012-04-29 21:09:18 -07001609 wacom->num_contacts_left = current_num_contacts;
1610
1611 /* There are at most 5 contacts per packet */
1612 contacts_to_send = min(5, wacom->num_contacts_left);
1613
1614 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng6afdc282012-11-03 12:16:15 -07001615 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
Ping Cheng1924e052016-08-09 14:38:56 -07001616 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001617 int id = get_unaligned_le16(&data[offset + 1]);
Ping Cheng02295e62013-01-04 23:56:00 -08001618 int slot = input_mt_get_slot_by_key(input, id);
Ping Cheng19635182012-04-29 21:09:18 -07001619
1620 if (slot < 0)
1621 continue;
1622
1623 input_mt_slot(input, slot);
1624 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1625 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001626 int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1627 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
Ping Cheng19635182012-04-29 21:09:18 -07001628 input_report_abs(input, ABS_MT_POSITION_X, x);
1629 input_report_abs(input, ABS_MT_POSITION_Y, y);
1630 }
Ping Cheng19635182012-04-29 21:09:18 -07001631 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001632 input_mt_sync_frame(input);
Ping Cheng19635182012-04-29 21:09:18 -07001633
1634 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001635 if (wacom->num_contacts_left <= 0) {
Ping Cheng19635182012-04-29 21:09:18 -07001636 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001637 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001638 }
Ping Cheng19635182012-04-29 21:09:18 -07001639 return 1;
1640}
1641
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001642static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1643{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001644 struct input_dev *input = wacom->touch_input;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001645 unsigned char *data = wacom->data;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001646 int i;
1647
1648 for (i = 0; i < 2; i++) {
1649 int p = data[1] & (1 << i);
Ping Cheng1924e052016-08-09 14:38:56 -07001650 bool touch = p && report_touch_events(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001651
1652 input_mt_slot(input, i);
1653 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1654 if (touch) {
1655 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1656 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1657
1658 input_report_abs(input, ABS_MT_POSITION_X, x);
1659 input_report_abs(input, ABS_MT_POSITION_Y, y);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001660 }
1661 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001662 input_mt_sync_frame(input);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001663
1664 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001665 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001666
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001667 return 1;
1668}
1669
Ping Chenga43c7c52011-03-12 20:34:42 -08001670static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
Ping Chengec67bbe2009-12-15 00:35:24 -08001671{
Jason Gerecke74b63412014-04-19 13:50:22 -07001672 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001673 struct input_dev *input = wacom->touch_input;
Ping Cheng1924e052016-08-09 14:38:56 -07001674 bool prox = report_touch_events(wacom);
Ping Chenga43c7c52011-03-12 20:34:42 -08001675 int x = 0, y = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -08001676
Ping Cheng19635182012-04-29 21:09:18 -07001677 if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1678 return 0;
1679
Ping Chenge0d41fd2015-02-20 14:27:30 -08001680 if (len == WACOM_PKGLEN_TPC1FG) {
1681 prox = prox && (data[0] & 0x01);
1682 x = get_unaligned_le16(&data[1]);
1683 y = get_unaligned_le16(&data[3]);
1684 } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1685 prox = prox && (data[2] & 0x01);
1686 x = get_unaligned_le16(&data[3]);
1687 y = get_unaligned_le16(&data[5]);
1688 } else {
1689 prox = prox && (data[1] & 0x01);
1690 x = le16_to_cpup((__le16 *)&data[2]);
1691 y = le16_to_cpup((__le16 *)&data[4]);
1692 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001693
1694 if (prox) {
1695 input_report_abs(input, ABS_X, x);
1696 input_report_abs(input, ABS_Y, y);
Ping Chengec67bbe2009-12-15 00:35:24 -08001697 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001698 input_report_key(input, BTN_TOUCH, prox);
1699
1700 /* keep touch state for pen events */
1701 wacom->shared->touch_down = prox;
1702
1703 return 1;
Ping Chengec67bbe2009-12-15 00:35:24 -08001704}
1705
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001706static int wacom_tpc_pen(struct wacom_wac *wacom)
Ping Cheng545f4e92008-11-24 11:44:27 -05001707{
Jason Gerecke74b63412014-04-19 13:50:22 -07001708 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001709 struct input_dev *input = wacom->pen_input;
Ping Chenga43c7c52011-03-12 20:34:42 -08001710 bool prox = data[1] & 0x20;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001711
Ping Chenga43c7c52011-03-12 20:34:42 -08001712 if (!wacom->shared->stylus_in_proximity) /* first in prox */
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001713 /* Going into proximity select tool */
1714 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001715
Ping Chenga43c7c52011-03-12 20:34:42 -08001716 /* keep pen state for touch events */
1717 wacom->shared->stylus_in_proximity = prox;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001718
Ping Cheng1924e052016-08-09 14:38:56 -07001719 /* send pen events only when touch is up or forced out
1720 * or touch arbitration is off
1721 */
1722 if (!delay_pen_events(wacom)) {
Ping Chenga43c7c52011-03-12 20:34:42 -08001723 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1724 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1725 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1726 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke0b335ca2014-07-24 13:15:31 -07001727 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
Ping Chenga43c7c52011-03-12 20:34:42 -08001728 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1729 input_report_key(input, wacom->tool[0], prox);
1730 return 1;
1731 }
1732
1733 return 0;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001734}
1735
1736static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1737{
Jason Gerecke74b63412014-04-19 13:50:22 -07001738 unsigned char *data = wacom->data;
Ping Cheng545f4e92008-11-24 11:44:27 -05001739
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001740 if (wacom->pen_input) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001741 dev_dbg(wacom->pen_input->dev.parent,
1742 "%s: received report #%d\n", __func__, data[0]);
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001743
1744 if (len == WACOM_PKGLEN_PENABLED ||
1745 data[0] == WACOM_REPORT_PENABLED)
1746 return wacom_tpc_pen(wacom);
1747 }
1748 else if (wacom->touch_input) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001749 dev_dbg(wacom->touch_input->dev.parent,
1750 "%s: received report #%d\n", __func__, data[0]);
Ping Cheng545f4e92008-11-24 11:44:27 -05001751
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001752 switch (len) {
1753 case WACOM_PKGLEN_TPC1FG:
Ping Cheng31175a82012-01-31 00:07:33 -08001754 return wacom_tpc_single_touch(wacom, len);
1755
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001756 case WACOM_PKGLEN_TPC2FG:
1757 return wacom_tpc_mt_touch(wacom);
Ping Cheng19635182012-04-29 21:09:18 -07001758
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001759 default:
1760 switch (data[0]) {
1761 case WACOM_REPORT_TPC1FG:
1762 case WACOM_REPORT_TPCHID:
1763 case WACOM_REPORT_TPCST:
1764 case WACOM_REPORT_TPC1FGE:
1765 return wacom_tpc_single_touch(wacom, len);
1766
1767 case WACOM_REPORT_TPCMT:
1768 case WACOM_REPORT_TPCMT2:
1769 return wacom_mt_touch(wacom);
1770
1771 }
Ping Cheng31175a82012-01-31 00:07:33 -08001772 }
1773 }
Ping Cheng545f4e92008-11-24 11:44:27 -05001774
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001775 return 0;
Ping Cheng545f4e92008-11-24 11:44:27 -05001776}
1777
Jason Gerecked252f4a2017-08-30 15:13:26 -07001778static int wacom_offset_rotation(struct input_dev *input, struct hid_usage *usage,
1779 int value, int num, int denom)
1780{
1781 struct input_absinfo *abs = &input->absinfo[usage->code];
1782 int range = (abs->maximum - abs->minimum + 1);
1783
1784 value += num*range/denom;
1785 if (value > abs->maximum)
1786 value -= range;
1787 else if (value < abs->minimum)
1788 value += range;
1789 return value;
1790}
1791
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08001792int wacom_equivalent_usage(int usage)
Jason Gereckec9c09582016-10-19 18:03:43 -07001793{
1794 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1795 int subpage = (usage & 0xFF00) << 8;
1796 int subusage = (usage & 0xFF);
1797
Jason Gerecke5922e612016-10-19 18:03:51 -07001798 if (subpage == WACOM_HID_SP_PAD ||
1799 subpage == WACOM_HID_SP_BUTTON ||
1800 subpage == WACOM_HID_SP_DIGITIZER ||
Jason Gereckeb5c921e2016-10-19 18:03:44 -07001801 subpage == WACOM_HID_SP_DIGITIZERINFO ||
Jason Gerecke61ce3462016-10-19 18:03:46 -07001802 usage == WACOM_HID_WD_SENSE ||
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001803 usage == WACOM_HID_WD_SERIALHI ||
1804 usage == WACOM_HID_WD_TOOLTYPE ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001805 usage == WACOM_HID_WD_DISTANCE ||
Jason Gereckebf78adc2016-10-19 18:03:53 -07001806 usage == WACOM_HID_WD_TOUCHSTRIP ||
1807 usage == WACOM_HID_WD_TOUCHSTRIP2 ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001808 usage == WACOM_HID_WD_TOUCHRING ||
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08001809 usage == WACOM_HID_WD_TOUCHRINGSTATUS ||
1810 usage == WACOM_HID_WD_REPORT_VALID) {
Jason Gereckec9c09582016-10-19 18:03:43 -07001811 return usage;
1812 }
1813
1814 if (subpage == HID_UP_UNDEFINED)
1815 subpage = HID_UP_DIGITIZER;
1816
1817 return subpage | subusage;
1818 }
1819
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08001820 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMTOUCH) {
1821 int subpage = (usage & 0xFF00) << 8;
1822 int subusage = (usage & 0xFF);
1823
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07001824 if (usage == WACOM_HID_WT_REPORT_VALID)
1825 return usage;
1826
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08001827 if (subpage == HID_UP_UNDEFINED)
1828 subpage = WACOM_HID_SP_DIGITIZER;
1829
1830 return subpage | subusage;
1831 }
1832
Jason Gereckec9c09582016-10-19 18:03:43 -07001833 return usage;
1834}
1835
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001836static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001837 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1838{
Jason Gerecke345857b2016-10-19 18:03:50 -07001839 struct wacom *wacom = input_get_drvdata(input);
1840 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1841 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001842 int fmin = field->logical_minimum;
1843 int fmax = field->logical_maximum;
Jason Gereckec9c09582016-10-19 18:03:43 -07001844 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
Jason Gerecke50066a02016-10-19 18:03:42 -07001845 int resolution_code = code;
1846
Jason Gereckec9c09582016-10-19 18:03:43 -07001847 if (equivalent_usage == HID_DG_TWIST) {
Jason Gerecke50066a02016-10-19 18:03:42 -07001848 resolution_code = ABS_RZ;
1849 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001850
Jason Gerecke345857b2016-10-19 18:03:50 -07001851 if (equivalent_usage == HID_GD_X) {
1852 fmin += features->offset_left;
1853 fmax -= features->offset_right;
1854 }
1855 if (equivalent_usage == HID_GD_Y) {
1856 fmin += features->offset_top;
1857 fmax -= features->offset_bottom;
1858 }
1859
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001860 usage->type = type;
1861 usage->code = code;
1862
1863 set_bit(type, input->evbit);
1864
1865 switch (type) {
1866 case EV_ABS:
1867 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1868 input_abs_set_res(input, code,
Jason Gerecke50066a02016-10-19 18:03:42 -07001869 hidinput_calc_abs_res(field, resolution_code));
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001870 break;
1871 case EV_KEY:
1872 input_set_capability(input, EV_KEY, code);
1873 break;
1874 case EV_MSC:
1875 input_set_capability(input, EV_MSC, code);
1876 break;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001877 case EV_SW:
1878 input_set_capability(input, EV_SW, code);
1879 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001880 }
1881}
1882
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07001883static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
1884 struct hid_field *field, struct hid_usage *usage)
1885{
1886 struct wacom *wacom = hid_get_drvdata(hdev);
1887 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1888 struct wacom_features *features = &wacom_wac->features;
1889 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1890
1891 switch (equivalent_usage) {
1892 case HID_DG_BATTERYSTRENGTH:
1893 case WACOM_HID_WD_BATTERY_LEVEL:
1894 case WACOM_HID_WD_BATTERY_CHARGING:
1895 features->quirks |= WACOM_QUIRK_BATTERY;
1896 break;
1897 }
1898}
1899
1900static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
1901 struct hid_usage *usage, __s32 value)
1902{
1903 struct wacom *wacom = hid_get_drvdata(hdev);
1904 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1905 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1906
1907 switch (equivalent_usage) {
1908 case HID_DG_BATTERYSTRENGTH:
1909 if (value == 0) {
1910 wacom_wac->hid_data.bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
1911 }
1912 else {
1913 value = value * 100 / (field->logical_maximum - field->logical_minimum);
1914 wacom_wac->hid_data.battery_capacity = value;
1915 wacom_wac->hid_data.bat_connected = 1;
1916 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1917 }
1918 break;
1919 case WACOM_HID_WD_BATTERY_LEVEL:
1920 value = value * 100 / (field->logical_maximum - field->logical_minimum);
1921 wacom_wac->hid_data.battery_capacity = value;
1922 wacom_wac->hid_data.bat_connected = 1;
1923 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1924 break;
1925 case WACOM_HID_WD_BATTERY_CHARGING:
1926 wacom_wac->hid_data.bat_charging = value;
1927 wacom_wac->hid_data.ps_connected = value;
1928 wacom_wac->hid_data.bat_connected = 1;
1929 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1930 break;
1931 }
1932}
1933
1934static void wacom_wac_battery_pre_report(struct hid_device *hdev,
1935 struct hid_report *report)
1936{
1937 return;
1938}
1939
1940static void wacom_wac_battery_report(struct hid_device *hdev,
1941 struct hid_report *report)
1942{
1943 struct wacom *wacom = hid_get_drvdata(hdev);
1944 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1945 struct wacom_features *features = &wacom_wac->features;
1946
1947 if (features->quirks & WACOM_QUIRK_BATTERY) {
1948 int status = wacom_wac->hid_data.bat_status;
1949 int capacity = wacom_wac->hid_data.battery_capacity;
1950 bool charging = wacom_wac->hid_data.bat_charging;
1951 bool connected = wacom_wac->hid_data.bat_connected;
1952 bool powered = wacom_wac->hid_data.ps_connected;
1953
1954 wacom_notify_battery(wacom_wac, status, capacity, charging,
1955 connected, powered);
1956 }
1957}
1958
Jason Gerecke5922e612016-10-19 18:03:51 -07001959static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1960 struct hid_field *field, struct hid_usage *usage)
1961{
1962 struct wacom *wacom = hid_get_drvdata(hdev);
1963 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1964 struct wacom_features *features = &wacom_wac->features;
1965 struct input_dev *input = wacom_wac->pad_input;
1966 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1967
1968 switch (equivalent_usage) {
1969 case WACOM_HID_WD_ACCELEROMETER_X:
1970 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1971 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001972 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001973 break;
1974 case WACOM_HID_WD_ACCELEROMETER_Y:
1975 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1976 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001977 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001978 break;
1979 case WACOM_HID_WD_ACCELEROMETER_Z:
1980 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1981 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001982 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001983 break;
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08001984 case WACOM_HID_WD_BUTTONCENTER:
Jason Gerecke5922e612016-10-19 18:03:51 -07001985 case WACOM_HID_WD_BUTTONHOME:
1986 case WACOM_HID_WD_BUTTONUP:
1987 case WACOM_HID_WD_BUTTONDOWN:
1988 case WACOM_HID_WD_BUTTONLEFT:
1989 case WACOM_HID_WD_BUTTONRIGHT:
1990 wacom_map_usage(input, usage, field, EV_KEY,
1991 wacom_numbered_button_to_key(features->numbered_buttons),
1992 0);
1993 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08001994 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001995 break;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001996 case WACOM_HID_WD_TOUCHONOFF:
Ping Chengd793ff82017-02-14 21:27:45 -08001997 case WACOM_HID_WD_MUTE_DEVICE:
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08001998 /*
1999 * This usage, which is used to mute touch events, comes
2000 * from the pad packet, but is reported on the touch
2001 * interface. Because the touch interface may not have
2002 * been created yet, we cannot call wacom_map_usage(). In
2003 * order to process this usage when we receive it, we set
2004 * the usage type and code directly.
2005 */
2006 wacom_wac->has_mute_touch_switch = true;
2007 usage->type = EV_SW;
2008 usage->code = SW_MUTE_DEVICE;
Ping Chengf3f24e72016-12-08 22:05:44 -08002009 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07002010 break;
2011 case WACOM_HID_WD_TOUCHSTRIP:
2012 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08002013 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07002014 break;
2015 case WACOM_HID_WD_TOUCHSTRIP2:
2016 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08002017 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07002018 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07002019 case WACOM_HID_WD_TOUCHRING:
2020 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08002021 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07002022 break;
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002023 case WACOM_HID_WD_TOUCHRINGSTATUS:
Jason Gerecke8d411cb2017-08-04 15:35:14 -07002024 /*
2025 * Only set up type/code association. Completely mapping
2026 * this usage may overwrite the axis resolution and range.
2027 */
2028 usage->type = EV_ABS;
2029 usage->code = ABS_WHEEL;
2030 set_bit(EV_ABS, input->evbit);
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002031 features->device_type |= WACOM_DEVICETYPE_PAD;
2032 break;
Ping Cheng4eb220c2017-02-14 21:26:21 -08002033 case WACOM_HID_WD_BUTTONCONFIG:
2034 wacom_map_usage(input, usage, field, EV_KEY, KEY_BUTTONCONFIG, 0);
2035 features->device_type |= WACOM_DEVICETYPE_PAD;
2036 break;
2037 case WACOM_HID_WD_ONSCREEN_KEYBOARD:
2038 wacom_map_usage(input, usage, field, EV_KEY, KEY_ONSCREEN_KEYBOARD, 0);
2039 features->device_type |= WACOM_DEVICETYPE_PAD;
2040 break;
2041 case WACOM_HID_WD_CONTROLPANEL:
2042 wacom_map_usage(input, usage, field, EV_KEY, KEY_CONTROLPANEL, 0);
2043 features->device_type |= WACOM_DEVICETYPE_PAD;
2044 break;
Benjamin Tissoires4082da82017-02-14 21:27:18 -08002045 case WACOM_HID_WD_MODE_CHANGE:
2046 /* do not overwrite previous data */
2047 if (!wacom_wac->has_mode_change) {
2048 wacom_wac->has_mode_change = true;
2049 wacom_wac->is_direct_mode = true;
2050 }
2051 features->device_type |= WACOM_DEVICETYPE_PAD;
2052 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07002053 }
2054
2055 switch (equivalent_usage & 0xfffffff0) {
2056 case WACOM_HID_WD_EXPRESSKEY00:
2057 wacom_map_usage(input, usage, field, EV_KEY,
2058 wacom_numbered_button_to_key(features->numbered_buttons),
2059 0);
2060 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08002061 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07002062 break;
2063 }
2064}
2065
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002066static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
2067 struct hid_usage *usage, __s32 value)
2068{
2069 struct wacom *wacom = hid_get_drvdata(hdev);
2070 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2071 struct input_dev *input = wacom_wac->pad_input;
2072 struct wacom_features *features = &wacom_wac->features;
2073 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08002074 int i;
Jason Gerecked252f4a2017-08-30 15:13:26 -07002075 bool do_report = false;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002076
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002077 /*
2078 * Avoid reporting this event and setting inrange_state if this usage
2079 * hasn't been mapped.
2080 */
Benjamin Tissoires4082da82017-02-14 21:27:18 -08002081 if (!usage->type && equivalent_usage != WACOM_HID_WD_MODE_CHANGE)
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002082 return;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002083
2084 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002085 if (usage->hid != WACOM_HID_WD_TOUCHRING)
2086 wacom_wac->hid_data.inrange_state |= value;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002087 }
2088
2089 switch (equivalent_usage) {
Jason Gerecked252f4a2017-08-30 15:13:26 -07002090 case WACOM_HID_WD_TOUCHRING:
2091 /*
2092 * Userspace expects touchrings to increase in value with
2093 * clockwise gestures and have their zero point at the
2094 * tablet's left. HID events "should" be clockwise-
2095 * increasing and zero at top, though the MobileStudio
2096 * Pro and 2nd-gen Intuos Pro don't do this...
2097 */
2098 if (hdev->vendor == 0x56a &&
2099 (hdev->product == 0x34d || hdev->product == 0x34e || /* MobileStudio Pro */
Ping Cheng384225c2019-06-23 16:52:43 -07002100 hdev->product == 0x357 || hdev->product == 0x358 || /* Intuos Pro 2 */
Aaron Armstrong Skomra6e2abc62019-06-26 15:48:48 -07002101 hdev->product == 0x392 || /* Intuos Pro 2 */
Jason Gereckefe4e9402019-12-16 10:18:57 -08002102 hdev->product == 0x398 || hdev->product == 0x399 || /* MobileStudio Pro */
2103 hdev->product == 0x3AA)) { /* MobileStudio Pro */
Jason Gerecked252f4a2017-08-30 15:13:26 -07002104 value = (field->logical_maximum - value);
2105
Aaron Armstrong Skomra6e2abc62019-06-26 15:48:48 -07002106 if (hdev->product == 0x357 || hdev->product == 0x358 ||
2107 hdev->product == 0x392)
Jason Gerecked252f4a2017-08-30 15:13:26 -07002108 value = wacom_offset_rotation(input, usage, value, 3, 16);
Ping Cheng384225c2019-06-23 16:52:43 -07002109 else if (hdev->product == 0x34d || hdev->product == 0x34e ||
Jason Gereckefe4e9402019-12-16 10:18:57 -08002110 hdev->product == 0x398 || hdev->product == 0x399 ||
2111 hdev->product == 0x3AA)
Jason Gerecked252f4a2017-08-30 15:13:26 -07002112 value = wacom_offset_rotation(input, usage, value, 1, 2);
2113 }
2114 else {
2115 value = wacom_offset_rotation(input, usage, value, 1, 4);
2116 }
2117 do_report = true;
2118 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002119 case WACOM_HID_WD_TOUCHRINGSTATUS:
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002120 if (!value)
2121 input_event(input, usage->type, usage->code, 0);
Ping Cheng354a3292016-12-08 22:03:27 -08002122 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002123
Ping Chengd793ff82017-02-14 21:27:45 -08002124 case WACOM_HID_WD_MUTE_DEVICE:
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002125 case WACOM_HID_WD_TOUCHONOFF:
2126 if (wacom_wac->shared->touch_input) {
Jason Gerecke403c0f62017-12-26 14:53:55 -08002127 bool *is_touch_on = &wacom_wac->shared->is_touch_on;
2128
2129 if (equivalent_usage == WACOM_HID_WD_MUTE_DEVICE && value)
2130 *is_touch_on = !(*is_touch_on);
2131 else if (equivalent_usage == WACOM_HID_WD_TOUCHONOFF)
2132 *is_touch_on = value;
2133
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002134 input_report_switch(wacom_wac->shared->touch_input,
Jason Gerecke403c0f62017-12-26 14:53:55 -08002135 SW_MUTE_DEVICE, !(*is_touch_on));
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002136 input_sync(wacom_wac->shared->touch_input);
2137 }
2138 break;
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08002139
Benjamin Tissoires4082da82017-02-14 21:27:18 -08002140 case WACOM_HID_WD_MODE_CHANGE:
2141 if (wacom_wac->is_direct_mode != value) {
2142 wacom_wac->is_direct_mode = value;
2143 wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_MODE_CHANGE);
2144 }
2145 break;
2146
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08002147 case WACOM_HID_WD_BUTTONCENTER:
2148 for (i = 0; i < wacom->led.count; i++)
2149 wacom_update_led(wacom, features->numbered_buttons,
2150 value, i);
2151 /* fall through*/
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002152 default:
Jason Gerecked252f4a2017-08-30 15:13:26 -07002153 do_report = true;
2154 break;
2155 }
2156
2157 if (do_report) {
Jason Gerecke5922e612016-10-19 18:03:51 -07002158 input_event(input, usage->type, usage->code, value);
Ping Chenged1fa732017-04-04 12:31:07 -07002159 if (value)
2160 wacom_wac->hid_data.pad_input_event_flag = true;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002161 }
Jason Gerecke5922e612016-10-19 18:03:51 -07002162}
2163
2164static void wacom_wac_pad_pre_report(struct hid_device *hdev,
2165 struct hid_report *report)
2166{
2167 struct wacom *wacom = hid_get_drvdata(hdev);
2168 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2169
2170 wacom_wac->hid_data.inrange_state = 0;
2171}
2172
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002173static void wacom_wac_pad_report(struct hid_device *hdev,
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002174 struct hid_report *report, struct hid_field *field)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002175{
2176 struct wacom *wacom = hid_get_drvdata(hdev);
2177 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002178 struct input_dev *input = wacom_wac->pad_input;
2179 bool active = wacom_wac->hid_data.inrange_state != 0;
2180
2181 /* report prox for expresskey events */
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002182 if (wacom_wac->hid_data.pad_input_event_flag) {
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002183 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002184 input_sync(input);
Ping Chenged1fa732017-04-04 12:31:07 -07002185 if (!active)
2186 wacom_wac->hid_data.pad_input_event_flag = false;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002187 }
Jason Gerecke5922e612016-10-19 18:03:51 -07002188}
2189
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002190static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
2191 struct hid_field *field, struct hid_usage *usage)
2192{
2193 struct wacom *wacom = hid_get_drvdata(hdev);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002194 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002195 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002196 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07002197 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002198
Jason Gereckec9c09582016-10-19 18:03:43 -07002199 switch (equivalent_usage) {
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002200 case HID_GD_X:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002201 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002202 break;
2203 case HID_GD_Y:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002204 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002205 break;
Jason Gereckeb5c921e2016-10-19 18:03:44 -07002206 case WACOM_HID_WD_DISTANCE:
Jason Gerecke50066a02016-10-19 18:03:42 -07002207 case HID_GD_Z:
2208 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
2209 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002210 case HID_DG_TIPPRESSURE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002211 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002212 break;
2213 case HID_DG_INRANGE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002214 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002215 break;
2216 case HID_DG_INVERT:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002217 wacom_map_usage(input, usage, field, EV_KEY,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002218 BTN_TOOL_RUBBER, 0);
2219 break;
Jason Gerecke50066a02016-10-19 18:03:42 -07002220 case HID_DG_TILT_X:
2221 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
2222 break;
2223 case HID_DG_TILT_Y:
2224 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
2225 break;
2226 case HID_DG_TWIST:
2227 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
2228 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002229 case HID_DG_ERASER:
2230 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002231 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002232 break;
2233 case HID_DG_BARRELSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002234 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002235 break;
2236 case HID_DG_BARRELSWITCH2:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002237 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002238 break;
2239 case HID_DG_TOOLSERIALNUMBER:
Jason Gerecke83417202017-11-10 11:50:01 -08002240 features->quirks |= WACOM_QUIRK_TOOLSERIAL;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002241 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002242 break;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002243 case WACOM_HID_WD_SENSE:
2244 features->quirks |= WACOM_QUIRK_SENSE;
2245 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
2246 break;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002247 case WACOM_HID_WD_SERIALHI:
2248 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
Jason Gerecke99aceda2017-11-10 11:50:00 -08002249
2250 if (!(features->quirks & WACOM_QUIRK_AESPEN)) {
2251 set_bit(EV_KEY, input->evbit);
2252 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
2253 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
2254 input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
2255 input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
2256 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
2257 if (!(features->device_type & WACOM_DEVICETYPE_DIRECT)) {
2258 input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
2259 input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
2260 }
Ping Cheng6e5364f2017-03-14 17:08:16 -07002261 }
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002262 break;
Jason Gerecke929d6d52016-10-19 18:03:45 -07002263 case WACOM_HID_WD_FINGERWHEEL:
2264 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2265 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002266 }
2267}
2268
Ping Cheng354a3292016-12-08 22:03:27 -08002269static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002270 struct hid_usage *usage, __s32 value)
2271{
2272 struct wacom *wacom = hid_get_drvdata(hdev);
2273 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002274 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002275 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07002276 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002277
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002278 if (wacom_wac->is_invalid_bt_frame)
2279 return;
2280
Jason Gereckec9c09582016-10-19 18:03:43 -07002281 switch (equivalent_usage) {
Jason Gerecke50066a02016-10-19 18:03:42 -07002282 case HID_GD_Z:
2283 /*
2284 * HID_GD_Z "should increase as the control's position is
2285 * moved from high to low", while ABS_DISTANCE instead
2286 * increases in value as the tool moves from low to high.
2287 */
2288 value = field->logical_maximum - value;
2289 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002290 case HID_DG_INRANGE:
2291 wacom_wac->hid_data.inrange_state = value;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002292 if (!(features->quirks & WACOM_QUIRK_SENSE))
2293 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002294 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002295 case HID_DG_INVERT:
2296 wacom_wac->hid_data.invert_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002297 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002298 case HID_DG_ERASER:
2299 case HID_DG_TIPSWITCH:
2300 wacom_wac->hid_data.tipswitch |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08002301 return;
Jason Gerecke9e429d52017-11-07 08:25:17 -08002302 case HID_DG_BARRELSWITCH:
2303 wacom_wac->hid_data.barrelswitch = value;
2304 return;
2305 case HID_DG_BARRELSWITCH2:
2306 wacom_wac->hid_data.barrelswitch2 = value;
2307 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002308 case HID_DG_TOOLSERIALNUMBER:
Jason Gerecke993f0d92017-09-07 17:44:12 -07002309 if (value) {
2310 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
Jason Gereckeff4797312019-11-06 11:59:46 -08002311 wacom_wac->serial[0] |= wacom_s32tou(value, field->report_size);
Jason Gerecke993f0d92017-09-07 17:44:12 -07002312 }
Ping Cheng354a3292016-12-08 22:03:27 -08002313 return;
Jason Gerecked252f4a2017-08-30 15:13:26 -07002314 case HID_DG_TWIST:
2315 /*
2316 * Userspace expects pen twist to have its zero point when
2317 * the buttons/finger is on the tablet's left. HID values
2318 * are zero when buttons are toward the top.
2319 */
2320 value = wacom_offset_rotation(input, usage, value, 1, 4);
2321 break;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002322 case WACOM_HID_WD_SENSE:
2323 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002324 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002325 case WACOM_HID_WD_SERIALHI:
Jason Gerecke993f0d92017-09-07 17:44:12 -07002326 if (value) {
Jason Gereckeff4797312019-11-06 11:59:46 -08002327 __u32 raw_value = wacom_s32tou(value, field->report_size);
2328
Jason Gerecke993f0d92017-09-07 17:44:12 -07002329 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
Jason Gereckeff4797312019-11-06 11:59:46 -08002330 wacom_wac->serial[0] |= ((__u64)raw_value) << 32;
Jason Gerecke993f0d92017-09-07 17:44:12 -07002331 /*
2332 * Non-USI EMR devices may contain additional tool type
2333 * information here. See WACOM_HID_WD_TOOLTYPE case for
2334 * more details.
2335 */
2336 if (value >> 20 == 1) {
Jason Gereckeff4797312019-11-06 11:59:46 -08002337 wacom_wac->id[0] |= raw_value & 0xFFFFF;
Jason Gerecke993f0d92017-09-07 17:44:12 -07002338 }
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002339 }
Ping Cheng354a3292016-12-08 22:03:27 -08002340 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002341 case WACOM_HID_WD_TOOLTYPE:
2342 /*
2343 * Some devices (MobileStudio Pro, and possibly later
2344 * devices as well) do not return the complete tool
2345 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
2346 * bitwise OR so the complete value can be built
2347 * up over time :(
2348 */
Jason Gereckeff4797312019-11-06 11:59:46 -08002349 wacom_wac->id[0] |= wacom_s32tou(value, field->report_size);
Ping Cheng354a3292016-12-08 22:03:27 -08002350 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002351 case WACOM_HID_WD_OFFSETLEFT:
2352 if (features->offset_left && value != features->offset_left)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002353 hid_warn(hdev, "%s: overriding existing left offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002354 "%d -> %d\n", __func__, value,
2355 features->offset_left);
2356 features->offset_left = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002357 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002358 case WACOM_HID_WD_OFFSETRIGHT:
2359 if (features->offset_right && value != features->offset_right)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002360 hid_warn(hdev, "%s: overriding existing right offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002361 "%d -> %d\n", __func__, value,
2362 features->offset_right);
2363 features->offset_right = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002364 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002365 case WACOM_HID_WD_OFFSETTOP:
2366 if (features->offset_top && value != features->offset_top)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002367 hid_warn(hdev, "%s: overriding existing top offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002368 "%d -> %d\n", __func__, value,
2369 features->offset_top);
2370 features->offset_top = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002371 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002372 case WACOM_HID_WD_OFFSETBOTTOM:
2373 if (features->offset_bottom && value != features->offset_bottom)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002374 hid_warn(hdev, "%s: overriding existing bottom offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002375 "%d -> %d\n", __func__, value,
2376 features->offset_bottom);
2377 features->offset_bottom = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002378 return;
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002379 case WACOM_HID_WD_REPORT_VALID:
2380 wacom_wac->is_invalid_bt_frame = !value;
2381 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002382 }
2383
Ping Cheng1924e052016-08-09 14:38:56 -07002384 /* send pen events only when touch is up or forced out
2385 * or touch arbitration is off
2386 */
2387 if (!usage->type || delay_pen_events(wacom_wac))
Ping Cheng354a3292016-12-08 22:03:27 -08002388 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002389
Jason Gerecke4affc232017-09-07 17:49:50 -07002390 /* send pen events only when the pen is in range */
Jason Gerecke5b401042017-09-07 17:52:15 -07002391 if (wacom_wac->hid_data.inrange_state)
2392 input_event(input, usage->type, usage->code, value);
2393 else if (wacom_wac->shared->stylus_in_proximity && !wacom_wac->hid_data.sense_state)
2394 input_event(input, usage->type, usage->code, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002395}
2396
Jason Gerecke06324e02015-07-21 11:07:23 -07002397static void wacom_wac_pen_pre_report(struct hid_device *hdev,
2398 struct hid_report *report)
2399{
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002400 struct wacom *wacom = hid_get_drvdata(hdev);
2401 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2402
2403 wacom_wac->is_invalid_bt_frame = false;
Jason Gerecke06324e02015-07-21 11:07:23 -07002404 return;
2405}
2406
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002407static void wacom_wac_pen_report(struct hid_device *hdev,
2408 struct hid_report *report)
2409{
2410 struct wacom *wacom = hid_get_drvdata(hdev);
2411 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002412 struct input_dev *input = wacom_wac->pen_input;
Jason Gerecke7690dd12017-09-07 17:48:55 -07002413 bool range = wacom_wac->hid_data.inrange_state;
2414 bool sense = wacom_wac->hid_data.sense_state;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002415
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002416 if (wacom_wac->is_invalid_bt_frame)
2417 return;
2418
Jason Gerecke7690dd12017-09-07 17:48:55 -07002419 if (!wacom_wac->tool[0] && range) { /* first in range */
2420 /* Going into range select tool */
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002421 if (wacom_wac->hid_data.invert_state)
2422 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
2423 else if (wacom_wac->id[0])
2424 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
2425 else
2426 wacom_wac->tool[0] = BTN_TOOL_PEN;
2427 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002428
2429 /* keep pen state for touch events */
Jason Gerecke7690dd12017-09-07 17:48:55 -07002430 wacom_wac->shared->stylus_in_proximity = sense;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002431
Jason Gerecke61ce3462016-10-19 18:03:46 -07002432 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002433 int id = wacom_wac->id[0];
Jason Gerecke9e429d52017-11-07 08:25:17 -08002434 int sw_state = wacom_wac->hid_data.barrelswitch |
2435 (wacom_wac->hid_data.barrelswitch2 << 1);
2436
2437 input_report_key(input, BTN_STYLUS, sw_state == 1);
2438 input_report_key(input, BTN_STYLUS2, sw_state == 2);
2439 input_report_key(input, BTN_STYLUS3, sw_state == 3);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002440
2441 /*
2442 * Non-USI EMR tools should have their IDs mangled to
2443 * match the legacy behavior of wacom_intuos_general
2444 */
2445 if (wacom_wac->serial[0] >> 52 == 1)
2446 id = wacom_intuos_id_mangle(id);
2447
2448 /*
2449 * To ensure compatibility with xf86-input-wacom, we should
2450 * report the BTN_TOOL_* event prior to the ABS_MISC or
2451 * MSC_SERIAL events.
2452 */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002453 input_report_key(input, BTN_TOUCH,
2454 wacom_wac->hid_data.tipswitch);
Jason Gerecke4affc232017-09-07 17:49:50 -07002455 input_report_key(input, wacom_wac->tool[0], sense);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002456 if (wacom_wac->serial[0]) {
2457 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
Jason Gerecke4affc232017-09-07 17:49:50 -07002458 input_report_abs(input, ABS_MISC, sense ? id : 0);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002459 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002460
2461 wacom_wac->hid_data.tipswitch = false;
2462
2463 input_sync(input);
2464 }
Jason Gerecke61ce3462016-10-19 18:03:46 -07002465
Jason Gerecke4affc232017-09-07 17:49:50 -07002466 if (!sense) {
Jason Gerecke61ce3462016-10-19 18:03:46 -07002467 wacom_wac->tool[0] = 0;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002468 wacom_wac->id[0] = 0;
Jason Gerecke993f0d92017-09-07 17:44:12 -07002469 wacom_wac->serial[0] = 0;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002470 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002471}
2472
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002473static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
2474 struct hid_field *field, struct hid_usage *usage)
2475{
2476 struct wacom *wacom = hid_get_drvdata(hdev);
2477 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002478 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002479 unsigned touch_max = wacom_wac->features.touch_max;
Jason Gereckec9c09582016-10-19 18:03:43 -07002480 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002481
Jason Gereckec9c09582016-10-19 18:03:43 -07002482 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002483 case HID_GD_X:
2484 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002485 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002486 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002487 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002488 ABS_MT_POSITION_X, 4);
2489 break;
2490 case HID_GD_Y:
2491 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002492 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002493 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002494 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002495 ABS_MT_POSITION_Y, 4);
2496 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002497 case HID_DG_WIDTH:
2498 case HID_DG_HEIGHT:
Jason Gerecke488abb52015-07-21 11:07:25 -07002499 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
2500 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
2501 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
2502 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002503 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002504 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002505 break;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002506 case HID_DG_CONTACTCOUNT:
Jason Gerecke499522c2015-10-07 16:54:21 -07002507 wacom_wac->hid_data.cc_report = field->report->id;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002508 wacom_wac->hid_data.cc_index = field->index;
2509 wacom_wac->hid_data.cc_value_index = usage->usage_index;
2510 break;
Jason Gerecke6f107fa2017-04-19 14:47:24 -07002511 case HID_DG_CONTACTID:
2512 if ((field->logical_maximum - field->logical_minimum) < touch_max) {
2513 /*
2514 * The HID descriptor for G11 sensors leaves logical
2515 * maximum set to '1' despite it being a multitouch
2516 * device. Override to a sensible number.
2517 */
2518 field->logical_maximum = 255;
2519 }
2520 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002521 }
2522}
2523
Jason Gerecke601a22f2014-12-10 16:26:04 -08002524static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
2525 struct input_dev *input)
2526{
2527 struct hid_data *hid_data = &wacom_wac->hid_data;
2528 bool mt = wacom_wac->features.touch_max > 1;
2529 bool prox = hid_data->tipswitch &&
Ping Cheng1924e052016-08-09 14:38:56 -07002530 report_touch_events(wacom_wac);
Jason Gerecke601a22f2014-12-10 16:26:04 -08002531
Ping Chengd793ff82017-02-14 21:27:45 -08002532 if (wacom_wac->shared->has_mute_touch_switch &&
2533 !wacom_wac->shared->is_touch_on) {
2534 if (!wacom_wac->shared->touch_down)
2535 return;
2536 prox = 0;
2537 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002538
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002539 wacom_wac->hid_data.num_received++;
2540 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
2541 return;
2542
Jason Gerecke601a22f2014-12-10 16:26:04 -08002543 if (mt) {
2544 int slot;
2545
2546 slot = input_mt_get_slot_by_key(input, hid_data->id);
2547 input_mt_slot(input, slot);
2548 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
2549 }
2550 else {
2551 input_report_key(input, BTN_TOUCH, prox);
2552 }
2553
2554 if (prox) {
2555 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
2556 hid_data->x);
2557 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
2558 hid_data->y);
Jason Gerecke488abb52015-07-21 11:07:25 -07002559
2560 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
2561 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
2562 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
2563 if (hid_data->width != hid_data->height)
2564 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
2565 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002566 }
2567}
2568
Ping Cheng354a3292016-12-08 22:03:27 -08002569static void wacom_wac_finger_event(struct hid_device *hdev,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002570 struct hid_field *field, struct hid_usage *usage, __s32 value)
2571{
2572 struct wacom *wacom = hid_get_drvdata(hdev);
2573 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckec9c09582016-10-19 18:03:43 -07002574 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Aaron Armstrong Skomra184eccd2019-06-12 14:19:29 -07002575 struct wacom_features *features = &wacom->wacom_wac.features;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002576
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07002577 if (wacom_wac->is_invalid_bt_frame)
2578 return;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002579
Jason Gereckec9c09582016-10-19 18:03:43 -07002580 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002581 case HID_GD_X:
2582 wacom_wac->hid_data.x = value;
2583 break;
2584 case HID_GD_Y:
2585 wacom_wac->hid_data.y = value;
2586 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002587 case HID_DG_WIDTH:
2588 wacom_wac->hid_data.width = value;
2589 break;
2590 case HID_DG_HEIGHT:
2591 wacom_wac->hid_data.height = value;
2592 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002593 case HID_DG_CONTACTID:
2594 wacom_wac->hid_data.id = value;
2595 break;
2596 case HID_DG_TIPSWITCH:
2597 wacom_wac->hid_data.tipswitch = value;
2598 break;
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07002599 case WACOM_HID_WT_REPORT_VALID:
2600 wacom_wac->is_invalid_bt_frame = !value;
2601 return;
Aaron Armstrong Skomra184eccd2019-06-12 14:19:29 -07002602 case HID_DG_CONTACTMAX:
2603 features->touch_max = value;
2604 return;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002605 }
2606
Jason Gerecke601a22f2014-12-10 16:26:04 -08002607 if (usage->usage_index + 1 == field->report_count) {
Jason Gereckec9c09582016-10-19 18:03:43 -07002608 if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002609 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
Jason Gerecke601a22f2014-12-10 16:26:04 -08002610 }
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002611}
2612
Jason Gerecke06324e02015-07-21 11:07:23 -07002613static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2614 struct hid_report *report)
2615{
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002616 struct wacom *wacom = hid_get_drvdata(hdev);
2617 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2618 struct hid_data* hid_data = &wacom_wac->hid_data;
Jason Gerecke003f50a2016-07-21 09:10:46 -07002619 int i;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002620
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07002621 wacom_wac->is_invalid_bt_frame = false;
2622
Jason Gerecke003f50a2016-07-21 09:10:46 -07002623 for (i = 0; i < report->maxfield; i++) {
2624 struct hid_field *field = report->field[i];
2625 int j;
Jason Gerecke499522c2015-10-07 16:54:21 -07002626
Jason Gerecke003f50a2016-07-21 09:10:46 -07002627 for (j = 0; j < field->maxusage; j++) {
2628 struct hid_usage *usage = &field->usage[j];
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002629 unsigned int equivalent_usage =
2630 wacom_equivalent_usage(usage->hid);
Jason Gerecke499522c2015-10-07 16:54:21 -07002631
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002632 switch (equivalent_usage) {
Jason Gerecke003f50a2016-07-21 09:10:46 -07002633 case HID_GD_X:
2634 case HID_GD_Y:
2635 case HID_DG_WIDTH:
2636 case HID_DG_HEIGHT:
2637 case HID_DG_CONTACTID:
2638 case HID_DG_INRANGE:
2639 case HID_DG_INVERT:
2640 case HID_DG_TIPSWITCH:
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002641 hid_data->last_slot_field = equivalent_usage;
Jason Gerecke003f50a2016-07-21 09:10:46 -07002642 break;
Jason Gereckeb43f9772020-04-08 07:58:37 -07002643 case HID_DG_CONTACTCOUNT:
2644 hid_data->cc_report = report->id;
2645 hid_data->cc_index = i;
2646 hid_data->cc_value_index = j;
2647 break;
Jason Gerecke499522c2015-10-07 16:54:21 -07002648 }
2649 }
2650 }
Jason Gereckeb43f9772020-04-08 07:58:37 -07002651
2652 if (hid_data->cc_report != 0 &&
2653 hid_data->cc_index >= 0) {
2654 struct hid_field *field = report->field[hid_data->cc_index];
2655 int value = field->value[hid_data->cc_value_index];
2656 if (value)
2657 hid_data->num_expected = value;
2658 }
2659 else {
2660 hid_data->num_expected = wacom_wac->features.touch_max;
2661 }
Jason Gerecke06324e02015-07-21 11:07:23 -07002662}
2663
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002664static void wacom_wac_finger_report(struct hid_device *hdev,
2665 struct hid_report *report)
2666{
2667 struct wacom *wacom = hid_get_drvdata(hdev);
2668 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002669 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002670 unsigned touch_max = wacom_wac->features.touch_max;
2671
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002672 /* If more packets of data are expected, give us a chance to
2673 * process them rather than immediately syncing a partial
2674 * update.
2675 */
2676 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2677 return;
2678
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002679 if (touch_max > 1)
Jason Gerecke601a22f2014-12-10 16:26:04 -08002680 input_mt_sync_frame(input);
2681
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002682 input_sync(input);
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002683 wacom_wac->hid_data.num_received = 0;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002684
2685 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07002686 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002687}
2688
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002689void wacom_wac_usage_mapping(struct hid_device *hdev,
2690 struct hid_field *field, struct hid_usage *usage)
2691{
2692 struct wacom *wacom = hid_get_drvdata(hdev);
2693 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002694 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002695
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002696 if (WACOM_DIRECT_DEVICE(field))
2697 features->device_type |= WACOM_DEVICETYPE_DIRECT;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002698
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07002699 /* usage tests must precede field tests */
2700 if (WACOM_BATTERY_USAGE(usage))
2701 wacom_wac_battery_usage_mapping(hdev, field, usage);
2702 else if (WACOM_PAD_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002703 wacom_wac_pad_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002704 else if (WACOM_PEN_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002705 wacom_wac_pen_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002706 else if (WACOM_FINGER_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002707 wacom_wac_finger_usage_mapping(hdev, field, usage);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002708}
2709
Ping Cheng354a3292016-12-08 22:03:27 -08002710void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002711 struct hid_usage *usage, __s32 value)
2712{
2713 struct wacom *wacom = hid_get_drvdata(hdev);
2714
2715 if (wacom->wacom_wac.features.type != HID_GENERIC)
Ping Cheng354a3292016-12-08 22:03:27 -08002716 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002717
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002718 if (value > field->logical_maximum || value < field->logical_minimum)
2719 return;
2720
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07002721 /* usage tests must precede field tests */
2722 if (WACOM_BATTERY_USAGE(usage))
2723 wacom_wac_battery_event(hdev, field, usage, value);
2724 else if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2725 wacom_wac_pad_event(hdev, field, usage, value);
2726 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002727 wacom_wac_pen_event(hdev, field, usage, value);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002728 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002729 wacom_wac_finger_event(hdev, field, usage, value);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002730}
2731
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002732static void wacom_report_events(struct hid_device *hdev,
2733 struct hid_report *report, int collection_index,
2734 int field_index)
Jason Gerecke06324e02015-07-21 11:07:23 -07002735{
2736 int r;
2737
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002738 for (r = field_index; r < report->maxfield; r++) {
Jason Gerecke06324e02015-07-21 11:07:23 -07002739 struct hid_field *field;
2740 unsigned count, n;
2741
2742 field = report->field[r];
2743 count = field->report_count;
2744
2745 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2746 continue;
2747
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002748 for (n = 0 ; n < count; n++) {
2749 if (field->usage[n].collection_index == collection_index)
2750 wacom_wac_event(hdev, field, &field->usage[n],
2751 field->value[n]);
2752 else
2753 return;
2754 }
Jason Gerecke06324e02015-07-21 11:07:23 -07002755 }
2756}
2757
Jiri Kosina7ba8fc02018-03-07 15:34:51 +01002758static int wacom_wac_collection(struct hid_device *hdev, struct hid_report *report,
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002759 int collection_index, struct hid_field *field,
2760 int field_index)
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002761{
2762 struct wacom *wacom = hid_get_drvdata(hdev);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002763
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002764 wacom_report_events(hdev, report, collection_index, field_index);
Jason Gerecke06324e02015-07-21 11:07:23 -07002765
Jason Gereckea9ce7852017-01-17 15:38:58 -08002766 /*
2767 * Non-input reports may be sent prior to the device being
2768 * completely initialized. Since only their events need
2769 * to be processed, exit after 'wacom_report_events' has
2770 * been called to prevent potential crashes in the report-
2771 * processing functions.
2772 */
2773 if (report->type != HID_INPUT_REPORT)
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002774 return -1;
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07002775
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002776 if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002777 wacom_wac_pen_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002778 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002779 wacom_wac_finger_report(hdev, report);
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002780
2781 return 0;
2782}
2783
2784void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2785{
2786 struct wacom *wacom = hid_get_drvdata(hdev);
2787 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2788 struct hid_field *field;
2789 bool pad_in_hid_field = false, pen_in_hid_field = false,
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002790 finger_in_hid_field = false, true_pad = false;
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002791 int r;
2792 int prev_collection = -1;
2793
2794 if (wacom_wac->features.type != HID_GENERIC)
2795 return;
2796
2797 for (r = 0; r < report->maxfield; r++) {
2798 field = report->field[r];
2799
2800 if (WACOM_PAD_FIELD(field))
2801 pad_in_hid_field = true;
2802 if (WACOM_PEN_FIELD(field))
2803 pen_in_hid_field = true;
2804 if (WACOM_FINGER_FIELD(field))
2805 finger_in_hid_field = true;
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002806 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY)
2807 true_pad = true;
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002808 }
2809
2810 wacom_wac_battery_pre_report(hdev, report);
2811
2812 if (pad_in_hid_field && wacom->wacom_wac.pad_input)
2813 wacom_wac_pad_pre_report(hdev, report);
2814 if (pen_in_hid_field && wacom->wacom_wac.pen_input)
2815 wacom_wac_pen_pre_report(hdev, report);
2816 if (finger_in_hid_field && wacom->wacom_wac.touch_input)
2817 wacom_wac_finger_pre_report(hdev, report);
2818
2819 for (r = 0; r < report->maxfield; r++) {
2820 field = report->field[r];
2821
2822 if (field->usage[0].collection_index != prev_collection) {
2823 if (wacom_wac_collection(hdev, report,
2824 field->usage[0].collection_index, field, r) < 0)
2825 return;
2826 prev_collection = field->usage[0].collection_index;
2827 }
2828 }
2829
2830 wacom_wac_battery_report(hdev, report);
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002831
2832 if (true_pad && wacom->wacom_wac.pad_input)
2833 wacom_wac_pad_report(hdev, report, field);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002834}
2835
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002836static int wacom_bpt_touch(struct wacom_wac *wacom)
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002837{
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002838 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002839 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires31168712014-07-24 12:50:10 -07002840 struct input_dev *pad_input = wacom->pad_input;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002841 unsigned char *data = wacom->data;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002842 int i;
2843
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002844 if (data[0] != 0x02)
2845 return 0;
2846
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002847 for (i = 0; i < 2; i++) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002848 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
Ping Cheng1924e052016-08-09 14:38:56 -07002849 bool touch = report_touch_events(wacom)
2850 && (data[offset + 3] & 0x80);
Chris Bagwell8f906862011-09-09 13:38:10 -07002851
2852 input_mt_slot(input, i);
2853 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +01002854 if (touch) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002855 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2856 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002857 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2858 x <<= 5;
2859 y <<= 5;
2860 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002861 input_report_abs(input, ABS_MT_POSITION_X, x);
2862 input_report_abs(input, ABS_MT_POSITION_Y, y);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002863 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002864 }
2865
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05002866 input_mt_sync_frame(input);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002867
Benjamin Tissoires31168712014-07-24 12:50:10 -07002868 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2869 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2870 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2871 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
Ping Cheng7d059ed2015-03-20 14:57:21 -07002872 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002873
Benjamin Tissoires31168712014-07-24 12:50:10 -07002874 return 1;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002875}
2876
Ping Cheng7d059ed2015-03-20 14:57:21 -07002877static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002878{
Ping Cheng9a35c412013-09-20 09:51:56 -07002879 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002880 struct input_dev *input = wacom->touch_input;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002881 bool touch = data[1] & 0x80;
Ping Cheng02295e62013-01-04 23:56:00 -08002882 int slot = input_mt_get_slot_by_key(input, data[0]);
2883
2884 if (slot < 0)
Ping Cheng7d059ed2015-03-20 14:57:21 -07002885 return;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002886
Ping Cheng1924e052016-08-09 14:38:56 -07002887 touch = touch && report_touch_events(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002888
Ping Cheng02295e62013-01-04 23:56:00 -08002889 input_mt_slot(input, slot);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002890 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2891
2892 if (touch) {
2893 int x = (data[2] << 4) | (data[4] >> 4);
2894 int y = (data[3] << 4) | (data[4] & 0x0f);
Ping Cheng9a35c412013-09-20 09:51:56 -07002895 int width, height;
Jason Gerecke4e904952012-10-03 17:19:11 -07002896
Ping Chengeda01da2015-09-23 13:51:15 -07002897 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
Jason Gerecke0b279da2013-11-25 18:43:16 -08002898 width = data[5] * 100;
2899 height = data[6] * 100;
Ping Cheng9a35c412013-09-20 09:51:56 -07002900 } else {
2901 /*
2902 * "a" is a scaled-down area which we assume is
2903 * roughly circular and which can be described as:
2904 * a=(pi*r^2)/C.
2905 */
2906 int a = data[5];
Ping Chengd7da3a32014-06-13 13:37:33 -07002907 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2908 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2909 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
Ping Cheng9a35c412013-09-20 09:51:56 -07002910 height = width * y_res / x_res;
2911 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002912
2913 input_report_abs(input, ABS_MT_POSITION_X, x);
2914 input_report_abs(input, ABS_MT_POSITION_Y, y);
Jason Gerecke4e904952012-10-03 17:19:11 -07002915 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2916 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002917 }
2918}
2919
2920static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2921{
Benjamin Tissoires31168712014-07-24 12:50:10 -07002922 struct input_dev *input = wacom->pad_input;
Ping Chengb5fd2a32013-11-25 18:44:55 -08002923 struct wacom_features *features = &wacom->features;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002924
Ping Chengeda01da2015-09-23 13:51:15 -07002925 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
Ping Chengb5fd2a32013-11-25 18:44:55 -08002926 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
2927 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
2928 } else {
2929 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
2930 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
2931 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002932 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002933 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
2934}
2935
2936static int wacom_bpt3_touch(struct wacom_wac *wacom)
2937{
Chris Bagwell73149ab2011-10-26 22:34:21 -07002938 unsigned char *data = wacom->data;
Jason Gerecke19d57d32012-03-06 10:19:19 -08002939 int count = data[1] & 0x07;
Ping Chengeda01da2015-09-23 13:51:15 -07002940 int touch_changed = 0, i;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002941
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002942 if (data[0] != 0x02)
2943 return 0;
2944
Chris Bagwell73149ab2011-10-26 22:34:21 -07002945 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
2946 for (i = 0; i < count; i++) {
2947 int offset = (8 * i) + 2;
2948 int msg_id = data[offset];
2949
Ping Chengeda01da2015-09-23 13:51:15 -07002950 if (msg_id >= 2 && msg_id <= 17) {
Ping Cheng7d059ed2015-03-20 14:57:21 -07002951 wacom_bpt3_touch_msg(wacom, data + offset);
Ping Chengeda01da2015-09-23 13:51:15 -07002952 touch_changed++;
2953 } else if (msg_id == 128)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002954 wacom_bpt3_button_msg(wacom, data + offset);
2955
2956 }
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002957
Ping Chengeda01da2015-09-23 13:51:15 -07002958 /* only update touch if we actually have a touchpad and touch data changed */
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002959 if (wacom->touch_input && touch_changed) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002960 input_mt_sync_frame(wacom->touch_input);
2961 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2962 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002963
Benjamin Tissoires31168712014-07-24 12:50:10 -07002964 return 1;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002965}
2966
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002967static int wacom_bpt_pen(struct wacom_wac *wacom)
2968{
Ping Cheng961794a2013-12-05 12:54:53 -08002969 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002970 struct input_dev *input = wacom->pen_input;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002971 unsigned char *data = wacom->data;
Jason Gerecke8947b0c2018-05-18 07:17:18 -07002972 int x = 0, y = 0, p = 0, d = 0;
2973 bool pen = false, btn1 = false, btn2 = false;
2974 bool range, prox, rdy;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002975
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002976 if (data[0] != WACOM_REPORT_PENABLED)
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002977 return 0;
2978
Jason Gerecke8947b0c2018-05-18 07:17:18 -07002979 range = (data[1] & 0x80) == 0x80;
2980 prox = (data[1] & 0x40) == 0x40;
2981 rdy = (data[1] & 0x20) == 0x20;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002982
Jason Gerecke8947b0c2018-05-18 07:17:18 -07002983 wacom->shared->stylus_in_proximity = range;
2984 if (delay_pen_events(wacom))
2985 return 0;
2986
2987 if (rdy) {
2988 p = le16_to_cpup((__le16 *)&data[6]);
2989 pen = data[1] & 0x01;
2990 btn1 = data[1] & 0x02;
2991 btn2 = data[1] & 0x04;
2992 }
2993 if (prox) {
2994 x = le16_to_cpup((__le16 *)&data[2]);
2995 y = le16_to_cpup((__le16 *)&data[4]);
2996
Ping Cheng01499312015-03-20 14:58:01 -07002997 if (data[1] & 0x08) {
2998 wacom->tool[0] = BTN_TOOL_RUBBER;
2999 wacom->id[0] = ERASER_DEVICE_ID;
3000 } else {
3001 wacom->tool[0] = BTN_TOOL_PEN;
3002 wacom->id[0] = STYLUS_DEVICE_ID;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003003 }
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003004 wacom->reporting_data = true;
Ping Cheng01499312015-03-20 14:58:01 -07003005 }
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003006 if (range) {
Chris Bagwellc18c2ce2011-10-10 08:52:13 -07003007 /*
3008 * Convert distance from out prox to distance from tablet.
3009 * distance will be greater than distance_max once
3010 * touching and applying pressure; do not report negative
3011 * distance.
3012 */
Ping Cheng961794a2013-12-05 12:54:53 -08003013 if (data[8] <= features->distance_max)
3014 d = features->distance_max - data[8];
Ping Cheng01499312015-03-20 14:58:01 -07003015 } else {
3016 wacom->id[0] = 0;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003017 }
3018
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003019 if (wacom->reporting_data) {
3020 input_report_key(input, BTN_TOUCH, pen);
3021 input_report_key(input, BTN_STYLUS, btn1);
3022 input_report_key(input, BTN_STYLUS2, btn2);
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003023
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003024 if (prox || !range) {
3025 input_report_abs(input, ABS_X, x);
3026 input_report_abs(input, ABS_Y, y);
3027 }
3028 input_report_abs(input, ABS_PRESSURE, p);
3029 input_report_abs(input, ABS_DISTANCE, d);
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003030
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003031 input_report_key(input, wacom->tool[0], range); /* PEN or RUBBER */
3032 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
3033 }
3034
3035 if (!range) {
3036 wacom->reporting_data = false;
3037 }
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003038
3039 return 1;
3040}
3041
Chris Bagwelle1d38e42010-09-12 00:09:27 -07003042static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
3043{
Ping Chengeda01da2015-09-23 13:51:15 -07003044 struct wacom_features *features = &wacom->features;
3045
3046 if ((features->type == INTUOSHT2) &&
Ping Chengeda01da2015-09-23 13:51:15 -07003047 (features->device_type & WACOM_DEVICETYPE_PEN))
3048 return wacom_intuos_irq(wacom);
3049 else if (len == WACOM_PKGLEN_BBTOUCH)
Chris Bagwelle1d38e42010-09-12 00:09:27 -07003050 return wacom_bpt_touch(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07003051 else if (len == WACOM_PKGLEN_BBTOUCH3)
3052 return wacom_bpt3_touch(wacom);
3053 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003054 return wacom_bpt_pen(wacom);
Chris Bagwelle1d38e42010-09-12 00:09:27 -07003055
3056 return 0;
3057}
3058
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003059static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
3060 unsigned char *data)
3061{
3062 unsigned char prefix;
3063
3064 /*
3065 * We need to reroute the event from the debug interface to the
3066 * pen interface.
3067 * We need to add the report ID to the actual pen report, so we
3068 * temporary overwrite the first byte to prevent having to kzalloc/kfree
3069 * and memcpy the report.
3070 */
3071 prefix = data[0];
3072 data[0] = WACOM_REPORT_BPAD_PEN;
3073
3074 /*
3075 * actually reroute the event.
3076 * No need to check if wacom->shared->pen is valid, hid_input_report()
3077 * will check for us.
3078 */
3079 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
3080 WACOM_PKGLEN_PENABLED, 1);
3081
3082 data[0] = prefix;
3083}
3084
3085static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
3086 unsigned char *data)
3087{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003088 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003089 unsigned char *finger_data, prefix;
3090 unsigned id;
3091 int x, y;
3092 bool valid;
3093
3094 prefix = data[0];
3095
3096 for (id = 0; id < wacom->features.touch_max; id++) {
3097 valid = !!(prefix & BIT(id)) &&
Ping Cheng1924e052016-08-09 14:38:56 -07003098 report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003099
3100 input_mt_slot(input, id);
3101 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
3102
3103 if (!valid)
3104 continue;
3105
3106 finger_data = data + 1 + id * 3;
3107 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
3108 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
3109
3110 input_report_abs(input, ABS_MT_POSITION_X, x);
3111 input_report_abs(input, ABS_MT_POSITION_Y, y);
3112 }
3113
3114 input_mt_sync_frame(input);
3115
3116 input_report_key(input, BTN_LEFT, prefix & 0x40);
3117 input_report_key(input, BTN_RIGHT, prefix & 0x80);
3118
3119 /* keep touch state for pen event */
Ping Cheng1924e052016-08-09 14:38:56 -07003120 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003121
3122 return 1;
3123}
3124
3125static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
3126{
3127 unsigned char *data = wacom->data;
3128
3129 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
3130 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
3131 (data[0] != WACOM_REPORT_BPAD_TOUCH))
3132 return 0;
3133
3134 if (data[1] & 0x01)
3135 wacom_bamboo_pad_pen_event(wacom, &data[1]);
3136
3137 if (data[1] & 0x02)
3138 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
3139
3140 return 0;
3141}
3142
Chris Bagwelld3825d52012-03-25 23:26:11 -07003143static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
3144{
Chris Bagwell16bf2882012-03-25 23:26:20 -07003145 unsigned char *data = wacom->data;
3146 int connected;
3147
Ping Chengb5fd2a32013-11-25 18:44:55 -08003148 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
Chris Bagwelld3825d52012-03-25 23:26:11 -07003149 return 0;
3150
Chris Bagwell16bf2882012-03-25 23:26:20 -07003151 connected = data[1] & 0x01;
3152 if (connected) {
Jason Gereckeb0882cb2015-03-06 11:47:43 -08003153 int pid, battery, charging;
Chris Bagwell16bf2882012-03-25 23:26:20 -07003154
Ping Chengeda01da2015-09-23 13:51:15 -07003155 if ((wacom->shared->type == INTUOSHT ||
3156 wacom->shared->type == INTUOSHT2) &&
Ping Cheng44b96832014-11-06 17:30:51 -08003157 wacom->shared->touch_input &&
3158 wacom->shared->touch_max) {
Ping Cheng961794a2013-12-05 12:54:53 -08003159 input_report_switch(wacom->shared->touch_input,
3160 SW_MUTE_DEVICE, data[5] & 0x40);
3161 input_sync(wacom->shared->touch_input);
3162 }
3163
Chris Bagwell16bf2882012-03-25 23:26:20 -07003164 pid = get_unaligned_be16(&data[6]);
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003165 battery = (data[5] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08003166 charging = !!(data[5] & 0x80);
Chris Bagwell16bf2882012-03-25 23:26:20 -07003167 if (wacom->pid != pid) {
3168 wacom->pid = pid;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003169 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Chris Bagwell16bf2882012-03-25 23:26:20 -07003170 }
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003171
Jason Gerecke16e45982017-04-28 09:25:33 -07003172 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
3173 battery, charging, 1, 0);
Jason Gerecke953f2c52015-03-06 11:47:39 -08003174
Chris Bagwell16bf2882012-03-25 23:26:20 -07003175 } else if (wacom->pid != 0) {
3176 /* disconnected while previously connected */
3177 wacom->pid = 0;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003178 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Jason Gerecke16e45982017-04-28 09:25:33 -07003179 wacom_notify_battery(wacom, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
Chris Bagwell16bf2882012-03-25 23:26:20 -07003180 }
3181
Chris Bagwelld3825d52012-03-25 23:26:11 -07003182 return 0;
3183}
3184
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003185static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
3186{
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003187 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003188 struct wacom_features *features = &wacom_wac->features;
3189 unsigned char *data = wacom_wac->data;
3190
3191 if (data[0] != WACOM_REPORT_USB)
3192 return 0;
3193
Ping Chengeda01da2015-09-23 13:51:15 -07003194 if ((features->type == INTUOSHT ||
3195 features->type == INTUOSHT2) &&
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003196 wacom_wac->shared->touch_input &&
3197 features->touch_max) {
3198 input_report_switch(wacom_wac->shared->touch_input,
3199 SW_MUTE_DEVICE, data[8] & 0x40);
3200 input_sync(wacom_wac->shared->touch_input);
3201 }
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003202
3203 if (data[9] & 0x02) { /* wireless module is attached */
3204 int battery = (data[8] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08003205 bool charging = !!(data[8] & 0x80);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003206
Jason Gerecke16e45982017-04-28 09:25:33 -07003207 wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
3208 battery, charging, battery || charging, 1);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003209
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02003210 if (!wacom->battery.battery &&
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003211 !(features->quirks & WACOM_QUIRK_BATTERY)) {
3212 features->quirks |= WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003213 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003214 }
3215 }
3216 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02003217 wacom->battery.battery) {
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003218 features->quirks &= ~WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003219 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke16e45982017-04-28 09:25:33 -07003220 wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003221 }
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003222 return 0;
3223}
3224
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003225void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
Ping Cheng3bea7332006-07-13 18:01:36 -07003226{
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003227 bool sync;
3228
Jason Childse33da8a2010-02-17 22:38:31 -08003229 switch (wacom_wac->features.type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003230 case PENPARTNER:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003231 sync = wacom_penpartner_irq(wacom_wac);
3232 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003233
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003234 case PL:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003235 sync = wacom_pl_irq(wacom_wac);
3236 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003237
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003238 case WACOM_G4:
3239 case GRAPHIRE:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003240 case GRAPHIRE_BT:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003241 case WACOM_MO:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003242 sync = wacom_graphire_irq(wacom_wac);
3243 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003244
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003245 case PTU:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003246 sync = wacom_ptu_irq(wacom_wac);
3247 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003248
Ping Chengc8f2edc2010-06-28 01:10:51 -07003249 case DTU:
3250 sync = wacom_dtu_irq(wacom_wac);
3251 break;
3252
Ping Cheng497ab1f2014-01-20 20:18:04 -08003253 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08003254 case DTUSX:
Ping Cheng497ab1f2014-01-20 20:18:04 -08003255 sync = wacom_dtus_irq(wacom_wac);
3256 break;
3257
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003258 case INTUOS:
3259 case INTUOS3S:
3260 case INTUOS3:
3261 case INTUOS3L:
3262 case INTUOS4S:
3263 case INTUOS4:
3264 case INTUOS4L:
3265 case CINTIQ:
3266 case WACOM_BEE:
Ping Cheng56218562013-05-05 19:56:18 -07003267 case WACOM_13HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003268 case WACOM_21UX2:
Ping Chengd838c642012-07-24 23:54:11 -07003269 case WACOM_22HD:
Jason Gerecke803296b2011-12-12 00:11:45 -08003270 case WACOM_24HD:
Ping Cheng500d4162015-01-27 13:30:03 -08003271 case WACOM_27QHD:
Ping Chenga112e9f2013-02-13 20:20:01 -08003272 case DTK:
Jason Gerecke36d3c512013-09-20 09:47:35 -07003273 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003274 case CINTIQ_COMPANION_2:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003275 sync = wacom_intuos_irq(wacom_wac);
3276 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003277
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07003278 case INTUOS4WL:
3279 sync = wacom_intuos_bt_irq(wacom_wac, len);
3280 break;
3281
Jason Gereckeb1e42792012-10-21 00:38:04 -07003282 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08003283 case WACOM_27QHDT:
Jason Gereckeb1e42792012-10-21 00:38:04 -07003284 sync = wacom_24hdt_irq(wacom_wac);
3285 break;
3286
Jason Gereckeae584ca2012-04-03 15:50:40 -07003287 case INTUOS5S:
3288 case INTUOS5:
3289 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07003290 case INTUOSPS:
3291 case INTUOSPM:
3292 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07003293 if (len == WACOM_PKGLEN_BBTOUCH3)
3294 sync = wacom_bpt3_touch(wacom_wac);
Jason Gerecke2d13a432015-03-06 11:47:42 -08003295 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
3296 sync = wacom_status_irq(wacom_wac, len);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003297 else
3298 sync = wacom_intuos_irq(wacom_wac);
3299 break;
3300
Jason Gerecke4922cd22017-01-25 12:08:37 -08003301 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003302 case INTUOSP2S_BT:
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08003303 case INTUOSHT3_BT:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003304 sync = wacom_intuos_pro2_bt_irq(wacom_wac, len);
3305 break;
3306
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003307 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07003308 case TABLETPCE:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003309 case TABLETPC2FG:
Ping Cheng19635182012-04-29 21:09:18 -07003310 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07003311 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07003312 case MTTPC_B:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003313 sync = wacom_tpc_irq(wacom_wac, len);
3314 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003315
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003316 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003317 case BAMBOO_PEN:
3318 case BAMBOO_TOUCH:
Ping Chengb5fd2a32013-11-25 18:44:55 -08003319 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07003320 case INTUOSHT2:
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003321 if (wacom_wac->data[0] == WACOM_REPORT_USB)
3322 sync = wacom_status_irq(wacom_wac, len);
3323 else
3324 sync = wacom_bpt_irq(wacom_wac, len);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003325 break;
3326
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003327 case BAMBOO_PAD:
3328 sync = wacom_bamboo_pad_irq(wacom_wac, len);
Ping Cheng3bea7332006-07-13 18:01:36 -07003329 break;
3330
Chris Bagwelld3825d52012-03-25 23:26:11 -07003331 case WIRELESS:
3332 sync = wacom_wireless_irq(wacom_wac, len);
3333 break;
3334
Aaron Skomra72b236d2015-08-20 16:05:17 -07003335 case REMOTE:
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02003336 sync = false;
Aaron Skomra72b236d2015-08-20 16:05:17 -07003337 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02003338 wacom_remote_status_irq(wacom_wac, len);
Aaron Skomra72b236d2015-08-20 16:05:17 -07003339 else
3340 sync = wacom_remote_irq(wacom_wac, len);
3341 break;
3342
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003343 default:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003344 sync = false;
3345 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07003346 }
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003347
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003348 if (sync) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003349 if (wacom_wac->pen_input)
3350 input_sync(wacom_wac->pen_input);
3351 if (wacom_wac->touch_input)
3352 input_sync(wacom_wac->touch_input);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003353 if (wacom_wac->pad_input)
3354 input_sync(wacom_wac->pad_input);
3355 }
Ping Cheng3bea7332006-07-13 18:01:36 -07003356}
3357
Ping Chengeda01da2015-09-23 13:51:15 -07003358static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
Ping Cheng3bea7332006-07-13 18:01:36 -07003359{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003360 struct input_dev *input_dev = wacom_wac->pen_input;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003361
3362 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003363
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003364 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003365 __set_bit(BTN_STYLUS, input_dev->keybit);
3366 __set_bit(BTN_STYLUS2, input_dev->keybit);
3367
3368 input_set_abs_params(input_dev, ABS_DISTANCE,
Jason Gereckebef7e202016-04-22 14:30:53 -07003369 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07003370}
3371
3372static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
3373{
3374 struct input_dev *input_dev = wacom_wac->pen_input;
Jason Gereckebef7e202016-04-22 14:30:53 -07003375 struct wacom_features *features = &wacom_wac->features;
Ping Chengeda01da2015-09-23 13:51:15 -07003376
3377 wacom_setup_basic_pro_pen(wacom_wac);
3378
3379 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3380 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
3381 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
3382 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
3383
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003384 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
Jason Gereckebef7e202016-04-22 14:30:53 -07003385 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003386 input_abs_set_res(input_dev, ABS_TILT_X, 57);
Jason Gereckebef7e202016-04-22 14:30:53 -07003387 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003388 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
Ping Cheng6521d0b2010-10-24 21:53:40 -07003389}
3390
3391static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
3392{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003393 struct input_dev *input_dev = wacom_wac->pen_input;
Ping Cheng6521d0b2010-10-24 21:53:40 -07003394
3395 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3396
3397 wacom_setup_cintiq(wacom_wac);
3398
3399 __set_bit(BTN_LEFT, input_dev->keybit);
3400 __set_bit(BTN_RIGHT, input_dev->keybit);
3401 __set_bit(BTN_MIDDLE, input_dev->keybit);
3402 __set_bit(BTN_SIDE, input_dev->keybit);
3403 __set_bit(BTN_EXTRA, input_dev->keybit);
3404 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3405 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
3406
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003407 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003408 input_abs_set_res(input_dev, ABS_RZ, 287);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003409 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
3410}
3411
Ping Cheng42f4f272015-04-15 16:53:54 -07003412void wacom_setup_device_quirks(struct wacom *wacom)
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003413{
Jason Gerecke11db8172018-10-10 13:40:26 -07003414 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Ping Cheng42f4f272015-04-15 16:53:54 -07003415 struct wacom_features *features = &wacom->wacom_wac.features;
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003416
Jason Gerecke862cf552015-06-15 18:01:43 -07003417 /* The pen and pad share the same interface on most devices */
3418 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
Ping Cheng3b164a02015-09-23 09:59:10 -07003419 features->type == DTUS ||
3420 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
Jason Gerecke862cf552015-06-15 18:01:43 -07003421 if (features->device_type & WACOM_DEVICETYPE_PEN)
3422 features->device_type |= WACOM_DEVICETYPE_PAD;
3423 }
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003424
3425 /* touch device found but size is not defined. use default */
Jason Gereckeaa86b182015-06-15 18:01:42 -07003426 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003427 features->x_max = 1023;
3428 features->y_max = 1023;
3429 }
3430
Ping Cheng42f4f272015-04-15 16:53:54 -07003431 /*
3432 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
3433 * touch interface in its HID descriptor. If this is the touch
3434 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
3435 * tablet values.
3436 */
Ping Cheng3b164a02015-09-23 09:59:10 -07003437 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
3438 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
Ping Cheng42f4f272015-04-15 16:53:54 -07003439 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
Jason Gerecke862cf552015-06-15 18:01:43 -07003440 if (features->touch_max)
3441 features->device_type |= WACOM_DEVICETYPE_TOUCH;
Jiri Kosinaa3088ab2015-11-17 00:24:14 +01003442 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
Jason Gerecke862cf552015-06-15 18:01:43 -07003443 features->device_type |= WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07003444
Jason Gerecke3b8d5732018-06-26 09:58:02 -07003445 if (features->type == INTUOSHT2) {
3446 features->x_max = features->x_max / 10;
3447 features->y_max = features->y_max / 10;
3448 }
3449 else {
3450 features->x_max = 4096;
3451 features->y_max = 4096;
3452 }
Ping Cheng42f4f272015-04-15 16:53:54 -07003453 }
Jason Gerecke96339202015-07-01 13:01:00 -07003454 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
3455 features->device_type |= WACOM_DEVICETYPE_PAD;
3456 }
Ping Cheng42f4f272015-04-15 16:53:54 -07003457 }
3458
3459 /*
Benjamin Tissoires580549e2016-03-25 15:26:55 +01003460 * Hack for the Bamboo One:
3461 * the device presents a PAD/Touch interface as most Bamboos and even
3462 * sends ghosts PAD data on it. However, later, we must disable this
3463 * ghost interface, and we can not detect it unless we set it here
3464 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
3465 */
3466 if (features->type == BAMBOO_PEN &&
3467 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
3468 features->device_type |= WACOM_DEVICETYPE_PAD;
3469
3470 /*
Jason Gerecke042628a2015-04-30 17:51:54 -07003471 * Raw Wacom-mode pen and touch events both come from interface
3472 * 0, whose HID descriptor has an application usage of 0xFF0D
Jason Gerecke8de82282016-10-19 18:03:37 -07003473 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
Jason Gerecke042628a2015-04-30 17:51:54 -07003474 * out through the HID_GENERIC device created for interface 1,
Benjamin Tissoires70caee0a2015-07-09 14:11:51 -04003475 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
Ping Cheng42f4f272015-04-15 16:53:54 -07003476 */
3477 if (features->type == BAMBOO_PAD)
Benjamin Tissoires70caee0a2015-07-09 14:11:51 -04003478 features->device_type = WACOM_DEVICETYPE_TOUCH;
Ping Cheng42f4f272015-04-15 16:53:54 -07003479
Aaron Skomra72b236d2015-08-20 16:05:17 -07003480 if (features->type == REMOTE)
3481 features->device_type = WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07003482
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003483 if (features->type == INTUOSP2_BT ||
3484 features->type == INTUOSP2S_BT) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08003485 features->device_type |= WACOM_DEVICETYPE_PEN |
3486 WACOM_DEVICETYPE_PAD |
3487 WACOM_DEVICETYPE_TOUCH;
3488 features->quirks |= WACOM_QUIRK_BATTERY;
3489 }
3490
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08003491 if (features->type == INTUOSHT3_BT) {
3492 features->device_type |= WACOM_DEVICETYPE_PEN |
3493 WACOM_DEVICETYPE_PAD;
3494 features->quirks |= WACOM_QUIRK_BATTERY;
3495 }
3496
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003497 switch (features->type) {
3498 case PL:
3499 case DTU:
3500 case DTUS:
3501 case DTUSX:
3502 case WACOM_21UX2:
3503 case WACOM_22HD:
3504 case DTK:
3505 case WACOM_24HD:
3506 case WACOM_27QHD:
3507 case CINTIQ_HYBRID:
3508 case CINTIQ_COMPANION_2:
3509 case CINTIQ:
3510 case WACOM_BEE:
3511 case WACOM_13HD:
3512 case WACOM_24HDT:
3513 case WACOM_27QHDT:
3514 case TABLETPC:
3515 case TABLETPCE:
3516 case TABLETPC2FG:
3517 case MTSCREEN:
3518 case MTTPC:
3519 case MTTPC_B:
3520 features->device_type |= WACOM_DEVICETYPE_DIRECT;
3521 break;
3522 }
3523
Ping Cheng42f4f272015-04-15 16:53:54 -07003524 if (wacom->hdev->bus == BUS_BLUETOOTH)
3525 features->quirks |= WACOM_QUIRK_BATTERY;
3526
Chris Bagwell73149ab2011-10-26 22:34:21 -07003527 /* quirk for bamboo touch with 2 low res touches */
Jason Gereckebe853fd2015-12-04 14:45:27 -08003528 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
Chris Bagwell73149ab2011-10-26 22:34:21 -07003529 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07003530 features->x_max <<= 5;
3531 features->y_max <<= 5;
3532 features->x_fuzz <<= 5;
3533 features->y_fuzz <<= 5;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07003534 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003535 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07003536
3537 if (features->type == WIRELESS) {
Jason Gereckeccad85c2015-08-03 10:17:04 -07003538 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003539 features->quirks |= WACOM_QUIRK_BATTERY;
3540 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07003541 }
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02003542
3543 if (features->type == REMOTE)
3544 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
Jason Gerecke11db8172018-10-10 13:40:26 -07003545
3546 /* HID descriptor for DTK-2451 / DTH-2452 claims to report lots
3547 * of things it shouldn't. Lets fix up the damage...
3548 */
3549 if (wacom->hdev->product == 0x382 || wacom->hdev->product == 0x37d) {
3550 features->quirks &= ~WACOM_QUIRK_TOOLSERIAL;
3551 __clear_bit(BTN_TOOL_BRUSH, wacom_wac->pen_input->keybit);
3552 __clear_bit(BTN_TOOL_PENCIL, wacom_wac->pen_input->keybit);
3553 __clear_bit(BTN_TOOL_AIRBRUSH, wacom_wac->pen_input->keybit);
3554 __clear_bit(ABS_Z, wacom_wac->pen_input->absbit);
3555 __clear_bit(ABS_DISTANCE, wacom_wac->pen_input->absbit);
3556 __clear_bit(ABS_TILT_X, wacom_wac->pen_input->absbit);
3557 __clear_bit(ABS_TILT_Y, wacom_wac->pen_input->absbit);
3558 __clear_bit(ABS_WHEEL, wacom_wac->pen_input->absbit);
3559 __clear_bit(ABS_MISC, wacom_wac->pen_input->absbit);
3560 __clear_bit(MSC_SERIAL, wacom_wac->pen_input->mscbit);
3561 __clear_bit(EV_MSC, wacom_wac->pen_input->evbit);
3562 }
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003563}
3564
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003565int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
Ping Cheng19635182012-04-29 21:09:18 -07003566 struct wacom_wac *wacom_wac)
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003567{
3568 struct wacom_features *features = &wacom_wac->features;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003569
3570 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3571
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003572 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
3573 return -ENODEV;
3574
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003575 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3576 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3577 else
3578 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3579
Jason Gerecke9e429d52017-11-07 08:25:17 -08003580 if (features->type == HID_GENERIC) {
3581 /* setup has already been done; apply otherwise-undetectible quirks */
3582 input_set_capability(input_dev, EV_KEY, BTN_STYLUS3);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04003583 return 0;
Jason Gerecke9e429d52017-11-07 08:25:17 -08003584 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04003585
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003586 __set_bit(BTN_TOUCH, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003587 __set_bit(ABS_MISC, input_dev->absbit);
3588
Jason Gereckee779ef22016-10-19 18:03:49 -07003589 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
3590 features->x_max - features->offset_right,
3591 features->x_fuzz, 0);
3592 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
3593 features->y_max - features->offset_bottom,
3594 features->y_fuzz, 0);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003595 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
3596 features->pressure_max, features->pressure_fuzz, 0);
3597
3598 /* penabled devices have fixed resolution for each model */
3599 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
3600 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
3601
Ping Cheng497ab1f2014-01-20 20:18:04 -08003602 switch (features->type) {
Ping Chenga2f71c62015-01-27 13:29:36 -08003603 case GRAPHIRE_BT:
3604 __clear_bit(ABS_MISC, input_dev->absbit);
Gustavo A. R. Silva1da92d42019-02-11 16:04:22 -06003605 /* fall through */
Ping Chenga2f71c62015-01-27 13:29:36 -08003606
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003607 case WACOM_MO:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003608 case WACOM_G4:
Ping Chenga2f71c62015-01-27 13:29:36 -08003609 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3610 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003611 features->distance_fuzz, 0);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003612 /* fall through */
3613
3614 case GRAPHIRE:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003615 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3616
3617 __set_bit(BTN_LEFT, input_dev->keybit);
3618 __set_bit(BTN_RIGHT, input_dev->keybit);
3619 __set_bit(BTN_MIDDLE, input_dev->keybit);
3620
3621 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3622 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3623 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3624 __set_bit(BTN_STYLUS, input_dev->keybit);
3625 __set_bit(BTN_STYLUS2, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003626 break;
3627
Ping Cheng500d4162015-01-27 13:30:03 -08003628 case WACOM_27QHD:
Jason Gerecke803296b2011-12-12 00:11:45 -08003629 case WACOM_24HD:
Ping Chenga112e9f2013-02-13 20:20:01 -08003630 case DTK:
Ping Chengd838c642012-07-24 23:54:11 -07003631 case WACOM_22HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003632 case WACOM_21UX2:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003633 case WACOM_BEE:
Ping Cheng6521d0b2010-10-24 21:53:40 -07003634 case CINTIQ:
Ping Cheng56218562013-05-05 19:56:18 -07003635 case WACOM_13HD:
Ping Chenga2f71c62015-01-27 13:29:36 -08003636 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003637 case CINTIQ_COMPANION_2:
Ping Cheng56218562013-05-05 19:56:18 -07003638 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003639 input_abs_set_res(input_dev, ABS_Z, 287);
Ping Cheng56218562013-05-05 19:56:18 -07003640 wacom_setup_cintiq(wacom_wac);
3641 break;
3642
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003643 case INTUOS3:
3644 case INTUOS3L:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003645 case INTUOS3S:
Ping Chenga2f71c62015-01-27 13:29:36 -08003646 case INTUOS4:
3647 case INTUOS4WL:
3648 case INTUOS4L:
3649 case INTUOS4S:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003650 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003651 input_abs_set_res(input_dev, ABS_Z, 287);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003652 /* fall through */
3653
3654 case INTUOS:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003655 wacom_setup_intuos(wacom_wac);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003656 break;
3657
Jason Gerecke9fee6192012-04-03 15:47:22 -07003658 case INTUOS5:
3659 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07003660 case INTUOSPM:
3661 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07003662 case INTUOS5S:
Ping Cheng9a35c412013-09-20 09:51:56 -07003663 case INTUOSPS:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003664 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003665 case INTUOSP2S_BT:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003666 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3667 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003668 features->distance_fuzz, 0);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003669
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003670 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
3671 input_abs_set_res(input_dev, ABS_Z, 287);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003672
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003673 wacom_setup_intuos(wacom_wac);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003674 break;
3675
Jason Gereckeb1e42792012-10-21 00:38:04 -07003676 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08003677 case WACOM_27QHDT:
Ping Cheng19635182012-04-29 21:09:18 -07003678 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07003679 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07003680 case MTTPC_B:
Ping Cheng6795a522012-06-28 16:49:00 -07003681 case TABLETPC2FG:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003682 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07003683 case TABLETPCE:
Ping Chenga43c7c52011-03-12 20:34:42 -08003684 __clear_bit(ABS_MISC, input_dev->absbit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003685 /* fall through */
3686
Ping Cheng497ab1f2014-01-20 20:18:04 -08003687 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08003688 case DTUSX:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003689 case PL:
Ping Chengc8f2edc2010-06-28 01:10:51 -07003690 case DTU:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003691 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003692 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003693 __set_bit(BTN_STYLUS, input_dev->keybit);
3694 __set_bit(BTN_STYLUS2, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003695 break;
3696
3697 case PTU:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003698 __set_bit(BTN_STYLUS2, input_dev->keybit);
3699 /* fall through */
3700
3701 case PENPARTNER:
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003702 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003703 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003704 __set_bit(BTN_STYLUS, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003705 break;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003706
Ping Chengb5fd2a32013-11-25 18:44:55 -08003707 case INTUOSHT:
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003708 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003709 case BAMBOO_PEN:
Ping Chengeda01da2015-09-23 13:51:15 -07003710 case INTUOSHT2:
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08003711 case INTUOSHT3_BT:
3712 if (features->type == INTUOSHT2 ||
3713 features->type == INTUOSHT3_BT) {
Ping Chengeda01da2015-09-23 13:51:15 -07003714 wacom_setup_basic_pro_pen(wacom_wac);
3715 } else {
3716 __clear_bit(ABS_MISC, input_dev->absbit);
3717 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3718 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3719 __set_bit(BTN_STYLUS, input_dev->keybit);
3720 __set_bit(BTN_STYLUS2, input_dev->keybit);
3721 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003722 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003723 features->distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07003724 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003725 break;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003726 case BAMBOO_PAD:
3727 __clear_bit(ABS_MISC, input_dev->absbit);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003728 break;
3729 }
3730 return 0;
3731}
3732
3733int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3734 struct wacom_wac *wacom_wac)
3735{
3736 struct wacom_features *features = &wacom_wac->features;
3737
3738 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3739
3740 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3741 return -ENODEV;
3742
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003743 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3744 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3745 else
3746 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3747
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003748 if (features->type == HID_GENERIC)
3749 /* setup has already been done */
3750 return 0;
3751
3752 __set_bit(BTN_TOUCH, input_dev->keybit);
3753
3754 if (features->touch_max == 1) {
3755 input_set_abs_params(input_dev, ABS_X, 0,
3756 features->x_max, features->x_fuzz, 0);
3757 input_set_abs_params(input_dev, ABS_Y, 0,
3758 features->y_max, features->y_fuzz, 0);
3759 input_abs_set_res(input_dev, ABS_X,
3760 features->x_resolution);
3761 input_abs_set_res(input_dev, ABS_Y,
3762 features->y_resolution);
3763 }
3764 else if (features->touch_max > 1) {
3765 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3766 features->x_max, features->x_fuzz, 0);
3767 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3768 features->y_max, features->y_fuzz, 0);
3769 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3770 features->x_resolution);
3771 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3772 features->y_resolution);
3773 }
3774
3775 switch (features->type) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08003776 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003777 case INTUOSP2S_BT:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003778 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3779 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3780
3781 if (wacom_wac->shared->touch->product == 0x361) {
3782 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3783 0, 12440, 4, 0);
3784 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3785 0, 8640, 4, 0);
3786 }
3787 else if (wacom_wac->shared->touch->product == 0x360) {
3788 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3789 0, 8960, 4, 0);
3790 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3791 0, 5920, 4, 0);
3792 }
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003793 else if (wacom_wac->shared->touch->product == 0x393) {
3794 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3795 0, 6400, 4, 0);
3796 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3797 0, 4000, 4, 0);
3798 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08003799 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
Aaron Armstrong Skomra68c20cc2019-05-10 15:34:18 -07003800 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, 40);
Jason Gerecke4922cd22017-01-25 12:08:37 -08003801
3802 /* fall through */
3803
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003804 case INTUOS5:
3805 case INTUOS5L:
3806 case INTUOSPM:
3807 case INTUOSPL:
3808 case INTUOS5S:
3809 case INTUOSPS:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003810 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3811 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3812 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3813 break;
3814
3815 case WACOM_24HDT:
3816 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3817 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3818 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3819 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
3820 /* fall through */
3821
3822 case WACOM_27QHDT:
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07003823 if (wacom_wac->shared->touch->product == 0x32C ||
3824 wacom_wac->shared->touch->product == 0xF6) {
3825 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3826 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3827 wacom_wac->shared->has_mute_touch_switch = true;
3828 }
3829 /* fall through */
3830
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003831 case MTSCREEN:
3832 case MTTPC:
3833 case MTTPC_B:
3834 case TABLETPC2FG:
3835 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
3836 /*fall through */
3837
3838 case TABLETPC:
3839 case TABLETPCE:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003840 break;
3841
3842 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07003843 case INTUOSHT2:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003844 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3845 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3846 /* fall through */
3847
3848 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003849 case BAMBOO_TOUCH:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003850 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3851 input_set_abs_params(input_dev,
3852 ABS_MT_TOUCH_MAJOR,
3853 0, features->x_max, 0, 0);
3854 input_set_abs_params(input_dev,
3855 ABS_MT_TOUCH_MINOR,
3856 0, features->y_max, 0, 0);
3857 }
3858 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3859 break;
3860
3861 case BAMBOO_PAD:
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003862 input_mt_init_slots(input_dev, features->touch_max,
3863 INPUT_MT_POINTER);
3864 __set_bit(BTN_LEFT, input_dev->keybit);
3865 __set_bit(BTN_RIGHT, input_dev->keybit);
3866 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07003867 }
Ping Cheng19635182012-04-29 21:09:18 -07003868 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07003869}
3870
Jason Gerecke49005b92016-10-19 18:03:39 -07003871static int wacom_numbered_button_to_key(int n)
3872{
3873 if (n < 10)
3874 return BTN_0 + n;
3875 else if (n < 16)
3876 return BTN_A + (n-10);
3877 else if (n < 18)
3878 return BTN_BASE + (n-16);
3879 else
3880 return 0;
3881}
3882
Jiri Kosina5397df12015-08-28 20:46:42 +02003883static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003884 int button_count)
3885{
3886 int i;
3887
Jason Gerecke49005b92016-10-19 18:03:39 -07003888 for (i = 0; i < button_count; i++) {
3889 int key = wacom_numbered_button_to_key(i);
3890
3891 if (key)
3892 __set_bit(key, input_dev->keybit);
3893 }
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003894}
3895
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003896static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3897{
3898 struct wacom_led *led;
3899 int i;
3900 bool updated = false;
3901
3902 /*
3903 * 24HD has LED group 1 to the left and LED group 0 to the right.
3904 * So group 0 matches the second half of the buttons and thus the mask
3905 * needs to be shifted.
3906 */
3907 if (group == 0)
3908 mask >>= 8;
3909
3910 for (i = 0; i < 3; i++) {
3911 led = wacom_led_find(wacom, group, i);
3912 if (!led) {
3913 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3914 i, group);
3915 continue;
3916 }
3917 if (!updated && mask & BIT(i)) {
3918 led->held = true;
3919 led_trigger_event(&led->trigger, LED_FULL);
3920 } else {
3921 led->held = false;
3922 }
3923 }
3924}
3925
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003926static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
3927 int mask, int group)
3928{
Jason Gerecke6441fc72019-05-07 11:53:21 -07003929 int group_button;
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003930
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003931 /*
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003932 * 21UX2 has LED group 1 to the left and LED group 0
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003933 * to the right. We need to reverse the group to match this
3934 * historical behavior.
3935 */
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003936 if (wacom->wacom_wac.features.type == WACOM_21UX2)
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003937 group = 1 - group;
3938
Jason Gerecke6441fc72019-05-07 11:53:21 -07003939 group_button = group * (button_count/wacom->led.count);
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003940
Jason Gerecke6441fc72019-05-07 11:53:21 -07003941 if (wacom->wacom_wac.features.type == INTUOSP2_BT)
3942 group_button = 8;
3943
3944 return mask & (1 << group_button);
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003945}
3946
3947static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
3948 int group)
3949{
3950 struct wacom_led *led, *next_led;
3951 int cur;
3952 bool pressed;
3953
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003954 if (wacom->wacom_wac.features.type == WACOM_24HD)
3955 return wacom_24hd_update_leds(wacom, mask, group);
3956
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003957 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
3958 cur = wacom->led.groups[group].select;
3959
3960 led = wacom_led_find(wacom, group, cur);
3961 if (!led) {
3962 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
3963 cur, group);
3964 return;
3965 }
3966
3967 if (!pressed) {
3968 led->held = false;
3969 return;
3970 }
3971
3972 if (led->held && pressed)
3973 return;
3974
3975 next_led = wacom_led_next(wacom, led);
3976 if (!next_led) {
3977 hid_err(wacom->hdev, "can't find next LED in group %d\n",
3978 group);
3979 return;
3980 }
3981 if (next_led == led)
3982 return;
3983
3984 next_led->held = true;
3985 led_trigger_event(&next_led->trigger,
3986 wacom_leds_brightness_get(next_led));
3987}
3988
Jason Gereckec7f05222015-11-30 17:13:47 -08003989static void wacom_report_numbered_buttons(struct input_dev *input_dev,
3990 int button_count, int mask)
3991{
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003992 struct wacom *wacom = input_get_drvdata(input_dev);
Jason Gereckec7f05222015-11-30 17:13:47 -08003993 int i;
3994
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003995 for (i = 0; i < wacom->led.count; i++)
3996 wacom_update_led(wacom, button_count, mask, i);
3997
Jason Gerecke49005b92016-10-19 18:03:39 -07003998 for (i = 0; i < button_count; i++) {
3999 int key = wacom_numbered_button_to_key(i);
4000
4001 if (key)
4002 input_report_key(input_dev, key, mask & (1 << i));
4003 }
Jason Gereckec7f05222015-11-30 17:13:47 -08004004}
4005
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004006int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
4007 struct wacom_wac *wacom_wac)
4008{
4009 struct wacom_features *features = &wacom_wac->features;
4010
Ping Chenge7deb152017-01-30 15:40:49 -08004011 if ((features->type == HID_GENERIC) && features->numbered_buttons > 0)
4012 features->device_type |= WACOM_DEVICETYPE_PAD;
4013
Jason Gerecke862cf552015-06-15 18:01:43 -07004014 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
4015 return -ENODEV;
4016
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02004017 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
4018 return -ENODEV;
4019
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004020 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
4021
4022 /* kept for making legacy xf86-input-wacom working with the wheels */
4023 __set_bit(ABS_MISC, input_dev->absbit);
4024
4025 /* kept for making legacy xf86-input-wacom accepting the pad */
Jason Gerecke5922e612016-10-19 18:03:51 -07004026 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
4027 input_dev->absinfo[ABS_X].maximum)))
4028 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
4029 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
4030 input_dev->absinfo[ABS_Y].maximum)))
4031 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004032
Benjamin Tissoires12969e32014-09-11 13:14:04 -04004033 /* kept for making udev and libwacom accepting the pad */
4034 __set_bit(BTN_STYLUS, input_dev->keybit);
4035
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004036 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
4037
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004038 switch (features->type) {
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004039
4040 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07004041 case CINTIQ_COMPANION_2:
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004042 case DTK:
4043 case DTUS:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004044 case GRAPHIRE_BT:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004045 break;
4046
Benjamin Tissoires38138102014-07-24 12:51:03 -07004047 case WACOM_MO:
4048 __set_bit(BTN_BACK, input_dev->keybit);
4049 __set_bit(BTN_LEFT, input_dev->keybit);
4050 __set_bit(BTN_FORWARD, input_dev->keybit);
4051 __set_bit(BTN_RIGHT, input_dev->keybit);
4052 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4053 break;
4054
4055 case WACOM_G4:
4056 __set_bit(BTN_BACK, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07004057 __set_bit(BTN_FORWARD, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07004058 input_set_capability(input_dev, EV_REL, REL_WHEEL);
4059 break;
4060
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004061 case WACOM_24HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004062 __set_bit(KEY_PROG1, input_dev->keybit);
4063 __set_bit(KEY_PROG2, input_dev->keybit);
4064 __set_bit(KEY_PROG3, input_dev->keybit);
4065
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07004066 __set_bit(KEY_ONSCREEN_KEYBOARD, input_dev->keybit);
4067 __set_bit(KEY_INFO, input_dev->keybit);
4068
4069 if (!features->oPid)
4070 __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
4071
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004072 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4073 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
4074 break;
4075
Ping Cheng500d4162015-01-27 13:30:03 -08004076 case WACOM_27QHD:
4077 __set_bit(KEY_PROG1, input_dev->keybit);
4078 __set_bit(KEY_PROG2, input_dev->keybit);
4079 __set_bit(KEY_PROG3, input_dev->keybit);
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07004080
4081 __set_bit(KEY_ONSCREEN_KEYBOARD, input_dev->keybit);
4082 __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
4083
4084 if (!features->oPid)
4085 __set_bit(KEY_CONTROLPANEL, input_dev->keybit);
Ping Cheng500d4162015-01-27 13:30:03 -08004086 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
4087 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
4088 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
4089 input_abs_set_res(input_dev, ABS_Y, 1024);
4090 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
4091 input_abs_set_res(input_dev, ABS_Z, 1024);
4092 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
4093 break;
4094
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004095 case WACOM_22HD:
4096 __set_bit(KEY_PROG1, input_dev->keybit);
4097 __set_bit(KEY_PROG2, input_dev->keybit);
4098 __set_bit(KEY_PROG3, input_dev->keybit);
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07004099
4100 __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
4101 __set_bit(KEY_INFO, input_dev->keybit);
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004102 /* fall through */
4103
4104 case WACOM_21UX2:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004105 case WACOM_BEE:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004106 case CINTIQ:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004107 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
4108 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
4109 break;
4110
4111 case WACOM_13HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004112 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4113 break;
4114
4115 case INTUOS3:
4116 case INTUOS3L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004117 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
4118 /* fall through */
4119
4120 case INTUOS3S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004121 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
4122 break;
4123
4124 case INTUOS5:
4125 case INTUOS5L:
4126 case INTUOSPM:
4127 case INTUOSPL:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004128 case INTUOS5S:
4129 case INTUOSPS:
Jason Gerecke4922cd22017-01-25 12:08:37 -08004130 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07004131 case INTUOSP2S_BT:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004132 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4133 break;
4134
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004135 case INTUOS4WL:
4136 /*
4137 * For Bluetooth devices, the udev rule does not work correctly
4138 * for pads unless we add a stylus capability, which forces
4139 * ID_INPUT_TABLET to be set.
4140 */
4141 __set_bit(BTN_STYLUS, input_dev->keybit);
4142 /* fall through */
4143
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004144 case INTUOS4:
4145 case INTUOS4L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004146 case INTUOS4S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004147 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4148 break;
4149
Benjamin Tissoires31168712014-07-24 12:50:10 -07004150 case INTUOSHT:
4151 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07004152 case BAMBOO_TOUCH:
Ping Chengeda01da2015-09-23 13:51:15 -07004153 case INTUOSHT2:
Benjamin Tissoires31168712014-07-24 12:50:10 -07004154 __clear_bit(ABS_MISC, input_dev->absbit);
4155
4156 __set_bit(BTN_LEFT, input_dev->keybit);
4157 __set_bit(BTN_FORWARD, input_dev->keybit);
4158 __set_bit(BTN_BACK, input_dev->keybit);
4159 __set_bit(BTN_RIGHT, input_dev->keybit);
4160
4161 break;
4162
Aaron Skomra72b236d2015-08-20 16:05:17 -07004163 case REMOTE:
4164 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
4165 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4166 break;
4167
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08004168 case INTUOSHT3_BT:
Jason Gerecke5922e612016-10-19 18:03:51 -07004169 case HID_GENERIC:
4170 break;
4171
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004172 default:
4173 /* no pad supported */
Ping Chengb3c8e932014-11-18 13:27:48 -08004174 return -ENODEV;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004175 }
4176 return 0;
4177}
4178
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004179static const struct wacom_features wacom_features_0x00 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004180 { "Wacom Penpartner", 5040, 3780, 255, 0,
4181 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004182static const struct wacom_features wacom_features_0x10 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004183 { "Wacom Graphire", 10206, 7422, 511, 63,
4184 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004185static const struct wacom_features wacom_features_0x81 =
4186 { "Wacom Graphire BT", 16704, 12064, 511, 32,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004187 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004188static const struct wacom_features wacom_features_0x11 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004189 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
4190 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004191static const struct wacom_features wacom_features_0x12 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004192 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
4193 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004194static const struct wacom_features wacom_features_0x13 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004195 { "Wacom Graphire3", 10208, 7424, 511, 63,
4196 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004197static const struct wacom_features wacom_features_0x14 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004198 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
4199 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004200static const struct wacom_features wacom_features_0x15 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004201 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
4202 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004203static const struct wacom_features wacom_features_0x16 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004204 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
4205 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004206static const struct wacom_features wacom_features_0x17 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004207 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
4208 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004209static const struct wacom_features wacom_features_0x18 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004210 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
4211 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004212static const struct wacom_features wacom_features_0x19 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004213 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
4214 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004215static const struct wacom_features wacom_features_0x60 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004216 { "Wacom Volito", 5104, 3712, 511, 63,
4217 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004218static const struct wacom_features wacom_features_0x61 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004219 { "Wacom PenStation2", 3250, 2320, 255, 63,
4220 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004221static const struct wacom_features wacom_features_0x62 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004222 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
4223 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004224static const struct wacom_features wacom_features_0x63 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004225 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
4226 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004227static const struct wacom_features wacom_features_0x64 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004228 { "Wacom PenPartner2", 3250, 2320, 511, 63,
4229 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004230static const struct wacom_features wacom_features_0x65 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004231 { "Wacom Bamboo", 14760, 9225, 511, 63,
4232 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004233static const struct wacom_features wacom_features_0x69 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004234 { "Wacom Bamboo1", 5104, 3712, 511, 63,
4235 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07004236static const struct wacom_features wacom_features_0x6A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004237 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
4238 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07004239static const struct wacom_features wacom_features_0x6B =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004240 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
4241 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004242static const struct wacom_features wacom_features_0x20 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004243 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
4244 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004245static const struct wacom_features wacom_features_0x21 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004246 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
4247 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004248static const struct wacom_features wacom_features_0x22 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004249 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
4250 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004251static const struct wacom_features wacom_features_0x23 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004252 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
4253 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004254static const struct wacom_features wacom_features_0x24 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004255 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
4256 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004257static const struct wacom_features wacom_features_0x30 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004258 { "Wacom PL400", 5408, 4056, 255, 0,
4259 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004260static const struct wacom_features wacom_features_0x31 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004261 { "Wacom PL500", 6144, 4608, 255, 0,
4262 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004263static const struct wacom_features wacom_features_0x32 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004264 { "Wacom PL600", 6126, 4604, 255, 0,
4265 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004266static const struct wacom_features wacom_features_0x33 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004267 { "Wacom PL600SX", 6260, 5016, 255, 0,
4268 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004269static const struct wacom_features wacom_features_0x34 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004270 { "Wacom PL550", 6144, 4608, 511, 0,
4271 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004272static const struct wacom_features wacom_features_0x35 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004273 { "Wacom PL800", 7220, 5780, 511, 0,
4274 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004275static const struct wacom_features wacom_features_0x37 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004276 { "Wacom PL700", 6758, 5406, 511, 0,
4277 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004278static const struct wacom_features wacom_features_0x38 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004279 { "Wacom PL510", 6282, 4762, 511, 0,
4280 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004281static const struct wacom_features wacom_features_0x39 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004282 { "Wacom DTU710", 34080, 27660, 511, 0,
4283 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004284static const struct wacom_features wacom_features_0xC4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004285 { "Wacom DTF521", 6282, 4762, 511, 0,
4286 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004287static const struct wacom_features wacom_features_0xC0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004288 { "Wacom DTF720", 6858, 5506, 511, 0,
4289 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004290static const struct wacom_features wacom_features_0xC2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004291 { "Wacom DTF720a", 6858, 5506, 511, 0,
4292 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004293static const struct wacom_features wacom_features_0x03 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004294 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
4295 PTU, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004296static const struct wacom_features wacom_features_0x41 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004297 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
4298 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004299static const struct wacom_features wacom_features_0x42 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004300 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4301 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004302static const struct wacom_features wacom_features_0x43 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004303 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
4304 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004305static const struct wacom_features wacom_features_0x44 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004306 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
4307 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004308static const struct wacom_features wacom_features_0x45 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004309 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
4310 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004311static const struct wacom_features wacom_features_0xB0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004312 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004313 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004314static const struct wacom_features wacom_features_0xB1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004315 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004316 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004317static const struct wacom_features wacom_features_0xB2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004318 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004319 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004320static const struct wacom_features wacom_features_0xB3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004321 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004322 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004323static const struct wacom_features wacom_features_0xB4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004324 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004325 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004326static const struct wacom_features wacom_features_0xB5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004327 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004328 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004329static const struct wacom_features wacom_features_0xB7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004330 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004331 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004332static const struct wacom_features wacom_features_0xB8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004333 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004334 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004335static const struct wacom_features wacom_features_0xB9 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004336 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004337 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004338static const struct wacom_features wacom_features_0xBA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004339 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004340 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004341static const struct wacom_features wacom_features_0xBB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004342 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004343 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004344static const struct wacom_features wacom_features_0xBC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004345 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004346 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004347static const struct wacom_features wacom_features_0xBD =
4348 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004349 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004350static const struct wacom_features wacom_features_0x26 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004351 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004352 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004353static const struct wacom_features wacom_features_0x27 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004354 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004355 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004356static const struct wacom_features wacom_features_0x28 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004357 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004358 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004359static const struct wacom_features wacom_features_0x29 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004360 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004361 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004362static const struct wacom_features wacom_features_0x2A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004363 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004364 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng9a35c412013-09-20 09:51:56 -07004365static const struct wacom_features wacom_features_0x314 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004366 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004367 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004368 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07004369static const struct wacom_features wacom_features_0x315 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004370 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004371 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004372 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07004373static const struct wacom_features wacom_features_0x317 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004374 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004375 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004376 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Jason Gerecke803296b2011-12-12 00:11:45 -08004377static const struct wacom_features wacom_features_0xF4 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004378 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004379 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Jason Gereckee779ef22016-10-19 18:03:49 -07004380 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004381 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Jason Gerecke6f4d0382012-08-21 22:11:59 -07004382static const struct wacom_features wacom_features_0xF8 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004383 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004384 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Ping Chengfa770342014-12-01 13:44:28 -08004385 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004386 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07004387 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
Jason Gereckeb1e42792012-10-21 00:38:04 -07004388static const struct wacom_features wacom_features_0xF6 =
4389 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004390 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
4391 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng500d4162015-01-27 13:30:03 -08004392static const struct wacom_features wacom_features_0x32A =
Jason Gereckee779ef22016-10-19 18:03:49 -07004393 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004394 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07004395 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga7e66452015-02-04 16:01:54 -08004396 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng500d4162015-01-27 13:30:03 -08004397static const struct wacom_features wacom_features_0x32B =
Jason Gereckee779ef22016-10-19 18:03:49 -07004398 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004399 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Ping Cheng500d4162015-01-27 13:30:03 -08004400 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004401 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng500d4162015-01-27 13:30:03 -08004402 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
4403static const struct wacom_features wacom_features_0x32C =
4404 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
4405 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004406static const struct wacom_features wacom_features_0x3F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004407 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004408 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004409static const struct wacom_features wacom_features_0xC5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004410 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004411 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004412static const struct wacom_features wacom_features_0xC6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004413 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004414 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Ping Cheng56218562013-05-05 19:56:18 -07004415static const struct wacom_features wacom_features_0x304 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004416 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004417 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Jason Gereckee779ef22016-10-19 18:03:49 -07004418 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004419 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengb4bf2122015-03-25 17:08:13 -07004420static const struct wacom_features wacom_features_0x333 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004421 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004422 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengb4bf2122015-03-25 17:08:13 -07004423 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004424 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengb4bf2122015-03-25 17:08:13 -07004425 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
4426static const struct wacom_features wacom_features_0x335 =
4427 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
4428 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
4429 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004430static const struct wacom_features wacom_features_0xC7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004431 { "Wacom DTU1931", 37832, 30305, 511, 0,
4432 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengc8f2edc2010-06-28 01:10:51 -07004433static const struct wacom_features wacom_features_0xCE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004434 { "Wacom DTU2231", 47864, 27011, 511, 0,
4435 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004436 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
Ping Chengc8f2edc2010-06-28 01:10:51 -07004437static const struct wacom_features wacom_features_0xF0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004438 { "Wacom DTU1631", 34623, 19553, 511, 0,
4439 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng497ab1f2014-01-20 20:18:04 -08004440static const struct wacom_features wacom_features_0xFB =
Jason Gereckee779ef22016-10-19 18:03:49 -07004441 { "Wacom DTU1031", 22096, 13960, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004442 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004443 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004444 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Chengfff00bf2014-12-04 18:23:04 -08004445static const struct wacom_features wacom_features_0x32F =
Jason Gereckee779ef22016-10-19 18:03:49 -07004446 { "Wacom DTU1031X", 22672, 12928, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004447 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07004448 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfff00bf2014-12-04 18:23:04 -08004449 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Aaron Skomra007760c2015-04-16 15:01:14 -07004450static const struct wacom_features wacom_features_0x336 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004451 { "Wacom DTU1141", 23672, 13403, 1023, 0,
Ping Chengff38e822015-11-12 17:21:14 -08004452 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004453 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengff38e822015-11-12 17:21:14 -08004454 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07004455static const struct wacom_features wacom_features_0x57 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004456 { "Wacom DTK2241", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004457 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Jason Gereckee779ef22016-10-19 18:03:49 -07004458 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004459 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chenga112e9f2013-02-13 20:20:01 -08004460static const struct wacom_features wacom_features_0x59 = /* Pen */
Jason Gereckee779ef22016-10-19 18:03:49 -07004461 { "Wacom DTH2242", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004462 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Ping Chengfa770342014-12-01 13:44:28 -08004463 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004464 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga112e9f2013-02-13 20:20:01 -08004465 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
4466static const struct wacom_features wacom_features_0x5D = /* Touch */
4467 { "Wacom DTH2242", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004468 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
4469 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004470static const struct wacom_features wacom_features_0xCC =
Jason Gereckee779ef22016-10-19 18:03:49 -07004471 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004472 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07004473 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004474 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengd838c642012-07-24 23:54:11 -07004475static const struct wacom_features wacom_features_0xFA =
Jason Gereckee779ef22016-10-19 18:03:49 -07004476 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004477 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07004478 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004479 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07004480static const struct wacom_features wacom_features_0x5B =
Jason Gereckee779ef22016-10-19 18:03:49 -07004481 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004482 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Ping Chengfa770342014-12-01 13:44:28 -08004483 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004484 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07004485 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
Ping Cheng56218562013-05-05 19:56:18 -07004486static const struct wacom_features wacom_features_0x5E =
4487 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004488 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
4489 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004490static const struct wacom_features wacom_features_0x90 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004491 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004492 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004493static const struct wacom_features wacom_features_0x93 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004494 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004495 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Ping Cheng11d0cf82011-06-27 12:57:58 -07004496static const struct wacom_features wacom_features_0x97 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004497 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004498 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004499static const struct wacom_features wacom_features_0x9A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004500 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004501 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004502static const struct wacom_features wacom_features_0x9F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004503 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004504 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004505static const struct wacom_features wacom_features_0xE2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004506 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
4507 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004508static const struct wacom_features wacom_features_0xE3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004509 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
4510 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng19635182012-04-29 21:09:18 -07004511static const struct wacom_features wacom_features_0xE5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004512 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
4513 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07004514static const struct wacom_features wacom_features_0xE6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004515 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
4516 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell0d0e3062011-12-11 23:50:59 -08004517static const struct wacom_features wacom_features_0xEC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004518 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004519 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Ping Chengac173832012-06-12 00:15:06 -07004520static const struct wacom_features wacom_features_0xED =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004521 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004522 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Ping Chengac173832012-06-12 00:15:06 -07004523static const struct wacom_features wacom_features_0xEF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004524 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004525 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Ping Cheng6afdc282012-11-03 12:16:15 -07004526static const struct wacom_features wacom_features_0x100 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004527 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
4528 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng6afdc282012-11-03 12:16:15 -07004529static const struct wacom_features wacom_features_0x101 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004530 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
4531 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Stephan Frank58694832013-03-07 14:08:50 -08004532static const struct wacom_features wacom_features_0x10D =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004533 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
4534 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke2d3163f2013-10-22 15:35:30 -07004535static const struct wacom_features wacom_features_0x10E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004536 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
4537 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07004538static const struct wacom_features wacom_features_0x10F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004539 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
4540 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke61616ed2014-05-14 11:42:22 -07004541static const struct wacom_features wacom_features_0x116 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004542 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004543 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07004544static const struct wacom_features wacom_features_0x12C =
4545 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004546 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Ping Chengedbe2652012-11-21 13:12:50 -08004547static const struct wacom_features wacom_features_0x4001 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004548 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
4549 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004550static const struct wacom_features wacom_features_0x4004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004551 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
4552 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004553static const struct wacom_features wacom_features_0x5000 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004554 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
4555 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004556static const struct wacom_features wacom_features_0x5002 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004557 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
4558 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004559static const struct wacom_features wacom_features_0x47 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004560 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4561 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwelld3825d52012-03-25 23:26:11 -07004562static const struct wacom_features wacom_features_0x84 =
Ping Cheng3b164a02015-09-23 09:59:10 -07004563 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004564static const struct wacom_features wacom_features_0xD0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004565 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004566 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004567static const struct wacom_features wacom_features_0xD1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004568 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
4569 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004570static const struct wacom_features wacom_features_0xD2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004571 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
4572 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004573static const struct wacom_features wacom_features_0xD3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004574 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
4575 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Kevin Granade57a78722010-12-10 23:04:02 -08004576static const struct wacom_features wacom_features_0xD4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004577 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004578 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Gerard Braad18adad12011-08-16 00:17:56 -07004579static const struct wacom_features wacom_features_0xD5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004580 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004581 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004582static const struct wacom_features wacom_features_0xD6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004583 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
4584 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004585static const struct wacom_features wacom_features_0xD7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004586 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
4587 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004588static const struct wacom_features wacom_features_0xD8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004589 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
4590 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004591static const struct wacom_features wacom_features_0xDA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004592 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
4593 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Chengf41a64e2013-08-21 09:14:49 -07004594static const struct wacom_features wacom_features_0xDB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004595 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
4596 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004597static const struct wacom_features wacom_features_0xDD =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004598 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
4599 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004600static const struct wacom_features wacom_features_0xDE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004601 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
4602 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004603static const struct wacom_features wacom_features_0xDF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004604 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
4605 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Ping Chengf41a64e2013-08-21 09:14:49 -07004606static const struct wacom_features wacom_features_0x300 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004607 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004608 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengf41a64e2013-08-21 09:14:49 -07004609static const struct wacom_features wacom_features_0x301 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004610 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
Aaron Armstrong Skomrab79cbc52017-03-29 13:07:36 -07004611 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004612static const struct wacom_features wacom_features_0x302 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004613 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
4614 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004615 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004616static const struct wacom_features wacom_features_0x303 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004617 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
4618 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004619 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004620static const struct wacom_features wacom_features_0x30E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004621 { "Wacom Intuos S", 15200, 9500, 1023, 31,
4622 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004623 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004624static const struct wacom_features wacom_features_0x6004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004625 { "ISD-V4", 12800, 8000, 255, 0,
4626 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004627static const struct wacom_features wacom_features_0x307 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004628 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004629 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08004630 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004631 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gerecke36d3c512013-09-20 09:47:35 -07004632 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004633static const struct wacom_features wacom_features_0x309 =
Jason Gerecke36d3c512013-09-20 09:47:35 -07004634 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004635 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
4636 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004637static const struct wacom_features wacom_features_0x30A =
Jason Gereckee779ef22016-10-19 18:03:49 -07004638 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004639 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08004640 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004641 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004642 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
4643static const struct wacom_features wacom_features_0x30C =
4644 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
4645 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
4646 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004647static const struct wacom_features wacom_features_0x318 =
4648 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
4649 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
4650static const struct wacom_features wacom_features_0x319 =
4651 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
4652 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
Jason Gereckef7acb552015-10-13 10:03:49 -07004653static const struct wacom_features wacom_features_0x325 =
4654 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
4655 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
4656 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004657 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckef7acb552015-10-13 10:03:49 -07004658 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
4659static const struct wacom_features wacom_features_0x326 = /* Touch */
4660 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
4661 .oPid = 0x325 };
Ping Chengfefb3912014-11-11 12:52:08 -08004662static const struct wacom_features wacom_features_0x323 =
4663 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
4664 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4665 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Aaron Skomra72b236d2015-08-20 16:05:17 -07004666static const struct wacom_features wacom_features_0x331 =
Ping Cheng3b164a02015-09-23 09:59:10 -07004667 { "Wacom Express Key Remote", .type = REMOTE,
4668 .numbered_buttons = 18, .check_for_hid_type = true,
Aaron Skomra72b236d2015-08-20 16:05:17 -07004669 .hid_type = HID_TYPE_USBNONE };
Ping Chengeda01da2015-09-23 13:51:15 -07004670static const struct wacom_features wacom_features_0x33B =
4671 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
4672 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4673 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4674static const struct wacom_features wacom_features_0x33C =
4675 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
4676 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4677 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4678static const struct wacom_features wacom_features_0x33D =
4679 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
4680 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4681 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4682static const struct wacom_features wacom_features_0x33E =
4683 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
4684 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4685 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chenge1123fe2016-04-12 13:37:45 -07004686static const struct wacom_features wacom_features_0x343 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004687 { "Wacom DTK1651", 34816, 19759, 1023, 0,
Ping Chenge1123fe2016-04-12 13:37:45 -07004688 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004689 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chenge1123fe2016-04-12 13:37:45 -07004690 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Jason Gerecke4922cd22017-01-25 12:08:37 -08004691static const struct wacom_features wacom_features_0x360 =
4692 { "Wacom Intuos Pro M", 44800, 29600, 8191, 63,
Aaron Armstrong Skomra49cc4c22017-03-06 10:54:57 -08004693 INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
Jason Gerecke4922cd22017-01-25 12:08:37 -08004694static const struct wacom_features wacom_features_0x361 =
4695 { "Wacom Intuos Pro L", 62200, 43200, 8191, 63,
Aaron Armstrong Skomra49cc4c22017-03-06 10:54:57 -08004696 INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08004697static const struct wacom_features wacom_features_0x377 =
4698 { "Wacom Intuos BT S", 15200, 9500, 4095, 63,
4699 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
4700static const struct wacom_features wacom_features_0x379 =
4701 { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
4702 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
Jason Gereckec9472182017-12-26 15:50:18 -08004703static const struct wacom_features wacom_features_0x37A =
4704 { "Wacom One by Wacom S", 15200, 9500, 2047, 63,
4705 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4706static const struct wacom_features wacom_features_0x37B =
4707 { "Wacom One by Wacom M", 21600, 13500, 2047, 63,
4708 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07004709static const struct wacom_features wacom_features_0x393 =
4710 { "Wacom Intuos Pro S", 31920, 19950, 8191, 63,
4711 INTUOSP2S_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7,
4712 .touch_max = 10 };
Bastian Blankb036f6f2010-02-10 23:06:23 -08004713
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004714static const struct wacom_features wacom_features_HID_ANY_ID =
Jason Gerecke41372d52016-08-08 12:06:30 -07004715 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004716
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004717#define USB_DEVICE_WACOM(prod) \
4718 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4719 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Bastian Blankb036f6f2010-02-10 23:06:23 -08004720
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004721#define BT_DEVICE_WACOM(prod) \
4722 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4723 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Aristeu Rozanski1483f552011-06-22 01:17:17 -07004724
Mika Westerbergeef23a82015-02-23 15:52:43 +02004725#define I2C_DEVICE_WACOM(prod) \
4726 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4727 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4728
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004729#define USB_DEVICE_LENOVO(prod) \
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004730 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
4731 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004732
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004733const struct hid_device_id wacom_ids[] = {
Bastian Blankb036f6f2010-02-10 23:06:23 -08004734 { USB_DEVICE_WACOM(0x00) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004735 { USB_DEVICE_WACOM(0x03) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004736 { USB_DEVICE_WACOM(0x10) },
4737 { USB_DEVICE_WACOM(0x11) },
4738 { USB_DEVICE_WACOM(0x12) },
4739 { USB_DEVICE_WACOM(0x13) },
4740 { USB_DEVICE_WACOM(0x14) },
4741 { USB_DEVICE_WACOM(0x15) },
4742 { USB_DEVICE_WACOM(0x16) },
4743 { USB_DEVICE_WACOM(0x17) },
4744 { USB_DEVICE_WACOM(0x18) },
4745 { USB_DEVICE_WACOM(0x19) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004746 { USB_DEVICE_WACOM(0x20) },
4747 { USB_DEVICE_WACOM(0x21) },
4748 { USB_DEVICE_WACOM(0x22) },
4749 { USB_DEVICE_WACOM(0x23) },
4750 { USB_DEVICE_WACOM(0x24) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004751 { USB_DEVICE_WACOM(0x26) },
4752 { USB_DEVICE_WACOM(0x27) },
4753 { USB_DEVICE_WACOM(0x28) },
4754 { USB_DEVICE_WACOM(0x29) },
4755 { USB_DEVICE_WACOM(0x2A) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004756 { USB_DEVICE_WACOM(0x30) },
4757 { USB_DEVICE_WACOM(0x31) },
4758 { USB_DEVICE_WACOM(0x32) },
4759 { USB_DEVICE_WACOM(0x33) },
4760 { USB_DEVICE_WACOM(0x34) },
4761 { USB_DEVICE_WACOM(0x35) },
4762 { USB_DEVICE_WACOM(0x37) },
4763 { USB_DEVICE_WACOM(0x38) },
4764 { USB_DEVICE_WACOM(0x39) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004765 { USB_DEVICE_WACOM(0x3F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004766 { USB_DEVICE_WACOM(0x41) },
4767 { USB_DEVICE_WACOM(0x42) },
4768 { USB_DEVICE_WACOM(0x43) },
4769 { USB_DEVICE_WACOM(0x44) },
4770 { USB_DEVICE_WACOM(0x45) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004771 { USB_DEVICE_WACOM(0x47) },
Ping Cheng56218562013-05-05 19:56:18 -07004772 { USB_DEVICE_WACOM(0x57) },
Ping Chenga112e9f2013-02-13 20:20:01 -08004773 { USB_DEVICE_WACOM(0x59) },
Ping Cheng56218562013-05-05 19:56:18 -07004774 { USB_DEVICE_WACOM(0x5B) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004775 { USB_DEVICE_WACOM(0x5D) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004776 { USB_DEVICE_WACOM(0x5E) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004777 { USB_DEVICE_WACOM(0x60) },
4778 { USB_DEVICE_WACOM(0x61) },
4779 { USB_DEVICE_WACOM(0x62) },
4780 { USB_DEVICE_WACOM(0x63) },
4781 { USB_DEVICE_WACOM(0x64) },
4782 { USB_DEVICE_WACOM(0x65) },
4783 { USB_DEVICE_WACOM(0x69) },
4784 { USB_DEVICE_WACOM(0x6A) },
4785 { USB_DEVICE_WACOM(0x6B) },
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004786 { BT_DEVICE_WACOM(0x81) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004787 { USB_DEVICE_WACOM(0x84) },
4788 { USB_DEVICE_WACOM(0x90) },
4789 { USB_DEVICE_WACOM(0x93) },
4790 { USB_DEVICE_WACOM(0x97) },
4791 { USB_DEVICE_WACOM(0x9A) },
4792 { USB_DEVICE_WACOM(0x9F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004793 { USB_DEVICE_WACOM(0xB0) },
4794 { USB_DEVICE_WACOM(0xB1) },
4795 { USB_DEVICE_WACOM(0xB2) },
4796 { USB_DEVICE_WACOM(0xB3) },
4797 { USB_DEVICE_WACOM(0xB4) },
4798 { USB_DEVICE_WACOM(0xB5) },
4799 { USB_DEVICE_WACOM(0xB7) },
4800 { USB_DEVICE_WACOM(0xB8) },
4801 { USB_DEVICE_WACOM(0xB9) },
4802 { USB_DEVICE_WACOM(0xBA) },
4803 { USB_DEVICE_WACOM(0xBB) },
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004804 { USB_DEVICE_WACOM(0xBC) },
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004805 { BT_DEVICE_WACOM(0xBD) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004806 { USB_DEVICE_WACOM(0xC0) },
4807 { USB_DEVICE_WACOM(0xC2) },
4808 { USB_DEVICE_WACOM(0xC4) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004809 { USB_DEVICE_WACOM(0xC5) },
4810 { USB_DEVICE_WACOM(0xC6) },
4811 { USB_DEVICE_WACOM(0xC7) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004812 { USB_DEVICE_WACOM(0xCC) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004813 { USB_DEVICE_WACOM(0xCE) },
Henrik Rydbergcb734c02010-09-05 12:53:16 -07004814 { USB_DEVICE_WACOM(0xD0) },
Chris Bagwell2aaacb12010-09-12 00:11:35 -07004815 { USB_DEVICE_WACOM(0xD1) },
4816 { USB_DEVICE_WACOM(0xD2) },
4817 { USB_DEVICE_WACOM(0xD3) },
Kevin Granade57a78722010-12-10 23:04:02 -08004818 { USB_DEVICE_WACOM(0xD4) },
Gerard Braad18adad12011-08-16 00:17:56 -07004819 { USB_DEVICE_WACOM(0xD5) },
Ping Chengd38acb42011-01-24 09:32:50 -08004820 { USB_DEVICE_WACOM(0xD6) },
4821 { USB_DEVICE_WACOM(0xD7) },
David Foleya318e6b2010-11-30 23:45:46 -08004822 { USB_DEVICE_WACOM(0xD8) },
4823 { USB_DEVICE_WACOM(0xDA) },
David Foley47d09232010-12-07 21:05:59 -08004824 { USB_DEVICE_WACOM(0xDB) },
Chris Bagwell73149ab2011-10-26 22:34:21 -07004825 { USB_DEVICE_WACOM(0xDD) },
4826 { USB_DEVICE_WACOM(0xDE) },
4827 { USB_DEVICE_WACOM(0xDF) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004828 { USB_DEVICE_WACOM(0xE2) },
4829 { USB_DEVICE_WACOM(0xE3) },
Ping Cheng19635182012-04-29 21:09:18 -07004830 { USB_DEVICE_WACOM(0xE5) },
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07004831 { USB_DEVICE_WACOM(0xE6) },
Chris Bagwell0d0e3062011-12-11 23:50:59 -08004832 { USB_DEVICE_WACOM(0xEC) },
Ping Chengac173832012-06-12 00:15:06 -07004833 { USB_DEVICE_WACOM(0xED) },
4834 { USB_DEVICE_WACOM(0xEF) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004835 { USB_DEVICE_WACOM(0xF0) },
4836 { USB_DEVICE_WACOM(0xF4) },
4837 { USB_DEVICE_WACOM(0xF6) },
4838 { USB_DEVICE_WACOM(0xF8) },
4839 { USB_DEVICE_WACOM(0xFA) },
4840 { USB_DEVICE_WACOM(0xFB) },
Ping Cheng6afdc282012-11-03 12:16:15 -07004841 { USB_DEVICE_WACOM(0x100) },
4842 { USB_DEVICE_WACOM(0x101) },
Stephan Frank58694832013-03-07 14:08:50 -08004843 { USB_DEVICE_WACOM(0x10D) },
Jason Gerecke2d3163f2013-10-22 15:35:30 -07004844 { USB_DEVICE_WACOM(0x10E) },
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07004845 { USB_DEVICE_WACOM(0x10F) },
Jason Gerecke61616ed2014-05-14 11:42:22 -07004846 { USB_DEVICE_WACOM(0x116) },
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07004847 { USB_DEVICE_WACOM(0x12C) },
Ping Chengf41a64e2013-08-21 09:14:49 -07004848 { USB_DEVICE_WACOM(0x300) },
4849 { USB_DEVICE_WACOM(0x301) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004850 { USB_DEVICE_WACOM(0x302) },
4851 { USB_DEVICE_WACOM(0x303) },
Ping Cheng56218562013-05-05 19:56:18 -07004852 { USB_DEVICE_WACOM(0x304) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004853 { USB_DEVICE_WACOM(0x307) },
4854 { USB_DEVICE_WACOM(0x309) },
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004855 { USB_DEVICE_WACOM(0x30A) },
4856 { USB_DEVICE_WACOM(0x30C) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004857 { USB_DEVICE_WACOM(0x30E) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004858 { USB_DEVICE_WACOM(0x314) },
4859 { USB_DEVICE_WACOM(0x315) },
4860 { USB_DEVICE_WACOM(0x317) },
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004861 { USB_DEVICE_WACOM(0x318) },
4862 { USB_DEVICE_WACOM(0x319) },
Ping Chengfefb3912014-11-11 12:52:08 -08004863 { USB_DEVICE_WACOM(0x323) },
Jason Gereckef7acb552015-10-13 10:03:49 -07004864 { USB_DEVICE_WACOM(0x325) },
4865 { USB_DEVICE_WACOM(0x326) },
Ping Cheng500d4162015-01-27 13:30:03 -08004866 { USB_DEVICE_WACOM(0x32A) },
4867 { USB_DEVICE_WACOM(0x32B) },
4868 { USB_DEVICE_WACOM(0x32C) },
Ping Chengfff00bf2014-12-04 18:23:04 -08004869 { USB_DEVICE_WACOM(0x32F) },
Aaron Skomra72b236d2015-08-20 16:05:17 -07004870 { USB_DEVICE_WACOM(0x331) },
Ping Chengb4bf2122015-03-25 17:08:13 -07004871 { USB_DEVICE_WACOM(0x333) },
4872 { USB_DEVICE_WACOM(0x335) },
Aaron Skomra007760c2015-04-16 15:01:14 -07004873 { USB_DEVICE_WACOM(0x336) },
Ping Chengeda01da2015-09-23 13:51:15 -07004874 { USB_DEVICE_WACOM(0x33B) },
4875 { USB_DEVICE_WACOM(0x33C) },
4876 { USB_DEVICE_WACOM(0x33D) },
4877 { USB_DEVICE_WACOM(0x33E) },
Ping Chenge1123fe2016-04-12 13:37:45 -07004878 { USB_DEVICE_WACOM(0x343) },
Jason Gerecke4922cd22017-01-25 12:08:37 -08004879 { BT_DEVICE_WACOM(0x360) },
4880 { BT_DEVICE_WACOM(0x361) },
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08004881 { BT_DEVICE_WACOM(0x377) },
4882 { BT_DEVICE_WACOM(0x379) },
Jason Gereckec9472182017-12-26 15:50:18 -08004883 { USB_DEVICE_WACOM(0x37A) },
4884 { USB_DEVICE_WACOM(0x37B) },
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07004885 { BT_DEVICE_WACOM(0x393) },
Ping Chengedbe2652012-11-21 13:12:50 -08004886 { USB_DEVICE_WACOM(0x4001) },
Jason Gerecked51ddb22014-05-14 17:14:29 -07004887 { USB_DEVICE_WACOM(0x4004) },
4888 { USB_DEVICE_WACOM(0x5000) },
4889 { USB_DEVICE_WACOM(0x5002) },
Benjamin Tissoires00d6f2272014-12-01 11:52:39 -05004890 { USB_DEVICE_LENOVO(0x6004) },
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004891
4892 { USB_DEVICE_WACOM(HID_ANY_ID) },
Mika Westerbergeef23a82015-02-23 15:52:43 +02004893 { I2C_DEVICE_WACOM(HID_ANY_ID) },
Jason Gereckeb9e06252017-01-25 12:08:35 -08004894 { BT_DEVICE_WACOM(HID_ANY_ID) },
Ping Cheng3bea7332006-07-13 18:01:36 -07004895 { }
4896};
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004897MODULE_DEVICE_TABLE(hid, wacom_ids);