blob: a7176fc0635dd2b7aa0fd7977938f8feb9b6a2ec [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ping Cheng3bea7332006-07-13 18:01:36 -07002/*
Dmitry Torokhov4104d132007-05-07 16:16:29 -04003 * drivers/input/tablet/wacom_wac.c
Ping Cheng3bea7332006-07-13 18:01:36 -07004 *
Ping Chengee545002009-12-15 00:35:24 -08005 * USB Wacom tablet support - Wacom specific code
Ping Cheng3bea7332006-07-13 18:01:36 -07006 */
7
8/*
Ping Cheng3bea7332006-07-13 18:01:36 -07009 */
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070010
Ping Cheng3bea7332006-07-13 18:01:36 -070011#include "wacom_wac.h"
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070012#include "wacom.h"
Henrik Rydberg47c78e82010-11-27 09:16:48 +010013#include <linux/input/mt.h>
Ping Cheng3bea7332006-07-13 18:01:36 -070014
Ping Chenge35fb8c2011-03-26 21:16:05 -070015/* resolution for penabled devices */
16#define WACOM_PL_RES 20
17#define WACOM_PENPRTN_RES 40
18#define WACOM_VOLITO_RES 50
19#define WACOM_GRAPHIRE_RES 80
20#define WACOM_INTUOS_RES 100
21#define WACOM_INTUOS3_RES 200
22
Ping Chengfa770342014-12-01 13:44:28 -080023/* Newer Cintiq and DTU have an offset between tablet and screen areas */
24#define WACOM_DTU_OFFSET 200
25#define WACOM_CINTIQ_OFFSET 400
26
Benjamin Tissoires387142b2014-08-06 13:52:56 -070027/*
28 * Scale factor relating reported contact size to logical contact area.
Jason Gerecke4e904952012-10-03 17:19:11 -070029 * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
30 */
31#define WACOM_CONTACT_AREA_SCALE 2607
32
Ping Cheng1924e052016-08-09 14:38:56 -070033static bool touch_arbitration = 1;
34module_param(touch_arbitration, bool, 0644);
35MODULE_PARM_DESC(touch_arbitration, " on (Y) off (N)");
36
Jason Gereckec7f05222015-11-30 17:13:47 -080037static void wacom_report_numbered_buttons(struct input_dev *input_dev,
38 int button_count, int mask);
39
Jason Gerecke5922e612016-10-19 18:03:51 -070040static int wacom_numbered_button_to_key(int n);
41
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -080042static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
43 int group);
Benjamin Tissoires387142b2014-08-06 13:52:56 -070044/*
45 * Percent of battery capacity for Graphire.
46 * 8th value means AC online and show 100% capacity.
47 */
48static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
49
Benjamin Tissoires81af7e62014-08-06 13:55:56 -070050/*
51 * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
52 */
53static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
54
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020055static void __wacom_notify_battery(struct wacom_battery *battery,
Jason Gerecke16e45982017-04-28 09:25:33 -070056 int bat_status, int bat_capacity,
57 bool bat_charging, bool bat_connected,
58 bool ps_connected)
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020059{
Jason Gerecke16e45982017-04-28 09:25:33 -070060 bool changed = battery->bat_status != bat_status ||
61 battery->battery_capacity != bat_capacity ||
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020062 battery->bat_charging != bat_charging ||
63 battery->bat_connected != bat_connected ||
64 battery->ps_connected != ps_connected;
65
66 if (changed) {
Jason Gerecke16e45982017-04-28 09:25:33 -070067 battery->bat_status = bat_status;
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +020068 battery->battery_capacity = bat_capacity;
69 battery->bat_charging = bat_charging;
70 battery->bat_connected = bat_connected;
71 battery->ps_connected = ps_connected;
72
73 if (battery->battery)
74 power_supply_changed(battery->battery);
75 }
76}
77
Jason Gerecke953f2c52015-03-06 11:47:39 -080078static void wacom_notify_battery(struct wacom_wac *wacom_wac,
Jason Gerecke16e45982017-04-28 09:25:33 -070079 int bat_status, int bat_capacity, bool bat_charging,
80 bool bat_connected, bool ps_connected)
Jason Gerecke953f2c52015-03-06 11:47:39 -080081{
82 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke953f2c52015-03-06 11:47:39 -080083
Jason Gerecke16e45982017-04-28 09:25:33 -070084 __wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
85 bat_charging, bat_connected, ps_connected);
Jason Gerecke953f2c52015-03-06 11:47:39 -080086}
87
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -070088static int wacom_penpartner_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -070089{
90 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -070091 struct input_dev *input = wacom->pen_input;
Ping Cheng3bea7332006-07-13 18:01:36 -070092
93 switch (data[0]) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -070094 case 1:
95 if (data[5] & 0x80) {
96 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
97 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -070098 input_report_key(input, wacom->tool[0], 1);
99 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700100 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
101 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700102 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
103 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
104 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700105 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700106 input_report_key(input, wacom->tool[0], 0);
107 input_report_abs(input, ABS_MISC, 0); /* report tool id */
108 input_report_abs(input, ABS_PRESSURE, -1);
109 input_report_key(input, BTN_TOUCH, 0);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700110 }
111 break;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700112
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700113 case 2:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700114 input_report_key(input, BTN_TOOL_PEN, 1);
115 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700116 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
117 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700118 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
119 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
120 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700121 break;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700122
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700123 default:
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700124 dev_dbg(input->dev.parent,
125 "%s: received unknown report #%d\n", __func__, data[0]);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700126 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700127 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700128
Ping Cheng3bea7332006-07-13 18:01:36 -0700129 return 1;
130}
131
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700132static int wacom_pl_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700133{
Jason Childse33da8a2010-02-17 22:38:31 -0800134 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700135 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700136 struct input_dev *input = wacom->pen_input;
Ping Chenge34b9d22008-05-05 11:36:41 -0400137 int prox, pressure;
Ping Cheng3bea7332006-07-13 18:01:36 -0700138
Ping Chengcad74702009-12-15 00:35:25 -0800139 if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700140 dev_dbg(input->dev.parent,
141 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700142 return 0;
143 }
144
145 prox = data[1] & 0x40;
146
Jason Gerecke025bcc12015-08-03 10:18:10 -0700147 if (!wacom->id[0]) {
148 if ((data[0] & 0x10) || (data[4] & 0x20)) {
149 wacom->tool[0] = BTN_TOOL_RUBBER;
150 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700151 }
Jason Gerecke025bcc12015-08-03 10:18:10 -0700152 else {
153 wacom->tool[0] = BTN_TOOL_PEN;
Ping Chenge34b9d22008-05-05 11:36:41 -0400154 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700155 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700156 }
157
Jason Gerecke025bcc12015-08-03 10:18:10 -0700158 /* If the eraser is in prox, STYLUS2 is always set. If we
159 * mis-detected the type and notice that STYLUS2 isn't set
160 * then force the eraser out of prox and let the pen in.
161 */
162 if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
163 input_report_key(input, BTN_TOOL_RUBBER, 0);
164 input_report_abs(input, ABS_MISC, 0);
165 input_sync(input);
166 wacom->tool[0] = BTN_TOOL_PEN;
167 wacom->id[0] = STYLUS_DEVICE_ID;
168 }
169
Jason Gerecke282e4632017-01-26 09:06:22 -0800170 if (prox) {
171 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
172 if (features->pressure_max > 255)
173 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
174 pressure += (features->pressure_max + 1) / 2;
Jason Gerecke025bcc12015-08-03 10:18:10 -0700175
Jason Gerecke282e4632017-01-26 09:06:22 -0800176 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
177 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
178 input_report_abs(input, ABS_PRESSURE, pressure);
Jason Gerecke025bcc12015-08-03 10:18:10 -0700179
Jason Gerecke282e4632017-01-26 09:06:22 -0800180 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
181 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
182 /* Only allow the stylus2 button to be reported for the pen tool. */
183 input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
184 }
Jason Gerecke025bcc12015-08-03 10:18:10 -0700185
186 if (!prox)
187 wacom->id[0] = 0;
188 input_report_key(input, wacom->tool[0], prox);
189 input_report_abs(input, ABS_MISC, wacom->id[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700190 return 1;
191}
192
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700193static int wacom_ptu_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700194{
195 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700196 struct input_dev *input = wacom->pen_input;
Ping Cheng3bea7332006-07-13 18:01:36 -0700197
Ping Chengcad74702009-12-15 00:35:25 -0800198 if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700199 dev_dbg(input->dev.parent,
200 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3bea7332006-07-13 18:01:36 -0700201 return 0;
202 }
203
Ping Cheng3bea7332006-07-13 18:01:36 -0700204 if (data[1] & 0x04) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700205 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
206 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
Ping Chenge34b9d22008-05-05 11:36:41 -0400207 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700208 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700209 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
210 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
Ping Chenge34b9d22008-05-05 11:36:41 -0400211 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700212 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700213 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700214 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
215 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
216 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700217 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
218 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
Ping Cheng3bea7332006-07-13 18:01:36 -0700219 return 1;
220}
221
Ping Chengc8f2edc2010-06-28 01:10:51 -0700222static int wacom_dtu_irq(struct wacom_wac *wacom)
223{
Jason Gerecke74b63412014-04-19 13:50:22 -0700224 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700225 struct input_dev *input = wacom->pen_input;
Jason Gerecke74b63412014-04-19 13:50:22 -0700226 int prox = data[1] & 0x20;
Ping Chengc8f2edc2010-06-28 01:10:51 -0700227
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700228 dev_dbg(input->dev.parent,
229 "%s: received report #%d", __func__, data[0]);
Ping Chengc8f2edc2010-06-28 01:10:51 -0700230
231 if (prox) {
232 /* Going into proximity select tool */
233 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
234 if (wacom->tool[0] == BTN_TOOL_PEN)
235 wacom->id[0] = STYLUS_DEVICE_ID;
236 else
237 wacom->id[0] = ERASER_DEVICE_ID;
238 }
239 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
240 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
241 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
242 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke74b63412014-04-19 13:50:22 -0700243 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
Ping Chengc8f2edc2010-06-28 01:10:51 -0700244 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
245 if (!prox) /* out-prox */
246 wacom->id[0] = 0;
247 input_report_key(input, wacom->tool[0], prox);
248 input_report_abs(input, ABS_MISC, wacom->id[0]);
249 return 1;
250}
251
Ping Cheng497ab1f2014-01-20 20:18:04 -0800252static int wacom_dtus_irq(struct wacom_wac *wacom)
253{
Jason Gerecke073b50b2019-08-16 11:54:26 -0700254 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700255 struct input_dev *input = wacom->pen_input;
Ping Cheng497ab1f2014-01-20 20:18:04 -0800256 unsigned short prox, pressure = 0;
257
258 if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
259 dev_dbg(input->dev.parent,
260 "%s: received unknown report #%d", __func__, data[0]);
261 return 0;
262 } else if (data[0] == WACOM_REPORT_DTUSPAD) {
Benjamin Tissoires422b0312014-07-24 12:50:39 -0700263 input = wacom->pad_input;
Ping Cheng497ab1f2014-01-20 20:18:04 -0800264 input_report_key(input, BTN_0, (data[1] & 0x01));
265 input_report_key(input, BTN_1, (data[1] & 0x02));
266 input_report_key(input, BTN_2, (data[1] & 0x04));
267 input_report_key(input, BTN_3, (data[1] & 0x08));
268 input_report_abs(input, ABS_MISC,
269 data[1] & 0x0f ? PAD_DEVICE_ID : 0);
Ping Cheng497ab1f2014-01-20 20:18:04 -0800270 return 1;
271 } else {
272 prox = data[1] & 0x80;
273 if (prox) {
274 switch ((data[1] >> 3) & 3) {
275 case 1: /* Rubber */
276 wacom->tool[0] = BTN_TOOL_RUBBER;
277 wacom->id[0] = ERASER_DEVICE_ID;
278 break;
279
280 case 2: /* Pen */
281 wacom->tool[0] = BTN_TOOL_PEN;
282 wacom->id[0] = STYLUS_DEVICE_ID;
283 break;
284 }
285 }
286
287 input_report_key(input, BTN_STYLUS, data[1] & 0x20);
288 input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
289 input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
290 input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
291 pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
292 input_report_abs(input, ABS_PRESSURE, pressure);
293 input_report_key(input, BTN_TOUCH, pressure > 10);
294
295 if (!prox) /* out-prox */
296 wacom->id[0] = 0;
297 input_report_key(input, wacom->tool[0], prox);
298 input_report_abs(input, ABS_MISC, wacom->id[0]);
Ping Cheng497ab1f2014-01-20 20:18:04 -0800299 return 1;
300 }
301}
302
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700303static int wacom_graphire_irq(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700304{
Jason Childse33da8a2010-02-17 22:38:31 -0800305 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700306 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700307 struct input_dev *input = wacom->pen_input;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700308 struct input_dev *pad_input = wacom->pad_input;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700309 int battery_capacity, ps_connected;
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700310 int prox;
Ping Cheng3b57ca02010-03-04 21:50:59 -0800311 int rw = 0;
312 int retval = 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700313
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700314 if (features->type == GRAPHIRE_BT) {
315 if (data[0] != WACOM_REPORT_PENABLED_BT) {
316 dev_dbg(input->dev.parent,
317 "%s: received unknown report #%d\n", __func__,
318 data[0]);
319 goto exit;
320 }
321 } else if (data[0] != WACOM_REPORT_PENABLED) {
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -0700322 dev_dbg(input->dev.parent,
323 "%s: received unknown report #%d\n", __func__, data[0]);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800324 goto exit;
Ping Cheng3bea7332006-07-13 18:01:36 -0700325 }
326
Ping Cheng3b57ca02010-03-04 21:50:59 -0800327 prox = data[1] & 0x80;
328 if (prox || wacom->id[0]) {
329 if (prox) {
330 switch ((data[1] >> 5) & 3) {
Ping Cheng3bea7332006-07-13 18:01:36 -0700331
332 case 0: /* Pen */
333 wacom->tool[0] = BTN_TOOL_PEN;
Ping Chenge34b9d22008-05-05 11:36:41 -0400334 wacom->id[0] = STYLUS_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700335 break;
336
337 case 1: /* Rubber */
338 wacom->tool[0] = BTN_TOOL_RUBBER;
Ping Chenge34b9d22008-05-05 11:36:41 -0400339 wacom->id[0] = ERASER_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700340 break;
341
342 case 2: /* Mouse with wheel */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700343 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500344 fallthrough;
Ping Cheng3bea7332006-07-13 18:01:36 -0700345
346 case 3: /* Mouse without wheel */
347 wacom->tool[0] = BTN_TOOL_MOUSE;
Ping Chenge34b9d22008-05-05 11:36:41 -0400348 wacom->id[0] = CURSOR_DEVICE_ID;
Ping Cheng3bea7332006-07-13 18:01:36 -0700349 break;
Ping Cheng3b57ca02010-03-04 21:50:59 -0800350 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700351 }
Dmitry Torokhov252f7762010-03-19 22:33:38 -0700352 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
353 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Ping Cheng3bea7332006-07-13 18:01:36 -0700354 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700355 if (features->type == GRAPHIRE_BT)
356 input_report_abs(input, ABS_PRESSURE, data[6] |
357 (((__u16) (data[1] & 0x08)) << 5));
358 else
359 input_report_abs(input, ABS_PRESSURE, data[6] |
360 ((data[7] & 0x03) << 8));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700361 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
362 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
363 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
Dmitry Torokhovafb567e2010-04-13 23:08:58 -0700364 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700365 input_report_key(input, BTN_LEFT, data[1] & 0x01);
366 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800367 if (features->type == WACOM_G4 ||
368 features->type == WACOM_MO) {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700369 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
Mike Autyd9f66c12010-08-28 20:35:17 -0700370 rw = (data[7] & 0x04) - (data[7] & 0x03);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700371 } else if (features->type == GRAPHIRE_BT) {
372 /* Compute distance between mouse and tablet */
373 rw = 44 - (data[6] >> 2);
374 rw = clamp_val(rw, 0, 31);
375 input_report_abs(input, ABS_DISTANCE, rw);
376 if (((data[1] >> 5) & 3) == 2) {
377 /* Mouse with wheel */
378 input_report_key(input, BTN_MIDDLE,
379 data[1] & 0x04);
380 rw = (data[6] & 0x01) ? -1 :
381 (data[6] & 0x02) ? 1 : 0;
382 } else {
383 rw = 0;
384 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800385 } else {
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700386 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
Mike Autyd9f66c12010-08-28 20:35:17 -0700387 rw = -(signed char)data[6];
Ping Cheng3b57ca02010-03-04 21:50:59 -0800388 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700389 input_report_rel(input, REL_WHEEL, rw);
Dmitry Torokhovafb567e2010-04-13 23:08:58 -0700390 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800391
392 if (!prox)
393 wacom->id[0] = 0;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700394 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
395 input_report_key(input, wacom->tool[0], prox);
396 input_sync(input); /* sync last event */
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800397 }
Ping Cheng3bea7332006-07-13 18:01:36 -0700398
399 /* send pad data */
Jason Childse33da8a2010-02-17 22:38:31 -0800400 switch (features->type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700401 case WACOM_G4:
Ping Cheng3b57ca02010-03-04 21:50:59 -0800402 prox = data[7] & 0xf8;
403 if (prox || wacom->id[1]) {
Ping Chenge34b9d22008-05-05 11:36:41 -0400404 wacom->id[1] = PAD_DEVICE_ID;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700405 input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
406 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
Ping Cheng3bea7332006-07-13 18:01:36 -0700407 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
Benjamin Tissoires38138102014-07-24 12:51:03 -0700408 input_report_rel(pad_input, REL_WHEEL, rw);
Ping Cheng3b57ca02010-03-04 21:50:59 -0800409 if (!prox)
410 wacom->id[1] = 0;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700411 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
Ping Chengab687b12010-04-05 23:07:41 -0700412 retval = 1;
Ping Cheng3bea7332006-07-13 18:01:36 -0700413 }
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400414 break;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700415
416 case WACOM_MO:
Ping Cheng3b57ca02010-03-04 21:50:59 -0800417 prox = (data[7] & 0xf8) || data[8];
418 if (prox || wacom->id[1]) {
Ping Chenge34b9d22008-05-05 11:36:41 -0400419 wacom->id[1] = PAD_DEVICE_ID;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700420 input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
421 input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
422 input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
423 input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
424 input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
Ping Cheng3b57ca02010-03-04 21:50:59 -0800425 if (!prox)
426 wacom->id[1] = 0;
Benjamin Tissoires38138102014-07-24 12:51:03 -0700427 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
Ping Cheng84460012011-07-06 18:05:43 -0700428 retval = 1;
Ping Cheng7ecfbfd2007-06-14 23:32:48 -0400429 }
430 break;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700431 case GRAPHIRE_BT:
432 prox = data[7] & 0x03;
433 if (prox || wacom->id[1]) {
434 wacom->id[1] = PAD_DEVICE_ID;
435 input_report_key(pad_input, BTN_0, (data[7] & 0x02));
436 input_report_key(pad_input, BTN_1, (data[7] & 0x01));
437 if (!prox)
438 wacom->id[1] = 0;
439 input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
440 retval = 1;
441 }
442 break;
443 }
444
445 /* Store current battery capacity and power supply state */
446 if (features->type == GRAPHIRE_BT) {
447 rw = (data[7] >> 2 & 0x07);
448 battery_capacity = batcap_gr[rw];
449 ps_connected = rw == 7;
Jason Gerecke16e45982017-04-28 09:25:33 -0700450 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
451 battery_capacity, ps_connected, 1,
452 ps_connected);
Ping Cheng3bea7332006-07-13 18:01:36 -0700453 }
Ping Cheng3b57ca02010-03-04 21:50:59 -0800454exit:
455 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -0700456}
457
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500458static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
459{
460 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke0bbfe282016-01-06 13:25:53 -0800461 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500462 struct hid_report *r;
463 struct hid_report_enum *re;
464
465 re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
Jason Gerecke0bbfe282016-01-06 13:25:53 -0800466 if (features->type == INTUOSHT2)
467 r = re->report_id_hash[WACOM_REPORT_INTUOSHT2_ID];
468 else
469 r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1];
Benjamin Tissoires5fcad162015-03-05 17:36:54 -0500470 if (r) {
471 hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
472 }
473}
474
Jason Gereckefb013a02015-11-30 17:13:46 -0800475static int wacom_intuos_pad(struct wacom_wac *wacom)
476{
477 struct wacom_features *features = &wacom->features;
478 unsigned char *data = wacom->data;
479 struct input_dev *input = wacom->pad_input;
Jason Gereckec7f05222015-11-30 17:13:47 -0800480 int i;
481 int buttons = 0, nbuttons = features->numbered_buttons;
482 int keys = 0, nkeys = 0;
483 int ring1 = 0, ring2 = 0;
484 int strip1 = 0, strip2 = 0;
485 bool prox = false;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700486 bool wrench = false, keyboard = false, mute_touch = false, menu = false,
487 info = false;
Jason Gereckefb013a02015-11-30 17:13:46 -0800488
489 /* pad packets. Works as a second tool and is always in prox */
490 if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
491 data[0] == WACOM_REPORT_CINTIQPAD))
492 return 0;
493
494 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800495 buttons = (data[3] << 1) | (data[2] & 0x01);
496 ring1 = data[1];
Jason Gereckefb013a02015-11-30 17:13:46 -0800497 } else if (features->type == DTK) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800498 buttons = data[6];
Jason Gereckefb013a02015-11-30 17:13:46 -0800499 } else if (features->type == WACOM_13HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800500 buttons = (data[4] << 1) | (data[3] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800501 } else if (features->type == WACOM_24HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800502 buttons = (data[8] << 8) | data[6];
503 ring1 = data[1];
504 ring2 = data[2];
Jason Gereckefb013a02015-11-30 17:13:46 -0800505
506 /*
507 * Three "buttons" are available on the 24HD which are
508 * physically implemented as a touchstrip. Each button
509 * is approximately 3 bits wide with a 2 bit spacing.
510 * The raw touchstrip bits are stored at:
511 * ((data[3] & 0x1f) << 8) | data[4])
512 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800513 nkeys = 3;
514 keys = ((data[3] & 0x1C) ? 1<<2 : 0) |
515 ((data[4] & 0xE0) ? 1<<1 : 0) |
516 ((data[4] & 0x07) ? 1<<0 : 0);
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700517 keyboard = !!(data[4] & 0xE0);
518 info = !!(data[3] & 0x1C);
519
520 if (features->oPid) {
521 mute_touch = !!(data[4] & 0x07);
522 if (mute_touch)
523 wacom->shared->is_touch_on =
524 !wacom->shared->is_touch_on;
525 } else {
526 wrench = !!(data[4] & 0x07);
527 }
Jason Gereckefb013a02015-11-30 17:13:46 -0800528 } else if (features->type == WACOM_27QHD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800529 nkeys = 3;
530 keys = data[2] & 0x07;
Jason Gereckefb013a02015-11-30 17:13:46 -0800531
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700532 wrench = !!(data[2] & 0x01);
533 keyboard = !!(data[2] & 0x02);
534
535 if (features->oPid) {
536 mute_touch = !!(data[2] & 0x04);
537 if (mute_touch)
538 wacom->shared->is_touch_on =
539 !wacom->shared->is_touch_on;
540 } else {
541 menu = !!(data[2] & 0x04);
542 }
Jason Gereckefb013a02015-11-30 17:13:46 -0800543 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
544 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
545 input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
Jason Gereckefb013a02015-11-30 17:13:46 -0800546 } else if (features->type == CINTIQ_HYBRID) {
547 /*
548 * Do not send hardware buttons under Android. They
549 * are already sent to the system through GPIO (and
550 * have different meaning).
Jason Gereckec7f05222015-11-30 17:13:47 -0800551 *
552 * d-pad right -> data[4] & 0x10
553 * d-pad up -> data[4] & 0x20
554 * d-pad left -> data[4] & 0x40
555 * d-pad down -> data[4] & 0x80
556 * d-pad center -> data[3] & 0x01
Jason Gereckefb013a02015-11-30 17:13:46 -0800557 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800558 buttons = (data[4] << 1) | (data[3] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800559 } else if (features->type == CINTIQ_COMPANION_2) {
Aaron Armstrong Skomra693c3da2019-07-23 11:09:15 -0700560 /* d-pad right -> data[2] & 0x10
561 * d-pad up -> data[2] & 0x20
562 * d-pad left -> data[2] & 0x40
563 * d-pad down -> data[2] & 0x80
564 * d-pad center -> data[1] & 0x01
Jason Gereckec7f05222015-11-30 17:13:47 -0800565 */
Jason Gerecke0402b6b2015-12-16 13:37:36 -0800566 buttons = ((data[2] >> 4) << 7) |
Aaron Armstrong Skomra693c3da2019-07-23 11:09:15 -0700567 ((data[1] & 0x04) << 4) |
Jason Gereckec7f05222015-11-30 17:13:47 -0800568 ((data[2] & 0x0F) << 2) |
569 (data[1] & 0x03);
Jason Gereckefb013a02015-11-30 17:13:46 -0800570 } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
Jason Gereckefb013a02015-11-30 17:13:46 -0800571 /*
572 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
573 * addition to the mechanical switch. Switch data is
574 * stored in data[4], capacitive data in data[5].
Jason Gereckec7f05222015-11-30 17:13:47 -0800575 *
576 * Touch ring mode switch (data[3]) has no capacitive sensor
Jason Gereckefb013a02015-11-30 17:13:46 -0800577 */
Jason Gereckec7f05222015-11-30 17:13:47 -0800578 buttons = (data[4] << 1) | (data[3] & 0x01);
579 ring1 = data[2];
Jason Gereckefb013a02015-11-30 17:13:46 -0800580 } else {
581 if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800582 buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) |
583 (data[6] << 1) | (data[5] & 0x01);
Jason Gereckefb013a02015-11-30 17:13:46 -0800584
585 if (features->type == WACOM_22HD) {
Jason Gereckec7f05222015-11-30 17:13:47 -0800586 nkeys = 3;
587 keys = data[9] & 0x07;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700588
589 info = !!(data[9] & 0x01);
590 wrench = !!(data[9] & 0x02);
Jason Gereckefb013a02015-11-30 17:13:46 -0800591 }
592 } else {
Ping Chengce067602017-08-31 15:50:03 -0700593 buttons = ((data[6] & 0x10) << 5) |
594 ((data[5] & 0x10) << 4) |
Jason Gereckec7f05222015-11-30 17:13:47 -0800595 ((data[6] & 0x0F) << 4) |
596 (data[5] & 0x0F);
Jason Gereckefb013a02015-11-30 17:13:46 -0800597 }
Jason Gereckef73d08d2015-12-16 13:37:33 -0800598 strip1 = ((data[1] & 0x1f) << 8) | data[2];
599 strip2 = ((data[3] & 0x1f) << 8) | data[4];
Jason Gereckefb013a02015-11-30 17:13:46 -0800600 }
Jason Gereckec7f05222015-11-30 17:13:47 -0800601
Jason Gerecke073b50b2019-08-16 11:54:26 -0700602 prox = (buttons & ~(~0U << nbuttons)) | (keys & ~(~0U << nkeys)) |
Dan Carpenter8f9cfdd2015-12-09 13:22:05 +0300603 (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2;
Jason Gereckec7f05222015-11-30 17:13:47 -0800604
605 wacom_report_numbered_buttons(input, nbuttons, buttons);
606
607 for (i = 0; i < nkeys; i++)
608 input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
609
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -0700610 input_report_key(input, KEY_BUTTONCONFIG, wrench);
611 input_report_key(input, KEY_ONSCREEN_KEYBOARD, keyboard);
612 input_report_key(input, KEY_CONTROLPANEL, menu);
613 input_report_key(input, KEY_INFO, info);
614
615 if (wacom->shared && wacom->shared->touch_input) {
616 input_report_switch(wacom->shared->touch_input,
617 SW_MUTE_DEVICE,
618 !wacom->shared->is_touch_on);
619 input_sync(wacom->shared->touch_input);
620 }
621
Jason Gereckec7f05222015-11-30 17:13:47 -0800622 input_report_abs(input, ABS_RX, strip1);
Jason Gerecke03a0dc52015-12-16 13:37:34 -0800623 input_report_abs(input, ABS_RY, strip2);
Jason Gereckec7f05222015-11-30 17:13:47 -0800624
Jason Gereckeaaae03e2015-12-16 13:37:35 -0800625 input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0);
626 input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0);
Jason Gereckec7f05222015-11-30 17:13:47 -0800627
628 input_report_key(input, wacom->tool[1], prox ? 1 : 0);
629 input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
630
631 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
632
Jason Gereckefb013a02015-11-30 17:13:46 -0800633 return 1;
634}
635
Jason Gerecke82527da2016-10-19 18:03:47 -0700636static int wacom_intuos_id_mangle(int tool_id)
637{
638 return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
639}
640
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100641static int wacom_intuos_get_tool_type(int tool_id)
642{
643 int tool_type;
644
645 switch (tool_id) {
646 case 0x812: /* Inking pen */
647 case 0x801: /* Intuos3 Inking pen */
Jason Gerecke82527da2016-10-19 18:03:47 -0700648 case 0x12802: /* Intuos4/5 Inking Pen */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100649 case 0x012:
650 tool_type = BTN_TOOL_PENCIL;
651 break;
652
653 case 0x822: /* Pen */
654 case 0x842:
655 case 0x852:
656 case 0x823: /* Intuos3 Grip Pen */
657 case 0x813: /* Intuos3 Classic Pen */
658 case 0x885: /* Intuos3 Marker Pen */
659 case 0x802: /* Intuos4/5 13HD/24HD General Pen */
660 case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
661 case 0x8e2: /* IntuosHT2 pen */
662 case 0x022:
Jason Gerecke82527da2016-10-19 18:03:47 -0700663 case 0x10804: /* Intuos4/5 13HD/24HD Art Pen */
Jason Gerecke4e6e7d72019-02-19 17:58:56 +0000664 case 0x10842: /* MobileStudio Pro Pro Pen slim */
Jason Gerecke82527da2016-10-19 18:03:47 -0700665 case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
666 case 0x16802: /* Cintiq 13HD Pro Pen */
667 case 0x18802: /* DTH2242 Pen */
668 case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100669 tool_type = BTN_TOOL_PEN;
670 break;
671
672 case 0x832: /* Stroke pen */
673 case 0x032:
674 tool_type = BTN_TOOL_BRUSH;
675 break;
676
677 case 0x007: /* Mouse 4D and 2D */
678 case 0x09c:
679 case 0x094:
680 case 0x017: /* Intuos3 2D Mouse */
681 case 0x806: /* Intuos4 Mouse */
682 tool_type = BTN_TOOL_MOUSE;
683 break;
684
685 case 0x096: /* Lens cursor */
686 case 0x097: /* Intuos3 Lens cursor */
687 case 0x006: /* Intuos4 Lens cursor */
688 tool_type = BTN_TOOL_LENS;
689 break;
690
691 case 0x82a: /* Eraser */
Jason Gerecke9ce9a122016-11-11 15:05:52 -0800692 case 0x84a:
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100693 case 0x85a:
694 case 0x91a:
695 case 0xd1a:
696 case 0x0fa:
697 case 0x82b: /* Intuos3 Grip Pen Eraser */
698 case 0x81b: /* Intuos3 Classic Pen Eraser */
699 case 0x91b: /* Intuos3 Airbrush Eraser */
700 case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
701 case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
702 case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
Jason Gerecke82527da2016-10-19 18:03:47 -0700703 case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
704 case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
705 case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
Jason Gerecke4e6e7d72019-02-19 17:58:56 +0000706 case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
Jason Gerecke82527da2016-10-19 18:03:47 -0700707 case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
708 case 0x1880a: /* DTH2242 Eraser */
709 case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100710 tool_type = BTN_TOOL_RUBBER;
711 break;
712
713 case 0xd12:
714 case 0x912:
715 case 0x112:
716 case 0x913: /* Intuos3 Airbrush */
717 case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
Jason Gerecke82527da2016-10-19 18:03:47 -0700718 case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100719 tool_type = BTN_TOOL_AIRBRUSH;
720 break;
721
722 default: /* Unknown tool */
723 tool_type = BTN_TOOL_PEN;
724 break;
725 }
726 return tool_type;
727}
728
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -0700729static void wacom_exit_report(struct wacom_wac *wacom)
730{
731 struct input_dev *input = wacom->pen_input;
732 struct wacom_features *features = &wacom->features;
733 unsigned char *data = wacom->data;
734 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
735
736 /*
737 * Reset all states otherwise we lose the initial states
738 * when in-prox next time
739 */
740 input_report_abs(input, ABS_X, 0);
741 input_report_abs(input, ABS_Y, 0);
742 input_report_abs(input, ABS_DISTANCE, 0);
743 input_report_abs(input, ABS_TILT_X, 0);
744 input_report_abs(input, ABS_TILT_Y, 0);
745 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
746 input_report_key(input, BTN_LEFT, 0);
747 input_report_key(input, BTN_MIDDLE, 0);
748 input_report_key(input, BTN_RIGHT, 0);
749 input_report_key(input, BTN_SIDE, 0);
750 input_report_key(input, BTN_EXTRA, 0);
751 input_report_abs(input, ABS_THROTTLE, 0);
752 input_report_abs(input, ABS_RZ, 0);
753 } else {
754 input_report_abs(input, ABS_PRESSURE, 0);
755 input_report_key(input, BTN_STYLUS, 0);
756 input_report_key(input, BTN_STYLUS2, 0);
757 input_report_key(input, BTN_TOUCH, 0);
758 input_report_abs(input, ABS_WHEEL, 0);
759 if (features->type >= INTUOS3S)
760 input_report_abs(input, ABS_Z, 0);
761 }
762 input_report_key(input, wacom->tool[idx], 0);
763 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
764 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
765 wacom->id[idx] = 0;
766}
767
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -0700768static int wacom_intuos_inout(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700769{
Jason Childse33da8a2010-02-17 22:38:31 -0800770 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700771 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700772 struct input_dev *input = wacom->pen_input;
Ping Cheng4750f5f2016-01-08 17:15:48 -0800773 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700774
Ping Cheng4750f5f2016-01-08 17:15:48 -0800775 if (!(((data[1] & 0xfc) == 0xc0) || /* in prox */
776 ((data[1] & 0xfe) == 0x20) || /* in range */
777 ((data[1] & 0xfe) == 0x80))) /* out prox */
778 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -0700779
780 /* Enter report */
781 if ((data[1] & 0xfc) == 0xc0) {
782 /* serial number of the tool */
783 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
784 (data[4] << 20) + (data[5] << 12) +
785 (data[6] << 4) + (data[7] >> 4);
786
Ping Cheng493630b2010-06-22 11:21:34 -0700787 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
Jason Gerecke82527da2016-10-19 18:03:47 -0700788 ((data[7] & 0x0f) << 16) | ((data[8] & 0xf0) << 8);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700789
Benjamin Tissoires7e129782016-02-12 17:27:40 +0100790 wacom->tool[idx] = wacom_intuos_get_tool_type(wacom->id[idx]);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -0700791
Ping Chengeff6ca92016-05-02 21:17:34 -0700792 wacom->shared->stylus_in_proximity = true;
Ping Cheng3bea7332006-07-13 18:01:36 -0700793 return 1;
794 }
795
Ping Chengc1b03f52016-01-08 17:16:06 -0800796 /* in Range */
797 if ((data[1] & 0xfe) == 0x20) {
Ping Cheng526d6e72016-01-08 17:16:25 -0800798 if (features->type != INTUOSHT2)
799 wacom->shared->stylus_in_proximity = true;
Ping Cheng486b9082015-02-20 14:25:58 -0800800
Ping Chengc1b03f52016-01-08 17:16:06 -0800801 /* in Range while exiting */
802 if (wacom->reporting_data) {
803 input_report_key(input, BTN_TOUCH, 0);
804 input_report_abs(input, ABS_PRESSURE, 0);
805 input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
806 return 2;
807 }
808 return 1;
Jason Gerecke4eb18302013-09-20 09:48:46 -0700809 }
810
Ping Cheng3bea7332006-07-13 18:01:36 -0700811 /* Exit report */
812 if ((data[1] & 0xfe) == 0x80) {
Ping Chengf3586d22015-03-20 14:57:00 -0700813 wacom->shared->stylus_in_proximity = false;
Ping Chengb3bd7ef2015-01-09 11:05:13 -0800814 wacom->reporting_data = false;
Jason Gereckeae584ca2012-04-03 15:50:40 -0700815
Ping Cheng373a5352015-01-09 11:04:50 -0800816 /* don't report exit if we don't know the ID */
817 if (!wacom->id[idx])
818 return 1;
819
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -0700820 wacom_exit_report(wacom);
Ping Cheng80d4e8e2007-02-23 12:22:48 -0800821 return 2;
Ping Cheng3bea7332006-07-13 18:01:36 -0700822 }
Ping Cheng373a5352015-01-09 11:04:50 -0800823
Ping Cheng3bea7332006-07-13 18:01:36 -0700824 return 0;
825}
826
Jason Gerecke9d339fe2021-07-19 13:55:33 -0700827static inline bool touch_is_muted(struct wacom_wac *wacom_wac)
828{
829 return wacom_wac->probe_complete &&
830 wacom_wac->shared->has_mute_touch_switch &&
831 !wacom_wac->shared->is_touch_on;
832}
833
Ping Cheng1924e052016-08-09 14:38:56 -0700834static inline bool report_touch_events(struct wacom_wac *wacom)
835{
836 return (touch_arbitration ? !wacom->shared->stylus_in_proximity : 1);
837}
838
839static inline bool delay_pen_events(struct wacom_wac *wacom)
840{
841 return (wacom->shared->touch_down && touch_arbitration);
Aaron Skomra72b236d2015-08-20 16:05:17 -0700842}
843
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800844static int wacom_intuos_general(struct wacom_wac *wacom)
Ping Cheng3bea7332006-07-13 18:01:36 -0700845{
Jason Childse33da8a2010-02-17 22:38:31 -0800846 struct wacom_features *features = &wacom->features;
Ping Cheng3bea7332006-07-13 18:01:36 -0700847 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -0700848 struct input_dev *input = wacom->pen_input;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800849 int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
Jason Gereckea8a09c82015-11-30 17:13:49 -0800850 unsigned char type = (data[1] >> 1) & 0x0F;
Jason Gerecke5f33f432015-11-30 17:13:51 -0800851 unsigned int x, y, distance, t;
Ping Cheng3bea7332006-07-13 18:01:36 -0700852
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800853 if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
854 data[0] != WACOM_REPORT_INTUOS_PEN)
855 return 0;
856
Ping Cheng1924e052016-08-09 14:38:56 -0700857 if (delay_pen_events(wacom))
Ping Chengc1b03f52016-01-08 17:16:06 -0800858 return 1;
859
Ping Cheng599b0822016-01-08 17:14:54 -0800860 /* don't report events if we don't know the tool ID */
861 if (!wacom->id[idx]) {
862 /* but reschedule a read of the current tool */
863 wacom_intuos_schedule_prox_event(wacom);
864 return 1;
865 }
866
Ping Cheng4750f5f2016-01-08 17:15:48 -0800867 /*
868 * don't report events for invalid data
869 */
870 /* older I4 styli don't work with new Cintiqs */
Jason Gerecke82527da2016-10-19 18:03:47 -0700871 if ((!((wacom->id[idx] >> 16) & 0x01) &&
Ping Cheng4750f5f2016-01-08 17:15:48 -0800872 (features->type == WACOM_21UX2)) ||
873 /* Only large Intuos support Lense Cursor */
874 (wacom->tool[idx] == BTN_TOOL_LENS &&
875 (features->type == INTUOS3 ||
876 features->type == INTUOS3S ||
877 features->type == INTUOS4 ||
878 features->type == INTUOS4S ||
879 features->type == INTUOS5 ||
880 features->type == INTUOS5S ||
881 features->type == INTUOSPM ||
882 features->type == INTUOSPS)) ||
883 /* Cintiq doesn't send data when RDY bit isn't set */
884 (features->type == CINTIQ && !(data[1] & 0x40)))
885 return 1;
886
Jason Gerecke5f33f432015-11-30 17:13:51 -0800887 x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
888 y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
889 distance = data[9] >> 2;
890 if (features->type < INTUOS3S) {
891 x >>= 1;
892 y >>= 1;
893 distance >>= 1;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800894 }
Jason Gereckeb72fb1d2019-08-07 14:11:55 -0700895 if (features->type == INTUOSHT2)
896 distance = features->distance_max - distance;
Jason Gerecke5f33f432015-11-30 17:13:51 -0800897 input_report_abs(input, ABS_X, x);
898 input_report_abs(input, ABS_Y, y);
899 input_report_abs(input, ABS_DISTANCE, distance);
Jason Gerecke16e0a6a2015-11-30 17:13:48 -0800900
Jason Gereckea8a09c82015-11-30 17:13:49 -0800901 switch (type) {
902 case 0x00:
903 case 0x01:
904 case 0x02:
905 case 0x03:
906 /* general pen packet */
Jason Gerecke5f33f432015-11-30 17:13:51 -0800907 t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
908 if (features->pressure_max < 2047)
909 t >>= 1;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700910 input_report_abs(input, ABS_PRESSURE, t);
Ping Chengeda01da2015-09-23 13:51:15 -0700911 if (features->type != INTUOSHT2) {
912 input_report_abs(input, ABS_TILT_X,
Jason Gereckeec5fc1c2014-11-18 16:50:08 -0800913 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
Ping Chengeda01da2015-09-23 13:51:15 -0700914 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
915 }
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700916 input_report_key(input, BTN_STYLUS, data[1] & 2);
917 input_report_key(input, BTN_STYLUS2, data[1] & 4);
918 input_report_key(input, BTN_TOUCH, t > 10);
Jason Gereckea8a09c82015-11-30 17:13:49 -0800919 break;
Ping Cheng3bea7332006-07-13 18:01:36 -0700920
Jason Gereckea8a09c82015-11-30 17:13:49 -0800921 case 0x0a:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800922 /* airbrush second packet */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700923 input_report_abs(input, ABS_WHEEL,
Ping Cheng3bea7332006-07-13 18:01:36 -0700924 (data[6] << 2) | ((data[7] >> 6) & 3));
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700925 input_report_abs(input, ABS_TILT_X,
Jason Gereckeec5fc1c2014-11-18 16:50:08 -0800926 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
927 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
Jason Gereckea8a09c82015-11-30 17:13:49 -0800928 break;
929
930 case 0x05:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800931 /* Rotation packet */
932 if (features->type >= INTUOS3S) {
933 /* I3 marker pen rotation */
934 t = (data[6] << 3) | ((data[7] >> 5) & 7);
935 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
936 ((t-1) / 2 + 450)) : (450 - t / 2) ;
937 input_report_abs(input, ABS_Z, t);
938 } else {
Jason Gerecke571f5722015-11-30 17:13:50 -0800939 /* 4D mouse 2nd packet */
Jason Gereckea8a09c82015-11-30 17:13:49 -0800940 t = (data[6] << 3) | ((data[7] >> 5) & 7);
941 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
942 ((t - 1) / 2) : -t / 2);
943 }
944 break;
Ping Cheng3bea7332006-07-13 18:01:36 -0700945
Jason Gereckea8a09c82015-11-30 17:13:49 -0800946 case 0x04:
Jason Gerecke571f5722015-11-30 17:13:50 -0800947 /* 4D mouse 1st packet */
948 input_report_key(input, BTN_LEFT, data[8] & 0x01);
949 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
950 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
951
952 input_report_key(input, BTN_SIDE, data[8] & 0x20);
953 input_report_key(input, BTN_EXTRA, data[8] & 0x10);
954 t = (data[6] << 2) | ((data[7] >> 6) & 3);
955 input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
956 break;
957
Jason Gereckea8a09c82015-11-30 17:13:49 -0800958 case 0x06:
Jason Gerecke571f5722015-11-30 17:13:50 -0800959 /* I4 mouse */
960 input_report_key(input, BTN_LEFT, data[6] & 0x01);
961 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
962 input_report_key(input, BTN_RIGHT, data[6] & 0x04);
963 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
964 - ((data[7] & 0x40) >> 6));
965 input_report_key(input, BTN_SIDE, data[6] & 0x08);
966 input_report_key(input, BTN_EXTRA, data[6] & 0x10);
967
968 input_report_abs(input, ABS_TILT_X,
969 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
970 input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
971 break;
972
Jason Gereckea8a09c82015-11-30 17:13:49 -0800973 case 0x08:
Jason Gerecke571f5722015-11-30 17:13:50 -0800974 if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
975 /* 2D mouse packet */
976 input_report_key(input, BTN_LEFT, data[8] & 0x04);
977 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
978 input_report_key(input, BTN_RIGHT, data[8] & 0x10);
979 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
980 - ((data[8] & 0x02) >> 1));
Ping Cheng3bea7332006-07-13 18:01:36 -0700981
Jason Gerecke571f5722015-11-30 17:13:50 -0800982 /* I3 2D mouse side buttons */
983 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
984 input_report_key(input, BTN_SIDE, data[8] & 0x40);
985 input_report_key(input, BTN_EXTRA, data[8] & 0x20);
Ping Cheng3bea7332006-07-13 18:01:36 -0700986 }
Jason Gereckea8a09c82015-11-30 17:13:49 -0800987 }
Jason Gerecke571f5722015-11-30 17:13:50 -0800988 else if (wacom->tool[idx] == BTN_TOOL_LENS) {
Ping Cheng3bea7332006-07-13 18:01:36 -0700989 /* Lens cursor packets */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -0700990 input_report_key(input, BTN_LEFT, data[8] & 0x01);
991 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
992 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
993 input_report_key(input, BTN_SIDE, data[8] & 0x10);
994 input_report_key(input, BTN_EXTRA, data[8] & 0x08);
Ping Cheng3bea7332006-07-13 18:01:36 -0700995 }
Jason Gereckea8a09c82015-11-30 17:13:49 -0800996 break;
997
Jason Gerecke571f5722015-11-30 17:13:50 -0800998 case 0x07:
Jason Gereckea8a09c82015-11-30 17:13:49 -0800999 case 0x09:
Jason Gerecke571f5722015-11-30 17:13:50 -08001000 case 0x0b:
Jason Gereckea8a09c82015-11-30 17:13:49 -08001001 case 0x0c:
1002 case 0x0d:
1003 case 0x0e:
1004 case 0x0f:
1005 /* unhandled */
1006 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07001007 }
Ping Cheng3bea7332006-07-13 18:01:36 -07001008
Jason Gerecke82527da2016-10-19 18:03:47 -07001009 input_report_abs(input, ABS_MISC,
1010 wacom_intuos_id_mangle(wacom->id[idx])); /* report tool id */
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07001011 input_report_key(input, wacom->tool[idx], 1);
1012 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
Ping Chengb3bd7ef2015-01-09 11:05:13 -08001013 wacom->reporting_data = true;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001014 return 2;
Ping Cheng3bea7332006-07-13 18:01:36 -07001015}
1016
1017static int wacom_intuos_irq(struct wacom_wac *wacom)
1018{
Ping Cheng3bea7332006-07-13 18:01:36 -07001019 unsigned char *data = wacom->data;
1020 struct input_dev *input = wacom->pen_input;
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001021 int result;
Ping Cheng3bea7332006-07-13 18:01:36 -07001022
1023 if (data[0] != WACOM_REPORT_PENABLED &&
Jason Gerecke06109992015-11-30 17:13:52 -08001024 data[0] != WACOM_REPORT_INTUOS_ID1 &&
1025 data[0] != WACOM_REPORT_INTUOS_ID2 &&
Ping Cheng3bea7332006-07-13 18:01:36 -07001026 data[0] != WACOM_REPORT_INTUOSPAD &&
1027 data[0] != WACOM_REPORT_INTUOS_PEN &&
1028 data[0] != WACOM_REPORT_CINTIQ &&
1029 data[0] != WACOM_REPORT_CINTIQPAD &&
1030 data[0] != WACOM_REPORT_INTUOS5PAD) {
1031 dev_dbg(input->dev.parent,
1032 "%s: received unknown report #%d\n", __func__, data[0]);
1033 return 0;
1034 }
1035
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001036 /* process pad events */
1037 result = wacom_intuos_pad(wacom);
1038 if (result)
1039 return result;
Ping Cheng3bea7332006-07-13 18:01:36 -07001040
1041 /* process in/out prox events */
1042 result = wacom_intuos_inout(wacom);
1043 if (result)
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001044 return result - 1;
Ping Cheng3bea7332006-07-13 18:01:36 -07001045
1046 /* process general packets */
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001047 result = wacom_intuos_general(wacom);
1048 if (result)
1049 return result - 1;
Ping Cheng3bea7332006-07-13 18:01:36 -07001050
Jason Gerecke16e0a6a2015-11-30 17:13:48 -08001051 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07001052}
1053
Jason Gerecke149f6f62017-03-31 10:02:05 -07001054static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
1055{
1056 unsigned char *data = wacom_wac->data;
1057 struct input_dev *input;
1058 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1059 struct wacom_remote *remote = wacom->remote;
1060 int bat_charging, bat_percent, touch_ring_mode;
1061 __u32 serial;
1062 int i, index = -1;
1063 unsigned long flags;
1064
1065 if (data[0] != WACOM_REPORT_REMOTE) {
1066 hid_dbg(wacom->hdev, "%s: received unknown report #%d",
1067 __func__, data[0]);
1068 return 0;
1069 }
1070
1071 serial = data[3] + (data[4] << 8) + (data[5] << 16);
1072 wacom_wac->id[0] = PAD_DEVICE_ID;
1073
1074 spin_lock_irqsave(&remote->remote_lock, flags);
1075
1076 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1077 if (remote->remotes[i].serial == serial) {
1078 index = i;
1079 break;
1080 }
1081 }
1082
1083 if (index < 0 || !remote->remotes[index].registered)
1084 goto out;
1085
1086 input = remote->remotes[index].input;
1087
1088 input_report_key(input, BTN_0, (data[9] & 0x01));
1089 input_report_key(input, BTN_1, (data[9] & 0x02));
1090 input_report_key(input, BTN_2, (data[9] & 0x04));
1091 input_report_key(input, BTN_3, (data[9] & 0x08));
1092 input_report_key(input, BTN_4, (data[9] & 0x10));
1093 input_report_key(input, BTN_5, (data[9] & 0x20));
1094 input_report_key(input, BTN_6, (data[9] & 0x40));
1095 input_report_key(input, BTN_7, (data[9] & 0x80));
1096
1097 input_report_key(input, BTN_8, (data[10] & 0x01));
1098 input_report_key(input, BTN_9, (data[10] & 0x02));
1099 input_report_key(input, BTN_A, (data[10] & 0x04));
1100 input_report_key(input, BTN_B, (data[10] & 0x08));
1101 input_report_key(input, BTN_C, (data[10] & 0x10));
1102 input_report_key(input, BTN_X, (data[10] & 0x20));
1103 input_report_key(input, BTN_Y, (data[10] & 0x40));
1104 input_report_key(input, BTN_Z, (data[10] & 0x80));
1105
1106 input_report_key(input, BTN_BASE, (data[11] & 0x01));
1107 input_report_key(input, BTN_BASE2, (data[11] & 0x02));
1108
1109 if (data[12] & 0x80)
Aaron Armstrong Skomrafcf887e2019-08-16 12:00:54 -07001110 input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f) - 1);
Jason Gerecke149f6f62017-03-31 10:02:05 -07001111 else
1112 input_report_abs(input, ABS_WHEEL, 0);
1113
1114 bat_percent = data[7] & 0x7f;
1115 bat_charging = !!(data[7] & 0x80);
1116
1117 if (data[9] | data[10] | (data[11] & 0x03) | data[12])
1118 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
1119 else
1120 input_report_abs(input, ABS_MISC, 0);
1121
1122 input_event(input, EV_MSC, MSC_SERIAL, serial);
1123
1124 input_sync(input);
1125
1126 /*Which mode select (LED light) is currently on?*/
1127 touch_ring_mode = (data[11] & 0xC0) >> 6;
1128
1129 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1130 if (remote->remotes[i].serial == serial)
1131 wacom->led.groups[i].select = touch_ring_mode;
1132 }
1133
Jason Gerecke16e45982017-04-28 09:25:33 -07001134 __wacom_notify_battery(&remote->remotes[index].battery,
1135 WACOM_POWER_SUPPLY_STATUS_AUTO, bat_percent,
Jason Gerecke149f6f62017-03-31 10:02:05 -07001136 bat_charging, 1, bat_charging);
1137
1138out:
1139 spin_unlock_irqrestore(&remote->remote_lock, flags);
1140 return 0;
1141}
1142
1143static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
1144{
1145 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1146 unsigned char *data = wacom_wac->data;
1147 struct wacom_remote *remote = wacom->remote;
1148 struct wacom_remote_data remote_data;
1149 unsigned long flags;
1150 int i, ret;
1151
1152 if (data[0] != WACOM_REPORT_DEVICE_LIST)
1153 return;
1154
1155 memset(&remote_data, 0, sizeof(struct wacom_remote_data));
1156
1157 for (i = 0; i < WACOM_MAX_REMOTES; i++) {
1158 int j = i * 6;
1159 int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
1160 bool connected = data[j+2];
1161
1162 remote_data.remote[i].serial = serial;
1163 remote_data.remote[i].connected = connected;
1164 }
1165
1166 spin_lock_irqsave(&remote->remote_lock, flags);
1167
1168 ret = kfifo_in(&remote->remote_fifo, &remote_data, sizeof(remote_data));
1169 if (ret != sizeof(remote_data)) {
1170 spin_unlock_irqrestore(&remote->remote_lock, flags);
1171 hid_err(wacom->hdev, "Can't queue Remote status event.\n");
1172 return;
1173 }
1174
1175 spin_unlock_irqrestore(&remote->remote_lock, flags);
1176
1177 wacom_schedule_work(wacom_wac, WACOM_WORKER_REMOTE);
1178}
1179
Jason Gereckeb1e42792012-10-21 00:38:04 -07001180static int int_dist(int x1, int y1, int x2, int y2)
1181{
1182 int x = x2 - x1;
1183 int y = y2 - y1;
1184
1185 return int_sqrt(x*x + y*y);
1186}
1187
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001188static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
1189 unsigned char *data)
1190{
1191 memcpy(wacom->data, data, 10);
1192 wacom_intuos_irq(wacom);
1193
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001194 input_sync(wacom->pen_input);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001195 if (wacom->pad_input)
1196 input_sync(wacom->pad_input);
1197}
1198
1199static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1200{
1201 unsigned char data[WACOM_PKGLEN_MAX];
1202 int i = 1;
1203 unsigned power_raw, battery_capacity, bat_charging, ps_connected;
1204
1205 memcpy(data, wacom->data, len);
1206
1207 switch (data[0]) {
1208 case 0x04:
1209 wacom_intuos_bt_process_data(wacom, data + i);
1210 i += 10;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001211 fallthrough;
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001212 case 0x03:
1213 wacom_intuos_bt_process_data(wacom, data + i);
1214 i += 10;
1215 wacom_intuos_bt_process_data(wacom, data + i);
1216 i += 10;
1217 power_raw = data[i];
1218 bat_charging = (power_raw & 0x08) ? 1 : 0;
1219 ps_connected = (power_raw & 0x10) ? 1 : 0;
1220 battery_capacity = batcap_i4[power_raw & 0x07];
Jason Gerecke16e45982017-04-28 09:25:33 -07001221 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1222 battery_capacity, bat_charging,
Jason Gerecke71fa6412015-03-11 10:25:41 -07001223 battery_capacity || bat_charging,
Jason Gerecke953f2c52015-03-06 11:47:39 -08001224 ps_connected);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001225 break;
1226 default:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001227 dev_dbg(wacom->pen_input->dev.parent,
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07001228 "Unknown report: %d,%d size:%zu\n",
1229 data[0], data[1], len);
1230 return 0;
1231 }
1232 return 0;
1233}
1234
Ping Cheng7d059ed2015-03-20 14:57:21 -07001235static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1236{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001237 struct input_dev *input = wacom->touch_input;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001238 unsigned touch_max = wacom->features.touch_max;
1239 int count = 0;
1240 int i;
1241
Ping Cheng26ba61f2015-05-19 17:42:02 -07001242 if (!touch_max)
1243 return 0;
1244
Jason Gerecke71b5c472015-04-15 17:22:32 -07001245 if (touch_max == 1)
1246 return test_bit(BTN_TOUCH, input->key) &&
Ping Cheng1924e052016-08-09 14:38:56 -07001247 report_touch_events(wacom);
Ping Cheng7d059ed2015-03-20 14:57:21 -07001248
1249 for (i = 0; i < input->mt->num_slots; i++) {
1250 struct input_mt_slot *ps = &input->mt->slots[i];
1251 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1252 if (id >= 0)
1253 count++;
1254 }
1255
1256 return count;
1257}
1258
Jason Gerecke4922cd22017-01-25 12:08:37 -08001259static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1260{
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001261 int pen_frame_len, pen_frames;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001262
1263 struct input_dev *pen_input = wacom->pen_input;
1264 unsigned char *data = wacom->data;
1265 int i;
1266
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07001267 if (wacom->features.type == INTUOSP2_BT ||
1268 wacom->features.type == INTUOSP2S_BT) {
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001269 wacom->serial[0] = get_unaligned_le64(&data[99]);
1270 wacom->id[0] = get_unaligned_le16(&data[107]);
1271 pen_frame_len = 14;
1272 pen_frames = 7;
1273 } else {
1274 wacom->serial[0] = get_unaligned_le64(&data[33]);
1275 wacom->id[0] = get_unaligned_le16(&data[41]);
1276 pen_frame_len = 8;
1277 pen_frames = 4;
1278 }
1279
Jason Gerecke4922cd22017-01-25 12:08:37 -08001280 if (wacom->serial[0] >> 52 == 1) {
1281 /* Add back in missing bits of ID for non-USI pens */
1282 wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
1283 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08001284
1285 for (i = 0; i < pen_frames; i++) {
1286 unsigned char *frame = &data[i*pen_frame_len + 1];
Jason Gereckea48324d2017-02-10 16:14:07 -08001287 bool valid = frame[0] & 0x80;
1288 bool prox = frame[0] & 0x40;
1289 bool range = frame[0] & 0x20;
Jason Gerecke2cc08802019-04-24 15:12:57 -07001290 bool invert = frame[0] & 0x10;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001291
Jason Gereckea48324d2017-02-10 16:14:07 -08001292 if (!valid)
Jason Gerecke4922cd22017-01-25 12:08:37 -08001293 continue;
1294
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -07001295 if (!prox) {
1296 wacom->shared->stylus_in_proximity = false;
1297 wacom_exit_report(wacom);
1298 input_sync(pen_input);
Jason Gerecke2cc08802019-04-24 15:12:57 -07001299
1300 wacom->tool[0] = 0;
1301 wacom->id[0] = 0;
1302 wacom->serial[0] = 0;
Aaron Armstrong Skomra619d3a22018-04-04 14:24:11 -07001303 return;
1304 }
Jason Gerecke2cc08802019-04-24 15:12:57 -07001305
Jason Gereckea48324d2017-02-10 16:14:07 -08001306 if (range) {
Jason Gerecke2cc08802019-04-24 15:12:57 -07001307 if (!wacom->tool[0]) { /* first in range */
1308 /* Going into range select tool */
1309 if (invert)
1310 wacom->tool[0] = BTN_TOOL_RUBBER;
1311 else if (wacom->id[0])
1312 wacom->tool[0] = wacom_intuos_get_tool_type(wacom->id[0]);
1313 else
1314 wacom->tool[0] = BTN_TOOL_PEN;
1315 }
1316
Jason Gereckea48324d2017-02-10 16:14:07 -08001317 input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
1318 input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001319
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07001320 if (wacom->features.type == INTUOSP2_BT ||
1321 wacom->features.type == INTUOSP2S_BT) {
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001322 /* Fix rotation alignment: userspace expects zero at left */
1323 int16_t rotation =
1324 (int16_t)get_unaligned_le16(&frame[9]);
1325 rotation += 1800/4;
1326
1327 if (rotation > 899)
1328 rotation -= 1800;
1329
1330 input_report_abs(pen_input, ABS_TILT_X,
1331 (char)frame[7]);
1332 input_report_abs(pen_input, ABS_TILT_Y,
1333 (char)frame[8]);
1334 input_report_abs(pen_input, ABS_Z, rotation);
1335 input_report_abs(pen_input, ABS_WHEEL,
1336 get_unaligned_le16(&frame[11]));
1337 }
Jason Gereckea48324d2017-02-10 16:14:07 -08001338 }
Jason Gereckee92a7be2019-04-24 15:12:58 -07001339 if (wacom->tool[0]) {
1340 input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
Aaron Armstrong Skomra7cdf6e42019-08-12 11:55:52 -07001341 if (wacom->features.type == INTUOSP2_BT ||
1342 wacom->features.type == INTUOSP2S_BT) {
Jason Gereckee92a7be2019-04-24 15:12:58 -07001343 input_report_abs(pen_input, ABS_DISTANCE,
1344 range ? frame[13] : wacom->features.distance_max);
1345 } else {
1346 input_report_abs(pen_input, ABS_DISTANCE,
1347 range ? frame[7] : wacom->features.distance_max);
1348 }
1349
Jason Gereckefe7f8d72019-05-07 11:53:20 -07001350 input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x09);
Jason Gereckee92a7be2019-04-24 15:12:58 -07001351 input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02);
1352 input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04);
1353
1354 input_report_key(pen_input, wacom->tool[0], prox);
1355 input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]);
1356 input_report_abs(pen_input, ABS_MISC,
1357 wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001358 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08001359
Jason Gereckea48324d2017-02-10 16:14:07 -08001360 wacom->shared->stylus_in_proximity = prox;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001361
1362 input_sync(pen_input);
1363 }
1364}
1365
1366static void wacom_intuos_pro2_bt_touch(struct wacom_wac *wacom)
1367{
1368 const int finger_touch_len = 8;
1369 const int finger_frames = 4;
1370 const int finger_frame_len = 43;
1371
1372 struct input_dev *touch_input = wacom->touch_input;
1373 unsigned char *data = wacom->data;
1374 int num_contacts_left = 5;
1375 int i, j;
1376
1377 for (i = 0; i < finger_frames; i++) {
1378 unsigned char *frame = &data[i*finger_frame_len + 109];
1379 int current_num_contacts = frame[0] & 0x7F;
1380 int contacts_to_send;
1381
1382 if (!(frame[0] & 0x80))
1383 continue;
1384
1385 /*
1386 * First packet resets the counter since only the first
1387 * packet in series will have non-zero current_num_contacts.
1388 */
1389 if (current_num_contacts)
1390 wacom->num_contacts_left = current_num_contacts;
1391
1392 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1393
1394 for (j = 0; j < contacts_to_send; j++) {
1395 unsigned char *touch = &frame[j*finger_touch_len + 1];
1396 int slot = input_mt_get_slot_by_key(touch_input, touch[0]);
1397 int x = get_unaligned_le16(&touch[2]);
1398 int y = get_unaligned_le16(&touch[4]);
1399 int w = touch[6] * input_abs_get_res(touch_input, ABS_MT_POSITION_X);
1400 int h = touch[7] * input_abs_get_res(touch_input, ABS_MT_POSITION_Y);
1401
1402 if (slot < 0)
1403 continue;
1404
1405 input_mt_slot(touch_input, slot);
1406 input_mt_report_slot_state(touch_input, MT_TOOL_FINGER, touch[1] & 0x01);
1407 input_report_abs(touch_input, ABS_MT_POSITION_X, x);
1408 input_report_abs(touch_input, ABS_MT_POSITION_Y, y);
1409 input_report_abs(touch_input, ABS_MT_TOUCH_MAJOR, max(w, h));
1410 input_report_abs(touch_input, ABS_MT_TOUCH_MINOR, min(w, h));
1411 input_report_abs(touch_input, ABS_MT_ORIENTATION, w > h);
1412 }
1413
1414 input_mt_sync_frame(touch_input);
1415
1416 wacom->num_contacts_left -= contacts_to_send;
1417 if (wacom->num_contacts_left <= 0) {
1418 wacom->num_contacts_left = 0;
1419 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Jason Gerecke69dbdff2019-05-07 11:53:22 -07001420 input_sync(touch_input);
Jason Gerecke4922cd22017-01-25 12:08:37 -08001421 }
1422 }
1423
Jason Gerecke69dbdff2019-05-07 11:53:22 -07001424 if (wacom->num_contacts_left == 0) {
1425 // Be careful that we don't accidentally call input_sync with
1426 // only a partial set of fingers of processed
1427 input_report_switch(touch_input, SW_MUTE_DEVICE, !(data[281] >> 7));
1428 input_sync(touch_input);
1429 }
1430
Jason Gerecke4922cd22017-01-25 12:08:37 -08001431}
1432
1433static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
1434{
1435 struct input_dev *pad_input = wacom->pad_input;
1436 unsigned char *data = wacom->data;
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001437 int nbuttons = wacom->features.numbered_buttons;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001438
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001439 int expresskeys = data[282];
1440 int center = (data[281] & 0x40) >> 6;
Jason Gerecked252f4a2017-08-30 15:13:26 -07001441 int ring = data[285] & 0x7F;
1442 bool ringstatus = data[285] & 0x80;
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001443 bool prox = expresskeys || center || ringstatus;
Jason Gerecked252f4a2017-08-30 15:13:26 -07001444
1445 /* Fix touchring data: userspace expects 0 at left and increasing clockwise */
1446 ring = 71 - ring;
1447 ring += 3*72/16;
1448 if (ring > 71)
1449 ring -= 72;
Jason Gerecke4922cd22017-01-25 12:08:37 -08001450
Jason Gereckedcce8ef2020-04-24 14:04:00 -07001451 wacom_report_numbered_buttons(pad_input, nbuttons,
1452 expresskeys | (center << (nbuttons - 1)));
Jason Gerecke4922cd22017-01-25 12:08:37 -08001453
Jason Gerecked252f4a2017-08-30 15:13:26 -07001454 input_report_abs(pad_input, ABS_WHEEL, ringstatus ? ring : 0);
Jason Gerecke4922cd22017-01-25 12:08:37 -08001455
1456 input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
1457 input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
1458 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1459
1460 input_sync(pad_input);
1461}
1462
1463static void wacom_intuos_pro2_bt_battery(struct wacom_wac *wacom)
1464{
1465 unsigned char *data = wacom->data;
1466
1467 bool chg = data[284] & 0x80;
1468 int battery_status = data[284] & 0x7F;
1469
Jason Gerecke16e45982017-04-28 09:25:33 -07001470 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1471 battery_status, chg, 1, chg);
Jason Gerecke4922cd22017-01-25 12:08:37 -08001472}
1473
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001474static void wacom_intuos_gen3_bt_pad(struct wacom_wac *wacom)
1475{
1476 struct input_dev *pad_input = wacom->pad_input;
1477 unsigned char *data = wacom->data;
1478
1479 int buttons = data[44];
1480
1481 wacom_report_numbered_buttons(pad_input, 4, buttons);
1482
1483 input_report_key(pad_input, wacom->tool[1], buttons ? 1 : 0);
1484 input_report_abs(pad_input, ABS_MISC, buttons ? PAD_DEVICE_ID : 0);
1485 input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
1486
1487 input_sync(pad_input);
1488}
1489
1490static void wacom_intuos_gen3_bt_battery(struct wacom_wac *wacom)
1491{
1492 unsigned char *data = wacom->data;
1493
1494 bool chg = data[45] & 0x80;
1495 int battery_status = data[45] & 0x7F;
1496
1497 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
1498 battery_status, chg, 1, chg);
1499}
1500
Jason Gerecke4922cd22017-01-25 12:08:37 -08001501static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
1502{
1503 unsigned char *data = wacom->data;
1504
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001505 if (data[0] != 0x80 && data[0] != 0x81) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08001506 dev_dbg(wacom->pen_input->dev.parent,
1507 "%s: received unknown report #%d\n", __func__, data[0]);
1508 return 0;
1509 }
1510
1511 wacom_intuos_pro2_bt_pen(wacom);
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07001512 if (wacom->features.type == INTUOSP2_BT ||
1513 wacom->features.type == INTUOSP2S_BT) {
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08001514 wacom_intuos_pro2_bt_touch(wacom);
1515 wacom_intuos_pro2_bt_pad(wacom);
1516 wacom_intuos_pro2_bt_battery(wacom);
1517 } else {
1518 wacom_intuos_gen3_bt_pad(wacom);
1519 wacom_intuos_gen3_bt_battery(wacom);
1520 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08001521 return 0;
1522}
1523
Jason Gereckeb1e42792012-10-21 00:38:04 -07001524static int wacom_24hdt_irq(struct wacom_wac *wacom)
1525{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001526 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001527 unsigned char *data = wacom->data;
Jason Gereckeb1e42792012-10-21 00:38:04 -07001528 int i;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001529 int current_num_contacts = data[61];
Jason Gereckeb1e42792012-10-21 00:38:04 -07001530 int contacts_to_send = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001531 int num_contacts_left = 4; /* maximum contacts per packet */
1532 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1533 int y_offset = 2;
1534
Jason Gerecke9d339fe2021-07-19 13:55:33 -07001535 if (touch_is_muted(wacom) && !wacom->shared->touch_down)
1536 return 0;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07001537
Ping Cheng500d4162015-01-27 13:30:03 -08001538 if (wacom->features.type == WACOM_27QHDT) {
1539 current_num_contacts = data[63];
1540 num_contacts_left = 10;
1541 byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
1542 y_offset = 0;
Ping Cheng500d4162015-01-27 13:30:03 -08001543 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001544
1545 /*
1546 * First packet resets the counter since only the first
1547 * packet in series will have non-zero current_num_contacts.
1548 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001549 if (current_num_contacts)
Jason Gereckeb1e42792012-10-21 00:38:04 -07001550 wacom->num_contacts_left = current_num_contacts;
1551
Ping Cheng500d4162015-01-27 13:30:03 -08001552 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001553
1554 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng500d4162015-01-27 13:30:03 -08001555 int offset = (byte_per_packet * i) + 1;
Ping Cheng1924e052016-08-09 14:38:56 -07001556 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Ping Cheng02295e62013-01-04 23:56:00 -08001557 int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001558
1559 if (slot < 0)
1560 continue;
1561 input_mt_slot(input, slot);
1562 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1563
1564 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001565 int t_x = get_unaligned_le16(&data[offset + 2]);
Ping Cheng500d4162015-01-27 13:30:03 -08001566 int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001567
1568 input_report_abs(input, ABS_MT_POSITION_X, t_x);
1569 input_report_abs(input, ABS_MT_POSITION_Y, t_y);
Ping Cheng500d4162015-01-27 13:30:03 -08001570
1571 if (wacom->features.type != WACOM_27QHDT) {
1572 int c_x = get_unaligned_le16(&data[offset + 4]);
1573 int c_y = get_unaligned_le16(&data[offset + 8]);
1574 int w = get_unaligned_le16(&data[offset + 10]);
1575 int h = get_unaligned_le16(&data[offset + 12]);
1576
1577 input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
1578 input_report_abs(input, ABS_MT_WIDTH_MAJOR,
1579 min(w, h) + int_dist(t_x, t_y, c_x, c_y));
1580 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1581 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1582 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001583 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001584 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001585 input_mt_sync_frame(input);
Jason Gereckeb1e42792012-10-21 00:38:04 -07001586
1587 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001588 if (wacom->num_contacts_left <= 0) {
Jason Gereckeb1e42792012-10-21 00:38:04 -07001589 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001590 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001591 }
Jason Gereckeb1e42792012-10-21 00:38:04 -07001592 return 1;
1593}
1594
Ping Cheng19635182012-04-29 21:09:18 -07001595static int wacom_mt_touch(struct wacom_wac *wacom)
1596{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001597 struct input_dev *input = wacom->touch_input;
Jason Gerecke74b63412014-04-19 13:50:22 -07001598 unsigned char *data = wacom->data;
Ping Cheng19635182012-04-29 21:09:18 -07001599 int i;
1600 int current_num_contacts = data[2];
1601 int contacts_to_send = 0;
Ping Cheng6afdc282012-11-03 12:16:15 -07001602 int x_offset = 0;
1603
1604 /* MTTPC does not support Height and Width */
Jason Gerecked51ddb22014-05-14 17:14:29 -07001605 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
Ping Cheng6afdc282012-11-03 12:16:15 -07001606 x_offset = -4;
Ping Cheng19635182012-04-29 21:09:18 -07001607
1608 /*
1609 * First packet resets the counter since only the first
1610 * packet in series will have non-zero current_num_contacts.
1611 */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001612 if (current_num_contacts)
Ping Cheng19635182012-04-29 21:09:18 -07001613 wacom->num_contacts_left = current_num_contacts;
1614
1615 /* There are at most 5 contacts per packet */
1616 contacts_to_send = min(5, wacom->num_contacts_left);
1617
1618 for (i = 0; i < contacts_to_send; i++) {
Ping Cheng6afdc282012-11-03 12:16:15 -07001619 int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
Ping Cheng1924e052016-08-09 14:38:56 -07001620 bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001621 int id = get_unaligned_le16(&data[offset + 1]);
Ping Cheng02295e62013-01-04 23:56:00 -08001622 int slot = input_mt_get_slot_by_key(input, id);
Ping Cheng19635182012-04-29 21:09:18 -07001623
1624 if (slot < 0)
1625 continue;
1626
1627 input_mt_slot(input, slot);
1628 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1629 if (touch) {
Jason Gereckeedc8e20a2014-05-14 16:53:30 -07001630 int x = get_unaligned_le16(&data[offset + x_offset + 7]);
1631 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
Ping Cheng19635182012-04-29 21:09:18 -07001632 input_report_abs(input, ABS_MT_POSITION_X, x);
1633 input_report_abs(input, ABS_MT_POSITION_Y, y);
1634 }
Ping Cheng19635182012-04-29 21:09:18 -07001635 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001636 input_mt_sync_frame(input);
Ping Cheng19635182012-04-29 21:09:18 -07001637
1638 wacom->num_contacts_left -= contacts_to_send;
Ping Chenge0d41fd2015-02-20 14:27:30 -08001639 if (wacom->num_contacts_left <= 0) {
Ping Cheng19635182012-04-29 21:09:18 -07001640 wacom->num_contacts_left = 0;
Ping Cheng7d059ed2015-03-20 14:57:21 -07001641 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Chenge0d41fd2015-02-20 14:27:30 -08001642 }
Ping Cheng19635182012-04-29 21:09:18 -07001643 return 1;
1644}
1645
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001646static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1647{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001648 struct input_dev *input = wacom->touch_input;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001649 unsigned char *data = wacom->data;
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001650 int i;
1651
1652 for (i = 0; i < 2; i++) {
1653 int p = data[1] & (1 << i);
Ping Cheng1924e052016-08-09 14:38:56 -07001654 bool touch = p && report_touch_events(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001655
1656 input_mt_slot(input, i);
1657 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
1658 if (touch) {
1659 int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
1660 int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
1661
1662 input_report_abs(input, ABS_MT_POSITION_X, x);
1663 input_report_abs(input, ABS_MT_POSITION_Y, y);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001664 }
1665 }
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05001666 input_mt_sync_frame(input);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001667
1668 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07001669 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001670
Ping Cheng84eb5aa2011-03-12 20:35:18 -08001671 return 1;
1672}
1673
Ping Chenga43c7c52011-03-12 20:34:42 -08001674static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
Ping Chengec67bbe2009-12-15 00:35:24 -08001675{
Jason Gerecke74b63412014-04-19 13:50:22 -07001676 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001677 struct input_dev *input = wacom->touch_input;
Ping Cheng1924e052016-08-09 14:38:56 -07001678 bool prox = report_touch_events(wacom);
Ping Chenga43c7c52011-03-12 20:34:42 -08001679 int x = 0, y = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -08001680
Ping Cheng19635182012-04-29 21:09:18 -07001681 if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
1682 return 0;
1683
Ping Chenge0d41fd2015-02-20 14:27:30 -08001684 if (len == WACOM_PKGLEN_TPC1FG) {
1685 prox = prox && (data[0] & 0x01);
1686 x = get_unaligned_le16(&data[1]);
1687 y = get_unaligned_le16(&data[3]);
1688 } else if (len == WACOM_PKGLEN_TPC1FG_B) {
1689 prox = prox && (data[2] & 0x01);
1690 x = get_unaligned_le16(&data[3]);
1691 y = get_unaligned_le16(&data[5]);
1692 } else {
1693 prox = prox && (data[1] & 0x01);
1694 x = le16_to_cpup((__le16 *)&data[2]);
1695 y = le16_to_cpup((__le16 *)&data[4]);
1696 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001697
1698 if (prox) {
1699 input_report_abs(input, ABS_X, x);
1700 input_report_abs(input, ABS_Y, y);
Ping Chengec67bbe2009-12-15 00:35:24 -08001701 }
Ping Chenga43c7c52011-03-12 20:34:42 -08001702 input_report_key(input, BTN_TOUCH, prox);
1703
1704 /* keep touch state for pen events */
1705 wacom->shared->touch_down = prox;
1706
1707 return 1;
Ping Chengec67bbe2009-12-15 00:35:24 -08001708}
1709
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001710static int wacom_tpc_pen(struct wacom_wac *wacom)
Ping Cheng545f4e92008-11-24 11:44:27 -05001711{
Jason Gerecke74b63412014-04-19 13:50:22 -07001712 unsigned char *data = wacom->data;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001713 struct input_dev *input = wacom->pen_input;
Ping Chenga43c7c52011-03-12 20:34:42 -08001714 bool prox = data[1] & 0x20;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001715
Ping Chenga43c7c52011-03-12 20:34:42 -08001716 if (!wacom->shared->stylus_in_proximity) /* first in prox */
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001717 /* Going into proximity select tool */
1718 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001719
Ping Chenga43c7c52011-03-12 20:34:42 -08001720 /* keep pen state for touch events */
1721 wacom->shared->stylus_in_proximity = prox;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001722
Ping Cheng1924e052016-08-09 14:38:56 -07001723 /* send pen events only when touch is up or forced out
1724 * or touch arbitration is off
1725 */
1726 if (!delay_pen_events(wacom)) {
Ping Chenga43c7c52011-03-12 20:34:42 -08001727 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
1728 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
1729 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
1730 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
Jason Gerecke0b335ca2014-07-24 13:15:31 -07001731 input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
Ping Chenga43c7c52011-03-12 20:34:42 -08001732 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
1733 input_report_key(input, wacom->tool[0], prox);
1734 return 1;
1735 }
1736
1737 return 0;
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001738}
1739
1740static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
1741{
Jason Gerecke74b63412014-04-19 13:50:22 -07001742 unsigned char *data = wacom->data;
Ping Cheng545f4e92008-11-24 11:44:27 -05001743
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001744 if (wacom->pen_input) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001745 dev_dbg(wacom->pen_input->dev.parent,
1746 "%s: received report #%d\n", __func__, data[0]);
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001747
1748 if (len == WACOM_PKGLEN_PENABLED ||
1749 data[0] == WACOM_REPORT_PENABLED)
1750 return wacom_tpc_pen(wacom);
1751 }
1752 else if (wacom->touch_input) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001753 dev_dbg(wacom->touch_input->dev.parent,
1754 "%s: received report #%d\n", __func__, data[0]);
Ping Cheng545f4e92008-11-24 11:44:27 -05001755
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001756 switch (len) {
1757 case WACOM_PKGLEN_TPC1FG:
Ping Cheng31175a82012-01-31 00:07:33 -08001758 return wacom_tpc_single_touch(wacom, len);
1759
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001760 case WACOM_PKGLEN_TPC2FG:
1761 return wacom_tpc_mt_touch(wacom);
Ping Cheng19635182012-04-29 21:09:18 -07001762
Jason Gerecke2ac97f02017-04-25 11:29:56 -07001763 default:
1764 switch (data[0]) {
1765 case WACOM_REPORT_TPC1FG:
1766 case WACOM_REPORT_TPCHID:
1767 case WACOM_REPORT_TPCST:
1768 case WACOM_REPORT_TPC1FGE:
1769 return wacom_tpc_single_touch(wacom, len);
1770
1771 case WACOM_REPORT_TPCMT:
1772 case WACOM_REPORT_TPCMT2:
1773 return wacom_mt_touch(wacom);
1774
1775 }
Ping Cheng31175a82012-01-31 00:07:33 -08001776 }
1777 }
Ping Cheng545f4e92008-11-24 11:44:27 -05001778
Ping Cheng8aa9a9a2011-03-12 20:34:11 -08001779 return 0;
Ping Cheng545f4e92008-11-24 11:44:27 -05001780}
1781
Jason Gerecked252f4a2017-08-30 15:13:26 -07001782static int wacom_offset_rotation(struct input_dev *input, struct hid_usage *usage,
1783 int value, int num, int denom)
1784{
1785 struct input_absinfo *abs = &input->absinfo[usage->code];
1786 int range = (abs->maximum - abs->minimum + 1);
1787
1788 value += num*range/denom;
1789 if (value > abs->maximum)
1790 value -= range;
1791 else if (value < abs->minimum)
1792 value += range;
1793 return value;
1794}
1795
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08001796int wacom_equivalent_usage(int usage)
Jason Gereckec9c09582016-10-19 18:03:43 -07001797{
1798 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
1799 int subpage = (usage & 0xFF00) << 8;
1800 int subusage = (usage & 0xFF);
1801
Jason Gerecke5922e612016-10-19 18:03:51 -07001802 if (subpage == WACOM_HID_SP_PAD ||
1803 subpage == WACOM_HID_SP_BUTTON ||
1804 subpage == WACOM_HID_SP_DIGITIZER ||
Jason Gereckeb5c921e2016-10-19 18:03:44 -07001805 subpage == WACOM_HID_SP_DIGITIZERINFO ||
Jason Gerecke61ce3462016-10-19 18:03:46 -07001806 usage == WACOM_HID_WD_SENSE ||
Jason Gereckef85c9dc2016-10-19 18:03:48 -07001807 usage == WACOM_HID_WD_SERIALHI ||
1808 usage == WACOM_HID_WD_TOOLTYPE ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001809 usage == WACOM_HID_WD_DISTANCE ||
Jason Gereckebf78adc2016-10-19 18:03:53 -07001810 usage == WACOM_HID_WD_TOUCHSTRIP ||
1811 usage == WACOM_HID_WD_TOUCHSTRIP2 ||
Jason Gerecke5922e612016-10-19 18:03:51 -07001812 usage == WACOM_HID_WD_TOUCHRING ||
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08001813 usage == WACOM_HID_WD_TOUCHRINGSTATUS ||
1814 usage == WACOM_HID_WD_REPORT_VALID) {
Jason Gereckec9c09582016-10-19 18:03:43 -07001815 return usage;
1816 }
1817
1818 if (subpage == HID_UP_UNDEFINED)
1819 subpage = HID_UP_DIGITIZER;
1820
1821 return subpage | subusage;
1822 }
1823
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08001824 if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMTOUCH) {
1825 int subpage = (usage & 0xFF00) << 8;
1826 int subusage = (usage & 0xFF);
1827
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07001828 if (usage == WACOM_HID_WT_REPORT_VALID)
1829 return usage;
1830
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08001831 if (subpage == HID_UP_UNDEFINED)
1832 subpage = WACOM_HID_SP_DIGITIZER;
1833
1834 return subpage | subusage;
1835 }
1836
Jason Gereckec9c09582016-10-19 18:03:43 -07001837 return usage;
1838}
1839
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07001840static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001841 struct hid_field *field, __u8 type, __u16 code, int fuzz)
1842{
Jason Gerecke345857b2016-10-19 18:03:50 -07001843 struct wacom *wacom = input_get_drvdata(input);
1844 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1845 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001846 int fmin = field->logical_minimum;
1847 int fmax = field->logical_maximum;
Jason Gereckec9c09582016-10-19 18:03:43 -07001848 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
Jason Gerecke50066a02016-10-19 18:03:42 -07001849 int resolution_code = code;
1850
Jason Gereckec9c09582016-10-19 18:03:43 -07001851 if (equivalent_usage == HID_DG_TWIST) {
Jason Gerecke50066a02016-10-19 18:03:42 -07001852 resolution_code = ABS_RZ;
1853 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001854
Jason Gerecke345857b2016-10-19 18:03:50 -07001855 if (equivalent_usage == HID_GD_X) {
1856 fmin += features->offset_left;
1857 fmax -= features->offset_right;
1858 }
1859 if (equivalent_usage == HID_GD_Y) {
1860 fmin += features->offset_top;
1861 fmax -= features->offset_bottom;
1862 }
1863
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001864 usage->type = type;
1865 usage->code = code;
1866
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001867 switch (type) {
1868 case EV_ABS:
1869 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
1870 input_abs_set_res(input, code,
Jason Gerecke50066a02016-10-19 18:03:42 -07001871 hidinput_calc_abs_res(field, resolution_code));
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001872 break;
1873 case EV_KEY:
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001874 case EV_MSC:
Jason Gereckebf78adc2016-10-19 18:03:53 -07001875 case EV_SW:
Ping Cheng46fc4662021-04-05 20:46:34 -07001876 input_set_capability(input, type, code);
Jason Gereckebf78adc2016-10-19 18:03:53 -07001877 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001878 }
1879}
1880
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07001881static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
1882 struct hid_field *field, struct hid_usage *usage)
1883{
1884 struct wacom *wacom = hid_get_drvdata(hdev);
1885 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1886 struct wacom_features *features = &wacom_wac->features;
1887 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1888
1889 switch (equivalent_usage) {
1890 case HID_DG_BATTERYSTRENGTH:
1891 case WACOM_HID_WD_BATTERY_LEVEL:
1892 case WACOM_HID_WD_BATTERY_CHARGING:
1893 features->quirks |= WACOM_QUIRK_BATTERY;
1894 break;
1895 }
1896}
1897
1898static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
1899 struct hid_usage *usage, __s32 value)
1900{
1901 struct wacom *wacom = hid_get_drvdata(hdev);
1902 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1903 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1904
1905 switch (equivalent_usage) {
1906 case HID_DG_BATTERYSTRENGTH:
1907 if (value == 0) {
1908 wacom_wac->hid_data.bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
1909 }
1910 else {
1911 value = value * 100 / (field->logical_maximum - field->logical_minimum);
1912 wacom_wac->hid_data.battery_capacity = value;
1913 wacom_wac->hid_data.bat_connected = 1;
1914 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1915 }
1916 break;
1917 case WACOM_HID_WD_BATTERY_LEVEL:
1918 value = value * 100 / (field->logical_maximum - field->logical_minimum);
1919 wacom_wac->hid_data.battery_capacity = value;
1920 wacom_wac->hid_data.bat_connected = 1;
1921 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1922 break;
1923 case WACOM_HID_WD_BATTERY_CHARGING:
1924 wacom_wac->hid_data.bat_charging = value;
1925 wacom_wac->hid_data.ps_connected = value;
1926 wacom_wac->hid_data.bat_connected = 1;
1927 wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
1928 break;
1929 }
1930}
1931
1932static void wacom_wac_battery_pre_report(struct hid_device *hdev,
1933 struct hid_report *report)
1934{
1935 return;
1936}
1937
1938static void wacom_wac_battery_report(struct hid_device *hdev,
1939 struct hid_report *report)
1940{
1941 struct wacom *wacom = hid_get_drvdata(hdev);
1942 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1943 struct wacom_features *features = &wacom_wac->features;
1944
1945 if (features->quirks & WACOM_QUIRK_BATTERY) {
1946 int status = wacom_wac->hid_data.bat_status;
1947 int capacity = wacom_wac->hid_data.battery_capacity;
1948 bool charging = wacom_wac->hid_data.bat_charging;
1949 bool connected = wacom_wac->hid_data.bat_connected;
1950 bool powered = wacom_wac->hid_data.ps_connected;
1951
1952 wacom_notify_battery(wacom_wac, status, capacity, charging,
1953 connected, powered);
1954 }
1955}
1956
Jason Gerecke5922e612016-10-19 18:03:51 -07001957static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
1958 struct hid_field *field, struct hid_usage *usage)
1959{
1960 struct wacom *wacom = hid_get_drvdata(hdev);
1961 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1962 struct wacom_features *features = &wacom_wac->features;
1963 struct input_dev *input = wacom_wac->pad_input;
1964 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
1965
1966 switch (equivalent_usage) {
1967 case WACOM_HID_WD_ACCELEROMETER_X:
1968 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1969 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001970 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001971 break;
1972 case WACOM_HID_WD_ACCELEROMETER_Y:
1973 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1974 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001975 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001976 break;
1977 case WACOM_HID_WD_ACCELEROMETER_Z:
1978 __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
1979 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08001980 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001981 break;
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08001982 case WACOM_HID_WD_BUTTONCENTER:
Jason Gerecke5922e612016-10-19 18:03:51 -07001983 case WACOM_HID_WD_BUTTONHOME:
1984 case WACOM_HID_WD_BUTTONUP:
1985 case WACOM_HID_WD_BUTTONDOWN:
1986 case WACOM_HID_WD_BUTTONLEFT:
1987 case WACOM_HID_WD_BUTTONRIGHT:
1988 wacom_map_usage(input, usage, field, EV_KEY,
1989 wacom_numbered_button_to_key(features->numbered_buttons),
1990 0);
1991 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08001992 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07001993 break;
Ping Chengd793ff82017-02-14 21:27:45 -08001994 case WACOM_HID_WD_MUTE_DEVICE:
Ping Chengdc9dc862021-07-19 13:55:29 -07001995 /* softkey touch switch */
1996 wacom_wac->is_soft_touch_switch = true;
1997 fallthrough;
1998 case WACOM_HID_WD_TOUCHONOFF:
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08001999 /*
Ping Chengdc9dc862021-07-19 13:55:29 -07002000 * These two usages, which are used to mute touch events, come
2001 * from the pad packet, but are reported on the touch
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002002 * interface. Because the touch interface may not have
2003 * been created yet, we cannot call wacom_map_usage(). In
Ping Chengdc9dc862021-07-19 13:55:29 -07002004 * order to process the usages when we receive them, we set
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002005 * the usage type and code directly.
2006 */
2007 wacom_wac->has_mute_touch_switch = true;
2008 usage->type = EV_SW;
2009 usage->code = SW_MUTE_DEVICE;
Ping Chengf3f24e72016-12-08 22:05:44 -08002010 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07002011 break;
2012 case WACOM_HID_WD_TOUCHSTRIP:
2013 wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08002014 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07002015 break;
2016 case WACOM_HID_WD_TOUCHSTRIP2:
2017 wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08002018 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gereckebf78adc2016-10-19 18:03:53 -07002019 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07002020 case WACOM_HID_WD_TOUCHRING:
2021 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
Ping Chengf3f24e72016-12-08 22:05:44 -08002022 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07002023 break;
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002024 case WACOM_HID_WD_TOUCHRINGSTATUS:
Jason Gerecke8d411cb2017-08-04 15:35:14 -07002025 /*
2026 * Only set up type/code association. Completely mapping
2027 * this usage may overwrite the axis resolution and range.
2028 */
2029 usage->type = EV_ABS;
2030 usage->code = ABS_WHEEL;
2031 set_bit(EV_ABS, input->evbit);
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002032 features->device_type |= WACOM_DEVICETYPE_PAD;
2033 break;
Ping Cheng4eb220c2017-02-14 21:26:21 -08002034 case WACOM_HID_WD_BUTTONCONFIG:
2035 wacom_map_usage(input, usage, field, EV_KEY, KEY_BUTTONCONFIG, 0);
2036 features->device_type |= WACOM_DEVICETYPE_PAD;
2037 break;
2038 case WACOM_HID_WD_ONSCREEN_KEYBOARD:
2039 wacom_map_usage(input, usage, field, EV_KEY, KEY_ONSCREEN_KEYBOARD, 0);
2040 features->device_type |= WACOM_DEVICETYPE_PAD;
2041 break;
2042 case WACOM_HID_WD_CONTROLPANEL:
2043 wacom_map_usage(input, usage, field, EV_KEY, KEY_CONTROLPANEL, 0);
2044 features->device_type |= WACOM_DEVICETYPE_PAD;
2045 break;
Benjamin Tissoires4082da82017-02-14 21:27:18 -08002046 case WACOM_HID_WD_MODE_CHANGE:
2047 /* do not overwrite previous data */
2048 if (!wacom_wac->has_mode_change) {
2049 wacom_wac->has_mode_change = true;
2050 wacom_wac->is_direct_mode = true;
2051 }
2052 features->device_type |= WACOM_DEVICETYPE_PAD;
2053 break;
Jason Gerecke5922e612016-10-19 18:03:51 -07002054 }
2055
2056 switch (equivalent_usage & 0xfffffff0) {
2057 case WACOM_HID_WD_EXPRESSKEY00:
2058 wacom_map_usage(input, usage, field, EV_KEY,
2059 wacom_numbered_button_to_key(features->numbered_buttons),
2060 0);
2061 features->numbered_buttons++;
Ping Chengf3f24e72016-12-08 22:05:44 -08002062 features->device_type |= WACOM_DEVICETYPE_PAD;
Jason Gerecke5922e612016-10-19 18:03:51 -07002063 break;
2064 }
2065}
2066
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002067static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
2068 struct hid_usage *usage, __s32 value)
2069{
2070 struct wacom *wacom = hid_get_drvdata(hdev);
2071 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2072 struct input_dev *input = wacom_wac->pad_input;
2073 struct wacom_features *features = &wacom_wac->features;
2074 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08002075 int i;
Jason Gerecked252f4a2017-08-30 15:13:26 -07002076 bool do_report = false;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002077
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002078 /*
2079 * Avoid reporting this event and setting inrange_state if this usage
2080 * hasn't been mapped.
2081 */
Benjamin Tissoires4082da82017-02-14 21:27:18 -08002082 if (!usage->type && equivalent_usage != WACOM_HID_WD_MODE_CHANGE)
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002083 return;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002084
2085 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002086 if (usage->hid != WACOM_HID_WD_TOUCHRING)
2087 wacom_wac->hid_data.inrange_state |= value;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002088 }
2089
2090 switch (equivalent_usage) {
Jason Gerecked252f4a2017-08-30 15:13:26 -07002091 case WACOM_HID_WD_TOUCHRING:
2092 /*
2093 * Userspace expects touchrings to increase in value with
2094 * clockwise gestures and have their zero point at the
2095 * tablet's left. HID events "should" be clockwise-
2096 * increasing and zero at top, though the MobileStudio
2097 * Pro and 2nd-gen Intuos Pro don't do this...
2098 */
2099 if (hdev->vendor == 0x56a &&
2100 (hdev->product == 0x34d || hdev->product == 0x34e || /* MobileStudio Pro */
Ping Cheng384225c2019-06-23 16:52:43 -07002101 hdev->product == 0x357 || hdev->product == 0x358 || /* Intuos Pro 2 */
Aaron Armstrong Skomra6e2abc62019-06-26 15:48:48 -07002102 hdev->product == 0x392 || /* Intuos Pro 2 */
Jason Gereckefe4e9402019-12-16 10:18:57 -08002103 hdev->product == 0x398 || hdev->product == 0x399 || /* MobileStudio Pro */
2104 hdev->product == 0x3AA)) { /* MobileStudio Pro */
Jason Gerecked252f4a2017-08-30 15:13:26 -07002105 value = (field->logical_maximum - value);
2106
Aaron Armstrong Skomra6e2abc62019-06-26 15:48:48 -07002107 if (hdev->product == 0x357 || hdev->product == 0x358 ||
2108 hdev->product == 0x392)
Jason Gerecked252f4a2017-08-30 15:13:26 -07002109 value = wacom_offset_rotation(input, usage, value, 3, 16);
Ping Cheng384225c2019-06-23 16:52:43 -07002110 else if (hdev->product == 0x34d || hdev->product == 0x34e ||
Jason Gereckefe4e9402019-12-16 10:18:57 -08002111 hdev->product == 0x398 || hdev->product == 0x399 ||
2112 hdev->product == 0x3AA)
Jason Gerecked252f4a2017-08-30 15:13:26 -07002113 value = wacom_offset_rotation(input, usage, value, 1, 2);
2114 }
2115 else {
2116 value = wacom_offset_rotation(input, usage, value, 1, 4);
2117 }
2118 do_report = true;
2119 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002120 case WACOM_HID_WD_TOUCHRINGSTATUS:
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002121 if (!value)
2122 input_event(input, usage->type, usage->code, 0);
Ping Cheng354a3292016-12-08 22:03:27 -08002123 break;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002124
Ping Chengd793ff82017-02-14 21:27:45 -08002125 case WACOM_HID_WD_MUTE_DEVICE:
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002126 case WACOM_HID_WD_TOUCHONOFF:
2127 if (wacom_wac->shared->touch_input) {
Jason Gerecke403c0f62017-12-26 14:53:55 -08002128 bool *is_touch_on = &wacom_wac->shared->is_touch_on;
2129
2130 if (equivalent_usage == WACOM_HID_WD_MUTE_DEVICE && value)
2131 *is_touch_on = !(*is_touch_on);
2132 else if (equivalent_usage == WACOM_HID_WD_TOUCHONOFF)
2133 *is_touch_on = value;
2134
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002135 input_report_switch(wacom_wac->shared->touch_input,
Jason Gerecke403c0f62017-12-26 14:53:55 -08002136 SW_MUTE_DEVICE, !(*is_touch_on));
Aaron Armstrong Skomrad2ec58a2017-01-25 12:08:41 -08002137 input_sync(wacom_wac->shared->touch_input);
2138 }
2139 break;
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08002140
Benjamin Tissoires4082da82017-02-14 21:27:18 -08002141 case WACOM_HID_WD_MODE_CHANGE:
2142 if (wacom_wac->is_direct_mode != value) {
2143 wacom_wac->is_direct_mode = value;
2144 wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_MODE_CHANGE);
2145 }
2146 break;
2147
Aaron Armstrong Skomra10c55ca2017-01-25 12:08:42 -08002148 case WACOM_HID_WD_BUTTONCENTER:
2149 for (i = 0; i < wacom->led.count; i++)
2150 wacom_update_led(wacom, features->numbered_buttons,
2151 value, i);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002152 fallthrough;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002153 default:
Jason Gerecked252f4a2017-08-30 15:13:26 -07002154 do_report = true;
2155 break;
2156 }
2157
2158 if (do_report) {
Jason Gerecke5922e612016-10-19 18:03:51 -07002159 input_event(input, usage->type, usage->code, value);
Ping Chenged1fa732017-04-04 12:31:07 -07002160 if (value)
2161 wacom_wac->hid_data.pad_input_event_flag = true;
Jason Gerecke93aab7f2016-10-19 18:03:52 -07002162 }
Jason Gerecke5922e612016-10-19 18:03:51 -07002163}
2164
2165static void wacom_wac_pad_pre_report(struct hid_device *hdev,
2166 struct hid_report *report)
2167{
2168 struct wacom *wacom = hid_get_drvdata(hdev);
2169 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2170
2171 wacom_wac->hid_data.inrange_state = 0;
2172}
2173
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002174static void wacom_wac_pad_report(struct hid_device *hdev,
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002175 struct hid_report *report, struct hid_field *field)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002176{
2177 struct wacom *wacom = hid_get_drvdata(hdev);
2178 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002179 struct input_dev *input = wacom_wac->pad_input;
2180 bool active = wacom_wac->hid_data.inrange_state != 0;
2181
2182 /* report prox for expresskey events */
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002183 if (wacom_wac->hid_data.pad_input_event_flag) {
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002184 input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002185 input_sync(input);
Ping Chenged1fa732017-04-04 12:31:07 -07002186 if (!active)
2187 wacom_wac->hid_data.pad_input_event_flag = false;
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002188 }
Jason Gerecke5922e612016-10-19 18:03:51 -07002189}
2190
Ping Cheng46fc4662021-04-05 20:46:34 -07002191static void wacom_set_barrel_switch3_usage(struct wacom_wac *wacom_wac)
2192{
2193 struct input_dev *input = wacom_wac->pen_input;
2194 struct wacom_features *features = &wacom_wac->features;
2195
2196 if (!(features->quirks & WACOM_QUIRK_AESPEN) &&
2197 wacom_wac->hid_data.barrelswitch &&
2198 wacom_wac->hid_data.barrelswitch2 &&
2199 wacom_wac->hid_data.serialhi)
2200 input_set_capability(input, EV_KEY, BTN_STYLUS3);
2201}
2202
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002203static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
2204 struct hid_field *field, struct hid_usage *usage)
2205{
2206 struct wacom *wacom = hid_get_drvdata(hdev);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002207 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002208 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002209 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07002210 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002211
Jason Gereckec9c09582016-10-19 18:03:43 -07002212 switch (equivalent_usage) {
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002213 case HID_GD_X:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002214 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002215 break;
2216 case HID_GD_Y:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002217 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002218 break;
Jason Gereckeb5c921e2016-10-19 18:03:44 -07002219 case WACOM_HID_WD_DISTANCE:
Jason Gerecke50066a02016-10-19 18:03:42 -07002220 case HID_GD_Z:
2221 wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
2222 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002223 case HID_DG_TIPPRESSURE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002224 wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002225 break;
2226 case HID_DG_INRANGE:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002227 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002228 break;
2229 case HID_DG_INVERT:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002230 wacom_map_usage(input, usage, field, EV_KEY,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002231 BTN_TOOL_RUBBER, 0);
2232 break;
Jason Gerecke50066a02016-10-19 18:03:42 -07002233 case HID_DG_TILT_X:
2234 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
2235 break;
2236 case HID_DG_TILT_Y:
2237 wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
2238 break;
2239 case HID_DG_TWIST:
2240 wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
2241 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002242 case HID_DG_ERASER:
Ping Cheng46fc4662021-04-05 20:46:34 -07002243 input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
2244 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
2245 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002246 case HID_DG_TIPSWITCH:
Ping Cheng46fc4662021-04-05 20:46:34 -07002247 input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002248 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002249 break;
2250 case HID_DG_BARRELSWITCH:
Ping Cheng46fc4662021-04-05 20:46:34 -07002251 wacom_wac->hid_data.barrelswitch = true;
2252 wacom_set_barrel_switch3_usage(wacom_wac);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002253 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002254 break;
2255 case HID_DG_BARRELSWITCH2:
Ping Cheng46fc4662021-04-05 20:46:34 -07002256 wacom_wac->hid_data.barrelswitch2 = true;
2257 wacom_set_barrel_switch3_usage(wacom_wac);
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002258 wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002259 break;
2260 case HID_DG_TOOLSERIALNUMBER:
Jason Gerecke83417202017-11-10 11:50:01 -08002261 features->quirks |= WACOM_QUIRK_TOOLSERIAL;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002262 wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002263 break;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002264 case WACOM_HID_WD_SENSE:
2265 features->quirks |= WACOM_QUIRK_SENSE;
2266 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
2267 break;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002268 case WACOM_HID_WD_SERIALHI:
Ping Cheng46fc4662021-04-05 20:46:34 -07002269 wacom_wac->hid_data.serialhi = true;
2270 wacom_set_barrel_switch3_usage(wacom_wac);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002271 wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002272 break;
Jason Gerecke929d6d52016-10-19 18:03:45 -07002273 case WACOM_HID_WD_FINGERWHEEL:
Ping Cheng46fc4662021-04-05 20:46:34 -07002274 input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
Jason Gerecke929d6d52016-10-19 18:03:45 -07002275 wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
2276 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002277 }
2278}
2279
Ping Cheng354a3292016-12-08 22:03:27 -08002280static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002281 struct hid_usage *usage, __s32 value)
2282{
2283 struct wacom *wacom = hid_get_drvdata(hdev);
2284 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002285 struct wacom_features *features = &wacom_wac->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002286 struct input_dev *input = wacom_wac->pen_input;
Jason Gereckec9c09582016-10-19 18:03:43 -07002287 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002288
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002289 if (wacom_wac->is_invalid_bt_frame)
2290 return;
2291
Jason Gereckec9c09582016-10-19 18:03:43 -07002292 switch (equivalent_usage) {
Jason Gerecke50066a02016-10-19 18:03:42 -07002293 case HID_GD_Z:
2294 /*
2295 * HID_GD_Z "should increase as the control's position is
2296 * moved from high to low", while ABS_DISTANCE instead
2297 * increases in value as the tool moves from low to high.
2298 */
2299 value = field->logical_maximum - value;
2300 break;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002301 case HID_DG_INRANGE:
2302 wacom_wac->hid_data.inrange_state = value;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002303 if (!(features->quirks & WACOM_QUIRK_SENSE))
2304 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002305 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002306 case HID_DG_INVERT:
2307 wacom_wac->hid_data.invert_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002308 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002309 case HID_DG_ERASER:
2310 case HID_DG_TIPSWITCH:
2311 wacom_wac->hid_data.tipswitch |= value;
Ping Cheng354a3292016-12-08 22:03:27 -08002312 return;
Jason Gerecke9e429d52017-11-07 08:25:17 -08002313 case HID_DG_BARRELSWITCH:
2314 wacom_wac->hid_data.barrelswitch = value;
2315 return;
2316 case HID_DG_BARRELSWITCH2:
2317 wacom_wac->hid_data.barrelswitch2 = value;
2318 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002319 case HID_DG_TOOLSERIALNUMBER:
Jason Gerecke993f0d92017-09-07 17:44:12 -07002320 if (value) {
2321 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
Jason Gereckeff4797312019-11-06 11:59:46 -08002322 wacom_wac->serial[0] |= wacom_s32tou(value, field->report_size);
Jason Gerecke993f0d92017-09-07 17:44:12 -07002323 }
Ping Cheng354a3292016-12-08 22:03:27 -08002324 return;
Jason Gerecked252f4a2017-08-30 15:13:26 -07002325 case HID_DG_TWIST:
2326 /*
2327 * Userspace expects pen twist to have its zero point when
2328 * the buttons/finger is on the tablet's left. HID values
2329 * are zero when buttons are toward the top.
2330 */
2331 value = wacom_offset_rotation(input, usage, value, 1, 4);
2332 break;
Jason Gerecke61ce3462016-10-19 18:03:46 -07002333 case WACOM_HID_WD_SENSE:
2334 wacom_wac->hid_data.sense_state = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002335 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002336 case WACOM_HID_WD_SERIALHI:
Jason Gerecke993f0d92017-09-07 17:44:12 -07002337 if (value) {
Jason Gereckeff4797312019-11-06 11:59:46 -08002338 __u32 raw_value = wacom_s32tou(value, field->report_size);
2339
Jason Gerecke993f0d92017-09-07 17:44:12 -07002340 wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
Jason Gereckeff4797312019-11-06 11:59:46 -08002341 wacom_wac->serial[0] |= ((__u64)raw_value) << 32;
Jason Gerecke993f0d92017-09-07 17:44:12 -07002342 /*
2343 * Non-USI EMR devices may contain additional tool type
2344 * information here. See WACOM_HID_WD_TOOLTYPE case for
2345 * more details.
2346 */
2347 if (value >> 20 == 1) {
Jason Gereckeff4797312019-11-06 11:59:46 -08002348 wacom_wac->id[0] |= raw_value & 0xFFFFF;
Jason Gerecke993f0d92017-09-07 17:44:12 -07002349 }
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002350 }
Ping Cheng354a3292016-12-08 22:03:27 -08002351 return;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002352 case WACOM_HID_WD_TOOLTYPE:
2353 /*
2354 * Some devices (MobileStudio Pro, and possibly later
2355 * devices as well) do not return the complete tool
2356 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
2357 * bitwise OR so the complete value can be built
2358 * up over time :(
2359 */
Jason Gereckeff4797312019-11-06 11:59:46 -08002360 wacom_wac->id[0] |= wacom_s32tou(value, field->report_size);
Ping Cheng354a3292016-12-08 22:03:27 -08002361 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002362 case WACOM_HID_WD_OFFSETLEFT:
2363 if (features->offset_left && value != features->offset_left)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002364 hid_warn(hdev, "%s: overriding existing left offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002365 "%d -> %d\n", __func__, value,
2366 features->offset_left);
2367 features->offset_left = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002368 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002369 case WACOM_HID_WD_OFFSETRIGHT:
2370 if (features->offset_right && value != features->offset_right)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002371 hid_warn(hdev, "%s: overriding existing right offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002372 "%d -> %d\n", __func__, value,
2373 features->offset_right);
2374 features->offset_right = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002375 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002376 case WACOM_HID_WD_OFFSETTOP:
2377 if (features->offset_top && value != features->offset_top)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002378 hid_warn(hdev, "%s: overriding existing top offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002379 "%d -> %d\n", __func__, value,
2380 features->offset_top);
2381 features->offset_top = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002382 return;
Jason Gerecke345857b2016-10-19 18:03:50 -07002383 case WACOM_HID_WD_OFFSETBOTTOM:
2384 if (features->offset_bottom && value != features->offset_bottom)
Colin Ian King75a5f3a2017-06-26 20:35:38 +01002385 hid_warn(hdev, "%s: overriding existing bottom offset "
Jason Gerecke345857b2016-10-19 18:03:50 -07002386 "%d -> %d\n", __func__, value,
2387 features->offset_bottom);
2388 features->offset_bottom = value;
Ping Cheng354a3292016-12-08 22:03:27 -08002389 return;
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002390 case WACOM_HID_WD_REPORT_VALID:
2391 wacom_wac->is_invalid_bt_frame = !value;
2392 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002393 }
2394
Ping Cheng1924e052016-08-09 14:38:56 -07002395 /* send pen events only when touch is up or forced out
2396 * or touch arbitration is off
2397 */
2398 if (!usage->type || delay_pen_events(wacom_wac))
Ping Cheng354a3292016-12-08 22:03:27 -08002399 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002400
Jason Gerecke4affc232017-09-07 17:49:50 -07002401 /* send pen events only when the pen is in range */
Jason Gerecke5b401042017-09-07 17:52:15 -07002402 if (wacom_wac->hid_data.inrange_state)
2403 input_event(input, usage->type, usage->code, value);
2404 else if (wacom_wac->shared->stylus_in_proximity && !wacom_wac->hid_data.sense_state)
2405 input_event(input, usage->type, usage->code, 0);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002406}
2407
Jason Gerecke06324e02015-07-21 11:07:23 -07002408static void wacom_wac_pen_pre_report(struct hid_device *hdev,
2409 struct hid_report *report)
2410{
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002411 struct wacom *wacom = hid_get_drvdata(hdev);
2412 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2413
2414 wacom_wac->is_invalid_bt_frame = false;
Jason Gerecke06324e02015-07-21 11:07:23 -07002415 return;
2416}
2417
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002418static void wacom_wac_pen_report(struct hid_device *hdev,
2419 struct hid_report *report)
2420{
2421 struct wacom *wacom = hid_get_drvdata(hdev);
2422 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002423 struct input_dev *input = wacom_wac->pen_input;
Jason Gerecke7690dd12017-09-07 17:48:55 -07002424 bool range = wacom_wac->hid_data.inrange_state;
2425 bool sense = wacom_wac->hid_data.sense_state;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002426
Aaron Armstrong Skomrab1f466a2018-03-06 10:48:35 -08002427 if (wacom_wac->is_invalid_bt_frame)
2428 return;
2429
Jason Gerecke7690dd12017-09-07 17:48:55 -07002430 if (!wacom_wac->tool[0] && range) { /* first in range */
2431 /* Going into range select tool */
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002432 if (wacom_wac->hid_data.invert_state)
2433 wacom_wac->tool[0] = BTN_TOOL_RUBBER;
2434 else if (wacom_wac->id[0])
2435 wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
2436 else
2437 wacom_wac->tool[0] = BTN_TOOL_PEN;
2438 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002439
2440 /* keep pen state for touch events */
Jason Gerecke7690dd12017-09-07 17:48:55 -07002441 wacom_wac->shared->stylus_in_proximity = sense;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002442
Jason Gerecke61ce3462016-10-19 18:03:46 -07002443 if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002444 int id = wacom_wac->id[0];
Jason Gerecke9e429d52017-11-07 08:25:17 -08002445 int sw_state = wacom_wac->hid_data.barrelswitch |
2446 (wacom_wac->hid_data.barrelswitch2 << 1);
2447
2448 input_report_key(input, BTN_STYLUS, sw_state == 1);
2449 input_report_key(input, BTN_STYLUS2, sw_state == 2);
2450 input_report_key(input, BTN_STYLUS3, sw_state == 3);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002451
2452 /*
2453 * Non-USI EMR tools should have their IDs mangled to
2454 * match the legacy behavior of wacom_intuos_general
2455 */
2456 if (wacom_wac->serial[0] >> 52 == 1)
2457 id = wacom_intuos_id_mangle(id);
2458
2459 /*
2460 * To ensure compatibility with xf86-input-wacom, we should
2461 * report the BTN_TOOL_* event prior to the ABS_MISC or
2462 * MSC_SERIAL events.
2463 */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002464 input_report_key(input, BTN_TOUCH,
2465 wacom_wac->hid_data.tipswitch);
Jason Gerecke4affc232017-09-07 17:49:50 -07002466 input_report_key(input, wacom_wac->tool[0], sense);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002467 if (wacom_wac->serial[0]) {
2468 input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
Jason Gerecke4affc232017-09-07 17:49:50 -07002469 input_report_abs(input, ABS_MISC, sense ? id : 0);
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002470 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002471
2472 wacom_wac->hid_data.tipswitch = false;
2473
2474 input_sync(input);
2475 }
Jason Gerecke61ce3462016-10-19 18:03:46 -07002476
Jason Gerecke4affc232017-09-07 17:49:50 -07002477 if (!sense) {
Jason Gerecke61ce3462016-10-19 18:03:46 -07002478 wacom_wac->tool[0] = 0;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002479 wacom_wac->id[0] = 0;
Jason Gerecke993f0d92017-09-07 17:44:12 -07002480 wacom_wac->serial[0] = 0;
Jason Gereckef85c9dc2016-10-19 18:03:48 -07002481 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002482}
2483
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002484static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
2485 struct hid_field *field, struct hid_usage *usage)
2486{
2487 struct wacom *wacom = hid_get_drvdata(hdev);
2488 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002489 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002490 unsigned touch_max = wacom_wac->features.touch_max;
Jason Gereckec9c09582016-10-19 18:03:43 -07002491 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002492
Jason Gereckec9c09582016-10-19 18:03:43 -07002493 switch (equivalent_usage) {
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002494 case HID_GD_X:
2495 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002496 wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002497 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002498 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002499 ABS_MT_POSITION_X, 4);
2500 break;
2501 case HID_GD_Y:
2502 if (touch_max == 1)
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002503 wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002504 else
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002505 wacom_map_usage(input, usage, field, EV_ABS,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002506 ABS_MT_POSITION_Y, 4);
2507 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002508 case HID_DG_WIDTH:
2509 case HID_DG_HEIGHT:
Jason Gerecke488abb52015-07-21 11:07:25 -07002510 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
2511 wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
2512 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
2513 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002514 case HID_DG_TIPSWITCH:
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002515 wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002516 break;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002517 case HID_DG_CONTACTCOUNT:
Jason Gerecke499522c2015-10-07 16:54:21 -07002518 wacom_wac->hid_data.cc_report = field->report->id;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002519 wacom_wac->hid_data.cc_index = field->index;
2520 wacom_wac->hid_data.cc_value_index = usage->usage_index;
2521 break;
Jason Gerecke6f107fa2017-04-19 14:47:24 -07002522 case HID_DG_CONTACTID:
2523 if ((field->logical_maximum - field->logical_minimum) < touch_max) {
2524 /*
2525 * The HID descriptor for G11 sensors leaves logical
2526 * maximum set to '1' despite it being a multitouch
2527 * device. Override to a sensible number.
2528 */
2529 field->logical_maximum = 255;
2530 }
2531 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002532 }
2533}
2534
Jason Gerecke601a22f2014-12-10 16:26:04 -08002535static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
2536 struct input_dev *input)
2537{
2538 struct hid_data *hid_data = &wacom_wac->hid_data;
2539 bool mt = wacom_wac->features.touch_max > 1;
2540 bool prox = hid_data->tipswitch &&
Ping Cheng1924e052016-08-09 14:38:56 -07002541 report_touch_events(wacom_wac);
Jason Gerecke601a22f2014-12-10 16:26:04 -08002542
Jason Gerecke9d339fe2021-07-19 13:55:33 -07002543 if (touch_is_muted(wacom_wac)) {
Ping Chengd793ff82017-02-14 21:27:45 -08002544 if (!wacom_wac->shared->touch_down)
2545 return;
Jiapeng Zhonge29c62f2021-01-20 15:34:30 +08002546 prox = false;
Ping Chengd793ff82017-02-14 21:27:45 -08002547 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002548
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002549 wacom_wac->hid_data.num_received++;
2550 if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
2551 return;
2552
Jason Gerecke601a22f2014-12-10 16:26:04 -08002553 if (mt) {
2554 int slot;
2555
2556 slot = input_mt_get_slot_by_key(input, hid_data->id);
Jason Gereckeccb51c2e2021-07-19 13:55:32 -07002557 if (slot < 0) {
Jason Gerecke7cc85242021-07-19 13:55:31 -07002558 return;
Jason Gereckeccb51c2e2021-07-19 13:55:32 -07002559 } else {
2560 struct input_mt_slot *ps = &input->mt->slots[slot];
2561 int mt_id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
2562
2563 if (!prox && mt_id < 0) {
2564 // No data to send for this slot; short-circuit
2565 return;
2566 }
2567 }
Jason Gerecke7cc85242021-07-19 13:55:31 -07002568
Jason Gerecke601a22f2014-12-10 16:26:04 -08002569 input_mt_slot(input, slot);
2570 input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
2571 }
2572 else {
2573 input_report_key(input, BTN_TOUCH, prox);
2574 }
2575
2576 if (prox) {
2577 input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
2578 hid_data->x);
2579 input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
2580 hid_data->y);
Jason Gerecke488abb52015-07-21 11:07:25 -07002581
2582 if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
2583 input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
2584 input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
2585 if (hid_data->width != hid_data->height)
2586 input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
2587 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002588 }
2589}
2590
Jason Gereckedf03e9b2022-01-18 14:37:56 -08002591static bool wacom_wac_slot_is_active(struct input_dev *dev, int key)
2592{
2593 struct input_mt *mt = dev->mt;
2594 struct input_mt_slot *s;
2595
2596 if (!mt)
2597 return false;
2598
2599 for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
2600 if (s->key == key &&
2601 input_mt_get_value(s, ABS_MT_TRACKING_ID) >= 0) {
2602 return true;
2603 }
2604 }
2605
2606 return false;
2607}
2608
Ping Cheng354a3292016-12-08 22:03:27 -08002609static void wacom_wac_finger_event(struct hid_device *hdev,
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002610 struct hid_field *field, struct hid_usage *usage, __s32 value)
2611{
2612 struct wacom *wacom = hid_get_drvdata(hdev);
2613 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckec9c09582016-10-19 18:03:43 -07002614 unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
Aaron Armstrong Skomra184eccd2019-06-12 14:19:29 -07002615 struct wacom_features *features = &wacom->wacom_wac.features;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002616
Jason Gerecke9d339fe2021-07-19 13:55:33 -07002617 if (touch_is_muted(wacom_wac) && !wacom_wac->shared->touch_down)
Jason Gerecke5bed0122021-07-19 13:55:30 -07002618 return;
2619
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07002620 if (wacom_wac->is_invalid_bt_frame)
2621 return;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002622
Jason Gereckec9c09582016-10-19 18:03:43 -07002623 switch (equivalent_usage) {
Jason Gerecke7fb04132021-11-08 16:31:01 -08002624 case HID_DG_CONFIDENCE:
2625 wacom_wac->hid_data.confidence = value;
2626 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002627 case HID_GD_X:
2628 wacom_wac->hid_data.x = value;
2629 break;
2630 case HID_GD_Y:
2631 wacom_wac->hid_data.y = value;
2632 break;
Jason Gerecke488abb52015-07-21 11:07:25 -07002633 case HID_DG_WIDTH:
2634 wacom_wac->hid_data.width = value;
2635 break;
2636 case HID_DG_HEIGHT:
2637 wacom_wac->hid_data.height = value;
2638 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002639 case HID_DG_CONTACTID:
2640 wacom_wac->hid_data.id = value;
2641 break;
2642 case HID_DG_TIPSWITCH:
2643 wacom_wac->hid_data.tipswitch = value;
2644 break;
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07002645 case WACOM_HID_WT_REPORT_VALID:
2646 wacom_wac->is_invalid_bt_frame = !value;
2647 return;
Aaron Armstrong Skomra184eccd2019-06-12 14:19:29 -07002648 case HID_DG_CONTACTMAX:
Jason Gerecke88f38842021-02-16 11:41:54 -08002649 if (!features->touch_max) {
2650 features->touch_max = value;
2651 } else {
2652 hid_warn(hdev, "%s: ignoring attempt to overwrite non-zero touch_max "
2653 "%d -> %d\n", __func__, features->touch_max, value);
2654 }
Aaron Armstrong Skomra184eccd2019-06-12 14:19:29 -07002655 return;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002656 }
2657
Jason Gerecke601a22f2014-12-10 16:26:04 -08002658 if (usage->usage_index + 1 == field->report_count) {
Jason Gereckedf03e9b2022-01-18 14:37:56 -08002659 if (equivalent_usage == wacom_wac->hid_data.last_slot_field) {
2660 bool touch_removed = wacom_wac_slot_is_active(wacom_wac->touch_input,
2661 wacom_wac->hid_data.id) && !wacom_wac->hid_data.tipswitch;
2662
2663 if (wacom_wac->hid_data.confidence || touch_removed) {
2664 wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
2665 }
2666 }
Jason Gerecke601a22f2014-12-10 16:26:04 -08002667 }
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002668}
2669
Jason Gerecke06324e02015-07-21 11:07:23 -07002670static void wacom_wac_finger_pre_report(struct hid_device *hdev,
2671 struct hid_report *report)
2672{
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002673 struct wacom *wacom = hid_get_drvdata(hdev);
2674 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2675 struct hid_data* hid_data = &wacom_wac->hid_data;
Jason Gerecke003f50a2016-07-21 09:10:46 -07002676 int i;
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002677
Jason Gerecke9d339fe2021-07-19 13:55:33 -07002678 if (touch_is_muted(wacom_wac) && !wacom_wac->shared->touch_down)
Jason Gerecke5bed0122021-07-19 13:55:30 -07002679 return;
2680
Aaron Armstrong Skomraf4e11d52019-06-12 14:19:30 -07002681 wacom_wac->is_invalid_bt_frame = false;
2682
Jason Gerecke7fb04132021-11-08 16:31:01 -08002683 hid_data->confidence = true;
2684
Jason Gerecke20f3cf52022-01-18 14:38:41 -08002685 hid_data->cc_report = 0;
2686 hid_data->cc_index = -1;
2687 hid_data->cc_value_index = -1;
2688
Jason Gerecke003f50a2016-07-21 09:10:46 -07002689 for (i = 0; i < report->maxfield; i++) {
2690 struct hid_field *field = report->field[i];
2691 int j;
Jason Gerecke499522c2015-10-07 16:54:21 -07002692
Jason Gerecke003f50a2016-07-21 09:10:46 -07002693 for (j = 0; j < field->maxusage; j++) {
2694 struct hid_usage *usage = &field->usage[j];
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002695 unsigned int equivalent_usage =
2696 wacom_equivalent_usage(usage->hid);
Jason Gerecke499522c2015-10-07 16:54:21 -07002697
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002698 switch (equivalent_usage) {
Jason Gerecke003f50a2016-07-21 09:10:46 -07002699 case HID_GD_X:
2700 case HID_GD_Y:
2701 case HID_DG_WIDTH:
2702 case HID_DG_HEIGHT:
2703 case HID_DG_CONTACTID:
2704 case HID_DG_INRANGE:
2705 case HID_DG_INVERT:
2706 case HID_DG_TIPSWITCH:
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002707 hid_data->last_slot_field = equivalent_usage;
Jason Gerecke003f50a2016-07-21 09:10:46 -07002708 break;
Jason Gereckeb43f9772020-04-08 07:58:37 -07002709 case HID_DG_CONTACTCOUNT:
2710 hid_data->cc_report = report->id;
2711 hid_data->cc_index = i;
2712 hid_data->cc_value_index = j;
2713 break;
Jason Gerecke499522c2015-10-07 16:54:21 -07002714 }
2715 }
2716 }
Jason Gereckeb43f9772020-04-08 07:58:37 -07002717
2718 if (hid_data->cc_report != 0 &&
2719 hid_data->cc_index >= 0) {
2720 struct hid_field *field = report->field[hid_data->cc_index];
2721 int value = field->value[hid_data->cc_value_index];
Jason Gerecke546e41a2022-01-18 14:37:55 -08002722 if (value) {
Jason Gereckeb43f9772020-04-08 07:58:37 -07002723 hid_data->num_expected = value;
Jason Gerecke546e41a2022-01-18 14:37:55 -08002724 hid_data->num_received = 0;
2725 }
Jason Gereckeb43f9772020-04-08 07:58:37 -07002726 }
2727 else {
2728 hid_data->num_expected = wacom_wac->features.touch_max;
Jason Gerecke546e41a2022-01-18 14:37:55 -08002729 hid_data->num_received = 0;
Jason Gereckeb43f9772020-04-08 07:58:37 -07002730 }
Jason Gerecke06324e02015-07-21 11:07:23 -07002731}
2732
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002733static void wacom_wac_finger_report(struct hid_device *hdev,
2734 struct hid_report *report)
2735{
2736 struct wacom *wacom = hid_get_drvdata(hdev);
2737 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002738 struct input_dev *input = wacom_wac->touch_input;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002739 unsigned touch_max = wacom_wac->features.touch_max;
2740
Jason Gereckeccb51c2e2021-07-19 13:55:32 -07002741 /* if there was nothing to process, don't send an empty sync */
2742 if (wacom_wac->hid_data.num_expected == 0)
2743 return;
2744
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002745 /* If more packets of data are expected, give us a chance to
2746 * process them rather than immediately syncing a partial
2747 * update.
2748 */
2749 if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
2750 return;
2751
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002752 if (touch_max > 1)
Jason Gerecke601a22f2014-12-10 16:26:04 -08002753 input_mt_sync_frame(input);
2754
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002755 input_sync(input);
Jason Gerecke1b5d514a2015-07-21 11:07:24 -07002756 wacom_wac->hid_data.num_received = 0;
Jason Gerecke546e41a2022-01-18 14:37:55 -08002757 wacom_wac->hid_data.num_expected = 0;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002758
2759 /* keep touch state for pen event */
Ping Cheng7d059ed2015-03-20 14:57:21 -07002760 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04002761}
2762
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002763void wacom_wac_usage_mapping(struct hid_device *hdev,
2764 struct hid_field *field, struct hid_usage *usage)
2765{
2766 struct wacom *wacom = hid_get_drvdata(hdev);
2767 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07002768 struct wacom_features *features = &wacom_wac->features;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002769
Aaron Armstrong Skomraac2423c2017-01-25 12:08:40 -08002770 if (WACOM_DIRECT_DEVICE(field))
2771 features->device_type |= WACOM_DEVICETYPE_DIRECT;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002772
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07002773 /* usage tests must precede field tests */
2774 if (WACOM_BATTERY_USAGE(usage))
2775 wacom_wac_battery_usage_mapping(hdev, field, usage);
2776 else if (WACOM_PAD_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002777 wacom_wac_pad_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002778 else if (WACOM_PEN_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002779 wacom_wac_pen_usage_mapping(hdev, field, usage);
Jason Gerecke5922e612016-10-19 18:03:51 -07002780 else if (WACOM_FINGER_FIELD(field))
Ping Cheng354a3292016-12-08 22:03:27 -08002781 wacom_wac_finger_usage_mapping(hdev, field, usage);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002782}
2783
Ping Cheng354a3292016-12-08 22:03:27 -08002784void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002785 struct hid_usage *usage, __s32 value)
2786{
2787 struct wacom *wacom = hid_get_drvdata(hdev);
2788
2789 if (wacom->wacom_wac.features.type != HID_GENERIC)
Ping Cheng354a3292016-12-08 22:03:27 -08002790 return;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002791
Aaron Armstrong Skomra60a22182017-01-25 12:08:39 -08002792 if (value > field->logical_maximum || value < field->logical_minimum)
2793 return;
2794
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07002795 /* usage tests must precede field tests */
2796 if (WACOM_BATTERY_USAGE(usage))
2797 wacom_wac_battery_event(hdev, field, usage, value);
2798 else if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
2799 wacom_wac_pad_event(hdev, field, usage, value);
2800 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002801 wacom_wac_pen_event(hdev, field, usage, value);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002802 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Cheng354a3292016-12-08 22:03:27 -08002803 wacom_wac_finger_event(hdev, field, usage, value);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002804}
2805
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002806static void wacom_report_events(struct hid_device *hdev,
2807 struct hid_report *report, int collection_index,
2808 int field_index)
Jason Gerecke06324e02015-07-21 11:07:23 -07002809{
2810 int r;
2811
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002812 for (r = field_index; r < report->maxfield; r++) {
Jason Gerecke06324e02015-07-21 11:07:23 -07002813 struct hid_field *field;
2814 unsigned count, n;
2815
2816 field = report->field[r];
2817 count = field->report_count;
2818
2819 if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
2820 continue;
2821
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002822 for (n = 0 ; n < count; n++) {
2823 if (field->usage[n].collection_index == collection_index)
2824 wacom_wac_event(hdev, field, &field->usage[n],
2825 field->value[n]);
2826 else
2827 return;
2828 }
Jason Gerecke06324e02015-07-21 11:07:23 -07002829 }
2830}
2831
Jiri Kosina7ba8fc02018-03-07 15:34:51 +01002832static int wacom_wac_collection(struct hid_device *hdev, struct hid_report *report,
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002833 int collection_index, struct hid_field *field,
2834 int field_index)
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002835{
2836 struct wacom *wacom = hid_get_drvdata(hdev);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002837
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002838 wacom_report_events(hdev, report, collection_index, field_index);
Jason Gerecke06324e02015-07-21 11:07:23 -07002839
Jason Gereckea9ce7852017-01-17 15:38:58 -08002840 /*
2841 * Non-input reports may be sent prior to the device being
2842 * completely initialized. Since only their events need
2843 * to be processed, exit after 'wacom_report_events' has
2844 * been called to prevent potential crashes in the report-
2845 * processing functions.
2846 */
2847 if (report->type != HID_INPUT_REPORT)
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002848 return -1;
Jason Gerecke5ac3d4a2017-04-28 09:25:34 -07002849
Jason Gerecked9216d72020-09-23 13:14:56 -07002850 if (WACOM_PAD_FIELD(field))
2851 return 0;
2852 else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002853 wacom_wac_pen_report(hdev, report);
Ping Cheng6f46cf92016-12-08 22:04:52 -08002854 else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
Ping Chengc9cfb2a2016-12-08 22:06:15 -08002855 wacom_wac_finger_report(hdev, report);
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002856
2857 return 0;
2858}
2859
2860void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
2861{
2862 struct wacom *wacom = hid_get_drvdata(hdev);
2863 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
2864 struct hid_field *field;
2865 bool pad_in_hid_field = false, pen_in_hid_field = false,
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002866 finger_in_hid_field = false, true_pad = false;
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002867 int r;
2868 int prev_collection = -1;
2869
2870 if (wacom_wac->features.type != HID_GENERIC)
2871 return;
2872
2873 for (r = 0; r < report->maxfield; r++) {
2874 field = report->field[r];
2875
2876 if (WACOM_PAD_FIELD(field))
2877 pad_in_hid_field = true;
2878 if (WACOM_PEN_FIELD(field))
2879 pen_in_hid_field = true;
2880 if (WACOM_FINGER_FIELD(field))
2881 finger_in_hid_field = true;
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002882 if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY)
2883 true_pad = true;
Aaron Armstrong Skomraf8b6a742018-03-06 10:48:34 -08002884 }
2885
2886 wacom_wac_battery_pre_report(hdev, report);
2887
2888 if (pad_in_hid_field && wacom->wacom_wac.pad_input)
2889 wacom_wac_pad_pre_report(hdev, report);
2890 if (pen_in_hid_field && wacom->wacom_wac.pen_input)
2891 wacom_wac_pen_pre_report(hdev, report);
2892 if (finger_in_hid_field && wacom->wacom_wac.touch_input)
2893 wacom_wac_finger_pre_report(hdev, report);
2894
2895 for (r = 0; r < report->maxfield; r++) {
2896 field = report->field[r];
2897
2898 if (field->usage[0].collection_index != prev_collection) {
2899 if (wacom_wac_collection(hdev, report,
2900 field->usage[0].collection_index, field, r) < 0)
2901 return;
2902 prev_collection = field->usage[0].collection_index;
2903 }
2904 }
2905
2906 wacom_wac_battery_report(hdev, report);
Aaron Armstrong Skomrad4b8efe2019-05-10 15:34:17 -07002907
2908 if (true_pad && wacom->wacom_wac.pad_input)
2909 wacom_wac_pad_report(hdev, report, field);
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04002910}
2911
Chris Bagwelle1d38e42010-09-12 00:09:27 -07002912static int wacom_bpt_touch(struct wacom_wac *wacom)
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002913{
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002914 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002915 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires31168712014-07-24 12:50:10 -07002916 struct input_dev *pad_input = wacom->pad_input;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002917 unsigned char *data = wacom->data;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002918 int i;
2919
Chris Bagwell5a6c8652011-11-07 19:52:42 -08002920 if (data[0] != 0x02)
2921 return 0;
2922
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002923 for (i = 0; i < 2; i++) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002924 int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
Ping Cheng1924e052016-08-09 14:38:56 -07002925 bool touch = report_touch_events(wacom)
2926 && (data[offset + 3] & 0x80);
Chris Bagwell8f906862011-09-09 13:38:10 -07002927
2928 input_mt_slot(input, i);
2929 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
Henrik Rydbergc5f4dec2010-12-15 13:50:34 +01002930 if (touch) {
Chris Bagwell8f906862011-09-09 13:38:10 -07002931 int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
2932 int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07002933 if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
2934 x <<= 5;
2935 y <<= 5;
2936 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002937 input_report_abs(input, ABS_MT_POSITION_X, x);
2938 input_report_abs(input, ABS_MT_POSITION_Y, y);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002939 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002940 }
2941
Benjamin Tissoires9a1c0012015-02-17 14:19:46 -05002942 input_mt_sync_frame(input);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002943
Benjamin Tissoires31168712014-07-24 12:50:10 -07002944 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
2945 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
2946 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
2947 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
Ping Cheng7d059ed2015-03-20 14:57:21 -07002948 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002949
Benjamin Tissoires31168712014-07-24 12:50:10 -07002950 return 1;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07002951}
2952
Ping Cheng7d059ed2015-03-20 14:57:21 -07002953static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
Chris Bagwell73149ab2011-10-26 22:34:21 -07002954{
Ping Cheng9a35c412013-09-20 09:51:56 -07002955 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07002956 struct input_dev *input = wacom->touch_input;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002957 bool touch = data[1] & 0x80;
Ping Cheng02295e62013-01-04 23:56:00 -08002958 int slot = input_mt_get_slot_by_key(input, data[0]);
2959
2960 if (slot < 0)
Ping Cheng7d059ed2015-03-20 14:57:21 -07002961 return;
Chris Bagwell73149ab2011-10-26 22:34:21 -07002962
Ping Cheng1924e052016-08-09 14:38:56 -07002963 touch = touch && report_touch_events(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002964
Ping Cheng02295e62013-01-04 23:56:00 -08002965 input_mt_slot(input, slot);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002966 input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
2967
2968 if (touch) {
2969 int x = (data[2] << 4) | (data[4] >> 4);
2970 int y = (data[3] << 4) | (data[4] & 0x0f);
Ping Cheng9a35c412013-09-20 09:51:56 -07002971 int width, height;
Jason Gerecke4e904952012-10-03 17:19:11 -07002972
Ping Chengeda01da2015-09-23 13:51:15 -07002973 if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
Jason Gerecke0b279da2013-11-25 18:43:16 -08002974 width = data[5] * 100;
2975 height = data[6] * 100;
Ping Cheng9a35c412013-09-20 09:51:56 -07002976 } else {
2977 /*
2978 * "a" is a scaled-down area which we assume is
2979 * roughly circular and which can be described as:
2980 * a=(pi*r^2)/C.
2981 */
2982 int a = data[5];
Ping Chengd7da3a32014-06-13 13:37:33 -07002983 int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
2984 int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
2985 width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
Ping Cheng9a35c412013-09-20 09:51:56 -07002986 height = width * y_res / x_res;
2987 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07002988
2989 input_report_abs(input, ABS_MT_POSITION_X, x);
2990 input_report_abs(input, ABS_MT_POSITION_Y, y);
Jason Gerecke4e904952012-10-03 17:19:11 -07002991 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
2992 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
Chris Bagwell73149ab2011-10-26 22:34:21 -07002993 }
2994}
2995
2996static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
2997{
Benjamin Tissoires31168712014-07-24 12:50:10 -07002998 struct input_dev *input = wacom->pad_input;
Ping Chengb5fd2a32013-11-25 18:44:55 -08002999 struct wacom_features *features = &wacom->features;
Chris Bagwell73149ab2011-10-26 22:34:21 -07003000
Ping Chengeda01da2015-09-23 13:51:15 -07003001 if (features->type == INTUOSHT || features->type == INTUOSHT2) {
Ping Chengb5fd2a32013-11-25 18:44:55 -08003002 input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
3003 input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
3004 } else {
3005 input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
3006 input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
3007 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07003008 input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
Chris Bagwell73149ab2011-10-26 22:34:21 -07003009 input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
3010}
3011
3012static int wacom_bpt3_touch(struct wacom_wac *wacom)
3013{
Chris Bagwell73149ab2011-10-26 22:34:21 -07003014 unsigned char *data = wacom->data;
Jason Gerecke19d57d32012-03-06 10:19:19 -08003015 int count = data[1] & 0x07;
Ping Chengeda01da2015-09-23 13:51:15 -07003016 int touch_changed = 0, i;
Chris Bagwell73149ab2011-10-26 22:34:21 -07003017
Chris Bagwell5a6c8652011-11-07 19:52:42 -08003018 if (data[0] != 0x02)
3019 return 0;
3020
Chris Bagwell73149ab2011-10-26 22:34:21 -07003021 /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
3022 for (i = 0; i < count; i++) {
3023 int offset = (8 * i) + 2;
3024 int msg_id = data[offset];
3025
Ping Chengeda01da2015-09-23 13:51:15 -07003026 if (msg_id >= 2 && msg_id <= 17) {
Ping Cheng7d059ed2015-03-20 14:57:21 -07003027 wacom_bpt3_touch_msg(wacom, data + offset);
Ping Chengeda01da2015-09-23 13:51:15 -07003028 touch_changed++;
3029 } else if (msg_id == 128)
Chris Bagwell73149ab2011-10-26 22:34:21 -07003030 wacom_bpt3_button_msg(wacom, data + offset);
3031
3032 }
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003033
Ping Chengeda01da2015-09-23 13:51:15 -07003034 /* only update touch if we actually have a touchpad and touch data changed */
Benjamin Tissoires84dfbd72016-07-13 18:05:55 +02003035 if (wacom->touch_input && touch_changed) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003036 input_mt_sync_frame(wacom->touch_input);
3037 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
3038 }
Chris Bagwell73149ab2011-10-26 22:34:21 -07003039
Benjamin Tissoires31168712014-07-24 12:50:10 -07003040 return 1;
Chris Bagwell73149ab2011-10-26 22:34:21 -07003041}
3042
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003043static int wacom_bpt_pen(struct wacom_wac *wacom)
3044{
Ping Cheng961794a2013-12-05 12:54:53 -08003045 struct wacom_features *features = &wacom->features;
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003046 struct input_dev *input = wacom->pen_input;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003047 unsigned char *data = wacom->data;
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003048 int x = 0, y = 0, p = 0, d = 0;
3049 bool pen = false, btn1 = false, btn2 = false;
3050 bool range, prox, rdy;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003051
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003052 if (data[0] != WACOM_REPORT_PENABLED)
Chris Bagwell5a6c8652011-11-07 19:52:42 -08003053 return 0;
3054
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003055 range = (data[1] & 0x80) == 0x80;
3056 prox = (data[1] & 0x40) == 0x40;
3057 rdy = (data[1] & 0x20) == 0x20;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003058
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003059 wacom->shared->stylus_in_proximity = range;
3060 if (delay_pen_events(wacom))
3061 return 0;
3062
3063 if (rdy) {
3064 p = le16_to_cpup((__le16 *)&data[6]);
3065 pen = data[1] & 0x01;
3066 btn1 = data[1] & 0x02;
3067 btn2 = data[1] & 0x04;
3068 }
3069 if (prox) {
3070 x = le16_to_cpup((__le16 *)&data[2]);
3071 y = le16_to_cpup((__le16 *)&data[4]);
3072
Ping Cheng01499312015-03-20 14:58:01 -07003073 if (data[1] & 0x08) {
3074 wacom->tool[0] = BTN_TOOL_RUBBER;
3075 wacom->id[0] = ERASER_DEVICE_ID;
3076 } else {
3077 wacom->tool[0] = BTN_TOOL_PEN;
3078 wacom->id[0] = STYLUS_DEVICE_ID;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003079 }
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003080 wacom->reporting_data = true;
Ping Cheng01499312015-03-20 14:58:01 -07003081 }
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003082 if (range) {
Chris Bagwellc18c2ce2011-10-10 08:52:13 -07003083 /*
3084 * Convert distance from out prox to distance from tablet.
3085 * distance will be greater than distance_max once
3086 * touching and applying pressure; do not report negative
3087 * distance.
3088 */
Ping Cheng961794a2013-12-05 12:54:53 -08003089 if (data[8] <= features->distance_max)
3090 d = features->distance_max - data[8];
Ping Cheng01499312015-03-20 14:58:01 -07003091 } else {
3092 wacom->id[0] = 0;
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003093 }
3094
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003095 if (wacom->reporting_data) {
3096 input_report_key(input, BTN_TOUCH, pen);
3097 input_report_key(input, BTN_STYLUS, btn1);
3098 input_report_key(input, BTN_STYLUS2, btn2);
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003099
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003100 if (prox || !range) {
3101 input_report_abs(input, ABS_X, x);
3102 input_report_abs(input, ABS_Y, y);
3103 }
3104 input_report_abs(input, ABS_PRESSURE, p);
3105 input_report_abs(input, ABS_DISTANCE, d);
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003106
Jason Gerecke8947b0c2018-05-18 07:17:18 -07003107 input_report_key(input, wacom->tool[0], range); /* PEN or RUBBER */
3108 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
3109 }
3110
3111 if (!range) {
3112 wacom->reporting_data = false;
3113 }
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003114
3115 return 1;
3116}
3117
Chris Bagwelle1d38e42010-09-12 00:09:27 -07003118static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
3119{
Ping Chengeda01da2015-09-23 13:51:15 -07003120 struct wacom_features *features = &wacom->features;
3121
3122 if ((features->type == INTUOSHT2) &&
Ping Chengeda01da2015-09-23 13:51:15 -07003123 (features->device_type & WACOM_DEVICETYPE_PEN))
3124 return wacom_intuos_irq(wacom);
3125 else if (len == WACOM_PKGLEN_BBTOUCH)
Chris Bagwelle1d38e42010-09-12 00:09:27 -07003126 return wacom_bpt_touch(wacom);
Chris Bagwell73149ab2011-10-26 22:34:21 -07003127 else if (len == WACOM_PKGLEN_BBTOUCH3)
3128 return wacom_bpt3_touch(wacom);
3129 else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
Chris Bagwell2aaacb12010-09-12 00:11:35 -07003130 return wacom_bpt_pen(wacom);
Chris Bagwelle1d38e42010-09-12 00:09:27 -07003131
3132 return 0;
3133}
3134
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003135static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
3136 unsigned char *data)
3137{
3138 unsigned char prefix;
3139
3140 /*
3141 * We need to reroute the event from the debug interface to the
3142 * pen interface.
3143 * We need to add the report ID to the actual pen report, so we
3144 * temporary overwrite the first byte to prevent having to kzalloc/kfree
3145 * and memcpy the report.
3146 */
3147 prefix = data[0];
3148 data[0] = WACOM_REPORT_BPAD_PEN;
3149
3150 /*
3151 * actually reroute the event.
3152 * No need to check if wacom->shared->pen is valid, hid_input_report()
3153 * will check for us.
3154 */
3155 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
3156 WACOM_PKGLEN_PENABLED, 1);
3157
3158 data[0] = prefix;
3159}
3160
3161static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
3162 unsigned char *data)
3163{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003164 struct input_dev *input = wacom->touch_input;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003165 unsigned char *finger_data, prefix;
3166 unsigned id;
3167 int x, y;
3168 bool valid;
3169
3170 prefix = data[0];
3171
3172 for (id = 0; id < wacom->features.touch_max; id++) {
3173 valid = !!(prefix & BIT(id)) &&
Ping Cheng1924e052016-08-09 14:38:56 -07003174 report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003175
3176 input_mt_slot(input, id);
3177 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
3178
3179 if (!valid)
3180 continue;
3181
3182 finger_data = data + 1 + id * 3;
3183 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
3184 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
3185
3186 input_report_abs(input, ABS_MT_POSITION_X, x);
3187 input_report_abs(input, ABS_MT_POSITION_Y, y);
3188 }
3189
3190 input_mt_sync_frame(input);
3191
3192 input_report_key(input, BTN_LEFT, prefix & 0x40);
3193 input_report_key(input, BTN_RIGHT, prefix & 0x80);
3194
3195 /* keep touch state for pen event */
Ping Cheng1924e052016-08-09 14:38:56 -07003196 wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003197
3198 return 1;
3199}
3200
3201static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
3202{
3203 unsigned char *data = wacom->data;
3204
3205 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
3206 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
3207 (data[0] != WACOM_REPORT_BPAD_TOUCH))
3208 return 0;
3209
3210 if (data[1] & 0x01)
3211 wacom_bamboo_pad_pen_event(wacom, &data[1]);
3212
3213 if (data[1] & 0x02)
3214 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
3215
3216 return 0;
3217}
3218
Chris Bagwelld3825d52012-03-25 23:26:11 -07003219static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
3220{
Chris Bagwell16bf2882012-03-25 23:26:20 -07003221 unsigned char *data = wacom->data;
3222 int connected;
3223
Ping Chengb5fd2a32013-11-25 18:44:55 -08003224 if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
Chris Bagwelld3825d52012-03-25 23:26:11 -07003225 return 0;
3226
Chris Bagwell16bf2882012-03-25 23:26:20 -07003227 connected = data[1] & 0x01;
3228 if (connected) {
Jason Gereckeb0882cb2015-03-06 11:47:43 -08003229 int pid, battery, charging;
Chris Bagwell16bf2882012-03-25 23:26:20 -07003230
Ping Chengeda01da2015-09-23 13:51:15 -07003231 if ((wacom->shared->type == INTUOSHT ||
3232 wacom->shared->type == INTUOSHT2) &&
Ping Cheng44b96832014-11-06 17:30:51 -08003233 wacom->shared->touch_input &&
3234 wacom->shared->touch_max) {
Ping Cheng961794a2013-12-05 12:54:53 -08003235 input_report_switch(wacom->shared->touch_input,
3236 SW_MUTE_DEVICE, data[5] & 0x40);
3237 input_sync(wacom->shared->touch_input);
3238 }
3239
Chris Bagwell16bf2882012-03-25 23:26:20 -07003240 pid = get_unaligned_be16(&data[6]);
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003241 battery = (data[5] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08003242 charging = !!(data[5] & 0x80);
Chris Bagwell16bf2882012-03-25 23:26:20 -07003243 if (wacom->pid != pid) {
3244 wacom->pid = pid;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003245 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Chris Bagwell16bf2882012-03-25 23:26:20 -07003246 }
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003247
Jason Gerecke16e45982017-04-28 09:25:33 -07003248 wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
3249 battery, charging, 1, 0);
Jason Gerecke953f2c52015-03-06 11:47:39 -08003250
Chris Bagwell16bf2882012-03-25 23:26:20 -07003251 } else if (wacom->pid != 0) {
3252 /* disconnected while previously connected */
3253 wacom->pid = 0;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003254 wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
Jason Gerecke16e45982017-04-28 09:25:33 -07003255 wacom_notify_battery(wacom, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
Chris Bagwell16bf2882012-03-25 23:26:20 -07003256 }
3257
Chris Bagwelld3825d52012-03-25 23:26:11 -07003258 return 0;
3259}
3260
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003261static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
3262{
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003263 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003264 struct wacom_features *features = &wacom_wac->features;
3265 unsigned char *data = wacom_wac->data;
3266
3267 if (data[0] != WACOM_REPORT_USB)
3268 return 0;
3269
Ping Chengeda01da2015-09-23 13:51:15 -07003270 if ((features->type == INTUOSHT ||
3271 features->type == INTUOSHT2) &&
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003272 wacom_wac->shared->touch_input &&
3273 features->touch_max) {
3274 input_report_switch(wacom_wac->shared->touch_input,
3275 SW_MUTE_DEVICE, data[8] & 0x40);
3276 input_sync(wacom_wac->shared->touch_input);
3277 }
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003278
3279 if (data[9] & 0x02) { /* wireless module is attached */
3280 int battery = (data[8] & 0x3f) * 100 / 31;
Jason Gereckeb0882cb2015-03-06 11:47:43 -08003281 bool charging = !!(data[8] & 0x80);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003282
Jason Gerecke16e45982017-04-28 09:25:33 -07003283 wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
3284 battery, charging, battery || charging, 1);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003285
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02003286 if (!wacom->battery.battery &&
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003287 !(features->quirks & WACOM_QUIRK_BATTERY)) {
3288 features->quirks |= WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003289 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003290 }
3291 }
3292 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
Benjamin Tissoires59d69bc2016-07-13 18:06:08 +02003293 wacom->battery.battery) {
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003294 features->quirks &= ~WACOM_QUIRK_BATTERY;
Benjamin Tissoiresd17d1f12016-07-13 18:05:52 +02003295 wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
Jason Gerecke16e45982017-04-28 09:25:33 -07003296 wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
Jason Gerecke8f93b0b2015-03-06 11:47:41 -08003297 }
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003298 return 0;
3299}
3300
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003301void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
Ping Cheng3bea7332006-07-13 18:01:36 -07003302{
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003303 bool sync;
3304
Jason Childse33da8a2010-02-17 22:38:31 -08003305 switch (wacom_wac->features.type) {
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003306 case PENPARTNER:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003307 sync = wacom_penpartner_irq(wacom_wac);
3308 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003309
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003310 case PL:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003311 sync = wacom_pl_irq(wacom_wac);
3312 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003313
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003314 case WACOM_G4:
3315 case GRAPHIRE:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07003316 case GRAPHIRE_BT:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003317 case WACOM_MO:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003318 sync = wacom_graphire_irq(wacom_wac);
3319 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003320
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003321 case PTU:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003322 sync = wacom_ptu_irq(wacom_wac);
3323 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003324
Ping Chengc8f2edc2010-06-28 01:10:51 -07003325 case DTU:
3326 sync = wacom_dtu_irq(wacom_wac);
3327 break;
3328
Ping Cheng497ab1f2014-01-20 20:18:04 -08003329 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08003330 case DTUSX:
Ping Cheng497ab1f2014-01-20 20:18:04 -08003331 sync = wacom_dtus_irq(wacom_wac);
3332 break;
3333
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003334 case INTUOS:
3335 case INTUOS3S:
3336 case INTUOS3:
3337 case INTUOS3L:
3338 case INTUOS4S:
3339 case INTUOS4:
3340 case INTUOS4L:
3341 case CINTIQ:
3342 case WACOM_BEE:
Ping Cheng56218562013-05-05 19:56:18 -07003343 case WACOM_13HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003344 case WACOM_21UX2:
Ping Chengd838c642012-07-24 23:54:11 -07003345 case WACOM_22HD:
Jason Gerecke803296b2011-12-12 00:11:45 -08003346 case WACOM_24HD:
Ping Cheng500d4162015-01-27 13:30:03 -08003347 case WACOM_27QHD:
Ping Chenga112e9f2013-02-13 20:20:01 -08003348 case DTK:
Jason Gerecke36d3c512013-09-20 09:47:35 -07003349 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003350 case CINTIQ_COMPANION_2:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003351 sync = wacom_intuos_irq(wacom_wac);
3352 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003353
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07003354 case INTUOS4WL:
3355 sync = wacom_intuos_bt_irq(wacom_wac, len);
3356 break;
3357
Jason Gereckeb1e42792012-10-21 00:38:04 -07003358 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08003359 case WACOM_27QHDT:
Jason Gereckeb1e42792012-10-21 00:38:04 -07003360 sync = wacom_24hdt_irq(wacom_wac);
3361 break;
3362
Jason Gereckeae584ca2012-04-03 15:50:40 -07003363 case INTUOS5S:
3364 case INTUOS5:
3365 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07003366 case INTUOSPS:
3367 case INTUOSPM:
3368 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07003369 if (len == WACOM_PKGLEN_BBTOUCH3)
3370 sync = wacom_bpt3_touch(wacom_wac);
Jason Gerecke2d13a432015-03-06 11:47:42 -08003371 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
3372 sync = wacom_status_irq(wacom_wac, len);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003373 else
3374 sync = wacom_intuos_irq(wacom_wac);
3375 break;
3376
Jason Gerecke4922cd22017-01-25 12:08:37 -08003377 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003378 case INTUOSP2S_BT:
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08003379 case INTUOSHT3_BT:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003380 sync = wacom_intuos_pro2_bt_irq(wacom_wac, len);
3381 break;
3382
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003383 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07003384 case TABLETPCE:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003385 case TABLETPC2FG:
Ping Cheng19635182012-04-29 21:09:18 -07003386 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07003387 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07003388 case MTTPC_B:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003389 sync = wacom_tpc_irq(wacom_wac, len);
3390 break;
Ping Cheng545f4e92008-11-24 11:44:27 -05003391
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003392 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003393 case BAMBOO_PEN:
3394 case BAMBOO_TOUCH:
Ping Chengb5fd2a32013-11-25 18:44:55 -08003395 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07003396 case INTUOSHT2:
Jason Gerecke4ca4ec72015-03-06 11:47:38 -08003397 if (wacom_wac->data[0] == WACOM_REPORT_USB)
3398 sync = wacom_status_irq(wacom_wac, len);
3399 else
3400 sync = wacom_bpt_irq(wacom_wac, len);
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003401 break;
3402
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003403 case BAMBOO_PAD:
3404 sync = wacom_bamboo_pad_irq(wacom_wac, len);
Ping Cheng3bea7332006-07-13 18:01:36 -07003405 break;
3406
Chris Bagwelld3825d52012-03-25 23:26:11 -07003407 case WIRELESS:
3408 sync = wacom_wireless_irq(wacom_wac, len);
3409 break;
3410
Aaron Skomra72b236d2015-08-20 16:05:17 -07003411 case REMOTE:
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02003412 sync = false;
Aaron Skomra72b236d2015-08-20 16:05:17 -07003413 if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
Benjamin Tissoirese6f28132016-07-13 18:06:01 +02003414 wacom_remote_status_irq(wacom_wac, len);
Aaron Skomra72b236d2015-08-20 16:05:17 -07003415 else
3416 sync = wacom_remote_irq(wacom_wac, len);
3417 break;
3418
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003419 default:
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003420 sync = false;
3421 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07003422 }
Dmitry Torokhov95dd3b32010-03-19 22:18:15 -07003423
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003424 if (sync) {
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003425 if (wacom_wac->pen_input)
3426 input_sync(wacom_wac->pen_input);
3427 if (wacom_wac->touch_input)
3428 input_sync(wacom_wac->touch_input);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07003429 if (wacom_wac->pad_input)
3430 input_sync(wacom_wac->pad_input);
3431 }
Ping Cheng3bea7332006-07-13 18:01:36 -07003432}
3433
Ping Chengeda01da2015-09-23 13:51:15 -07003434static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
Ping Cheng3bea7332006-07-13 18:01:36 -07003435{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003436 struct input_dev *input_dev = wacom_wac->pen_input;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003437
3438 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003439
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003440 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003441 __set_bit(BTN_STYLUS, input_dev->keybit);
3442 __set_bit(BTN_STYLUS2, input_dev->keybit);
3443
3444 input_set_abs_params(input_dev, ABS_DISTANCE,
Jason Gereckebef7e202016-04-22 14:30:53 -07003445 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07003446}
3447
3448static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
3449{
3450 struct input_dev *input_dev = wacom_wac->pen_input;
Jason Gereckebef7e202016-04-22 14:30:53 -07003451 struct wacom_features *features = &wacom_wac->features;
Ping Chengeda01da2015-09-23 13:51:15 -07003452
3453 wacom_setup_basic_pro_pen(wacom_wac);
3454
3455 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3456 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
3457 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
3458 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
3459
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003460 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
Jason Gereckebef7e202016-04-22 14:30:53 -07003461 input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003462 input_abs_set_res(input_dev, ABS_TILT_X, 57);
Jason Gereckebef7e202016-04-22 14:30:53 -07003463 input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003464 input_abs_set_res(input_dev, ABS_TILT_Y, 57);
Ping Cheng6521d0b2010-10-24 21:53:40 -07003465}
3466
3467static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
3468{
Jason Gerecke2a6cdbd2015-06-15 18:01:45 -07003469 struct input_dev *input_dev = wacom_wac->pen_input;
Ping Cheng6521d0b2010-10-24 21:53:40 -07003470
3471 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3472
3473 wacom_setup_cintiq(wacom_wac);
3474
3475 __set_bit(BTN_LEFT, input_dev->keybit);
3476 __set_bit(BTN_RIGHT, input_dev->keybit);
3477 __set_bit(BTN_MIDDLE, input_dev->keybit);
3478 __set_bit(BTN_SIDE, input_dev->keybit);
3479 __set_bit(BTN_EXTRA, input_dev->keybit);
3480 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3481 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
3482
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003483 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003484 input_abs_set_res(input_dev, ABS_RZ, 287);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003485 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
3486}
3487
Ping Cheng42f4f272015-04-15 16:53:54 -07003488void wacom_setup_device_quirks(struct wacom *wacom)
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003489{
Jason Gerecke11db8172018-10-10 13:40:26 -07003490 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Ping Cheng42f4f272015-04-15 16:53:54 -07003491 struct wacom_features *features = &wacom->wacom_wac.features;
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003492
Jason Gerecke862cf552015-06-15 18:01:43 -07003493 /* The pen and pad share the same interface on most devices */
3494 if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
Ping Cheng3b164a02015-09-23 09:59:10 -07003495 features->type == DTUS ||
3496 (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
Jason Gerecke862cf552015-06-15 18:01:43 -07003497 if (features->device_type & WACOM_DEVICETYPE_PEN)
3498 features->device_type |= WACOM_DEVICETYPE_PAD;
3499 }
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003500
3501 /* touch device found but size is not defined. use default */
Jason Gereckeaa86b182015-06-15 18:01:42 -07003502 if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003503 features->x_max = 1023;
3504 features->y_max = 1023;
3505 }
3506
Ping Cheng42f4f272015-04-15 16:53:54 -07003507 /*
3508 * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
3509 * touch interface in its HID descriptor. If this is the touch
3510 * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
3511 * tablet values.
3512 */
Ping Cheng3b164a02015-09-23 09:59:10 -07003513 if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
3514 (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
Ping Cheng42f4f272015-04-15 16:53:54 -07003515 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
Jason Gerecke862cf552015-06-15 18:01:43 -07003516 if (features->touch_max)
3517 features->device_type |= WACOM_DEVICETYPE_TOUCH;
Jiri Kosinaa3088ab2015-11-17 00:24:14 +01003518 if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
Jason Gerecke862cf552015-06-15 18:01:43 -07003519 features->device_type |= WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07003520
Jason Gerecke3b8d5732018-06-26 09:58:02 -07003521 if (features->type == INTUOSHT2) {
3522 features->x_max = features->x_max / 10;
3523 features->y_max = features->y_max / 10;
3524 }
3525 else {
3526 features->x_max = 4096;
3527 features->y_max = 4096;
3528 }
Ping Cheng42f4f272015-04-15 16:53:54 -07003529 }
Jason Gerecke96339202015-07-01 13:01:00 -07003530 else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
3531 features->device_type |= WACOM_DEVICETYPE_PAD;
3532 }
Ping Cheng42f4f272015-04-15 16:53:54 -07003533 }
3534
3535 /*
Benjamin Tissoires580549e2016-03-25 15:26:55 +01003536 * Hack for the Bamboo One:
3537 * the device presents a PAD/Touch interface as most Bamboos and even
3538 * sends ghosts PAD data on it. However, later, we must disable this
3539 * ghost interface, and we can not detect it unless we set it here
3540 * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
3541 */
3542 if (features->type == BAMBOO_PEN &&
3543 features->pktlen == WACOM_PKGLEN_BBTOUCH3)
3544 features->device_type |= WACOM_DEVICETYPE_PAD;
3545
3546 /*
Jason Gerecke042628a2015-04-30 17:51:54 -07003547 * Raw Wacom-mode pen and touch events both come from interface
3548 * 0, whose HID descriptor has an application usage of 0xFF0D
Jason Gerecke8de82282016-10-19 18:03:37 -07003549 * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
Jason Gerecke042628a2015-04-30 17:51:54 -07003550 * out through the HID_GENERIC device created for interface 1,
Benjamin Tissoires70caee0a2015-07-09 14:11:51 -04003551 * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
Ping Cheng42f4f272015-04-15 16:53:54 -07003552 */
3553 if (features->type == BAMBOO_PAD)
Benjamin Tissoires70caee0a2015-07-09 14:11:51 -04003554 features->device_type = WACOM_DEVICETYPE_TOUCH;
Ping Cheng42f4f272015-04-15 16:53:54 -07003555
Aaron Skomra72b236d2015-08-20 16:05:17 -07003556 if (features->type == REMOTE)
3557 features->device_type = WACOM_DEVICETYPE_PAD;
Ping Cheng42f4f272015-04-15 16:53:54 -07003558
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003559 if (features->type == INTUOSP2_BT ||
3560 features->type == INTUOSP2S_BT) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08003561 features->device_type |= WACOM_DEVICETYPE_PEN |
3562 WACOM_DEVICETYPE_PAD |
3563 WACOM_DEVICETYPE_TOUCH;
3564 features->quirks |= WACOM_QUIRK_BATTERY;
3565 }
3566
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08003567 if (features->type == INTUOSHT3_BT) {
3568 features->device_type |= WACOM_DEVICETYPE_PEN |
3569 WACOM_DEVICETYPE_PAD;
3570 features->quirks |= WACOM_QUIRK_BATTERY;
3571 }
3572
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003573 switch (features->type) {
3574 case PL:
3575 case DTU:
3576 case DTUS:
3577 case DTUSX:
3578 case WACOM_21UX2:
3579 case WACOM_22HD:
3580 case DTK:
3581 case WACOM_24HD:
3582 case WACOM_27QHD:
3583 case CINTIQ_HYBRID:
3584 case CINTIQ_COMPANION_2:
3585 case CINTIQ:
3586 case WACOM_BEE:
3587 case WACOM_13HD:
3588 case WACOM_24HDT:
3589 case WACOM_27QHDT:
3590 case TABLETPC:
3591 case TABLETPCE:
3592 case TABLETPC2FG:
3593 case MTSCREEN:
3594 case MTTPC:
3595 case MTTPC_B:
3596 features->device_type |= WACOM_DEVICETYPE_DIRECT;
3597 break;
3598 }
3599
Ping Cheng42f4f272015-04-15 16:53:54 -07003600 if (wacom->hdev->bus == BUS_BLUETOOTH)
3601 features->quirks |= WACOM_QUIRK_BATTERY;
3602
Chris Bagwell73149ab2011-10-26 22:34:21 -07003603 /* quirk for bamboo touch with 2 low res touches */
Jason Gereckebe853fd2015-12-04 14:45:27 -08003604 if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
Chris Bagwell73149ab2011-10-26 22:34:21 -07003605 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07003606 features->x_max <<= 5;
3607 features->y_max <<= 5;
3608 features->x_fuzz <<= 5;
3609 features->y_fuzz <<= 5;
Henrik Rydbergf4ccbef2010-09-05 12:57:13 -07003610 features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003611 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07003612
3613 if (features->type == WIRELESS) {
Jason Gereckeccad85c2015-08-03 10:17:04 -07003614 if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07003615 features->quirks |= WACOM_QUIRK_BATTERY;
3616 }
Chris Bagwelld3825d52012-03-25 23:26:11 -07003617 }
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02003618
3619 if (features->type == REMOTE)
3620 features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
Jason Gerecke11db8172018-10-10 13:40:26 -07003621
3622 /* HID descriptor for DTK-2451 / DTH-2452 claims to report lots
3623 * of things it shouldn't. Lets fix up the damage...
3624 */
3625 if (wacom->hdev->product == 0x382 || wacom->hdev->product == 0x37d) {
3626 features->quirks &= ~WACOM_QUIRK_TOOLSERIAL;
3627 __clear_bit(BTN_TOOL_BRUSH, wacom_wac->pen_input->keybit);
3628 __clear_bit(BTN_TOOL_PENCIL, wacom_wac->pen_input->keybit);
3629 __clear_bit(BTN_TOOL_AIRBRUSH, wacom_wac->pen_input->keybit);
3630 __clear_bit(ABS_Z, wacom_wac->pen_input->absbit);
3631 __clear_bit(ABS_DISTANCE, wacom_wac->pen_input->absbit);
3632 __clear_bit(ABS_TILT_X, wacom_wac->pen_input->absbit);
3633 __clear_bit(ABS_TILT_Y, wacom_wac->pen_input->absbit);
3634 __clear_bit(ABS_WHEEL, wacom_wac->pen_input->absbit);
3635 __clear_bit(ABS_MISC, wacom_wac->pen_input->absbit);
3636 __clear_bit(MSC_SERIAL, wacom_wac->pen_input->mscbit);
3637 __clear_bit(EV_MSC, wacom_wac->pen_input->evbit);
3638 }
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07003639}
3640
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003641int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
Ping Cheng19635182012-04-29 21:09:18 -07003642 struct wacom_wac *wacom_wac)
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003643{
3644 struct wacom_features *features = &wacom_wac->features;
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003645
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003646 if (!(features->device_type & WACOM_DEVICETYPE_PEN))
3647 return -ENODEV;
3648
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003649 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3650 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3651 else
3652 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3653
Ping Cheng46fc4662021-04-05 20:46:34 -07003654 if (features->type == HID_GENERIC)
3655 /* setup has already been done */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04003656 return 0;
3657
Ping Cheng276559d2021-03-11 11:30:09 -08003658 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003659 __set_bit(BTN_TOUCH, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003660 __set_bit(ABS_MISC, input_dev->absbit);
3661
Jason Gereckee779ef22016-10-19 18:03:49 -07003662 input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
3663 features->x_max - features->offset_right,
3664 features->x_fuzz, 0);
3665 input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
3666 features->y_max - features->offset_bottom,
3667 features->y_fuzz, 0);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003668 input_set_abs_params(input_dev, ABS_PRESSURE, 0,
3669 features->pressure_max, features->pressure_fuzz, 0);
3670
3671 /* penabled devices have fixed resolution for each model */
3672 input_abs_set_res(input_dev, ABS_X, features->x_resolution);
3673 input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
3674
Ping Cheng497ab1f2014-01-20 20:18:04 -08003675 switch (features->type) {
Ping Chenga2f71c62015-01-27 13:29:36 -08003676 case GRAPHIRE_BT:
3677 __clear_bit(ABS_MISC, input_dev->absbit);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003678 fallthrough;
Ping Chenga2f71c62015-01-27 13:29:36 -08003679
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003680 case WACOM_MO:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003681 case WACOM_G4:
Ping Chenga2f71c62015-01-27 13:29:36 -08003682 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3683 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003684 features->distance_fuzz, 0);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003685 fallthrough;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003686
3687 case GRAPHIRE:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003688 input_set_capability(input_dev, EV_REL, REL_WHEEL);
3689
3690 __set_bit(BTN_LEFT, input_dev->keybit);
3691 __set_bit(BTN_RIGHT, input_dev->keybit);
3692 __set_bit(BTN_MIDDLE, input_dev->keybit);
3693
3694 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3695 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3696 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
3697 __set_bit(BTN_STYLUS, input_dev->keybit);
3698 __set_bit(BTN_STYLUS2, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003699 break;
3700
Ping Cheng500d4162015-01-27 13:30:03 -08003701 case WACOM_27QHD:
Jason Gerecke803296b2011-12-12 00:11:45 -08003702 case WACOM_24HD:
Ping Chenga112e9f2013-02-13 20:20:01 -08003703 case DTK:
Ping Chengd838c642012-07-24 23:54:11 -07003704 case WACOM_22HD:
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07003705 case WACOM_21UX2:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003706 case WACOM_BEE:
Ping Cheng6521d0b2010-10-24 21:53:40 -07003707 case CINTIQ:
Ping Cheng56218562013-05-05 19:56:18 -07003708 case WACOM_13HD:
Ping Chenga2f71c62015-01-27 13:29:36 -08003709 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07003710 case CINTIQ_COMPANION_2:
Ping Cheng56218562013-05-05 19:56:18 -07003711 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003712 input_abs_set_res(input_dev, ABS_Z, 287);
Ping Cheng56218562013-05-05 19:56:18 -07003713 wacom_setup_cintiq(wacom_wac);
3714 break;
3715
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003716 case INTUOS3:
3717 case INTUOS3L:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003718 case INTUOS3S:
Ping Chenga2f71c62015-01-27 13:29:36 -08003719 case INTUOS4:
3720 case INTUOS4WL:
3721 case INTUOS4L:
3722 case INTUOS4S:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003723 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
Jason Gerecke26fe4122014-11-18 16:50:09 -08003724 input_abs_set_res(input_dev, ABS_Z, 287);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003725 fallthrough;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003726
3727 case INTUOS:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003728 wacom_setup_intuos(wacom_wac);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003729 break;
3730
Jason Gerecke9fee6192012-04-03 15:47:22 -07003731 case INTUOS5:
3732 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -07003733 case INTUOSPM:
3734 case INTUOSPL:
Jason Gereckeae584ca2012-04-03 15:50:40 -07003735 case INTUOS5S:
Ping Cheng9a35c412013-09-20 09:51:56 -07003736 case INTUOSPS:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003737 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003738 case INTUOSP2S_BT:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003739 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
3740 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003741 features->distance_fuzz, 0);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003742
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003743 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
3744 input_abs_set_res(input_dev, ABS_Z, 287);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003745
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003746 wacom_setup_intuos(wacom_wac);
Jason Gereckeae584ca2012-04-03 15:50:40 -07003747 break;
3748
Jason Gereckeb1e42792012-10-21 00:38:04 -07003749 case WACOM_24HDT:
Ping Cheng500d4162015-01-27 13:30:03 -08003750 case WACOM_27QHDT:
Ping Cheng19635182012-04-29 21:09:18 -07003751 case MTSCREEN:
Ping Cheng6afdc282012-11-03 12:16:15 -07003752 case MTTPC:
Jason Gerecked51ddb22014-05-14 17:14:29 -07003753 case MTTPC_B:
Ping Cheng6795a522012-06-28 16:49:00 -07003754 case TABLETPC2FG:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003755 case TABLETPC:
Ping Chengac173832012-06-12 00:15:06 -07003756 case TABLETPCE:
Ping Chenga43c7c52011-03-12 20:34:42 -08003757 __clear_bit(ABS_MISC, input_dev->absbit);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003758 fallthrough;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003759
Ping Cheng497ab1f2014-01-20 20:18:04 -08003760 case DTUS:
Ping Chengfff00bf2014-12-04 18:23:04 -08003761 case DTUSX:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003762 case PL:
Ping Chengc8f2edc2010-06-28 01:10:51 -07003763 case DTU:
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003764 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003765 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003766 __set_bit(BTN_STYLUS, input_dev->keybit);
3767 __set_bit(BTN_STYLUS2, input_dev->keybit);
Jason Gerecke35120692011-09-08 09:38:14 -07003768 break;
3769
3770 case PTU:
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003771 __set_bit(BTN_STYLUS2, input_dev->keybit);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003772 fallthrough;
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003773
3774 case PENPARTNER:
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003775 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
Dmitry Torokhov8da23fc2010-03-19 22:18:15 -07003776 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
Jason Gerecke1fab84a2011-08-26 23:18:22 -07003777 __set_bit(BTN_STYLUS, input_dev->keybit);
Dmitry Torokhov73a97f42010-03-19 22:18:15 -07003778 break;
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003779
Ping Chengb5fd2a32013-11-25 18:44:55 -08003780 case INTUOSHT:
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003781 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003782 case BAMBOO_PEN:
Ping Chengeda01da2015-09-23 13:51:15 -07003783 case INTUOSHT2:
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08003784 case INTUOSHT3_BT:
3785 if (features->type == INTUOSHT2 ||
3786 features->type == INTUOSHT3_BT) {
Ping Chengeda01da2015-09-23 13:51:15 -07003787 wacom_setup_basic_pro_pen(wacom_wac);
3788 } else {
3789 __clear_bit(ABS_MISC, input_dev->absbit);
3790 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
3791 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3792 __set_bit(BTN_STYLUS, input_dev->keybit);
3793 __set_bit(BTN_STYLUS2, input_dev->keybit);
3794 input_set_abs_params(input_dev, ABS_DISTANCE, 0,
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003795 features->distance_max,
Jason Gereckebef7e202016-04-22 14:30:53 -07003796 features->distance_fuzz, 0);
Ping Chengeda01da2015-09-23 13:51:15 -07003797 }
Henrik Rydbergcb734c02010-09-05 12:53:16 -07003798 break;
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003799 case BAMBOO_PAD:
3800 __clear_bit(ABS_MISC, input_dev->absbit);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003801 break;
3802 }
3803 return 0;
3804}
3805
3806int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
3807 struct wacom_wac *wacom_wac)
3808{
3809 struct wacom_features *features = &wacom_wac->features;
3810
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003811 if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
3812 return -ENODEV;
3813
Jason Gereckee5bc8eb2016-08-08 12:06:29 -07003814 if (features->device_type & WACOM_DEVICETYPE_DIRECT)
3815 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
3816 else
3817 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
3818
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003819 if (features->type == HID_GENERIC)
3820 /* setup has already been done */
3821 return 0;
3822
Ping Cheng276559d2021-03-11 11:30:09 -08003823 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003824 __set_bit(BTN_TOUCH, input_dev->keybit);
3825
3826 if (features->touch_max == 1) {
3827 input_set_abs_params(input_dev, ABS_X, 0,
3828 features->x_max, features->x_fuzz, 0);
3829 input_set_abs_params(input_dev, ABS_Y, 0,
3830 features->y_max, features->y_fuzz, 0);
3831 input_abs_set_res(input_dev, ABS_X,
3832 features->x_resolution);
3833 input_abs_set_res(input_dev, ABS_Y,
3834 features->y_resolution);
3835 }
3836 else if (features->touch_max > 1) {
3837 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
3838 features->x_max, features->x_fuzz, 0);
3839 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
3840 features->y_max, features->y_fuzz, 0);
3841 input_abs_set_res(input_dev, ABS_MT_POSITION_X,
3842 features->x_resolution);
3843 input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
3844 features->y_resolution);
3845 }
3846
3847 switch (features->type) {
Jason Gerecke4922cd22017-01-25 12:08:37 -08003848 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003849 case INTUOSP2S_BT:
Jason Gerecke4922cd22017-01-25 12:08:37 -08003850 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3851 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
3852
3853 if (wacom_wac->shared->touch->product == 0x361) {
3854 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3855 0, 12440, 4, 0);
3856 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3857 0, 8640, 4, 0);
3858 }
3859 else if (wacom_wac->shared->touch->product == 0x360) {
3860 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3861 0, 8960, 4, 0);
3862 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3863 0, 5920, 4, 0);
3864 }
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07003865 else if (wacom_wac->shared->touch->product == 0x393) {
3866 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
3867 0, 6400, 4, 0);
3868 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
3869 0, 4000, 4, 0);
3870 }
Jason Gerecke4922cd22017-01-25 12:08:37 -08003871 input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
Aaron Armstrong Skomra68c20cc2019-05-10 15:34:18 -07003872 input_abs_set_res(input_dev, ABS_MT_POSITION_Y, 40);
Jason Gerecke4922cd22017-01-25 12:08:37 -08003873
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003874 fallthrough;
Jason Gerecke4922cd22017-01-25 12:08:37 -08003875
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003876 case INTUOS5:
3877 case INTUOS5L:
3878 case INTUOSPM:
3879 case INTUOSPL:
3880 case INTUOS5S:
3881 case INTUOSPS:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003882 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3883 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
3884 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3885 break;
3886
3887 case WACOM_24HDT:
3888 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
3889 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
3890 input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
3891 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003892 fallthrough;
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003893
3894 case WACOM_27QHDT:
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07003895 if (wacom_wac->shared->touch->product == 0x32C ||
3896 wacom_wac->shared->touch->product == 0xF6) {
3897 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3898 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
Jason Gerecke6ca23502021-07-19 13:55:28 -07003899 wacom_wac->has_mute_touch_switch = true;
Ping Chengdc9dc862021-07-19 13:55:29 -07003900 wacom_wac->is_soft_touch_switch = true;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07003901 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003902 fallthrough;
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07003903
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003904 case MTSCREEN:
3905 case MTTPC:
3906 case MTTPC_B:
3907 case TABLETPC2FG:
3908 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003909 fallthrough;
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003910
3911 case TABLETPC:
3912 case TABLETPCE:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003913 break;
3914
3915 case INTUOSHT:
Ping Chengeda01da2015-09-23 13:51:15 -07003916 case INTUOSHT2:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003917 input_dev->evbit[0] |= BIT_MASK(EV_SW);
3918 __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003919 fallthrough;
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003920
3921 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07003922 case BAMBOO_TOUCH:
Jason Gerecke2636a3f2015-06-15 18:01:44 -07003923 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
3924 input_set_abs_params(input_dev,
3925 ABS_MT_TOUCH_MAJOR,
3926 0, features->x_max, 0, 0);
3927 input_set_abs_params(input_dev,
3928 ABS_MT_TOUCH_MINOR,
3929 0, features->y_max, 0, 0);
3930 }
3931 input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
3932 break;
3933
3934 case BAMBOO_PAD:
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05003935 input_mt_init_slots(input_dev, features->touch_max,
3936 INPUT_MT_POINTER);
3937 __set_bit(BTN_LEFT, input_dev->keybit);
3938 __set_bit(BTN_RIGHT, input_dev->keybit);
3939 break;
Ping Cheng3bea7332006-07-13 18:01:36 -07003940 }
Ping Cheng19635182012-04-29 21:09:18 -07003941 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -07003942}
3943
Jason Gerecke49005b92016-10-19 18:03:39 -07003944static int wacom_numbered_button_to_key(int n)
3945{
3946 if (n < 10)
3947 return BTN_0 + n;
3948 else if (n < 16)
3949 return BTN_A + (n-10);
3950 else if (n < 18)
3951 return BTN_BASE + (n-16);
3952 else
3953 return 0;
3954}
3955
Jiri Kosina5397df12015-08-28 20:46:42 +02003956static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003957 int button_count)
3958{
3959 int i;
3960
Jason Gerecke49005b92016-10-19 18:03:39 -07003961 for (i = 0; i < button_count; i++) {
3962 int key = wacom_numbered_button_to_key(i);
3963
3964 if (key)
3965 __set_bit(key, input_dev->keybit);
3966 }
Aaron Skomra70ee06c2015-08-20 16:05:16 -07003967}
3968
Benjamin Tissoires6a062812016-07-13 18:06:14 +02003969static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
3970{
3971 struct wacom_led *led;
3972 int i;
3973 bool updated = false;
3974
3975 /*
3976 * 24HD has LED group 1 to the left and LED group 0 to the right.
3977 * So group 0 matches the second half of the buttons and thus the mask
3978 * needs to be shifted.
3979 */
3980 if (group == 0)
3981 mask >>= 8;
3982
3983 for (i = 0; i < 3; i++) {
3984 led = wacom_led_find(wacom, group, i);
3985 if (!led) {
3986 hid_err(wacom->hdev, "can't find LED %d in group %d\n",
3987 i, group);
3988 continue;
3989 }
3990 if (!updated && mask & BIT(i)) {
3991 led->held = true;
3992 led_trigger_event(&led->trigger, LED_FULL);
3993 } else {
3994 led->held = false;
3995 }
3996 }
3997}
3998
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02003999static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
4000 int mask, int group)
4001{
Jason Gerecke6441fc72019-05-07 11:53:21 -07004002 int group_button;
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02004003
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02004004 /*
Benjamin Tissoires6a062812016-07-13 18:06:14 +02004005 * 21UX2 has LED group 1 to the left and LED group 0
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02004006 * to the right. We need to reverse the group to match this
4007 * historical behavior.
4008 */
Benjamin Tissoires6a062812016-07-13 18:06:14 +02004009 if (wacom->wacom_wac.features.type == WACOM_21UX2)
Benjamin Tissoires5a0fe8ab2016-07-13 18:06:13 +02004010 group = 1 - group;
4011
Jason Gerecke6441fc72019-05-07 11:53:21 -07004012 group_button = group * (button_count/wacom->led.count);
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02004013
Jason Gerecke6441fc72019-05-07 11:53:21 -07004014 if (wacom->wacom_wac.features.type == INTUOSP2_BT)
4015 group_button = 8;
4016
4017 return mask & (1 << group_button);
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02004018}
4019
4020static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
4021 int group)
4022{
4023 struct wacom_led *led, *next_led;
4024 int cur;
4025 bool pressed;
4026
Benjamin Tissoires6a062812016-07-13 18:06:14 +02004027 if (wacom->wacom_wac.features.type == WACOM_24HD)
4028 return wacom_24hd_update_leds(wacom, mask, group);
4029
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02004030 pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
4031 cur = wacom->led.groups[group].select;
4032
4033 led = wacom_led_find(wacom, group, cur);
4034 if (!led) {
4035 hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
4036 cur, group);
4037 return;
4038 }
4039
4040 if (!pressed) {
4041 led->held = false;
4042 return;
4043 }
4044
4045 if (led->held && pressed)
4046 return;
4047
4048 next_led = wacom_led_next(wacom, led);
4049 if (!next_led) {
4050 hid_err(wacom->hdev, "can't find next LED in group %d\n",
4051 group);
4052 return;
4053 }
4054 if (next_led == led)
4055 return;
4056
4057 next_led->held = true;
4058 led_trigger_event(&next_led->trigger,
4059 wacom_leds_brightness_get(next_led));
4060}
4061
Jason Gereckec7f05222015-11-30 17:13:47 -08004062static void wacom_report_numbered_buttons(struct input_dev *input_dev,
4063 int button_count, int mask)
4064{
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02004065 struct wacom *wacom = input_get_drvdata(input_dev);
Jason Gereckec7f05222015-11-30 17:13:47 -08004066 int i;
4067
Benjamin Tissoires34736aa2016-07-13 18:06:12 +02004068 for (i = 0; i < wacom->led.count; i++)
4069 wacom_update_led(wacom, button_count, mask, i);
4070
Jason Gerecke49005b92016-10-19 18:03:39 -07004071 for (i = 0; i < button_count; i++) {
4072 int key = wacom_numbered_button_to_key(i);
4073
4074 if (key)
4075 input_report_key(input_dev, key, mask & (1 << i));
4076 }
Jason Gereckec7f05222015-11-30 17:13:47 -08004077}
4078
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004079int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
4080 struct wacom_wac *wacom_wac)
4081{
4082 struct wacom_features *features = &wacom_wac->features;
4083
Ping Chenge7deb152017-01-30 15:40:49 -08004084 if ((features->type == HID_GENERIC) && features->numbered_buttons > 0)
4085 features->device_type |= WACOM_DEVICETYPE_PAD;
4086
Jason Gerecke862cf552015-06-15 18:01:43 -07004087 if (!(features->device_type & WACOM_DEVICETYPE_PAD))
4088 return -ENODEV;
4089
Benjamin Tissoires7c35dc32016-07-13 18:06:07 +02004090 if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
4091 return -ENODEV;
4092
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004093 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
4094
4095 /* kept for making legacy xf86-input-wacom working with the wheels */
4096 __set_bit(ABS_MISC, input_dev->absbit);
4097
4098 /* kept for making legacy xf86-input-wacom accepting the pad */
Jason Gerecke5922e612016-10-19 18:03:51 -07004099 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
4100 input_dev->absinfo[ABS_X].maximum)))
4101 input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
4102 if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
4103 input_dev->absinfo[ABS_Y].maximum)))
4104 input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004105
Benjamin Tissoires12969e32014-09-11 13:14:04 -04004106 /* kept for making udev and libwacom accepting the pad */
4107 __set_bit(BTN_STYLUS, input_dev->keybit);
4108
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004109 wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
4110
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004111 switch (features->type) {
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004112
4113 case CINTIQ_HYBRID:
Jason Gereckef7acb552015-10-13 10:03:49 -07004114 case CINTIQ_COMPANION_2:
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004115 case DTK:
4116 case DTUS:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004117 case GRAPHIRE_BT:
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004118 break;
4119
Benjamin Tissoires38138102014-07-24 12:51:03 -07004120 case WACOM_MO:
4121 __set_bit(BTN_BACK, input_dev->keybit);
4122 __set_bit(BTN_LEFT, input_dev->keybit);
4123 __set_bit(BTN_FORWARD, input_dev->keybit);
4124 __set_bit(BTN_RIGHT, input_dev->keybit);
4125 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4126 break;
4127
4128 case WACOM_G4:
4129 __set_bit(BTN_BACK, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07004130 __set_bit(BTN_FORWARD, input_dev->keybit);
Benjamin Tissoires38138102014-07-24 12:51:03 -07004131 input_set_capability(input_dev, EV_REL, REL_WHEEL);
4132 break;
4133
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004134 case WACOM_24HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004135 __set_bit(KEY_PROG1, input_dev->keybit);
4136 __set_bit(KEY_PROG2, input_dev->keybit);
4137 __set_bit(KEY_PROG3, input_dev->keybit);
4138
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07004139 __set_bit(KEY_ONSCREEN_KEYBOARD, input_dev->keybit);
4140 __set_bit(KEY_INFO, input_dev->keybit);
4141
4142 if (!features->oPid)
4143 __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
4144
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004145 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4146 input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
4147 break;
4148
Ping Cheng500d4162015-01-27 13:30:03 -08004149 case WACOM_27QHD:
4150 __set_bit(KEY_PROG1, input_dev->keybit);
4151 __set_bit(KEY_PROG2, input_dev->keybit);
4152 __set_bit(KEY_PROG3, input_dev->keybit);
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07004153
4154 __set_bit(KEY_ONSCREEN_KEYBOARD, input_dev->keybit);
4155 __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
4156
4157 if (!features->oPid)
4158 __set_bit(KEY_CONTROLPANEL, input_dev->keybit);
Ping Cheng500d4162015-01-27 13:30:03 -08004159 input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
4160 input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
4161 input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
4162 input_abs_set_res(input_dev, ABS_Y, 1024);
4163 input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
4164 input_abs_set_res(input_dev, ABS_Z, 1024);
4165 __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
4166 break;
4167
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004168 case WACOM_22HD:
4169 __set_bit(KEY_PROG1, input_dev->keybit);
4170 __set_bit(KEY_PROG2, input_dev->keybit);
4171 __set_bit(KEY_PROG3, input_dev->keybit);
Aaron Armstrong Skomra670e9092019-08-16 12:02:50 -07004172
4173 __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
4174 __set_bit(KEY_INFO, input_dev->keybit);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004175 fallthrough;
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004176
4177 case WACOM_21UX2:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004178 case WACOM_BEE:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004179 case CINTIQ:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004180 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
4181 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
4182 break;
4183
4184 case WACOM_13HD:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004185 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4186 break;
4187
4188 case INTUOS3:
4189 case INTUOS3L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004190 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004191 fallthrough;
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004192
4193 case INTUOS3S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004194 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
4195 break;
4196
4197 case INTUOS5:
4198 case INTUOS5L:
4199 case INTUOSPM:
4200 case INTUOSPL:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004201 case INTUOS5S:
4202 case INTUOSPS:
Jason Gerecke4922cd22017-01-25 12:08:37 -08004203 case INTUOSP2_BT:
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07004204 case INTUOSP2S_BT:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004205 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4206 break;
4207
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004208 case INTUOS4WL:
4209 /*
4210 * For Bluetooth devices, the udev rule does not work correctly
4211 * for pads unless we add a stylus capability, which forces
4212 * ID_INPUT_TABLET to be set.
4213 */
4214 __set_bit(BTN_STYLUS, input_dev->keybit);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004215 fallthrough;
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004216
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004217 case INTUOS4:
4218 case INTUOS4L:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004219 case INTUOS4S:
Benjamin Tissoires10059cdc2014-07-24 12:49:08 -07004220 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4221 break;
4222
Benjamin Tissoires31168712014-07-24 12:50:10 -07004223 case INTUOSHT:
4224 case BAMBOO_PT:
Ping Cheng3b164a02015-09-23 09:59:10 -07004225 case BAMBOO_TOUCH:
Ping Chengeda01da2015-09-23 13:51:15 -07004226 case INTUOSHT2:
Benjamin Tissoires31168712014-07-24 12:50:10 -07004227 __clear_bit(ABS_MISC, input_dev->absbit);
4228
4229 __set_bit(BTN_LEFT, input_dev->keybit);
4230 __set_bit(BTN_FORWARD, input_dev->keybit);
4231 __set_bit(BTN_BACK, input_dev->keybit);
4232 __set_bit(BTN_RIGHT, input_dev->keybit);
4233
4234 break;
4235
Aaron Skomra72b236d2015-08-20 16:05:17 -07004236 case REMOTE:
4237 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
4238 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
4239 break;
4240
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08004241 case INTUOSHT3_BT:
Jason Gerecke5922e612016-10-19 18:03:51 -07004242 case HID_GENERIC:
4243 break;
4244
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004245 default:
4246 /* no pad supported */
Ping Chengb3c8e932014-11-18 13:27:48 -08004247 return -ENODEV;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07004248 }
4249 return 0;
4250}
4251
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004252static const struct wacom_features wacom_features_0x00 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004253 { "Wacom Penpartner", 5040, 3780, 255, 0,
4254 PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004255static const struct wacom_features wacom_features_0x10 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004256 { "Wacom Graphire", 10206, 7422, 511, 63,
4257 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004258static const struct wacom_features wacom_features_0x81 =
4259 { "Wacom Graphire BT", 16704, 12064, 511, 32,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004260 GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004261static const struct wacom_features wacom_features_0x11 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004262 { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
4263 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004264static const struct wacom_features wacom_features_0x12 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004265 { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
4266 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004267static const struct wacom_features wacom_features_0x13 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004268 { "Wacom Graphire3", 10208, 7424, 511, 63,
4269 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004270static const struct wacom_features wacom_features_0x14 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004271 { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
4272 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004273static const struct wacom_features wacom_features_0x15 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004274 { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
4275 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004276static const struct wacom_features wacom_features_0x16 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004277 { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
4278 WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004279static const struct wacom_features wacom_features_0x17 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004280 { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
4281 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004282static const struct wacom_features wacom_features_0x18 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004283 { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
4284 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004285static const struct wacom_features wacom_features_0x19 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004286 { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
4287 GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004288static const struct wacom_features wacom_features_0x60 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004289 { "Wacom Volito", 5104, 3712, 511, 63,
4290 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004291static const struct wacom_features wacom_features_0x61 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004292 { "Wacom PenStation2", 3250, 2320, 255, 63,
4293 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004294static const struct wacom_features wacom_features_0x62 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004295 { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
4296 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004297static const struct wacom_features wacom_features_0x63 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004298 { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
4299 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004300static const struct wacom_features wacom_features_0x64 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004301 { "Wacom PenPartner2", 3250, 2320, 511, 63,
4302 GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004303static const struct wacom_features wacom_features_0x65 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004304 { "Wacom Bamboo", 14760, 9225, 511, 63,
4305 WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004306static const struct wacom_features wacom_features_0x69 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004307 { "Wacom Bamboo1", 5104, 3712, 511, 63,
4308 GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07004309static const struct wacom_features wacom_features_0x6A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004310 { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
4311 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng11d0cf82011-06-27 12:57:58 -07004312static const struct wacom_features wacom_features_0x6B =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004313 { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
4314 GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004315static const struct wacom_features wacom_features_0x20 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004316 { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
4317 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004318static const struct wacom_features wacom_features_0x21 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004319 { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
4320 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004321static const struct wacom_features wacom_features_0x22 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004322 { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
4323 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004324static const struct wacom_features wacom_features_0x23 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004325 { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
4326 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004327static const struct wacom_features wacom_features_0x24 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004328 { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
4329 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004330static const struct wacom_features wacom_features_0x30 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004331 { "Wacom PL400", 5408, 4056, 255, 0,
4332 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004333static const struct wacom_features wacom_features_0x31 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004334 { "Wacom PL500", 6144, 4608, 255, 0,
4335 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004336static const struct wacom_features wacom_features_0x32 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004337 { "Wacom PL600", 6126, 4604, 255, 0,
4338 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004339static const struct wacom_features wacom_features_0x33 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004340 { "Wacom PL600SX", 6260, 5016, 255, 0,
4341 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004342static const struct wacom_features wacom_features_0x34 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004343 { "Wacom PL550", 6144, 4608, 511, 0,
4344 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004345static const struct wacom_features wacom_features_0x35 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004346 { "Wacom PL800", 7220, 5780, 511, 0,
4347 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004348static const struct wacom_features wacom_features_0x37 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004349 { "Wacom PL700", 6758, 5406, 511, 0,
4350 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004351static const struct wacom_features wacom_features_0x38 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004352 { "Wacom PL510", 6282, 4762, 511, 0,
4353 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004354static const struct wacom_features wacom_features_0x39 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004355 { "Wacom DTU710", 34080, 27660, 511, 0,
4356 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004357static const struct wacom_features wacom_features_0xC4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004358 { "Wacom DTF521", 6282, 4762, 511, 0,
4359 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004360static const struct wacom_features wacom_features_0xC0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004361 { "Wacom DTF720", 6858, 5506, 511, 0,
4362 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004363static const struct wacom_features wacom_features_0xC2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004364 { "Wacom DTF720a", 6858, 5506, 511, 0,
4365 PL, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004366static const struct wacom_features wacom_features_0x03 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004367 { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
4368 PTU, WACOM_PL_RES, WACOM_PL_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004369static const struct wacom_features wacom_features_0x41 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004370 { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
4371 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004372static const struct wacom_features wacom_features_0x42 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004373 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4374 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004375static const struct wacom_features wacom_features_0x43 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004376 { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
4377 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004378static const struct wacom_features wacom_features_0x44 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004379 { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
4380 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004381static const struct wacom_features wacom_features_0x45 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004382 { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
4383 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004384static const struct wacom_features wacom_features_0xB0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004385 { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004386 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004387static const struct wacom_features wacom_features_0xB1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004388 { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004389 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004390static const struct wacom_features wacom_features_0xB2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004391 { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004392 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004393static const struct wacom_features wacom_features_0xB3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004394 { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004395 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004396static const struct wacom_features wacom_features_0xB4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004397 { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004398 INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004399static const struct wacom_features wacom_features_0xB5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004400 { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004401 INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004402static const struct wacom_features wacom_features_0xB7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004403 { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004404 INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004405static const struct wacom_features wacom_features_0xB8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004406 { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004407 INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004408static const struct wacom_features wacom_features_0xB9 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004409 { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004410 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004411static const struct wacom_features wacom_features_0xBA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004412 { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004413 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004414static const struct wacom_features wacom_features_0xBB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004415 { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004416 INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004417static const struct wacom_features wacom_features_0xBC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004418 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004419 INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004420static const struct wacom_features wacom_features_0xBD =
4421 { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004422 INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004423static const struct wacom_features wacom_features_0x26 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004424 { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004425 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004426static const struct wacom_features wacom_features_0x27 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004427 { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004428 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004429static const struct wacom_features wacom_features_0x28 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004430 { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004431 INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004432static const struct wacom_features wacom_features_0x29 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004433 { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004434 INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
Jason Gerecke9fee6192012-04-03 15:47:22 -07004435static const struct wacom_features wacom_features_0x2A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004436 { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004437 INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
Ping Cheng9a35c412013-09-20 09:51:56 -07004438static const struct wacom_features wacom_features_0x314 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004439 { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004440 INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004441 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07004442static const struct wacom_features wacom_features_0x315 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004443 { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004444 INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004445 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng9a35c412013-09-20 09:51:56 -07004446static const struct wacom_features wacom_features_0x317 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004447 { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004448 INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004449 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Jason Gerecke803296b2011-12-12 00:11:45 -08004450static const struct wacom_features wacom_features_0xF4 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004451 { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004452 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Jason Gereckee779ef22016-10-19 18:03:49 -07004453 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004454 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Jason Gerecke6f4d0382012-08-21 22:11:59 -07004455static const struct wacom_features wacom_features_0xF8 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004456 { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004457 WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
Ping Chengfa770342014-12-01 13:44:28 -08004458 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004459 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07004460 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
Jason Gereckeb1e42792012-10-21 00:38:04 -07004461static const struct wacom_features wacom_features_0xF6 =
4462 { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004463 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
4464 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng500d4162015-01-27 13:30:03 -08004465static const struct wacom_features wacom_features_0x32A =
Jason Gereckee779ef22016-10-19 18:03:49 -07004466 { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004467 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07004468 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga7e66452015-02-04 16:01:54 -08004469 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng500d4162015-01-27 13:30:03 -08004470static const struct wacom_features wacom_features_0x32B =
Jason Gereckee779ef22016-10-19 18:03:49 -07004471 { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004472 WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
Ping Cheng500d4162015-01-27 13:30:03 -08004473 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004474 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng500d4162015-01-27 13:30:03 -08004475 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
4476static const struct wacom_features wacom_features_0x32C =
4477 { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
4478 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004479static const struct wacom_features wacom_features_0x3F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004480 { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004481 CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004482static const struct wacom_features wacom_features_0xC5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004483 { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004484 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004485static const struct wacom_features wacom_features_0xC6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004486 { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004487 WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
Ping Cheng56218562013-05-05 19:56:18 -07004488static const struct wacom_features wacom_features_0x304 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004489 { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004490 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Jason Gereckee779ef22016-10-19 18:03:49 -07004491 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004492 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengb4bf2122015-03-25 17:08:13 -07004493static const struct wacom_features wacom_features_0x333 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004494 { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004495 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengb4bf2122015-03-25 17:08:13 -07004496 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004497 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengb4bf2122015-03-25 17:08:13 -07004498 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
4499static const struct wacom_features wacom_features_0x335 =
4500 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
4501 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
4502 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004503static const struct wacom_features wacom_features_0xC7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004504 { "Wacom DTU1931", 37832, 30305, 511, 0,
4505 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengc8f2edc2010-06-28 01:10:51 -07004506static const struct wacom_features wacom_features_0xCE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004507 { "Wacom DTU2231", 47864, 27011, 511, 0,
4508 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004509 .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
Ping Chengc8f2edc2010-06-28 01:10:51 -07004510static const struct wacom_features wacom_features_0xF0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004511 { "Wacom DTU1631", 34623, 19553, 511, 0,
4512 DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng497ab1f2014-01-20 20:18:04 -08004513static const struct wacom_features wacom_features_0xFB =
Jason Gereckee779ef22016-10-19 18:03:49 -07004514 { "Wacom DTU1031", 22096, 13960, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004515 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004516 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004517 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Chengfff00bf2014-12-04 18:23:04 -08004518static const struct wacom_features wacom_features_0x32F =
Jason Gereckee779ef22016-10-19 18:03:49 -07004519 { "Wacom DTU1031X", 22672, 12928, 511, 0,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004520 DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
Jason Gereckee779ef22016-10-19 18:03:49 -07004521 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengfff00bf2014-12-04 18:23:04 -08004522 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Aaron Skomra007760c2015-04-16 15:01:14 -07004523static const struct wacom_features wacom_features_0x336 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004524 { "Wacom DTU1141", 23672, 13403, 1023, 0,
Ping Chengff38e822015-11-12 17:21:14 -08004525 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004526 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chengff38e822015-11-12 17:21:14 -08004527 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07004528static const struct wacom_features wacom_features_0x57 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004529 { "Wacom DTK2241", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004530 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Jason Gereckee779ef22016-10-19 18:03:49 -07004531 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004532 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chenga112e9f2013-02-13 20:20:01 -08004533static const struct wacom_features wacom_features_0x59 = /* Pen */
Jason Gereckee779ef22016-10-19 18:03:49 -07004534 { "Wacom DTH2242", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004535 DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
Ping Chengfa770342014-12-01 13:44:28 -08004536 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004537 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chenga112e9f2013-02-13 20:20:01 -08004538 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
4539static const struct wacom_features wacom_features_0x5D = /* Touch */
4540 { "Wacom DTH2242", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004541 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
4542 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004543static const struct wacom_features wacom_features_0xCC =
Jason Gereckee779ef22016-10-19 18:03:49 -07004544 { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004545 WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07004546 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004547 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Chengd838c642012-07-24 23:54:11 -07004548static const struct wacom_features wacom_features_0xFA =
Jason Gereckee779ef22016-10-19 18:03:49 -07004549 { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004550 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Jason Gereckee779ef22016-10-19 18:03:49 -07004551 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Chengfa770342014-12-01 13:44:28 -08004552 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
Ping Cheng56218562013-05-05 19:56:18 -07004553static const struct wacom_features wacom_features_0x5B =
Jason Gereckee779ef22016-10-19 18:03:49 -07004554 { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004555 WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
Ping Chengfa770342014-12-01 13:44:28 -08004556 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004557 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Ping Cheng3bd1f7e2013-05-23 10:22:33 -07004558 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
Ping Cheng56218562013-05-05 19:56:18 -07004559static const struct wacom_features wacom_features_0x5E =
4560 { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004561 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
4562 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004563static const struct wacom_features wacom_features_0x90 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004564 { "Wacom ISDv4 90", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004565 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004566static const struct wacom_features wacom_features_0x93 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004567 { "Wacom ISDv4 93", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004568 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Ping Cheng11d0cf82011-06-27 12:57:58 -07004569static const struct wacom_features wacom_features_0x97 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004570 { "Wacom ISDv4 97", 26202, 16325, 511, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004571 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004572static const struct wacom_features wacom_features_0x9A =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004573 { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004574 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004575static const struct wacom_features wacom_features_0x9F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004576 { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004577 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004578static const struct wacom_features wacom_features_0xE2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004579 { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
4580 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004581static const struct wacom_features wacom_features_0xE3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004582 { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
4583 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng19635182012-04-29 21:09:18 -07004584static const struct wacom_features wacom_features_0xE5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004585 { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
4586 MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07004587static const struct wacom_features wacom_features_0xE6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004588 { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
4589 TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell0d0e3062011-12-11 23:50:59 -08004590static const struct wacom_features wacom_features_0xEC =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004591 { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004592 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Ping Chengac173832012-06-12 00:15:06 -07004593static const struct wacom_features wacom_features_0xED =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004594 { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004595 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Ping Chengac173832012-06-12 00:15:06 -07004596static const struct wacom_features wacom_features_0xEF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004597 { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004598 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Ping Cheng6afdc282012-11-03 12:16:15 -07004599static const struct wacom_features wacom_features_0x100 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004600 { "Wacom ISDv4 100", 26202, 16325, 255, 0,
4601 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng6afdc282012-11-03 12:16:15 -07004602static const struct wacom_features wacom_features_0x101 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004603 { "Wacom ISDv4 101", 26202, 16325, 255, 0,
4604 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Stephan Frank58694832013-03-07 14:08:50 -08004605static const struct wacom_features wacom_features_0x10D =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004606 { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
4607 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke2d3163f2013-10-22 15:35:30 -07004608static const struct wacom_features wacom_features_0x10E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004609 { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
4610 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07004611static const struct wacom_features wacom_features_0x10F =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004612 { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
4613 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecke61616ed2014-05-14 11:42:22 -07004614static const struct wacom_features wacom_features_0x116 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004615 { "Wacom ISDv4 116", 26202, 16325, 255, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004616 TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07004617static const struct wacom_features wacom_features_0x12C =
4618 { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
Jason Gerecke29b9e142018-06-25 13:24:34 -07004619 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
Ping Chengedbe2652012-11-21 13:12:50 -08004620static const struct wacom_features wacom_features_0x4001 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004621 { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
4622 MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004623static const struct wacom_features wacom_features_0x4004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004624 { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
4625 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004626static const struct wacom_features wacom_features_0x5000 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004627 { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
4628 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Jason Gerecked51ddb22014-05-14 17:14:29 -07004629static const struct wacom_features wacom_features_0x5002 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004630 { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
4631 MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Dmitry Torokhove87a3442010-02-18 01:51:47 -08004632static const struct wacom_features wacom_features_0x47 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004633 { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
4634 INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwelld3825d52012-03-25 23:26:11 -07004635static const struct wacom_features wacom_features_0x84 =
Ping Cheng3b164a02015-09-23 09:59:10 -07004636 { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004637static const struct wacom_features wacom_features_0xD0 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004638 { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004639 BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004640static const struct wacom_features wacom_features_0xD1 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004641 { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
4642 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004643static const struct wacom_features wacom_features_0xD2 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004644 { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
4645 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004646static const struct wacom_features wacom_features_0xD3 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004647 { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
4648 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Kevin Granade57a78722010-12-10 23:04:02 -08004649static const struct wacom_features wacom_features_0xD4 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004650 { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004651 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Gerard Braad18adad12011-08-16 00:17:56 -07004652static const struct wacom_features wacom_features_0xD5 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004653 { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004654 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004655static const struct wacom_features wacom_features_0xD6 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004656 { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
4657 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004658static const struct wacom_features wacom_features_0xD7 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004659 { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
4660 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004661static const struct wacom_features wacom_features_0xD8 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004662 { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
4663 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Cheng7b824bb2011-03-26 21:16:04 -07004664static const struct wacom_features wacom_features_0xDA =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004665 { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
4666 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Ping Chengf41a64e2013-08-21 09:14:49 -07004667static const struct wacom_features wacom_features_0xDB =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004668 { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
4669 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004670static const struct wacom_features wacom_features_0xDD =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004671 { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
4672 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004673static const struct wacom_features wacom_features_0xDE =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004674 { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
4675 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Chris Bagwell73149ab2011-10-26 22:34:21 -07004676static const struct wacom_features wacom_features_0xDF =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004677 { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
4678 BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
Ping Chengf41a64e2013-08-21 09:14:49 -07004679static const struct wacom_features wacom_features_0x300 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004680 { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
Ping Cheng3b164a02015-09-23 09:59:10 -07004681 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengf41a64e2013-08-21 09:14:49 -07004682static const struct wacom_features wacom_features_0x301 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004683 { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
Aaron Armstrong Skomrab79cbc52017-03-29 13:07:36 -07004684 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004685static const struct wacom_features wacom_features_0x302 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004686 { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
4687 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004688 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004689static const struct wacom_features wacom_features_0x303 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004690 { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
4691 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004692 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chengb5fd2a32013-11-25 18:44:55 -08004693static const struct wacom_features wacom_features_0x30E =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004694 { "Wacom Intuos S", 15200, 9500, 1023, 31,
4695 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004696 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004697static const struct wacom_features wacom_features_0x6004 =
Benjamin Tissoires80befa92014-07-24 13:05:19 -07004698 { "ISD-V4", 12800, 8000, 255, 0,
4699 TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004700static const struct wacom_features wacom_features_0x307 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004701 { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004702 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08004703 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004704 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gerecke36d3c512013-09-20 09:47:35 -07004705 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004706static const struct wacom_features wacom_features_0x309 =
Jason Gerecke36d3c512013-09-20 09:47:35 -07004707 { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004708 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
4709 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004710static const struct wacom_features wacom_features_0x30A =
Jason Gereckee779ef22016-10-19 18:03:49 -07004711 { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
Aaron Skomra70ee06c2015-08-20 16:05:16 -07004712 CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
Ping Chengfa770342014-12-01 13:44:28 -08004713 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004714 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004715 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
4716static const struct wacom_features wacom_features_0x30C =
4717 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
4718 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
4719 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004720static const struct wacom_features wacom_features_0x318 =
4721 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
4722 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
4723static const struct wacom_features wacom_features_0x319 =
4724 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
4725 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
Jason Gereckef7acb552015-10-13 10:03:49 -07004726static const struct wacom_features wacom_features_0x325 =
4727 { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
4728 CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
4729 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckee779ef22016-10-19 18:03:49 -07004730 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
Jason Gereckef7acb552015-10-13 10:03:49 -07004731 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
4732static const struct wacom_features wacom_features_0x326 = /* Touch */
4733 { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
4734 .oPid = 0x325 };
Ping Chengfefb3912014-11-11 12:52:08 -08004735static const struct wacom_features wacom_features_0x323 =
4736 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
4737 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4738 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Aaron Skomra72b236d2015-08-20 16:05:17 -07004739static const struct wacom_features wacom_features_0x331 =
Ping Cheng3b164a02015-09-23 09:59:10 -07004740 { "Wacom Express Key Remote", .type = REMOTE,
4741 .numbered_buttons = 18, .check_for_hid_type = true,
Aaron Skomra72b236d2015-08-20 16:05:17 -07004742 .hid_type = HID_TYPE_USBNONE };
Ping Chengeda01da2015-09-23 13:51:15 -07004743static const struct wacom_features wacom_features_0x33B =
4744 { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
4745 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4746 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4747static const struct wacom_features wacom_features_0x33C =
4748 { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
4749 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4750 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4751static const struct wacom_features wacom_features_0x33D =
4752 { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
4753 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
4754 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
4755static const struct wacom_features wacom_features_0x33E =
4756 { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
4757 INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
4758 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
Ping Chenge1123fe2016-04-12 13:37:45 -07004759static const struct wacom_features wacom_features_0x343 =
Jason Gereckee779ef22016-10-19 18:03:49 -07004760 { "Wacom DTK1651", 34816, 19759, 1023, 0,
Ping Chenge1123fe2016-04-12 13:37:45 -07004761 DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
Jason Gereckee779ef22016-10-19 18:03:49 -07004762 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
Ping Chenge1123fe2016-04-12 13:37:45 -07004763 WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
Jason Gerecke4922cd22017-01-25 12:08:37 -08004764static const struct wacom_features wacom_features_0x360 =
4765 { "Wacom Intuos Pro M", 44800, 29600, 8191, 63,
Aaron Armstrong Skomra49cc4c22017-03-06 10:54:57 -08004766 INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
Jason Gerecke4922cd22017-01-25 12:08:37 -08004767static const struct wacom_features wacom_features_0x361 =
4768 { "Wacom Intuos Pro L", 62200, 43200, 8191, 63,
Aaron Armstrong Skomra49cc4c22017-03-06 10:54:57 -08004769 INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08004770static const struct wacom_features wacom_features_0x377 =
4771 { "Wacom Intuos BT S", 15200, 9500, 4095, 63,
4772 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
4773static const struct wacom_features wacom_features_0x379 =
4774 { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
4775 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
Jason Gereckec9472182017-12-26 15:50:18 -08004776static const struct wacom_features wacom_features_0x37A =
4777 { "Wacom One by Wacom S", 15200, 9500, 2047, 63,
4778 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
4779static const struct wacom_features wacom_features_0x37B =
4780 { "Wacom One by Wacom M", 21600, 13500, 2047, 63,
4781 BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07004782static const struct wacom_features wacom_features_0x393 =
4783 { "Wacom Intuos Pro S", 31920, 19950, 8191, 63,
4784 INTUOSP2S_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7,
4785 .touch_max = 10 };
Joshua-Dickens0c8fbaa2021-09-14 13:28:25 -04004786static const struct wacom_features wacom_features_0x3c6 =
4787 { "Wacom Intuos BT S", 15200, 9500, 4095, 63,
4788 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
4789static const struct wacom_features wacom_features_0x3c8 =
4790 { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
4791 INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
Bastian Blankb036f6f2010-02-10 23:06:23 -08004792
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004793static const struct wacom_features wacom_features_HID_ANY_ID =
Jason Gerecke41372d52016-08-08 12:06:30 -07004794 { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004795
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004796#define USB_DEVICE_WACOM(prod) \
4797 HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4798 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Bastian Blankb036f6f2010-02-10 23:06:23 -08004799
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004800#define BT_DEVICE_WACOM(prod) \
4801 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4802 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Aristeu Rozanski1483f552011-06-22 01:17:17 -07004803
Mika Westerbergeef23a82015-02-23 15:52:43 +02004804#define I2C_DEVICE_WACOM(prod) \
4805 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
4806 .driver_data = (kernel_ulong_t)&wacom_features_##prod
4807
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004808#define USB_DEVICE_LENOVO(prod) \
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004809 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
4810 .driver_data = (kernel_ulong_t)&wacom_features_##prod
Ajay Ramaswamy7b4b3062010-12-23 01:19:39 -08004811
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004812const struct hid_device_id wacom_ids[] = {
Bastian Blankb036f6f2010-02-10 23:06:23 -08004813 { USB_DEVICE_WACOM(0x00) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004814 { USB_DEVICE_WACOM(0x03) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004815 { USB_DEVICE_WACOM(0x10) },
4816 { USB_DEVICE_WACOM(0x11) },
4817 { USB_DEVICE_WACOM(0x12) },
4818 { USB_DEVICE_WACOM(0x13) },
4819 { USB_DEVICE_WACOM(0x14) },
4820 { USB_DEVICE_WACOM(0x15) },
4821 { USB_DEVICE_WACOM(0x16) },
4822 { USB_DEVICE_WACOM(0x17) },
4823 { USB_DEVICE_WACOM(0x18) },
4824 { USB_DEVICE_WACOM(0x19) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004825 { USB_DEVICE_WACOM(0x20) },
4826 { USB_DEVICE_WACOM(0x21) },
4827 { USB_DEVICE_WACOM(0x22) },
4828 { USB_DEVICE_WACOM(0x23) },
4829 { USB_DEVICE_WACOM(0x24) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004830 { USB_DEVICE_WACOM(0x26) },
4831 { USB_DEVICE_WACOM(0x27) },
4832 { USB_DEVICE_WACOM(0x28) },
4833 { USB_DEVICE_WACOM(0x29) },
4834 { USB_DEVICE_WACOM(0x2A) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004835 { USB_DEVICE_WACOM(0x30) },
4836 { USB_DEVICE_WACOM(0x31) },
4837 { USB_DEVICE_WACOM(0x32) },
4838 { USB_DEVICE_WACOM(0x33) },
4839 { USB_DEVICE_WACOM(0x34) },
4840 { USB_DEVICE_WACOM(0x35) },
4841 { USB_DEVICE_WACOM(0x37) },
4842 { USB_DEVICE_WACOM(0x38) },
4843 { USB_DEVICE_WACOM(0x39) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004844 { USB_DEVICE_WACOM(0x3F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004845 { USB_DEVICE_WACOM(0x41) },
4846 { USB_DEVICE_WACOM(0x42) },
4847 { USB_DEVICE_WACOM(0x43) },
4848 { USB_DEVICE_WACOM(0x44) },
4849 { USB_DEVICE_WACOM(0x45) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004850 { USB_DEVICE_WACOM(0x47) },
Ping Cheng56218562013-05-05 19:56:18 -07004851 { USB_DEVICE_WACOM(0x57) },
Ping Chenga112e9f2013-02-13 20:20:01 -08004852 { USB_DEVICE_WACOM(0x59) },
Ping Cheng56218562013-05-05 19:56:18 -07004853 { USB_DEVICE_WACOM(0x5B) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004854 { USB_DEVICE_WACOM(0x5D) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004855 { USB_DEVICE_WACOM(0x5E) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004856 { USB_DEVICE_WACOM(0x60) },
4857 { USB_DEVICE_WACOM(0x61) },
4858 { USB_DEVICE_WACOM(0x62) },
4859 { USB_DEVICE_WACOM(0x63) },
4860 { USB_DEVICE_WACOM(0x64) },
4861 { USB_DEVICE_WACOM(0x65) },
4862 { USB_DEVICE_WACOM(0x69) },
4863 { USB_DEVICE_WACOM(0x6A) },
4864 { USB_DEVICE_WACOM(0x6B) },
Benjamin Tissoires387142b2014-08-06 13:52:56 -07004865 { BT_DEVICE_WACOM(0x81) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004866 { USB_DEVICE_WACOM(0x84) },
4867 { USB_DEVICE_WACOM(0x90) },
4868 { USB_DEVICE_WACOM(0x93) },
4869 { USB_DEVICE_WACOM(0x97) },
4870 { USB_DEVICE_WACOM(0x9A) },
4871 { USB_DEVICE_WACOM(0x9F) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004872 { USB_DEVICE_WACOM(0xB0) },
4873 { USB_DEVICE_WACOM(0xB1) },
4874 { USB_DEVICE_WACOM(0xB2) },
4875 { USB_DEVICE_WACOM(0xB3) },
4876 { USB_DEVICE_WACOM(0xB4) },
4877 { USB_DEVICE_WACOM(0xB5) },
4878 { USB_DEVICE_WACOM(0xB7) },
4879 { USB_DEVICE_WACOM(0xB8) },
4880 { USB_DEVICE_WACOM(0xB9) },
4881 { USB_DEVICE_WACOM(0xBA) },
4882 { USB_DEVICE_WACOM(0xBB) },
Ping Cheng3a4b4aa2010-06-03 22:10:21 -07004883 { USB_DEVICE_WACOM(0xBC) },
Benjamin Tissoires81af7e62014-08-06 13:55:56 -07004884 { BT_DEVICE_WACOM(0xBD) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004885 { USB_DEVICE_WACOM(0xC0) },
4886 { USB_DEVICE_WACOM(0xC2) },
4887 { USB_DEVICE_WACOM(0xC4) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004888 { USB_DEVICE_WACOM(0xC5) },
4889 { USB_DEVICE_WACOM(0xC6) },
4890 { USB_DEVICE_WACOM(0xC7) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004891 { USB_DEVICE_WACOM(0xCC) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004892 { USB_DEVICE_WACOM(0xCE) },
Henrik Rydbergcb734c02010-09-05 12:53:16 -07004893 { USB_DEVICE_WACOM(0xD0) },
Chris Bagwell2aaacb12010-09-12 00:11:35 -07004894 { USB_DEVICE_WACOM(0xD1) },
4895 { USB_DEVICE_WACOM(0xD2) },
4896 { USB_DEVICE_WACOM(0xD3) },
Kevin Granade57a78722010-12-10 23:04:02 -08004897 { USB_DEVICE_WACOM(0xD4) },
Gerard Braad18adad12011-08-16 00:17:56 -07004898 { USB_DEVICE_WACOM(0xD5) },
Ping Chengd38acb42011-01-24 09:32:50 -08004899 { USB_DEVICE_WACOM(0xD6) },
4900 { USB_DEVICE_WACOM(0xD7) },
David Foleya318e6b2010-11-30 23:45:46 -08004901 { USB_DEVICE_WACOM(0xD8) },
4902 { USB_DEVICE_WACOM(0xDA) },
David Foley47d09232010-12-07 21:05:59 -08004903 { USB_DEVICE_WACOM(0xDB) },
Chris Bagwell73149ab2011-10-26 22:34:21 -07004904 { USB_DEVICE_WACOM(0xDD) },
4905 { USB_DEVICE_WACOM(0xDE) },
4906 { USB_DEVICE_WACOM(0xDF) },
Bastian Blankb036f6f2010-02-10 23:06:23 -08004907 { USB_DEVICE_WACOM(0xE2) },
4908 { USB_DEVICE_WACOM(0xE3) },
Ping Cheng19635182012-04-29 21:09:18 -07004909 { USB_DEVICE_WACOM(0xE5) },
Manoj Iyer26fcd2a2011-03-31 22:39:43 -07004910 { USB_DEVICE_WACOM(0xE6) },
Chris Bagwell0d0e3062011-12-11 23:50:59 -08004911 { USB_DEVICE_WACOM(0xEC) },
Ping Chengac173832012-06-12 00:15:06 -07004912 { USB_DEVICE_WACOM(0xED) },
4913 { USB_DEVICE_WACOM(0xEF) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004914 { USB_DEVICE_WACOM(0xF0) },
4915 { USB_DEVICE_WACOM(0xF4) },
4916 { USB_DEVICE_WACOM(0xF6) },
4917 { USB_DEVICE_WACOM(0xF8) },
4918 { USB_DEVICE_WACOM(0xFA) },
4919 { USB_DEVICE_WACOM(0xFB) },
Ping Cheng6afdc282012-11-03 12:16:15 -07004920 { USB_DEVICE_WACOM(0x100) },
4921 { USB_DEVICE_WACOM(0x101) },
Stephan Frank58694832013-03-07 14:08:50 -08004922 { USB_DEVICE_WACOM(0x10D) },
Jason Gerecke2d3163f2013-10-22 15:35:30 -07004923 { USB_DEVICE_WACOM(0x10E) },
Jason Gerecke9b4f60e2013-10-15 23:46:34 -07004924 { USB_DEVICE_WACOM(0x10F) },
Jason Gerecke61616ed2014-05-14 11:42:22 -07004925 { USB_DEVICE_WACOM(0x116) },
Jason Gereckeaeaf50d2014-07-28 10:53:16 -07004926 { USB_DEVICE_WACOM(0x12C) },
Ping Chengf41a64e2013-08-21 09:14:49 -07004927 { USB_DEVICE_WACOM(0x300) },
4928 { USB_DEVICE_WACOM(0x301) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004929 { USB_DEVICE_WACOM(0x302) },
4930 { USB_DEVICE_WACOM(0x303) },
Ping Cheng56218562013-05-05 19:56:18 -07004931 { USB_DEVICE_WACOM(0x304) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004932 { USB_DEVICE_WACOM(0x307) },
4933 { USB_DEVICE_WACOM(0x309) },
Benjamin Tissoires89f2ab52014-09-03 15:43:25 -04004934 { USB_DEVICE_WACOM(0x30A) },
4935 { USB_DEVICE_WACOM(0x30C) },
Benjamin Tissoiresa3e6f652014-07-24 13:05:49 -07004936 { USB_DEVICE_WACOM(0x30E) },
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004937 { USB_DEVICE_WACOM(0x314) },
4938 { USB_DEVICE_WACOM(0x315) },
4939 { USB_DEVICE_WACOM(0x317) },
Benjamin Tissoires8c97a762015-02-26 11:28:50 -05004940 { USB_DEVICE_WACOM(0x318) },
4941 { USB_DEVICE_WACOM(0x319) },
Ping Chengfefb3912014-11-11 12:52:08 -08004942 { USB_DEVICE_WACOM(0x323) },
Jason Gereckef7acb552015-10-13 10:03:49 -07004943 { USB_DEVICE_WACOM(0x325) },
4944 { USB_DEVICE_WACOM(0x326) },
Ping Cheng500d4162015-01-27 13:30:03 -08004945 { USB_DEVICE_WACOM(0x32A) },
4946 { USB_DEVICE_WACOM(0x32B) },
4947 { USB_DEVICE_WACOM(0x32C) },
Ping Chengfff00bf2014-12-04 18:23:04 -08004948 { USB_DEVICE_WACOM(0x32F) },
Aaron Skomra72b236d2015-08-20 16:05:17 -07004949 { USB_DEVICE_WACOM(0x331) },
Ping Chengb4bf2122015-03-25 17:08:13 -07004950 { USB_DEVICE_WACOM(0x333) },
4951 { USB_DEVICE_WACOM(0x335) },
Aaron Skomra007760c2015-04-16 15:01:14 -07004952 { USB_DEVICE_WACOM(0x336) },
Ping Chengeda01da2015-09-23 13:51:15 -07004953 { USB_DEVICE_WACOM(0x33B) },
4954 { USB_DEVICE_WACOM(0x33C) },
4955 { USB_DEVICE_WACOM(0x33D) },
4956 { USB_DEVICE_WACOM(0x33E) },
Ping Chenge1123fe2016-04-12 13:37:45 -07004957 { USB_DEVICE_WACOM(0x343) },
Jason Gerecke4922cd22017-01-25 12:08:37 -08004958 { BT_DEVICE_WACOM(0x360) },
4959 { BT_DEVICE_WACOM(0x361) },
Aaron Armstrong Skomra87046b62018-03-06 10:48:33 -08004960 { BT_DEVICE_WACOM(0x377) },
4961 { BT_DEVICE_WACOM(0x379) },
Jason Gereckec9472182017-12-26 15:50:18 -08004962 { USB_DEVICE_WACOM(0x37A) },
4963 { USB_DEVICE_WACOM(0x37B) },
Aaron Armstrong Skomra912c6aa2019-06-12 14:19:28 -07004964 { BT_DEVICE_WACOM(0x393) },
Joshua-Dickens0c8fbaa2021-09-14 13:28:25 -04004965 { BT_DEVICE_WACOM(0x3c6) },
4966 { BT_DEVICE_WACOM(0x3c8) },
Ping Chengedbe2652012-11-21 13:12:50 -08004967 { USB_DEVICE_WACOM(0x4001) },
Jason Gerecked51ddb22014-05-14 17:14:29 -07004968 { USB_DEVICE_WACOM(0x4004) },
4969 { USB_DEVICE_WACOM(0x5000) },
4970 { USB_DEVICE_WACOM(0x5002) },
Benjamin Tissoires00d6f2272014-12-01 11:52:39 -05004971 { USB_DEVICE_LENOVO(0x6004) },
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04004972
4973 { USB_DEVICE_WACOM(HID_ANY_ID) },
Mika Westerbergeef23a82015-02-23 15:52:43 +02004974 { I2C_DEVICE_WACOM(HID_ANY_ID) },
Jason Gereckeb9e06252017-01-25 12:08:35 -08004975 { BT_DEVICE_WACOM(HID_ANY_ID) },
Ping Cheng3bea7332006-07-13 18:01:36 -07004976 { }
4977};
Benjamin Tissoires29b47392014-07-24 12:52:23 -07004978MODULE_DEVICE_TABLE(hid, wacom_ids);