wacom_wac.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218
  1. /*
  2. * drivers/input/tablet/wacom_wac.c
  3. *
  4. * USB Wacom tablet support - Wacom specific code
  5. *
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include "wacom_wac.h"
  14. #include "wacom.h"
  15. #include <linux/input/mt.h>
  16. #include <linux/hid.h>
  17. /* resolution for penabled devices */
  18. #define WACOM_PL_RES 20
  19. #define WACOM_PENPRTN_RES 40
  20. #define WACOM_VOLITO_RES 50
  21. #define WACOM_GRAPHIRE_RES 80
  22. #define WACOM_INTUOS_RES 100
  23. #define WACOM_INTUOS3_RES 200
  24. /* Scale factor relating reported contact size to logical contact area.
  25. * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
  26. */
  27. #define WACOM_CONTACT_AREA_SCALE 2607
  28. static int wacom_penpartner_irq(struct wacom_wac *wacom)
  29. {
  30. unsigned char *data = wacom->data;
  31. struct input_dev *input = wacom->input;
  32. switch (data[0]) {
  33. case 1:
  34. if (data[5] & 0x80) {
  35. wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  36. wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
  37. input_report_key(input, wacom->tool[0], 1);
  38. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  39. input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
  40. input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
  41. input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
  42. input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
  43. input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
  44. } else {
  45. input_report_key(input, wacom->tool[0], 0);
  46. input_report_abs(input, ABS_MISC, 0); /* report tool id */
  47. input_report_abs(input, ABS_PRESSURE, -1);
  48. input_report_key(input, BTN_TOUCH, 0);
  49. }
  50. break;
  51. case 2:
  52. input_report_key(input, BTN_TOOL_PEN, 1);
  53. input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
  54. input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
  55. input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
  56. input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
  57. input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
  58. input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
  59. break;
  60. default:
  61. dev_dbg(input->dev.parent,
  62. "%s: received unknown report #%d\n", __func__, data[0]);
  63. return 0;
  64. }
  65. return 1;
  66. }
  67. static int wacom_pl_irq(struct wacom_wac *wacom)
  68. {
  69. struct wacom_features *features = &wacom->features;
  70. unsigned char *data = wacom->data;
  71. struct input_dev *input = wacom->input;
  72. int prox, pressure;
  73. if (data[0] != WACOM_REPORT_PENABLED) {
  74. dev_dbg(input->dev.parent,
  75. "%s: received unknown report #%d\n", __func__, data[0]);
  76. return 0;
  77. }
  78. prox = data[1] & 0x40;
  79. if (prox) {
  80. wacom->id[0] = ERASER_DEVICE_ID;
  81. pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
  82. if (features->pressure_max > 255)
  83. pressure = (pressure << 1) | ((data[4] >> 6) & 1);
  84. pressure += (features->pressure_max + 1) / 2;
  85. /*
  86. * if going from out of proximity into proximity select between the eraser
  87. * and the pen based on the state of the stylus2 button, choose eraser if
  88. * pressed else choose pen. if not a proximity change from out to in, send
  89. * an out of proximity for previous tool then a in for new tool.
  90. */
  91. if (!wacom->tool[0]) {
  92. /* Eraser bit set for DTF */
  93. if (data[1] & 0x10)
  94. wacom->tool[1] = BTN_TOOL_RUBBER;
  95. else
  96. /* Going into proximity select tool */
  97. wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  98. } else {
  99. /* was entered with stylus2 pressed */
  100. if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
  101. /* report out proximity for previous tool */
  102. input_report_key(input, wacom->tool[1], 0);
  103. input_sync(input);
  104. wacom->tool[1] = BTN_TOOL_PEN;
  105. return 0;
  106. }
  107. }
  108. if (wacom->tool[1] != BTN_TOOL_RUBBER) {
  109. /* Unknown tool selected default to pen tool */
  110. wacom->tool[1] = BTN_TOOL_PEN;
  111. wacom->id[0] = STYLUS_DEVICE_ID;
  112. }
  113. input_report_key(input, wacom->tool[1], prox); /* report in proximity for tool */
  114. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  115. input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
  116. input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
  117. input_report_abs(input, ABS_PRESSURE, pressure);
  118. input_report_key(input, BTN_TOUCH, data[4] & 0x08);
  119. input_report_key(input, BTN_STYLUS, data[4] & 0x10);
  120. /* Only allow the stylus2 button to be reported for the pen tool. */
  121. input_report_key(input, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
  122. } else {
  123. /* report proximity-out of a (valid) tool */
  124. if (wacom->tool[1] != BTN_TOOL_RUBBER) {
  125. /* Unknown tool selected default to pen tool */
  126. wacom->tool[1] = BTN_TOOL_PEN;
  127. }
  128. input_report_key(input, wacom->tool[1], prox);
  129. }
  130. wacom->tool[0] = prox; /* Save proximity state */
  131. return 1;
  132. }
  133. static int wacom_ptu_irq(struct wacom_wac *wacom)
  134. {
  135. unsigned char *data = wacom->data;
  136. struct input_dev *input = wacom->input;
  137. if (data[0] != WACOM_REPORT_PENABLED) {
  138. dev_dbg(input->dev.parent,
  139. "%s: received unknown report #%d\n", __func__, data[0]);
  140. return 0;
  141. }
  142. if (data[1] & 0x04) {
  143. input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
  144. input_report_key(input, BTN_TOUCH, data[1] & 0x08);
  145. wacom->id[0] = ERASER_DEVICE_ID;
  146. } else {
  147. input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
  148. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  149. wacom->id[0] = STYLUS_DEVICE_ID;
  150. }
  151. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  152. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  153. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  154. input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
  155. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  156. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  157. return 1;
  158. }
  159. static int wacom_dtu_irq(struct wacom_wac *wacom)
  160. {
  161. struct wacom_features *features = &wacom->features;
  162. char *data = wacom->data;
  163. struct input_dev *input = wacom->input;
  164. int prox = data[1] & 0x20, pressure;
  165. dev_dbg(input->dev.parent,
  166. "%s: received report #%d", __func__, data[0]);
  167. if (prox) {
  168. /* Going into proximity select tool */
  169. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  170. if (wacom->tool[0] == BTN_TOOL_PEN)
  171. wacom->id[0] = STYLUS_DEVICE_ID;
  172. else
  173. wacom->id[0] = ERASER_DEVICE_ID;
  174. }
  175. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  176. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  177. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  178. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  179. pressure = ((data[7] & 0x01) << 8) | data[6];
  180. if (pressure < 0)
  181. pressure = features->pressure_max + pressure + 1;
  182. input_report_abs(input, ABS_PRESSURE, pressure);
  183. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  184. if (!prox) /* out-prox */
  185. wacom->id[0] = 0;
  186. input_report_key(input, wacom->tool[0], prox);
  187. input_report_abs(input, ABS_MISC, wacom->id[0]);
  188. return 1;
  189. }
  190. static int wacom_graphire_irq(struct wacom_wac *wacom)
  191. {
  192. struct wacom_features *features = &wacom->features;
  193. unsigned char *data = wacom->data;
  194. struct input_dev *input = wacom->input;
  195. int prox;
  196. int rw = 0;
  197. int retval = 0;
  198. if (data[0] != WACOM_REPORT_PENABLED) {
  199. dev_dbg(input->dev.parent,
  200. "%s: received unknown report #%d\n", __func__, data[0]);
  201. goto exit;
  202. }
  203. prox = data[1] & 0x80;
  204. if (prox || wacom->id[0]) {
  205. if (prox) {
  206. switch ((data[1] >> 5) & 3) {
  207. case 0: /* Pen */
  208. wacom->tool[0] = BTN_TOOL_PEN;
  209. wacom->id[0] = STYLUS_DEVICE_ID;
  210. break;
  211. case 1: /* Rubber */
  212. wacom->tool[0] = BTN_TOOL_RUBBER;
  213. wacom->id[0] = ERASER_DEVICE_ID;
  214. break;
  215. case 2: /* Mouse with wheel */
  216. input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
  217. /* fall through */
  218. case 3: /* Mouse without wheel */
  219. wacom->tool[0] = BTN_TOOL_MOUSE;
  220. wacom->id[0] = CURSOR_DEVICE_ID;
  221. break;
  222. }
  223. }
  224. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  225. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  226. if (wacom->tool[0] != BTN_TOOL_MOUSE) {
  227. input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x03) << 8));
  228. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  229. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  230. input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
  231. } else {
  232. input_report_key(input, BTN_LEFT, data[1] & 0x01);
  233. input_report_key(input, BTN_RIGHT, data[1] & 0x02);
  234. if (features->type == WACOM_G4 ||
  235. features->type == WACOM_MO) {
  236. input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
  237. rw = (data[7] & 0x04) - (data[7] & 0x03);
  238. } else {
  239. input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
  240. rw = -(signed char)data[6];
  241. }
  242. input_report_rel(input, REL_WHEEL, rw);
  243. }
  244. if (!prox)
  245. wacom->id[0] = 0;
  246. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  247. input_report_key(input, wacom->tool[0], prox);
  248. input_event(input, EV_MSC, MSC_SERIAL, 1);
  249. input_sync(input); /* sync last event */
  250. }
  251. /* send pad data */
  252. switch (features->type) {
  253. case WACOM_G4:
  254. prox = data[7] & 0xf8;
  255. if (prox || wacom->id[1]) {
  256. wacom->id[1] = PAD_DEVICE_ID;
  257. input_report_key(input, BTN_BACK, (data[7] & 0x40));
  258. input_report_key(input, BTN_FORWARD, (data[7] & 0x80));
  259. rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
  260. input_report_rel(input, REL_WHEEL, rw);
  261. if (!prox)
  262. wacom->id[1] = 0;
  263. input_report_abs(input, ABS_MISC, wacom->id[1]);
  264. input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
  265. retval = 1;
  266. }
  267. break;
  268. case WACOM_MO:
  269. prox = (data[7] & 0xf8) || data[8];
  270. if (prox || wacom->id[1]) {
  271. wacom->id[1] = PAD_DEVICE_ID;
  272. input_report_key(input, BTN_BACK, (data[7] & 0x08));
  273. input_report_key(input, BTN_LEFT, (data[7] & 0x20));
  274. input_report_key(input, BTN_FORWARD, (data[7] & 0x10));
  275. input_report_key(input, BTN_RIGHT, (data[7] & 0x40));
  276. input_report_abs(input, ABS_WHEEL, (data[8] & 0x7f));
  277. if (!prox)
  278. wacom->id[1] = 0;
  279. input_report_abs(input, ABS_MISC, wacom->id[1]);
  280. input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
  281. retval = 1;
  282. }
  283. break;
  284. }
  285. exit:
  286. return retval;
  287. }
  288. static int wacom_intuos_inout(struct wacom_wac *wacom)
  289. {
  290. struct wacom_features *features = &wacom->features;
  291. unsigned char *data = wacom->data;
  292. struct input_dev *input = wacom->input;
  293. int idx = 0;
  294. /* tool number */
  295. if (features->type == INTUOS)
  296. idx = data[1] & 0x01;
  297. /* Enter report */
  298. if ((data[1] & 0xfc) == 0xc0) {
  299. if (features->quirks == WACOM_QUIRK_MULTI_INPUT)
  300. wacom->shared->stylus_in_proximity = true;
  301. /* serial number of the tool */
  302. wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
  303. (data[4] << 20) + (data[5] << 12) +
  304. (data[6] << 4) + (data[7] >> 4);
  305. wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
  306. ((data[7] & 0x0f) << 20) | ((data[8] & 0xf0) << 12);
  307. switch (wacom->id[idx] & 0xfffff) {
  308. case 0x812: /* Inking pen */
  309. case 0x801: /* Intuos3 Inking pen */
  310. case 0x20802: /* Intuos4 Inking Pen */
  311. case 0x012:
  312. wacom->tool[idx] = BTN_TOOL_PENCIL;
  313. break;
  314. case 0x822: /* Pen */
  315. case 0x842:
  316. case 0x852:
  317. case 0x823: /* Intuos3 Grip Pen */
  318. case 0x813: /* Intuos3 Classic Pen */
  319. case 0x885: /* Intuos3 Marker Pen */
  320. case 0x802: /* Intuos4 General Pen */
  321. case 0x804: /* Intuos4 Marker Pen */
  322. case 0x40802: /* Intuos4 Classic Pen */
  323. case 0x022:
  324. wacom->tool[idx] = BTN_TOOL_PEN;
  325. break;
  326. case 0x832: /* Stroke pen */
  327. case 0x032:
  328. wacom->tool[idx] = BTN_TOOL_BRUSH;
  329. break;
  330. case 0x007: /* Mouse 4D and 2D */
  331. case 0x09c:
  332. case 0x094:
  333. case 0x017: /* Intuos3 2D Mouse */
  334. case 0x806: /* Intuos4 Mouse */
  335. wacom->tool[idx] = BTN_TOOL_MOUSE;
  336. break;
  337. case 0x096: /* Lens cursor */
  338. case 0x097: /* Intuos3 Lens cursor */
  339. case 0x006: /* Intuos4 Lens cursor */
  340. wacom->tool[idx] = BTN_TOOL_LENS;
  341. break;
  342. case 0x82a: /* Eraser */
  343. case 0x85a:
  344. case 0x91a:
  345. case 0xd1a:
  346. case 0x0fa:
  347. case 0x82b: /* Intuos3 Grip Pen Eraser */
  348. case 0x81b: /* Intuos3 Classic Pen Eraser */
  349. case 0x91b: /* Intuos3 Airbrush Eraser */
  350. case 0x80c: /* Intuos4 Marker Pen Eraser */
  351. case 0x80a: /* Intuos4 General Pen Eraser */
  352. case 0x4080a: /* Intuos4 Classic Pen Eraser */
  353. case 0x90a: /* Intuos4 Airbrush Eraser */
  354. wacom->tool[idx] = BTN_TOOL_RUBBER;
  355. break;
  356. case 0xd12:
  357. case 0x912:
  358. case 0x112:
  359. case 0x913: /* Intuos3 Airbrush */
  360. case 0x902: /* Intuos4 Airbrush */
  361. wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
  362. break;
  363. default: /* Unknown tool */
  364. wacom->tool[idx] = BTN_TOOL_PEN;
  365. break;
  366. }
  367. return 1;
  368. }
  369. /* older I4 styli don't work with new Cintiqs */
  370. if (!((wacom->id[idx] >> 20) & 0x01) &&
  371. (features->type == WACOM_21UX2))
  372. return 1;
  373. /* Exit report */
  374. if ((data[1] & 0xfe) == 0x80) {
  375. if (features->quirks == WACOM_QUIRK_MULTI_INPUT)
  376. wacom->shared->stylus_in_proximity = false;
  377. /*
  378. * Reset all states otherwise we lose the initial states
  379. * when in-prox next time
  380. */
  381. input_report_abs(input, ABS_X, 0);
  382. input_report_abs(input, ABS_Y, 0);
  383. input_report_abs(input, ABS_DISTANCE, 0);
  384. input_report_abs(input, ABS_TILT_X, 0);
  385. input_report_abs(input, ABS_TILT_Y, 0);
  386. if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
  387. input_report_key(input, BTN_LEFT, 0);
  388. input_report_key(input, BTN_MIDDLE, 0);
  389. input_report_key(input, BTN_RIGHT, 0);
  390. input_report_key(input, BTN_SIDE, 0);
  391. input_report_key(input, BTN_EXTRA, 0);
  392. input_report_abs(input, ABS_THROTTLE, 0);
  393. input_report_abs(input, ABS_RZ, 0);
  394. } else {
  395. input_report_abs(input, ABS_PRESSURE, 0);
  396. input_report_key(input, BTN_STYLUS, 0);
  397. input_report_key(input, BTN_STYLUS2, 0);
  398. input_report_key(input, BTN_TOUCH, 0);
  399. input_report_abs(input, ABS_WHEEL, 0);
  400. if (features->type >= INTUOS3S)
  401. input_report_abs(input, ABS_Z, 0);
  402. }
  403. input_report_key(input, wacom->tool[idx], 0);
  404. input_report_abs(input, ABS_MISC, 0); /* reset tool id */
  405. input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  406. wacom->id[idx] = 0;
  407. return 2;
  408. }
  409. return 0;
  410. }
  411. static void wacom_intuos_general(struct wacom_wac *wacom)
  412. {
  413. struct wacom_features *features = &wacom->features;
  414. unsigned char *data = wacom->data;
  415. struct input_dev *input = wacom->input;
  416. unsigned int t;
  417. /* general pen packet */
  418. if ((data[1] & 0xb8) == 0xa0) {
  419. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  420. if (features->type >= INTUOS4S && features->type <= WACOM_24HD) {
  421. t = (t << 1) | (data[1] & 1);
  422. }
  423. input_report_abs(input, ABS_PRESSURE, t);
  424. input_report_abs(input, ABS_TILT_X,
  425. ((data[7] << 1) & 0x7e) | (data[8] >> 7));
  426. input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
  427. input_report_key(input, BTN_STYLUS, data[1] & 2);
  428. input_report_key(input, BTN_STYLUS2, data[1] & 4);
  429. input_report_key(input, BTN_TOUCH, t > 10);
  430. }
  431. /* airbrush second packet */
  432. if ((data[1] & 0xbc) == 0xb4) {
  433. input_report_abs(input, ABS_WHEEL,
  434. (data[6] << 2) | ((data[7] >> 6) & 3));
  435. input_report_abs(input, ABS_TILT_X,
  436. ((data[7] << 1) & 0x7e) | (data[8] >> 7));
  437. input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
  438. }
  439. }
  440. static int wacom_intuos_irq(struct wacom_wac *wacom)
  441. {
  442. struct wacom_features *features = &wacom->features;
  443. unsigned char *data = wacom->data;
  444. struct input_dev *input = wacom->input;
  445. unsigned int t;
  446. int idx = 0, result;
  447. if (data[0] != WACOM_REPORT_PENABLED &&
  448. data[0] != WACOM_REPORT_INTUOSREAD &&
  449. data[0] != WACOM_REPORT_INTUOSWRITE &&
  450. data[0] != WACOM_REPORT_INTUOSPAD &&
  451. data[0] != WACOM_REPORT_INTUOS5PAD) {
  452. dev_dbg(input->dev.parent,
  453. "%s: received unknown report #%d\n", __func__, data[0]);
  454. return 0;
  455. }
  456. /* tool number */
  457. if (features->type == INTUOS)
  458. idx = data[1] & 0x01;
  459. /* pad packets. Works as a second tool and is always in prox */
  460. if (data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD) {
  461. if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
  462. input_report_key(input, BTN_0, (data[2] & 0x01));
  463. input_report_key(input, BTN_1, (data[3] & 0x01));
  464. input_report_key(input, BTN_2, (data[3] & 0x02));
  465. input_report_key(input, BTN_3, (data[3] & 0x04));
  466. input_report_key(input, BTN_4, (data[3] & 0x08));
  467. input_report_key(input, BTN_5, (data[3] & 0x10));
  468. input_report_key(input, BTN_6, (data[3] & 0x20));
  469. if (data[1] & 0x80) {
  470. input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
  471. } else {
  472. /* Out of proximity, clear wheel value. */
  473. input_report_abs(input, ABS_WHEEL, 0);
  474. }
  475. if (features->type != INTUOS4S) {
  476. input_report_key(input, BTN_7, (data[3] & 0x40));
  477. input_report_key(input, BTN_8, (data[3] & 0x80));
  478. }
  479. if (data[1] | (data[2] & 0x01) | data[3]) {
  480. input_report_key(input, wacom->tool[1], 1);
  481. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  482. } else {
  483. input_report_key(input, wacom->tool[1], 0);
  484. input_report_abs(input, ABS_MISC, 0);
  485. }
  486. } else if (features->type == WACOM_24HD) {
  487. input_report_key(input, BTN_0, (data[6] & 0x01));
  488. input_report_key(input, BTN_1, (data[6] & 0x02));
  489. input_report_key(input, BTN_2, (data[6] & 0x04));
  490. input_report_key(input, BTN_3, (data[6] & 0x08));
  491. input_report_key(input, BTN_4, (data[6] & 0x10));
  492. input_report_key(input, BTN_5, (data[6] & 0x20));
  493. input_report_key(input, BTN_6, (data[6] & 0x40));
  494. input_report_key(input, BTN_7, (data[6] & 0x80));
  495. input_report_key(input, BTN_8, (data[8] & 0x01));
  496. input_report_key(input, BTN_9, (data[8] & 0x02));
  497. input_report_key(input, BTN_A, (data[8] & 0x04));
  498. input_report_key(input, BTN_B, (data[8] & 0x08));
  499. input_report_key(input, BTN_C, (data[8] & 0x10));
  500. input_report_key(input, BTN_X, (data[8] & 0x20));
  501. input_report_key(input, BTN_Y, (data[8] & 0x40));
  502. input_report_key(input, BTN_Z, (data[8] & 0x80));
  503. /*
  504. * Three "buttons" are available on the 24HD which are
  505. * physically implemented as a touchstrip. Each button
  506. * is approximately 3 bits wide with a 2 bit spacing.
  507. * The raw touchstrip bits are stored at:
  508. * ((data[3] & 0x1f) << 8) | data[4])
  509. */
  510. input_report_key(input, KEY_PROG1, data[4] & 0x07);
  511. input_report_key(input, KEY_PROG2, data[4] & 0xE0);
  512. input_report_key(input, KEY_PROG3, data[3] & 0x1C);
  513. if (data[1] & 0x80) {
  514. input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
  515. } else {
  516. /* Out of proximity, clear wheel value. */
  517. input_report_abs(input, ABS_WHEEL, 0);
  518. }
  519. if (data[2] & 0x80) {
  520. input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
  521. } else {
  522. /* Out of proximity, clear second wheel value. */
  523. input_report_abs(input, ABS_THROTTLE, 0);
  524. }
  525. if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
  526. input_report_key(input, wacom->tool[1], 1);
  527. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  528. } else {
  529. input_report_key(input, wacom->tool[1], 0);
  530. input_report_abs(input, ABS_MISC, 0);
  531. }
  532. } else if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
  533. int i;
  534. /* Touch ring mode switch has no capacitive sensor */
  535. input_report_key(input, BTN_0, (data[3] & 0x01));
  536. /*
  537. * ExpressKeys on Intuos5 have a capacitive sensor in
  538. * addition to the mechanical switch. Switch data is
  539. * stored in data[4], capacitive data in data[5].
  540. */
  541. for (i = 0; i < 8; i++)
  542. input_report_key(input, BTN_1 + i, data[4] & (1 << i));
  543. if (data[2] & 0x80) {
  544. input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
  545. } else {
  546. /* Out of proximity, clear wheel value. */
  547. input_report_abs(input, ABS_WHEEL, 0);
  548. }
  549. if (data[2] | (data[3] & 0x01) | data[4] | data[5]) {
  550. input_report_key(input, wacom->tool[1], 1);
  551. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  552. } else {
  553. input_report_key(input, wacom->tool[1], 0);
  554. input_report_abs(input, ABS_MISC, 0);
  555. }
  556. } else {
  557. if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
  558. input_report_key(input, BTN_0, (data[5] & 0x01));
  559. input_report_key(input, BTN_1, (data[6] & 0x01));
  560. input_report_key(input, BTN_2, (data[6] & 0x02));
  561. input_report_key(input, BTN_3, (data[6] & 0x04));
  562. input_report_key(input, BTN_4, (data[6] & 0x08));
  563. input_report_key(input, BTN_5, (data[6] & 0x10));
  564. input_report_key(input, BTN_6, (data[6] & 0x20));
  565. input_report_key(input, BTN_7, (data[6] & 0x40));
  566. input_report_key(input, BTN_8, (data[6] & 0x80));
  567. input_report_key(input, BTN_9, (data[7] & 0x01));
  568. input_report_key(input, BTN_A, (data[8] & 0x01));
  569. input_report_key(input, BTN_B, (data[8] & 0x02));
  570. input_report_key(input, BTN_C, (data[8] & 0x04));
  571. input_report_key(input, BTN_X, (data[8] & 0x08));
  572. input_report_key(input, BTN_Y, (data[8] & 0x10));
  573. input_report_key(input, BTN_Z, (data[8] & 0x20));
  574. input_report_key(input, BTN_BASE, (data[8] & 0x40));
  575. input_report_key(input, BTN_BASE2, (data[8] & 0x80));
  576. if (features->type == WACOM_22HD) {
  577. input_report_key(input, KEY_PROG1, data[9] & 0x01);
  578. input_report_key(input, KEY_PROG2, data[9] & 0x02);
  579. input_report_key(input, KEY_PROG3, data[9] & 0x04);
  580. }
  581. } else {
  582. input_report_key(input, BTN_0, (data[5] & 0x01));
  583. input_report_key(input, BTN_1, (data[5] & 0x02));
  584. input_report_key(input, BTN_2, (data[5] & 0x04));
  585. input_report_key(input, BTN_3, (data[5] & 0x08));
  586. input_report_key(input, BTN_4, (data[6] & 0x01));
  587. input_report_key(input, BTN_5, (data[6] & 0x02));
  588. input_report_key(input, BTN_6, (data[6] & 0x04));
  589. input_report_key(input, BTN_7, (data[6] & 0x08));
  590. input_report_key(input, BTN_8, (data[5] & 0x10));
  591. input_report_key(input, BTN_9, (data[6] & 0x10));
  592. }
  593. input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
  594. input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
  595. if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
  596. data[2] | (data[3] & 0x1f) | data[4] | data[8] |
  597. (data[7] & 0x01)) {
  598. input_report_key(input, wacom->tool[1], 1);
  599. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  600. } else {
  601. input_report_key(input, wacom->tool[1], 0);
  602. input_report_abs(input, ABS_MISC, 0);
  603. }
  604. }
  605. input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
  606. return 1;
  607. }
  608. /* process in/out prox events */
  609. result = wacom_intuos_inout(wacom);
  610. if (result)
  611. return result - 1;
  612. /* don't proceed if we don't know the ID */
  613. if (!wacom->id[idx])
  614. return 0;
  615. /* Only large Intuos support Lense Cursor */
  616. if (wacom->tool[idx] == BTN_TOOL_LENS &&
  617. (features->type == INTUOS3 ||
  618. features->type == INTUOS3S ||
  619. features->type == INTUOS4 ||
  620. features->type == INTUOS4S ||
  621. features->type == INTUOS5 ||
  622. features->type == INTUOS5S)) {
  623. return 0;
  624. }
  625. /* Cintiq doesn't send data when RDY bit isn't set */
  626. if (features->type == CINTIQ && !(data[1] & 0x40))
  627. return 0;
  628. if (features->type >= INTUOS3S) {
  629. input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
  630. input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
  631. input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
  632. } else {
  633. input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
  634. input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
  635. input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
  636. }
  637. /* process general packets */
  638. wacom_intuos_general(wacom);
  639. /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
  640. if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
  641. if (data[1] & 0x02) {
  642. /* Rotation packet */
  643. if (features->type >= INTUOS3S) {
  644. /* I3 marker pen rotation */
  645. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  646. t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
  647. ((t-1) / 2 + 450)) : (450 - t / 2) ;
  648. input_report_abs(input, ABS_Z, t);
  649. } else {
  650. /* 4D mouse rotation packet */
  651. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  652. input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
  653. ((t - 1) / 2) : -t / 2);
  654. }
  655. } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
  656. /* 4D mouse packet */
  657. input_report_key(input, BTN_LEFT, data[8] & 0x01);
  658. input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
  659. input_report_key(input, BTN_RIGHT, data[8] & 0x04);
  660. input_report_key(input, BTN_SIDE, data[8] & 0x20);
  661. input_report_key(input, BTN_EXTRA, data[8] & 0x10);
  662. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  663. input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
  664. } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
  665. /* I4 mouse */
  666. if ((features->type >= INTUOS4S && features->type <= INTUOS4L) ||
  667. (features->type >= INTUOS5S && features->type <= INTUOS5L)) {
  668. input_report_key(input, BTN_LEFT, data[6] & 0x01);
  669. input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
  670. input_report_key(input, BTN_RIGHT, data[6] & 0x04);
  671. input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
  672. - ((data[7] & 0x40) >> 6));
  673. input_report_key(input, BTN_SIDE, data[6] & 0x08);
  674. input_report_key(input, BTN_EXTRA, data[6] & 0x10);
  675. input_report_abs(input, ABS_TILT_X,
  676. ((data[7] << 1) & 0x7e) | (data[8] >> 7));
  677. input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
  678. } else {
  679. /* 2D mouse packet */
  680. input_report_key(input, BTN_LEFT, data[8] & 0x04);
  681. input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
  682. input_report_key(input, BTN_RIGHT, data[8] & 0x10);
  683. input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
  684. - ((data[8] & 0x02) >> 1));
  685. /* I3 2D mouse side buttons */
  686. if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
  687. input_report_key(input, BTN_SIDE, data[8] & 0x40);
  688. input_report_key(input, BTN_EXTRA, data[8] & 0x20);
  689. }
  690. }
  691. } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
  692. features->type == INTUOS4L || features->type == INTUOS5L) &&
  693. wacom->tool[idx] == BTN_TOOL_LENS) {
  694. /* Lens cursor packets */
  695. input_report_key(input, BTN_LEFT, data[8] & 0x01);
  696. input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
  697. input_report_key(input, BTN_RIGHT, data[8] & 0x04);
  698. input_report_key(input, BTN_SIDE, data[8] & 0x10);
  699. input_report_key(input, BTN_EXTRA, data[8] & 0x08);
  700. }
  701. }
  702. input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
  703. input_report_key(input, wacom->tool[idx], 1);
  704. input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  705. return 1;
  706. }
  707. static int find_slot_from_contactid(struct wacom_wac *wacom, int contactid)
  708. {
  709. int touch_max = wacom->features.touch_max;
  710. int i;
  711. if (!wacom->slots)
  712. return -1;
  713. for (i = 0; i < touch_max; ++i) {
  714. if (wacom->slots[i] == contactid)
  715. return i;
  716. }
  717. for (i = 0; i < touch_max; ++i) {
  718. if (wacom->slots[i] == -1)
  719. return i;
  720. }
  721. return -1;
  722. }
  723. static int int_dist(int x1, int y1, int x2, int y2)
  724. {
  725. int x = x2 - x1;
  726. int y = y2 - y1;
  727. return int_sqrt(x*x + y*y);
  728. }
  729. static int wacom_24hdt_irq(struct wacom_wac *wacom)
  730. {
  731. struct input_dev *input = wacom->input;
  732. char *data = wacom->data;
  733. int i;
  734. int current_num_contacts = data[61];
  735. int contacts_to_send = 0;
  736. /*
  737. * First packet resets the counter since only the first
  738. * packet in series will have non-zero current_num_contacts.
  739. */
  740. if (current_num_contacts)
  741. wacom->num_contacts_left = current_num_contacts;
  742. /* There are at most 4 contacts per packet */
  743. contacts_to_send = min(4, wacom->num_contacts_left);
  744. for (i = 0; i < contacts_to_send; i++) {
  745. int offset = (WACOM_BYTES_PER_24HDT_PACKET * i) + 1;
  746. bool touch = data[offset] & 0x1 && !wacom->shared->stylus_in_proximity;
  747. int id = data[offset + 1];
  748. int slot = find_slot_from_contactid(wacom, id);
  749. if (slot < 0)
  750. continue;
  751. input_mt_slot(input, slot);
  752. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  753. if (touch) {
  754. int t_x = le16_to_cpup((__le16 *)&data[offset + 2]);
  755. int c_x = le16_to_cpup((__le16 *)&data[offset + 4]);
  756. int t_y = le16_to_cpup((__le16 *)&data[offset + 6]);
  757. int c_y = le16_to_cpup((__le16 *)&data[offset + 8]);
  758. int w = le16_to_cpup((__le16 *)&data[offset + 10]);
  759. int h = le16_to_cpup((__le16 *)&data[offset + 12]);
  760. input_report_abs(input, ABS_MT_POSITION_X, t_x);
  761. input_report_abs(input, ABS_MT_POSITION_Y, t_y);
  762. input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
  763. input_report_abs(input, ABS_MT_WIDTH_MAJOR, min(w, h) + int_dist(t_x, t_y, c_x, c_y));
  764. input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
  765. input_report_abs(input, ABS_MT_ORIENTATION, w > h);
  766. }
  767. wacom->slots[slot] = touch ? id : -1;
  768. }
  769. input_mt_report_pointer_emulation(input, true);
  770. wacom->num_contacts_left -= contacts_to_send;
  771. if (wacom->num_contacts_left <= 0)
  772. wacom->num_contacts_left = 0;
  773. return 1;
  774. }
  775. static int wacom_mt_touch(struct wacom_wac *wacom)
  776. {
  777. struct input_dev *input = wacom->input;
  778. char *data = wacom->data;
  779. int i;
  780. int current_num_contacts = data[2];
  781. int contacts_to_send = 0;
  782. int x_offset = 0;
  783. /* MTTPC does not support Height and Width */
  784. if (wacom->features.type == MTTPC)
  785. x_offset = -4;
  786. /*
  787. * First packet resets the counter since only the first
  788. * packet in series will have non-zero current_num_contacts.
  789. */
  790. if (current_num_contacts)
  791. wacom->num_contacts_left = current_num_contacts;
  792. /* There are at most 5 contacts per packet */
  793. contacts_to_send = min(5, wacom->num_contacts_left);
  794. for (i = 0; i < contacts_to_send; i++) {
  795. int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
  796. bool touch = data[offset] & 0x1;
  797. int id = le16_to_cpup((__le16 *)&data[offset + 1]);
  798. int slot = find_slot_from_contactid(wacom, id);
  799. if (slot < 0)
  800. continue;
  801. input_mt_slot(input, slot);
  802. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  803. if (touch) {
  804. int x = le16_to_cpup((__le16 *)&data[offset + x_offset + 7]);
  805. int y = le16_to_cpup((__le16 *)&data[offset + x_offset + 9]);
  806. input_report_abs(input, ABS_MT_POSITION_X, x);
  807. input_report_abs(input, ABS_MT_POSITION_Y, y);
  808. }
  809. wacom->slots[slot] = touch ? id : -1;
  810. }
  811. input_mt_report_pointer_emulation(input, true);
  812. wacom->num_contacts_left -= contacts_to_send;
  813. if (wacom->num_contacts_left < 0)
  814. wacom->num_contacts_left = 0;
  815. return 1;
  816. }
  817. static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
  818. {
  819. struct input_dev *input = wacom->input;
  820. unsigned char *data = wacom->data;
  821. int contact_with_no_pen_down_count = 0;
  822. int i;
  823. for (i = 0; i < 2; i++) {
  824. int p = data[1] & (1 << i);
  825. bool touch = p && !wacom->shared->stylus_in_proximity;
  826. input_mt_slot(input, i);
  827. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  828. if (touch) {
  829. int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
  830. int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
  831. input_report_abs(input, ABS_MT_POSITION_X, x);
  832. input_report_abs(input, ABS_MT_POSITION_Y, y);
  833. contact_with_no_pen_down_count++;
  834. }
  835. }
  836. /* keep touch state for pen event */
  837. wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
  838. input_mt_report_pointer_emulation(input, true);
  839. return 1;
  840. }
  841. static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
  842. {
  843. char *data = wacom->data;
  844. struct input_dev *input = wacom->input;
  845. bool prox;
  846. int x = 0, y = 0;
  847. if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
  848. return 0;
  849. if (!wacom->shared->stylus_in_proximity) {
  850. if (len == WACOM_PKGLEN_TPC1FG) {
  851. prox = data[0] & 0x01;
  852. x = get_unaligned_le16(&data[1]);
  853. y = get_unaligned_le16(&data[3]);
  854. } else {
  855. prox = data[1] & 0x01;
  856. x = le16_to_cpup((__le16 *)&data[2]);
  857. y = le16_to_cpup((__le16 *)&data[4]);
  858. }
  859. } else
  860. /* force touch out when pen is in prox */
  861. prox = 0;
  862. if (prox) {
  863. input_report_abs(input, ABS_X, x);
  864. input_report_abs(input, ABS_Y, y);
  865. }
  866. input_report_key(input, BTN_TOUCH, prox);
  867. /* keep touch state for pen events */
  868. wacom->shared->touch_down = prox;
  869. return 1;
  870. }
  871. static int wacom_tpc_pen(struct wacom_wac *wacom)
  872. {
  873. struct wacom_features *features = &wacom->features;
  874. char *data = wacom->data;
  875. struct input_dev *input = wacom->input;
  876. int pressure;
  877. bool prox = data[1] & 0x20;
  878. if (!wacom->shared->stylus_in_proximity) /* first in prox */
  879. /* Going into proximity select tool */
  880. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  881. /* keep pen state for touch events */
  882. wacom->shared->stylus_in_proximity = prox;
  883. /* send pen events only when touch is up or forced out */
  884. if (!wacom->shared->touch_down) {
  885. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  886. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  887. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  888. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  889. pressure = ((data[7] & 0x01) << 8) | data[6];
  890. if (pressure < 0)
  891. pressure = features->pressure_max + pressure + 1;
  892. input_report_abs(input, ABS_PRESSURE, pressure);
  893. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  894. input_report_key(input, wacom->tool[0], prox);
  895. return 1;
  896. }
  897. return 0;
  898. }
  899. static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
  900. {
  901. char *data = wacom->data;
  902. dev_dbg(wacom->input->dev.parent,
  903. "%s: received report #%d\n", __func__, data[0]);
  904. switch (len) {
  905. case WACOM_PKGLEN_TPC1FG:
  906. return wacom_tpc_single_touch(wacom, len);
  907. case WACOM_PKGLEN_TPC2FG:
  908. return wacom_tpc_mt_touch(wacom);
  909. default:
  910. switch (data[0]) {
  911. case WACOM_REPORT_TPC1FG:
  912. case WACOM_REPORT_TPCHID:
  913. case WACOM_REPORT_TPCST:
  914. case WACOM_REPORT_TPC1FGE:
  915. return wacom_tpc_single_touch(wacom, len);
  916. case WACOM_REPORT_TPCMT:
  917. return wacom_mt_touch(wacom);
  918. case WACOM_REPORT_PENABLED:
  919. return wacom_tpc_pen(wacom);
  920. }
  921. }
  922. return 0;
  923. }
  924. static int wacom_bpt_touch(struct wacom_wac *wacom)
  925. {
  926. struct wacom_features *features = &wacom->features;
  927. struct input_dev *input = wacom->input;
  928. unsigned char *data = wacom->data;
  929. int i;
  930. if (data[0] != 0x02)
  931. return 0;
  932. for (i = 0; i < 2; i++) {
  933. int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
  934. bool touch = data[offset + 3] & 0x80;
  935. /*
  936. * Touch events need to be disabled while stylus is
  937. * in proximity because user's hand is resting on touchpad
  938. * and sending unwanted events. User expects tablet buttons
  939. * to continue working though.
  940. */
  941. touch = touch && !wacom->shared->stylus_in_proximity;
  942. input_mt_slot(input, i);
  943. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  944. if (touch) {
  945. int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
  946. int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
  947. if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
  948. x <<= 5;
  949. y <<= 5;
  950. }
  951. input_report_abs(input, ABS_MT_POSITION_X, x);
  952. input_report_abs(input, ABS_MT_POSITION_Y, y);
  953. }
  954. }
  955. input_mt_report_pointer_emulation(input, true);
  956. input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
  957. input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
  958. input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
  959. input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
  960. input_sync(input);
  961. return 0;
  962. }
  963. static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
  964. {
  965. struct input_dev *input = wacom->input;
  966. int slot_id = data[0] - 2; /* data[0] is between 2 and 17 */
  967. bool touch = data[1] & 0x80;
  968. touch = touch && !wacom->shared->stylus_in_proximity;
  969. input_mt_slot(input, slot_id);
  970. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  971. if (touch) {
  972. int x = (data[2] << 4) | (data[4] >> 4);
  973. int y = (data[3] << 4) | (data[4] & 0x0f);
  974. int a = data[5];
  975. // "a" is a scaled-down area which we assume is roughly
  976. // circular and which can be described as: a=(pi*r^2)/C.
  977. int x_res = input_abs_get_res(input, ABS_X);
  978. int y_res = input_abs_get_res(input, ABS_Y);
  979. int width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
  980. int height = width * y_res / x_res;
  981. input_report_abs(input, ABS_MT_POSITION_X, x);
  982. input_report_abs(input, ABS_MT_POSITION_Y, y);
  983. input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
  984. input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
  985. }
  986. }
  987. static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
  988. {
  989. struct input_dev *input = wacom->input;
  990. input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
  991. input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
  992. input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
  993. input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
  994. }
  995. static int wacom_bpt3_touch(struct wacom_wac *wacom)
  996. {
  997. struct input_dev *input = wacom->input;
  998. unsigned char *data = wacom->data;
  999. int count = data[1] & 0x07;
  1000. int i;
  1001. if (data[0] != 0x02)
  1002. return 0;
  1003. /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
  1004. for (i = 0; i < count; i++) {
  1005. int offset = (8 * i) + 2;
  1006. int msg_id = data[offset];
  1007. if (msg_id >= 2 && msg_id <= 17)
  1008. wacom_bpt3_touch_msg(wacom, data + offset);
  1009. else if (msg_id == 128)
  1010. wacom_bpt3_button_msg(wacom, data + offset);
  1011. }
  1012. input_mt_report_pointer_emulation(input, true);
  1013. input_sync(input);
  1014. return 0;
  1015. }
  1016. static int wacom_bpt_pen(struct wacom_wac *wacom)
  1017. {
  1018. struct input_dev *input = wacom->input;
  1019. unsigned char *data = wacom->data;
  1020. int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
  1021. if (data[0] != 0x02)
  1022. return 0;
  1023. prox = (data[1] & 0x20) == 0x20;
  1024. /*
  1025. * All reports shared between PEN and RUBBER tool must be
  1026. * forced to a known starting value (zero) when transitioning to
  1027. * out-of-prox.
  1028. *
  1029. * If not reset then, to userspace, it will look like lost events
  1030. * if new tool comes in-prox with same values as previous tool sent.
  1031. *
  1032. * Hardware does report zero in most out-of-prox cases but not all.
  1033. */
  1034. if (prox) {
  1035. if (!wacom->shared->stylus_in_proximity) {
  1036. if (data[1] & 0x08) {
  1037. wacom->tool[0] = BTN_TOOL_RUBBER;
  1038. wacom->id[0] = ERASER_DEVICE_ID;
  1039. } else {
  1040. wacom->tool[0] = BTN_TOOL_PEN;
  1041. wacom->id[0] = STYLUS_DEVICE_ID;
  1042. }
  1043. wacom->shared->stylus_in_proximity = true;
  1044. }
  1045. x = le16_to_cpup((__le16 *)&data[2]);
  1046. y = le16_to_cpup((__le16 *)&data[4]);
  1047. p = le16_to_cpup((__le16 *)&data[6]);
  1048. /*
  1049. * Convert distance from out prox to distance from tablet.
  1050. * distance will be greater than distance_max once
  1051. * touching and applying pressure; do not report negative
  1052. * distance.
  1053. */
  1054. if (data[8] <= wacom->features.distance_max)
  1055. d = wacom->features.distance_max - data[8];
  1056. pen = data[1] & 0x01;
  1057. btn1 = data[1] & 0x02;
  1058. btn2 = data[1] & 0x04;
  1059. }
  1060. input_report_key(input, BTN_TOUCH, pen);
  1061. input_report_key(input, BTN_STYLUS, btn1);
  1062. input_report_key(input, BTN_STYLUS2, btn2);
  1063. input_report_abs(input, ABS_X, x);
  1064. input_report_abs(input, ABS_Y, y);
  1065. input_report_abs(input, ABS_PRESSURE, p);
  1066. input_report_abs(input, ABS_DISTANCE, d);
  1067. if (!prox) {
  1068. wacom->id[0] = 0;
  1069. wacom->shared->stylus_in_proximity = false;
  1070. }
  1071. input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
  1072. input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
  1073. return 1;
  1074. }
  1075. static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
  1076. {
  1077. if (len == WACOM_PKGLEN_BBTOUCH)
  1078. return wacom_bpt_touch(wacom);
  1079. else if (len == WACOM_PKGLEN_BBTOUCH3)
  1080. return wacom_bpt3_touch(wacom);
  1081. else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
  1082. return wacom_bpt_pen(wacom);
  1083. return 0;
  1084. }
  1085. static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
  1086. {
  1087. unsigned char *data = wacom->data;
  1088. int connected;
  1089. if (len != WACOM_PKGLEN_WIRELESS || data[0] != 0x80)
  1090. return 0;
  1091. connected = data[1] & 0x01;
  1092. if (connected) {
  1093. int pid, battery;
  1094. pid = get_unaligned_be16(&data[6]);
  1095. battery = data[5] & 0x3f;
  1096. if (wacom->pid != pid) {
  1097. wacom->pid = pid;
  1098. wacom_schedule_work(wacom);
  1099. }
  1100. wacom->battery_capacity = battery;
  1101. } else if (wacom->pid != 0) {
  1102. /* disconnected while previously connected */
  1103. wacom->pid = 0;
  1104. wacom_schedule_work(wacom);
  1105. wacom->battery_capacity = 0;
  1106. }
  1107. return 0;
  1108. }
  1109. void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
  1110. {
  1111. bool sync;
  1112. switch (wacom_wac->features.type) {
  1113. case PENPARTNER:
  1114. sync = wacom_penpartner_irq(wacom_wac);
  1115. break;
  1116. case PL:
  1117. sync = wacom_pl_irq(wacom_wac);
  1118. break;
  1119. case WACOM_G4:
  1120. case GRAPHIRE:
  1121. case WACOM_MO:
  1122. sync = wacom_graphire_irq(wacom_wac);
  1123. break;
  1124. case PTU:
  1125. sync = wacom_ptu_irq(wacom_wac);
  1126. break;
  1127. case DTU:
  1128. sync = wacom_dtu_irq(wacom_wac);
  1129. break;
  1130. case INTUOS:
  1131. case INTUOS3S:
  1132. case INTUOS3:
  1133. case INTUOS3L:
  1134. case INTUOS4S:
  1135. case INTUOS4:
  1136. case INTUOS4L:
  1137. case CINTIQ:
  1138. case WACOM_BEE:
  1139. case WACOM_21UX2:
  1140. case WACOM_22HD:
  1141. case WACOM_24HD:
  1142. sync = wacom_intuos_irq(wacom_wac);
  1143. break;
  1144. case WACOM_24HDT:
  1145. sync = wacom_24hdt_irq(wacom_wac);
  1146. break;
  1147. case INTUOS5S:
  1148. case INTUOS5:
  1149. case INTUOS5L:
  1150. if (len == WACOM_PKGLEN_BBTOUCH3)
  1151. sync = wacom_bpt3_touch(wacom_wac);
  1152. else
  1153. sync = wacom_intuos_irq(wacom_wac);
  1154. break;
  1155. case TABLETPC:
  1156. case TABLETPCE:
  1157. case TABLETPC2FG:
  1158. case MTSCREEN:
  1159. case MTTPC:
  1160. sync = wacom_tpc_irq(wacom_wac, len);
  1161. break;
  1162. case BAMBOO_PT:
  1163. sync = wacom_bpt_irq(wacom_wac, len);
  1164. break;
  1165. case WIRELESS:
  1166. sync = wacom_wireless_irq(wacom_wac, len);
  1167. break;
  1168. default:
  1169. sync = false;
  1170. break;
  1171. }
  1172. if (sync)
  1173. input_sync(wacom_wac->input);
  1174. }
  1175. static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
  1176. {
  1177. struct input_dev *input_dev = wacom_wac->input;
  1178. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  1179. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1180. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1181. __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
  1182. __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
  1183. __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
  1184. __set_bit(BTN_STYLUS, input_dev->keybit);
  1185. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1186. input_set_abs_params(input_dev, ABS_DISTANCE,
  1187. 0, wacom_wac->features.distance_max, 0, 0);
  1188. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  1189. input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
  1190. input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
  1191. }
  1192. static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
  1193. {
  1194. struct input_dev *input_dev = wacom_wac->input;
  1195. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  1196. wacom_setup_cintiq(wacom_wac);
  1197. __set_bit(BTN_LEFT, input_dev->keybit);
  1198. __set_bit(BTN_RIGHT, input_dev->keybit);
  1199. __set_bit(BTN_MIDDLE, input_dev->keybit);
  1200. __set_bit(BTN_SIDE, input_dev->keybit);
  1201. __set_bit(BTN_EXTRA, input_dev->keybit);
  1202. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  1203. __set_bit(BTN_TOOL_LENS, input_dev->keybit);
  1204. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  1205. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  1206. }
  1207. void wacom_setup_device_quirks(struct wacom_features *features)
  1208. {
  1209. /* touch device found but size is not defined. use default */
  1210. if (features->device_type == BTN_TOOL_FINGER && !features->x_max) {
  1211. features->x_max = 1023;
  1212. features->y_max = 1023;
  1213. }
  1214. /* these device have multiple inputs */
  1215. if (features->type >= WIRELESS ||
  1216. (features->type >= INTUOS5S && features->type <= INTUOS5L) ||
  1217. (features->oVid && features->oPid))
  1218. features->quirks |= WACOM_QUIRK_MULTI_INPUT;
  1219. /* quirk for bamboo touch with 2 low res touches */
  1220. if (features->type == BAMBOO_PT &&
  1221. features->pktlen == WACOM_PKGLEN_BBTOUCH) {
  1222. features->x_max <<= 5;
  1223. features->y_max <<= 5;
  1224. features->x_fuzz <<= 5;
  1225. features->y_fuzz <<= 5;
  1226. features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
  1227. }
  1228. if (features->type == WIRELESS) {
  1229. /* monitor never has input and pen/touch have delayed create */
  1230. features->quirks |= WACOM_QUIRK_NO_INPUT;
  1231. /* must be monitor interface if no device_type set */
  1232. if (!features->device_type)
  1233. features->quirks |= WACOM_QUIRK_MONITOR;
  1234. }
  1235. }
  1236. static unsigned int wacom_calculate_touch_res(unsigned int logical_max,
  1237. unsigned int physical_max)
  1238. {
  1239. /* Touch physical dimensions are in 100th of mm */
  1240. return (logical_max * 100) / physical_max;
  1241. }
  1242. int wacom_setup_input_capabilities(struct input_dev *input_dev,
  1243. struct wacom_wac *wacom_wac)
  1244. {
  1245. struct wacom_features *features = &wacom_wac->features;
  1246. int i;
  1247. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  1248. __set_bit(BTN_TOUCH, input_dev->keybit);
  1249. input_set_abs_params(input_dev, ABS_X, 0, features->x_max,
  1250. features->x_fuzz, 0);
  1251. input_set_abs_params(input_dev, ABS_Y, 0, features->y_max,
  1252. features->y_fuzz, 0);
  1253. if (features->device_type == BTN_TOOL_PEN) {
  1254. input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max,
  1255. features->pressure_fuzz, 0);
  1256. /* penabled devices have fixed resolution for each model */
  1257. input_abs_set_res(input_dev, ABS_X, features->x_resolution);
  1258. input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
  1259. } else {
  1260. input_abs_set_res(input_dev, ABS_X,
  1261. wacom_calculate_touch_res(features->x_max,
  1262. features->x_phy));
  1263. input_abs_set_res(input_dev, ABS_Y,
  1264. wacom_calculate_touch_res(features->y_max,
  1265. features->y_phy));
  1266. }
  1267. __set_bit(ABS_MISC, input_dev->absbit);
  1268. switch (wacom_wac->features.type) {
  1269. case WACOM_MO:
  1270. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  1271. /* fall through */
  1272. case WACOM_G4:
  1273. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  1274. __set_bit(BTN_BACK, input_dev->keybit);
  1275. __set_bit(BTN_FORWARD, input_dev->keybit);
  1276. /* fall through */
  1277. case GRAPHIRE:
  1278. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  1279. __set_bit(BTN_LEFT, input_dev->keybit);
  1280. __set_bit(BTN_RIGHT, input_dev->keybit);
  1281. __set_bit(BTN_MIDDLE, input_dev->keybit);
  1282. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1283. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1284. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  1285. __set_bit(BTN_STYLUS, input_dev->keybit);
  1286. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1287. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1288. break;
  1289. case WACOM_24HD:
  1290. __set_bit(BTN_A, input_dev->keybit);
  1291. __set_bit(BTN_B, input_dev->keybit);
  1292. __set_bit(BTN_C, input_dev->keybit);
  1293. __set_bit(BTN_X, input_dev->keybit);
  1294. __set_bit(BTN_Y, input_dev->keybit);
  1295. __set_bit(BTN_Z, input_dev->keybit);
  1296. for (i = 0; i < 10; i++)
  1297. __set_bit(BTN_0 + i, input_dev->keybit);
  1298. __set_bit(KEY_PROG1, input_dev->keybit);
  1299. __set_bit(KEY_PROG2, input_dev->keybit);
  1300. __set_bit(KEY_PROG3, input_dev->keybit);
  1301. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1302. input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
  1303. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1304. wacom_setup_cintiq(wacom_wac);
  1305. break;
  1306. case WACOM_22HD:
  1307. __set_bit(KEY_PROG1, input_dev->keybit);
  1308. __set_bit(KEY_PROG2, input_dev->keybit);
  1309. __set_bit(KEY_PROG3, input_dev->keybit);
  1310. /* fall through */
  1311. case WACOM_21UX2:
  1312. __set_bit(BTN_A, input_dev->keybit);
  1313. __set_bit(BTN_B, input_dev->keybit);
  1314. __set_bit(BTN_C, input_dev->keybit);
  1315. __set_bit(BTN_X, input_dev->keybit);
  1316. __set_bit(BTN_Y, input_dev->keybit);
  1317. __set_bit(BTN_Z, input_dev->keybit);
  1318. __set_bit(BTN_BASE, input_dev->keybit);
  1319. __set_bit(BTN_BASE2, input_dev->keybit);
  1320. /* fall through */
  1321. case WACOM_BEE:
  1322. __set_bit(BTN_8, input_dev->keybit);
  1323. __set_bit(BTN_9, input_dev->keybit);
  1324. /* fall through */
  1325. case CINTIQ:
  1326. for (i = 0; i < 8; i++)
  1327. __set_bit(BTN_0 + i, input_dev->keybit);
  1328. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  1329. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  1330. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1331. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1332. wacom_setup_cintiq(wacom_wac);
  1333. break;
  1334. case INTUOS3:
  1335. case INTUOS3L:
  1336. __set_bit(BTN_4, input_dev->keybit);
  1337. __set_bit(BTN_5, input_dev->keybit);
  1338. __set_bit(BTN_6, input_dev->keybit);
  1339. __set_bit(BTN_7, input_dev->keybit);
  1340. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  1341. /* fall through */
  1342. case INTUOS3S:
  1343. __set_bit(BTN_0, input_dev->keybit);
  1344. __set_bit(BTN_1, input_dev->keybit);
  1345. __set_bit(BTN_2, input_dev->keybit);
  1346. __set_bit(BTN_3, input_dev->keybit);
  1347. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  1348. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1349. /* fall through */
  1350. case INTUOS:
  1351. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1352. wacom_setup_intuos(wacom_wac);
  1353. break;
  1354. case INTUOS5:
  1355. case INTUOS5L:
  1356. if (features->device_type == BTN_TOOL_PEN) {
  1357. __set_bit(BTN_7, input_dev->keybit);
  1358. __set_bit(BTN_8, input_dev->keybit);
  1359. }
  1360. /* fall through */
  1361. case INTUOS5S:
  1362. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1363. if (features->device_type == BTN_TOOL_PEN) {
  1364. for (i = 0; i < 7; i++)
  1365. __set_bit(BTN_0 + i, input_dev->keybit);
  1366. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  1367. features->distance_max,
  1368. 0, 0);
  1369. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1370. wacom_setup_intuos(wacom_wac);
  1371. } else if (features->device_type == BTN_TOOL_FINGER) {
  1372. __clear_bit(ABS_MISC, input_dev->absbit);
  1373. __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
  1374. __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
  1375. __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
  1376. __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
  1377. input_mt_init_slots(input_dev, features->touch_max, 0);
  1378. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
  1379. 0, features->x_max, 0, 0);
  1380. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
  1381. 0, features->y_max, 0, 0);
  1382. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  1383. 0, features->x_max,
  1384. features->x_fuzz, 0);
  1385. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  1386. 0, features->y_max,
  1387. features->y_fuzz, 0);
  1388. }
  1389. break;
  1390. case INTUOS4:
  1391. case INTUOS4L:
  1392. __set_bit(BTN_7, input_dev->keybit);
  1393. __set_bit(BTN_8, input_dev->keybit);
  1394. /* fall through */
  1395. case INTUOS4S:
  1396. for (i = 0; i < 7; i++)
  1397. __set_bit(BTN_0 + i, input_dev->keybit);
  1398. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1399. wacom_setup_intuos(wacom_wac);
  1400. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1401. break;
  1402. case WACOM_24HDT:
  1403. if (features->device_type == BTN_TOOL_FINGER) {
  1404. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
  1405. input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
  1406. input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
  1407. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  1408. }
  1409. /* fall through */
  1410. case MTSCREEN:
  1411. case MTTPC:
  1412. if (features->device_type == BTN_TOOL_FINGER) {
  1413. wacom_wac->slots = kmalloc(features->touch_max *
  1414. sizeof(int),
  1415. GFP_KERNEL);
  1416. if (!wacom_wac->slots)
  1417. return -ENOMEM;
  1418. for (i = 0; i < features->touch_max; i++)
  1419. wacom_wac->slots[i] = -1;
  1420. }
  1421. /* fall through */
  1422. case TABLETPC2FG:
  1423. if (features->device_type == BTN_TOOL_FINGER) {
  1424. input_mt_init_slots(input_dev, features->touch_max, 0);
  1425. input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
  1426. 0, MT_TOOL_MAX, 0, 0);
  1427. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  1428. 0, features->x_max, 0, 0);
  1429. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  1430. 0, features->y_max, 0, 0);
  1431. }
  1432. /* fall through */
  1433. case TABLETPC:
  1434. case TABLETPCE:
  1435. __clear_bit(ABS_MISC, input_dev->absbit);
  1436. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1437. if (features->device_type != BTN_TOOL_PEN)
  1438. break; /* no need to process stylus stuff */
  1439. /* fall through */
  1440. case PL:
  1441. case DTU:
  1442. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1443. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1444. __set_bit(BTN_STYLUS, input_dev->keybit);
  1445. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1446. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1447. break;
  1448. case PTU:
  1449. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1450. /* fall through */
  1451. case PENPARTNER:
  1452. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1453. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1454. __set_bit(BTN_STYLUS, input_dev->keybit);
  1455. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1456. break;
  1457. case BAMBOO_PT:
  1458. __clear_bit(ABS_MISC, input_dev->absbit);
  1459. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1460. if (features->device_type == BTN_TOOL_FINGER) {
  1461. __set_bit(BTN_LEFT, input_dev->keybit);
  1462. __set_bit(BTN_FORWARD, input_dev->keybit);
  1463. __set_bit(BTN_BACK, input_dev->keybit);
  1464. __set_bit(BTN_RIGHT, input_dev->keybit);
  1465. __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
  1466. __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
  1467. input_mt_init_slots(input_dev, features->touch_max, 0);
  1468. if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
  1469. __set_bit(BTN_TOOL_TRIPLETAP,
  1470. input_dev->keybit);
  1471. __set_bit(BTN_TOOL_QUADTAP,
  1472. input_dev->keybit);
  1473. input_set_abs_params(input_dev,
  1474. ABS_MT_TOUCH_MAJOR,
  1475. 0, features->x_max, 0, 0);
  1476. input_set_abs_params(input_dev,
  1477. ABS_MT_TOUCH_MINOR,
  1478. 0, features->y_max, 0, 0);
  1479. }
  1480. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  1481. 0, features->x_max,
  1482. features->x_fuzz, 0);
  1483. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  1484. 0, features->y_max,
  1485. features->y_fuzz, 0);
  1486. } else if (features->device_type == BTN_TOOL_PEN) {
  1487. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1488. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1489. __set_bit(BTN_STYLUS, input_dev->keybit);
  1490. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1491. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  1492. features->distance_max,
  1493. 0, 0);
  1494. }
  1495. break;
  1496. }
  1497. return 0;
  1498. }
  1499. static const struct wacom_features wacom_features_0x00 =
  1500. { "Wacom Penpartner", WACOM_PKGLEN_PENPRTN, 5040, 3780, 255,
  1501. 0, PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  1502. static const struct wacom_features wacom_features_0x10 =
  1503. { "Wacom Graphire", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511,
  1504. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1505. static const struct wacom_features wacom_features_0x11 =
  1506. { "Wacom Graphire2 4x5", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511,
  1507. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1508. static const struct wacom_features wacom_features_0x12 =
  1509. { "Wacom Graphire2 5x7", WACOM_PKGLEN_GRAPHIRE, 13918, 10206, 511,
  1510. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1511. static const struct wacom_features wacom_features_0x13 =
  1512. { "Wacom Graphire3", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511,
  1513. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1514. static const struct wacom_features wacom_features_0x14 =
  1515. { "Wacom Graphire3 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511,
  1516. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1517. static const struct wacom_features wacom_features_0x15 =
  1518. { "Wacom Graphire4 4x5", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511,
  1519. 63, WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1520. static const struct wacom_features wacom_features_0x16 =
  1521. { "Wacom Graphire4 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511,
  1522. 63, WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1523. static const struct wacom_features wacom_features_0x17 =
  1524. { "Wacom BambooFun 4x5", WACOM_PKGLEN_BBFUN, 14760, 9225, 511,
  1525. 63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1526. static const struct wacom_features wacom_features_0x18 =
  1527. { "Wacom BambooFun 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 511,
  1528. 63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1529. static const struct wacom_features wacom_features_0x19 =
  1530. { "Wacom Bamboo1 Medium", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511,
  1531. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1532. static const struct wacom_features wacom_features_0x60 =
  1533. { "Wacom Volito", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511,
  1534. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1535. static const struct wacom_features wacom_features_0x61 =
  1536. { "Wacom PenStation2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 255,
  1537. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1538. static const struct wacom_features wacom_features_0x62 =
  1539. { "Wacom Volito2 4x5", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511,
  1540. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1541. static const struct wacom_features wacom_features_0x63 =
  1542. { "Wacom Volito2 2x3", WACOM_PKGLEN_GRAPHIRE, 3248, 2320, 511,
  1543. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1544. static const struct wacom_features wacom_features_0x64 =
  1545. { "Wacom PenPartner2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 511,
  1546. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1547. static const struct wacom_features wacom_features_0x65 =
  1548. { "Wacom Bamboo", WACOM_PKGLEN_BBFUN, 14760, 9225, 511,
  1549. 63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1550. static const struct wacom_features wacom_features_0x69 =
  1551. { "Wacom Bamboo1", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511,
  1552. 63, GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  1553. static const struct wacom_features wacom_features_0x6A =
  1554. { "Wacom Bamboo1 4x6", WACOM_PKGLEN_GRAPHIRE, 14760, 9225, 1023,
  1555. 63, GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1556. static const struct wacom_features wacom_features_0x6B =
  1557. { "Wacom Bamboo1 5x8", WACOM_PKGLEN_GRAPHIRE, 21648, 13530, 1023,
  1558. 63, GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1559. static const struct wacom_features wacom_features_0x20 =
  1560. { "Wacom Intuos 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023,
  1561. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1562. static const struct wacom_features wacom_features_0x21 =
  1563. { "Wacom Intuos 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
  1564. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1565. static const struct wacom_features wacom_features_0x22 =
  1566. { "Wacom Intuos 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023,
  1567. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1568. static const struct wacom_features wacom_features_0x23 =
  1569. { "Wacom Intuos 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023,
  1570. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1571. static const struct wacom_features wacom_features_0x24 =
  1572. { "Wacom Intuos 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023,
  1573. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1574. static const struct wacom_features wacom_features_0x30 =
  1575. { "Wacom PL400", WACOM_PKGLEN_GRAPHIRE, 5408, 4056, 255,
  1576. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1577. static const struct wacom_features wacom_features_0x31 =
  1578. { "Wacom PL500", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 255,
  1579. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1580. static const struct wacom_features wacom_features_0x32 =
  1581. { "Wacom PL600", WACOM_PKGLEN_GRAPHIRE, 6126, 4604, 255,
  1582. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1583. static const struct wacom_features wacom_features_0x33 =
  1584. { "Wacom PL600SX", WACOM_PKGLEN_GRAPHIRE, 6260, 5016, 255,
  1585. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1586. static const struct wacom_features wacom_features_0x34 =
  1587. { "Wacom PL550", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 511,
  1588. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1589. static const struct wacom_features wacom_features_0x35 =
  1590. { "Wacom PL800", WACOM_PKGLEN_GRAPHIRE, 7220, 5780, 511,
  1591. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1592. static const struct wacom_features wacom_features_0x37 =
  1593. { "Wacom PL700", WACOM_PKGLEN_GRAPHIRE, 6758, 5406, 511,
  1594. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1595. static const struct wacom_features wacom_features_0x38 =
  1596. { "Wacom PL510", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511,
  1597. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1598. static const struct wacom_features wacom_features_0x39 =
  1599. { "Wacom DTU710", WACOM_PKGLEN_GRAPHIRE, 34080, 27660, 511,
  1600. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1601. static const struct wacom_features wacom_features_0xC4 =
  1602. { "Wacom DTF521", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511,
  1603. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1604. static const struct wacom_features wacom_features_0xC0 =
  1605. { "Wacom DTF720", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511,
  1606. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1607. static const struct wacom_features wacom_features_0xC2 =
  1608. { "Wacom DTF720a", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511,
  1609. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1610. static const struct wacom_features wacom_features_0x03 =
  1611. { "Wacom Cintiq Partner", WACOM_PKGLEN_GRAPHIRE, 20480, 15360, 511,
  1612. 0, PTU, WACOM_PL_RES, WACOM_PL_RES };
  1613. static const struct wacom_features wacom_features_0x41 =
  1614. { "Wacom Intuos2 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023,
  1615. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1616. static const struct wacom_features wacom_features_0x42 =
  1617. { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
  1618. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1619. static const struct wacom_features wacom_features_0x43 =
  1620. { "Wacom Intuos2 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023,
  1621. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1622. static const struct wacom_features wacom_features_0x44 =
  1623. { "Wacom Intuos2 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023,
  1624. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1625. static const struct wacom_features wacom_features_0x45 =
  1626. { "Wacom Intuos2 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023,
  1627. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1628. static const struct wacom_features wacom_features_0xB0 =
  1629. { "Wacom Intuos3 4x5", WACOM_PKGLEN_INTUOS, 25400, 20320, 1023,
  1630. 63, INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1631. static const struct wacom_features wacom_features_0xB1 =
  1632. { "Wacom Intuos3 6x8", WACOM_PKGLEN_INTUOS, 40640, 30480, 1023,
  1633. 63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1634. static const struct wacom_features wacom_features_0xB2 =
  1635. { "Wacom Intuos3 9x12", WACOM_PKGLEN_INTUOS, 60960, 45720, 1023,
  1636. 63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1637. static const struct wacom_features wacom_features_0xB3 =
  1638. { "Wacom Intuos3 12x12", WACOM_PKGLEN_INTUOS, 60960, 60960, 1023,
  1639. 63, INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1640. static const struct wacom_features wacom_features_0xB4 =
  1641. { "Wacom Intuos3 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 1023,
  1642. 63, INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1643. static const struct wacom_features wacom_features_0xB5 =
  1644. { "Wacom Intuos3 6x11", WACOM_PKGLEN_INTUOS, 54204, 31750, 1023,
  1645. 63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1646. static const struct wacom_features wacom_features_0xB7 =
  1647. { "Wacom Intuos3 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 1023,
  1648. 63, INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1649. static const struct wacom_features wacom_features_0xB8 =
  1650. { "Wacom Intuos4 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047,
  1651. 63, INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1652. static const struct wacom_features wacom_features_0xB9 =
  1653. { "Wacom Intuos4 6x9", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047,
  1654. 63, INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1655. static const struct wacom_features wacom_features_0xBA =
  1656. { "Wacom Intuos4 8x13", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047,
  1657. 63, INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1658. static const struct wacom_features wacom_features_0xBB =
  1659. { "Wacom Intuos4 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 2047,
  1660. 63, INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1661. static const struct wacom_features wacom_features_0xBC =
  1662. { "Wacom Intuos4 WL", WACOM_PKGLEN_INTUOS, 40840, 25400, 2047,
  1663. 63, INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1664. static const struct wacom_features wacom_features_0x26 =
  1665. { "Wacom Intuos5 touch S", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047,
  1666. 63, INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
  1667. .touch_max = 16 };
  1668. static const struct wacom_features wacom_features_0x27 =
  1669. { "Wacom Intuos5 touch M", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047,
  1670. 63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
  1671. .touch_max = 16 };
  1672. static const struct wacom_features wacom_features_0x28 =
  1673. { "Wacom Intuos5 touch L", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047,
  1674. 63, INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
  1675. .touch_max = 16 };
  1676. static const struct wacom_features wacom_features_0x29 =
  1677. { "Wacom Intuos5 S", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047,
  1678. 63, INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1679. static const struct wacom_features wacom_features_0x2A =
  1680. { "Wacom Intuos5 M", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047,
  1681. 63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1682. static const struct wacom_features wacom_features_0xF4 =
  1683. { "Wacom Cintiq 24HD", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047,
  1684. 63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1685. static const struct wacom_features wacom_features_0xF8 =
  1686. { "Wacom Cintiq 24HD touch", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047, /* Pen */
  1687. 63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
  1688. static const struct wacom_features wacom_features_0xF6 =
  1689. { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
  1690. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10 };
  1691. static const struct wacom_features wacom_features_0x3F =
  1692. { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023,
  1693. 63, CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1694. static const struct wacom_features wacom_features_0xC5 =
  1695. { "Wacom Cintiq 20WSX", WACOM_PKGLEN_INTUOS, 86680, 54180, 1023,
  1696. 63, WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1697. static const struct wacom_features wacom_features_0xC6 =
  1698. { "Wacom Cintiq 12WX", WACOM_PKGLEN_INTUOS, 53020, 33440, 1023,
  1699. 63, WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1700. static const struct wacom_features wacom_features_0xC7 =
  1701. { "Wacom DTU1931", WACOM_PKGLEN_GRAPHIRE, 37832, 30305, 511,
  1702. 0, PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1703. static const struct wacom_features wacom_features_0xCE =
  1704. { "Wacom DTU2231", WACOM_PKGLEN_GRAPHIRE, 47864, 27011, 511,
  1705. 0, DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1706. static const struct wacom_features wacom_features_0xF0 =
  1707. { "Wacom DTU1631", WACOM_PKGLEN_GRAPHIRE, 34623, 19553, 511,
  1708. 0, DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1709. static const struct wacom_features wacom_features_0xCC =
  1710. { "Wacom Cintiq 21UX2", WACOM_PKGLEN_INTUOS, 87200, 65600, 2047,
  1711. 63, WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1712. static const struct wacom_features wacom_features_0xFA =
  1713. { "Wacom Cintiq 22HD", WACOM_PKGLEN_INTUOS, 95840, 54260, 2047,
  1714. 63, WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1715. static const struct wacom_features wacom_features_0x90 =
  1716. { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1717. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1718. static const struct wacom_features wacom_features_0x93 =
  1719. { "Wacom ISDv4 93", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1720. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1721. static const struct wacom_features wacom_features_0x97 =
  1722. { "Wacom ISDv4 97", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 511,
  1723. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1724. static const struct wacom_features wacom_features_0x9A =
  1725. { "Wacom ISDv4 9A", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1726. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1727. static const struct wacom_features wacom_features_0x9F =
  1728. { "Wacom ISDv4 9F", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1729. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1730. static const struct wacom_features wacom_features_0xE2 =
  1731. { "Wacom ISDv4 E2", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255,
  1732. 0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1733. .touch_max = 2 };
  1734. static const struct wacom_features wacom_features_0xE3 =
  1735. { "Wacom ISDv4 E3", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255,
  1736. 0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1737. .touch_max = 2 };
  1738. static const struct wacom_features wacom_features_0xE5 =
  1739. { "Wacom ISDv4 E5", WACOM_PKGLEN_MTOUCH, 26202, 16325, 255,
  1740. 0, MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1741. static const struct wacom_features wacom_features_0xE6 =
  1742. { "Wacom ISDv4 E6", WACOM_PKGLEN_TPC2FG, 27760, 15694, 255,
  1743. 0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1744. .touch_max = 2 };
  1745. static const struct wacom_features wacom_features_0xEC =
  1746. { "Wacom ISDv4 EC", WACOM_PKGLEN_GRAPHIRE, 25710, 14500, 255,
  1747. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1748. static const struct wacom_features wacom_features_0xED =
  1749. { "Wacom ISDv4 ED", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1750. 0, TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1751. static const struct wacom_features wacom_features_0xEF =
  1752. { "Wacom ISDv4 EF", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1753. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1754. static const struct wacom_features wacom_features_0x100 =
  1755. { "Wacom ISDv4 100", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
  1756. 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1757. static const struct wacom_features wacom_features_0x101 =
  1758. { "Wacom ISDv4 101", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
  1759. 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1760. static const struct wacom_features wacom_features_0x47 =
  1761. { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
  1762. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1763. static const struct wacom_features wacom_features_0x84 =
  1764. { "Wacom Wireless Receiver", WACOM_PKGLEN_WIRELESS, 0, 0, 0,
  1765. 0, WIRELESS, 0, 0, .touch_max = 16 };
  1766. static const struct wacom_features wacom_features_0xD0 =
  1767. { "Wacom Bamboo 2FG", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1768. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1769. .touch_max = 2 };
  1770. static const struct wacom_features wacom_features_0xD1 =
  1771. { "Wacom Bamboo 2FG 4x5", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1772. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1773. .touch_max = 2 };
  1774. static const struct wacom_features wacom_features_0xD2 =
  1775. { "Wacom Bamboo Craft", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1776. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1777. static const struct wacom_features wacom_features_0xD3 =
  1778. { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1779. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1780. .touch_max = 2 };
  1781. static const struct wacom_features wacom_features_0xD4 =
  1782. { "Wacom Bamboo Pen", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1783. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1784. static const struct wacom_features wacom_features_0xD5 =
  1785. { "Wacom Bamboo Pen 6x8", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1786. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1787. static const struct wacom_features wacom_features_0xD6 =
  1788. { "Wacom BambooPT 2FG 4x5", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1789. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1790. .touch_max = 2 };
  1791. static const struct wacom_features wacom_features_0xD7 =
  1792. { "Wacom BambooPT 2FG Small", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1793. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1794. .touch_max = 2 };
  1795. static const struct wacom_features wacom_features_0xD8 =
  1796. { "Wacom Bamboo Comic 2FG", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1797. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1798. .touch_max = 2 };
  1799. static const struct wacom_features wacom_features_0xDA =
  1800. { "Wacom Bamboo 2FG 4x5 SE", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1801. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1802. .touch_max = 2 };
  1803. static struct wacom_features wacom_features_0xDB =
  1804. { "Wacom Bamboo 2FG 6x8 SE", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1805. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1806. .touch_max = 2 };
  1807. static const struct wacom_features wacom_features_0xDD =
  1808. { "Wacom Bamboo Connect", WACOM_PKGLEN_BBPEN, 14720, 9200, 1023,
  1809. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1810. static const struct wacom_features wacom_features_0xDE =
  1811. { "Wacom Bamboo 16FG 4x5", WACOM_PKGLEN_BBPEN, 14720, 9200, 1023,
  1812. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1813. .touch_max = 16 };
  1814. static const struct wacom_features wacom_features_0xDF =
  1815. { "Wacom Bamboo 16FG 6x8", WACOM_PKGLEN_BBPEN, 21648, 13700, 1023,
  1816. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1817. .touch_max = 16 };
  1818. static const struct wacom_features wacom_features_0x6004 =
  1819. { "ISD-V4", WACOM_PKGLEN_GRAPHIRE, 12800, 8000, 255,
  1820. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1821. #define USB_DEVICE_WACOM(prod) \
  1822. USB_DEVICE(USB_VENDOR_ID_WACOM, prod), \
  1823. .driver_info = (kernel_ulong_t)&wacom_features_##prod
  1824. #define USB_DEVICE_DETAILED(prod, class, sub, proto) \
  1825. USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_WACOM, prod, class, \
  1826. sub, proto), \
  1827. .driver_info = (kernel_ulong_t)&wacom_features_##prod
  1828. #define USB_DEVICE_LENOVO(prod) \
  1829. USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
  1830. .driver_info = (kernel_ulong_t)&wacom_features_##prod
  1831. const struct usb_device_id wacom_ids[] = {
  1832. { USB_DEVICE_WACOM(0x00) },
  1833. { USB_DEVICE_WACOM(0x10) },
  1834. { USB_DEVICE_WACOM(0x11) },
  1835. { USB_DEVICE_WACOM(0x12) },
  1836. { USB_DEVICE_WACOM(0x13) },
  1837. { USB_DEVICE_WACOM(0x14) },
  1838. { USB_DEVICE_WACOM(0x15) },
  1839. { USB_DEVICE_WACOM(0x16) },
  1840. { USB_DEVICE_WACOM(0x17) },
  1841. { USB_DEVICE_WACOM(0x18) },
  1842. { USB_DEVICE_WACOM(0x19) },
  1843. { USB_DEVICE_WACOM(0x60) },
  1844. { USB_DEVICE_WACOM(0x61) },
  1845. { USB_DEVICE_WACOM(0x62) },
  1846. { USB_DEVICE_WACOM(0x63) },
  1847. { USB_DEVICE_WACOM(0x64) },
  1848. { USB_DEVICE_WACOM(0x65) },
  1849. { USB_DEVICE_WACOM(0x69) },
  1850. { USB_DEVICE_WACOM(0x6A) },
  1851. { USB_DEVICE_WACOM(0x6B) },
  1852. { USB_DEVICE_WACOM(0x20) },
  1853. { USB_DEVICE_WACOM(0x21) },
  1854. { USB_DEVICE_WACOM(0x22) },
  1855. { USB_DEVICE_WACOM(0x23) },
  1856. { USB_DEVICE_WACOM(0x24) },
  1857. { USB_DEVICE_WACOM(0x30) },
  1858. { USB_DEVICE_WACOM(0x31) },
  1859. { USB_DEVICE_WACOM(0x32) },
  1860. { USB_DEVICE_WACOM(0x33) },
  1861. { USB_DEVICE_WACOM(0x34) },
  1862. { USB_DEVICE_WACOM(0x35) },
  1863. { USB_DEVICE_WACOM(0x37) },
  1864. { USB_DEVICE_WACOM(0x38) },
  1865. { USB_DEVICE_WACOM(0x39) },
  1866. { USB_DEVICE_WACOM(0xC4) },
  1867. { USB_DEVICE_WACOM(0xC0) },
  1868. { USB_DEVICE_WACOM(0xC2) },
  1869. { USB_DEVICE_WACOM(0x03) },
  1870. { USB_DEVICE_WACOM(0x41) },
  1871. { USB_DEVICE_WACOM(0x42) },
  1872. { USB_DEVICE_WACOM(0x43) },
  1873. { USB_DEVICE_WACOM(0x44) },
  1874. { USB_DEVICE_WACOM(0x45) },
  1875. { USB_DEVICE_WACOM(0xB0) },
  1876. { USB_DEVICE_WACOM(0xB1) },
  1877. { USB_DEVICE_WACOM(0xB2) },
  1878. { USB_DEVICE_WACOM(0xB3) },
  1879. { USB_DEVICE_WACOM(0xB4) },
  1880. { USB_DEVICE_WACOM(0xB5) },
  1881. { USB_DEVICE_WACOM(0xB7) },
  1882. { USB_DEVICE_WACOM(0xB8) },
  1883. { USB_DEVICE_WACOM(0xB9) },
  1884. { USB_DEVICE_WACOM(0xBA) },
  1885. { USB_DEVICE_WACOM(0xBB) },
  1886. { USB_DEVICE_WACOM(0xBC) },
  1887. { USB_DEVICE_WACOM(0x26) },
  1888. { USB_DEVICE_WACOM(0x27) },
  1889. { USB_DEVICE_WACOM(0x28) },
  1890. { USB_DEVICE_WACOM(0x29) },
  1891. { USB_DEVICE_WACOM(0x2A) },
  1892. { USB_DEVICE_WACOM(0x3F) },
  1893. { USB_DEVICE_WACOM(0xC5) },
  1894. { USB_DEVICE_WACOM(0xC6) },
  1895. { USB_DEVICE_WACOM(0xC7) },
  1896. /*
  1897. * DTU-2231 has two interfaces on the same configuration,
  1898. * only one is used.
  1899. */
  1900. { USB_DEVICE_DETAILED(0xCE, USB_CLASS_HID,
  1901. USB_INTERFACE_SUBCLASS_BOOT,
  1902. USB_INTERFACE_PROTOCOL_MOUSE) },
  1903. { USB_DEVICE_WACOM(0x84) },
  1904. { USB_DEVICE_WACOM(0xD0) },
  1905. { USB_DEVICE_WACOM(0xD1) },
  1906. { USB_DEVICE_WACOM(0xD2) },
  1907. { USB_DEVICE_WACOM(0xD3) },
  1908. { USB_DEVICE_WACOM(0xD4) },
  1909. { USB_DEVICE_WACOM(0xD5) },
  1910. { USB_DEVICE_WACOM(0xD6) },
  1911. { USB_DEVICE_WACOM(0xD7) },
  1912. { USB_DEVICE_WACOM(0xD8) },
  1913. { USB_DEVICE_WACOM(0xDA) },
  1914. { USB_DEVICE_WACOM(0xDB) },
  1915. { USB_DEVICE_WACOM(0xDD) },
  1916. { USB_DEVICE_WACOM(0xDE) },
  1917. { USB_DEVICE_WACOM(0xDF) },
  1918. { USB_DEVICE_WACOM(0xF0) },
  1919. { USB_DEVICE_WACOM(0xCC) },
  1920. { USB_DEVICE_WACOM(0x90) },
  1921. { USB_DEVICE_WACOM(0x93) },
  1922. { USB_DEVICE_WACOM(0x97) },
  1923. { USB_DEVICE_WACOM(0x9A) },
  1924. { USB_DEVICE_WACOM(0x9F) },
  1925. { USB_DEVICE_WACOM(0xE2) },
  1926. { USB_DEVICE_WACOM(0xE3) },
  1927. { USB_DEVICE_WACOM(0xE5) },
  1928. { USB_DEVICE_WACOM(0xE6) },
  1929. { USB_DEVICE_WACOM(0xEC) },
  1930. { USB_DEVICE_WACOM(0xED) },
  1931. { USB_DEVICE_WACOM(0xEF) },
  1932. { USB_DEVICE_WACOM(0x100) },
  1933. { USB_DEVICE_WACOM(0x101) },
  1934. { USB_DEVICE_WACOM(0x47) },
  1935. { USB_DEVICE_WACOM(0xF4) },
  1936. { USB_DEVICE_WACOM(0xF8) },
  1937. { USB_DEVICE_WACOM(0xF6) },
  1938. { USB_DEVICE_WACOM(0xFA) },
  1939. { USB_DEVICE_LENOVO(0x6004) },
  1940. { }
  1941. };
  1942. MODULE_DEVICE_TABLE(usb, wacom_ids);