blob: ef29f7ad76643d6d835e582f936e6cfd87ab08c9 [file] [log] [blame]
Ping Cheng3bea7332006-07-13 18:01:36 -07001/*
Dmitry Torokhov4104d132007-05-07 16:16:29 -04002 * drivers/input/tablet/wacom_wac.c
Ping Cheng3bea7332006-07-13 18:01:36 -07003 *
Ping Chengee545002009-12-15 00:35:24 -08004 * USB Wacom tablet support - Wacom specific code
Ping Cheng3bea7332006-07-13 18:01:36 -07005 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070014
Ping Cheng3bea7332006-07-13 18:01:36 -070015#include "wacom_wac.h"
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070016#include "wacom.h"
Henrik Rydberg47c78e82010-11-27 09:16:48 +010017#include <linux/input/mt.h>
Ping Cheng3bea7332006-07-13 18:01:36 -070018
Ping Chenge35fb8c2011-03-26 21:16:05 -070019/* resolution for penabled devices */
20#define WACOM_PL_RES 20
21#define WACOM_PENPRTN_RES 40
22#define WACOM_VOLITO_RES 50
23#define WACOM_GRAPHIRE_RES 80
24#define WACOM_INTUOS_RES 100
25#define WACOM_INTUOS3_RES 200
26
Ping Chengfa770342014-12-01 13:44:28 -080027/* Newer Cintiq and DTU have an offset between tablet and screen areas */
28#define WACOM_DTU_OFFSET 200
29#define WACOM_CINTIQ_OFFSET 400
30
Benjamin Tissoires387142b2014-08-06 13:52:56 -070031/*
32 * Scale factor relating reported contact size to logical contact area.
Jason Gerecke4e904952012-10-03 17:19:11 -070033 * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
34 */
35#define WACOM_CONTACT_AREA_SCALE 2607
36
Ping Cheng1924e052016-08-09 14:38:56 -070037static bool touch_arbitration = 1;
38module_param(touch_arbitration, bool, 0644);
39MODULE_PARM_DESC(touch_arbitration, " on (Y) off (N)");
40
Jason Gereckec7f05222015-11-30 17:13:47 -080041static void wacom_report_numbered_buttons(struct input_dev *input_dev,
42 int button_count, int mask);
43
Jason Gerecke5922e612016-10-19 18:03:51 -070044static int wacom_numbered_button_to_key(int n);
45
Benjamin Tissoires387142b2014-08-06 13:52:56 -070046/*
47 * Percent of battery capacity for Graphire.
48 * 8th value means AC online and show 100% capacity.
49 */
50static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
51
Benjamin Tissoires81af7e62014-08-06 13:55:56 -070052/*
53 * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
54 */
55static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
56
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020057static void __wacom_notify_battery(struct wacom_battery *battery,
58 int bat_capacity, bool bat_charging,
59 bool bat_connected, bool ps_connected)
60{
61 bool changed = battery->battery_capacity != bat_capacity ||
62 battery->bat_charging != bat_charging ||
63 battery->bat_connected != bat_connected ||
64 battery->ps_connected != ps_connected;
65
66 if (changed) {
67 battery->battery_capacity = bat_capacity;
68 battery->bat_charging = bat_charging;
69 battery->bat_connected = bat_connected;
70 battery->ps_connected = ps_connected;
71
72 if (battery->battery)
73 power_supply_changed(battery->battery);
74 }
75}
76
Jason Gerecke953f2c52015-03-06 11:47:39 -080077static void wacom_notify_battery(struct wacom_wac *wacom_wac,
Jason Gerecke71fa6412015-03-11 10:25:41 -070078 int bat_capacity, bool bat_charging, bool bat_connected,
79 bool ps_connected)
Jason Gerecke953f2c52015-03-06 11:47:39 -080080{
81 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke953f2c52015-03-06 11:47:39 -080082
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020083 __wacom_notify_battery(&wacom->battery, bat_capacity, bat_charging,
84 bat_connected, ps_connected);
Jason Gerecke953f2c52015-03-06 11:47:39 -080085}
86
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -070087static int wacom_penpartner_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -070088{
89 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -070090 struct input_dev *input = wacom->pen_input;
Ping Cheng3bea7332006-07-13 18:01:36 -070091
92 switch (data[0]) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -070093 case 1:
94 if (data[5] & 0x80) {
95 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
96 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -070097 input_report_key(input, wacom->tool[0], 1);
98 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -070099 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
100 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700101 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
102 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
103 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700104 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700105 input_report_key(input, wacom->tool[0], 0);
106 input_report_abs(input, ABS_MISC, 0); /* report tool id */
107 input_report_abs(input, ABS_PRESSURE, -1);
108 input_report_key(input, BTN_TOUCH, 0);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700109 }
110 break;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700111
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700112 case 2:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700113 input_report_key(input, BTN_TOOL_PEN, 1);
114 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700115 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
116 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700117 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
118 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
119 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700120 break;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700121
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700122 default:
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700123 dev_dbg(input->dev.parent,
124 "%s: received unknown report #%d\n", __func__, data[0]);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700125 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700126 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700127
Ping Cheng3bea7332006-07-13 18:01:36 -0700128 return 1;
129}
130
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700131static int wacom_pl_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700132{
Jason Childse33da8a2010-02-17 22:38:31 -0800133 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700134 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700135 struct input_dev *input = wacom->pen_input;
Ping Chenge34b9d22008-05-05 11:36:41 -0400136 int prox, pressure;
Ping Cheng3bea7332006-07-13 18:01:36 -0700137
Ping Chengcad74702009-12-15 00:35:25 -0800138 if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700139 dev_dbg(input->dev.parent,
140 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700141 return 0;
142 }
143
144 prox = data[1] & 0x40;
145
Jason Gerecke025bcc12015-08-03 10:18:10 -0700146 if (!wacom->id[0]) {
147 if ((data[0] & 0x10) || (data[4] & 0x20)) {
148 wacom->tool[0] = BTN_TOOL_RUBBER;
149 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700150 }
Jason Gerecke025bcc12015-08-03 10:18:10 -0700151 else {
152 wacom->tool[0] = BTN_TOOL_PEN;
Ping Chenge34b9d22008-05-05 11:36:41 -0400153 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700154 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700155 }
156
Jason Gerecke025bcc12015-08-03 10:18:10 -0700157 /* If the eraser is in prox, STYLUS2 is always set. If we
158 * mis-detected the type and notice that STYLUS2 isn't set
159 * then force the eraser out of prox and let the pen in.
160 */
161 if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
162 input_report_key(input, BTN_TOOL_RUBBER, 0);
163 input_report_abs(input, ABS_MISC, 0);
164 input_sync(input);
165 wacom->tool[0] = BTN_TOOL_PEN;
166 wacom->id[0] = STYLUS_DEVICE_ID;
167 }
168
169 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
170 if (features->pressure_max > 255)
171 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
172 pressure += (features->pressure_max + 1) / 2;
173
174 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
175 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
176 input_report_abs(input, ABS_PRESSURE, pressure);
177
178 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
179 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
180 /* Only allow the stylus2 button to be reported for the pen tool. */
181 input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
182
183 if (!prox)
184 wacom->id[0] = 0;
185 input_report_key(input, wacom->tool[0], prox);
186 input_report_abs(input, ABS_MISC, wacom->id[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700187 return 1;
188}
189
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700190static int wacom_ptu_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700191{
192 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700193 struct input_dev *input = wacom->pen_input;
Ping Cheng3bea7332006-07-13 18:01:36 -0700194
Ping Chengcad74702009-12-15 00:35:25 -0800195 if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700196 dev_dbg(input->dev.parent,
197 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700198 return 0;
199 }
200
Ping Cheng3bea7332006-07-13 18:01:36 -0700201 if (data[1] & 0x04) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700202 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
203 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
Ping Chenge34b9d22008-05-05 11:36:41 -0400204 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700205 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700206 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
207 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
Ping Chenge34b9d22008-05-05 11:36:41 -0400208 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700209 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700210 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700211 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
212 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
213 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700214 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
215 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
Ping Cheng3bea7332006-07-13 18:01:36 -0700216 return 1;
217}
218
Ping Chengc8f2edc2010-06-28 01:10:51 -0700219static int wacom_dtu_irq(struct wacom_wac *wacom)
220{
Jason Gerecke74b63412014-04-19 13:50:22 -0700221 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700222 struct input_dev *input = wacom->pen_input;
Jason Gerecke74b63412014-04-19 13:50:22 -0700223 int prox = data[1] & 0x20;
Ping Chengc8f2edc2010-06-28 01:10:51 -0700224
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700225 dev_dbg(input->dev.parent,
226 "%s: received report #%d", __func__, data[0]);
Ping Chengc8f2edc2010-06-28 01:10:51 -0700227
228 if (prox) {
229 /* Going into proximity select tool */
230 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
231 if (wacom->tool[0] == BTN_TOOL_PEN)
232 wacom->id[0] = STYLUS_DEVICE_ID;
233 else
234 wacom->id[0] = ERASER_DEVICE_ID;
235 }
236 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
237 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
238 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
239 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke74b63412014-04-19 13:50:22 -0700240 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
Ping Chengc8f2edc2010-06-28 01:10:51 -0700241 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
242 if (!prox) /* out-prox */
243 wacom->id[0] = 0;
244 input_report_key(input, wacom->tool[0], prox);
245 input_report_abs(input, ABS_MISC, wacom->id[0]);
246 return 1;
247}
248
Ping Cheng497ab1f2014-01-20 20:18:04 -0800249static int wacom_dtus_irq(struct wacom_wac *wacom)
250{
251 char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700252 struct input_dev *input = wacom->pen_input;
Ping Cheng497ab1f2014-01-20 20:18:04 -0800253 unsigned short prox, pressure = 0;
254
255 if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
256 dev_dbg(input->dev.parent,
257 "%s: received unknown report #%d", __func__, data[0]);
258 return 0;
259 } else if (data[0] == WACOM_REPORT_DTUSPAD) {
Benjamin Tissoires422b0312014-07-24 12:50:39 -0700260 input = wacom->pad_input;
Ping Cheng497ab1f2014-01-20 20:18:04 -0800261 input_report_key(input, BTN_0, (data[1] & 0x01));
262 input_report_key(input, BTN_1, (data[1] & 0x02));
263 input_report_key(input, BTN_2, (data[1] & 0x04));
264 input_report_key(input, BTN_3, (data[1] & 0x08));
265 input_report_abs(input, ABS_MISC,
266 data[1] & 0x0f ? PAD_DEVICE_ID : 0);
Ping Cheng497ab1f2014-01-20 20:18:04 -0800267 return 1;
268 } else {
269 prox = data[1] & 0x80;
270 if (prox) {
271 switch ((data[1] >> 3) & 3) {
272 case 1: /* Rubber */
273 wacom->tool[0] = BTN_TOOL_RUBBER;
274 wacom->id[0] = ERASER_DEVICE_ID;
275 break;
276
277 case 2: /* Pen */
278 wacom->tool[0] = BTN_TOOL_PEN;
279 wacom->id[0] = STYLUS_DEVICE_ID;
280 break;
281 }
282 }
283
284 input_report_key(input, BTN_STYLUS, data[1] & 0x20);
285 input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
286 input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
287 input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
288 pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
289 input_report_abs(input, ABS_PRESSURE, pressure);
290 input_report_key(input, BTN_TOUCH, pressure > 10);
291
292 if (!prox) /* out-prox */
293 wacom->id[0] = 0;
294 input_report_key(input, wacom->tool[0], prox);
295 input_report_abs(input, ABS_MISC, wacom->id[0]);
Ping Cheng497ab1f2014-01-20 20:18:04 -0800296 return 1;
297 }
298}
299
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700300static int wacom_graphire_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700301{
Jason Childse33da8a2010-02-17 22:38:31 -0800302 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700303 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700304 struct input_dev *input = wacom->pen_input;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700305 struct input_dev *pad_input = wacom->pad_input;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700306 int battery_capacity, ps_connected;
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700307 int prox;
Ping Cheng3b57ca02010-03-04 21:50:59 -0800308 int rw = 0;
309 int retval = 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700310
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700311 if (features->type == GRAPHIRE_BT) {
312 if (data[0] != WACOM_REPORT_PENABLED_BT) {
313 dev_dbg(input->dev.parent,
314 "%s: received unknown report #%d\n", __func__,
315 data[0]);
316 goto exit;
317 }
318 } else if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700319 dev_dbg(input->dev.parent,
320 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800321 goto exit;
Ping Cheng3bea7332006-07-13 18:01:36 -0700322 }
323
Ping Cheng3b57ca02010-03-04 21:50:59 -0800324 prox = data[1] & 0x80;
325 if (prox || wacom->id[0]) {
326 if (prox) {
327 switch ((data[1] >> 5) & 3) {
Ping Cheng3bea7332006-07-13 18:01:36 -0700328
329 case 0: /* Pen */
330 wacom->tool[0] = BTN_TOOL_PEN;
Ping Chenge34b9d22008-05-05 11:36:41 -0400331 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700332 break;
333
334 case 1: /* Rubber */
335 wacom->tool[0] = BTN_TOOL_RUBBER;
Ping Chenge34b9d22008-05-05 11:36:41 -0400336 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700337 break;
338
339 case 2: /* Mouse with wheel */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700340 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
Ping Cheng3bea7332006-07-13 18:01:36 -0700341 /* fall through */
342
343 case 3: /* Mouse without wheel */
344 wacom->tool[0] = BTN_TOOL_MOUSE;
Ping Chenge34b9d22008-05-05 11:36:41 -0400345 wacom->id[0] = CURSOR_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700346 break;
Ping Cheng3b57ca02010-03-04 21:50:59 -0800347 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700348 }
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700349 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
350 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Ping Cheng3bea7332006-07-13 18:01:36 -0700351 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700352 if (features->type == GRAPHIRE_BT)
353 input_report_abs(input, ABS_PRESSURE, data[6] |
354 (((__u16) (data[1] & 0x08)) << 5));
355 else
356 input_report_abs(input, ABS_PRESSURE, data[6] |
357 ((data[7] & 0x03) << 8));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700358 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
359 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
360 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
Dmitry Torokhovafb567e2010-04-13 23:08:58 -0700361 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700362 input_report_key(input, BTN_LEFT, data[1] & 0x01);
363 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800364 if (features->type == WACOM_G4 ||
365 features->type == WACOM_MO) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700366 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
Mike Autyd9f66c12010-08-28 20:35:17 -0700367 rw = (data[7] & 0x04) - (data[7] & 0x03);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700368 } else if (features->type == GRAPHIRE_BT) {
369 /* Compute distance between mouse and tablet */
370 rw = 44 - (data[6] >> 2);
371 rw = clamp_val(rw, 0, 31);
372 input_report_abs(input, ABS_DISTANCE, rw);
373 if (((data[1] >> 5) & 3) == 2) {
374 /* Mouse with wheel */
375 input_report_key(input, BTN_MIDDLE,
376 data[1] & 0x04);
377 rw = (data[6] & 0x01) ? -1 :
378 (data[6] & 0x02) ? 1 : 0;
379 } else {
380 rw = 0;
381 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800382 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700383 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
Mike Autyd9f66c12010-08-28 20:35:17 -0700384 rw = -(signed char)data[6];
Ping Cheng3b57ca02010-03-04 21:50:59 -0800385 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700386 input_report_rel(input, REL_WHEEL, rw);
Dmitry Torokhovafb567e2010-04-13 23:08:58 -0700387 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800388
389 if (!prox)
390 wacom->id[0] = 0;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700391 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
392 input_report_key(input, wacom->tool[0], prox);
393 input_sync(input); /* sync last event */
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800394 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700395
396 /* send pad data */
Jason Childse33da8a2010-02-17 22:38:31 -0800397 switch (features->type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700398 case WACOM_G4:
Ping Cheng3b57ca02010-03-04 21:50:59 -0800399 prox = data[7] & 0xf8;
400 if (prox || wacom->id[1]) {
Ping Chenge34b9d22008-05-05 11:36:41 -0400401 wacom->id[1] = PAD_DEVICE_ID;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700402 input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
403 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
Ping Cheng3bea7332006-07-13 18:01:36 -0700404 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
Benjamin Tissoires38138102014-07-24 12:51:03 -0700405 input_report_rel(pad_input, REL_WHEEL, rw);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800406 if (!prox)
407 wacom->id[1] = 0;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700408 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
Ping Chengab687b12010-04-05 23:07:41 -0700409 retval = 1;
Ping Cheng3bea7332006-07-13 18:01:36 -0700410 }
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400411 break;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700412
413 case WACOM_MO:
Ping Cheng3b57ca02010-03-04 21:50:59 -0800414 prox = (data[7] & 0xf8) || data[8];
415 if (prox || wacom->id[1]) {
Ping Chenge34b9d22008-05-05 11:36:41 -0400416 wacom->id[1] = PAD_DEVICE_ID;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700417 input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
418 input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
419 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
420 input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
421 input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
Ping Cheng3b57ca02010-03-04 21:50:59 -0800422 if (!prox)
423 wacom->id[1] = 0;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700424 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
Ping Cheng84460012011-07-06 18:05:43 -0700425 retval = 1;
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400426 }
427 break;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700428 case GRAPHIRE_BT:
429 prox = data[7] & 0x03;
430 if (prox || wacom->id[1]) {
431 wacom->id[1] = PAD_DEVICE_ID;
432 input_report_key(pad_input, BTN_0, (data[7] & 0x02));
433 input_report_key(pad_input, BTN_1, (data[7] & 0x01));
434 if (!prox)
435 wacom->id[1] = 0;
436 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
437 retval = 1;
438 }
439 break;
440 }
441
442 /* Store current battery capacity and power supply state */
443 if (features->type == GRAPHIRE_BT) {
444 rw = (data[7] >> 2 & 0x07);
445 battery_capacity = batcap_gr[rw];
446 ps_connected = rw == 7;
Jason Gerecke953f2c52015-03-06 11:47:39 -0800447 wacom_notify_battery(wacom, battery_capacity, ps_connected,
Jason Gerecke71fa6412015-03-11 10:25:41 -0700448 1, ps_connected);
Ping Cheng3bea7332006-07-13 18:01:36 -0700449 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800450exit:
451 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -0700452}
453
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500454static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
455{
456 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke0bbfe282016-01-06 13:25:53 -0800457 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500458 struct hid_report *r;
459 struct hid_report_enum *re;
460
461 re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
Jason Gerecke0bbfe282016-01-06 13:25:53 -0800462 if (features->type == INTUOSHT2)
463 r = re->report_id_hash[WACOM_REPORT_INTUOSHT2_ID];
464 else
465 r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1];
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500466 if (r) {
467 hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
468 }
469}
470
Jason Gereckefb013a02015-11-30 17:13:46 -0800471static int wacom_intuos_pad(struct wacom_wac *wacom)
472{
473 struct wacom_features *features = &wacom->features;
474 unsigned char *data = wacom->data;
475 struct input_dev *input = wacom->pad_input;
Jason Gereckec7f05222015-11-30 17:13:47 -0800476 int i;
477 int buttons = 0, nbuttons = features->numbered_buttons;
478 int keys = 0, nkeys = 0;
479 int ring1 = 0, ring2 = 0;
480 int strip1 = 0, strip2 = 0;
481 bool prox = false;
Jason Gereckefb013a02015-11-30 17:13:46 -0800482
483 /* pad packets. Works as a second tool and is always in prox */
484 if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
485 data[0] == WACOM_REPORT_CINTIQPAD))
486 return 0;
487
488 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800489 buttons = (data[3] << 1) | (data[2] & 0x01);
490 ring1 = data[1];
Jason Gereckefb013a02015-11-30 17:13:46 -0800491 } else if (features->type == DTK) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800492 buttons = data[6];
Jason Gereckefb013a02015-11-30 17:13:46 -0800493 } else if (features->type == WACOM_13HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800494 buttons = (data[4] << 1) | (data[3] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800495 } else if (features->type == WACOM_24HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800496 buttons = (data[8] << 8) | data[6];
497 ring1 = data[1];
498 ring2 = data[2];
Jason Gereckefb013a02015-11-30 17:13:46 -0800499
500 /*
501 * Three "buttons" are available on the 24HD which are
502 * physically implemented as a touchstrip. Each button
503 * is approximately 3 bits wide with a 2 bit spacing.
504 * The raw touchstrip bits are stored at:
505 * ((data[3] & 0x1f) << 8) | data[4])
506 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800507 nkeys = 3;
508 keys = ((data[3] & 0x1C) ? 1<<2 : 0) |
509 ((data[4] & 0xE0) ? 1<<1 : 0) |
510 ((data[4] & 0x07) ? 1<<0 : 0);
Jason Gereckefb013a02015-11-30 17:13:46 -0800511 } else if (features->type == WACOM_27QHD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800512 nkeys = 3;
513 keys = data[2] & 0x07;
Jason Gereckefb013a02015-11-30 17:13:46 -0800514
515 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
516 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
517 input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
Jason Gereckefb013a02015-11-30 17:13:46 -0800518 } else if (features->type == CINTIQ_HYBRID) {
519 /*
520 * Do not send hardware buttons under Android. They
521 * are already sent to the system through GPIO (and
522 * have different meaning).
Jason Gereckec7f05222015-11-30 17:13:47 -0800523 *
524 * d-pad right -> data[4] & 0x10
525 * d-pad up -> data[4] & 0x20
526 * d-pad left -> data[4] & 0x40
527 * d-pad down -> data[4] & 0x80
528 * d-pad center -> data[3] & 0x01
Jason Gereckefb013a02015-11-30 17:13:46 -0800529 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800530 buttons = (data[4] << 1) | (data[3] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800531 } else if (features->type == CINTIQ_COMPANION_2) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800532 /* d-pad right -> data[4] & 0x10
533 * d-pad up -> data[4] & 0x20
534 * d-pad left -> data[4] & 0x40
535 * d-pad down -> data[4] & 0x80
536 * d-pad center -> data[3] & 0x01
537 */
Jason Gerecke0402b6b2015-12-16 13:37:36 -0800538 buttons = ((data[2] >> 4) << 7) |
Jason Gereckec7f05222015-11-30 17:13:47 -0800539 ((data[1] & 0x04) << 6) |
540 ((data[2] & 0x0F) << 2) |
541 (data[1] & 0x03);
Jason Gereckefb013a02015-11-30 17:13:46 -0800542 } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
Jason Gereckefb013a02015-11-30 17:13:46 -0800543 /*
544 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
545 * addition to the mechanical switch. Switch data is
546 * stored in data[4], capacitive data in data[5].
Jason Gereckec7f05222015-11-30 17:13:47 -0800547 *
548 * Touch ring mode switch (data[3]) has no capacitive sensor
Jason Gereckefb013a02015-11-30 17:13:46 -0800549 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800550 buttons = (data[4] << 1) | (data[3] & 0x01);
551 ring1 = data[2];
Jason Gereckefb013a02015-11-30 17:13:46 -0800552 } else {
553 if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800554 buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) |
555 (data[6] << 1) | (data[5] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800556
557 if (features->type == WACOM_22HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800558 nkeys = 3;
559 keys = data[9] & 0x07;
Jason Gereckefb013a02015-11-30 17:13:46 -0800560 }
561 } else {
Jason Gereckec7f05222015-11-30 17:13:47 -0800562 buttons = ((data[6] & 0x10) << 10) |
563 ((data[5] & 0x10) << 9) |
564 ((data[6] & 0x0F) << 4) |
565 (data[5] & 0x0F);
Jason Gereckefb013a02015-11-30 17:13:46 -0800566 }
Jason Gereckef73d08d2015-12-16 13:37:33 -0800567 strip1 = ((data[1] & 0x1f) << 8) | data[2];
568 strip2 = ((data[3] & 0x1f) << 8) | data[4];
Jason Gereckefb013a02015-11-30 17:13:46 -0800569 }
Jason Gereckec7f05222015-11-30 17:13:47 -0800570
Dan Carpenter8f9cfdd2015-12-09 13:22:05 +0300571 prox = (buttons & ~(~0 << nbuttons)) | (keys & ~(~0 << nkeys)) |
572 (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2;
Jason Gereckec7f05222015-11-30 17:13:47 -0800573
574 wacom_report_numbered_buttons(input, nbuttons, buttons);
575
576 for (i = 0; i < nkeys; i++)
577 input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
578
579 input_report_abs(input, ABS_RX, strip1);
Jason Gerecke03a0dc52015-12-16 13:37:34 -0800580 input_report_abs(input, ABS_RY, strip2);
Jason Gereckec7f05222015-11-30 17:13:47 -0800581
Jason Gereckeaaae03e2015-12-16 13:37:35 -0800582 input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0);
583 input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0);
Jason Gereckec7f05222015-11-30 17:13:47 -0800584
585 input_report_key(input, wacom->tool[1], prox ? 1 : 0);
586 input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
587
588 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
589
Jason Gereckefb013a02015-11-30 17:13:46 -0800590 return 1;
591}
592
Jason Gerecke82527da2016-10-19 18:03:47 -0700593static int wacom_intuos_id_mangle(int tool_id)
594{
595 return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
596}
597
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100598static int wacom_intuos_get_tool_type(int tool_id)
599{
600 int tool_type;
601
602 switch (tool_id) {
603 case 0x812: /* Inking pen */
604 case 0x801: /* Intuos3 Inking pen */
Jason Gerecke82527da2016-10-19 18:03:47 -0700605 case 0x12802: /* Intuos4/5 Inking Pen */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100606 case 0x012:
607 tool_type = BTN_TOOL_PENCIL;
608 break;
609
610 case 0x822: /* Pen */
611 case 0x842:
612 case 0x852:
613 case 0x823: /* Intuos3 Grip Pen */
614 case 0x813: /* Intuos3 Classic Pen */
615 case 0x885: /* Intuos3 Marker Pen */
616 case 0x802: /* Intuos4/5 13HD/24HD General Pen */
617 case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
618 case 0x8e2: /* IntuosHT2 pen */
619 case 0x022:
Jason Gerecke82527da2016-10-19 18:03:47 -0700620 case 0x10804: /* Intuos4/5 13HD/24HD Art Pen */
621 case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
622 case 0x16802: /* Cintiq 13HD Pro Pen */
623 case 0x18802: /* DTH2242 Pen */
624 case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100625 tool_type = BTN_TOOL_PEN;
626 break;
627
628 case 0x832: /* Stroke pen */
629 case 0x032:
630 tool_type = BTN_TOOL_BRUSH;
631 break;
632
633 case 0x007: /* Mouse 4D and 2D */
634 case 0x09c:
635 case 0x094:
636 case 0x017: /* Intuos3 2D Mouse */
637 case 0x806: /* Intuos4 Mouse */
638 tool_type = BTN_TOOL_MOUSE;
639 break;
640
641 case 0x096: /* Lens cursor */
642 case 0x097: /* Intuos3 Lens cursor */
643 case 0x006: /* Intuos4 Lens cursor */
644 tool_type = BTN_TOOL_LENS;
645 break;
646
647 case 0x82a: /* Eraser */
Jason Gerecke9ce9a122016-11-11 15:05:52 -0800648 case 0x84a:
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100649 case 0x85a:
650 case 0x91a:
651 case 0xd1a:
652 case 0x0fa:
653 case 0x82b: /* Intuos3 Grip Pen Eraser */
654 case 0x81b: /* Intuos3 Classic Pen Eraser */
655 case 0x91b: /* Intuos3 Airbrush Eraser */
656 case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
657 case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
658 case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
Jason Gerecke82527da2016-10-19 18:03:47 -0700659 case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
660 case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
661 case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
662 case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
663 case 0x1880a: /* DTH2242 Eraser */
664 case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100665 tool_type = BTN_TOOL_RUBBER;
666 break;
667
668 case 0xd12:
669 case 0x912:
670 case 0x112:
671 case 0x913: /* Intuos3 Airbrush */
672 case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
Jason Gerecke82527da2016-10-19 18:03:47 -0700673 case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100674 tool_type = BTN_TOOL_AIRBRUSH;
675 break;
676
677 default: /* Unknown tool */
678 tool_type = BTN_TOOL_PEN;
679 break;
680 }
681 return tool_type;
682}
683
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700684static int wacom_intuos_inout(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700685{
Jason Childse33da8a2010-02-17 22:38:31 -0800686 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700687 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700688 struct input_dev *input = wacom->pen_input;
Ping Cheng4750f5f2016-01-08 17:15:48 -0800689 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700690
Ping Cheng4750f5f2016-01-08 17:15:48 -0800691 if (!(((data[1] & 0xfc) == 0xc0) || /* in prox */
692 ((data[1] & 0xfe) == 0x20) || /* in range */
693 ((data[1] & 0xfe) == 0x80))) /* out prox */
694 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700695
696 /* Enter report */
697 if ((data[1] & 0xfc) == 0xc0) {
698 /* serial number of the tool */
699 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
700 (data[4] << 20) + (data[5] << 12) +
701 (data[6] << 4) + (data[7] >> 4);
702
Ping Cheng493630b2010-06-22 11:21:34 -0700703 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
Jason Gerecke82527da2016-10-19 18:03:47 -0700704 ((data[7] & 0x0f) << 16) | ((data[8] & 0xf0) << 8);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700705
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100706 wacom->tool[idx] = wacom_intuos_get_tool_type(wacom->id[idx]);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700707
Ping Chengeff6ca92016-05-02 21:17:34 -0700708 wacom->shared->stylus_in_proximity = true;
Ping Cheng3bea7332006-07-13 18:01:36 -0700709 return 1;
710 }
711
Ping Chengc1b03f52016-01-08 17:16:06 -0800712 /* in Range */
713 if ((data[1] & 0xfe) == 0x20) {
Ping Cheng526d6e72016-01-08 17:16:25 -0800714 if (features->type != INTUOSHT2)
715 wacom->shared->stylus_in_proximity = true;
Ping Cheng486b9082015-02-20 14:25:58 -0800716
Ping Chengc1b03f52016-01-08 17:16:06 -0800717 /* in Range while exiting */
718 if (wacom->reporting_data) {
719 input_report_key(input, BTN_TOUCH, 0);
720 input_report_abs(input, ABS_PRESSURE, 0);
721 input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
722 return 2;
723 }
724 return 1;
Jason Gerecke4eb18302013-09-20 09:48:46 -0700725 }
726
Ping Cheng3bea7332006-07-13 18:01:36 -0700727 /* Exit report */
728 if ((data[1] & 0xfe) == 0x80) {
Ping Chengf3586d22015-03-20 14:57:00 -0700729 wacom->shared->stylus_in_proximity = false;
Ping Chengb3bd7ef2015-01-09 11:05:13 -0800730 wacom->reporting_data = false;
Jason Gereckeae584ca2012-04-03 15:50:40 -0700731
Ping Cheng373a5352015-01-09 11:04:50 -0800732 /* don't report exit if we don't know the ID */
733 if (!wacom->id[idx])
734 return 1;
735
Ping Cheng6f660f12009-05-08 18:30:33 -0700736 /*
737 * Reset all states otherwise we lose the initial states
738 * when in-prox next time
739 */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700740 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);
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800745 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700746 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);
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400753 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700754 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);
Jason Childse33da8a2010-02-17 22:38:31 -0800759 if (features->type >= INTUOS3S)
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700760 input_report_abs(input, ABS_Z, 0);
Ping Cheng8d32e3a2006-09-26 13:34:47 -0700761 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700762 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]);
Ping Cheng6f660f12009-05-08 18:30:33 -0700765 wacom->id[idx] = 0;
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800766 return 2;
Ping Cheng3bea7332006-07-13 18:01:36 -0700767 }
Ping Cheng373a5352015-01-09 11:04:50 -0800768
Ping Cheng3bea7332006-07-13 18:01:36 -0700769 return 0;
770}
771
Aaron Skomra72b236d2015-08-20 16:05:17 -0700772static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
773{
774 unsigned char *data = wacom_wac->data;
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +0200775 struct input_dev *input;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700776 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Benjamin Tissoires83e6b402016-07-13 18:06:02 +0200777 struct wacom_remote *remote = wacom->remote;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700778 int bat_charging, bat_percent, touch_ring_mode;
779 __u32 serial;
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +0200780 int i, index = -1;
781 unsigned long flags;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700782
783 if (data[0] != WACOM_REPORT_REMOTE) {
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +0200784 hid_dbg(wacom->hdev, "%s: received unknown report #%d",
785 __func__, data[0]);
Aaron Skomra72b236d2015-08-20 16:05:17 -0700786 return 0;
787 }
788
789 serial = data[3] + (data[4] << 8) + (data[5] << 16);
790 wacom_wac->id[0] = PAD_DEVICE_ID;
791
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +0200792 spin_lock_irqsave(&remote->remote_lock, flags);
793
794 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
795 if (remote->remotes[i].serial == serial) {
796 index = i;
797 break;
798 }
799 }
800
801 if (index < 0 || !remote->remotes[index].registered)
802 goto out;
803
804 input = remote->remotes[index].input;
805
Aaron Skomra72b236d2015-08-20 16:05:17 -0700806 input_report_key(input, BTN_0, (data[9] & 0x01));
807 input_report_key(input, BTN_1, (data[9] & 0x02));
808 input_report_key(input, BTN_2, (data[9] & 0x04));
809 input_report_key(input, BTN_3, (data[9] & 0x08));
810 input_report_key(input, BTN_4, (data[9] & 0x10));
811 input_report_key(input, BTN_5, (data[9] & 0x20));
812 input_report_key(input, BTN_6, (data[9] & 0x40));
813 input_report_key(input, BTN_7, (data[9] & 0x80));
814
815 input_report_key(input, BTN_8, (data[10] & 0x01));
816 input_report_key(input, BTN_9, (data[10] & 0x02));
817 input_report_key(input, BTN_A, (data[10] & 0x04));
818 input_report_key(input, BTN_B, (data[10] & 0x08));
819 input_report_key(input, BTN_C, (data[10] & 0x10));
820 input_report_key(input, BTN_X, (data[10] & 0x20));
821 input_report_key(input, BTN_Y, (data[10] & 0x40));
822 input_report_key(input, BTN_Z, (data[10] & 0x80));
823
824 input_report_key(input, BTN_BASE, (data[11] & 0x01));
825 input_report_key(input, BTN_BASE2, (data[11] & 0x02));
826
827 if (data[12] & 0x80)
828 input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f));
829 else
830 input_report_abs(input, ABS_WHEEL, 0);
831
832 bat_percent = data[7] & 0x7f;
833 bat_charging = !!(data[7] & 0x80);
834
835 if (data[9] | data[10] | (data[11] & 0x03) | data[12])
836 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
837 else
838 input_report_abs(input, ABS_MISC, 0);
839
840 input_event(input, EV_MSC, MSC_SERIAL, serial);
841
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +0200842 input_sync(input);
843
Aaron Skomra72b236d2015-08-20 16:05:17 -0700844 /*Which mode select (LED light) is currently on?*/
845 touch_ring_mode = (data[11] & 0xC0) >> 6;
846
847 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
Benjamin Tissoirese7749f62016-07-13 18:06:06 +0200848 if (remote->remotes[i].serial == serial)
Benjamin Tissoiresa50aac72016-07-13 18:06:00 +0200849 wacom->led.groups[i].select = touch_ring_mode;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700850 }
851
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +0200852 __wacom_notify_battery(&remote->remotes[index].battery, bat_percent,
853 bat_charging, 1, bat_charging);
Aaron Skomra72b236d2015-08-20 16:05:17 -0700854
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +0200855out:
856 spin_unlock_irqrestore(&remote->remote_lock, flags);
857 return 0;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700858}
859
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200860static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
Aaron Skomra72b236d2015-08-20 16:05:17 -0700861{
862 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
863 unsigned char *data = wacom_wac->data;
Benjamin Tissoires83e6b402016-07-13 18:06:02 +0200864 struct wacom_remote *remote = wacom->remote;
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200865 struct wacom_remote_data remote_data;
866 unsigned long flags;
867 int i, ret;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700868
869 if (data[0] != WACOM_REPORT_DEVICE_LIST)
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200870 return;
871
872 memset(&remote_data, 0, sizeof(struct wacom_remote_data));
Aaron Skomra72b236d2015-08-20 16:05:17 -0700873
874 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
875 int j = i * 6;
876 int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
877 bool connected = data[j+2];
878
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200879 remote_data.remote[i].serial = serial;
880 remote_data.remote[i].connected = connected;
Aaron Skomra72b236d2015-08-20 16:05:17 -0700881 }
882
Benjamin Tissoires83e6b402016-07-13 18:06:02 +0200883 spin_lock_irqsave(&remote->remote_lock, flags);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200884
Benjamin Tissoires83e6b402016-07-13 18:06:02 +0200885 ret = kfifo_in(&remote->remote_fifo, &remote_data, sizeof(remote_data));
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200886 if (ret != sizeof(remote_data)) {
Benjamin Tissoires83e6b402016-07-13 18:06:02 +0200887 spin_unlock_irqrestore(&remote->remote_lock, flags);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200888 hid_err(wacom->hdev, "Can't queue Remote status event.\n");
889 return;
890 }
891
Benjamin Tissoires83e6b402016-07-13 18:06:02 +0200892 spin_unlock_irqrestore(&remote->remote_lock, flags);
Benjamin Tissoirese6f28132016-07-13 18:06:01 +0200893
894 wacom_schedule_work(wacom_wac, WACOM_WORKER_REMOTE);
Aaron Skomra72b236d2015-08-20 16:05:17 -0700895}
896
Ping Cheng1924e052016-08-09 14:38:56 -0700897static inline bool report_touch_events(struct wacom_wac *wacom)
898{
899 return (touch_arbitration ? !wacom->shared->stylus_in_proximity : 1);
900}
901
902static inline bool delay_pen_events(struct wacom_wac *wacom)
903{
904 return (wacom->shared->touch_down && touch_arbitration);
Ping Cheng3bea7332006-07-13 18:01:36 -0700905}
906
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800907static int wacom_intuos_general(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700908{
Jason Childse33da8a2010-02-17 22:38:31 -0800909 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700910 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700911 struct input_dev *input = wacom->pen_input;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800912 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
Jason Gereckea8a09c82015-11-30 17:13:49 -0800913 unsigned char type = (data[1] >> 1) & 0x0F;
Jason Gerecke5f33f432015-11-30 17:13:51 -0800914 unsigned int x, y, distance, t;
Ping Cheng3bea7332006-07-13 18:01:36 -0700915
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800916 if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
917 data[0] != WACOM_REPORT_INTUOS_PEN)
918 return 0;
919
Ping Cheng1924e052016-08-09 14:38:56 -0700920 if (delay_pen_events(wacom))
Ping Chengc1b03f52016-01-08 17:16:06 -0800921 return 1;
922
Ping Cheng599b0822016-01-08 17:14:54 -0800923 /* don't report events if we don't know the tool ID */
924 if (!wacom->id[idx]) {
925 /* but reschedule a read of the current tool */
926 wacom_intuos_schedule_prox_event(wacom);
927 return 1;
928 }
929
Ping Cheng4750f5f2016-01-08 17:15:48 -0800930 /*
931 * don't report events for invalid data
932 */
933 /* older I4 styli don't work with new Cintiqs */
Jason Gerecke82527da2016-10-19 18:03:47 -0700934 if ((!((wacom->id[idx] >> 16) & 0x01) &&
Ping Cheng4750f5f2016-01-08 17:15:48 -0800935 (features->type == WACOM_21UX2)) ||
936 /* Only large Intuos support Lense Cursor */
937 (wacom->tool[idx] == BTN_TOOL_LENS &&
938 (features->type == INTUOS3 ||
939 features->type == INTUOS3S ||
940 features->type == INTUOS4 ||
941 features->type == INTUOS4S ||
942 features->type == INTUOS5 ||
943 features->type == INTUOS5S ||
944 features->type == INTUOSPM ||
945 features->type == INTUOSPS)) ||
946 /* Cintiq doesn't send data when RDY bit isn't set */
947 (features->type == CINTIQ && !(data[1] & 0x40)))
948 return 1;
949
Jason Gerecke5f33f432015-11-30 17:13:51 -0800950 x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
951 y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
952 distance = data[9] >> 2;
953 if (features->type < INTUOS3S) {
954 x >>= 1;
955 y >>= 1;
956 distance >>= 1;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800957 }
Jason Gerecke5f33f432015-11-30 17:13:51 -0800958 input_report_abs(input, ABS_X, x);
959 input_report_abs(input, ABS_Y, y);
960 input_report_abs(input, ABS_DISTANCE, distance);
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800961
Jason Gereckea8a09c82015-11-30 17:13:49 -0800962 switch (type) {
963 case 0x00:
964 case 0x01:
965 case 0x02:
966 case 0x03:
967 /* general pen packet */
Jason Gerecke5f33f432015-11-30 17:13:51 -0800968 t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
969 if (features->pressure_max < 2047)
970 t >>= 1;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700971 input_report_abs(input, ABS_PRESSURE, t);
Ping Chengeda01da2015-09-23 13:51:15 -0700972 if (features->type != INTUOSHT2) {
973 input_report_abs(input, ABS_TILT_X,
Jason Gereckeec5fc1c2014-11-18 16:50:08 -0800974 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
Ping Chengeda01da2015-09-23 13:51:15 -0700975 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
976 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700977 input_report_key(input, BTN_STYLUS, data[1] & 2);
978 input_report_key(input, BTN_STYLUS2, data[1] & 4);
979 input_report_key(input, BTN_TOUCH, t > 10);
Jason Gereckea8a09c82015-11-30 17:13:49 -0800980 break;
Ping Cheng3bea7332006-07-13 18:01:36 -0700981
Jason Gereckea8a09c82015-11-30 17:13:49 -0800982 case 0x0a:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800983 /* airbrush second packet */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700984 input_report_abs(input, ABS_WHEEL,
Ping Cheng3bea7332006-07-13 18:01:36 -0700985 (data[6] << 2) | ((data[7] >> 6) & 3));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700986 input_report_abs(input, ABS_TILT_X,
Jason Gereckeec5fc1c2014-11-18 16:50:08 -0800987 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
988 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
Jason Gereckea8a09c82015-11-30 17:13:49 -0800989 break;
990
991 case 0x05:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800992 /* Rotation packet */
993 if (features->type >= INTUOS3S) {
994 /* I3 marker pen rotation */
995 t = (data[6] << 3) | ((data[7] >> 5) & 7);
996 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
997 ((t-1) / 2 + 450)) : (450 - t / 2) ;
998 input_report_abs(input, ABS_Z, t);
999 } else {
Jason Gerecke571f5722015-11-30 17:13:50 -08001000 /* 4D mouse 2nd packet */
Jason Gereckea8a09c82015-11-30 17:13:49 -08001001 t = (data[6] << 3) | ((data[7] >> 5) & 7);
1002 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
1003 ((t - 1) / 2) : -t / 2);
1004 }
1005 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07001006
Jason Gereckea8a09c82015-11-30 17:13:49 -08001007 case 0x04:
Jason Gerecke571f5722015-11-30 17:13:50 -08001008 /* 4D mouse 1st packet */
1009 input_report_key(input, BTN_LEFT, data[8] & 0x01);
1010 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
1011 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
1012
1013 input_report_key(input, BTN_SIDE, data[8] & 0x20);
1014 input_report_key(input, BTN_EXTRA, data[8] & 0x10);
1015 t = (data[6] << 2) | ((data[7] >> 6) & 3);
1016 input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
1017 break;
1018
Jason Gereckea8a09c82015-11-30 17:13:49 -08001019 case 0x06:
Jason Gerecke571f5722015-11-30 17:13:50 -08001020 /* I4 mouse */
1021 input_report_key(input, BTN_LEFT, data[6] & 0x01);
1022 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
1023 input_report_key(input, BTN_RIGHT, data[6] & 0x04);
1024 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
1025 - ((data[7] & 0x40) >> 6));
1026 input_report_key(input, BTN_SIDE, data[6] & 0x08);
1027 input_report_key(input, BTN_EXTRA, data[6] & 0x10);
1028
1029 input_report_abs(input, ABS_TILT_X,
1030 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
1031 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
1032 break;
1033
Jason Gereckea8a09c82015-11-30 17:13:49 -08001034 case 0x08:
Jason Gerecke571f5722015-11-30 17:13:50 -08001035 if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
1036 /* 2D mouse packet */
1037 input_report_key(input, BTN_LEFT, data[8] & 0x04);
1038 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
1039 input_report_key(input, BTN_RIGHT, data[8] & 0x10);
1040 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
1041 - ((data[8] & 0x02) >> 1));
Ping Cheng3bea7332006-07-13 18:01:36 -07001042
Jason Gerecke571f5722015-11-30 17:13:50 -08001043 /* I3 2D mouse side buttons */
1044 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
1045 input_report_key(input, BTN_SIDE, data[8] & 0x40);
1046 input_report_key(input, BTN_EXTRA, data[8] & 0x20);
Ping Cheng3bea7332006-07-13 18:01:36 -07001047 }
Jason Gereckea8a09c82015-11-30 17:13:49 -08001048 }
Jason Gerecke571f5722015-11-30 17:13:50 -08001049 else if (wacom->tool[idx] == BTN_TOOL_LENS) {
Ping Cheng3bea7332006-07-13 18:01:36 -07001050 /* Lens cursor packets */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07001051 input_report_key(input, BTN_LEFT, data[8] & 0x01);
1052 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
1053 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
1054 input_report_key(input, BTN_SIDE, data[8] & 0x10);
1055 input_report_key(input, BTN_EXTRA, data[8] & 0x08);
Ping Cheng3bea7332006-07-13 18:01:36 -07001056 }
Jason Gereckea8a09c82015-11-30 17:13:49 -08001057 break;
1058
Jason Gerecke571f5722015-11-30 17:13:50 -08001059 case 0x07:
Jason Gereckea8a09c82015-11-30 17:13:49 -08001060 case 0x09:
Jason Gerecke571f5722015-11-30 17:13:50 -08001061 case 0x0b:
Jason Gereckea8a09c82015-11-30 17:13:49 -08001062 case 0x0c:
1063 case 0x0d:
1064 case 0x0e:
1065 case 0x0f:
1066 /* unhandled */
1067 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07001068 }
Ping Cheng3bea7332006-07-13 18:01:36 -07001069
Jason Gerecke82527da2016-10-19 18:03:47 -07001070 input_report_abs(input, ABS_MISC,
1071 wacom_intuos_id_mangle(wacom->id[idx])); /* report tool id */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07001072 input_report_key(input, wacom->tool[idx], 1);
1073 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
Ping Chengb3bd7ef2015-01-09 11:05:13 -08001074 wacom->reporting_data = true;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001075 return 2;
Ping Cheng3bea7332006-07-13 18:01:36 -07001076}
1077
1078static int wacom_intuos_irq(struct wacom_wac *wacom)
1079{
Ping Cheng3bea7332006-07-13 18:01:36 -07001080 unsigned char *data = wacom->data;
1081 struct input_dev *input = wacom->pen_input;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001082 int result;
Ping Cheng3bea7332006-07-13 18:01:36 -07001083
1084 if (data[0] != WACOM_REPORT_PENABLED &&
Jason Gerecke06109992015-11-30 17:13:52 -08001085 data[0] != WACOM_REPORT_INTUOS_ID1 &&
1086 data[0] != WACOM_REPORT_INTUOS_ID2 &&
Ping Cheng3bea7332006-07-13 18:01:36 -07001087 data[0] != WACOM_REPORT_INTUOSPAD &&
1088 data[0] != WACOM_REPORT_INTUOS_PEN &&
1089 data[0] != WACOM_REPORT_CINTIQ &&
1090 data[0] != WACOM_REPORT_CINTIQPAD &&
1091 data[0] != WACOM_REPORT_INTUOS5PAD) {
1092 dev_dbg(input->dev.parent,
1093 "%s: received unknown report #%d\n", __func__, data[0]);
1094 return 0;
1095 }
1096
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001097 /* process pad events */
1098 result = wacom_intuos_pad(wacom);
1099 if (result)
1100 return result;
Ping Cheng3bea7332006-07-13 18:01:36 -07001101
1102 /* process in/out prox events */
1103 result = wacom_intuos_inout(wacom);
1104 if (result)
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001105 return result - 1;
Ping Cheng3bea7332006-07-13 18:01:36 -07001106
1107 /* process general packets */
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001108 result = wacom_intuos_general(wacom);
1109 if (result)
1110 return result - 1;
Ping Cheng3bea7332006-07-13 18:01:36 -07001111
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001112 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07001113}
1114
Jason Gereckeb1e42792012-10-21 00:38:04 -07001115static int int_dist(int x1, int y1, int x2, int y2)
1116{
1117 int x = x2 - x1;
1118 int y = y2 - y1;
1119
1120 return int_sqrt(x*x + y*y);
1121}
1122
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001123static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
1124 unsigned char *data)
1125{
1126 memcpy(wacom->data, data, 10);
1127 wacom_intuos_irq(wacom);
1128
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001129 input_sync(wacom->pen_input);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001130 if (wacom->pad_input)
1131 input_sync(wacom->pad_input);
1132}
1133
1134static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1135{
1136 unsigned char data[WACOM_PKGLEN_MAX];
1137 int i = 1;
1138 unsigned power_raw, battery_capacity, bat_charging, ps_connected;
1139
1140 memcpy(data, wacom->data, len);
1141
1142 switch (data[0]) {
1143 case 0x04:
1144 wacom_intuos_bt_process_data(wacom, data + i);
1145 i += 10;
1146 /* fall through */
1147 case 0x03:
1148 wacom_intuos_bt_process_data(wacom, data + i);
1149 i += 10;
1150 wacom_intuos_bt_process_data(wacom, data + i);
1151 i += 10;
1152 power_raw = data[i];
1153 bat_charging = (power_raw & 0x08) ? 1 : 0;
1154 ps_connected = (power_raw & 0x10) ? 1 : 0;
1155 battery_capacity = batcap_i4[power_raw & 0x07];
Jason Gerecke953f2c52015-03-06 11:47:39 -08001156 wacom_notify_battery(wacom, battery_capacity, bat_charging,
Jason Gerecke71fa6412015-03-11 10:25:41 -07001157 battery_capacity || bat_charging,
Jason Gerecke953f2c52015-03-06 11:47:39 -08001158 ps_connected);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001159 break;
1160 default:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001161 dev_dbg(wacom->pen_input->dev.parent,
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001162 "Unknown report: %d,%d size:%zu\n",
1163 data[0], data[1], len);
1164 return 0;
1165 }
1166 return 0;
1167}
1168
Ping Cheng7d059ed2015-03-20 14:57:21 -07001169static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1170{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001171 struct input_dev *input = wacom->touch_input;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001172 unsigned touch_max = wacom->features.touch_max;
1173 int count = 0;
1174 int i;
1175
Ping Cheng26ba61f2015-05-19 17:42:02 -07001176 if (!touch_max)
1177 return 0;
1178
Jason Gerecke71b5c472015-04-15 17:22:32 -07001179 if (touch_max == 1)
1180 return test_bit(BTN_TOUCH, input->key) &&
Ping Cheng1924e052016-08-09 14:38:56 -07001181 report_touch_events(wacom);
Ping Cheng7d059ed2015-03-20 14:57:21 -07001182
1183 for (i = 0; i < input->mt->num_slots; i++) {
1184 struct input_mt_slot *ps = &input->mt->slots[i];
1185 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1186 if (id >= 0)
1187 count++;
1188 }
1189
1190 return count;
1191}
1192
Jason Gerecke4922cd22017-01-25 12:08:37 -08001193static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1194{
1195 const int pen_frame_len = 14;
1196 const int pen_frames = 7;
1197
1198 struct input_dev *pen_input = wacom->pen_input;
1199 unsigned char *data = wacom->data;
1200 int i;
1201
1202 wacom->serial[0] = get_unaligned_le64(&data[99]);
1203 wacom->id[0] = get_unaligned_le16(&data[107]);
1204 if (wacom->serial[0] >> 52 == 1) {
1205 /* Add back in missing bits of ID for non-USI pens */
1206 wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
1207 }
1208 wacom->tool[0] = wacom_intuos_get_tool_type(wacom_intuos_id_mangle(wacom->id[0]));
1209
1210 for (i = 0; i < pen_frames; i++) {
1211 unsigned char *frame = &data[i*pen_frame_len + 1];
1212
1213 if (!(frame[0] & 0x80))
1214 continue;
1215
1216 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
1217 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
1218 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
1219 input_report_abs(pen_input, ABS_TILT_X, frame[7]);
1220 input_report_abs(pen_input, ABS_TILT_Y, frame[8]);
1221 input_report_abs(pen_input, ABS_Z, get_unaligned_le16(&frame[9]));
1222 input_report_abs(pen_input, ABS_WHEEL, get_unaligned_le16(&frame[11]));
1223 input_report_abs(pen_input, ABS_DISTANCE, frame[13]);
1224
1225 input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x01);
1226 input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02);
1227 input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04);
1228
1229 input_report_key(pen_input, wacom->tool[0], 1);
1230 input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]);
1231 input_report_abs(pen_input, ABS_MISC,
1232 wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */
1233
1234 wacom->shared->stylus_in_proximity = frame[0] & 0x40;
1235
1236 input_sync(pen_input);
1237 }
1238}
1239
1240static void wacom_intuos_pro2_bt_touch(struct wacom_wac *wacom)
1241{
1242 const int finger_touch_len = 8;
1243 const int finger_frames = 4;
1244 const int finger_frame_len = 43;
1245
1246 struct input_dev *touch_input = wacom->touch_input;
1247 unsigned char *data = wacom->data;
1248 int num_contacts_left = 5;
1249 int i, j;
1250
1251 for (i = 0; i < finger_frames; i++) {
1252 unsigned char *frame = &data[i*finger_frame_len + 109];
1253 int current_num_contacts = frame[0] & 0x7F;
1254 int contacts_to_send;
1255
1256 if (!(frame[0] & 0x80))
1257 continue;
1258
1259 /*
1260 * First packet resets the counter since only the first
1261 * packet in series will have non-zero current_num_contacts.
1262 */
1263 if (current_num_contacts)
1264 wacom->num_contacts_left = current_num_contacts;
1265
1266 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1267
1268 for (j = 0; j < contacts_to_send; j++) {
1269 unsigned char *touch = &frame[j*finger_touch_len + 1];
1270 int slot = input_mt_get_slot_by_key(touch_input, touch[0]);
1271 int x = get_unaligned_le16(&touch[2]);
1272 int y = get_unaligned_le16(&touch[4]);
1273 int w = touch[6] * input_abs_get_res(touch_input, ABS_MT_POSITION_X);
1274 int h = touch[7] * input_abs_get_res(touch_input, ABS_MT_POSITION_Y);
1275
1276 if (slot < 0)
1277 continue;
1278
1279 input_mt_slot(touch_input, slot);
1280 input_mt_report_slot_state(touch_input, MT_TOOL_FINGER, touch[1] & 0x01);
1281 input_report_abs(touch_input, ABS_MT_POSITION_X, x);
1282 input_report_abs(touch_input, ABS_MT_POSITION_Y, y);
1283 input_report_abs(touch_input, ABS_MT_TOUCH_MAJOR, max(w, h));
1284 input_report_abs(touch_input, ABS_MT_TOUCH_MINOR, min(w, h));
1285 input_report_abs(touch_input, ABS_MT_ORIENTATION, w > h);
1286 }
1287
1288 input_mt_sync_frame(touch_input);
1289
1290 wacom->num_contacts_left -= contacts_to_send;
1291 if (wacom->num_contacts_left <= 0) {
1292 wacom->num_contacts_left = 0;
1293 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1294 }
1295 }
1296
1297 input_report_switch(touch_input, SW_MUTE_DEVICE, !(data[281] >> 7));
1298 input_sync(touch_input);
1299}
1300
1301static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
1302{
1303 struct input_dev *pad_input = wacom->pad_input;
1304 unsigned char *data = wacom->data;
1305
1306 int buttons = (data[282] << 1) | ((data[281] >> 6) & 0x01);
1307 int ring = data[285];
1308 int prox = buttons | (ring & 0x80);
1309
1310 wacom_report_numbered_buttons(pad_input, 9, buttons);
1311
1312 input_report_abs(pad_input, ABS_WHEEL, (ring & 0x80) ? (ring & 0x7f) : 0);
1313
1314 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
1315 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
1316 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1317
1318 input_sync(pad_input);
1319}
1320
1321static void wacom_intuos_pro2_bt_battery(struct wacom_wac *wacom)
1322{
1323 unsigned char *data = wacom->data;
1324
1325 bool chg = data[284] & 0x80;
1326 int battery_status = data[284] & 0x7F;
1327
1328 wacom_notify_battery(wacom, battery_status, chg, 1, chg);
1329}
1330
1331static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
1332{
1333 unsigned char *data = wacom->data;
1334
1335 if (data[0] != 0x80) {
1336 dev_dbg(wacom->pen_input->dev.parent,
1337 "%s: received unknown report #%d\n", __func__, data[0]);
1338 return 0;
1339 }
1340
1341 wacom_intuos_pro2_bt_pen(wacom);
1342 wacom_intuos_pro2_bt_touch(wacom);
1343 wacom_intuos_pro2_bt_pad(wacom);
1344 wacom_intuos_pro2_bt_battery(wacom);
1345 return 0;
1346}
1347
Jason Gereckeb1e42792012-10-21 00:38:04 -07001348static int wacom_24hdt_irq(struct wacom_wac *wacom)
1349{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001350 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001351 unsigned char *data = wacom->data;
Jason Gereckeb1e42792012-10-21 00:38:04 -07001352 int i;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001353 int current_num_contacts = data[61];
Jason Gereckeb1e42792012-10-21 00:38:04 -07001354 int contacts_to_send = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001355 int num_contacts_left = 4; /* maximum contacts per packet */
1356 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1357 int y_offset = 2;
1358
1359 if (wacom->features.type == WACOM_27QHDT) {
1360 current_num_contacts = data[63];
1361 num_contacts_left = 10;
1362 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1363 y_offset = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001364 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001365
1366 /*
1367 * First packet resets the counter since only the first
1368 * packet in series will have non-zero current_num_contacts.
1369 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001370 if (current_num_contacts)
Jason Gereckeb1e42792012-10-21 00:38:04 -07001371 wacom->num_contacts_left = current_num_contacts;
1372
Ping Cheng500d4162015-01-27 13:30:03 -08001373 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001374
1375 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng500d4162015-01-27 13:30:03 -08001376 int offset = (byte_per_packet * i) + 1;
Ping Cheng1924e052016-08-09 14:38:56 -07001377 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Ping Cheng02295e62013-01-04 23:56:00 -08001378 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001379
1380 if (slot < 0)
1381 continue;
1382 input_mt_slot(input, slot);
1383 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1384
1385 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001386 int t_x = get_unaligned_le16(&data[offset + 2]);
Ping Cheng500d4162015-01-27 13:30:03 -08001387 int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001388
1389 input_report_abs(input, ABS_MT_POSITION_X, t_x);
1390 input_report_abs(input, ABS_MT_POSITION_Y, t_y);
Ping Cheng500d4162015-01-27 13:30:03 -08001391
1392 if (wacom->features.type != WACOM_27QHDT) {
1393 int c_x = get_unaligned_le16(&data[offset + 4]);
1394 int c_y = get_unaligned_le16(&data[offset + 8]);
1395 int w = get_unaligned_le16(&data[offset + 10]);
1396 int h = get_unaligned_le16(&data[offset + 12]);
1397
1398 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1399 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1400 min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1401 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1402 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1403 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001404 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001405 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001406 input_mt_sync_frame(input);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001407
1408 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001409 if (wacom->num_contacts_left <= 0) {
Jason Gereckeb1e42792012-10-21 00:38:04 -07001410 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001411 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001412 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001413 return 1;
1414}
1415
Ping Cheng19635182012-04-29 21:09:18 -07001416static int wacom_mt_touch(struct wacom_wac *wacom)
1417{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001418 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001419 unsigned char *data = wacom->data;
Ping Cheng19635182012-04-29 21:09:18 -07001420 int i;
1421 int current_num_contacts = data[2];
1422 int contacts_to_send = 0;
Ping Cheng6afdc282012-11-03 12:16:15 -07001423 int x_offset = 0;
1424
1425 /* MTTPC does not support Height and Width */
Jason Gerecked51ddb22014-05-14 17:14:29 -07001426 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
Ping Cheng6afdc282012-11-03 12:16:15 -07001427 x_offset = -4;
Ping Cheng19635182012-04-29 21:09:18 -07001428
1429 /*
1430 * First packet resets the counter since only the first
1431 * packet in series will have non-zero current_num_contacts.
1432 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001433 if (current_num_contacts)
Ping Cheng19635182012-04-29 21:09:18 -07001434 wacom->num_contacts_left = current_num_contacts;
1435
1436 /* There are at most 5 contacts per packet */
1437 contacts_to_send = min(5, wacom->num_contacts_left);
1438
1439 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng6afdc282012-11-03 12:16:15 -07001440 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
Ping Cheng1924e052016-08-09 14:38:56 -07001441 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001442 int id = get_unaligned_le16(&data[offset + 1]);
Ping Cheng02295e62013-01-04 23:56:00 -08001443 int slot = input_mt_get_slot_by_key(input, id);
Ping Cheng19635182012-04-29 21:09:18 -07001444
1445 if (slot < 0)
1446 continue;
1447
1448 input_mt_slot(input, slot);
1449 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1450 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001451 int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1452 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
Ping Cheng19635182012-04-29 21:09:18 -07001453 input_report_abs(input, ABS_MT_POSITION_X, x);
1454 input_report_abs(input, ABS_MT_POSITION_Y, y);
1455 }
Ping Cheng19635182012-04-29 21:09:18 -07001456 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001457 input_mt_sync_frame(input);
Ping Cheng19635182012-04-29 21:09:18 -07001458
1459 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001460 if (wacom->num_contacts_left <= 0) {
Ping Cheng19635182012-04-29 21:09:18 -07001461 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001462 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001463 }
Ping Cheng19635182012-04-29 21:09:18 -07001464 return 1;
1465}
1466
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001467static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1468{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001469 struct input_dev *input = wacom->touch_input;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001470 unsigned char *data = wacom->data;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001471 int i;
1472
1473 for (i = 0; i < 2; i++) {
1474 int p = data[1] & (1 << i);
Ping Cheng1924e052016-08-09 14:38:56 -07001475 bool touch = p && report_touch_events(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001476
1477 input_mt_slot(input, i);
1478 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1479 if (touch) {
1480 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1481 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1482
1483 input_report_abs(input, ABS_MT_POSITION_X, x);
1484 input_report_abs(input, ABS_MT_POSITION_Y, y);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001485 }
1486 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001487 input_mt_sync_frame(input);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001488
1489 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001490 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001491
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001492 return 1;
1493}
1494
Ping Chenga43c7c52011-03-12 20:34:42 -08001495static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
Ping Chengec67bbe2009-12-15 00:35:24 -08001496{
Jason Gerecke74b63412014-04-19 13:50:22 -07001497 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001498 struct input_dev *input = wacom->touch_input;
Ping Cheng1924e052016-08-09 14:38:56 -07001499 bool prox = report_touch_events(wacom);
Ping Chenga43c7c52011-03-12 20:34:42 -08001500 int x = 0, y = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -08001501
Ping Cheng19635182012-04-29 21:09:18 -07001502 if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1503 return 0;
1504
Ping Chenge0d41fd2015-02-20 14:27:30 -08001505 if (len == WACOM_PKGLEN_TPC1FG) {
1506 prox = prox && (data[0] & 0x01);
1507 x = get_unaligned_le16(&data[1]);
1508 y = get_unaligned_le16(&data[3]);
1509 } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1510 prox = prox && (data[2] & 0x01);
1511 x = get_unaligned_le16(&data[3]);
1512 y = get_unaligned_le16(&data[5]);
1513 } else {
1514 prox = prox && (data[1] & 0x01);
1515 x = le16_to_cpup((__le16 *)&data[2]);
1516 y = le16_to_cpup((__le16 *)&data[4]);
1517 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001518
1519 if (prox) {
1520 input_report_abs(input, ABS_X, x);
1521 input_report_abs(input, ABS_Y, y);
Ping Chengec67bbe2009-12-15 00:35:24 -08001522 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001523 input_report_key(input, BTN_TOUCH, prox);
1524
1525 /* keep touch state for pen events */
1526 wacom->shared->touch_down = prox;
1527
1528 return 1;
Ping Chengec67bbe2009-12-15 00:35:24 -08001529}
1530
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001531static int wacom_tpc_pen(struct wacom_wac *wacom)
Ping Cheng545f4e92008-11-24 11:44:27 -05001532{
Jason Gerecke74b63412014-04-19 13:50:22 -07001533 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001534 struct input_dev *input = wacom->pen_input;
Ping Chenga43c7c52011-03-12 20:34:42 -08001535 bool prox = data[1] & 0x20;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001536
Ping Chenga43c7c52011-03-12 20:34:42 -08001537 if (!wacom->shared->stylus_in_proximity) /* first in prox */
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001538 /* Going into proximity select tool */
1539 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001540
Ping Chenga43c7c52011-03-12 20:34:42 -08001541 /* keep pen state for touch events */
1542 wacom->shared->stylus_in_proximity = prox;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001543
Ping Cheng1924e052016-08-09 14:38:56 -07001544 /* send pen events only when touch is up or forced out
1545 * or touch arbitration is off
1546 */
1547 if (!delay_pen_events(wacom)) {
Ping Chenga43c7c52011-03-12 20:34:42 -08001548 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1549 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1550 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1551 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke0b335ca2014-07-24 13:15:31 -07001552 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
Ping Chenga43c7c52011-03-12 20:34:42 -08001553 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1554 input_report_key(input, wacom->tool[0], prox);
1555 return 1;
1556 }
1557
1558 return 0;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001559}
1560
1561static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1562{
Jason Gerecke74b63412014-04-19 13:50:22 -07001563 unsigned char *data = wacom->data;
Ping Cheng545f4e92008-11-24 11:44:27 -05001564
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001565 if (wacom->pen_input)
1566 dev_dbg(wacom->pen_input->dev.parent,
1567 "%s: received report #%d\n", __func__, data[0]);
1568 else if (wacom->touch_input)
1569 dev_dbg(wacom->touch_input->dev.parent,
1570 "%s: received report #%d\n", __func__, data[0]);
Ping Cheng545f4e92008-11-24 11:44:27 -05001571
Ping Cheng31175a82012-01-31 00:07:33 -08001572 switch (len) {
1573 case WACOM_PKGLEN_TPC1FG:
Ping Cheng19635182012-04-29 21:09:18 -07001574 return wacom_tpc_single_touch(wacom, len);
Ping Cheng31175a82012-01-31 00:07:33 -08001575
1576 case WACOM_PKGLEN_TPC2FG:
Ping Cheng19635182012-04-29 21:09:18 -07001577 return wacom_tpc_mt_touch(wacom);
Ping Cheng31175a82012-01-31 00:07:33 -08001578
Jason Gerecked51ddb22014-05-14 17:14:29 -07001579 case WACOM_PKGLEN_PENABLED:
1580 return wacom_tpc_pen(wacom);
1581
Ping Cheng31175a82012-01-31 00:07:33 -08001582 default:
1583 switch (data[0]) {
1584 case WACOM_REPORT_TPC1FG:
1585 case WACOM_REPORT_TPCHID:
1586 case WACOM_REPORT_TPCST:
Ping Chengac173832012-06-12 00:15:06 -07001587 case WACOM_REPORT_TPC1FGE:
Ping Cheng31175a82012-01-31 00:07:33 -08001588 return wacom_tpc_single_touch(wacom, len);
1589
Ping Cheng19635182012-04-29 21:09:18 -07001590 case WACOM_REPORT_TPCMT:
Jason Gerecked51ddb22014-05-14 17:14:29 -07001591 case WACOM_REPORT_TPCMT2:
Ping Cheng19635182012-04-29 21:09:18 -07001592 return wacom_mt_touch(wacom);
1593
Ping Cheng31175a82012-01-31 00:07:33 -08001594 case WACOM_REPORT_PENABLED:
1595 return wacom_tpc_pen(wacom);
1596 }
1597 }
Ping Cheng545f4e92008-11-24 11:44:27 -05001598
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001599 return 0;
Ping Cheng545f4e92008-11-24 11:44:27 -05001600}
1601
Jason Gereckec9c09582016-10-19 18:03:43 -07001602static int wacom_equivalent_usage(int usage)
1603{
1604 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1605 int subpage = (usage & 0xFF00) << 8;
1606 int subusage = (usage & 0xFF);
1607
Jason Gerecke5922e612016-10-19 18:03:51 -07001608 if (subpage == WACOM_HID_SP_PAD ||
1609 subpage == WACOM_HID_SP_BUTTON ||
1610 subpage == WACOM_HID_SP_DIGITIZER ||
Jason Gereckeb5c921e2016-10-19 18:03:44 -07001611 subpage == WACOM_HID_SP_DIGITIZERINFO ||
Jason Gerecke61ce3462016-10-19 18:03:46 -07001612 usage == WACOM_HID_WD_SENSE ||
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001613 usage == WACOM_HID_WD_SERIALHI ||
1614 usage == WACOM_HID_WD_TOOLTYPE ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001615 usage == WACOM_HID_WD_DISTANCE ||
Jason Gereckebf78adc2016-10-19 18:03:53 -07001616 usage == WACOM_HID_WD_TOUCHSTRIP ||
1617 usage == WACOM_HID_WD_TOUCHSTRIP2 ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001618 usage == WACOM_HID_WD_TOUCHRING ||
1619 usage == WACOM_HID_WD_TOUCHRINGSTATUS) {
Jason Gereckec9c09582016-10-19 18:03:43 -07001620 return usage;
1621 }
1622
1623 if (subpage == HID_UP_UNDEFINED)
1624 subpage = HID_UP_DIGITIZER;
1625
1626 return subpage | subusage;
1627 }
1628
1629 return usage;
1630}
1631
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001632static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001633 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1634{
Jason Gerecke345857b2016-10-19 18:03:50 -07001635 struct wacom *wacom = input_get_drvdata(input);
1636 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1637 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001638 int fmin = field->logical_minimum;
1639 int fmax = field->logical_maximum;
Jason Gereckec9c09582016-10-19 18:03:43 -07001640 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
Jason Gerecke50066a02016-10-19 18:03:42 -07001641 int resolution_code = code;
1642
Jason Gereckec9c09582016-10-19 18:03:43 -07001643 if (equivalent_usage == HID_DG_TWIST) {
Jason Gerecke50066a02016-10-19 18:03:42 -07001644 resolution_code = ABS_RZ;
1645 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001646
Jason Gerecke345857b2016-10-19 18:03:50 -07001647 if (equivalent_usage == HID_GD_X) {
1648 fmin += features->offset_left;
1649 fmax -= features->offset_right;
1650 }
1651 if (equivalent_usage == HID_GD_Y) {
1652 fmin += features->offset_top;
1653 fmax -= features->offset_bottom;
1654 }
1655
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001656 usage->type = type;
1657 usage->code = code;
1658
1659 set_bit(type, input->evbit);
1660
1661 switch (type) {
1662 case EV_ABS:
1663 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1664 input_abs_set_res(input, code,
Jason Gerecke50066a02016-10-19 18:03:42 -07001665 hidinput_calc_abs_res(field, resolution_code));
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001666 break;
1667 case EV_KEY:
1668 input_set_capability(input, EV_KEY, code);
1669 break;
1670 case EV_MSC:
1671 input_set_capability(input, EV_MSC, code);
1672 break;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001673 case EV_SW:
1674 input_set_capability(input, EV_SW, code);
1675 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001676 }
1677}
1678
Jason Gerecke5922e612016-10-19 18:03:51 -07001679static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1680 struct hid_field *field, struct hid_usage *usage)
1681{
1682 struct wacom *wacom = hid_get_drvdata(hdev);
1683 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1684 struct wacom_features *features = &wacom_wac->features;
1685 struct input_dev *input = wacom_wac->pad_input;
1686 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1687
1688 switch (equivalent_usage) {
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001689 case WACOM_HID_WD_BATTERY_LEVEL:
1690 case WACOM_HID_WD_BATTERY_CHARGING:
1691 features->quirks |= WACOM_QUIRK_BATTERY;
1692 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07001693 case WACOM_HID_WD_ACCELEROMETER_X:
1694 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1695 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001696 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001697 break;
1698 case WACOM_HID_WD_ACCELEROMETER_Y:
1699 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1700 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001701 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001702 break;
1703 case WACOM_HID_WD_ACCELEROMETER_Z:
1704 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1705 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001706 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001707 break;
1708 case WACOM_HID_WD_BUTTONHOME:
1709 case WACOM_HID_WD_BUTTONUP:
1710 case WACOM_HID_WD_BUTTONDOWN:
1711 case WACOM_HID_WD_BUTTONLEFT:
1712 case WACOM_HID_WD_BUTTONRIGHT:
Jason Gereckebf78adc2016-10-19 18:03:53 -07001713 case WACOM_HID_WD_BUTTONCENTER:
Jason Gerecke5922e612016-10-19 18:03:51 -07001714 wacom_map_usage(input, usage, field, EV_KEY,
1715 wacom_numbered_button_to_key(features->numbered_buttons),
1716 0);
1717 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08001718 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001719 break;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001720 case WACOM_HID_WD_TOUCHONOFF:
1721 wacom_map_usage(input, usage, field, EV_SW, SW_MUTE_DEVICE, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001722 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001723 break;
1724 case WACOM_HID_WD_TOUCHSTRIP:
1725 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001726 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001727 break;
1728 case WACOM_HID_WD_TOUCHSTRIP2:
1729 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001730 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001731 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07001732 case WACOM_HID_WD_TOUCHRING:
1733 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001734 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001735 break;
1736 }
1737
1738 switch (equivalent_usage & 0xfffffff0) {
1739 case WACOM_HID_WD_EXPRESSKEY00:
1740 wacom_map_usage(input, usage, field, EV_KEY,
1741 wacom_numbered_button_to_key(features->numbered_buttons),
1742 0);
1743 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08001744 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001745 break;
1746 }
1747}
1748
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001749static void wacom_wac_pad_battery_event(struct hid_device *hdev, struct hid_field *field,
Jason Gerecke5922e612016-10-19 18:03:51 -07001750 struct hid_usage *usage, __s32 value)
1751{
1752 struct wacom *wacom = hid_get_drvdata(hdev);
1753 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke5922e612016-10-19 18:03:51 -07001754 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1755
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001756 switch (equivalent_usage) {
1757 case WACOM_HID_WD_BATTERY_LEVEL:
1758 wacom_wac->hid_data.battery_capacity = value;
1759 wacom_wac->hid_data.bat_connected = 1;
Ping Cheng354a3292016-12-08 22:03:27 -08001760 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001761
1762 case WACOM_HID_WD_BATTERY_CHARGING:
1763 wacom_wac->hid_data.bat_charging = value;
1764 wacom_wac->hid_data.ps_connected = value;
1765 wacom_wac->hid_data.bat_connected = 1;
Ping Cheng354a3292016-12-08 22:03:27 -08001766 break;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001767 }
1768}
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001769
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001770static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
1771 struct hid_usage *usage, __s32 value)
1772{
1773 struct wacom *wacom = hid_get_drvdata(hdev);
1774 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1775 struct input_dev *input = wacom_wac->pad_input;
1776 struct wacom_features *features = &wacom_wac->features;
1777 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1778
1779 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
1780 wacom_wac->hid_data.inrange_state |= value;
1781 }
1782
1783 switch (equivalent_usage) {
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001784 case WACOM_HID_WD_TOUCHRINGSTATUS:
Ping Cheng354a3292016-12-08 22:03:27 -08001785 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001786
1787 default:
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001788 features->input_event_flag = true;
Jason Gerecke5922e612016-10-19 18:03:51 -07001789 input_event(input, usage->type, usage->code, value);
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001790 break;
1791 }
Jason Gerecke5922e612016-10-19 18:03:51 -07001792}
1793
1794static void wacom_wac_pad_pre_report(struct hid_device *hdev,
1795 struct hid_report *report)
1796{
1797 struct wacom *wacom = hid_get_drvdata(hdev);
1798 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1799
1800 wacom_wac->hid_data.inrange_state = 0;
1801}
1802
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001803static void wacom_wac_pad_battery_report(struct hid_device *hdev,
Jason Gerecke5922e612016-10-19 18:03:51 -07001804 struct hid_report *report)
1805{
1806 struct wacom *wacom = hid_get_drvdata(hdev);
1807 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001808 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke5922e612016-10-19 18:03:51 -07001809
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001810 if (features->quirks & WACOM_QUIRK_BATTERY) {
1811 int capacity = wacom_wac->hid_data.battery_capacity;
1812 bool charging = wacom_wac->hid_data.bat_charging;
1813 bool connected = wacom_wac->hid_data.bat_connected;
1814 bool powered = wacom_wac->hid_data.ps_connected;
1815
1816 wacom_notify_battery(wacom_wac, capacity, charging,
1817 connected, powered);
1818 }
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001819}
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001820
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001821static void wacom_wac_pad_report(struct hid_device *hdev,
1822 struct hid_report *report)
1823{
1824 struct wacom *wacom = hid_get_drvdata(hdev);
1825 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1826 struct wacom_features *features = &wacom_wac->features;
1827 struct input_dev *input = wacom_wac->pad_input;
1828 bool active = wacom_wac->hid_data.inrange_state != 0;
1829
1830 /* report prox for expresskey events */
1831 if (wacom_equivalent_usage(report->field[0]->physical) == HID_DG_TABLETFUNCTIONKEY) {
1832 features->input_event_flag = true;
1833 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
1834 }
1835
1836 if (features->input_event_flag) {
1837 features->input_event_flag = false;
1838 input_sync(input);
1839 }
Jason Gerecke5922e612016-10-19 18:03:51 -07001840}
1841
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001842static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
1843 struct hid_field *field, struct hid_usage *usage)
1844{
1845 struct wacom *wacom = hid_get_drvdata(hdev);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001846 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001847 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001848 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07001849 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001850
Jason Gereckec9c09582016-10-19 18:03:43 -07001851 switch (equivalent_usage) {
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001852 case HID_GD_X:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001853 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001854 break;
1855 case HID_GD_Y:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001856 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001857 break;
Jason Gereckeb5c921e2016-10-19 18:03:44 -07001858 case WACOM_HID_WD_DISTANCE:
Jason Gerecke50066a02016-10-19 18:03:42 -07001859 case HID_GD_Z:
1860 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
1861 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001862 case HID_DG_TIPPRESSURE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001863 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001864 break;
1865 case HID_DG_INRANGE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001866 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001867 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001868 case HID_DG_BATTERYSTRENGTH:
1869 features->quirks |= WACOM_QUIRK_BATTERY;
1870 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001871 case HID_DG_INVERT:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001872 wacom_map_usage(input, usage, field, EV_KEY,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001873 BTN_TOOL_RUBBER, 0);
1874 break;
Jason Gerecke50066a02016-10-19 18:03:42 -07001875 case HID_DG_TILT_X:
1876 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
1877 break;
1878 case HID_DG_TILT_Y:
1879 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
1880 break;
1881 case HID_DG_TWIST:
1882 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1883 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001884 case HID_DG_ERASER:
1885 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001886 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001887 break;
1888 case HID_DG_BARRELSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001889 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001890 break;
1891 case HID_DG_BARRELSWITCH2:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001892 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001893 break;
1894 case HID_DG_TOOLSERIALNUMBER:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001895 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001896 break;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001897 case WACOM_HID_WD_SENSE:
1898 features->quirks |= WACOM_QUIRK_SENSE;
1899 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1900 break;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001901 case WACOM_HID_WD_SERIALHI:
1902 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
1903 set_bit(EV_KEY, input->evbit);
1904 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
1905 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
1906 input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
1907 input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
1908 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
1909 input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
1910 input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
1911 break;
Jason Gerecke929d6d52016-10-19 18:03:45 -07001912 case WACOM_HID_WD_FINGERWHEEL:
1913 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1914 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001915 }
1916}
1917
Ping Cheng354a3292016-12-08 22:03:27 -08001918static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001919 struct hid_usage *usage, __s32 value)
1920{
1921 struct wacom *wacom = hid_get_drvdata(hdev);
1922 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001923 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001924 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07001925 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001926
Jason Gereckec9c09582016-10-19 18:03:43 -07001927 switch (equivalent_usage) {
Jason Gerecke50066a02016-10-19 18:03:42 -07001928 case HID_GD_Z:
1929 /*
1930 * HID_GD_Z "should increase as the control's position is
1931 * moved from high to low", while ABS_DISTANCE instead
1932 * increases in value as the tool moves from low to high.
1933 */
1934 value = field->logical_maximum - value;
1935 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001936 case HID_DG_INRANGE:
1937 wacom_wac->hid_data.inrange_state = value;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001938 if (!(features->quirks & WACOM_QUIRK_SENSE))
1939 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001940 return;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001941 case HID_DG_BATTERYSTRENGTH:
1942 wacom_wac->hid_data.battery_capacity = value;
1943 wacom_wac->hid_data.bat_connected = 1;
1944 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001945 case HID_DG_INVERT:
1946 wacom_wac->hid_data.invert_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001947 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001948 case HID_DG_ERASER:
1949 case HID_DG_TIPSWITCH:
1950 wacom_wac->hid_data.tipswitch |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08001951 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001952 case HID_DG_TOOLSERIALNUMBER:
Dan Carpentera35f09b2016-11-10 22:25:39 +03001953 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001954 wacom_wac->serial[0] |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08001955 return;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001956 case WACOM_HID_WD_SENSE:
1957 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001958 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001959 case WACOM_HID_WD_SERIALHI:
1960 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
1961 wacom_wac->serial[0] |= ((__u64)value) << 32;
1962 /*
1963 * Non-USI EMR devices may contain additional tool type
1964 * information here. See WACOM_HID_WD_TOOLTYPE case for
1965 * more details.
1966 */
1967 if (value >> 20 == 1) {
1968 wacom_wac->id[0] |= value & 0xFFFFF;
1969 }
Ping Cheng354a3292016-12-08 22:03:27 -08001970 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001971 case WACOM_HID_WD_TOOLTYPE:
1972 /*
1973 * Some devices (MobileStudio Pro, and possibly later
1974 * devices as well) do not return the complete tool
1975 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
1976 * bitwise OR so the complete value can be built
1977 * up over time :(
1978 */
1979 wacom_wac->id[0] |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08001980 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001981 case WACOM_HID_WD_OFFSETLEFT:
1982 if (features->offset_left && value != features->offset_left)
1983 hid_warn(hdev, "%s: overriding exising left offset "
1984 "%d -> %d\n", __func__, value,
1985 features->offset_left);
1986 features->offset_left = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001987 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001988 case WACOM_HID_WD_OFFSETRIGHT:
1989 if (features->offset_right && value != features->offset_right)
1990 hid_warn(hdev, "%s: overriding exising right offset "
1991 "%d -> %d\n", __func__, value,
1992 features->offset_right);
1993 features->offset_right = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001994 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001995 case WACOM_HID_WD_OFFSETTOP:
1996 if (features->offset_top && value != features->offset_top)
1997 hid_warn(hdev, "%s: overriding exising top offset "
1998 "%d -> %d\n", __func__, value,
1999 features->offset_top);
2000 features->offset_top = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002001 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002002 case WACOM_HID_WD_OFFSETBOTTOM:
2003 if (features->offset_bottom && value != features->offset_bottom)
2004 hid_warn(hdev, "%s: overriding exising bottom offset "
2005 "%d -> %d\n", __func__, value,
2006 features->offset_bottom);
2007 features->offset_bottom = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002008 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002009 }
2010
Ping Cheng1924e052016-08-09 14:38:56 -07002011 /* send pen events only when touch is up or forced out
2012 * or touch arbitration is off
2013 */
2014 if (!usage->type || delay_pen_events(wacom_wac))
Ping Cheng354a3292016-12-08 22:03:27 -08002015 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002016
Jason Gerecke61ce3462016-10-19 18:03:46 -07002017 /* send pen events only when the pen is in/entering/leaving proximity */
2018 if (!wacom_wac->hid_data.inrange_state && !wacom_wac->tool[0])
Ping Cheng354a3292016-12-08 22:03:27 -08002019 return;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002020
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002021 input_event(input, usage->type, usage->code, value);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002022}
2023
Jason Gerecke06324e02015-07-21 11:07:23 -07002024static void wacom_wac_pen_pre_report(struct hid_device *hdev,
2025 struct hid_report *report)
2026{
2027 return;
2028}
2029
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002030static void wacom_wac_pen_report(struct hid_device *hdev,
2031 struct hid_report *report)
2032{
2033 struct wacom *wacom = hid_get_drvdata(hdev);
2034 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002035 struct input_dev *input = wacom_wac->pen_input;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002036 bool prox = wacom_wac->hid_data.inrange_state;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002037 bool range = wacom_wac->hid_data.sense_state;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002038
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002039 if (!wacom_wac->tool[0] && prox) { /* first in prox */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002040 /* Going into proximity select tool */
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002041 if (wacom_wac->hid_data.invert_state)
2042 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
2043 else if (wacom_wac->id[0])
2044 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
2045 else
2046 wacom_wac->tool[0] = BTN_TOOL_PEN;
2047 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002048
2049 /* keep pen state for touch events */
Jason Gerecke61ce3462016-10-19 18:03:46 -07002050 wacom_wac->shared->stylus_in_proximity = range;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002051
Jason Gerecke61ce3462016-10-19 18:03:46 -07002052 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002053 int id = wacom_wac->id[0];
2054
2055 /*
2056 * Non-USI EMR tools should have their IDs mangled to
2057 * match the legacy behavior of wacom_intuos_general
2058 */
2059 if (wacom_wac->serial[0] >> 52 == 1)
2060 id = wacom_intuos_id_mangle(id);
2061
2062 /*
2063 * To ensure compatibility with xf86-input-wacom, we should
2064 * report the BTN_TOOL_* event prior to the ABS_MISC or
2065 * MSC_SERIAL events.
2066 */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002067 input_report_key(input, BTN_TOUCH,
2068 wacom_wac->hid_data.tipswitch);
2069 input_report_key(input, wacom_wac->tool[0], prox);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002070 if (wacom_wac->serial[0]) {
2071 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
2072 input_report_abs(input, ABS_MISC, id);
2073 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002074
2075 wacom_wac->hid_data.tipswitch = false;
2076
2077 input_sync(input);
2078 }
Jason Gerecke61ce3462016-10-19 18:03:46 -07002079
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002080 if (!prox) {
Jason Gerecke61ce3462016-10-19 18:03:46 -07002081 wacom_wac->tool[0] = 0;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002082 wacom_wac->id[0] = 0;
2083 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002084}
2085
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002086static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
2087 struct hid_field *field, struct hid_usage *usage)
2088{
2089 struct wacom *wacom = hid_get_drvdata(hdev);
2090 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002091 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002092 unsigned touch_max = wacom_wac->features.touch_max;
Jason Gereckec9c09582016-10-19 18:03:43 -07002093 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002094
Jason Gereckec9c09582016-10-19 18:03:43 -07002095 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002096 case HID_GD_X:
2097 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002098 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002099 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002100 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002101 ABS_MT_POSITION_X, 4);
2102 break;
2103 case HID_GD_Y:
2104 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002105 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002106 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002107 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002108 ABS_MT_POSITION_Y, 4);
2109 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002110 case HID_DG_WIDTH:
2111 case HID_DG_HEIGHT:
Jason Gerecke488abb52015-07-21 11:07:25 -07002112 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
2113 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
2114 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
2115 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002116 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002117 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002118 break;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002119 case HID_DG_CONTACTCOUNT:
Jason Gerecke499522c2015-10-07 16:54:21 -07002120 wacom_wac->hid_data.cc_report = field->report->id;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002121 wacom_wac->hid_data.cc_index = field->index;
2122 wacom_wac->hid_data.cc_value_index = usage->usage_index;
2123 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002124 }
2125}
2126
Jason Gerecke601a22f2014-12-10 16:26:04 -08002127static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
2128 struct input_dev *input)
2129{
2130 struct hid_data *hid_data = &wacom_wac->hid_data;
2131 bool mt = wacom_wac->features.touch_max > 1;
2132 bool prox = hid_data->tipswitch &&
Ping Cheng1924e052016-08-09 14:38:56 -07002133 report_touch_events(wacom_wac);
Jason Gerecke601a22f2014-12-10 16:26:04 -08002134
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002135 wacom_wac->hid_data.num_received++;
2136 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
2137 return;
2138
Jason Gerecke601a22f2014-12-10 16:26:04 -08002139 if (mt) {
2140 int slot;
2141
2142 slot = input_mt_get_slot_by_key(input, hid_data->id);
2143 input_mt_slot(input, slot);
2144 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
2145 }
2146 else {
2147 input_report_key(input, BTN_TOUCH, prox);
2148 }
2149
2150 if (prox) {
2151 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
2152 hid_data->x);
2153 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
2154 hid_data->y);
Jason Gerecke488abb52015-07-21 11:07:25 -07002155
2156 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
2157 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
2158 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
2159 if (hid_data->width != hid_data->height)
2160 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
2161 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002162 }
2163}
2164
Ping Cheng354a3292016-12-08 22:03:27 -08002165static void wacom_wac_finger_event(struct hid_device *hdev,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002166 struct hid_field *field, struct hid_usage *usage, __s32 value)
2167{
2168 struct wacom *wacom = hid_get_drvdata(hdev);
2169 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckec9c09582016-10-19 18:03:43 -07002170 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002171
Jason Gereckec9c09582016-10-19 18:03:43 -07002172 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002173 case HID_GD_X:
2174 wacom_wac->hid_data.x = value;
2175 break;
2176 case HID_GD_Y:
2177 wacom_wac->hid_data.y = value;
2178 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002179 case HID_DG_WIDTH:
2180 wacom_wac->hid_data.width = value;
2181 break;
2182 case HID_DG_HEIGHT:
2183 wacom_wac->hid_data.height = value;
2184 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002185 case HID_DG_CONTACTID:
2186 wacom_wac->hid_data.id = value;
2187 break;
2188 case HID_DG_TIPSWITCH:
2189 wacom_wac->hid_data.tipswitch = value;
2190 break;
2191 }
2192
2193
Jason Gerecke601a22f2014-12-10 16:26:04 -08002194 if (usage->usage_index + 1 == field->report_count) {
Jason Gereckec9c09582016-10-19 18:03:43 -07002195 if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002196 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
Jason Gerecke601a22f2014-12-10 16:26:04 -08002197 }
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002198}
2199
Jason Gerecke06324e02015-07-21 11:07:23 -07002200static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2201 struct hid_report *report)
2202{
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002203 struct wacom *wacom = hid_get_drvdata(hdev);
2204 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2205 struct hid_data* hid_data = &wacom_wac->hid_data;
Jason Gerecke003f50a2016-07-21 09:10:46 -07002206 int i;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002207
Jason Gerecke003f50a2016-07-21 09:10:46 -07002208 for (i = 0; i < report->maxfield; i++) {
2209 struct hid_field *field = report->field[i];
2210 int j;
Jason Gerecke499522c2015-10-07 16:54:21 -07002211
Jason Gerecke003f50a2016-07-21 09:10:46 -07002212 for (j = 0; j < field->maxusage; j++) {
2213 struct hid_usage *usage = &field->usage[j];
Jason Gerecke499522c2015-10-07 16:54:21 -07002214
Jason Gerecke003f50a2016-07-21 09:10:46 -07002215 switch (usage->hid) {
2216 case HID_GD_X:
2217 case HID_GD_Y:
2218 case HID_DG_WIDTH:
2219 case HID_DG_HEIGHT:
2220 case HID_DG_CONTACTID:
2221 case HID_DG_INRANGE:
2222 case HID_DG_INVERT:
2223 case HID_DG_TIPSWITCH:
2224 hid_data->last_slot_field = usage->hid;
2225 break;
2226 case HID_DG_CONTACTCOUNT:
2227 hid_data->cc_report = report->id;
2228 hid_data->cc_index = i;
2229 hid_data->cc_value_index = j;
2230 break;
Jason Gerecke499522c2015-10-07 16:54:21 -07002231 }
2232 }
2233 }
Jason Gerecke003f50a2016-07-21 09:10:46 -07002234
Jason Gereckedf707932015-10-07 16:54:22 -07002235 if (hid_data->cc_report != 0 &&
2236 hid_data->cc_index >= 0) {
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002237 struct hid_field *field = report->field[hid_data->cc_index];
2238 int value = field->value[hid_data->cc_value_index];
2239 if (value)
2240 hid_data->num_expected = value;
2241 }
2242 else {
2243 hid_data->num_expected = wacom_wac->features.touch_max;
2244 }
Jason Gerecke06324e02015-07-21 11:07:23 -07002245}
2246
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002247static void wacom_wac_finger_report(struct hid_device *hdev,
2248 struct hid_report *report)
2249{
2250 struct wacom *wacom = hid_get_drvdata(hdev);
2251 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002252 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002253 unsigned touch_max = wacom_wac->features.touch_max;
2254
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002255 /* If more packets of data are expected, give us a chance to
2256 * process them rather than immediately syncing a partial
2257 * update.
2258 */
2259 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2260 return;
2261
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002262 if (touch_max > 1)
Jason Gerecke601a22f2014-12-10 16:26:04 -08002263 input_mt_sync_frame(input);
2264
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002265 input_sync(input);
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002266 wacom_wac->hid_data.num_received = 0;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002267
2268 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07002269 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002270}
2271
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002272void wacom_wac_usage_mapping(struct hid_device *hdev,
2273 struct hid_field *field, struct hid_usage *usage)
2274{
2275 struct wacom *wacom = hid_get_drvdata(hdev);
2276 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002277 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002278
2279 /* currently, only direct devices have proper hid report descriptors */
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002280 features->device_type |= WACOM_DEVICETYPE_DIRECT;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002281
Jason Gerecke5922e612016-10-19 18:03:51 -07002282 if (WACOM_PAD_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002283 wacom_wac_pad_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002284 else if (WACOM_PEN_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002285 wacom_wac_pen_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002286 else if (WACOM_FINGER_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002287 wacom_wac_finger_usage_mapping(hdev, field, usage);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002288}
2289
Ping Cheng354a3292016-12-08 22:03:27 -08002290void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002291 struct hid_usage *usage, __s32 value)
2292{
2293 struct wacom *wacom = hid_get_drvdata(hdev);
2294
2295 if (wacom->wacom_wac.features.type != HID_GENERIC)
Ping Cheng354a3292016-12-08 22:03:27 -08002296 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002297
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002298 if (WACOM_PAD_FIELD(field)) {
2299 wacom_wac_pad_battery_event(hdev, field, usage, value);
2300 if (wacom->wacom_wac.pad_input)
2301 wacom_wac_pad_event(hdev, field, usage, value);
2302 } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002303 wacom_wac_pen_event(hdev, field, usage, value);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002304 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002305 wacom_wac_finger_event(hdev, field, usage, value);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002306}
2307
Jason Gerecke06324e02015-07-21 11:07:23 -07002308static void wacom_report_events(struct hid_device *hdev, struct hid_report *report)
2309{
2310 int r;
2311
2312 for (r = 0; r < report->maxfield; r++) {
2313 struct hid_field *field;
2314 unsigned count, n;
2315
2316 field = report->field[r];
2317 count = field->report_count;
2318
2319 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2320 continue;
2321
2322 for (n = 0; n < count; n++)
2323 wacom_wac_event(hdev, field, &field->usage[n], field->value[n]);
2324 }
2325}
2326
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002327void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2328{
2329 struct wacom *wacom = hid_get_drvdata(hdev);
2330 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2331 struct hid_field *field = report->field[0];
2332
2333 if (wacom_wac->features.type != HID_GENERIC)
2334 return;
2335
Ping Cheng6f46cf92016-12-08 22:04:52 -08002336 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
Jason Gerecke5922e612016-10-19 18:03:51 -07002337 wacom_wac_pad_pre_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002338 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Jason Gerecke06324e02015-07-21 11:07:23 -07002339 wacom_wac_pen_pre_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002340 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Jason Gerecke06324e02015-07-21 11:07:23 -07002341 wacom_wac_finger_pre_report(hdev, report);
2342
2343 wacom_report_events(hdev, report);
2344
Jason Gereckea9ce7852017-01-17 15:38:58 -08002345 /*
2346 * Non-input reports may be sent prior to the device being
2347 * completely initialized. Since only their events need
2348 * to be processed, exit after 'wacom_report_events' has
2349 * been called to prevent potential crashes in the report-
2350 * processing functions.
2351 */
2352 if (report->type != HID_INPUT_REPORT)
2353 return;
2354
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002355 if (WACOM_PAD_FIELD(field)) {
2356 wacom_wac_pad_battery_report(hdev, report);
2357 if (wacom->wacom_wac.pad_input)
2358 wacom_wac_pad_report(hdev, report);
2359 } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2360 wacom_wac_pen_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002361 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002362 wacom_wac_finger_report(hdev, report);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002363}
2364
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002365static int wacom_bpt_touch(struct wacom_wac *wacom)
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002366{
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002367 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002368 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires31168712014-07-24 12:50:10 -07002369 struct input_dev *pad_input = wacom->pad_input;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002370 unsigned char *data = wacom->data;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002371 int i;
2372
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002373 if (data[0] != 0x02)
2374 return 0;
2375
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002376 for (i = 0; i < 2; i++) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002377 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
Ping Cheng1924e052016-08-09 14:38:56 -07002378 bool touch = report_touch_events(wacom)
2379 && (data[offset + 3] & 0x80);
Chris Bagwell8f906862011-09-09 13:38:10 -07002380
2381 input_mt_slot(input, i);
2382 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +01002383 if (touch) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002384 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2385 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002386 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2387 x <<= 5;
2388 y <<= 5;
2389 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002390 input_report_abs(input, ABS_MT_POSITION_X, x);
2391 input_report_abs(input, ABS_MT_POSITION_Y, y);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002392 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002393 }
2394
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05002395 input_mt_sync_frame(input);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002396
Benjamin Tissoires31168712014-07-24 12:50:10 -07002397 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2398 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2399 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2400 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
Ping Cheng7d059ed2015-03-20 14:57:21 -07002401 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002402
Benjamin Tissoires31168712014-07-24 12:50:10 -07002403 return 1;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002404}
2405
Ping Cheng7d059ed2015-03-20 14:57:21 -07002406static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002407{
Ping Cheng9a35c412013-09-20 09:51:56 -07002408 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002409 struct input_dev *input = wacom->touch_input;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002410 bool touch = data[1] & 0x80;
Ping Cheng02295e62013-01-04 23:56:00 -08002411 int slot = input_mt_get_slot_by_key(input, data[0]);
2412
2413 if (slot < 0)
Ping Cheng7d059ed2015-03-20 14:57:21 -07002414 return;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002415
Ping Cheng1924e052016-08-09 14:38:56 -07002416 touch = touch && report_touch_events(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002417
Ping Cheng02295e62013-01-04 23:56:00 -08002418 input_mt_slot(input, slot);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002419 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2420
2421 if (touch) {
2422 int x = (data[2] << 4) | (data[4] >> 4);
2423 int y = (data[3] << 4) | (data[4] & 0x0f);
Ping Cheng9a35c412013-09-20 09:51:56 -07002424 int width, height;
Jason Gerecke4e904952012-10-03 17:19:11 -07002425
Ping Chengeda01da2015-09-23 13:51:15 -07002426 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
Jason Gerecke0b279da2013-11-25 18:43:16 -08002427 width = data[5] * 100;
2428 height = data[6] * 100;
Ping Cheng9a35c412013-09-20 09:51:56 -07002429 } else {
2430 /*
2431 * "a" is a scaled-down area which we assume is
2432 * roughly circular and which can be described as:
2433 * a=(pi*r^2)/C.
2434 */
2435 int a = data[5];
Ping Chengd7da3a32014-06-13 13:37:33 -07002436 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2437 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2438 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
Ping Cheng9a35c412013-09-20 09:51:56 -07002439 height = width * y_res / x_res;
2440 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002441
2442 input_report_abs(input, ABS_MT_POSITION_X, x);
2443 input_report_abs(input, ABS_MT_POSITION_Y, y);
Jason Gerecke4e904952012-10-03 17:19:11 -07002444 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2445 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002446 }
2447}
2448
2449static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2450{
Benjamin Tissoires31168712014-07-24 12:50:10 -07002451 struct input_dev *input = wacom->pad_input;
Ping Chengb5fd2a32013-11-25 18:44:55 -08002452 struct wacom_features *features = &wacom->features;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002453
Ping Chengeda01da2015-09-23 13:51:15 -07002454 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
Ping Chengb5fd2a32013-11-25 18:44:55 -08002455 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
2456 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
2457 } else {
2458 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
2459 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
2460 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002461 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002462 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
2463}
2464
2465static int wacom_bpt3_touch(struct wacom_wac *wacom)
2466{
Chris Bagwell73149ab2011-10-26 22:34:21 -07002467 unsigned char *data = wacom->data;
Jason Gerecke19d57d32012-03-06 10:19:19 -08002468 int count = data[1] & 0x07;
Ping Chengeda01da2015-09-23 13:51:15 -07002469 int touch_changed = 0, i;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002470
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002471 if (data[0] != 0x02)
2472 return 0;
2473
Chris Bagwell73149ab2011-10-26 22:34:21 -07002474 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
2475 for (i = 0; i < count; i++) {
2476 int offset = (8 * i) + 2;
2477 int msg_id = data[offset];
2478
Ping Chengeda01da2015-09-23 13:51:15 -07002479 if (msg_id >= 2 && msg_id <= 17) {
Ping Cheng7d059ed2015-03-20 14:57:21 -07002480 wacom_bpt3_touch_msg(wacom, data + offset);
Ping Chengeda01da2015-09-23 13:51:15 -07002481 touch_changed++;
2482 } else if (msg_id == 128)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002483 wacom_bpt3_button_msg(wacom, data + offset);
2484
2485 }
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002486
Ping Chengeda01da2015-09-23 13:51:15 -07002487 /* only update touch if we actually have a touchpad and touch data changed */
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002488 if (wacom->touch_input && touch_changed) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002489 input_mt_sync_frame(wacom->touch_input);
2490 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2491 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002492
Benjamin Tissoires31168712014-07-24 12:50:10 -07002493 return 1;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002494}
2495
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002496static int wacom_bpt_pen(struct wacom_wac *wacom)
2497{
Ping Cheng961794a2013-12-05 12:54:53 -08002498 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002499 struct input_dev *input = wacom->pen_input;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002500 unsigned char *data = wacom->data;
2501 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
2502
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002503 if (data[0] != WACOM_REPORT_PENABLED)
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002504 return 0;
2505
Chris Bagwellc5981412011-10-26 22:28:34 -07002506 prox = (data[1] & 0x20) == 0x20;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002507
2508 /*
2509 * All reports shared between PEN and RUBBER tool must be
2510 * forced to a known starting value (zero) when transitioning to
2511 * out-of-prox.
2512 *
2513 * If not reset then, to userspace, it will look like lost events
2514 * if new tool comes in-prox with same values as previous tool sent.
2515 *
2516 * Hardware does report zero in most out-of-prox cases but not all.
2517 */
Ping Cheng01499312015-03-20 14:58:01 -07002518 if (!wacom->shared->stylus_in_proximity) {
2519 if (data[1] & 0x08) {
2520 wacom->tool[0] = BTN_TOOL_RUBBER;
2521 wacom->id[0] = ERASER_DEVICE_ID;
2522 } else {
2523 wacom->tool[0] = BTN_TOOL_PEN;
2524 wacom->id[0] = STYLUS_DEVICE_ID;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002525 }
Ping Cheng01499312015-03-20 14:58:01 -07002526 }
2527
2528 wacom->shared->stylus_in_proximity = prox;
Ping Cheng1924e052016-08-09 14:38:56 -07002529 if (delay_pen_events(wacom))
Ping Cheng01499312015-03-20 14:58:01 -07002530 return 0;
2531
2532 if (prox) {
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002533 x = le16_to_cpup((__le16 *)&data[2]);
2534 y = le16_to_cpup((__le16 *)&data[4]);
2535 p = le16_to_cpup((__le16 *)&data[6]);
Chris Bagwellc18c2ce2011-10-10 08:52:13 -07002536 /*
2537 * Convert distance from out prox to distance from tablet.
2538 * distance will be greater than distance_max once
2539 * touching and applying pressure; do not report negative
2540 * distance.
2541 */
Ping Cheng961794a2013-12-05 12:54:53 -08002542 if (data[8] <= features->distance_max)
2543 d = features->distance_max - data[8];
Chris Bagwellc18c2ce2011-10-10 08:52:13 -07002544
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002545 pen = data[1] & 0x01;
2546 btn1 = data[1] & 0x02;
2547 btn2 = data[1] & 0x04;
Ping Cheng01499312015-03-20 14:58:01 -07002548 } else {
2549 wacom->id[0] = 0;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002550 }
2551
2552 input_report_key(input, BTN_TOUCH, pen);
2553 input_report_key(input, BTN_STYLUS, btn1);
2554 input_report_key(input, BTN_STYLUS2, btn2);
2555
2556 input_report_abs(input, ABS_X, x);
2557 input_report_abs(input, ABS_Y, y);
2558 input_report_abs(input, ABS_PRESSURE, p);
2559 input_report_abs(input, ABS_DISTANCE, d);
2560
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002561 input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
2562 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
2563
2564 return 1;
2565}
2566
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002567static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
2568{
Ping Chengeda01da2015-09-23 13:51:15 -07002569 struct wacom_features *features = &wacom->features;
2570
2571 if ((features->type == INTUOSHT2) &&
Ping Chengeda01da2015-09-23 13:51:15 -07002572 (features->device_type & WACOM_DEVICETYPE_PEN))
2573 return wacom_intuos_irq(wacom);
2574 else if (len == WACOM_PKGLEN_BBTOUCH)
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002575 return wacom_bpt_touch(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002576 else if (len == WACOM_PKGLEN_BBTOUCH3)
2577 return wacom_bpt3_touch(wacom);
2578 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002579 return wacom_bpt_pen(wacom);
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002580
2581 return 0;
2582}
2583
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002584static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
2585 unsigned char *data)
2586{
2587 unsigned char prefix;
2588
2589 /*
2590 * We need to reroute the event from the debug interface to the
2591 * pen interface.
2592 * We need to add the report ID to the actual pen report, so we
2593 * temporary overwrite the first byte to prevent having to kzalloc/kfree
2594 * and memcpy the report.
2595 */
2596 prefix = data[0];
2597 data[0] = WACOM_REPORT_BPAD_PEN;
2598
2599 /*
2600 * actually reroute the event.
2601 * No need to check if wacom->shared->pen is valid, hid_input_report()
2602 * will check for us.
2603 */
2604 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
2605 WACOM_PKGLEN_PENABLED, 1);
2606
2607 data[0] = prefix;
2608}
2609
2610static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
2611 unsigned char *data)
2612{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002613 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002614 unsigned char *finger_data, prefix;
2615 unsigned id;
2616 int x, y;
2617 bool valid;
2618
2619 prefix = data[0];
2620
2621 for (id = 0; id < wacom->features.touch_max; id++) {
2622 valid = !!(prefix & BIT(id)) &&
Ping Cheng1924e052016-08-09 14:38:56 -07002623 report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002624
2625 input_mt_slot(input, id);
2626 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
2627
2628 if (!valid)
2629 continue;
2630
2631 finger_data = data + 1 + id * 3;
2632 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
2633 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
2634
2635 input_report_abs(input, ABS_MT_POSITION_X, x);
2636 input_report_abs(input, ABS_MT_POSITION_Y, y);
2637 }
2638
2639 input_mt_sync_frame(input);
2640
2641 input_report_key(input, BTN_LEFT, prefix & 0x40);
2642 input_report_key(input, BTN_RIGHT, prefix & 0x80);
2643
2644 /* keep touch state for pen event */
Ping Cheng1924e052016-08-09 14:38:56 -07002645 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002646
2647 return 1;
2648}
2649
2650static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
2651{
2652 unsigned char *data = wacom->data;
2653
2654 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
2655 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
2656 (data[0] != WACOM_REPORT_BPAD_TOUCH))
2657 return 0;
2658
2659 if (data[1] & 0x01)
2660 wacom_bamboo_pad_pen_event(wacom, &data[1]);
2661
2662 if (data[1] & 0x02)
2663 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
2664
2665 return 0;
2666}
2667
Chris Bagwelld3825d52012-03-25 23:26:11 -07002668static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
2669{
Chris Bagwell16bf2882012-03-25 23:26:20 -07002670 unsigned char *data = wacom->data;
2671 int connected;
2672
Ping Chengb5fd2a32013-11-25 18:44:55 -08002673 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
Chris Bagwelld3825d52012-03-25 23:26:11 -07002674 return 0;
2675
Chris Bagwell16bf2882012-03-25 23:26:20 -07002676 connected = data[1] & 0x01;
2677 if (connected) {
Jason Gereckeb0882cb2015-03-06 11:47:43 -08002678 int pid, battery, charging;
Chris Bagwell16bf2882012-03-25 23:26:20 -07002679
Ping Chengeda01da2015-09-23 13:51:15 -07002680 if ((wacom->shared->type == INTUOSHT ||
2681 wacom->shared->type == INTUOSHT2) &&
Ping Cheng44b96832014-11-06 17:30:51 -08002682 wacom->shared->touch_input &&
2683 wacom->shared->touch_max) {
Ping Cheng961794a2013-12-05 12:54:53 -08002684 input_report_switch(wacom->shared->touch_input,
2685 SW_MUTE_DEVICE, data[5] & 0x40);
2686 input_sync(wacom->shared->touch_input);
2687 }
2688
Chris Bagwell16bf2882012-03-25 23:26:20 -07002689 pid = get_unaligned_be16(&data[6]);
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07002690 battery = (data[5] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08002691 charging = !!(data[5] & 0x80);
Chris Bagwell16bf2882012-03-25 23:26:20 -07002692 if (wacom->pid != pid) {
2693 wacom->pid = pid;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002694 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Chris Bagwell16bf2882012-03-25 23:26:20 -07002695 }
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07002696
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02002697 wacom_notify_battery(wacom, battery, charging, 1, 0);
Jason Gerecke953f2c52015-03-06 11:47:39 -08002698
Chris Bagwell16bf2882012-03-25 23:26:20 -07002699 } else if (wacom->pid != 0) {
2700 /* disconnected while previously connected */
2701 wacom->pid = 0;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002702 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Jason Gerecke71fa6412015-03-11 10:25:41 -07002703 wacom_notify_battery(wacom, 0, 0, 0, 0);
Chris Bagwell16bf2882012-03-25 23:26:20 -07002704 }
2705
Chris Bagwelld3825d52012-03-25 23:26:11 -07002706 return 0;
2707}
2708
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002709static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
2710{
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002711 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002712 struct wacom_features *features = &wacom_wac->features;
2713 unsigned char *data = wacom_wac->data;
2714
2715 if (data[0] != WACOM_REPORT_USB)
2716 return 0;
2717
Ping Chengeda01da2015-09-23 13:51:15 -07002718 if ((features->type == INTUOSHT ||
2719 features->type == INTUOSHT2) &&
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002720 wacom_wac->shared->touch_input &&
2721 features->touch_max) {
2722 input_report_switch(wacom_wac->shared->touch_input,
2723 SW_MUTE_DEVICE, data[8] & 0x40);
2724 input_sync(wacom_wac->shared->touch_input);
2725 }
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002726
2727 if (data[9] & 0x02) { /* wireless module is attached */
2728 int battery = (data[8] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08002729 bool charging = !!(data[8] & 0x80);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002730
2731 wacom_notify_battery(wacom_wac, battery, charging,
Jason Gerecke71fa6412015-03-11 10:25:41 -07002732 battery || charging, 1);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002733
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02002734 if (!wacom->battery.battery &&
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002735 !(features->quirks & WACOM_QUIRK_BATTERY)) {
2736 features->quirks |= WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002737 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002738 }
2739 }
2740 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02002741 wacom->battery.battery) {
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002742 features->quirks &= ~WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002743 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke71fa6412015-03-11 10:25:41 -07002744 wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002745 }
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002746 return 0;
2747}
2748
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002749void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
Ping Cheng3bea7332006-07-13 18:01:36 -07002750{
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002751 bool sync;
2752
Jason Childse33da8a2010-02-17 22:38:31 -08002753 switch (wacom_wac->features.type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002754 case PENPARTNER:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002755 sync = wacom_penpartner_irq(wacom_wac);
2756 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002757
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002758 case PL:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002759 sync = wacom_pl_irq(wacom_wac);
2760 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002761
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002762 case WACOM_G4:
2763 case GRAPHIRE:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07002764 case GRAPHIRE_BT:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002765 case WACOM_MO:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002766 sync = wacom_graphire_irq(wacom_wac);
2767 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002768
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002769 case PTU:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002770 sync = wacom_ptu_irq(wacom_wac);
2771 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002772
Ping Chengc8f2edc2010-06-28 01:10:51 -07002773 case DTU:
2774 sync = wacom_dtu_irq(wacom_wac);
2775 break;
2776
Ping Cheng497ab1f2014-01-20 20:18:04 -08002777 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08002778 case DTUSX:
Ping Cheng497ab1f2014-01-20 20:18:04 -08002779 sync = wacom_dtus_irq(wacom_wac);
2780 break;
2781
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002782 case INTUOS:
2783 case INTUOS3S:
2784 case INTUOS3:
2785 case INTUOS3L:
2786 case INTUOS4S:
2787 case INTUOS4:
2788 case INTUOS4L:
2789 case CINTIQ:
2790 case WACOM_BEE:
Ping Cheng56218562013-05-05 19:56:18 -07002791 case WACOM_13HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07002792 case WACOM_21UX2:
Ping Chengd838c642012-07-24 23:54:11 -07002793 case WACOM_22HD:
Jason Gerecke803296b2011-12-12 00:11:45 -08002794 case WACOM_24HD:
Ping Cheng500d4162015-01-27 13:30:03 -08002795 case WACOM_27QHD:
Ping Chenga112e9f2013-02-13 20:20:01 -08002796 case DTK:
Jason Gerecke36d3c512013-09-20 09:47:35 -07002797 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07002798 case CINTIQ_COMPANION_2:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002799 sync = wacom_intuos_irq(wacom_wac);
2800 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002801
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07002802 case INTUOS4WL:
2803 sync = wacom_intuos_bt_irq(wacom_wac, len);
2804 break;
2805
Jason Gereckeb1e42792012-10-21 00:38:04 -07002806 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08002807 case WACOM_27QHDT:
Jason Gereckeb1e42792012-10-21 00:38:04 -07002808 sync = wacom_24hdt_irq(wacom_wac);
2809 break;
2810
Jason Gereckeae584ca2012-04-03 15:50:40 -07002811 case INTUOS5S:
2812 case INTUOS5:
2813 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07002814 case INTUOSPS:
2815 case INTUOSPM:
2816 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07002817 if (len == WACOM_PKGLEN_BBTOUCH3)
2818 sync = wacom_bpt3_touch(wacom_wac);
Jason Gerecke2d13a432015-03-06 11:47:42 -08002819 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
2820 sync = wacom_status_irq(wacom_wac, len);
Jason Gereckeae584ca2012-04-03 15:50:40 -07002821 else
2822 sync = wacom_intuos_irq(wacom_wac);
2823 break;
2824
Jason Gerecke4922cd22017-01-25 12:08:37 -08002825 case INTUOSP2_BT:
2826 sync = wacom_intuos_pro2_bt_irq(wacom_wac, len);
2827 break;
2828
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002829 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07002830 case TABLETPCE:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002831 case TABLETPC2FG:
Ping Cheng19635182012-04-29 21:09:18 -07002832 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07002833 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07002834 case MTTPC_B:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002835 sync = wacom_tpc_irq(wacom_wac, len);
2836 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002837
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002838 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07002839 case BAMBOO_PEN:
2840 case BAMBOO_TOUCH:
Ping Chengb5fd2a32013-11-25 18:44:55 -08002841 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07002842 case INTUOSHT2:
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002843 if (wacom_wac->data[0] == WACOM_REPORT_USB)
2844 sync = wacom_status_irq(wacom_wac, len);
2845 else
2846 sync = wacom_bpt_irq(wacom_wac, len);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002847 break;
2848
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002849 case BAMBOO_PAD:
2850 sync = wacom_bamboo_pad_irq(wacom_wac, len);
Ping Cheng3bea7332006-07-13 18:01:36 -07002851 break;
2852
Chris Bagwelld3825d52012-03-25 23:26:11 -07002853 case WIRELESS:
2854 sync = wacom_wireless_irq(wacom_wac, len);
2855 break;
2856
Aaron Skomra72b236d2015-08-20 16:05:17 -07002857 case REMOTE:
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002858 sync = false;
Aaron Skomra72b236d2015-08-20 16:05:17 -07002859 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002860 wacom_remote_status_irq(wacom_wac, len);
Aaron Skomra72b236d2015-08-20 16:05:17 -07002861 else
2862 sync = wacom_remote_irq(wacom_wac, len);
2863 break;
2864
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002865 default:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002866 sync = false;
2867 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07002868 }
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002869
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07002870 if (sync) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002871 if (wacom_wac->pen_input)
2872 input_sync(wacom_wac->pen_input);
2873 if (wacom_wac->touch_input)
2874 input_sync(wacom_wac->touch_input);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07002875 if (wacom_wac->pad_input)
2876 input_sync(wacom_wac->pad_input);
2877 }
Ping Cheng3bea7332006-07-13 18:01:36 -07002878}
2879
Ping Chengeda01da2015-09-23 13:51:15 -07002880static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
Ping Cheng3bea7332006-07-13 18:01:36 -07002881{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002882 struct input_dev *input_dev = wacom_wac->pen_input;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002883
2884 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002885
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002886 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002887 __set_bit(BTN_STYLUS, input_dev->keybit);
2888 __set_bit(BTN_STYLUS2, input_dev->keybit);
2889
2890 input_set_abs_params(input_dev, ABS_DISTANCE,
Jason Gereckebef7e202016-04-22 14:30:53 -07002891 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07002892}
2893
2894static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
2895{
2896 struct input_dev *input_dev = wacom_wac->pen_input;
Jason Gereckebef7e202016-04-22 14:30:53 -07002897 struct wacom_features *features = &wacom_wac->features;
Ping Chengeda01da2015-09-23 13:51:15 -07002898
2899 wacom_setup_basic_pro_pen(wacom_wac);
2900
2901 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2902 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
2903 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
2904 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
2905
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002906 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
Jason Gereckebef7e202016-04-22 14:30:53 -07002907 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002908 input_abs_set_res(input_dev, ABS_TILT_X, 57);
Jason Gereckebef7e202016-04-22 14:30:53 -07002909 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002910 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
Ping Cheng6521d0b2010-10-24 21:53:40 -07002911}
2912
2913static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
2914{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002915 struct input_dev *input_dev = wacom_wac->pen_input;
Ping Cheng6521d0b2010-10-24 21:53:40 -07002916
2917 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2918
2919 wacom_setup_cintiq(wacom_wac);
2920
2921 __set_bit(BTN_LEFT, input_dev->keybit);
2922 __set_bit(BTN_RIGHT, input_dev->keybit);
2923 __set_bit(BTN_MIDDLE, input_dev->keybit);
2924 __set_bit(BTN_SIDE, input_dev->keybit);
2925 __set_bit(BTN_EXTRA, input_dev->keybit);
2926 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2927 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
2928
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002929 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002930 input_abs_set_res(input_dev, ABS_RZ, 287);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002931 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
2932}
2933
Ping Cheng42f4f272015-04-15 16:53:54 -07002934void wacom_setup_device_quirks(struct wacom *wacom)
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002935{
Ping Cheng42f4f272015-04-15 16:53:54 -07002936 struct wacom_features *features = &wacom->wacom_wac.features;
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002937
Jason Gerecke862cf552015-06-15 18:01:43 -07002938 /* The pen and pad share the same interface on most devices */
Jason Gerecke5922e612016-10-19 18:03:51 -07002939 if (features->numbered_buttons > 0)
2940 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke862cf552015-06-15 18:01:43 -07002941 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
Ping Cheng3b164a02015-09-23 09:59:10 -07002942 features->type == DTUS ||
2943 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
Jason Gerecke862cf552015-06-15 18:01:43 -07002944 if (features->device_type & WACOM_DEVICETYPE_PEN)
2945 features->device_type |= WACOM_DEVICETYPE_PAD;
2946 }
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002947
2948 /* touch device found but size is not defined. use default */
Jason Gereckeaa86b182015-06-15 18:01:42 -07002949 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002950 features->x_max = 1023;
2951 features->y_max = 1023;
2952 }
2953
Ping Cheng42f4f272015-04-15 16:53:54 -07002954 /*
2955 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
2956 * touch interface in its HID descriptor. If this is the touch
2957 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
2958 * tablet values.
2959 */
Ping Cheng3b164a02015-09-23 09:59:10 -07002960 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
2961 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
Ping Cheng42f4f272015-04-15 16:53:54 -07002962 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
Jason Gerecke862cf552015-06-15 18:01:43 -07002963 if (features->touch_max)
2964 features->device_type |= WACOM_DEVICETYPE_TOUCH;
Jiri Kosinaa3088ab2015-11-17 00:24:14 +01002965 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
Jason Gerecke862cf552015-06-15 18:01:43 -07002966 features->device_type |= WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07002967
2968 features->x_max = 4096;
2969 features->y_max = 4096;
Ping Cheng42f4f272015-04-15 16:53:54 -07002970 }
Jason Gerecke96339202015-07-01 13:01:00 -07002971 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2972 features->device_type |= WACOM_DEVICETYPE_PAD;
2973 }
Ping Cheng42f4f272015-04-15 16:53:54 -07002974 }
2975
2976 /*
Benjamin Tissoires580549e2016-03-25 15:26:55 +01002977 * Hack for the Bamboo One:
2978 * the device presents a PAD/Touch interface as most Bamboos and even
2979 * sends ghosts PAD data on it. However, later, we must disable this
2980 * ghost interface, and we can not detect it unless we set it here
2981 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
2982 */
2983 if (features->type == BAMBOO_PEN &&
2984 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
2985 features->device_type |= WACOM_DEVICETYPE_PAD;
2986
2987 /*
Jason Gerecke042628a2015-04-30 17:51:54 -07002988 * Raw Wacom-mode pen and touch events both come from interface
2989 * 0, whose HID descriptor has an application usage of 0xFF0D
Jason Gerecke8de82282016-10-19 18:03:37 -07002990 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
Jason Gerecke042628a2015-04-30 17:51:54 -07002991 * out through the HID_GENERIC device created for interface 1,
Benjamin Tissoires70caee0a2015-07-09 14:11:51 -04002992 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
Ping Cheng42f4f272015-04-15 16:53:54 -07002993 */
2994 if (features->type == BAMBOO_PAD)
Benjamin Tissoires70caee0a2015-07-09 14:11:51 -04002995 features->device_type = WACOM_DEVICETYPE_TOUCH;
Ping Cheng42f4f272015-04-15 16:53:54 -07002996
Aaron Skomra72b236d2015-08-20 16:05:17 -07002997 if (features->type == REMOTE)
2998 features->device_type = WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07002999
Jason Gerecke4922cd22017-01-25 12:08:37 -08003000 if (features->type == INTUOSP2_BT) {
3001 features->device_type |= WACOM_DEVICETYPE_PEN |
3002 WACOM_DEVICETYPE_PAD |
3003 WACOM_DEVICETYPE_TOUCH;
3004 features->quirks |= WACOM_QUIRK_BATTERY;
3005 }
3006
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003007 switch (features->type) {
3008 case PL:
3009 case DTU:
3010 case DTUS:
3011 case DTUSX:
3012 case WACOM_21UX2:
3013 case WACOM_22HD:
3014 case DTK:
3015 case WACOM_24HD:
3016 case WACOM_27QHD:
3017 case CINTIQ_HYBRID:
3018 case CINTIQ_COMPANION_2:
3019 case CINTIQ:
3020 case WACOM_BEE:
3021 case WACOM_13HD:
3022 case WACOM_24HDT:
3023 case WACOM_27QHDT:
3024 case TABLETPC:
3025 case TABLETPCE:
3026 case TABLETPC2FG:
3027 case MTSCREEN:
3028 case MTTPC:
3029 case MTTPC_B:
3030 features->device_type |= WACOM_DEVICETYPE_DIRECT;
3031 break;
3032 }
3033
Ping Cheng42f4f272015-04-15 16:53:54 -07003034 if (wacom->hdev->bus == BUS_BLUETOOTH)
3035 features->quirks |= WACOM_QUIRK_BATTERY;
3036
Chris Bagwell73149ab2011-10-26 22:34:21 -07003037 /* quirk for bamboo touch with 2 low res touches */
Jason Gereckebe853fd2015-12-04 14:45:27 -08003038 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
Chris Bagwell73149ab2011-10-26 22:34:21 -07003039 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07003040 features->x_max <<= 5;
3041 features->y_max <<= 5;
3042 features->x_fuzz <<= 5;
3043 features->y_fuzz <<= 5;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07003044 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003045 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07003046
3047 if (features->type == WIRELESS) {
Jason Gereckeccad85c2015-08-03 10:17:04 -07003048 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003049 features->quirks |= WACOM_QUIRK_BATTERY;
3050 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07003051 }
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02003052
3053 if (features->type == REMOTE)
3054 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003055}
3056
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003057int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
Ping Cheng19635182012-04-29 21:09:18 -07003058 struct wacom_wac *wacom_wac)
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003059{
3060 struct wacom_features *features = &wacom_wac->features;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003061
3062 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3063
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003064 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
3065 return -ENODEV;
3066
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003067 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3068 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3069 else
3070 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3071
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04003072 if (features->type == HID_GENERIC)
3073 /* setup has already been done */
3074 return 0;
3075
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003076 __set_bit(BTN_TOUCH, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003077 __set_bit(ABS_MISC, input_dev->absbit);
3078
Jason Gereckee779ef22016-10-19 18:03:49 -07003079 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
3080 features->x_max - features->offset_right,
3081 features->x_fuzz, 0);
3082 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
3083 features->y_max - features->offset_bottom,
3084 features->y_fuzz, 0);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003085 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
3086 features->pressure_max, features->pressure_fuzz, 0);
3087
3088 /* penabled devices have fixed resolution for each model */
3089 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
3090 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
3091
Ping Cheng497ab1f2014-01-20 20:18:04 -08003092 switch (features->type) {
Ping Chenga2f71c62015-01-27 13:29:36 -08003093 case GRAPHIRE_BT:
3094 __clear_bit(ABS_MISC, input_dev->absbit);
3095
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003096 case WACOM_MO:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003097 case WACOM_G4:
Ping Chenga2f71c62015-01-27 13:29:36 -08003098 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3099 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003100 features->distance_fuzz, 0);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003101 /* fall through */
3102
3103 case GRAPHIRE:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003104 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3105
3106 __set_bit(BTN_LEFT, input_dev->keybit);
3107 __set_bit(BTN_RIGHT, input_dev->keybit);
3108 __set_bit(BTN_MIDDLE, input_dev->keybit);
3109
3110 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3111 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3112 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3113 __set_bit(BTN_STYLUS, input_dev->keybit);
3114 __set_bit(BTN_STYLUS2, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003115 break;
3116
Ping Cheng500d4162015-01-27 13:30:03 -08003117 case WACOM_27QHD:
Jason Gerecke803296b2011-12-12 00:11:45 -08003118 case WACOM_24HD:
Ping Chenga112e9f2013-02-13 20:20:01 -08003119 case DTK:
Ping Chengd838c642012-07-24 23:54:11 -07003120 case WACOM_22HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003121 case WACOM_21UX2:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003122 case WACOM_BEE:
Ping Cheng6521d0b2010-10-24 21:53:40 -07003123 case CINTIQ:
Ping Cheng56218562013-05-05 19:56:18 -07003124 case WACOM_13HD:
Ping Chenga2f71c62015-01-27 13:29:36 -08003125 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003126 case CINTIQ_COMPANION_2:
Ping Cheng56218562013-05-05 19:56:18 -07003127 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003128 input_abs_set_res(input_dev, ABS_Z, 287);
Ping Cheng56218562013-05-05 19:56:18 -07003129 wacom_setup_cintiq(wacom_wac);
3130 break;
3131
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003132 case INTUOS3:
3133 case INTUOS3L:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003134 case INTUOS3S:
Ping Chenga2f71c62015-01-27 13:29:36 -08003135 case INTUOS4:
3136 case INTUOS4WL:
3137 case INTUOS4L:
3138 case INTUOS4S:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003139 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003140 input_abs_set_res(input_dev, ABS_Z, 287);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003141 /* fall through */
3142
3143 case INTUOS:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003144 wacom_setup_intuos(wacom_wac);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003145 break;
3146
Jason Gerecke9fee6192012-04-03 15:47:22 -07003147 case INTUOS5:
3148 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07003149 case INTUOSPM:
3150 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07003151 case INTUOS5S:
Ping Cheng9a35c412013-09-20 09:51:56 -07003152 case INTUOSPS:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003153 case INTUOSP2_BT:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003154 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3155 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003156 features->distance_fuzz, 0);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003157
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003158 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
3159 input_abs_set_res(input_dev, ABS_Z, 287);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003160
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003161 wacom_setup_intuos(wacom_wac);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003162 break;
3163
Jason Gereckeb1e42792012-10-21 00:38:04 -07003164 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08003165 case WACOM_27QHDT:
Ping Cheng19635182012-04-29 21:09:18 -07003166 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07003167 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07003168 case MTTPC_B:
Ping Cheng6795a522012-06-28 16:49:00 -07003169 case TABLETPC2FG:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003170 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07003171 case TABLETPCE:
Ping Chenga43c7c52011-03-12 20:34:42 -08003172 __clear_bit(ABS_MISC, input_dev->absbit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003173 /* fall through */
3174
Ping Cheng497ab1f2014-01-20 20:18:04 -08003175 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08003176 case DTUSX:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003177 case PL:
Ping Chengc8f2edc2010-06-28 01:10:51 -07003178 case DTU:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003179 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003180 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003181 __set_bit(BTN_STYLUS, input_dev->keybit);
3182 __set_bit(BTN_STYLUS2, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003183 break;
3184
3185 case PTU:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003186 __set_bit(BTN_STYLUS2, input_dev->keybit);
3187 /* fall through */
3188
3189 case PENPARTNER:
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003190 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003191 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003192 __set_bit(BTN_STYLUS, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003193 break;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003194
Ping Chengb5fd2a32013-11-25 18:44:55 -08003195 case INTUOSHT:
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003196 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003197 case BAMBOO_PEN:
Ping Chengeda01da2015-09-23 13:51:15 -07003198 case INTUOSHT2:
Ping Chengeda01da2015-09-23 13:51:15 -07003199 if (features->type == INTUOSHT2) {
3200 wacom_setup_basic_pro_pen(wacom_wac);
3201 } else {
3202 __clear_bit(ABS_MISC, input_dev->absbit);
3203 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3204 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3205 __set_bit(BTN_STYLUS, input_dev->keybit);
3206 __set_bit(BTN_STYLUS2, input_dev->keybit);
3207 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003208 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003209 features->distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07003210 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003211 break;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003212 case BAMBOO_PAD:
3213 __clear_bit(ABS_MISC, input_dev->absbit);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003214 break;
3215 }
3216 return 0;
3217}
3218
3219int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3220 struct wacom_wac *wacom_wac)
3221{
3222 struct wacom_features *features = &wacom_wac->features;
3223
3224 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3225
3226 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3227 return -ENODEV;
3228
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003229 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3230 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3231 else
3232 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3233
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003234 if (features->type == HID_GENERIC)
3235 /* setup has already been done */
3236 return 0;
3237
3238 __set_bit(BTN_TOUCH, input_dev->keybit);
3239
3240 if (features->touch_max == 1) {
3241 input_set_abs_params(input_dev, ABS_X, 0,
3242 features->x_max, features->x_fuzz, 0);
3243 input_set_abs_params(input_dev, ABS_Y, 0,
3244 features->y_max, features->y_fuzz, 0);
3245 input_abs_set_res(input_dev, ABS_X,
3246 features->x_resolution);
3247 input_abs_set_res(input_dev, ABS_Y,
3248 features->y_resolution);
3249 }
3250 else if (features->touch_max > 1) {
3251 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3252 features->x_max, features->x_fuzz, 0);
3253 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3254 features->y_max, features->y_fuzz, 0);
3255 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3256 features->x_resolution);
3257 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3258 features->y_resolution);
3259 }
3260
3261 switch (features->type) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08003262 case INTUOSP2_BT:
3263 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3264 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3265
3266 if (wacom_wac->shared->touch->product == 0x361) {
3267 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3268 0, 12440, 4, 0);
3269 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3270 0, 8640, 4, 0);
3271 }
3272 else if (wacom_wac->shared->touch->product == 0x360) {
3273 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3274 0, 8960, 4, 0);
3275 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3276 0, 5920, 4, 0);
3277 }
3278 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
3279 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
3280
3281 /* fall through */
3282
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003283 case INTUOS5:
3284 case INTUOS5L:
3285 case INTUOSPM:
3286 case INTUOSPL:
3287 case INTUOS5S:
3288 case INTUOSPS:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003289 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3290 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3291 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3292 break;
3293
3294 case WACOM_24HDT:
3295 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3296 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3297 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3298 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
3299 /* fall through */
3300
3301 case WACOM_27QHDT:
3302 case MTSCREEN:
3303 case MTTPC:
3304 case MTTPC_B:
3305 case TABLETPC2FG:
3306 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
3307 /*fall through */
3308
3309 case TABLETPC:
3310 case TABLETPCE:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003311 break;
3312
3313 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07003314 case INTUOSHT2:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003315 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3316 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3317 /* fall through */
3318
3319 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003320 case BAMBOO_TOUCH:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003321 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3322 input_set_abs_params(input_dev,
3323 ABS_MT_TOUCH_MAJOR,
3324 0, features->x_max, 0, 0);
3325 input_set_abs_params(input_dev,
3326 ABS_MT_TOUCH_MINOR,
3327 0, features->y_max, 0, 0);
3328 }
3329 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3330 break;
3331
3332 case BAMBOO_PAD:
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003333 input_mt_init_slots(input_dev, features->touch_max,
3334 INPUT_MT_POINTER);
3335 __set_bit(BTN_LEFT, input_dev->keybit);
3336 __set_bit(BTN_RIGHT, input_dev->keybit);
3337 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07003338 }
Ping Cheng19635182012-04-29 21:09:18 -07003339 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07003340}
3341
Jason Gerecke49005b92016-10-19 18:03:39 -07003342static int wacom_numbered_button_to_key(int n)
3343{
3344 if (n < 10)
3345 return BTN_0 + n;
3346 else if (n < 16)
3347 return BTN_A + (n-10);
3348 else if (n < 18)
3349 return BTN_BASE + (n-16);
3350 else
3351 return 0;
3352}
3353
Jiri Kosina5397df12015-08-28 20:46:42 +02003354static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003355 int button_count)
3356{
3357 int i;
3358
Jason Gerecke49005b92016-10-19 18:03:39 -07003359 for (i = 0; i < button_count; i++) {
3360 int key = wacom_numbered_button_to_key(i);
3361
3362 if (key)
3363 __set_bit(key, input_dev->keybit);
3364 }
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003365}
3366
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003367static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3368{
3369 struct wacom_led *led;
3370 int i;
3371 bool updated = false;
3372
3373 /*
3374 * 24HD has LED group 1 to the left and LED group 0 to the right.
3375 * So group 0 matches the second half of the buttons and thus the mask
3376 * needs to be shifted.
3377 */
3378 if (group == 0)
3379 mask >>= 8;
3380
3381 for (i = 0; i < 3; i++) {
3382 led = wacom_led_find(wacom, group, i);
3383 if (!led) {
3384 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3385 i, group);
3386 continue;
3387 }
3388 if (!updated && mask & BIT(i)) {
3389 led->held = true;
3390 led_trigger_event(&led->trigger, LED_FULL);
3391 } else {
3392 led->held = false;
3393 }
3394 }
3395}
3396
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003397static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
3398 int mask, int group)
3399{
3400 int button_per_group;
3401
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003402 /*
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003403 * 21UX2 has LED group 1 to the left and LED group 0
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003404 * to the right. We need to reverse the group to match this
3405 * historical behavior.
3406 */
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003407 if (wacom->wacom_wac.features.type == WACOM_21UX2)
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003408 group = 1 - group;
3409
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003410 button_per_group = button_count/wacom->led.count;
3411
3412 return mask & (1 << (group * button_per_group));
3413}
3414
3415static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
3416 int group)
3417{
3418 struct wacom_led *led, *next_led;
3419 int cur;
3420 bool pressed;
3421
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003422 if (wacom->wacom_wac.features.type == WACOM_24HD)
3423 return wacom_24hd_update_leds(wacom, mask, group);
3424
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003425 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
3426 cur = wacom->led.groups[group].select;
3427
3428 led = wacom_led_find(wacom, group, cur);
3429 if (!led) {
3430 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
3431 cur, group);
3432 return;
3433 }
3434
3435 if (!pressed) {
3436 led->held = false;
3437 return;
3438 }
3439
3440 if (led->held && pressed)
3441 return;
3442
3443 next_led = wacom_led_next(wacom, led);
3444 if (!next_led) {
3445 hid_err(wacom->hdev, "can't find next LED in group %d\n",
3446 group);
3447 return;
3448 }
3449 if (next_led == led)
3450 return;
3451
3452 next_led->held = true;
3453 led_trigger_event(&next_led->trigger,
3454 wacom_leds_brightness_get(next_led));
3455}
3456
Jason Gereckec7f05222015-11-30 17:13:47 -08003457static void wacom_report_numbered_buttons(struct input_dev *input_dev,
3458 int button_count, int mask)
3459{
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003460 struct wacom *wacom = input_get_drvdata(input_dev);
Jason Gereckec7f05222015-11-30 17:13:47 -08003461 int i;
3462
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003463 for (i = 0; i < wacom->led.count; i++)
3464 wacom_update_led(wacom, button_count, mask, i);
3465
Jason Gerecke49005b92016-10-19 18:03:39 -07003466 for (i = 0; i < button_count; i++) {
3467 int key = wacom_numbered_button_to_key(i);
3468
3469 if (key)
3470 input_report_key(input_dev, key, mask & (1 << i));
3471 }
Jason Gereckec7f05222015-11-30 17:13:47 -08003472}
3473
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003474int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3475 struct wacom_wac *wacom_wac)
3476{
3477 struct wacom_features *features = &wacom_wac->features;
3478
Jason Gerecke862cf552015-06-15 18:01:43 -07003479 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
3480 return -ENODEV;
3481
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02003482 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
3483 return -ENODEV;
3484
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003485 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3486
3487 /* kept for making legacy xf86-input-wacom working with the wheels */
3488 __set_bit(ABS_MISC, input_dev->absbit);
3489
3490 /* kept for making legacy xf86-input-wacom accepting the pad */
Jason Gerecke5922e612016-10-19 18:03:51 -07003491 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
3492 input_dev->absinfo[ABS_X].maximum)))
3493 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
3494 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
3495 input_dev->absinfo[ABS_Y].maximum)))
3496 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003497
Benjamin Tissoires12969e32014-09-11 13:14:04 -04003498 /* kept for making udev and libwacom accepting the pad */
3499 __set_bit(BTN_STYLUS, input_dev->keybit);
3500
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003501 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
3502
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003503 switch (features->type) {
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003504
3505 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003506 case CINTIQ_COMPANION_2:
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003507 case DTK:
3508 case DTUS:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003509 case GRAPHIRE_BT:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003510 break;
3511
Benjamin Tissoires38138102014-07-24 12:51:03 -07003512 case WACOM_MO:
3513 __set_bit(BTN_BACK, input_dev->keybit);
3514 __set_bit(BTN_LEFT, input_dev->keybit);
3515 __set_bit(BTN_FORWARD, input_dev->keybit);
3516 __set_bit(BTN_RIGHT, input_dev->keybit);
3517 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3518 break;
3519
3520 case WACOM_G4:
3521 __set_bit(BTN_BACK, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07003522 __set_bit(BTN_FORWARD, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07003523 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3524 break;
3525
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003526 case WACOM_24HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003527 __set_bit(KEY_PROG1, input_dev->keybit);
3528 __set_bit(KEY_PROG2, input_dev->keybit);
3529 __set_bit(KEY_PROG3, input_dev->keybit);
3530
3531 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3532 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
3533 break;
3534
Ping Cheng500d4162015-01-27 13:30:03 -08003535 case WACOM_27QHD:
3536 __set_bit(KEY_PROG1, input_dev->keybit);
3537 __set_bit(KEY_PROG2, input_dev->keybit);
3538 __set_bit(KEY_PROG3, input_dev->keybit);
3539 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
3540 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
3541 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
3542 input_abs_set_res(input_dev, ABS_Y, 1024);
3543 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
3544 input_abs_set_res(input_dev, ABS_Z, 1024);
3545 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
3546 break;
3547
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003548 case WACOM_22HD:
3549 __set_bit(KEY_PROG1, input_dev->keybit);
3550 __set_bit(KEY_PROG2, input_dev->keybit);
3551 __set_bit(KEY_PROG3, input_dev->keybit);
3552 /* fall through */
3553
3554 case WACOM_21UX2:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003555 case WACOM_BEE:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003556 case CINTIQ:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003557 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3558 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3559 break;
3560
3561 case WACOM_13HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003562 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3563 break;
3564
3565 case INTUOS3:
3566 case INTUOS3L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003567 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3568 /* fall through */
3569
3570 case INTUOS3S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003571 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3572 break;
3573
3574 case INTUOS5:
3575 case INTUOS5L:
3576 case INTUOSPM:
3577 case INTUOSPL:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003578 case INTUOS5S:
3579 case INTUOSPS:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003580 case INTUOSP2_BT:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003581 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3582 break;
3583
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07003584 case INTUOS4WL:
3585 /*
3586 * For Bluetooth devices, the udev rule does not work correctly
3587 * for pads unless we add a stylus capability, which forces
3588 * ID_INPUT_TABLET to be set.
3589 */
3590 __set_bit(BTN_STYLUS, input_dev->keybit);
3591 /* fall through */
3592
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003593 case INTUOS4:
3594 case INTUOS4L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003595 case INTUOS4S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003596 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3597 break;
3598
Benjamin Tissoires31168712014-07-24 12:50:10 -07003599 case INTUOSHT:
3600 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003601 case BAMBOO_TOUCH:
Ping Chengeda01da2015-09-23 13:51:15 -07003602 case INTUOSHT2:
Benjamin Tissoires31168712014-07-24 12:50:10 -07003603 __clear_bit(ABS_MISC, input_dev->absbit);
3604
3605 __set_bit(BTN_LEFT, input_dev->keybit);
3606 __set_bit(BTN_FORWARD, input_dev->keybit);
3607 __set_bit(BTN_BACK, input_dev->keybit);
3608 __set_bit(BTN_RIGHT, input_dev->keybit);
3609
3610 break;
3611
Aaron Skomra72b236d2015-08-20 16:05:17 -07003612 case REMOTE:
3613 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
3614 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3615 break;
3616
Jason Gerecke5922e612016-10-19 18:03:51 -07003617 case HID_GENERIC:
3618 break;
3619
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003620 default:
3621 /* no pad supported */
Ping Chengb3c8e932014-11-18 13:27:48 -08003622 return -ENODEV;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003623 }
3624 return 0;
3625}
3626
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003627static const struct wacom_features wacom_features_0x00 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003628 { "Wacom Penpartner", 5040, 3780, 255, 0,
3629 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003630static const struct wacom_features wacom_features_0x10 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003631 { "Wacom Graphire", 10206, 7422, 511, 63,
3632 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003633static const struct wacom_features wacom_features_0x81 =
3634 { "Wacom Graphire BT", 16704, 12064, 511, 32,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003635 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003636static const struct wacom_features wacom_features_0x11 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003637 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
3638 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003639static const struct wacom_features wacom_features_0x12 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003640 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
3641 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003642static const struct wacom_features wacom_features_0x13 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003643 { "Wacom Graphire3", 10208, 7424, 511, 63,
3644 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003645static const struct wacom_features wacom_features_0x14 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003646 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
3647 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003648static const struct wacom_features wacom_features_0x15 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003649 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
3650 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003651static const struct wacom_features wacom_features_0x16 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003652 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
3653 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003654static const struct wacom_features wacom_features_0x17 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003655 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
3656 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003657static const struct wacom_features wacom_features_0x18 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003658 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
3659 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003660static const struct wacom_features wacom_features_0x19 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003661 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
3662 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003663static const struct wacom_features wacom_features_0x60 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003664 { "Wacom Volito", 5104, 3712, 511, 63,
3665 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003666static const struct wacom_features wacom_features_0x61 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003667 { "Wacom PenStation2", 3250, 2320, 255, 63,
3668 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003669static const struct wacom_features wacom_features_0x62 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003670 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
3671 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003672static const struct wacom_features wacom_features_0x63 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003673 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
3674 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003675static const struct wacom_features wacom_features_0x64 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003676 { "Wacom PenPartner2", 3250, 2320, 511, 63,
3677 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003678static const struct wacom_features wacom_features_0x65 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003679 { "Wacom Bamboo", 14760, 9225, 511, 63,
3680 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003681static const struct wacom_features wacom_features_0x69 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003682 { "Wacom Bamboo1", 5104, 3712, 511, 63,
3683 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07003684static const struct wacom_features wacom_features_0x6A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003685 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
3686 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07003687static const struct wacom_features wacom_features_0x6B =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003688 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
3689 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003690static const struct wacom_features wacom_features_0x20 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003691 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
3692 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003693static const struct wacom_features wacom_features_0x21 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003694 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
3695 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003696static const struct wacom_features wacom_features_0x22 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003697 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
3698 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003699static const struct wacom_features wacom_features_0x23 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003700 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
3701 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003702static const struct wacom_features wacom_features_0x24 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003703 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
3704 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003705static const struct wacom_features wacom_features_0x30 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003706 { "Wacom PL400", 5408, 4056, 255, 0,
3707 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003708static const struct wacom_features wacom_features_0x31 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003709 { "Wacom PL500", 6144, 4608, 255, 0,
3710 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003711static const struct wacom_features wacom_features_0x32 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003712 { "Wacom PL600", 6126, 4604, 255, 0,
3713 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003714static const struct wacom_features wacom_features_0x33 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003715 { "Wacom PL600SX", 6260, 5016, 255, 0,
3716 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003717static const struct wacom_features wacom_features_0x34 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003718 { "Wacom PL550", 6144, 4608, 511, 0,
3719 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003720static const struct wacom_features wacom_features_0x35 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003721 { "Wacom PL800", 7220, 5780, 511, 0,
3722 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003723static const struct wacom_features wacom_features_0x37 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003724 { "Wacom PL700", 6758, 5406, 511, 0,
3725 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003726static const struct wacom_features wacom_features_0x38 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003727 { "Wacom PL510", 6282, 4762, 511, 0,
3728 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003729static const struct wacom_features wacom_features_0x39 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003730 { "Wacom DTU710", 34080, 27660, 511, 0,
3731 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003732static const struct wacom_features wacom_features_0xC4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003733 { "Wacom DTF521", 6282, 4762, 511, 0,
3734 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003735static const struct wacom_features wacom_features_0xC0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003736 { "Wacom DTF720", 6858, 5506, 511, 0,
3737 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003738static const struct wacom_features wacom_features_0xC2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003739 { "Wacom DTF720a", 6858, 5506, 511, 0,
3740 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003741static const struct wacom_features wacom_features_0x03 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003742 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
3743 PTU, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003744static const struct wacom_features wacom_features_0x41 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003745 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
3746 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003747static const struct wacom_features wacom_features_0x42 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003748 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3749 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003750static const struct wacom_features wacom_features_0x43 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003751 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
3752 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003753static const struct wacom_features wacom_features_0x44 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003754 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
3755 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003756static const struct wacom_features wacom_features_0x45 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003757 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
3758 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003759static const struct wacom_features wacom_features_0xB0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003760 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003761 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003762static const struct wacom_features wacom_features_0xB1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003763 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003764 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003765static const struct wacom_features wacom_features_0xB2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003766 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003767 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003768static const struct wacom_features wacom_features_0xB3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003769 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003770 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003771static const struct wacom_features wacom_features_0xB4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003772 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003773 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003774static const struct wacom_features wacom_features_0xB5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003775 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003776 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003777static const struct wacom_features wacom_features_0xB7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003778 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003779 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003780static const struct wacom_features wacom_features_0xB8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003781 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003782 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003783static const struct wacom_features wacom_features_0xB9 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003784 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003785 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003786static const struct wacom_features wacom_features_0xBA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003787 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003788 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003789static const struct wacom_features wacom_features_0xBB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003790 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003791 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003792static const struct wacom_features wacom_features_0xBC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003793 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003794 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07003795static const struct wacom_features wacom_features_0xBD =
3796 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003797 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003798static const struct wacom_features wacom_features_0x26 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003799 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003800 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003801static const struct wacom_features wacom_features_0x27 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003802 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003803 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003804static const struct wacom_features wacom_features_0x28 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003805 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003806 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003807static const struct wacom_features wacom_features_0x29 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003808 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003809 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003810static const struct wacom_features wacom_features_0x2A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003811 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003812 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng9a35c412013-09-20 09:51:56 -07003813static const struct wacom_features wacom_features_0x314 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003814 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003815 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003816 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07003817static const struct wacom_features wacom_features_0x315 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003818 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003819 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003820 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07003821static const struct wacom_features wacom_features_0x317 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003822 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003823 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003824 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Jason Gerecke803296b2011-12-12 00:11:45 -08003825static const struct wacom_features wacom_features_0xF4 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003826 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003827 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Jason Gereckee779ef22016-10-19 18:03:49 -07003828 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003829 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Jason Gerecke6f4d0382012-08-21 22:11:59 -07003830static const struct wacom_features wacom_features_0xF8 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003831 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003832 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Ping Chengfa770342014-12-01 13:44:28 -08003833 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003834 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07003835 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
Jason Gereckeb1e42792012-10-21 00:38:04 -07003836static const struct wacom_features wacom_features_0xF6 =
3837 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003838 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
3839 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng500d4162015-01-27 13:30:03 -08003840static const struct wacom_features wacom_features_0x32A =
Jason Gereckee779ef22016-10-19 18:03:49 -07003841 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003842 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07003843 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga7e66452015-02-04 16:01:54 -08003844 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng500d4162015-01-27 13:30:03 -08003845static const struct wacom_features wacom_features_0x32B =
Jason Gereckee779ef22016-10-19 18:03:49 -07003846 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003847 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Ping Cheng500d4162015-01-27 13:30:03 -08003848 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003849 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng500d4162015-01-27 13:30:03 -08003850 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
3851static const struct wacom_features wacom_features_0x32C =
3852 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
3853 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003854static const struct wacom_features wacom_features_0x3F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003855 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003856 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003857static const struct wacom_features wacom_features_0xC5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003858 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003859 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003860static const struct wacom_features wacom_features_0xC6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003861 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003862 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Ping Cheng56218562013-05-05 19:56:18 -07003863static const struct wacom_features wacom_features_0x304 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003864 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003865 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Jason Gereckee779ef22016-10-19 18:03:49 -07003866 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003867 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengb4bf2122015-03-25 17:08:13 -07003868static const struct wacom_features wacom_features_0x333 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003869 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003870 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengb4bf2122015-03-25 17:08:13 -07003871 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003872 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengb4bf2122015-03-25 17:08:13 -07003873 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
3874static const struct wacom_features wacom_features_0x335 =
3875 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
3876 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
3877 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003878static const struct wacom_features wacom_features_0xC7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003879 { "Wacom DTU1931", 37832, 30305, 511, 0,
3880 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengc8f2edc2010-06-28 01:10:51 -07003881static const struct wacom_features wacom_features_0xCE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003882 { "Wacom DTU2231", 47864, 27011, 511, 0,
3883 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003884 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
Ping Chengc8f2edc2010-06-28 01:10:51 -07003885static const struct wacom_features wacom_features_0xF0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003886 { "Wacom DTU1631", 34623, 19553, 511, 0,
3887 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng497ab1f2014-01-20 20:18:04 -08003888static const struct wacom_features wacom_features_0xFB =
Jason Gereckee779ef22016-10-19 18:03:49 -07003889 { "Wacom DTU1031", 22096, 13960, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003890 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07003891 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003892 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Chengfff00bf2014-12-04 18:23:04 -08003893static const struct wacom_features wacom_features_0x32F =
Jason Gereckee779ef22016-10-19 18:03:49 -07003894 { "Wacom DTU1031X", 22672, 12928, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003895 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07003896 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfff00bf2014-12-04 18:23:04 -08003897 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Aaron Skomra007760c2015-04-16 15:01:14 -07003898static const struct wacom_features wacom_features_0x336 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003899 { "Wacom DTU1141", 23672, 13403, 1023, 0,
Ping Chengff38e822015-11-12 17:21:14 -08003900 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07003901 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengff38e822015-11-12 17:21:14 -08003902 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07003903static const struct wacom_features wacom_features_0x57 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003904 { "Wacom DTK2241", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003905 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Jason Gereckee779ef22016-10-19 18:03:49 -07003906 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003907 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chenga112e9f2013-02-13 20:20:01 -08003908static const struct wacom_features wacom_features_0x59 = /* Pen */
Jason Gereckee779ef22016-10-19 18:03:49 -07003909 { "Wacom DTH2242", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003910 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Ping Chengfa770342014-12-01 13:44:28 -08003911 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003912 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga112e9f2013-02-13 20:20:01 -08003913 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
3914static const struct wacom_features wacom_features_0x5D = /* Touch */
3915 { "Wacom DTH2242", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003916 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
3917 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003918static const struct wacom_features wacom_features_0xCC =
Jason Gereckee779ef22016-10-19 18:03:49 -07003919 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003920 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07003921 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003922 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengd838c642012-07-24 23:54:11 -07003923static const struct wacom_features wacom_features_0xFA =
Jason Gereckee779ef22016-10-19 18:03:49 -07003924 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003925 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07003926 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003927 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07003928static const struct wacom_features wacom_features_0x5B =
Jason Gereckee779ef22016-10-19 18:03:49 -07003929 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003930 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Ping Chengfa770342014-12-01 13:44:28 -08003931 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003932 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07003933 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
Ping Cheng56218562013-05-05 19:56:18 -07003934static const struct wacom_features wacom_features_0x5E =
3935 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003936 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
3937 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003938static const struct wacom_features wacom_features_0x90 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003939 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
3940 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003941static const struct wacom_features wacom_features_0x93 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003942 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
3943 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07003944static const struct wacom_features wacom_features_0x97 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003945 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
3946 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003947static const struct wacom_features wacom_features_0x9A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003948 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
3949 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003950static const struct wacom_features wacom_features_0x9F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003951 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
3952 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003953static const struct wacom_features wacom_features_0xE2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003954 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
3955 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003956static const struct wacom_features wacom_features_0xE3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003957 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
3958 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng19635182012-04-29 21:09:18 -07003959static const struct wacom_features wacom_features_0xE5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003960 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
3961 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07003962static const struct wacom_features wacom_features_0xE6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003963 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
3964 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell0d0e3062011-12-11 23:50:59 -08003965static const struct wacom_features wacom_features_0xEC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003966 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
3967 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengac173832012-06-12 00:15:06 -07003968static const struct wacom_features wacom_features_0xED =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003969 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
3970 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengac173832012-06-12 00:15:06 -07003971static const struct wacom_features wacom_features_0xEF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003972 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
3973 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng6afdc282012-11-03 12:16:15 -07003974static const struct wacom_features wacom_features_0x100 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003975 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
3976 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng6afdc282012-11-03 12:16:15 -07003977static const struct wacom_features wacom_features_0x101 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003978 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
3979 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Stephan Frank58694832013-03-07 14:08:50 -08003980static const struct wacom_features wacom_features_0x10D =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003981 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
3982 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke2d3163f2013-10-22 15:35:30 -07003983static const struct wacom_features wacom_features_0x10E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003984 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
3985 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07003986static const struct wacom_features wacom_features_0x10F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003987 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
3988 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke61616ed2014-05-14 11:42:22 -07003989static const struct wacom_features wacom_features_0x116 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003990 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
3991 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07003992static const struct wacom_features wacom_features_0x12C =
3993 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
3994 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengedbe2652012-11-21 13:12:50 -08003995static const struct wacom_features wacom_features_0x4001 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003996 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
3997 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07003998static const struct wacom_features wacom_features_0x4004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003999 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
4000 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004001static const struct wacom_features wacom_features_0x5000 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004002 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
4003 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004004static const struct wacom_features wacom_features_0x5002 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004005 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
4006 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004007static const struct wacom_features wacom_features_0x47 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004008 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4009 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwelld3825d52012-03-25 23:26:11 -07004010static const struct wacom_features wacom_features_0x84 =
Ping Cheng3b164a02015-09-23 09:59:10 -07004011 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004012static const struct wacom_features wacom_features_0xD0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004013 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004014 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004015static const struct wacom_features wacom_features_0xD1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004016 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
4017 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004018static const struct wacom_features wacom_features_0xD2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004019 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
4020 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004021static const struct wacom_features wacom_features_0xD3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004022 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
4023 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Kevin Granade57a78722010-12-10 23:04:02 -08004024static const struct wacom_features wacom_features_0xD4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004025 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004026 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Gerard Braad18adad12011-08-16 00:17:56 -07004027static const struct wacom_features wacom_features_0xD5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004028 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004029 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004030static const struct wacom_features wacom_features_0xD6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004031 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
4032 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004033static const struct wacom_features wacom_features_0xD7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004034 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
4035 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004036static const struct wacom_features wacom_features_0xD8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004037 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
4038 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004039static const struct wacom_features wacom_features_0xDA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004040 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
4041 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Chengf41a64e2013-08-21 09:14:49 -07004042static const struct wacom_features wacom_features_0xDB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004043 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
4044 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004045static const struct wacom_features wacom_features_0xDD =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004046 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
4047 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004048static const struct wacom_features wacom_features_0xDE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004049 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
4050 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004051static const struct wacom_features wacom_features_0xDF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004052 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
4053 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Ping Chengf41a64e2013-08-21 09:14:49 -07004054static const struct wacom_features wacom_features_0x300 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004055 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004056 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengf41a64e2013-08-21 09:14:49 -07004057static const struct wacom_features wacom_features_0x301 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004058 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
4059 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004060static const struct wacom_features wacom_features_0x302 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004061 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
4062 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004063 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004064static const struct wacom_features wacom_features_0x303 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004065 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
4066 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004067 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004068static const struct wacom_features wacom_features_0x30E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004069 { "Wacom Intuos S", 15200, 9500, 1023, 31,
4070 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004071 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004072static const struct wacom_features wacom_features_0x6004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004073 { "ISD-V4", 12800, 8000, 255, 0,
4074 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004075static const struct wacom_features wacom_features_0x307 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004076 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004077 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08004078 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004079 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gerecke36d3c512013-09-20 09:47:35 -07004080 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004081static const struct wacom_features wacom_features_0x309 =
Jason Gerecke36d3c512013-09-20 09:47:35 -07004082 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004083 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
4084 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004085static const struct wacom_features wacom_features_0x30A =
Jason Gereckee779ef22016-10-19 18:03:49 -07004086 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004087 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08004088 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004089 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004090 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
4091static const struct wacom_features wacom_features_0x30C =
4092 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
4093 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
4094 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004095static const struct wacom_features wacom_features_0x318 =
4096 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
4097 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
4098static const struct wacom_features wacom_features_0x319 =
4099 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
4100 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
Jason Gereckef7acb552015-10-13 10:03:49 -07004101static const struct wacom_features wacom_features_0x325 =
4102 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
4103 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
4104 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004105 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckef7acb552015-10-13 10:03:49 -07004106 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
4107static const struct wacom_features wacom_features_0x326 = /* Touch */
4108 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
4109 .oPid = 0x325 };
Ping Chengfefb3912014-11-11 12:52:08 -08004110static const struct wacom_features wacom_features_0x323 =
4111 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
4112 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4113 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Aaron Skomra72b236d2015-08-20 16:05:17 -07004114static const struct wacom_features wacom_features_0x331 =
Ping Cheng3b164a02015-09-23 09:59:10 -07004115 { "Wacom Express Key Remote", .type = REMOTE,
4116 .numbered_buttons = 18, .check_for_hid_type = true,
Aaron Skomra72b236d2015-08-20 16:05:17 -07004117 .hid_type = HID_TYPE_USBNONE };
Ping Chengeda01da2015-09-23 13:51:15 -07004118static const struct wacom_features wacom_features_0x33B =
4119 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
4120 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4121 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4122static const struct wacom_features wacom_features_0x33C =
4123 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
4124 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4125 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4126static const struct wacom_features wacom_features_0x33D =
4127 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
4128 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4129 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4130static const struct wacom_features wacom_features_0x33E =
4131 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
4132 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4133 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chenge1123fe2016-04-12 13:37:45 -07004134static const struct wacom_features wacom_features_0x343 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004135 { "Wacom DTK1651", 34816, 19759, 1023, 0,
Ping Chenge1123fe2016-04-12 13:37:45 -07004136 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004137 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chenge1123fe2016-04-12 13:37:45 -07004138 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Jason Gerecke4922cd22017-01-25 12:08:37 -08004139static const struct wacom_features wacom_features_0x360 =
4140 { "Wacom Intuos Pro M", 44800, 29600, 8191, 63,
4141 INTUOSP2_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 9, .touch_max = 10 };
4142static const struct wacom_features wacom_features_0x361 =
4143 { "Wacom Intuos Pro L", 62200, 43200, 8191, 63,
4144 INTUOSP2_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 9, .touch_max = 10 };
Bastian Blankb036f6f2010-02-10 23:06:23 -08004145
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004146static const struct wacom_features wacom_features_HID_ANY_ID =
Jason Gerecke41372d52016-08-08 12:06:30 -07004147 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004148
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004149#define USB_DEVICE_WACOM(prod) \
4150 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4151 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Bastian Blankb036f6f2010-02-10 23:06:23 -08004152
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004153#define BT_DEVICE_WACOM(prod) \
4154 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4155 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Aristeu Rozanski1483f552011-06-22 01:17:17 -07004156
Mika Westerbergeef23a82015-02-23 15:52:43 +02004157#define I2C_DEVICE_WACOM(prod) \
4158 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4159 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4160
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004161#define USB_DEVICE_LENOVO(prod) \
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004162 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
4163 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004164
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004165const struct hid_device_id wacom_ids[] = {
Bastian Blankb036f6f2010-02-10 23:06:23 -08004166 { USB_DEVICE_WACOM(0x00) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004167 { USB_DEVICE_WACOM(0x03) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004168 { USB_DEVICE_WACOM(0x10) },
4169 { USB_DEVICE_WACOM(0x11) },
4170 { USB_DEVICE_WACOM(0x12) },
4171 { USB_DEVICE_WACOM(0x13) },
4172 { USB_DEVICE_WACOM(0x14) },
4173 { USB_DEVICE_WACOM(0x15) },
4174 { USB_DEVICE_WACOM(0x16) },
4175 { USB_DEVICE_WACOM(0x17) },
4176 { USB_DEVICE_WACOM(0x18) },
4177 { USB_DEVICE_WACOM(0x19) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004178 { USB_DEVICE_WACOM(0x20) },
4179 { USB_DEVICE_WACOM(0x21) },
4180 { USB_DEVICE_WACOM(0x22) },
4181 { USB_DEVICE_WACOM(0x23) },
4182 { USB_DEVICE_WACOM(0x24) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004183 { USB_DEVICE_WACOM(0x26) },
4184 { USB_DEVICE_WACOM(0x27) },
4185 { USB_DEVICE_WACOM(0x28) },
4186 { USB_DEVICE_WACOM(0x29) },
4187 { USB_DEVICE_WACOM(0x2A) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004188 { USB_DEVICE_WACOM(0x30) },
4189 { USB_DEVICE_WACOM(0x31) },
4190 { USB_DEVICE_WACOM(0x32) },
4191 { USB_DEVICE_WACOM(0x33) },
4192 { USB_DEVICE_WACOM(0x34) },
4193 { USB_DEVICE_WACOM(0x35) },
4194 { USB_DEVICE_WACOM(0x37) },
4195 { USB_DEVICE_WACOM(0x38) },
4196 { USB_DEVICE_WACOM(0x39) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004197 { USB_DEVICE_WACOM(0x3F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004198 { USB_DEVICE_WACOM(0x41) },
4199 { USB_DEVICE_WACOM(0x42) },
4200 { USB_DEVICE_WACOM(0x43) },
4201 { USB_DEVICE_WACOM(0x44) },
4202 { USB_DEVICE_WACOM(0x45) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004203 { USB_DEVICE_WACOM(0x47) },
Ping Cheng56218562013-05-05 19:56:18 -07004204 { USB_DEVICE_WACOM(0x57) },
Ping Chenga112e9f2013-02-13 20:20:01 -08004205 { USB_DEVICE_WACOM(0x59) },
Ping Cheng56218562013-05-05 19:56:18 -07004206 { USB_DEVICE_WACOM(0x5B) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004207 { USB_DEVICE_WACOM(0x5D) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004208 { USB_DEVICE_WACOM(0x5E) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004209 { USB_DEVICE_WACOM(0x60) },
4210 { USB_DEVICE_WACOM(0x61) },
4211 { USB_DEVICE_WACOM(0x62) },
4212 { USB_DEVICE_WACOM(0x63) },
4213 { USB_DEVICE_WACOM(0x64) },
4214 { USB_DEVICE_WACOM(0x65) },
4215 { USB_DEVICE_WACOM(0x69) },
4216 { USB_DEVICE_WACOM(0x6A) },
4217 { USB_DEVICE_WACOM(0x6B) },
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004218 { BT_DEVICE_WACOM(0x81) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004219 { USB_DEVICE_WACOM(0x84) },
4220 { USB_DEVICE_WACOM(0x90) },
4221 { USB_DEVICE_WACOM(0x93) },
4222 { USB_DEVICE_WACOM(0x97) },
4223 { USB_DEVICE_WACOM(0x9A) },
4224 { USB_DEVICE_WACOM(0x9F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004225 { USB_DEVICE_WACOM(0xB0) },
4226 { USB_DEVICE_WACOM(0xB1) },
4227 { USB_DEVICE_WACOM(0xB2) },
4228 { USB_DEVICE_WACOM(0xB3) },
4229 { USB_DEVICE_WACOM(0xB4) },
4230 { USB_DEVICE_WACOM(0xB5) },
4231 { USB_DEVICE_WACOM(0xB7) },
4232 { USB_DEVICE_WACOM(0xB8) },
4233 { USB_DEVICE_WACOM(0xB9) },
4234 { USB_DEVICE_WACOM(0xBA) },
4235 { USB_DEVICE_WACOM(0xBB) },
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004236 { USB_DEVICE_WACOM(0xBC) },
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004237 { BT_DEVICE_WACOM(0xBD) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004238 { USB_DEVICE_WACOM(0xC0) },
4239 { USB_DEVICE_WACOM(0xC2) },
4240 { USB_DEVICE_WACOM(0xC4) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004241 { USB_DEVICE_WACOM(0xC5) },
4242 { USB_DEVICE_WACOM(0xC6) },
4243 { USB_DEVICE_WACOM(0xC7) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004244 { USB_DEVICE_WACOM(0xCC) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004245 { USB_DEVICE_WACOM(0xCE) },
Henrik Rydbergcb734c02010-09-05 12:53:16 -07004246 { USB_DEVICE_WACOM(0xD0) },
Chris Bagwell2aaacb12010-09-12 00:11:35 -07004247 { USB_DEVICE_WACOM(0xD1) },
4248 { USB_DEVICE_WACOM(0xD2) },
4249 { USB_DEVICE_WACOM(0xD3) },
Kevin Granade57a78722010-12-10 23:04:02 -08004250 { USB_DEVICE_WACOM(0xD4) },
Gerard Braad18adad12011-08-16 00:17:56 -07004251 { USB_DEVICE_WACOM(0xD5) },
Ping Chengd38acb42011-01-24 09:32:50 -08004252 { USB_DEVICE_WACOM(0xD6) },
4253 { USB_DEVICE_WACOM(0xD7) },
David Foleya318e6b2010-11-30 23:45:46 -08004254 { USB_DEVICE_WACOM(0xD8) },
4255 { USB_DEVICE_WACOM(0xDA) },
David Foley47d09232010-12-07 21:05:59 -08004256 { USB_DEVICE_WACOM(0xDB) },
Chris Bagwell73149ab2011-10-26 22:34:21 -07004257 { USB_DEVICE_WACOM(0xDD) },
4258 { USB_DEVICE_WACOM(0xDE) },
4259 { USB_DEVICE_WACOM(0xDF) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004260 { USB_DEVICE_WACOM(0xE2) },
4261 { USB_DEVICE_WACOM(0xE3) },
Ping Cheng19635182012-04-29 21:09:18 -07004262 { USB_DEVICE_WACOM(0xE5) },
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07004263 { USB_DEVICE_WACOM(0xE6) },
Chris Bagwell0d0e3062011-12-11 23:50:59 -08004264 { USB_DEVICE_WACOM(0xEC) },
Ping Chengac173832012-06-12 00:15:06 -07004265 { USB_DEVICE_WACOM(0xED) },
4266 { USB_DEVICE_WACOM(0xEF) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004267 { USB_DEVICE_WACOM(0xF0) },
4268 { USB_DEVICE_WACOM(0xF4) },
4269 { USB_DEVICE_WACOM(0xF6) },
4270 { USB_DEVICE_WACOM(0xF8) },
4271 { USB_DEVICE_WACOM(0xFA) },
4272 { USB_DEVICE_WACOM(0xFB) },
Ping Cheng6afdc282012-11-03 12:16:15 -07004273 { USB_DEVICE_WACOM(0x100) },
4274 { USB_DEVICE_WACOM(0x101) },
Stephan Frank58694832013-03-07 14:08:50 -08004275 { USB_DEVICE_WACOM(0x10D) },
Jason Gerecke2d3163f2013-10-22 15:35:30 -07004276 { USB_DEVICE_WACOM(0x10E) },
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07004277 { USB_DEVICE_WACOM(0x10F) },
Jason Gerecke61616ed2014-05-14 11:42:22 -07004278 { USB_DEVICE_WACOM(0x116) },
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07004279 { USB_DEVICE_WACOM(0x12C) },
Ping Chengf41a64e2013-08-21 09:14:49 -07004280 { USB_DEVICE_WACOM(0x300) },
4281 { USB_DEVICE_WACOM(0x301) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004282 { USB_DEVICE_WACOM(0x302) },
4283 { USB_DEVICE_WACOM(0x303) },
Ping Cheng56218562013-05-05 19:56:18 -07004284 { USB_DEVICE_WACOM(0x304) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004285 { USB_DEVICE_WACOM(0x307) },
4286 { USB_DEVICE_WACOM(0x309) },
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004287 { USB_DEVICE_WACOM(0x30A) },
4288 { USB_DEVICE_WACOM(0x30C) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004289 { USB_DEVICE_WACOM(0x30E) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004290 { USB_DEVICE_WACOM(0x314) },
4291 { USB_DEVICE_WACOM(0x315) },
4292 { USB_DEVICE_WACOM(0x317) },
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004293 { USB_DEVICE_WACOM(0x318) },
4294 { USB_DEVICE_WACOM(0x319) },
Ping Chengfefb3912014-11-11 12:52:08 -08004295 { USB_DEVICE_WACOM(0x323) },
Jason Gereckef7acb552015-10-13 10:03:49 -07004296 { USB_DEVICE_WACOM(0x325) },
4297 { USB_DEVICE_WACOM(0x326) },
Ping Cheng500d4162015-01-27 13:30:03 -08004298 { USB_DEVICE_WACOM(0x32A) },
4299 { USB_DEVICE_WACOM(0x32B) },
4300 { USB_DEVICE_WACOM(0x32C) },
Ping Chengfff00bf2014-12-04 18:23:04 -08004301 { USB_DEVICE_WACOM(0x32F) },
Aaron Skomra72b236d2015-08-20 16:05:17 -07004302 { USB_DEVICE_WACOM(0x331) },
Ping Chengb4bf2122015-03-25 17:08:13 -07004303 { USB_DEVICE_WACOM(0x333) },
4304 { USB_DEVICE_WACOM(0x335) },
Aaron Skomra007760c2015-04-16 15:01:14 -07004305 { USB_DEVICE_WACOM(0x336) },
Ping Chengeda01da2015-09-23 13:51:15 -07004306 { USB_DEVICE_WACOM(0x33B) },
4307 { USB_DEVICE_WACOM(0x33C) },
4308 { USB_DEVICE_WACOM(0x33D) },
4309 { USB_DEVICE_WACOM(0x33E) },
Ping Chenge1123fe2016-04-12 13:37:45 -07004310 { USB_DEVICE_WACOM(0x343) },
Jason Gerecke4922cd22017-01-25 12:08:37 -08004311 { BT_DEVICE_WACOM(0x360) },
4312 { BT_DEVICE_WACOM(0x361) },
Ping Chengedbe2652012-11-21 13:12:50 -08004313 { USB_DEVICE_WACOM(0x4001) },
Jason Gerecked51ddb22014-05-14 17:14:29 -07004314 { USB_DEVICE_WACOM(0x4004) },
4315 { USB_DEVICE_WACOM(0x5000) },
4316 { USB_DEVICE_WACOM(0x5002) },
Benjamin Tissoires00d6f2272014-12-01 11:52:39 -05004317 { USB_DEVICE_LENOVO(0x6004) },
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004318
4319 { USB_DEVICE_WACOM(HID_ANY_ID) },
Mika Westerbergeef23a82015-02-23 15:52:43 +02004320 { I2C_DEVICE_WACOM(HID_ANY_ID) },
Jason Gereckeb9e06252017-01-25 12:08:35 -08004321 { BT_DEVICE_WACOM(HID_ANY_ID) },
Ping Cheng3bea7332006-07-13 18:01:36 -07004322 { }
4323};
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004324MODULE_DEVICE_TABLE(hid, wacom_ids);