blob: a23b736d05d28916809e3bc46b451680b209697a [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 Gereckeb1e42792012-10-21 00:38:04 -07001193static int wacom_24hdt_irq(struct wacom_wac *wacom)
1194{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001195 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001196 unsigned char *data = wacom->data;
Jason Gereckeb1e42792012-10-21 00:38:04 -07001197 int i;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001198 int current_num_contacts = data[61];
Jason Gereckeb1e42792012-10-21 00:38:04 -07001199 int contacts_to_send = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001200 int num_contacts_left = 4; /* maximum contacts per packet */
1201 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1202 int y_offset = 2;
1203
1204 if (wacom->features.type == WACOM_27QHDT) {
1205 current_num_contacts = data[63];
1206 num_contacts_left = 10;
1207 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1208 y_offset = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001209 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001210
1211 /*
1212 * First packet resets the counter since only the first
1213 * packet in series will have non-zero current_num_contacts.
1214 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001215 if (current_num_contacts)
Jason Gereckeb1e42792012-10-21 00:38:04 -07001216 wacom->num_contacts_left = current_num_contacts;
1217
Ping Cheng500d4162015-01-27 13:30:03 -08001218 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001219
1220 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng500d4162015-01-27 13:30:03 -08001221 int offset = (byte_per_packet * i) + 1;
Ping Cheng1924e052016-08-09 14:38:56 -07001222 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Ping Cheng02295e62013-01-04 23:56:00 -08001223 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001224
1225 if (slot < 0)
1226 continue;
1227 input_mt_slot(input, slot);
1228 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1229
1230 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001231 int t_x = get_unaligned_le16(&data[offset + 2]);
Ping Cheng500d4162015-01-27 13:30:03 -08001232 int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001233
1234 input_report_abs(input, ABS_MT_POSITION_X, t_x);
1235 input_report_abs(input, ABS_MT_POSITION_Y, t_y);
Ping Cheng500d4162015-01-27 13:30:03 -08001236
1237 if (wacom->features.type != WACOM_27QHDT) {
1238 int c_x = get_unaligned_le16(&data[offset + 4]);
1239 int c_y = get_unaligned_le16(&data[offset + 8]);
1240 int w = get_unaligned_le16(&data[offset + 10]);
1241 int h = get_unaligned_le16(&data[offset + 12]);
1242
1243 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1244 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1245 min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1246 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1247 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1248 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001249 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001250 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001251 input_mt_sync_frame(input);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001252
1253 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001254 if (wacom->num_contacts_left <= 0) {
Jason Gereckeb1e42792012-10-21 00:38:04 -07001255 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001256 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001257 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001258 return 1;
1259}
1260
Ping Cheng19635182012-04-29 21:09:18 -07001261static int wacom_mt_touch(struct wacom_wac *wacom)
1262{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001263 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001264 unsigned char *data = wacom->data;
Ping Cheng19635182012-04-29 21:09:18 -07001265 int i;
1266 int current_num_contacts = data[2];
1267 int contacts_to_send = 0;
Ping Cheng6afdc282012-11-03 12:16:15 -07001268 int x_offset = 0;
1269
1270 /* MTTPC does not support Height and Width */
Jason Gerecked51ddb22014-05-14 17:14:29 -07001271 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
Ping Cheng6afdc282012-11-03 12:16:15 -07001272 x_offset = -4;
Ping Cheng19635182012-04-29 21:09:18 -07001273
1274 /*
1275 * First packet resets the counter since only the first
1276 * packet in series will have non-zero current_num_contacts.
1277 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001278 if (current_num_contacts)
Ping Cheng19635182012-04-29 21:09:18 -07001279 wacom->num_contacts_left = current_num_contacts;
1280
1281 /* There are at most 5 contacts per packet */
1282 contacts_to_send = min(5, wacom->num_contacts_left);
1283
1284 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng6afdc282012-11-03 12:16:15 -07001285 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
Ping Cheng1924e052016-08-09 14:38:56 -07001286 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001287 int id = get_unaligned_le16(&data[offset + 1]);
Ping Cheng02295e62013-01-04 23:56:00 -08001288 int slot = input_mt_get_slot_by_key(input, id);
Ping Cheng19635182012-04-29 21:09:18 -07001289
1290 if (slot < 0)
1291 continue;
1292
1293 input_mt_slot(input, slot);
1294 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1295 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001296 int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1297 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
Ping Cheng19635182012-04-29 21:09:18 -07001298 input_report_abs(input, ABS_MT_POSITION_X, x);
1299 input_report_abs(input, ABS_MT_POSITION_Y, y);
1300 }
Ping Cheng19635182012-04-29 21:09:18 -07001301 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001302 input_mt_sync_frame(input);
Ping Cheng19635182012-04-29 21:09:18 -07001303
1304 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001305 if (wacom->num_contacts_left <= 0) {
Ping Cheng19635182012-04-29 21:09:18 -07001306 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001307 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001308 }
Ping Cheng19635182012-04-29 21:09:18 -07001309 return 1;
1310}
1311
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001312static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1313{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001314 struct input_dev *input = wacom->touch_input;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001315 unsigned char *data = wacom->data;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001316 int i;
1317
1318 for (i = 0; i < 2; i++) {
1319 int p = data[1] & (1 << i);
Ping Cheng1924e052016-08-09 14:38:56 -07001320 bool touch = p && report_touch_events(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001321
1322 input_mt_slot(input, i);
1323 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1324 if (touch) {
1325 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1326 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1327
1328 input_report_abs(input, ABS_MT_POSITION_X, x);
1329 input_report_abs(input, ABS_MT_POSITION_Y, y);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001330 }
1331 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001332 input_mt_sync_frame(input);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001333
1334 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001335 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001336
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001337 return 1;
1338}
1339
Ping Chenga43c7c52011-03-12 20:34:42 -08001340static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
Ping Chengec67bbe2009-12-15 00:35:24 -08001341{
Jason Gerecke74b63412014-04-19 13:50:22 -07001342 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001343 struct input_dev *input = wacom->touch_input;
Ping Cheng1924e052016-08-09 14:38:56 -07001344 bool prox = report_touch_events(wacom);
Ping Chenga43c7c52011-03-12 20:34:42 -08001345 int x = 0, y = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -08001346
Ping Cheng19635182012-04-29 21:09:18 -07001347 if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1348 return 0;
1349
Ping Chenge0d41fd2015-02-20 14:27:30 -08001350 if (len == WACOM_PKGLEN_TPC1FG) {
1351 prox = prox && (data[0] & 0x01);
1352 x = get_unaligned_le16(&data[1]);
1353 y = get_unaligned_le16(&data[3]);
1354 } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1355 prox = prox && (data[2] & 0x01);
1356 x = get_unaligned_le16(&data[3]);
1357 y = get_unaligned_le16(&data[5]);
1358 } else {
1359 prox = prox && (data[1] & 0x01);
1360 x = le16_to_cpup((__le16 *)&data[2]);
1361 y = le16_to_cpup((__le16 *)&data[4]);
1362 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001363
1364 if (prox) {
1365 input_report_abs(input, ABS_X, x);
1366 input_report_abs(input, ABS_Y, y);
Ping Chengec67bbe2009-12-15 00:35:24 -08001367 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001368 input_report_key(input, BTN_TOUCH, prox);
1369
1370 /* keep touch state for pen events */
1371 wacom->shared->touch_down = prox;
1372
1373 return 1;
Ping Chengec67bbe2009-12-15 00:35:24 -08001374}
1375
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001376static int wacom_tpc_pen(struct wacom_wac *wacom)
Ping Cheng545f4e92008-11-24 11:44:27 -05001377{
Jason Gerecke74b63412014-04-19 13:50:22 -07001378 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001379 struct input_dev *input = wacom->pen_input;
Ping Chenga43c7c52011-03-12 20:34:42 -08001380 bool prox = data[1] & 0x20;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001381
Ping Chenga43c7c52011-03-12 20:34:42 -08001382 if (!wacom->shared->stylus_in_proximity) /* first in prox */
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001383 /* Going into proximity select tool */
1384 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001385
Ping Chenga43c7c52011-03-12 20:34:42 -08001386 /* keep pen state for touch events */
1387 wacom->shared->stylus_in_proximity = prox;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001388
Ping Cheng1924e052016-08-09 14:38:56 -07001389 /* send pen events only when touch is up or forced out
1390 * or touch arbitration is off
1391 */
1392 if (!delay_pen_events(wacom)) {
Ping Chenga43c7c52011-03-12 20:34:42 -08001393 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1394 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1395 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1396 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke0b335ca2014-07-24 13:15:31 -07001397 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
Ping Chenga43c7c52011-03-12 20:34:42 -08001398 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1399 input_report_key(input, wacom->tool[0], prox);
1400 return 1;
1401 }
1402
1403 return 0;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001404}
1405
1406static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1407{
Jason Gerecke74b63412014-04-19 13:50:22 -07001408 unsigned char *data = wacom->data;
Ping Cheng545f4e92008-11-24 11:44:27 -05001409
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001410 if (wacom->pen_input)
1411 dev_dbg(wacom->pen_input->dev.parent,
1412 "%s: received report #%d\n", __func__, data[0]);
1413 else if (wacom->touch_input)
1414 dev_dbg(wacom->touch_input->dev.parent,
1415 "%s: received report #%d\n", __func__, data[0]);
Ping Cheng545f4e92008-11-24 11:44:27 -05001416
Ping Cheng31175a82012-01-31 00:07:33 -08001417 switch (len) {
1418 case WACOM_PKGLEN_TPC1FG:
Ping Cheng19635182012-04-29 21:09:18 -07001419 return wacom_tpc_single_touch(wacom, len);
Ping Cheng31175a82012-01-31 00:07:33 -08001420
1421 case WACOM_PKGLEN_TPC2FG:
Ping Cheng19635182012-04-29 21:09:18 -07001422 return wacom_tpc_mt_touch(wacom);
Ping Cheng31175a82012-01-31 00:07:33 -08001423
Jason Gerecked51ddb22014-05-14 17:14:29 -07001424 case WACOM_PKGLEN_PENABLED:
1425 return wacom_tpc_pen(wacom);
1426
Ping Cheng31175a82012-01-31 00:07:33 -08001427 default:
1428 switch (data[0]) {
1429 case WACOM_REPORT_TPC1FG:
1430 case WACOM_REPORT_TPCHID:
1431 case WACOM_REPORT_TPCST:
Ping Chengac173832012-06-12 00:15:06 -07001432 case WACOM_REPORT_TPC1FGE:
Ping Cheng31175a82012-01-31 00:07:33 -08001433 return wacom_tpc_single_touch(wacom, len);
1434
Ping Cheng19635182012-04-29 21:09:18 -07001435 case WACOM_REPORT_TPCMT:
Jason Gerecked51ddb22014-05-14 17:14:29 -07001436 case WACOM_REPORT_TPCMT2:
Ping Cheng19635182012-04-29 21:09:18 -07001437 return wacom_mt_touch(wacom);
1438
Ping Cheng31175a82012-01-31 00:07:33 -08001439 case WACOM_REPORT_PENABLED:
1440 return wacom_tpc_pen(wacom);
1441 }
1442 }
Ping Cheng545f4e92008-11-24 11:44:27 -05001443
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001444 return 0;
Ping Cheng545f4e92008-11-24 11:44:27 -05001445}
1446
Jason Gereckec9c09582016-10-19 18:03:43 -07001447static int wacom_equivalent_usage(int usage)
1448{
1449 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1450 int subpage = (usage & 0xFF00) << 8;
1451 int subusage = (usage & 0xFF);
1452
Jason Gerecke5922e612016-10-19 18:03:51 -07001453 if (subpage == WACOM_HID_SP_PAD ||
1454 subpage == WACOM_HID_SP_BUTTON ||
1455 subpage == WACOM_HID_SP_DIGITIZER ||
Jason Gereckeb5c921e2016-10-19 18:03:44 -07001456 subpage == WACOM_HID_SP_DIGITIZERINFO ||
Jason Gerecke61ce3462016-10-19 18:03:46 -07001457 usage == WACOM_HID_WD_SENSE ||
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001458 usage == WACOM_HID_WD_SERIALHI ||
1459 usage == WACOM_HID_WD_TOOLTYPE ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001460 usage == WACOM_HID_WD_DISTANCE ||
Jason Gereckebf78adc2016-10-19 18:03:53 -07001461 usage == WACOM_HID_WD_TOUCHSTRIP ||
1462 usage == WACOM_HID_WD_TOUCHSTRIP2 ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001463 usage == WACOM_HID_WD_TOUCHRING ||
1464 usage == WACOM_HID_WD_TOUCHRINGSTATUS) {
Jason Gereckec9c09582016-10-19 18:03:43 -07001465 return usage;
1466 }
1467
1468 if (subpage == HID_UP_UNDEFINED)
1469 subpage = HID_UP_DIGITIZER;
1470
1471 return subpage | subusage;
1472 }
1473
1474 return usage;
1475}
1476
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001477static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001478 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1479{
Jason Gerecke345857b2016-10-19 18:03:50 -07001480 struct wacom *wacom = input_get_drvdata(input);
1481 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1482 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001483 int fmin = field->logical_minimum;
1484 int fmax = field->logical_maximum;
Jason Gereckec9c09582016-10-19 18:03:43 -07001485 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
Jason Gerecke50066a02016-10-19 18:03:42 -07001486 int resolution_code = code;
1487
Jason Gereckec9c09582016-10-19 18:03:43 -07001488 if (equivalent_usage == HID_DG_TWIST) {
Jason Gerecke50066a02016-10-19 18:03:42 -07001489 resolution_code = ABS_RZ;
1490 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001491
Jason Gerecke345857b2016-10-19 18:03:50 -07001492 if (equivalent_usage == HID_GD_X) {
1493 fmin += features->offset_left;
1494 fmax -= features->offset_right;
1495 }
1496 if (equivalent_usage == HID_GD_Y) {
1497 fmin += features->offset_top;
1498 fmax -= features->offset_bottom;
1499 }
1500
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001501 usage->type = type;
1502 usage->code = code;
1503
1504 set_bit(type, input->evbit);
1505
1506 switch (type) {
1507 case EV_ABS:
1508 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1509 input_abs_set_res(input, code,
Jason Gerecke50066a02016-10-19 18:03:42 -07001510 hidinput_calc_abs_res(field, resolution_code));
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001511 break;
1512 case EV_KEY:
1513 input_set_capability(input, EV_KEY, code);
1514 break;
1515 case EV_MSC:
1516 input_set_capability(input, EV_MSC, code);
1517 break;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001518 case EV_SW:
1519 input_set_capability(input, EV_SW, code);
1520 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001521 }
1522}
1523
Jason Gerecke5922e612016-10-19 18:03:51 -07001524static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1525 struct hid_field *field, struct hid_usage *usage)
1526{
1527 struct wacom *wacom = hid_get_drvdata(hdev);
1528 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1529 struct wacom_features *features = &wacom_wac->features;
1530 struct input_dev *input = wacom_wac->pad_input;
1531 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1532
1533 switch (equivalent_usage) {
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001534 case WACOM_HID_WD_BATTERY_LEVEL:
1535 case WACOM_HID_WD_BATTERY_CHARGING:
1536 features->quirks |= WACOM_QUIRK_BATTERY;
1537 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07001538 case WACOM_HID_WD_ACCELEROMETER_X:
1539 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1540 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001541 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001542 break;
1543 case WACOM_HID_WD_ACCELEROMETER_Y:
1544 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1545 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001546 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001547 break;
1548 case WACOM_HID_WD_ACCELEROMETER_Z:
1549 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1550 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001551 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001552 break;
1553 case WACOM_HID_WD_BUTTONHOME:
1554 case WACOM_HID_WD_BUTTONUP:
1555 case WACOM_HID_WD_BUTTONDOWN:
1556 case WACOM_HID_WD_BUTTONLEFT:
1557 case WACOM_HID_WD_BUTTONRIGHT:
Jason Gereckebf78adc2016-10-19 18:03:53 -07001558 case WACOM_HID_WD_BUTTONCENTER:
Jason Gerecke5922e612016-10-19 18:03:51 -07001559 wacom_map_usage(input, usage, field, EV_KEY,
1560 wacom_numbered_button_to_key(features->numbered_buttons),
1561 0);
1562 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08001563 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001564 break;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001565 case WACOM_HID_WD_TOUCHONOFF:
1566 wacom_map_usage(input, usage, field, EV_SW, SW_MUTE_DEVICE, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001567 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001568 break;
1569 case WACOM_HID_WD_TOUCHSTRIP:
1570 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001571 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001572 break;
1573 case WACOM_HID_WD_TOUCHSTRIP2:
1574 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001575 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07001576 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07001577 case WACOM_HID_WD_TOUCHRING:
1578 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001579 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001580 break;
1581 }
1582
1583 switch (equivalent_usage & 0xfffffff0) {
1584 case WACOM_HID_WD_EXPRESSKEY00:
1585 wacom_map_usage(input, usage, field, EV_KEY,
1586 wacom_numbered_button_to_key(features->numbered_buttons),
1587 0);
1588 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08001589 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001590 break;
1591 }
1592}
1593
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001594static void wacom_wac_pad_battery_event(struct hid_device *hdev, struct hid_field *field,
Jason Gerecke5922e612016-10-19 18:03:51 -07001595 struct hid_usage *usage, __s32 value)
1596{
1597 struct wacom *wacom = hid_get_drvdata(hdev);
1598 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke5922e612016-10-19 18:03:51 -07001599 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1600
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001601 switch (equivalent_usage) {
1602 case WACOM_HID_WD_BATTERY_LEVEL:
1603 wacom_wac->hid_data.battery_capacity = value;
1604 wacom_wac->hid_data.bat_connected = 1;
Ping Cheng354a3292016-12-08 22:03:27 -08001605 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001606
1607 case WACOM_HID_WD_BATTERY_CHARGING:
1608 wacom_wac->hid_data.bat_charging = value;
1609 wacom_wac->hid_data.ps_connected = value;
1610 wacom_wac->hid_data.bat_connected = 1;
Ping Cheng354a3292016-12-08 22:03:27 -08001611 break;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001612 }
1613}
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001614
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001615static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
1616 struct hid_usage *usage, __s32 value)
1617{
1618 struct wacom *wacom = hid_get_drvdata(hdev);
1619 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1620 struct input_dev *input = wacom_wac->pad_input;
1621 struct wacom_features *features = &wacom_wac->features;
1622 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1623
1624 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
1625 wacom_wac->hid_data.inrange_state |= value;
1626 }
1627
1628 switch (equivalent_usage) {
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001629 case WACOM_HID_WD_TOUCHRINGSTATUS:
Ping Cheng354a3292016-12-08 22:03:27 -08001630 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001631
1632 default:
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001633 features->input_event_flag = true;
Jason Gerecke5922e612016-10-19 18:03:51 -07001634 input_event(input, usage->type, usage->code, value);
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001635 break;
1636 }
Jason Gerecke5922e612016-10-19 18:03:51 -07001637}
1638
1639static void wacom_wac_pad_pre_report(struct hid_device *hdev,
1640 struct hid_report *report)
1641{
1642 struct wacom *wacom = hid_get_drvdata(hdev);
1643 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1644
1645 wacom_wac->hid_data.inrange_state = 0;
1646}
1647
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001648static void wacom_wac_pad_battery_report(struct hid_device *hdev,
Jason Gerecke5922e612016-10-19 18:03:51 -07001649 struct hid_report *report)
1650{
1651 struct wacom *wacom = hid_get_drvdata(hdev);
1652 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001653 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke5922e612016-10-19 18:03:51 -07001654
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001655 if (features->quirks & WACOM_QUIRK_BATTERY) {
1656 int capacity = wacom_wac->hid_data.battery_capacity;
1657 bool charging = wacom_wac->hid_data.bat_charging;
1658 bool connected = wacom_wac->hid_data.bat_connected;
1659 bool powered = wacom_wac->hid_data.ps_connected;
1660
1661 wacom_notify_battery(wacom_wac, capacity, charging,
1662 connected, powered);
1663 }
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001664}
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001665
Ping Chengc9cfb2a2016-12-08 22:06:15 -08001666static void wacom_wac_pad_report(struct hid_device *hdev,
1667 struct hid_report *report)
1668{
1669 struct wacom *wacom = hid_get_drvdata(hdev);
1670 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1671 struct wacom_features *features = &wacom_wac->features;
1672 struct input_dev *input = wacom_wac->pad_input;
1673 bool active = wacom_wac->hid_data.inrange_state != 0;
1674
1675 /* report prox for expresskey events */
1676 if (wacom_equivalent_usage(report->field[0]->physical) == HID_DG_TABLETFUNCTIONKEY) {
1677 features->input_event_flag = true;
1678 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
1679 }
1680
1681 if (features->input_event_flag) {
1682 features->input_event_flag = false;
1683 input_sync(input);
1684 }
Jason Gerecke5922e612016-10-19 18:03:51 -07001685}
1686
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001687static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
1688 struct hid_field *field, struct hid_usage *usage)
1689{
1690 struct wacom *wacom = hid_get_drvdata(hdev);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001691 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001692 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001693 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07001694 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001695
Jason Gereckec9c09582016-10-19 18:03:43 -07001696 switch (equivalent_usage) {
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001697 case HID_GD_X:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001698 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001699 break;
1700 case HID_GD_Y:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001701 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001702 break;
Jason Gereckeb5c921e2016-10-19 18:03:44 -07001703 case WACOM_HID_WD_DISTANCE:
Jason Gerecke50066a02016-10-19 18:03:42 -07001704 case HID_GD_Z:
1705 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
1706 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001707 case HID_DG_TIPPRESSURE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001708 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001709 break;
1710 case HID_DG_INRANGE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001711 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001712 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001713 case HID_DG_BATTERYSTRENGTH:
1714 features->quirks |= WACOM_QUIRK_BATTERY;
1715 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001716 case HID_DG_INVERT:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001717 wacom_map_usage(input, usage, field, EV_KEY,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001718 BTN_TOOL_RUBBER, 0);
1719 break;
Jason Gerecke50066a02016-10-19 18:03:42 -07001720 case HID_DG_TILT_X:
1721 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
1722 break;
1723 case HID_DG_TILT_Y:
1724 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
1725 break;
1726 case HID_DG_TWIST:
1727 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
1728 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001729 case HID_DG_ERASER:
1730 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001731 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001732 break;
1733 case HID_DG_BARRELSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001734 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001735 break;
1736 case HID_DG_BARRELSWITCH2:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001737 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001738 break;
1739 case HID_DG_TOOLSERIALNUMBER:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001740 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001741 break;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001742 case WACOM_HID_WD_SENSE:
1743 features->quirks |= WACOM_QUIRK_SENSE;
1744 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
1745 break;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001746 case WACOM_HID_WD_SERIALHI:
1747 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
1748 set_bit(EV_KEY, input->evbit);
1749 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
1750 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
1751 input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
1752 input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
1753 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
1754 input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
1755 input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
1756 break;
Jason Gerecke929d6d52016-10-19 18:03:45 -07001757 case WACOM_HID_WD_FINGERWHEEL:
1758 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
1759 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001760 }
1761}
1762
Ping Cheng354a3292016-12-08 22:03:27 -08001763static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001764 struct hid_usage *usage, __s32 value)
1765{
1766 struct wacom *wacom = hid_get_drvdata(hdev);
1767 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001768 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001769 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07001770 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001771
Jason Gereckec9c09582016-10-19 18:03:43 -07001772 switch (equivalent_usage) {
Jason Gerecke50066a02016-10-19 18:03:42 -07001773 case HID_GD_Z:
1774 /*
1775 * HID_GD_Z "should increase as the control's position is
1776 * moved from high to low", while ABS_DISTANCE instead
1777 * increases in value as the tool moves from low to high.
1778 */
1779 value = field->logical_maximum - value;
1780 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001781 case HID_DG_INRANGE:
1782 wacom_wac->hid_data.inrange_state = value;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001783 if (!(features->quirks & WACOM_QUIRK_SENSE))
1784 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001785 return;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07001786 case HID_DG_BATTERYSTRENGTH:
1787 wacom_wac->hid_data.battery_capacity = value;
1788 wacom_wac->hid_data.bat_connected = 1;
1789 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001790 case HID_DG_INVERT:
1791 wacom_wac->hid_data.invert_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001792 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001793 case HID_DG_ERASER:
1794 case HID_DG_TIPSWITCH:
1795 wacom_wac->hid_data.tipswitch |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08001796 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001797 case HID_DG_TOOLSERIALNUMBER:
Dan Carpentera35f09b2016-11-10 22:25:39 +03001798 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001799 wacom_wac->serial[0] |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08001800 return;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001801 case WACOM_HID_WD_SENSE:
1802 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001803 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001804 case WACOM_HID_WD_SERIALHI:
1805 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
1806 wacom_wac->serial[0] |= ((__u64)value) << 32;
1807 /*
1808 * Non-USI EMR devices may contain additional tool type
1809 * information here. See WACOM_HID_WD_TOOLTYPE case for
1810 * more details.
1811 */
1812 if (value >> 20 == 1) {
1813 wacom_wac->id[0] |= value & 0xFFFFF;
1814 }
Ping Cheng354a3292016-12-08 22:03:27 -08001815 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001816 case WACOM_HID_WD_TOOLTYPE:
1817 /*
1818 * Some devices (MobileStudio Pro, and possibly later
1819 * devices as well) do not return the complete tool
1820 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
1821 * bitwise OR so the complete value can be built
1822 * up over time :(
1823 */
1824 wacom_wac->id[0] |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08001825 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001826 case WACOM_HID_WD_OFFSETLEFT:
1827 if (features->offset_left && value != features->offset_left)
1828 hid_warn(hdev, "%s: overriding exising left offset "
1829 "%d -> %d\n", __func__, value,
1830 features->offset_left);
1831 features->offset_left = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001832 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001833 case WACOM_HID_WD_OFFSETRIGHT:
1834 if (features->offset_right && value != features->offset_right)
1835 hid_warn(hdev, "%s: overriding exising right offset "
1836 "%d -> %d\n", __func__, value,
1837 features->offset_right);
1838 features->offset_right = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001839 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001840 case WACOM_HID_WD_OFFSETTOP:
1841 if (features->offset_top && value != features->offset_top)
1842 hid_warn(hdev, "%s: overriding exising top offset "
1843 "%d -> %d\n", __func__, value,
1844 features->offset_top);
1845 features->offset_top = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001846 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07001847 case WACOM_HID_WD_OFFSETBOTTOM:
1848 if (features->offset_bottom && value != features->offset_bottom)
1849 hid_warn(hdev, "%s: overriding exising bottom offset "
1850 "%d -> %d\n", __func__, value,
1851 features->offset_bottom);
1852 features->offset_bottom = value;
Ping Cheng354a3292016-12-08 22:03:27 -08001853 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001854 }
1855
Ping Cheng1924e052016-08-09 14:38:56 -07001856 /* send pen events only when touch is up or forced out
1857 * or touch arbitration is off
1858 */
1859 if (!usage->type || delay_pen_events(wacom_wac))
Ping Cheng354a3292016-12-08 22:03:27 -08001860 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001861
Jason Gerecke61ce3462016-10-19 18:03:46 -07001862 /* send pen events only when the pen is in/entering/leaving proximity */
1863 if (!wacom_wac->hid_data.inrange_state && !wacom_wac->tool[0])
Ping Cheng354a3292016-12-08 22:03:27 -08001864 return;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001865
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001866 input_event(input, usage->type, usage->code, value);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001867}
1868
Jason Gerecke06324e02015-07-21 11:07:23 -07001869static void wacom_wac_pen_pre_report(struct hid_device *hdev,
1870 struct hid_report *report)
1871{
1872 return;
1873}
1874
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001875static void wacom_wac_pen_report(struct hid_device *hdev,
1876 struct hid_report *report)
1877{
1878 struct wacom *wacom = hid_get_drvdata(hdev);
1879 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001880 struct input_dev *input = wacom_wac->pen_input;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001881 bool prox = wacom_wac->hid_data.inrange_state;
Jason Gerecke61ce3462016-10-19 18:03:46 -07001882 bool range = wacom_wac->hid_data.sense_state;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001883
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001884 if (!wacom_wac->tool[0] && prox) { /* first in prox */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001885 /* Going into proximity select tool */
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001886 if (wacom_wac->hid_data.invert_state)
1887 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
1888 else if (wacom_wac->id[0])
1889 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
1890 else
1891 wacom_wac->tool[0] = BTN_TOOL_PEN;
1892 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001893
1894 /* keep pen state for touch events */
Jason Gerecke61ce3462016-10-19 18:03:46 -07001895 wacom_wac->shared->stylus_in_proximity = range;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001896
Jason Gerecke61ce3462016-10-19 18:03:46 -07001897 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001898 int id = wacom_wac->id[0];
1899
1900 /*
1901 * Non-USI EMR tools should have their IDs mangled to
1902 * match the legacy behavior of wacom_intuos_general
1903 */
1904 if (wacom_wac->serial[0] >> 52 == 1)
1905 id = wacom_intuos_id_mangle(id);
1906
1907 /*
1908 * To ensure compatibility with xf86-input-wacom, we should
1909 * report the BTN_TOOL_* event prior to the ABS_MISC or
1910 * MSC_SERIAL events.
1911 */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001912 input_report_key(input, BTN_TOUCH,
1913 wacom_wac->hid_data.tipswitch);
1914 input_report_key(input, wacom_wac->tool[0], prox);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001915 if (wacom_wac->serial[0]) {
1916 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
1917 input_report_abs(input, ABS_MISC, id);
1918 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001919
1920 wacom_wac->hid_data.tipswitch = false;
1921
1922 input_sync(input);
1923 }
Jason Gerecke61ce3462016-10-19 18:03:46 -07001924
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001925 if (!prox) {
Jason Gerecke61ce3462016-10-19 18:03:46 -07001926 wacom_wac->tool[0] = 0;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001927 wacom_wac->id[0] = 0;
1928 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001929}
1930
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001931static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
1932 struct hid_field *field, struct hid_usage *usage)
1933{
1934 struct wacom *wacom = hid_get_drvdata(hdev);
1935 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001936 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001937 unsigned touch_max = wacom_wac->features.touch_max;
Jason Gereckec9c09582016-10-19 18:03:43 -07001938 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001939
Jason Gereckec9c09582016-10-19 18:03:43 -07001940 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001941 case HID_GD_X:
1942 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001943 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001944 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001945 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001946 ABS_MT_POSITION_X, 4);
1947 break;
1948 case HID_GD_Y:
1949 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001950 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001951 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001952 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001953 ABS_MT_POSITION_Y, 4);
1954 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07001955 case HID_DG_WIDTH:
1956 case HID_DG_HEIGHT:
Jason Gerecke488abb52015-07-21 11:07:25 -07001957 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
1958 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
1959 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
1960 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001961 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001962 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001963 break;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07001964 case HID_DG_CONTACTCOUNT:
Jason Gerecke499522c2015-10-07 16:54:21 -07001965 wacom_wac->hid_data.cc_report = field->report->id;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07001966 wacom_wac->hid_data.cc_index = field->index;
1967 wacom_wac->hid_data.cc_value_index = usage->usage_index;
1968 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001969 }
1970}
1971
Jason Gerecke601a22f2014-12-10 16:26:04 -08001972static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
1973 struct input_dev *input)
1974{
1975 struct hid_data *hid_data = &wacom_wac->hid_data;
1976 bool mt = wacom_wac->features.touch_max > 1;
1977 bool prox = hid_data->tipswitch &&
Ping Cheng1924e052016-08-09 14:38:56 -07001978 report_touch_events(wacom_wac);
Jason Gerecke601a22f2014-12-10 16:26:04 -08001979
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07001980 wacom_wac->hid_data.num_received++;
1981 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
1982 return;
1983
Jason Gerecke601a22f2014-12-10 16:26:04 -08001984 if (mt) {
1985 int slot;
1986
1987 slot = input_mt_get_slot_by_key(input, hid_data->id);
1988 input_mt_slot(input, slot);
1989 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
1990 }
1991 else {
1992 input_report_key(input, BTN_TOUCH, prox);
1993 }
1994
1995 if (prox) {
1996 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
1997 hid_data->x);
1998 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
1999 hid_data->y);
Jason Gerecke488abb52015-07-21 11:07:25 -07002000
2001 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
2002 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
2003 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
2004 if (hid_data->width != hid_data->height)
2005 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
2006 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002007 }
2008}
2009
Ping Cheng354a3292016-12-08 22:03:27 -08002010static void wacom_wac_finger_event(struct hid_device *hdev,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002011 struct hid_field *field, struct hid_usage *usage, __s32 value)
2012{
2013 struct wacom *wacom = hid_get_drvdata(hdev);
2014 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckec9c09582016-10-19 18:03:43 -07002015 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002016
Jason Gereckec9c09582016-10-19 18:03:43 -07002017 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002018 case HID_GD_X:
2019 wacom_wac->hid_data.x = value;
2020 break;
2021 case HID_GD_Y:
2022 wacom_wac->hid_data.y = value;
2023 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002024 case HID_DG_WIDTH:
2025 wacom_wac->hid_data.width = value;
2026 break;
2027 case HID_DG_HEIGHT:
2028 wacom_wac->hid_data.height = value;
2029 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002030 case HID_DG_CONTACTID:
2031 wacom_wac->hid_data.id = value;
2032 break;
2033 case HID_DG_TIPSWITCH:
2034 wacom_wac->hid_data.tipswitch = value;
2035 break;
2036 }
2037
2038
Jason Gerecke601a22f2014-12-10 16:26:04 -08002039 if (usage->usage_index + 1 == field->report_count) {
Jason Gereckec9c09582016-10-19 18:03:43 -07002040 if (equivalent_usage == wacom_wac->hid_data.last_slot_field)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002041 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
Jason Gerecke601a22f2014-12-10 16:26:04 -08002042 }
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002043}
2044
Jason Gerecke06324e02015-07-21 11:07:23 -07002045static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2046 struct hid_report *report)
2047{
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002048 struct wacom *wacom = hid_get_drvdata(hdev);
2049 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2050 struct hid_data* hid_data = &wacom_wac->hid_data;
Jason Gerecke003f50a2016-07-21 09:10:46 -07002051 int i;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002052
Jason Gerecke003f50a2016-07-21 09:10:46 -07002053 for (i = 0; i < report->maxfield; i++) {
2054 struct hid_field *field = report->field[i];
2055 int j;
Jason Gerecke499522c2015-10-07 16:54:21 -07002056
Jason Gerecke003f50a2016-07-21 09:10:46 -07002057 for (j = 0; j < field->maxusage; j++) {
2058 struct hid_usage *usage = &field->usage[j];
Jason Gerecke499522c2015-10-07 16:54:21 -07002059
Jason Gerecke003f50a2016-07-21 09:10:46 -07002060 switch (usage->hid) {
2061 case HID_GD_X:
2062 case HID_GD_Y:
2063 case HID_DG_WIDTH:
2064 case HID_DG_HEIGHT:
2065 case HID_DG_CONTACTID:
2066 case HID_DG_INRANGE:
2067 case HID_DG_INVERT:
2068 case HID_DG_TIPSWITCH:
2069 hid_data->last_slot_field = usage->hid;
2070 break;
2071 case HID_DG_CONTACTCOUNT:
2072 hid_data->cc_report = report->id;
2073 hid_data->cc_index = i;
2074 hid_data->cc_value_index = j;
2075 break;
Jason Gerecke499522c2015-10-07 16:54:21 -07002076 }
2077 }
2078 }
Jason Gerecke003f50a2016-07-21 09:10:46 -07002079
Jason Gereckedf707932015-10-07 16:54:22 -07002080 if (hid_data->cc_report != 0 &&
2081 hid_data->cc_index >= 0) {
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002082 struct hid_field *field = report->field[hid_data->cc_index];
2083 int value = field->value[hid_data->cc_value_index];
2084 if (value)
2085 hid_data->num_expected = value;
2086 }
2087 else {
2088 hid_data->num_expected = wacom_wac->features.touch_max;
2089 }
Jason Gerecke06324e02015-07-21 11:07:23 -07002090}
2091
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002092static void wacom_wac_finger_report(struct hid_device *hdev,
2093 struct hid_report *report)
2094{
2095 struct wacom *wacom = hid_get_drvdata(hdev);
2096 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002097 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002098 unsigned touch_max = wacom_wac->features.touch_max;
2099
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002100 /* If more packets of data are expected, give us a chance to
2101 * process them rather than immediately syncing a partial
2102 * update.
2103 */
2104 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2105 return;
2106
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002107 if (touch_max > 1)
Jason Gerecke601a22f2014-12-10 16:26:04 -08002108 input_mt_sync_frame(input);
2109
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002110 input_sync(input);
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002111 wacom_wac->hid_data.num_received = 0;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002112
2113 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07002114 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002115}
2116
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002117void wacom_wac_usage_mapping(struct hid_device *hdev,
2118 struct hid_field *field, struct hid_usage *usage)
2119{
2120 struct wacom *wacom = hid_get_drvdata(hdev);
2121 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002122 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002123
2124 /* currently, only direct devices have proper hid report descriptors */
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002125 features->device_type |= WACOM_DEVICETYPE_DIRECT;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002126
Jason Gerecke5922e612016-10-19 18:03:51 -07002127 if (WACOM_PAD_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002128 wacom_wac_pad_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002129 else if (WACOM_PEN_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002130 wacom_wac_pen_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002131 else if (WACOM_FINGER_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002132 wacom_wac_finger_usage_mapping(hdev, field, usage);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002133}
2134
Ping Cheng354a3292016-12-08 22:03:27 -08002135void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002136 struct hid_usage *usage, __s32 value)
2137{
2138 struct wacom *wacom = hid_get_drvdata(hdev);
2139
2140 if (wacom->wacom_wac.features.type != HID_GENERIC)
Ping Cheng354a3292016-12-08 22:03:27 -08002141 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002142
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002143 if (WACOM_PAD_FIELD(field)) {
2144 wacom_wac_pad_battery_event(hdev, field, usage, value);
2145 if (wacom->wacom_wac.pad_input)
2146 wacom_wac_pad_event(hdev, field, usage, value);
2147 } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002148 wacom_wac_pen_event(hdev, field, usage, value);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002149 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002150 wacom_wac_finger_event(hdev, field, usage, value);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002151}
2152
Jason Gerecke06324e02015-07-21 11:07:23 -07002153static void wacom_report_events(struct hid_device *hdev, struct hid_report *report)
2154{
2155 int r;
2156
2157 for (r = 0; r < report->maxfield; r++) {
2158 struct hid_field *field;
2159 unsigned count, n;
2160
2161 field = report->field[r];
2162 count = field->report_count;
2163
2164 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2165 continue;
2166
2167 for (n = 0; n < count; n++)
2168 wacom_wac_event(hdev, field, &field->usage[n], field->value[n]);
2169 }
2170}
2171
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002172void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2173{
2174 struct wacom *wacom = hid_get_drvdata(hdev);
2175 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2176 struct hid_field *field = report->field[0];
2177
2178 if (wacom_wac->features.type != HID_GENERIC)
2179 return;
2180
Ping Cheng6f46cf92016-12-08 22:04:52 -08002181 if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
Jason Gerecke5922e612016-10-19 18:03:51 -07002182 wacom_wac_pad_pre_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002183 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Jason Gerecke06324e02015-07-21 11:07:23 -07002184 wacom_wac_pen_pre_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002185 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Jason Gerecke06324e02015-07-21 11:07:23 -07002186 wacom_wac_finger_pre_report(hdev, report);
2187
2188 wacom_report_events(hdev, report);
2189
Jason Gereckea9ce7852017-01-17 15:38:58 -08002190 /*
2191 * Non-input reports may be sent prior to the device being
2192 * completely initialized. Since only their events need
2193 * to be processed, exit after 'wacom_report_events' has
2194 * been called to prevent potential crashes in the report-
2195 * processing functions.
2196 */
2197 if (report->type != HID_INPUT_REPORT)
2198 return;
2199
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002200 if (WACOM_PAD_FIELD(field)) {
2201 wacom_wac_pad_battery_report(hdev, report);
2202 if (wacom->wacom_wac.pad_input)
2203 wacom_wac_pad_report(hdev, report);
2204 } else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
2205 wacom_wac_pen_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002206 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002207 wacom_wac_finger_report(hdev, report);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002208}
2209
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002210static int wacom_bpt_touch(struct wacom_wac *wacom)
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002211{
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002212 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002213 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires31168712014-07-24 12:50:10 -07002214 struct input_dev *pad_input = wacom->pad_input;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002215 unsigned char *data = wacom->data;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002216 int i;
2217
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002218 if (data[0] != 0x02)
2219 return 0;
2220
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002221 for (i = 0; i < 2; i++) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002222 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
Ping Cheng1924e052016-08-09 14:38:56 -07002223 bool touch = report_touch_events(wacom)
2224 && (data[offset + 3] & 0x80);
Chris Bagwell8f906862011-09-09 13:38:10 -07002225
2226 input_mt_slot(input, i);
2227 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +01002228 if (touch) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002229 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2230 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002231 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2232 x <<= 5;
2233 y <<= 5;
2234 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002235 input_report_abs(input, ABS_MT_POSITION_X, x);
2236 input_report_abs(input, ABS_MT_POSITION_Y, y);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002237 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002238 }
2239
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05002240 input_mt_sync_frame(input);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002241
Benjamin Tissoires31168712014-07-24 12:50:10 -07002242 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2243 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2244 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2245 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
Ping Cheng7d059ed2015-03-20 14:57:21 -07002246 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002247
Benjamin Tissoires31168712014-07-24 12:50:10 -07002248 return 1;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002249}
2250
Ping Cheng7d059ed2015-03-20 14:57:21 -07002251static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002252{
Ping Cheng9a35c412013-09-20 09:51:56 -07002253 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002254 struct input_dev *input = wacom->touch_input;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002255 bool touch = data[1] & 0x80;
Ping Cheng02295e62013-01-04 23:56:00 -08002256 int slot = input_mt_get_slot_by_key(input, data[0]);
2257
2258 if (slot < 0)
Ping Cheng7d059ed2015-03-20 14:57:21 -07002259 return;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002260
Ping Cheng1924e052016-08-09 14:38:56 -07002261 touch = touch && report_touch_events(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002262
Ping Cheng02295e62013-01-04 23:56:00 -08002263 input_mt_slot(input, slot);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002264 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2265
2266 if (touch) {
2267 int x = (data[2] << 4) | (data[4] >> 4);
2268 int y = (data[3] << 4) | (data[4] & 0x0f);
Ping Cheng9a35c412013-09-20 09:51:56 -07002269 int width, height;
Jason Gerecke4e904952012-10-03 17:19:11 -07002270
Ping Chengeda01da2015-09-23 13:51:15 -07002271 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
Jason Gerecke0b279da2013-11-25 18:43:16 -08002272 width = data[5] * 100;
2273 height = data[6] * 100;
Ping Cheng9a35c412013-09-20 09:51:56 -07002274 } else {
2275 /*
2276 * "a" is a scaled-down area which we assume is
2277 * roughly circular and which can be described as:
2278 * a=(pi*r^2)/C.
2279 */
2280 int a = data[5];
Ping Chengd7da3a32014-06-13 13:37:33 -07002281 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2282 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2283 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
Ping Cheng9a35c412013-09-20 09:51:56 -07002284 height = width * y_res / x_res;
2285 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002286
2287 input_report_abs(input, ABS_MT_POSITION_X, x);
2288 input_report_abs(input, ABS_MT_POSITION_Y, y);
Jason Gerecke4e904952012-10-03 17:19:11 -07002289 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2290 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002291 }
2292}
2293
2294static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2295{
Benjamin Tissoires31168712014-07-24 12:50:10 -07002296 struct input_dev *input = wacom->pad_input;
Ping Chengb5fd2a32013-11-25 18:44:55 -08002297 struct wacom_features *features = &wacom->features;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002298
Ping Chengeda01da2015-09-23 13:51:15 -07002299 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
Ping Chengb5fd2a32013-11-25 18:44:55 -08002300 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
2301 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
2302 } else {
2303 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
2304 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
2305 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002306 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002307 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
2308}
2309
2310static int wacom_bpt3_touch(struct wacom_wac *wacom)
2311{
Chris Bagwell73149ab2011-10-26 22:34:21 -07002312 unsigned char *data = wacom->data;
Jason Gerecke19d57d32012-03-06 10:19:19 -08002313 int count = data[1] & 0x07;
Ping Chengeda01da2015-09-23 13:51:15 -07002314 int touch_changed = 0, i;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002315
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002316 if (data[0] != 0x02)
2317 return 0;
2318
Chris Bagwell73149ab2011-10-26 22:34:21 -07002319 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
2320 for (i = 0; i < count; i++) {
2321 int offset = (8 * i) + 2;
2322 int msg_id = data[offset];
2323
Ping Chengeda01da2015-09-23 13:51:15 -07002324 if (msg_id >= 2 && msg_id <= 17) {
Ping Cheng7d059ed2015-03-20 14:57:21 -07002325 wacom_bpt3_touch_msg(wacom, data + offset);
Ping Chengeda01da2015-09-23 13:51:15 -07002326 touch_changed++;
2327 } else if (msg_id == 128)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002328 wacom_bpt3_button_msg(wacom, data + offset);
2329
2330 }
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002331
Ping Chengeda01da2015-09-23 13:51:15 -07002332 /* only update touch if we actually have a touchpad and touch data changed */
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02002333 if (wacom->touch_input && touch_changed) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002334 input_mt_sync_frame(wacom->touch_input);
2335 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
2336 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002337
Benjamin Tissoires31168712014-07-24 12:50:10 -07002338 return 1;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002339}
2340
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002341static int wacom_bpt_pen(struct wacom_wac *wacom)
2342{
Ping Cheng961794a2013-12-05 12:54:53 -08002343 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002344 struct input_dev *input = wacom->pen_input;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002345 unsigned char *data = wacom->data;
2346 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
2347
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002348 if (data[0] != WACOM_REPORT_PENABLED)
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002349 return 0;
2350
Chris Bagwellc5981412011-10-26 22:28:34 -07002351 prox = (data[1] & 0x20) == 0x20;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002352
2353 /*
2354 * All reports shared between PEN and RUBBER tool must be
2355 * forced to a known starting value (zero) when transitioning to
2356 * out-of-prox.
2357 *
2358 * If not reset then, to userspace, it will look like lost events
2359 * if new tool comes in-prox with same values as previous tool sent.
2360 *
2361 * Hardware does report zero in most out-of-prox cases but not all.
2362 */
Ping Cheng01499312015-03-20 14:58:01 -07002363 if (!wacom->shared->stylus_in_proximity) {
2364 if (data[1] & 0x08) {
2365 wacom->tool[0] = BTN_TOOL_RUBBER;
2366 wacom->id[0] = ERASER_DEVICE_ID;
2367 } else {
2368 wacom->tool[0] = BTN_TOOL_PEN;
2369 wacom->id[0] = STYLUS_DEVICE_ID;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002370 }
Ping Cheng01499312015-03-20 14:58:01 -07002371 }
2372
2373 wacom->shared->stylus_in_proximity = prox;
Ping Cheng1924e052016-08-09 14:38:56 -07002374 if (delay_pen_events(wacom))
Ping Cheng01499312015-03-20 14:58:01 -07002375 return 0;
2376
2377 if (prox) {
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002378 x = le16_to_cpup((__le16 *)&data[2]);
2379 y = le16_to_cpup((__le16 *)&data[4]);
2380 p = le16_to_cpup((__le16 *)&data[6]);
Chris Bagwellc18c2ce2011-10-10 08:52:13 -07002381 /*
2382 * Convert distance from out prox to distance from tablet.
2383 * distance will be greater than distance_max once
2384 * touching and applying pressure; do not report negative
2385 * distance.
2386 */
Ping Cheng961794a2013-12-05 12:54:53 -08002387 if (data[8] <= features->distance_max)
2388 d = features->distance_max - data[8];
Chris Bagwellc18c2ce2011-10-10 08:52:13 -07002389
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002390 pen = data[1] & 0x01;
2391 btn1 = data[1] & 0x02;
2392 btn2 = data[1] & 0x04;
Ping Cheng01499312015-03-20 14:58:01 -07002393 } else {
2394 wacom->id[0] = 0;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002395 }
2396
2397 input_report_key(input, BTN_TOUCH, pen);
2398 input_report_key(input, BTN_STYLUS, btn1);
2399 input_report_key(input, BTN_STYLUS2, btn2);
2400
2401 input_report_abs(input, ABS_X, x);
2402 input_report_abs(input, ABS_Y, y);
2403 input_report_abs(input, ABS_PRESSURE, p);
2404 input_report_abs(input, ABS_DISTANCE, d);
2405
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002406 input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
2407 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
2408
2409 return 1;
2410}
2411
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002412static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
2413{
Ping Chengeda01da2015-09-23 13:51:15 -07002414 struct wacom_features *features = &wacom->features;
2415
2416 if ((features->type == INTUOSHT2) &&
Ping Chengeda01da2015-09-23 13:51:15 -07002417 (features->device_type & WACOM_DEVICETYPE_PEN))
2418 return wacom_intuos_irq(wacom);
2419 else if (len == WACOM_PKGLEN_BBTOUCH)
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002420 return wacom_bpt_touch(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002421 else if (len == WACOM_PKGLEN_BBTOUCH3)
2422 return wacom_bpt3_touch(wacom);
2423 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
Chris Bagwell2aaacb12010-09-12 00:11:35 -07002424 return wacom_bpt_pen(wacom);
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002425
2426 return 0;
2427}
2428
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002429static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
2430 unsigned char *data)
2431{
2432 unsigned char prefix;
2433
2434 /*
2435 * We need to reroute the event from the debug interface to the
2436 * pen interface.
2437 * We need to add the report ID to the actual pen report, so we
2438 * temporary overwrite the first byte to prevent having to kzalloc/kfree
2439 * and memcpy the report.
2440 */
2441 prefix = data[0];
2442 data[0] = WACOM_REPORT_BPAD_PEN;
2443
2444 /*
2445 * actually reroute the event.
2446 * No need to check if wacom->shared->pen is valid, hid_input_report()
2447 * will check for us.
2448 */
2449 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
2450 WACOM_PKGLEN_PENABLED, 1);
2451
2452 data[0] = prefix;
2453}
2454
2455static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
2456 unsigned char *data)
2457{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002458 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002459 unsigned char *finger_data, prefix;
2460 unsigned id;
2461 int x, y;
2462 bool valid;
2463
2464 prefix = data[0];
2465
2466 for (id = 0; id < wacom->features.touch_max; id++) {
2467 valid = !!(prefix & BIT(id)) &&
Ping Cheng1924e052016-08-09 14:38:56 -07002468 report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002469
2470 input_mt_slot(input, id);
2471 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
2472
2473 if (!valid)
2474 continue;
2475
2476 finger_data = data + 1 + id * 3;
2477 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
2478 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
2479
2480 input_report_abs(input, ABS_MT_POSITION_X, x);
2481 input_report_abs(input, ABS_MT_POSITION_Y, y);
2482 }
2483
2484 input_mt_sync_frame(input);
2485
2486 input_report_key(input, BTN_LEFT, prefix & 0x40);
2487 input_report_key(input, BTN_RIGHT, prefix & 0x80);
2488
2489 /* keep touch state for pen event */
Ping Cheng1924e052016-08-09 14:38:56 -07002490 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002491
2492 return 1;
2493}
2494
2495static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
2496{
2497 unsigned char *data = wacom->data;
2498
2499 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
2500 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
2501 (data[0] != WACOM_REPORT_BPAD_TOUCH))
2502 return 0;
2503
2504 if (data[1] & 0x01)
2505 wacom_bamboo_pad_pen_event(wacom, &data[1]);
2506
2507 if (data[1] & 0x02)
2508 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
2509
2510 return 0;
2511}
2512
Chris Bagwelld3825d52012-03-25 23:26:11 -07002513static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
2514{
Chris Bagwell16bf2882012-03-25 23:26:20 -07002515 unsigned char *data = wacom->data;
2516 int connected;
2517
Ping Chengb5fd2a32013-11-25 18:44:55 -08002518 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
Chris Bagwelld3825d52012-03-25 23:26:11 -07002519 return 0;
2520
Chris Bagwell16bf2882012-03-25 23:26:20 -07002521 connected = data[1] & 0x01;
2522 if (connected) {
Jason Gereckeb0882cb2015-03-06 11:47:43 -08002523 int pid, battery, charging;
Chris Bagwell16bf2882012-03-25 23:26:20 -07002524
Ping Chengeda01da2015-09-23 13:51:15 -07002525 if ((wacom->shared->type == INTUOSHT ||
2526 wacom->shared->type == INTUOSHT2) &&
Ping Cheng44b96832014-11-06 17:30:51 -08002527 wacom->shared->touch_input &&
2528 wacom->shared->touch_max) {
Ping Cheng961794a2013-12-05 12:54:53 -08002529 input_report_switch(wacom->shared->touch_input,
2530 SW_MUTE_DEVICE, data[5] & 0x40);
2531 input_sync(wacom->shared->touch_input);
2532 }
2533
Chris Bagwell16bf2882012-03-25 23:26:20 -07002534 pid = get_unaligned_be16(&data[6]);
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07002535 battery = (data[5] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08002536 charging = !!(data[5] & 0x80);
Chris Bagwell16bf2882012-03-25 23:26:20 -07002537 if (wacom->pid != pid) {
2538 wacom->pid = pid;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002539 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Chris Bagwell16bf2882012-03-25 23:26:20 -07002540 }
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07002541
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02002542 wacom_notify_battery(wacom, battery, charging, 1, 0);
Jason Gerecke953f2c52015-03-06 11:47:39 -08002543
Chris Bagwell16bf2882012-03-25 23:26:20 -07002544 } else if (wacom->pid != 0) {
2545 /* disconnected while previously connected */
2546 wacom->pid = 0;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002547 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Jason Gerecke71fa6412015-03-11 10:25:41 -07002548 wacom_notify_battery(wacom, 0, 0, 0, 0);
Chris Bagwell16bf2882012-03-25 23:26:20 -07002549 }
2550
Chris Bagwelld3825d52012-03-25 23:26:11 -07002551 return 0;
2552}
2553
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002554static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
2555{
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002556 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002557 struct wacom_features *features = &wacom_wac->features;
2558 unsigned char *data = wacom_wac->data;
2559
2560 if (data[0] != WACOM_REPORT_USB)
2561 return 0;
2562
Ping Chengeda01da2015-09-23 13:51:15 -07002563 if ((features->type == INTUOSHT ||
2564 features->type == INTUOSHT2) &&
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002565 wacom_wac->shared->touch_input &&
2566 features->touch_max) {
2567 input_report_switch(wacom_wac->shared->touch_input,
2568 SW_MUTE_DEVICE, data[8] & 0x40);
2569 input_sync(wacom_wac->shared->touch_input);
2570 }
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002571
2572 if (data[9] & 0x02) { /* wireless module is attached */
2573 int battery = (data[8] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08002574 bool charging = !!(data[8] & 0x80);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002575
2576 wacom_notify_battery(wacom_wac, battery, charging,
Jason Gerecke71fa6412015-03-11 10:25:41 -07002577 battery || charging, 1);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002578
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02002579 if (!wacom->battery.battery &&
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002580 !(features->quirks & WACOM_QUIRK_BATTERY)) {
2581 features->quirks |= WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002582 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002583 }
2584 }
2585 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02002586 wacom->battery.battery) {
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002587 features->quirks &= ~WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02002588 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke71fa6412015-03-11 10:25:41 -07002589 wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08002590 }
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002591 return 0;
2592}
2593
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002594void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
Ping Cheng3bea7332006-07-13 18:01:36 -07002595{
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002596 bool sync;
2597
Jason Childse33da8a2010-02-17 22:38:31 -08002598 switch (wacom_wac->features.type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002599 case PENPARTNER:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002600 sync = wacom_penpartner_irq(wacom_wac);
2601 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002602
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002603 case PL:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002604 sync = wacom_pl_irq(wacom_wac);
2605 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002606
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002607 case WACOM_G4:
2608 case GRAPHIRE:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07002609 case GRAPHIRE_BT:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002610 case WACOM_MO:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002611 sync = wacom_graphire_irq(wacom_wac);
2612 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002613
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002614 case PTU:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002615 sync = wacom_ptu_irq(wacom_wac);
2616 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002617
Ping Chengc8f2edc2010-06-28 01:10:51 -07002618 case DTU:
2619 sync = wacom_dtu_irq(wacom_wac);
2620 break;
2621
Ping Cheng497ab1f2014-01-20 20:18:04 -08002622 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08002623 case DTUSX:
Ping Cheng497ab1f2014-01-20 20:18:04 -08002624 sync = wacom_dtus_irq(wacom_wac);
2625 break;
2626
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002627 case INTUOS:
2628 case INTUOS3S:
2629 case INTUOS3:
2630 case INTUOS3L:
2631 case INTUOS4S:
2632 case INTUOS4:
2633 case INTUOS4L:
2634 case CINTIQ:
2635 case WACOM_BEE:
Ping Cheng56218562013-05-05 19:56:18 -07002636 case WACOM_13HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07002637 case WACOM_21UX2:
Ping Chengd838c642012-07-24 23:54:11 -07002638 case WACOM_22HD:
Jason Gerecke803296b2011-12-12 00:11:45 -08002639 case WACOM_24HD:
Ping Cheng500d4162015-01-27 13:30:03 -08002640 case WACOM_27QHD:
Ping Chenga112e9f2013-02-13 20:20:01 -08002641 case DTK:
Jason Gerecke36d3c512013-09-20 09:47:35 -07002642 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07002643 case CINTIQ_COMPANION_2:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002644 sync = wacom_intuos_irq(wacom_wac);
2645 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002646
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07002647 case INTUOS4WL:
2648 sync = wacom_intuos_bt_irq(wacom_wac, len);
2649 break;
2650
Jason Gereckeb1e42792012-10-21 00:38:04 -07002651 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08002652 case WACOM_27QHDT:
Jason Gereckeb1e42792012-10-21 00:38:04 -07002653 sync = wacom_24hdt_irq(wacom_wac);
2654 break;
2655
Jason Gereckeae584ca2012-04-03 15:50:40 -07002656 case INTUOS5S:
2657 case INTUOS5:
2658 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07002659 case INTUOSPS:
2660 case INTUOSPM:
2661 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07002662 if (len == WACOM_PKGLEN_BBTOUCH3)
2663 sync = wacom_bpt3_touch(wacom_wac);
Jason Gerecke2d13a432015-03-06 11:47:42 -08002664 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
2665 sync = wacom_status_irq(wacom_wac, len);
Jason Gereckeae584ca2012-04-03 15:50:40 -07002666 else
2667 sync = wacom_intuos_irq(wacom_wac);
2668 break;
2669
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002670 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07002671 case TABLETPCE:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002672 case TABLETPC2FG:
Ping Cheng19635182012-04-29 21:09:18 -07002673 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07002674 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07002675 case MTTPC_B:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002676 sync = wacom_tpc_irq(wacom_wac, len);
2677 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05002678
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002679 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07002680 case BAMBOO_PEN:
2681 case BAMBOO_TOUCH:
Ping Chengb5fd2a32013-11-25 18:44:55 -08002682 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07002683 case INTUOSHT2:
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08002684 if (wacom_wac->data[0] == WACOM_REPORT_USB)
2685 sync = wacom_status_irq(wacom_wac, len);
2686 else
2687 sync = wacom_bpt_irq(wacom_wac, len);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002688 break;
2689
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05002690 case BAMBOO_PAD:
2691 sync = wacom_bamboo_pad_irq(wacom_wac, len);
Ping Cheng3bea7332006-07-13 18:01:36 -07002692 break;
2693
Chris Bagwelld3825d52012-03-25 23:26:11 -07002694 case WIRELESS:
2695 sync = wacom_wireless_irq(wacom_wac, len);
2696 break;
2697
Aaron Skomra72b236d2015-08-20 16:05:17 -07002698 case REMOTE:
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002699 sync = false;
Aaron Skomra72b236d2015-08-20 16:05:17 -07002700 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02002701 wacom_remote_status_irq(wacom_wac, len);
Aaron Skomra72b236d2015-08-20 16:05:17 -07002702 else
2703 sync = wacom_remote_irq(wacom_wac, len);
2704 break;
2705
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002706 default:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002707 sync = false;
2708 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07002709 }
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07002710
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07002711 if (sync) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002712 if (wacom_wac->pen_input)
2713 input_sync(wacom_wac->pen_input);
2714 if (wacom_wac->touch_input)
2715 input_sync(wacom_wac->touch_input);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07002716 if (wacom_wac->pad_input)
2717 input_sync(wacom_wac->pad_input);
2718 }
Ping Cheng3bea7332006-07-13 18:01:36 -07002719}
2720
Ping Chengeda01da2015-09-23 13:51:15 -07002721static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
Ping Cheng3bea7332006-07-13 18:01:36 -07002722{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002723 struct input_dev *input_dev = wacom_wac->pen_input;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002724
2725 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002726
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002727 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002728 __set_bit(BTN_STYLUS, input_dev->keybit);
2729 __set_bit(BTN_STYLUS2, input_dev->keybit);
2730
2731 input_set_abs_params(input_dev, ABS_DISTANCE,
Jason Gereckebef7e202016-04-22 14:30:53 -07002732 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07002733}
2734
2735static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
2736{
2737 struct input_dev *input_dev = wacom_wac->pen_input;
Jason Gereckebef7e202016-04-22 14:30:53 -07002738 struct wacom_features *features = &wacom_wac->features;
Ping Chengeda01da2015-09-23 13:51:15 -07002739
2740 wacom_setup_basic_pro_pen(wacom_wac);
2741
2742 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2743 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
2744 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
2745 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
2746
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002747 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
Jason Gereckebef7e202016-04-22 14:30:53 -07002748 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002749 input_abs_set_res(input_dev, ABS_TILT_X, 57);
Jason Gereckebef7e202016-04-22 14:30:53 -07002750 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002751 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
Ping Cheng6521d0b2010-10-24 21:53:40 -07002752}
2753
2754static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
2755{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002756 struct input_dev *input_dev = wacom_wac->pen_input;
Ping Cheng6521d0b2010-10-24 21:53:40 -07002757
2758 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2759
2760 wacom_setup_cintiq(wacom_wac);
2761
2762 __set_bit(BTN_LEFT, input_dev->keybit);
2763 __set_bit(BTN_RIGHT, input_dev->keybit);
2764 __set_bit(BTN_MIDDLE, input_dev->keybit);
2765 __set_bit(BTN_SIDE, input_dev->keybit);
2766 __set_bit(BTN_EXTRA, input_dev->keybit);
2767 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2768 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
2769
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002770 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002771 input_abs_set_res(input_dev, ABS_RZ, 287);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002772 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
2773}
2774
Ping Cheng42f4f272015-04-15 16:53:54 -07002775void wacom_setup_device_quirks(struct wacom *wacom)
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002776{
Ping Cheng42f4f272015-04-15 16:53:54 -07002777 struct wacom_features *features = &wacom->wacom_wac.features;
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002778
Jason Gerecke862cf552015-06-15 18:01:43 -07002779 /* The pen and pad share the same interface on most devices */
Jason Gerecke5922e612016-10-19 18:03:51 -07002780 if (features->numbered_buttons > 0)
2781 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke862cf552015-06-15 18:01:43 -07002782 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
Ping Cheng3b164a02015-09-23 09:59:10 -07002783 features->type == DTUS ||
2784 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
Jason Gerecke862cf552015-06-15 18:01:43 -07002785 if (features->device_type & WACOM_DEVICETYPE_PEN)
2786 features->device_type |= WACOM_DEVICETYPE_PAD;
2787 }
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002788
2789 /* touch device found but size is not defined. use default */
Jason Gereckeaa86b182015-06-15 18:01:42 -07002790 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002791 features->x_max = 1023;
2792 features->y_max = 1023;
2793 }
2794
Ping Cheng42f4f272015-04-15 16:53:54 -07002795 /*
2796 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
2797 * touch interface in its HID descriptor. If this is the touch
2798 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
2799 * tablet values.
2800 */
Ping Cheng3b164a02015-09-23 09:59:10 -07002801 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
2802 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
Ping Cheng42f4f272015-04-15 16:53:54 -07002803 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
Jason Gerecke862cf552015-06-15 18:01:43 -07002804 if (features->touch_max)
2805 features->device_type |= WACOM_DEVICETYPE_TOUCH;
Jiri Kosinaa3088ab2015-11-17 00:24:14 +01002806 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
Jason Gerecke862cf552015-06-15 18:01:43 -07002807 features->device_type |= WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07002808
2809 features->x_max = 4096;
2810 features->y_max = 4096;
Ping Cheng42f4f272015-04-15 16:53:54 -07002811 }
Jason Gerecke96339202015-07-01 13:01:00 -07002812 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
2813 features->device_type |= WACOM_DEVICETYPE_PAD;
2814 }
Ping Cheng42f4f272015-04-15 16:53:54 -07002815 }
2816
2817 /*
Benjamin Tissoires580549e2016-03-25 15:26:55 +01002818 * Hack for the Bamboo One:
2819 * the device presents a PAD/Touch interface as most Bamboos and even
2820 * sends ghosts PAD data on it. However, later, we must disable this
2821 * ghost interface, and we can not detect it unless we set it here
2822 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
2823 */
2824 if (features->type == BAMBOO_PEN &&
2825 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
2826 features->device_type |= WACOM_DEVICETYPE_PAD;
2827
2828 /*
Jason Gerecke042628a2015-04-30 17:51:54 -07002829 * Raw Wacom-mode pen and touch events both come from interface
2830 * 0, whose HID descriptor has an application usage of 0xFF0D
Jason Gerecke8de82282016-10-19 18:03:37 -07002831 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
Jason Gerecke042628a2015-04-30 17:51:54 -07002832 * out through the HID_GENERIC device created for interface 1,
Benjamin Tissoires70caee02015-07-09 14:11:51 -04002833 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
Ping Cheng42f4f272015-04-15 16:53:54 -07002834 */
2835 if (features->type == BAMBOO_PAD)
Benjamin Tissoires70caee02015-07-09 14:11:51 -04002836 features->device_type = WACOM_DEVICETYPE_TOUCH;
Ping Cheng42f4f272015-04-15 16:53:54 -07002837
Aaron Skomra72b236d2015-08-20 16:05:17 -07002838 if (features->type == REMOTE)
2839 features->device_type = WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07002840
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002841 switch (features->type) {
2842 case PL:
2843 case DTU:
2844 case DTUS:
2845 case DTUSX:
2846 case WACOM_21UX2:
2847 case WACOM_22HD:
2848 case DTK:
2849 case WACOM_24HD:
2850 case WACOM_27QHD:
2851 case CINTIQ_HYBRID:
2852 case CINTIQ_COMPANION_2:
2853 case CINTIQ:
2854 case WACOM_BEE:
2855 case WACOM_13HD:
2856 case WACOM_24HDT:
2857 case WACOM_27QHDT:
2858 case TABLETPC:
2859 case TABLETPCE:
2860 case TABLETPC2FG:
2861 case MTSCREEN:
2862 case MTTPC:
2863 case MTTPC_B:
2864 features->device_type |= WACOM_DEVICETYPE_DIRECT;
2865 break;
2866 }
2867
Ping Cheng42f4f272015-04-15 16:53:54 -07002868 if (wacom->hdev->bus == BUS_BLUETOOTH)
2869 features->quirks |= WACOM_QUIRK_BATTERY;
2870
Chris Bagwell73149ab2011-10-26 22:34:21 -07002871 /* quirk for bamboo touch with 2 low res touches */
Jason Gereckebe853fd2015-12-04 14:45:27 -08002872 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
Chris Bagwell73149ab2011-10-26 22:34:21 -07002873 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002874 features->x_max <<= 5;
2875 features->y_max <<= 5;
2876 features->x_fuzz <<= 5;
2877 features->y_fuzz <<= 5;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002878 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002879 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07002880
2881 if (features->type == WIRELESS) {
Jason Gereckeccad85c2015-08-03 10:17:04 -07002882 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07002883 features->quirks |= WACOM_QUIRK_BATTERY;
2884 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07002885 }
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02002886
2887 if (features->type == REMOTE)
2888 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07002889}
2890
Jason Gerecke2636a3f2015-06-15 18:01:44 -07002891int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
Ping Cheng19635182012-04-29 21:09:18 -07002892 struct wacom_wac *wacom_wac)
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002893{
2894 struct wacom_features *features = &wacom_wac->features;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002895
2896 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
2897
Jason Gerecke2636a3f2015-06-15 18:01:44 -07002898 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
2899 return -ENODEV;
2900
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002901 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
2902 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
2903 else
2904 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
2905
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002906 if (features->type == HID_GENERIC)
2907 /* setup has already been done */
2908 return 0;
2909
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002910 __set_bit(BTN_TOUCH, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002911 __set_bit(ABS_MISC, input_dev->absbit);
2912
Jason Gereckee779ef22016-10-19 18:03:49 -07002913 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
2914 features->x_max - features->offset_right,
2915 features->x_fuzz, 0);
2916 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
2917 features->y_max - features->offset_bottom,
2918 features->y_fuzz, 0);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07002919 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
2920 features->pressure_max, features->pressure_fuzz, 0);
2921
2922 /* penabled devices have fixed resolution for each model */
2923 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
2924 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
2925
Ping Cheng497ab1f2014-01-20 20:18:04 -08002926 switch (features->type) {
Ping Chenga2f71c62015-01-27 13:29:36 -08002927 case GRAPHIRE_BT:
2928 __clear_bit(ABS_MISC, input_dev->absbit);
2929
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002930 case WACOM_MO:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002931 case WACOM_G4:
Ping Chenga2f71c62015-01-27 13:29:36 -08002932 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2933 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07002934 features->distance_fuzz, 0);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002935 /* fall through */
2936
2937 case GRAPHIRE:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002938 input_set_capability(input_dev, EV_REL, REL_WHEEL);
2939
2940 __set_bit(BTN_LEFT, input_dev->keybit);
2941 __set_bit(BTN_RIGHT, input_dev->keybit);
2942 __set_bit(BTN_MIDDLE, input_dev->keybit);
2943
2944 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2945 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
2946 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
2947 __set_bit(BTN_STYLUS, input_dev->keybit);
2948 __set_bit(BTN_STYLUS2, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002949 break;
2950
Ping Cheng500d4162015-01-27 13:30:03 -08002951 case WACOM_27QHD:
Jason Gerecke803296b2011-12-12 00:11:45 -08002952 case WACOM_24HD:
Ping Chenga112e9f2013-02-13 20:20:01 -08002953 case DTK:
Ping Chengd838c642012-07-24 23:54:11 -07002954 case WACOM_22HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07002955 case WACOM_21UX2:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002956 case WACOM_BEE:
Ping Cheng6521d0b2010-10-24 21:53:40 -07002957 case CINTIQ:
Ping Cheng56218562013-05-05 19:56:18 -07002958 case WACOM_13HD:
Ping Chenga2f71c62015-01-27 13:29:36 -08002959 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07002960 case CINTIQ_COMPANION_2:
Ping Cheng56218562013-05-05 19:56:18 -07002961 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002962 input_abs_set_res(input_dev, ABS_Z, 287);
Ping Cheng56218562013-05-05 19:56:18 -07002963 wacom_setup_cintiq(wacom_wac);
2964 break;
2965
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002966 case INTUOS3:
2967 case INTUOS3L:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002968 case INTUOS3S:
Ping Chenga2f71c62015-01-27 13:29:36 -08002969 case INTUOS4:
2970 case INTUOS4WL:
2971 case INTUOS4L:
2972 case INTUOS4S:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002973 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08002974 input_abs_set_res(input_dev, ABS_Z, 287);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002975 /* fall through */
2976
2977 case INTUOS:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07002978 wacom_setup_intuos(wacom_wac);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07002979 break;
2980
Jason Gerecke9fee6192012-04-03 15:47:22 -07002981 case INTUOS5:
2982 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07002983 case INTUOSPM:
2984 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07002985 case INTUOS5S:
Ping Cheng9a35c412013-09-20 09:51:56 -07002986 case INTUOSPS:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07002987 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
2988 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07002989 features->distance_fuzz, 0);
Jason Gereckeae584ca2012-04-03 15:50:40 -07002990
Jason Gerecke2636a3f2015-06-15 18:01:44 -07002991 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
2992 input_abs_set_res(input_dev, ABS_Z, 287);
Jason Gereckeae584ca2012-04-03 15:50:40 -07002993
Jason Gerecke2636a3f2015-06-15 18:01:44 -07002994 wacom_setup_intuos(wacom_wac);
Jason Gereckeae584ca2012-04-03 15:50:40 -07002995 break;
2996
Jason Gereckeb1e42792012-10-21 00:38:04 -07002997 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08002998 case WACOM_27QHDT:
Ping Cheng19635182012-04-29 21:09:18 -07002999 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07003000 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07003001 case MTTPC_B:
Ping Cheng6795a522012-06-28 16:49:00 -07003002 case TABLETPC2FG:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003003 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07003004 case TABLETPCE:
Ping Chenga43c7c52011-03-12 20:34:42 -08003005 __clear_bit(ABS_MISC, input_dev->absbit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003006 /* fall through */
3007
Ping Cheng497ab1f2014-01-20 20:18:04 -08003008 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08003009 case DTUSX:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003010 case PL:
Ping Chengc8f2edc2010-06-28 01:10:51 -07003011 case DTU:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003012 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003013 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003014 __set_bit(BTN_STYLUS, input_dev->keybit);
3015 __set_bit(BTN_STYLUS2, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003016 break;
3017
3018 case PTU:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003019 __set_bit(BTN_STYLUS2, input_dev->keybit);
3020 /* fall through */
3021
3022 case PENPARTNER:
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003023 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003024 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003025 __set_bit(BTN_STYLUS, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003026 break;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003027
Ping Chengb5fd2a32013-11-25 18:44:55 -08003028 case INTUOSHT:
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003029 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003030 case BAMBOO_PEN:
Ping Chengeda01da2015-09-23 13:51:15 -07003031 case INTUOSHT2:
Ping Chengeda01da2015-09-23 13:51:15 -07003032 if (features->type == INTUOSHT2) {
3033 wacom_setup_basic_pro_pen(wacom_wac);
3034 } else {
3035 __clear_bit(ABS_MISC, input_dev->absbit);
3036 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3037 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3038 __set_bit(BTN_STYLUS, input_dev->keybit);
3039 __set_bit(BTN_STYLUS2, input_dev->keybit);
3040 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003041 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003042 features->distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07003043 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003044 break;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003045 case BAMBOO_PAD:
3046 __clear_bit(ABS_MISC, input_dev->absbit);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003047 break;
3048 }
3049 return 0;
3050}
3051
3052int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3053 struct wacom_wac *wacom_wac)
3054{
3055 struct wacom_features *features = &wacom_wac->features;
3056
3057 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3058
3059 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3060 return -ENODEV;
3061
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003062 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3063 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3064 else
3065 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3066
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003067 if (features->type == HID_GENERIC)
3068 /* setup has already been done */
3069 return 0;
3070
3071 __set_bit(BTN_TOUCH, input_dev->keybit);
3072
3073 if (features->touch_max == 1) {
3074 input_set_abs_params(input_dev, ABS_X, 0,
3075 features->x_max, features->x_fuzz, 0);
3076 input_set_abs_params(input_dev, ABS_Y, 0,
3077 features->y_max, features->y_fuzz, 0);
3078 input_abs_set_res(input_dev, ABS_X,
3079 features->x_resolution);
3080 input_abs_set_res(input_dev, ABS_Y,
3081 features->y_resolution);
3082 }
3083 else if (features->touch_max > 1) {
3084 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3085 features->x_max, features->x_fuzz, 0);
3086 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3087 features->y_max, features->y_fuzz, 0);
3088 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3089 features->x_resolution);
3090 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3091 features->y_resolution);
3092 }
3093
3094 switch (features->type) {
3095 case INTUOS5:
3096 case INTUOS5L:
3097 case INTUOSPM:
3098 case INTUOSPL:
3099 case INTUOS5S:
3100 case INTUOSPS:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003101 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3102 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3103 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3104 break;
3105
3106 case WACOM_24HDT:
3107 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3108 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3109 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3110 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
3111 /* fall through */
3112
3113 case WACOM_27QHDT:
3114 case MTSCREEN:
3115 case MTTPC:
3116 case MTTPC_B:
3117 case TABLETPC2FG:
3118 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
3119 /*fall through */
3120
3121 case TABLETPC:
3122 case TABLETPCE:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003123 break;
3124
3125 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07003126 case INTUOSHT2:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003127 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3128 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3129 /* fall through */
3130
3131 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003132 case BAMBOO_TOUCH:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003133 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3134 input_set_abs_params(input_dev,
3135 ABS_MT_TOUCH_MAJOR,
3136 0, features->x_max, 0, 0);
3137 input_set_abs_params(input_dev,
3138 ABS_MT_TOUCH_MINOR,
3139 0, features->y_max, 0, 0);
3140 }
3141 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3142 break;
3143
3144 case BAMBOO_PAD:
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003145 input_mt_init_slots(input_dev, features->touch_max,
3146 INPUT_MT_POINTER);
3147 __set_bit(BTN_LEFT, input_dev->keybit);
3148 __set_bit(BTN_RIGHT, input_dev->keybit);
3149 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07003150 }
Ping Cheng19635182012-04-29 21:09:18 -07003151 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07003152}
3153
Jason Gerecke49005b92016-10-19 18:03:39 -07003154static int wacom_numbered_button_to_key(int n)
3155{
3156 if (n < 10)
3157 return BTN_0 + n;
3158 else if (n < 16)
3159 return BTN_A + (n-10);
3160 else if (n < 18)
3161 return BTN_BASE + (n-16);
3162 else
3163 return 0;
3164}
3165
Jiri Kosina5397df12015-08-28 20:46:42 +02003166static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003167 int button_count)
3168{
3169 int i;
3170
Jason Gerecke49005b92016-10-19 18:03:39 -07003171 for (i = 0; i < button_count; i++) {
3172 int key = wacom_numbered_button_to_key(i);
3173
3174 if (key)
3175 __set_bit(key, input_dev->keybit);
3176 }
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003177}
3178
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003179static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3180{
3181 struct wacom_led *led;
3182 int i;
3183 bool updated = false;
3184
3185 /*
3186 * 24HD has LED group 1 to the left and LED group 0 to the right.
3187 * So group 0 matches the second half of the buttons and thus the mask
3188 * needs to be shifted.
3189 */
3190 if (group == 0)
3191 mask >>= 8;
3192
3193 for (i = 0; i < 3; i++) {
3194 led = wacom_led_find(wacom, group, i);
3195 if (!led) {
3196 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3197 i, group);
3198 continue;
3199 }
3200 if (!updated && mask & BIT(i)) {
3201 led->held = true;
3202 led_trigger_event(&led->trigger, LED_FULL);
3203 } else {
3204 led->held = false;
3205 }
3206 }
3207}
3208
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003209static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
3210 int mask, int group)
3211{
3212 int button_per_group;
3213
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003214 /*
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003215 * 21UX2 has LED group 1 to the left and LED group 0
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003216 * to the right. We need to reverse the group to match this
3217 * historical behavior.
3218 */
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003219 if (wacom->wacom_wac.features.type == WACOM_21UX2)
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02003220 group = 1 - group;
3221
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003222 button_per_group = button_count/wacom->led.count;
3223
3224 return mask & (1 << (group * button_per_group));
3225}
3226
3227static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
3228 int group)
3229{
3230 struct wacom_led *led, *next_led;
3231 int cur;
3232 bool pressed;
3233
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003234 if (wacom->wacom_wac.features.type == WACOM_24HD)
3235 return wacom_24hd_update_leds(wacom, mask, group);
3236
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003237 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
3238 cur = wacom->led.groups[group].select;
3239
3240 led = wacom_led_find(wacom, group, cur);
3241 if (!led) {
3242 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
3243 cur, group);
3244 return;
3245 }
3246
3247 if (!pressed) {
3248 led->held = false;
3249 return;
3250 }
3251
3252 if (led->held && pressed)
3253 return;
3254
3255 next_led = wacom_led_next(wacom, led);
3256 if (!next_led) {
3257 hid_err(wacom->hdev, "can't find next LED in group %d\n",
3258 group);
3259 return;
3260 }
3261 if (next_led == led)
3262 return;
3263
3264 next_led->held = true;
3265 led_trigger_event(&next_led->trigger,
3266 wacom_leds_brightness_get(next_led));
3267}
3268
Jason Gereckec7f05222015-11-30 17:13:47 -08003269static void wacom_report_numbered_buttons(struct input_dev *input_dev,
3270 int button_count, int mask)
3271{
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003272 struct wacom *wacom = input_get_drvdata(input_dev);
Jason Gereckec7f05222015-11-30 17:13:47 -08003273 int i;
3274
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003275 for (i = 0; i < wacom->led.count; i++)
3276 wacom_update_led(wacom, button_count, mask, i);
3277
Jason Gerecke49005b92016-10-19 18:03:39 -07003278 for (i = 0; i < button_count; i++) {
3279 int key = wacom_numbered_button_to_key(i);
3280
3281 if (key)
3282 input_report_key(input_dev, key, mask & (1 << i));
3283 }
Jason Gereckec7f05222015-11-30 17:13:47 -08003284}
3285
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003286int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
3287 struct wacom_wac *wacom_wac)
3288{
3289 struct wacom_features *features = &wacom_wac->features;
3290
Jason Gerecke862cf552015-06-15 18:01:43 -07003291 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
3292 return -ENODEV;
3293
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02003294 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
3295 return -ENODEV;
3296
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003297 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
3298
3299 /* kept for making legacy xf86-input-wacom working with the wheels */
3300 __set_bit(ABS_MISC, input_dev->absbit);
3301
3302 /* kept for making legacy xf86-input-wacom accepting the pad */
Jason Gerecke5922e612016-10-19 18:03:51 -07003303 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
3304 input_dev->absinfo[ABS_X].maximum)))
3305 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
3306 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
3307 input_dev->absinfo[ABS_Y].maximum)))
3308 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003309
Benjamin Tissoires12969e32014-09-11 13:14:04 -04003310 /* kept for making udev and libwacom accepting the pad */
3311 __set_bit(BTN_STYLUS, input_dev->keybit);
3312
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003313 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
3314
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003315 switch (features->type) {
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003316
3317 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003318 case CINTIQ_COMPANION_2:
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003319 case DTK:
3320 case DTUS:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003321 case GRAPHIRE_BT:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003322 break;
3323
Benjamin Tissoires38138102014-07-24 12:51:03 -07003324 case WACOM_MO:
3325 __set_bit(BTN_BACK, input_dev->keybit);
3326 __set_bit(BTN_LEFT, input_dev->keybit);
3327 __set_bit(BTN_FORWARD, input_dev->keybit);
3328 __set_bit(BTN_RIGHT, input_dev->keybit);
3329 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3330 break;
3331
3332 case WACOM_G4:
3333 __set_bit(BTN_BACK, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07003334 __set_bit(BTN_FORWARD, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07003335 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3336 break;
3337
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003338 case WACOM_24HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003339 __set_bit(KEY_PROG1, input_dev->keybit);
3340 __set_bit(KEY_PROG2, input_dev->keybit);
3341 __set_bit(KEY_PROG3, input_dev->keybit);
3342
3343 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3344 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
3345 break;
3346
Ping Cheng500d4162015-01-27 13:30:03 -08003347 case WACOM_27QHD:
3348 __set_bit(KEY_PROG1, input_dev->keybit);
3349 __set_bit(KEY_PROG2, input_dev->keybit);
3350 __set_bit(KEY_PROG3, input_dev->keybit);
3351 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
3352 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
3353 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
3354 input_abs_set_res(input_dev, ABS_Y, 1024);
3355 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
3356 input_abs_set_res(input_dev, ABS_Z, 1024);
3357 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
3358 break;
3359
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003360 case WACOM_22HD:
3361 __set_bit(KEY_PROG1, input_dev->keybit);
3362 __set_bit(KEY_PROG2, input_dev->keybit);
3363 __set_bit(KEY_PROG3, input_dev->keybit);
3364 /* fall through */
3365
3366 case WACOM_21UX2:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003367 case WACOM_BEE:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003368 case CINTIQ:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003369 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3370 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3371 break;
3372
3373 case WACOM_13HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003374 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3375 break;
3376
3377 case INTUOS3:
3378 case INTUOS3L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003379 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
3380 /* fall through */
3381
3382 case INTUOS3S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003383 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
3384 break;
3385
3386 case INTUOS5:
3387 case INTUOS5L:
3388 case INTUOSPM:
3389 case INTUOSPL:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003390 case INTUOS5S:
3391 case INTUOSPS:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003392 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3393 break;
3394
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07003395 case INTUOS4WL:
3396 /*
3397 * For Bluetooth devices, the udev rule does not work correctly
3398 * for pads unless we add a stylus capability, which forces
3399 * ID_INPUT_TABLET to be set.
3400 */
3401 __set_bit(BTN_STYLUS, input_dev->keybit);
3402 /* fall through */
3403
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003404 case INTUOS4:
3405 case INTUOS4L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003406 case INTUOS4S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07003407 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3408 break;
3409
Benjamin Tissoires31168712014-07-24 12:50:10 -07003410 case INTUOSHT:
3411 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003412 case BAMBOO_TOUCH:
Ping Chengeda01da2015-09-23 13:51:15 -07003413 case INTUOSHT2:
Benjamin Tissoires31168712014-07-24 12:50:10 -07003414 __clear_bit(ABS_MISC, input_dev->absbit);
3415
3416 __set_bit(BTN_LEFT, input_dev->keybit);
3417 __set_bit(BTN_FORWARD, input_dev->keybit);
3418 __set_bit(BTN_BACK, input_dev->keybit);
3419 __set_bit(BTN_RIGHT, input_dev->keybit);
3420
3421 break;
3422
Aaron Skomra72b236d2015-08-20 16:05:17 -07003423 case REMOTE:
3424 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
3425 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
3426 break;
3427
Jason Gerecke5922e612016-10-19 18:03:51 -07003428 case HID_GENERIC:
3429 break;
3430
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003431 default:
3432 /* no pad supported */
Ping Chengb3c8e932014-11-18 13:27:48 -08003433 return -ENODEV;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003434 }
3435 return 0;
3436}
3437
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003438static const struct wacom_features wacom_features_0x00 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003439 { "Wacom Penpartner", 5040, 3780, 255, 0,
3440 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003441static const struct wacom_features wacom_features_0x10 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003442 { "Wacom Graphire", 10206, 7422, 511, 63,
3443 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003444static const struct wacom_features wacom_features_0x81 =
3445 { "Wacom Graphire BT", 16704, 12064, 511, 32,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003446 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003447static const struct wacom_features wacom_features_0x11 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003448 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
3449 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003450static const struct wacom_features wacom_features_0x12 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003451 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
3452 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003453static const struct wacom_features wacom_features_0x13 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003454 { "Wacom Graphire3", 10208, 7424, 511, 63,
3455 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003456static const struct wacom_features wacom_features_0x14 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003457 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
3458 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003459static const struct wacom_features wacom_features_0x15 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003460 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
3461 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003462static const struct wacom_features wacom_features_0x16 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003463 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
3464 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003465static const struct wacom_features wacom_features_0x17 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003466 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
3467 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003468static const struct wacom_features wacom_features_0x18 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003469 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
3470 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003471static const struct wacom_features wacom_features_0x19 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003472 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
3473 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003474static const struct wacom_features wacom_features_0x60 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003475 { "Wacom Volito", 5104, 3712, 511, 63,
3476 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003477static const struct wacom_features wacom_features_0x61 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003478 { "Wacom PenStation2", 3250, 2320, 255, 63,
3479 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003480static const struct wacom_features wacom_features_0x62 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003481 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
3482 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003483static const struct wacom_features wacom_features_0x63 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003484 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
3485 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003486static const struct wacom_features wacom_features_0x64 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003487 { "Wacom PenPartner2", 3250, 2320, 511, 63,
3488 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003489static const struct wacom_features wacom_features_0x65 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003490 { "Wacom Bamboo", 14760, 9225, 511, 63,
3491 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003492static const struct wacom_features wacom_features_0x69 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003493 { "Wacom Bamboo1", 5104, 3712, 511, 63,
3494 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07003495static const struct wacom_features wacom_features_0x6A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003496 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
3497 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07003498static const struct wacom_features wacom_features_0x6B =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003499 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
3500 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003501static const struct wacom_features wacom_features_0x20 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003502 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
3503 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003504static const struct wacom_features wacom_features_0x21 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003505 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
3506 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003507static const struct wacom_features wacom_features_0x22 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003508 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
3509 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003510static const struct wacom_features wacom_features_0x23 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003511 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
3512 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003513static const struct wacom_features wacom_features_0x24 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003514 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
3515 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003516static const struct wacom_features wacom_features_0x30 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003517 { "Wacom PL400", 5408, 4056, 255, 0,
3518 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003519static const struct wacom_features wacom_features_0x31 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003520 { "Wacom PL500", 6144, 4608, 255, 0,
3521 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003522static const struct wacom_features wacom_features_0x32 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003523 { "Wacom PL600", 6126, 4604, 255, 0,
3524 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003525static const struct wacom_features wacom_features_0x33 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003526 { "Wacom PL600SX", 6260, 5016, 255, 0,
3527 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003528static const struct wacom_features wacom_features_0x34 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003529 { "Wacom PL550", 6144, 4608, 511, 0,
3530 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003531static const struct wacom_features wacom_features_0x35 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003532 { "Wacom PL800", 7220, 5780, 511, 0,
3533 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003534static const struct wacom_features wacom_features_0x37 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003535 { "Wacom PL700", 6758, 5406, 511, 0,
3536 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003537static const struct wacom_features wacom_features_0x38 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003538 { "Wacom PL510", 6282, 4762, 511, 0,
3539 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003540static const struct wacom_features wacom_features_0x39 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003541 { "Wacom DTU710", 34080, 27660, 511, 0,
3542 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003543static const struct wacom_features wacom_features_0xC4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003544 { "Wacom DTF521", 6282, 4762, 511, 0,
3545 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003546static const struct wacom_features wacom_features_0xC0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003547 { "Wacom DTF720", 6858, 5506, 511, 0,
3548 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003549static const struct wacom_features wacom_features_0xC2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003550 { "Wacom DTF720a", 6858, 5506, 511, 0,
3551 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003552static const struct wacom_features wacom_features_0x03 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003553 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
3554 PTU, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003555static const struct wacom_features wacom_features_0x41 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003556 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
3557 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003558static const struct wacom_features wacom_features_0x42 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003559 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3560 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003561static const struct wacom_features wacom_features_0x43 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003562 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
3563 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003564static const struct wacom_features wacom_features_0x44 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003565 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
3566 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003567static const struct wacom_features wacom_features_0x45 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003568 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
3569 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003570static const struct wacom_features wacom_features_0xB0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003571 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003572 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003573static const struct wacom_features wacom_features_0xB1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003574 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003575 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003576static const struct wacom_features wacom_features_0xB2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003577 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003578 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003579static const struct wacom_features wacom_features_0xB3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003580 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003581 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003582static const struct wacom_features wacom_features_0xB4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003583 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003584 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003585static const struct wacom_features wacom_features_0xB5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003586 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003587 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003588static const struct wacom_features wacom_features_0xB7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003589 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003590 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003591static const struct wacom_features wacom_features_0xB8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003592 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003593 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003594static const struct wacom_features wacom_features_0xB9 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003595 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003596 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003597static const struct wacom_features wacom_features_0xBA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003598 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003599 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003600static const struct wacom_features wacom_features_0xBB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003601 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003602 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003603static const struct wacom_features wacom_features_0xBC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003604 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003605 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07003606static const struct wacom_features wacom_features_0xBD =
3607 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003608 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003609static const struct wacom_features wacom_features_0x26 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003610 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003611 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003612static const struct wacom_features wacom_features_0x27 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003613 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003614 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003615static const struct wacom_features wacom_features_0x28 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003616 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003617 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003618static const struct wacom_features wacom_features_0x29 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003619 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003620 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07003621static const struct wacom_features wacom_features_0x2A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003622 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003623 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng9a35c412013-09-20 09:51:56 -07003624static const struct wacom_features wacom_features_0x314 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003625 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003626 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003627 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07003628static const struct wacom_features wacom_features_0x315 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003629 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003630 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003631 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07003632static const struct wacom_features wacom_features_0x317 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003633 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003634 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003635 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Jason Gerecke803296b2011-12-12 00:11:45 -08003636static const struct wacom_features wacom_features_0xF4 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003637 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003638 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Jason Gereckee779ef22016-10-19 18:03:49 -07003639 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003640 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Jason Gerecke6f4d0382012-08-21 22:11:59 -07003641static const struct wacom_features wacom_features_0xF8 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003642 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003643 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Ping Chengfa770342014-12-01 13:44:28 -08003644 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003645 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07003646 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
Jason Gereckeb1e42792012-10-21 00:38:04 -07003647static const struct wacom_features wacom_features_0xF6 =
3648 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003649 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
3650 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng500d4162015-01-27 13:30:03 -08003651static const struct wacom_features wacom_features_0x32A =
Jason Gereckee779ef22016-10-19 18:03:49 -07003652 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003653 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07003654 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga7e66452015-02-04 16:01:54 -08003655 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng500d4162015-01-27 13:30:03 -08003656static const struct wacom_features wacom_features_0x32B =
Jason Gereckee779ef22016-10-19 18:03:49 -07003657 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003658 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Ping Cheng500d4162015-01-27 13:30:03 -08003659 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003660 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng500d4162015-01-27 13:30:03 -08003661 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
3662static const struct wacom_features wacom_features_0x32C =
3663 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
3664 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003665static const struct wacom_features wacom_features_0x3F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003666 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003667 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003668static const struct wacom_features wacom_features_0xC5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003669 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003670 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003671static const struct wacom_features wacom_features_0xC6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003672 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003673 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Ping Cheng56218562013-05-05 19:56:18 -07003674static const struct wacom_features wacom_features_0x304 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003675 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003676 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Jason Gereckee779ef22016-10-19 18:03:49 -07003677 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003678 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengb4bf2122015-03-25 17:08:13 -07003679static const struct wacom_features wacom_features_0x333 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003680 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003681 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengb4bf2122015-03-25 17:08:13 -07003682 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003683 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengb4bf2122015-03-25 17:08:13 -07003684 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
3685static const struct wacom_features wacom_features_0x335 =
3686 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
3687 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
3688 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003689static const struct wacom_features wacom_features_0xC7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003690 { "Wacom DTU1931", 37832, 30305, 511, 0,
3691 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengc8f2edc2010-06-28 01:10:51 -07003692static const struct wacom_features wacom_features_0xCE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003693 { "Wacom DTU2231", 47864, 27011, 511, 0,
3694 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003695 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
Ping Chengc8f2edc2010-06-28 01:10:51 -07003696static const struct wacom_features wacom_features_0xF0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003697 { "Wacom DTU1631", 34623, 19553, 511, 0,
3698 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng497ab1f2014-01-20 20:18:04 -08003699static const struct wacom_features wacom_features_0xFB =
Jason Gereckee779ef22016-10-19 18:03:49 -07003700 { "Wacom DTU1031", 22096, 13960, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003701 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07003702 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003703 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Chengfff00bf2014-12-04 18:23:04 -08003704static const struct wacom_features wacom_features_0x32F =
Jason Gereckee779ef22016-10-19 18:03:49 -07003705 { "Wacom DTU1031X", 22672, 12928, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003706 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07003707 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfff00bf2014-12-04 18:23:04 -08003708 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Aaron Skomra007760c2015-04-16 15:01:14 -07003709static const struct wacom_features wacom_features_0x336 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003710 { "Wacom DTU1141", 23672, 13403, 1023, 0,
Ping Chengff38e822015-11-12 17:21:14 -08003711 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07003712 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengff38e822015-11-12 17:21:14 -08003713 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07003714static const struct wacom_features wacom_features_0x57 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003715 { "Wacom DTK2241", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003716 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Jason Gereckee779ef22016-10-19 18:03:49 -07003717 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003718 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chenga112e9f2013-02-13 20:20:01 -08003719static const struct wacom_features wacom_features_0x59 = /* Pen */
Jason Gereckee779ef22016-10-19 18:03:49 -07003720 { "Wacom DTH2242", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003721 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Ping Chengfa770342014-12-01 13:44:28 -08003722 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003723 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga112e9f2013-02-13 20:20:01 -08003724 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
3725static const struct wacom_features wacom_features_0x5D = /* Touch */
3726 { "Wacom DTH2242", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003727 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
3728 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003729static const struct wacom_features wacom_features_0xCC =
Jason Gereckee779ef22016-10-19 18:03:49 -07003730 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003731 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07003732 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003733 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengd838c642012-07-24 23:54:11 -07003734static const struct wacom_features wacom_features_0xFA =
Jason Gereckee779ef22016-10-19 18:03:49 -07003735 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003736 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07003737 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08003738 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07003739static const struct wacom_features wacom_features_0x5B =
Jason Gereckee779ef22016-10-19 18:03:49 -07003740 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003741 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Ping Chengfa770342014-12-01 13:44:28 -08003742 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003743 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07003744 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
Ping Cheng56218562013-05-05 19:56:18 -07003745static const struct wacom_features wacom_features_0x5E =
3746 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003747 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
3748 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003749static const struct wacom_features wacom_features_0x90 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003750 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
3751 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003752static const struct wacom_features wacom_features_0x93 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003753 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
3754 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07003755static const struct wacom_features wacom_features_0x97 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003756 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
3757 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003758static const struct wacom_features wacom_features_0x9A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003759 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
3760 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003761static const struct wacom_features wacom_features_0x9F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003762 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
3763 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003764static const struct wacom_features wacom_features_0xE2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003765 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
3766 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003767static const struct wacom_features wacom_features_0xE3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003768 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
3769 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng19635182012-04-29 21:09:18 -07003770static const struct wacom_features wacom_features_0xE5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003771 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
3772 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07003773static const struct wacom_features wacom_features_0xE6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003774 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
3775 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell0d0e3062011-12-11 23:50:59 -08003776static const struct wacom_features wacom_features_0xEC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003777 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
3778 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengac173832012-06-12 00:15:06 -07003779static const struct wacom_features wacom_features_0xED =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003780 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
3781 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengac173832012-06-12 00:15:06 -07003782static const struct wacom_features wacom_features_0xEF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003783 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
3784 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng6afdc282012-11-03 12:16:15 -07003785static const struct wacom_features wacom_features_0x100 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003786 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
3787 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng6afdc282012-11-03 12:16:15 -07003788static const struct wacom_features wacom_features_0x101 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003789 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
3790 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Stephan Frank58694832013-03-07 14:08:50 -08003791static const struct wacom_features wacom_features_0x10D =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003792 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
3793 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke2d3163f2013-10-22 15:35:30 -07003794static const struct wacom_features wacom_features_0x10E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003795 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
3796 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07003797static const struct wacom_features wacom_features_0x10F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003798 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
3799 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke61616ed2014-05-14 11:42:22 -07003800static const struct wacom_features wacom_features_0x116 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003801 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
3802 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07003803static const struct wacom_features wacom_features_0x12C =
3804 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
3805 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengedbe2652012-11-21 13:12:50 -08003806static const struct wacom_features wacom_features_0x4001 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003807 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
3808 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07003809static const struct wacom_features wacom_features_0x4004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003810 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
3811 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07003812static const struct wacom_features wacom_features_0x5000 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003813 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
3814 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07003815static const struct wacom_features wacom_features_0x5002 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003816 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
3817 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08003818static const struct wacom_features wacom_features_0x47 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003819 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
3820 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwelld3825d52012-03-25 23:26:11 -07003821static const struct wacom_features wacom_features_0x84 =
Ping Cheng3b164a02015-09-23 09:59:10 -07003822 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003823static const struct wacom_features wacom_features_0xD0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003824 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07003825 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003826static const struct wacom_features wacom_features_0xD1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003827 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
3828 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003829static const struct wacom_features wacom_features_0xD2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003830 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
3831 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003832static const struct wacom_features wacom_features_0xD3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003833 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
3834 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Kevin Granade57a78722010-12-10 23:04:02 -08003835static const struct wacom_features wacom_features_0xD4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003836 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07003837 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Gerard Braad18adad12011-08-16 00:17:56 -07003838static const struct wacom_features wacom_features_0xD5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003839 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07003840 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003841static const struct wacom_features wacom_features_0xD6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003842 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
3843 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003844static const struct wacom_features wacom_features_0xD7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003845 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
3846 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003847static const struct wacom_features wacom_features_0xD8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003848 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
3849 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07003850static const struct wacom_features wacom_features_0xDA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003851 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
3852 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Chengf41a64e2013-08-21 09:14:49 -07003853static const struct wacom_features wacom_features_0xDB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003854 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
3855 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07003856static const struct wacom_features wacom_features_0xDD =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003857 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
3858 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwell73149ab2011-10-26 22:34:21 -07003859static const struct wacom_features wacom_features_0xDE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003860 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
3861 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07003862static const struct wacom_features wacom_features_0xDF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003863 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
3864 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Ping Chengf41a64e2013-08-21 09:14:49 -07003865static const struct wacom_features wacom_features_0x300 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003866 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07003867 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengf41a64e2013-08-21 09:14:49 -07003868static const struct wacom_features wacom_features_0x301 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003869 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
3870 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengb5fd2a32013-11-25 18:44:55 -08003871static const struct wacom_features wacom_features_0x302 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003872 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
3873 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003874 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08003875static const struct wacom_features wacom_features_0x303 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003876 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
3877 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003878 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08003879static const struct wacom_features wacom_features_0x30E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003880 { "Wacom Intuos S", 15200, 9500, 1023, 31,
3881 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003882 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08003883static const struct wacom_features wacom_features_0x6004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07003884 { "ISD-V4", 12800, 8000, 255, 0,
3885 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07003886static const struct wacom_features wacom_features_0x307 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003887 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003888 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08003889 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003890 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gerecke36d3c512013-09-20 09:47:35 -07003891 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07003892static const struct wacom_features wacom_features_0x309 =
Jason Gerecke36d3c512013-09-20 09:47:35 -07003893 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003894 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
3895 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04003896static const struct wacom_features wacom_features_0x30A =
Jason Gereckee779ef22016-10-19 18:03:49 -07003897 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003898 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08003899 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003900 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04003901 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
3902static const struct wacom_features wacom_features_0x30C =
3903 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
3904 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
3905 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003906static const struct wacom_features wacom_features_0x318 =
3907 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
3908 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3909static const struct wacom_features wacom_features_0x319 =
3910 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
3911 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
Jason Gereckef7acb552015-10-13 10:03:49 -07003912static const struct wacom_features wacom_features_0x325 =
3913 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
3914 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
3915 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07003916 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckef7acb552015-10-13 10:03:49 -07003917 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
3918static const struct wacom_features wacom_features_0x326 = /* Touch */
3919 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
3920 .oPid = 0x325 };
Ping Chengfefb3912014-11-11 12:52:08 -08003921static const struct wacom_features wacom_features_0x323 =
3922 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
3923 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3924 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Aaron Skomra72b236d2015-08-20 16:05:17 -07003925static const struct wacom_features wacom_features_0x331 =
Ping Cheng3b164a02015-09-23 09:59:10 -07003926 { "Wacom Express Key Remote", .type = REMOTE,
3927 .numbered_buttons = 18, .check_for_hid_type = true,
Aaron Skomra72b236d2015-08-20 16:05:17 -07003928 .hid_type = HID_TYPE_USBNONE };
Ping Chengeda01da2015-09-23 13:51:15 -07003929static const struct wacom_features wacom_features_0x33B =
3930 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
3931 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3932 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3933static const struct wacom_features wacom_features_0x33C =
3934 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
3935 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3936 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3937static const struct wacom_features wacom_features_0x33D =
3938 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
3939 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
3940 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3941static const struct wacom_features wacom_features_0x33E =
3942 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
3943 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
3944 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chenge1123fe2016-04-12 13:37:45 -07003945static const struct wacom_features wacom_features_0x343 =
Jason Gereckee779ef22016-10-19 18:03:49 -07003946 { "Wacom DTK1651", 34816, 19759, 1023, 0,
Ping Chenge1123fe2016-04-12 13:37:45 -07003947 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07003948 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chenge1123fe2016-04-12 13:37:45 -07003949 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Bastian Blankb036f6f2010-02-10 23:06:23 -08003950
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04003951static const struct wacom_features wacom_features_HID_ANY_ID =
Jason Gerecke41372d52016-08-08 12:06:30 -07003952 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04003953
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003954#define USB_DEVICE_WACOM(prod) \
3955 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3956 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Bastian Blankb036f6f2010-02-10 23:06:23 -08003957
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003958#define BT_DEVICE_WACOM(prod) \
3959 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3960 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Aristeu Rozanski1483f552011-06-22 01:17:17 -07003961
Mika Westerbergeef23a82015-02-23 15:52:43 +02003962#define I2C_DEVICE_WACOM(prod) \
3963 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3964 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3965
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08003966#define USB_DEVICE_LENOVO(prod) \
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003967 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
3968 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08003969
Benjamin Tissoires29b47392014-07-24 12:52:23 -07003970const struct hid_device_id wacom_ids[] = {
Bastian Blankb036f6f2010-02-10 23:06:23 -08003971 { USB_DEVICE_WACOM(0x00) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07003972 { USB_DEVICE_WACOM(0x03) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08003973 { USB_DEVICE_WACOM(0x10) },
3974 { USB_DEVICE_WACOM(0x11) },
3975 { USB_DEVICE_WACOM(0x12) },
3976 { USB_DEVICE_WACOM(0x13) },
3977 { USB_DEVICE_WACOM(0x14) },
3978 { USB_DEVICE_WACOM(0x15) },
3979 { USB_DEVICE_WACOM(0x16) },
3980 { USB_DEVICE_WACOM(0x17) },
3981 { USB_DEVICE_WACOM(0x18) },
3982 { USB_DEVICE_WACOM(0x19) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08003983 { USB_DEVICE_WACOM(0x20) },
3984 { USB_DEVICE_WACOM(0x21) },
3985 { USB_DEVICE_WACOM(0x22) },
3986 { USB_DEVICE_WACOM(0x23) },
3987 { USB_DEVICE_WACOM(0x24) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07003988 { USB_DEVICE_WACOM(0x26) },
3989 { USB_DEVICE_WACOM(0x27) },
3990 { USB_DEVICE_WACOM(0x28) },
3991 { USB_DEVICE_WACOM(0x29) },
3992 { USB_DEVICE_WACOM(0x2A) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08003993 { USB_DEVICE_WACOM(0x30) },
3994 { USB_DEVICE_WACOM(0x31) },
3995 { USB_DEVICE_WACOM(0x32) },
3996 { USB_DEVICE_WACOM(0x33) },
3997 { USB_DEVICE_WACOM(0x34) },
3998 { USB_DEVICE_WACOM(0x35) },
3999 { USB_DEVICE_WACOM(0x37) },
4000 { USB_DEVICE_WACOM(0x38) },
4001 { USB_DEVICE_WACOM(0x39) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004002 { USB_DEVICE_WACOM(0x3F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004003 { USB_DEVICE_WACOM(0x41) },
4004 { USB_DEVICE_WACOM(0x42) },
4005 { USB_DEVICE_WACOM(0x43) },
4006 { USB_DEVICE_WACOM(0x44) },
4007 { USB_DEVICE_WACOM(0x45) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004008 { USB_DEVICE_WACOM(0x47) },
Ping Cheng56218562013-05-05 19:56:18 -07004009 { USB_DEVICE_WACOM(0x57) },
Ping Chenga112e9f2013-02-13 20:20:01 -08004010 { USB_DEVICE_WACOM(0x59) },
Ping Cheng56218562013-05-05 19:56:18 -07004011 { USB_DEVICE_WACOM(0x5B) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004012 { USB_DEVICE_WACOM(0x5D) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004013 { USB_DEVICE_WACOM(0x5E) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004014 { USB_DEVICE_WACOM(0x60) },
4015 { USB_DEVICE_WACOM(0x61) },
4016 { USB_DEVICE_WACOM(0x62) },
4017 { USB_DEVICE_WACOM(0x63) },
4018 { USB_DEVICE_WACOM(0x64) },
4019 { USB_DEVICE_WACOM(0x65) },
4020 { USB_DEVICE_WACOM(0x69) },
4021 { USB_DEVICE_WACOM(0x6A) },
4022 { USB_DEVICE_WACOM(0x6B) },
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004023 { BT_DEVICE_WACOM(0x81) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004024 { USB_DEVICE_WACOM(0x84) },
4025 { USB_DEVICE_WACOM(0x90) },
4026 { USB_DEVICE_WACOM(0x93) },
4027 { USB_DEVICE_WACOM(0x97) },
4028 { USB_DEVICE_WACOM(0x9A) },
4029 { USB_DEVICE_WACOM(0x9F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004030 { USB_DEVICE_WACOM(0xB0) },
4031 { USB_DEVICE_WACOM(0xB1) },
4032 { USB_DEVICE_WACOM(0xB2) },
4033 { USB_DEVICE_WACOM(0xB3) },
4034 { USB_DEVICE_WACOM(0xB4) },
4035 { USB_DEVICE_WACOM(0xB5) },
4036 { USB_DEVICE_WACOM(0xB7) },
4037 { USB_DEVICE_WACOM(0xB8) },
4038 { USB_DEVICE_WACOM(0xB9) },
4039 { USB_DEVICE_WACOM(0xBA) },
4040 { USB_DEVICE_WACOM(0xBB) },
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004041 { USB_DEVICE_WACOM(0xBC) },
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004042 { BT_DEVICE_WACOM(0xBD) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004043 { USB_DEVICE_WACOM(0xC0) },
4044 { USB_DEVICE_WACOM(0xC2) },
4045 { USB_DEVICE_WACOM(0xC4) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004046 { USB_DEVICE_WACOM(0xC5) },
4047 { USB_DEVICE_WACOM(0xC6) },
4048 { USB_DEVICE_WACOM(0xC7) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004049 { USB_DEVICE_WACOM(0xCC) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004050 { USB_DEVICE_WACOM(0xCE) },
Henrik Rydbergcb734c02010-09-05 12:53:16 -07004051 { USB_DEVICE_WACOM(0xD0) },
Chris Bagwell2aaacb12010-09-12 00:11:35 -07004052 { USB_DEVICE_WACOM(0xD1) },
4053 { USB_DEVICE_WACOM(0xD2) },
4054 { USB_DEVICE_WACOM(0xD3) },
Kevin Granade57a78722010-12-10 23:04:02 -08004055 { USB_DEVICE_WACOM(0xD4) },
Gerard Braad18adad12011-08-16 00:17:56 -07004056 { USB_DEVICE_WACOM(0xD5) },
Ping Chengd38acb42011-01-24 09:32:50 -08004057 { USB_DEVICE_WACOM(0xD6) },
4058 { USB_DEVICE_WACOM(0xD7) },
David Foleya318e6b2010-11-30 23:45:46 -08004059 { USB_DEVICE_WACOM(0xD8) },
4060 { USB_DEVICE_WACOM(0xDA) },
David Foley47d09232010-12-07 21:05:59 -08004061 { USB_DEVICE_WACOM(0xDB) },
Chris Bagwell73149ab2011-10-26 22:34:21 -07004062 { USB_DEVICE_WACOM(0xDD) },
4063 { USB_DEVICE_WACOM(0xDE) },
4064 { USB_DEVICE_WACOM(0xDF) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004065 { USB_DEVICE_WACOM(0xE2) },
4066 { USB_DEVICE_WACOM(0xE3) },
Ping Cheng19635182012-04-29 21:09:18 -07004067 { USB_DEVICE_WACOM(0xE5) },
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07004068 { USB_DEVICE_WACOM(0xE6) },
Chris Bagwell0d0e3062011-12-11 23:50:59 -08004069 { USB_DEVICE_WACOM(0xEC) },
Ping Chengac173832012-06-12 00:15:06 -07004070 { USB_DEVICE_WACOM(0xED) },
4071 { USB_DEVICE_WACOM(0xEF) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004072 { USB_DEVICE_WACOM(0xF0) },
4073 { USB_DEVICE_WACOM(0xF4) },
4074 { USB_DEVICE_WACOM(0xF6) },
4075 { USB_DEVICE_WACOM(0xF8) },
4076 { USB_DEVICE_WACOM(0xFA) },
4077 { USB_DEVICE_WACOM(0xFB) },
Ping Cheng6afdc282012-11-03 12:16:15 -07004078 { USB_DEVICE_WACOM(0x100) },
4079 { USB_DEVICE_WACOM(0x101) },
Stephan Frank58694832013-03-07 14:08:50 -08004080 { USB_DEVICE_WACOM(0x10D) },
Jason Gerecke2d3163f2013-10-22 15:35:30 -07004081 { USB_DEVICE_WACOM(0x10E) },
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07004082 { USB_DEVICE_WACOM(0x10F) },
Jason Gerecke61616ed2014-05-14 11:42:22 -07004083 { USB_DEVICE_WACOM(0x116) },
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07004084 { USB_DEVICE_WACOM(0x12C) },
Ping Chengf41a64e2013-08-21 09:14:49 -07004085 { USB_DEVICE_WACOM(0x300) },
4086 { USB_DEVICE_WACOM(0x301) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004087 { USB_DEVICE_WACOM(0x302) },
4088 { USB_DEVICE_WACOM(0x303) },
Ping Cheng56218562013-05-05 19:56:18 -07004089 { USB_DEVICE_WACOM(0x304) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004090 { USB_DEVICE_WACOM(0x307) },
4091 { USB_DEVICE_WACOM(0x309) },
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004092 { USB_DEVICE_WACOM(0x30A) },
4093 { USB_DEVICE_WACOM(0x30C) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004094 { USB_DEVICE_WACOM(0x30E) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004095 { USB_DEVICE_WACOM(0x314) },
4096 { USB_DEVICE_WACOM(0x315) },
4097 { USB_DEVICE_WACOM(0x317) },
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004098 { USB_DEVICE_WACOM(0x318) },
4099 { USB_DEVICE_WACOM(0x319) },
Ping Chengfefb3912014-11-11 12:52:08 -08004100 { USB_DEVICE_WACOM(0x323) },
Jason Gereckef7acb552015-10-13 10:03:49 -07004101 { USB_DEVICE_WACOM(0x325) },
4102 { USB_DEVICE_WACOM(0x326) },
Ping Cheng500d4162015-01-27 13:30:03 -08004103 { USB_DEVICE_WACOM(0x32A) },
4104 { USB_DEVICE_WACOM(0x32B) },
4105 { USB_DEVICE_WACOM(0x32C) },
Ping Chengfff00bf2014-12-04 18:23:04 -08004106 { USB_DEVICE_WACOM(0x32F) },
Aaron Skomra72b236d2015-08-20 16:05:17 -07004107 { USB_DEVICE_WACOM(0x331) },
Ping Chengb4bf2122015-03-25 17:08:13 -07004108 { USB_DEVICE_WACOM(0x333) },
4109 { USB_DEVICE_WACOM(0x335) },
Aaron Skomra007760c2015-04-16 15:01:14 -07004110 { USB_DEVICE_WACOM(0x336) },
Ping Chengeda01da2015-09-23 13:51:15 -07004111 { USB_DEVICE_WACOM(0x33B) },
4112 { USB_DEVICE_WACOM(0x33C) },
4113 { USB_DEVICE_WACOM(0x33D) },
4114 { USB_DEVICE_WACOM(0x33E) },
Ping Chenge1123fe2016-04-12 13:37:45 -07004115 { USB_DEVICE_WACOM(0x343) },
Ping Chengedbe2652012-11-21 13:12:50 -08004116 { USB_DEVICE_WACOM(0x4001) },
Jason Gerecked51ddb22014-05-14 17:14:29 -07004117 { USB_DEVICE_WACOM(0x4004) },
4118 { USB_DEVICE_WACOM(0x5000) },
4119 { USB_DEVICE_WACOM(0x5002) },
Benjamin Tissoires00d6f222014-12-01 11:52:39 -05004120 { USB_DEVICE_LENOVO(0x6004) },
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004121
4122 { USB_DEVICE_WACOM(HID_ANY_ID) },
Mika Westerbergeef23a82015-02-23 15:52:43 +02004123 { I2C_DEVICE_WACOM(HID_ANY_ID) },
Jason Gereckeb9e06252017-01-25 12:08:35 -08004124 { BT_DEVICE_WACOM(HID_ANY_ID) },
Ping Cheng3bea7332006-07-13 18:01:36 -07004125 { }
4126};
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004127MODULE_DEVICE_TABLE(hid, wacom_ids);