wacom_wac.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  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 int_dist(int x1, int y1, int x2, int y2)
  708. {
  709. int x = x2 - x1;
  710. int y = y2 - y1;
  711. return int_sqrt(x*x + y*y);
  712. }
  713. static int wacom_24hdt_irq(struct wacom_wac *wacom)
  714. {
  715. struct input_dev *input = wacom->input;
  716. char *data = wacom->data;
  717. int i;
  718. int current_num_contacts = data[61];
  719. int contacts_to_send = 0;
  720. /*
  721. * First packet resets the counter since only the first
  722. * packet in series will have non-zero current_num_contacts.
  723. */
  724. if (current_num_contacts)
  725. wacom->num_contacts_left = current_num_contacts;
  726. /* There are at most 4 contacts per packet */
  727. contacts_to_send = min(4, wacom->num_contacts_left);
  728. for (i = 0; i < contacts_to_send; i++) {
  729. int offset = (WACOM_BYTES_PER_24HDT_PACKET * i) + 1;
  730. bool touch = data[offset] & 0x1 && !wacom->shared->stylus_in_proximity;
  731. int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
  732. if (slot < 0)
  733. continue;
  734. input_mt_slot(input, slot);
  735. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  736. if (touch) {
  737. int t_x = le16_to_cpup((__le16 *)&data[offset + 2]);
  738. int c_x = le16_to_cpup((__le16 *)&data[offset + 4]);
  739. int t_y = le16_to_cpup((__le16 *)&data[offset + 6]);
  740. int c_y = le16_to_cpup((__le16 *)&data[offset + 8]);
  741. int w = le16_to_cpup((__le16 *)&data[offset + 10]);
  742. int h = le16_to_cpup((__le16 *)&data[offset + 12]);
  743. input_report_abs(input, ABS_MT_POSITION_X, t_x);
  744. input_report_abs(input, ABS_MT_POSITION_Y, t_y);
  745. input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
  746. input_report_abs(input, ABS_MT_WIDTH_MAJOR, min(w, h) + int_dist(t_x, t_y, c_x, c_y));
  747. input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
  748. input_report_abs(input, ABS_MT_ORIENTATION, w > h);
  749. }
  750. }
  751. input_mt_report_pointer_emulation(input, true);
  752. wacom->num_contacts_left -= contacts_to_send;
  753. if (wacom->num_contacts_left <= 0)
  754. wacom->num_contacts_left = 0;
  755. return 1;
  756. }
  757. static int wacom_mt_touch(struct wacom_wac *wacom)
  758. {
  759. struct input_dev *input = wacom->input;
  760. char *data = wacom->data;
  761. int i;
  762. int current_num_contacts = data[2];
  763. int contacts_to_send = 0;
  764. int x_offset = 0;
  765. /* MTTPC does not support Height and Width */
  766. if (wacom->features.type == MTTPC)
  767. x_offset = -4;
  768. /*
  769. * First packet resets the counter since only the first
  770. * packet in series will have non-zero current_num_contacts.
  771. */
  772. if (current_num_contacts)
  773. wacom->num_contacts_left = current_num_contacts;
  774. /* There are at most 5 contacts per packet */
  775. contacts_to_send = min(5, wacom->num_contacts_left);
  776. for (i = 0; i < contacts_to_send; i++) {
  777. int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
  778. bool touch = data[offset] & 0x1;
  779. int id = le16_to_cpup((__le16 *)&data[offset + 1]);
  780. int slot = input_mt_get_slot_by_key(input, id);
  781. if (slot < 0)
  782. continue;
  783. input_mt_slot(input, slot);
  784. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  785. if (touch) {
  786. int x = le16_to_cpup((__le16 *)&data[offset + x_offset + 7]);
  787. int y = le16_to_cpup((__le16 *)&data[offset + x_offset + 9]);
  788. input_report_abs(input, ABS_MT_POSITION_X, x);
  789. input_report_abs(input, ABS_MT_POSITION_Y, y);
  790. }
  791. }
  792. input_mt_report_pointer_emulation(input, true);
  793. wacom->num_contacts_left -= contacts_to_send;
  794. if (wacom->num_contacts_left < 0)
  795. wacom->num_contacts_left = 0;
  796. return 1;
  797. }
  798. static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
  799. {
  800. struct input_dev *input = wacom->input;
  801. unsigned char *data = wacom->data;
  802. int contact_with_no_pen_down_count = 0;
  803. int i;
  804. for (i = 0; i < 2; i++) {
  805. int p = data[1] & (1 << i);
  806. bool touch = p && !wacom->shared->stylus_in_proximity;
  807. input_mt_slot(input, i);
  808. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  809. if (touch) {
  810. int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
  811. int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
  812. input_report_abs(input, ABS_MT_POSITION_X, x);
  813. input_report_abs(input, ABS_MT_POSITION_Y, y);
  814. contact_with_no_pen_down_count++;
  815. }
  816. }
  817. input_mt_report_pointer_emulation(input, true);
  818. /* keep touch state for pen event */
  819. wacom->shared->touch_down = (contact_with_no_pen_down_count > 0);
  820. return 1;
  821. }
  822. static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
  823. {
  824. char *data = wacom->data;
  825. struct input_dev *input = wacom->input;
  826. bool prox;
  827. int x = 0, y = 0;
  828. if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
  829. return 0;
  830. if (!wacom->shared->stylus_in_proximity) {
  831. if (len == WACOM_PKGLEN_TPC1FG) {
  832. prox = data[0] & 0x01;
  833. x = get_unaligned_le16(&data[1]);
  834. y = get_unaligned_le16(&data[3]);
  835. } else {
  836. prox = data[1] & 0x01;
  837. x = le16_to_cpup((__le16 *)&data[2]);
  838. y = le16_to_cpup((__le16 *)&data[4]);
  839. }
  840. } else
  841. /* force touch out when pen is in prox */
  842. prox = 0;
  843. if (prox) {
  844. input_report_abs(input, ABS_X, x);
  845. input_report_abs(input, ABS_Y, y);
  846. }
  847. input_report_key(input, BTN_TOUCH, prox);
  848. /* keep touch state for pen events */
  849. wacom->shared->touch_down = prox;
  850. return 1;
  851. }
  852. static int wacom_tpc_pen(struct wacom_wac *wacom)
  853. {
  854. struct wacom_features *features = &wacom->features;
  855. char *data = wacom->data;
  856. struct input_dev *input = wacom->input;
  857. int pressure;
  858. bool prox = data[1] & 0x20;
  859. if (!wacom->shared->stylus_in_proximity) /* first in prox */
  860. /* Going into proximity select tool */
  861. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  862. /* keep pen state for touch events */
  863. wacom->shared->stylus_in_proximity = prox;
  864. /* send pen events only when touch is up or forced out */
  865. if (!wacom->shared->touch_down) {
  866. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  867. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  868. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  869. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  870. pressure = ((data[7] & 0x01) << 8) | data[6];
  871. if (pressure < 0)
  872. pressure = features->pressure_max + pressure + 1;
  873. input_report_abs(input, ABS_PRESSURE, pressure);
  874. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  875. input_report_key(input, wacom->tool[0], prox);
  876. return 1;
  877. }
  878. return 0;
  879. }
  880. static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
  881. {
  882. char *data = wacom->data;
  883. dev_dbg(wacom->input->dev.parent,
  884. "%s: received report #%d\n", __func__, data[0]);
  885. switch (len) {
  886. case WACOM_PKGLEN_TPC1FG:
  887. return wacom_tpc_single_touch(wacom, len);
  888. case WACOM_PKGLEN_TPC2FG:
  889. return wacom_tpc_mt_touch(wacom);
  890. default:
  891. switch (data[0]) {
  892. case WACOM_REPORT_TPC1FG:
  893. case WACOM_REPORT_TPCHID:
  894. case WACOM_REPORT_TPCST:
  895. case WACOM_REPORT_TPC1FGE:
  896. return wacom_tpc_single_touch(wacom, len);
  897. case WACOM_REPORT_TPCMT:
  898. return wacom_mt_touch(wacom);
  899. case WACOM_REPORT_PENABLED:
  900. return wacom_tpc_pen(wacom);
  901. }
  902. }
  903. return 0;
  904. }
  905. static int wacom_bpt_touch(struct wacom_wac *wacom)
  906. {
  907. struct wacom_features *features = &wacom->features;
  908. struct input_dev *input = wacom->input;
  909. unsigned char *data = wacom->data;
  910. int i;
  911. if (data[0] != 0x02)
  912. return 0;
  913. for (i = 0; i < 2; i++) {
  914. int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
  915. bool touch = data[offset + 3] & 0x80;
  916. /*
  917. * Touch events need to be disabled while stylus is
  918. * in proximity because user's hand is resting on touchpad
  919. * and sending unwanted events. User expects tablet buttons
  920. * to continue working though.
  921. */
  922. touch = touch && !wacom->shared->stylus_in_proximity;
  923. input_mt_slot(input, i);
  924. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  925. if (touch) {
  926. int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
  927. int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
  928. if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
  929. x <<= 5;
  930. y <<= 5;
  931. }
  932. input_report_abs(input, ABS_MT_POSITION_X, x);
  933. input_report_abs(input, ABS_MT_POSITION_Y, y);
  934. }
  935. }
  936. input_mt_report_pointer_emulation(input, true);
  937. input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
  938. input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
  939. input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
  940. input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
  941. input_sync(input);
  942. return 0;
  943. }
  944. static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
  945. {
  946. struct input_dev *input = wacom->input;
  947. bool touch = data[1] & 0x80;
  948. int slot = input_mt_get_slot_by_key(input, data[0]);
  949. if (slot < 0)
  950. return;
  951. touch = touch && !wacom->shared->stylus_in_proximity;
  952. input_mt_slot(input, slot);
  953. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  954. if (touch) {
  955. int x = (data[2] << 4) | (data[4] >> 4);
  956. int y = (data[3] << 4) | (data[4] & 0x0f);
  957. int a = data[5];
  958. // "a" is a scaled-down area which we assume is roughly
  959. // circular and which can be described as: a=(pi*r^2)/C.
  960. int x_res = input_abs_get_res(input, ABS_X);
  961. int y_res = input_abs_get_res(input, ABS_Y);
  962. int width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
  963. int height = width * y_res / x_res;
  964. input_report_abs(input, ABS_MT_POSITION_X, x);
  965. input_report_abs(input, ABS_MT_POSITION_Y, y);
  966. input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
  967. input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
  968. }
  969. }
  970. static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
  971. {
  972. struct input_dev *input = wacom->input;
  973. input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
  974. input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
  975. input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
  976. input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
  977. }
  978. static int wacom_bpt3_touch(struct wacom_wac *wacom)
  979. {
  980. struct input_dev *input = wacom->input;
  981. unsigned char *data = wacom->data;
  982. int count = data[1] & 0x07;
  983. int i;
  984. if (data[0] != 0x02)
  985. return 0;
  986. /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
  987. for (i = 0; i < count; i++) {
  988. int offset = (8 * i) + 2;
  989. int msg_id = data[offset];
  990. if (msg_id >= 2 && msg_id <= 17)
  991. wacom_bpt3_touch_msg(wacom, data + offset);
  992. else if (msg_id == 128)
  993. wacom_bpt3_button_msg(wacom, data + offset);
  994. }
  995. input_mt_report_pointer_emulation(input, true);
  996. input_sync(input);
  997. return 0;
  998. }
  999. static int wacom_bpt_pen(struct wacom_wac *wacom)
  1000. {
  1001. struct input_dev *input = wacom->input;
  1002. unsigned char *data = wacom->data;
  1003. int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
  1004. if (data[0] != 0x02)
  1005. return 0;
  1006. prox = (data[1] & 0x20) == 0x20;
  1007. /*
  1008. * All reports shared between PEN and RUBBER tool must be
  1009. * forced to a known starting value (zero) when transitioning to
  1010. * out-of-prox.
  1011. *
  1012. * If not reset then, to userspace, it will look like lost events
  1013. * if new tool comes in-prox with same values as previous tool sent.
  1014. *
  1015. * Hardware does report zero in most out-of-prox cases but not all.
  1016. */
  1017. if (prox) {
  1018. if (!wacom->shared->stylus_in_proximity) {
  1019. if (data[1] & 0x08) {
  1020. wacom->tool[0] = BTN_TOOL_RUBBER;
  1021. wacom->id[0] = ERASER_DEVICE_ID;
  1022. } else {
  1023. wacom->tool[0] = BTN_TOOL_PEN;
  1024. wacom->id[0] = STYLUS_DEVICE_ID;
  1025. }
  1026. wacom->shared->stylus_in_proximity = true;
  1027. }
  1028. x = le16_to_cpup((__le16 *)&data[2]);
  1029. y = le16_to_cpup((__le16 *)&data[4]);
  1030. p = le16_to_cpup((__le16 *)&data[6]);
  1031. /*
  1032. * Convert distance from out prox to distance from tablet.
  1033. * distance will be greater than distance_max once
  1034. * touching and applying pressure; do not report negative
  1035. * distance.
  1036. */
  1037. if (data[8] <= wacom->features.distance_max)
  1038. d = wacom->features.distance_max - data[8];
  1039. pen = data[1] & 0x01;
  1040. btn1 = data[1] & 0x02;
  1041. btn2 = data[1] & 0x04;
  1042. }
  1043. input_report_key(input, BTN_TOUCH, pen);
  1044. input_report_key(input, BTN_STYLUS, btn1);
  1045. input_report_key(input, BTN_STYLUS2, btn2);
  1046. input_report_abs(input, ABS_X, x);
  1047. input_report_abs(input, ABS_Y, y);
  1048. input_report_abs(input, ABS_PRESSURE, p);
  1049. input_report_abs(input, ABS_DISTANCE, d);
  1050. if (!prox) {
  1051. wacom->id[0] = 0;
  1052. wacom->shared->stylus_in_proximity = false;
  1053. }
  1054. input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
  1055. input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
  1056. return 1;
  1057. }
  1058. static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
  1059. {
  1060. if (len == WACOM_PKGLEN_BBTOUCH)
  1061. return wacom_bpt_touch(wacom);
  1062. else if (len == WACOM_PKGLEN_BBTOUCH3)
  1063. return wacom_bpt3_touch(wacom);
  1064. else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
  1065. return wacom_bpt_pen(wacom);
  1066. return 0;
  1067. }
  1068. static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
  1069. {
  1070. unsigned char *data = wacom->data;
  1071. int connected;
  1072. if (len != WACOM_PKGLEN_WIRELESS || data[0] != 0x80)
  1073. return 0;
  1074. connected = data[1] & 0x01;
  1075. if (connected) {
  1076. int pid, battery;
  1077. pid = get_unaligned_be16(&data[6]);
  1078. battery = data[5] & 0x3f;
  1079. if (wacom->pid != pid) {
  1080. wacom->pid = pid;
  1081. wacom_schedule_work(wacom);
  1082. }
  1083. wacom->battery_capacity = battery;
  1084. } else if (wacom->pid != 0) {
  1085. /* disconnected while previously connected */
  1086. wacom->pid = 0;
  1087. wacom_schedule_work(wacom);
  1088. wacom->battery_capacity = 0;
  1089. }
  1090. return 0;
  1091. }
  1092. void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
  1093. {
  1094. bool sync;
  1095. switch (wacom_wac->features.type) {
  1096. case PENPARTNER:
  1097. sync = wacom_penpartner_irq(wacom_wac);
  1098. break;
  1099. case PL:
  1100. sync = wacom_pl_irq(wacom_wac);
  1101. break;
  1102. case WACOM_G4:
  1103. case GRAPHIRE:
  1104. case WACOM_MO:
  1105. sync = wacom_graphire_irq(wacom_wac);
  1106. break;
  1107. case PTU:
  1108. sync = wacom_ptu_irq(wacom_wac);
  1109. break;
  1110. case DTU:
  1111. sync = wacom_dtu_irq(wacom_wac);
  1112. break;
  1113. case INTUOS:
  1114. case INTUOS3S:
  1115. case INTUOS3:
  1116. case INTUOS3L:
  1117. case INTUOS4S:
  1118. case INTUOS4:
  1119. case INTUOS4L:
  1120. case CINTIQ:
  1121. case WACOM_BEE:
  1122. case WACOM_21UX2:
  1123. case WACOM_22HD:
  1124. case WACOM_24HD:
  1125. sync = wacom_intuos_irq(wacom_wac);
  1126. break;
  1127. case WACOM_24HDT:
  1128. sync = wacom_24hdt_irq(wacom_wac);
  1129. break;
  1130. case INTUOS5S:
  1131. case INTUOS5:
  1132. case INTUOS5L:
  1133. if (len == WACOM_PKGLEN_BBTOUCH3)
  1134. sync = wacom_bpt3_touch(wacom_wac);
  1135. else
  1136. sync = wacom_intuos_irq(wacom_wac);
  1137. break;
  1138. case TABLETPC:
  1139. case TABLETPCE:
  1140. case TABLETPC2FG:
  1141. case MTSCREEN:
  1142. case MTTPC:
  1143. sync = wacom_tpc_irq(wacom_wac, len);
  1144. break;
  1145. case BAMBOO_PT:
  1146. sync = wacom_bpt_irq(wacom_wac, len);
  1147. break;
  1148. case WIRELESS:
  1149. sync = wacom_wireless_irq(wacom_wac, len);
  1150. break;
  1151. default:
  1152. sync = false;
  1153. break;
  1154. }
  1155. if (sync)
  1156. input_sync(wacom_wac->input);
  1157. }
  1158. static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
  1159. {
  1160. struct input_dev *input_dev = wacom_wac->input;
  1161. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  1162. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1163. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1164. __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
  1165. __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
  1166. __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
  1167. __set_bit(BTN_STYLUS, input_dev->keybit);
  1168. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1169. input_set_abs_params(input_dev, ABS_DISTANCE,
  1170. 0, wacom_wac->features.distance_max, 0, 0);
  1171. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  1172. input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
  1173. input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
  1174. }
  1175. static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
  1176. {
  1177. struct input_dev *input_dev = wacom_wac->input;
  1178. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  1179. wacom_setup_cintiq(wacom_wac);
  1180. __set_bit(BTN_LEFT, input_dev->keybit);
  1181. __set_bit(BTN_RIGHT, input_dev->keybit);
  1182. __set_bit(BTN_MIDDLE, input_dev->keybit);
  1183. __set_bit(BTN_SIDE, input_dev->keybit);
  1184. __set_bit(BTN_EXTRA, input_dev->keybit);
  1185. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  1186. __set_bit(BTN_TOOL_LENS, input_dev->keybit);
  1187. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  1188. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  1189. }
  1190. void wacom_setup_device_quirks(struct wacom_features *features)
  1191. {
  1192. /* touch device found but size is not defined. use default */
  1193. if (features->device_type == BTN_TOOL_FINGER && !features->x_max) {
  1194. features->x_max = 1023;
  1195. features->y_max = 1023;
  1196. }
  1197. /* these device have multiple inputs */
  1198. if (features->type >= WIRELESS ||
  1199. (features->type >= INTUOS5S && features->type <= INTUOS5L) ||
  1200. (features->oVid && features->oPid))
  1201. features->quirks |= WACOM_QUIRK_MULTI_INPUT;
  1202. /* quirk for bamboo touch with 2 low res touches */
  1203. if (features->type == BAMBOO_PT &&
  1204. features->pktlen == WACOM_PKGLEN_BBTOUCH) {
  1205. features->x_max <<= 5;
  1206. features->y_max <<= 5;
  1207. features->x_fuzz <<= 5;
  1208. features->y_fuzz <<= 5;
  1209. features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
  1210. }
  1211. if (features->type == WIRELESS) {
  1212. /* monitor never has input and pen/touch have delayed create */
  1213. features->quirks |= WACOM_QUIRK_NO_INPUT;
  1214. /* must be monitor interface if no device_type set */
  1215. if (!features->device_type)
  1216. features->quirks |= WACOM_QUIRK_MONITOR;
  1217. }
  1218. }
  1219. static unsigned int wacom_calculate_touch_res(unsigned int logical_max,
  1220. unsigned int physical_max)
  1221. {
  1222. /* Touch physical dimensions are in 100th of mm */
  1223. return (logical_max * 100) / physical_max;
  1224. }
  1225. static void wacom_abs_set_axis(struct input_dev *input_dev,
  1226. struct wacom_wac *wacom_wac)
  1227. {
  1228. struct wacom_features *features = &wacom_wac->features;
  1229. if (features->device_type == BTN_TOOL_PEN) {
  1230. input_set_abs_params(input_dev, ABS_X, 0, features->x_max,
  1231. features->x_fuzz, 0);
  1232. input_set_abs_params(input_dev, ABS_Y, 0, features->y_max,
  1233. features->y_fuzz, 0);
  1234. input_set_abs_params(input_dev, ABS_PRESSURE, 0,
  1235. features->pressure_max, features->pressure_fuzz, 0);
  1236. /* penabled devices have fixed resolution for each model */
  1237. input_abs_set_res(input_dev, ABS_X, features->x_resolution);
  1238. input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
  1239. } else {
  1240. if (features->touch_max <= 2) {
  1241. input_set_abs_params(input_dev, ABS_X, 0,
  1242. features->x_max, features->x_fuzz, 0);
  1243. input_set_abs_params(input_dev, ABS_Y, 0,
  1244. features->y_max, features->y_fuzz, 0);
  1245. input_abs_set_res(input_dev, ABS_X,
  1246. wacom_calculate_touch_res(features->x_max,
  1247. features->x_phy));
  1248. input_abs_set_res(input_dev, ABS_Y,
  1249. wacom_calculate_touch_res(features->y_max,
  1250. features->y_phy));
  1251. }
  1252. if (features->touch_max > 1) {
  1253. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
  1254. features->x_max, features->x_fuzz, 0);
  1255. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
  1256. features->y_max, features->y_fuzz, 0);
  1257. input_abs_set_res(input_dev, ABS_MT_POSITION_X,
  1258. wacom_calculate_touch_res(features->x_max,
  1259. features->x_phy));
  1260. input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
  1261. wacom_calculate_touch_res(features->y_max,
  1262. features->y_phy));
  1263. }
  1264. }
  1265. }
  1266. int wacom_setup_input_capabilities(struct input_dev *input_dev,
  1267. struct wacom_wac *wacom_wac)
  1268. {
  1269. struct wacom_features *features = &wacom_wac->features;
  1270. int i;
  1271. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  1272. __set_bit(BTN_TOUCH, input_dev->keybit);
  1273. __set_bit(ABS_MISC, input_dev->absbit);
  1274. wacom_abs_set_axis(input_dev, wacom_wac);
  1275. switch (wacom_wac->features.type) {
  1276. case WACOM_MO:
  1277. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  1278. /* fall through */
  1279. case WACOM_G4:
  1280. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  1281. __set_bit(BTN_BACK, input_dev->keybit);
  1282. __set_bit(BTN_FORWARD, input_dev->keybit);
  1283. /* fall through */
  1284. case GRAPHIRE:
  1285. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  1286. __set_bit(BTN_LEFT, input_dev->keybit);
  1287. __set_bit(BTN_RIGHT, input_dev->keybit);
  1288. __set_bit(BTN_MIDDLE, input_dev->keybit);
  1289. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1290. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1291. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  1292. __set_bit(BTN_STYLUS, input_dev->keybit);
  1293. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1294. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1295. break;
  1296. case WACOM_24HD:
  1297. __set_bit(BTN_A, input_dev->keybit);
  1298. __set_bit(BTN_B, input_dev->keybit);
  1299. __set_bit(BTN_C, input_dev->keybit);
  1300. __set_bit(BTN_X, input_dev->keybit);
  1301. __set_bit(BTN_Y, input_dev->keybit);
  1302. __set_bit(BTN_Z, input_dev->keybit);
  1303. for (i = 0; i < 10; i++)
  1304. __set_bit(BTN_0 + i, input_dev->keybit);
  1305. __set_bit(KEY_PROG1, input_dev->keybit);
  1306. __set_bit(KEY_PROG2, input_dev->keybit);
  1307. __set_bit(KEY_PROG3, input_dev->keybit);
  1308. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1309. input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
  1310. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1311. wacom_setup_cintiq(wacom_wac);
  1312. break;
  1313. case WACOM_22HD:
  1314. __set_bit(KEY_PROG1, input_dev->keybit);
  1315. __set_bit(KEY_PROG2, input_dev->keybit);
  1316. __set_bit(KEY_PROG3, input_dev->keybit);
  1317. /* fall through */
  1318. case WACOM_21UX2:
  1319. __set_bit(BTN_A, input_dev->keybit);
  1320. __set_bit(BTN_B, input_dev->keybit);
  1321. __set_bit(BTN_C, input_dev->keybit);
  1322. __set_bit(BTN_X, input_dev->keybit);
  1323. __set_bit(BTN_Y, input_dev->keybit);
  1324. __set_bit(BTN_Z, input_dev->keybit);
  1325. __set_bit(BTN_BASE, input_dev->keybit);
  1326. __set_bit(BTN_BASE2, input_dev->keybit);
  1327. /* fall through */
  1328. case WACOM_BEE:
  1329. __set_bit(BTN_8, input_dev->keybit);
  1330. __set_bit(BTN_9, input_dev->keybit);
  1331. /* fall through */
  1332. case CINTIQ:
  1333. for (i = 0; i < 8; i++)
  1334. __set_bit(BTN_0 + i, input_dev->keybit);
  1335. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  1336. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  1337. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1338. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1339. wacom_setup_cintiq(wacom_wac);
  1340. break;
  1341. case INTUOS3:
  1342. case INTUOS3L:
  1343. __set_bit(BTN_4, input_dev->keybit);
  1344. __set_bit(BTN_5, input_dev->keybit);
  1345. __set_bit(BTN_6, input_dev->keybit);
  1346. __set_bit(BTN_7, input_dev->keybit);
  1347. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  1348. /* fall through */
  1349. case INTUOS3S:
  1350. __set_bit(BTN_0, input_dev->keybit);
  1351. __set_bit(BTN_1, input_dev->keybit);
  1352. __set_bit(BTN_2, input_dev->keybit);
  1353. __set_bit(BTN_3, input_dev->keybit);
  1354. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  1355. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1356. /* fall through */
  1357. case INTUOS:
  1358. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1359. wacom_setup_intuos(wacom_wac);
  1360. break;
  1361. case INTUOS5:
  1362. case INTUOS5L:
  1363. if (features->device_type == BTN_TOOL_PEN) {
  1364. __set_bit(BTN_7, input_dev->keybit);
  1365. __set_bit(BTN_8, input_dev->keybit);
  1366. }
  1367. /* fall through */
  1368. case INTUOS5S:
  1369. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1370. if (features->device_type == BTN_TOOL_PEN) {
  1371. for (i = 0; i < 7; i++)
  1372. __set_bit(BTN_0 + i, input_dev->keybit);
  1373. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  1374. features->distance_max,
  1375. 0, 0);
  1376. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1377. wacom_setup_intuos(wacom_wac);
  1378. } else if (features->device_type == BTN_TOOL_FINGER) {
  1379. __clear_bit(ABS_MISC, input_dev->absbit);
  1380. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
  1381. 0, features->x_max, 0, 0);
  1382. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
  1383. 0, features->y_max, 0, 0);
  1384. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
  1385. }
  1386. break;
  1387. case INTUOS4:
  1388. case INTUOS4L:
  1389. __set_bit(BTN_7, input_dev->keybit);
  1390. __set_bit(BTN_8, input_dev->keybit);
  1391. /* fall through */
  1392. case INTUOS4S:
  1393. for (i = 0; i < 7; i++)
  1394. __set_bit(BTN_0 + i, input_dev->keybit);
  1395. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  1396. wacom_setup_intuos(wacom_wac);
  1397. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1398. break;
  1399. case WACOM_24HDT:
  1400. if (features->device_type == BTN_TOOL_FINGER) {
  1401. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
  1402. input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
  1403. input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
  1404. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  1405. }
  1406. /* fall through */
  1407. case MTSCREEN:
  1408. case MTTPC:
  1409. case TABLETPC2FG:
  1410. if (features->device_type == BTN_TOOL_FINGER) {
  1411. unsigned int flags = INPUT_MT_DIRECT;
  1412. if (wacom_wac->features.type == TABLETPC2FG)
  1413. flags = 0;
  1414. input_mt_init_slots(input_dev, features->touch_max, flags);
  1415. }
  1416. /* fall through */
  1417. case TABLETPC:
  1418. case TABLETPCE:
  1419. __clear_bit(ABS_MISC, input_dev->absbit);
  1420. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1421. if (features->device_type != BTN_TOOL_PEN)
  1422. break; /* no need to process stylus stuff */
  1423. /* fall through */
  1424. case PL:
  1425. case DTU:
  1426. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1427. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1428. __set_bit(BTN_STYLUS, input_dev->keybit);
  1429. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1430. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1431. break;
  1432. case PTU:
  1433. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1434. /* fall through */
  1435. case PENPARTNER:
  1436. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1437. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1438. __set_bit(BTN_STYLUS, input_dev->keybit);
  1439. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1440. break;
  1441. case BAMBOO_PT:
  1442. __clear_bit(ABS_MISC, input_dev->absbit);
  1443. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  1444. if (features->device_type == BTN_TOOL_FINGER) {
  1445. unsigned int flags = INPUT_MT_POINTER;
  1446. __set_bit(BTN_LEFT, input_dev->keybit);
  1447. __set_bit(BTN_FORWARD, input_dev->keybit);
  1448. __set_bit(BTN_BACK, input_dev->keybit);
  1449. __set_bit(BTN_RIGHT, input_dev->keybit);
  1450. if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
  1451. input_set_abs_params(input_dev,
  1452. ABS_MT_TOUCH_MAJOR,
  1453. 0, features->x_max, 0, 0);
  1454. input_set_abs_params(input_dev,
  1455. ABS_MT_TOUCH_MINOR,
  1456. 0, features->y_max, 0, 0);
  1457. } else {
  1458. __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
  1459. __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
  1460. flags = 0;
  1461. }
  1462. input_mt_init_slots(input_dev, features->touch_max, flags);
  1463. } else if (features->device_type == BTN_TOOL_PEN) {
  1464. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  1465. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  1466. __set_bit(BTN_STYLUS, input_dev->keybit);
  1467. __set_bit(BTN_STYLUS2, input_dev->keybit);
  1468. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  1469. features->distance_max,
  1470. 0, 0);
  1471. }
  1472. break;
  1473. }
  1474. return 0;
  1475. }
  1476. static const struct wacom_features wacom_features_0x00 =
  1477. { "Wacom Penpartner", WACOM_PKGLEN_PENPRTN, 5040, 3780, 255,
  1478. 0, PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  1479. static const struct wacom_features wacom_features_0x10 =
  1480. { "Wacom Graphire", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511,
  1481. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1482. static const struct wacom_features wacom_features_0x11 =
  1483. { "Wacom Graphire2 4x5", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511,
  1484. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1485. static const struct wacom_features wacom_features_0x12 =
  1486. { "Wacom Graphire2 5x7", WACOM_PKGLEN_GRAPHIRE, 13918, 10206, 511,
  1487. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1488. static const struct wacom_features wacom_features_0x13 =
  1489. { "Wacom Graphire3", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511,
  1490. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1491. static const struct wacom_features wacom_features_0x14 =
  1492. { "Wacom Graphire3 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511,
  1493. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1494. static const struct wacom_features wacom_features_0x15 =
  1495. { "Wacom Graphire4 4x5", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511,
  1496. 63, WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1497. static const struct wacom_features wacom_features_0x16 =
  1498. { "Wacom Graphire4 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511,
  1499. 63, WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1500. static const struct wacom_features wacom_features_0x17 =
  1501. { "Wacom BambooFun 4x5", WACOM_PKGLEN_BBFUN, 14760, 9225, 511,
  1502. 63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1503. static const struct wacom_features wacom_features_0x18 =
  1504. { "Wacom BambooFun 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 511,
  1505. 63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1506. static const struct wacom_features wacom_features_0x19 =
  1507. { "Wacom Bamboo1 Medium", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511,
  1508. 63, GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  1509. static const struct wacom_features wacom_features_0x60 =
  1510. { "Wacom Volito", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511,
  1511. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1512. static const struct wacom_features wacom_features_0x61 =
  1513. { "Wacom PenStation2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 255,
  1514. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1515. static const struct wacom_features wacom_features_0x62 =
  1516. { "Wacom Volito2 4x5", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511,
  1517. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1518. static const struct wacom_features wacom_features_0x63 =
  1519. { "Wacom Volito2 2x3", WACOM_PKGLEN_GRAPHIRE, 3248, 2320, 511,
  1520. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1521. static const struct wacom_features wacom_features_0x64 =
  1522. { "Wacom PenPartner2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 511,
  1523. 63, GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  1524. static const struct wacom_features wacom_features_0x65 =
  1525. { "Wacom Bamboo", WACOM_PKGLEN_BBFUN, 14760, 9225, 511,
  1526. 63, WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1527. static const struct wacom_features wacom_features_0x69 =
  1528. { "Wacom Bamboo1", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511,
  1529. 63, GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  1530. static const struct wacom_features wacom_features_0x6A =
  1531. { "Wacom Bamboo1 4x6", WACOM_PKGLEN_GRAPHIRE, 14760, 9225, 1023,
  1532. 63, GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1533. static const struct wacom_features wacom_features_0x6B =
  1534. { "Wacom Bamboo1 5x8", WACOM_PKGLEN_GRAPHIRE, 21648, 13530, 1023,
  1535. 63, GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1536. static const struct wacom_features wacom_features_0x20 =
  1537. { "Wacom Intuos 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023,
  1538. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1539. static const struct wacom_features wacom_features_0x21 =
  1540. { "Wacom Intuos 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
  1541. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1542. static const struct wacom_features wacom_features_0x22 =
  1543. { "Wacom Intuos 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023,
  1544. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1545. static const struct wacom_features wacom_features_0x23 =
  1546. { "Wacom Intuos 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023,
  1547. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1548. static const struct wacom_features wacom_features_0x24 =
  1549. { "Wacom Intuos 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023,
  1550. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1551. static const struct wacom_features wacom_features_0x30 =
  1552. { "Wacom PL400", WACOM_PKGLEN_GRAPHIRE, 5408, 4056, 255,
  1553. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1554. static const struct wacom_features wacom_features_0x31 =
  1555. { "Wacom PL500", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 255,
  1556. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1557. static const struct wacom_features wacom_features_0x32 =
  1558. { "Wacom PL600", WACOM_PKGLEN_GRAPHIRE, 6126, 4604, 255,
  1559. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1560. static const struct wacom_features wacom_features_0x33 =
  1561. { "Wacom PL600SX", WACOM_PKGLEN_GRAPHIRE, 6260, 5016, 255,
  1562. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1563. static const struct wacom_features wacom_features_0x34 =
  1564. { "Wacom PL550", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 511,
  1565. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1566. static const struct wacom_features wacom_features_0x35 =
  1567. { "Wacom PL800", WACOM_PKGLEN_GRAPHIRE, 7220, 5780, 511,
  1568. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1569. static const struct wacom_features wacom_features_0x37 =
  1570. { "Wacom PL700", WACOM_PKGLEN_GRAPHIRE, 6758, 5406, 511,
  1571. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1572. static const struct wacom_features wacom_features_0x38 =
  1573. { "Wacom PL510", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511,
  1574. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1575. static const struct wacom_features wacom_features_0x39 =
  1576. { "Wacom DTU710", WACOM_PKGLEN_GRAPHIRE, 34080, 27660, 511,
  1577. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1578. static const struct wacom_features wacom_features_0xC4 =
  1579. { "Wacom DTF521", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511,
  1580. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1581. static const struct wacom_features wacom_features_0xC0 =
  1582. { "Wacom DTF720", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511,
  1583. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1584. static const struct wacom_features wacom_features_0xC2 =
  1585. { "Wacom DTF720a", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511,
  1586. 0, PL, WACOM_PL_RES, WACOM_PL_RES };
  1587. static const struct wacom_features wacom_features_0x03 =
  1588. { "Wacom Cintiq Partner", WACOM_PKGLEN_GRAPHIRE, 20480, 15360, 511,
  1589. 0, PTU, WACOM_PL_RES, WACOM_PL_RES };
  1590. static const struct wacom_features wacom_features_0x41 =
  1591. { "Wacom Intuos2 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023,
  1592. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1593. static const struct wacom_features wacom_features_0x42 =
  1594. { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
  1595. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1596. static const struct wacom_features wacom_features_0x43 =
  1597. { "Wacom Intuos2 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023,
  1598. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1599. static const struct wacom_features wacom_features_0x44 =
  1600. { "Wacom Intuos2 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023,
  1601. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1602. static const struct wacom_features wacom_features_0x45 =
  1603. { "Wacom Intuos2 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023,
  1604. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1605. static const struct wacom_features wacom_features_0xB0 =
  1606. { "Wacom Intuos3 4x5", WACOM_PKGLEN_INTUOS, 25400, 20320, 1023,
  1607. 63, INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1608. static const struct wacom_features wacom_features_0xB1 =
  1609. { "Wacom Intuos3 6x8", WACOM_PKGLEN_INTUOS, 40640, 30480, 1023,
  1610. 63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1611. static const struct wacom_features wacom_features_0xB2 =
  1612. { "Wacom Intuos3 9x12", WACOM_PKGLEN_INTUOS, 60960, 45720, 1023,
  1613. 63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1614. static const struct wacom_features wacom_features_0xB3 =
  1615. { "Wacom Intuos3 12x12", WACOM_PKGLEN_INTUOS, 60960, 60960, 1023,
  1616. 63, INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1617. static const struct wacom_features wacom_features_0xB4 =
  1618. { "Wacom Intuos3 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 1023,
  1619. 63, INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1620. static const struct wacom_features wacom_features_0xB5 =
  1621. { "Wacom Intuos3 6x11", WACOM_PKGLEN_INTUOS, 54204, 31750, 1023,
  1622. 63, INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1623. static const struct wacom_features wacom_features_0xB7 =
  1624. { "Wacom Intuos3 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 1023,
  1625. 63, INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1626. static const struct wacom_features wacom_features_0xB8 =
  1627. { "Wacom Intuos4 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047,
  1628. 63, INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1629. static const struct wacom_features wacom_features_0xB9 =
  1630. { "Wacom Intuos4 6x9", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047,
  1631. 63, INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1632. static const struct wacom_features wacom_features_0xBA =
  1633. { "Wacom Intuos4 8x13", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047,
  1634. 63, INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1635. static const struct wacom_features wacom_features_0xBB =
  1636. { "Wacom Intuos4 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 2047,
  1637. 63, INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1638. static const struct wacom_features wacom_features_0xBC =
  1639. { "Wacom Intuos4 WL", WACOM_PKGLEN_INTUOS, 40840, 25400, 2047,
  1640. 63, INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1641. static const struct wacom_features wacom_features_0x26 =
  1642. { "Wacom Intuos5 touch S", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047,
  1643. 63, INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
  1644. .touch_max = 16 };
  1645. static const struct wacom_features wacom_features_0x27 =
  1646. { "Wacom Intuos5 touch M", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047,
  1647. 63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
  1648. .touch_max = 16 };
  1649. static const struct wacom_features wacom_features_0x28 =
  1650. { "Wacom Intuos5 touch L", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047,
  1651. 63, INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
  1652. .touch_max = 16 };
  1653. static const struct wacom_features wacom_features_0x29 =
  1654. { "Wacom Intuos5 S", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047,
  1655. 63, INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1656. static const struct wacom_features wacom_features_0x2A =
  1657. { "Wacom Intuos5 M", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047,
  1658. 63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1659. static const struct wacom_features wacom_features_0xF4 =
  1660. { "Wacom Cintiq 24HD", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047,
  1661. 63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1662. static const struct wacom_features wacom_features_0xF8 =
  1663. { "Wacom Cintiq 24HD touch", WACOM_PKGLEN_INTUOS, 104480, 65600, 2047, /* Pen */
  1664. 63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
  1665. static const struct wacom_features wacom_features_0xF6 =
  1666. { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
  1667. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10 };
  1668. static const struct wacom_features wacom_features_0x3F =
  1669. { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023,
  1670. 63, CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1671. static const struct wacom_features wacom_features_0xC5 =
  1672. { "Wacom Cintiq 20WSX", WACOM_PKGLEN_INTUOS, 86680, 54180, 1023,
  1673. 63, WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1674. static const struct wacom_features wacom_features_0xC6 =
  1675. { "Wacom Cintiq 12WX", WACOM_PKGLEN_INTUOS, 53020, 33440, 1023,
  1676. 63, WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1677. static const struct wacom_features wacom_features_0xC7 =
  1678. { "Wacom DTU1931", WACOM_PKGLEN_GRAPHIRE, 37832, 30305, 511,
  1679. 0, PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1680. static const struct wacom_features wacom_features_0xCE =
  1681. { "Wacom DTU2231", WACOM_PKGLEN_GRAPHIRE, 47864, 27011, 511,
  1682. 0, DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1683. static const struct wacom_features wacom_features_0xF0 =
  1684. { "Wacom DTU1631", WACOM_PKGLEN_GRAPHIRE, 34623, 19553, 511,
  1685. 0, DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1686. static const struct wacom_features wacom_features_0xCC =
  1687. { "Wacom Cintiq 21UX2", WACOM_PKGLEN_INTUOS, 87200, 65600, 2047,
  1688. 63, WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1689. static const struct wacom_features wacom_features_0xFA =
  1690. { "Wacom Cintiq 22HD", WACOM_PKGLEN_INTUOS, 95840, 54260, 2047,
  1691. 63, WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
  1692. static const struct wacom_features wacom_features_0x90 =
  1693. { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1694. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1695. static const struct wacom_features wacom_features_0x93 =
  1696. { "Wacom ISDv4 93", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1697. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1698. static const struct wacom_features wacom_features_0x97 =
  1699. { "Wacom ISDv4 97", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 511,
  1700. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1701. static const struct wacom_features wacom_features_0x9A =
  1702. { "Wacom ISDv4 9A", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1703. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1704. static const struct wacom_features wacom_features_0x9F =
  1705. { "Wacom ISDv4 9F", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1706. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1707. static const struct wacom_features wacom_features_0xE2 =
  1708. { "Wacom ISDv4 E2", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255,
  1709. 0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1710. .touch_max = 2 };
  1711. static const struct wacom_features wacom_features_0xE3 =
  1712. { "Wacom ISDv4 E3", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255,
  1713. 0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1714. .touch_max = 2 };
  1715. static const struct wacom_features wacom_features_0xE5 =
  1716. { "Wacom ISDv4 E5", WACOM_PKGLEN_MTOUCH, 26202, 16325, 255,
  1717. 0, MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1718. static const struct wacom_features wacom_features_0xE6 =
  1719. { "Wacom ISDv4 E6", WACOM_PKGLEN_TPC2FG, 27760, 15694, 255,
  1720. 0, TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1721. .touch_max = 2 };
  1722. static const struct wacom_features wacom_features_0xEC =
  1723. { "Wacom ISDv4 EC", WACOM_PKGLEN_GRAPHIRE, 25710, 14500, 255,
  1724. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1725. static const struct wacom_features wacom_features_0xED =
  1726. { "Wacom ISDv4 ED", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1727. 0, TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1728. static const struct wacom_features wacom_features_0xEF =
  1729. { "Wacom ISDv4 EF", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
  1730. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1731. static const struct wacom_features wacom_features_0x100 =
  1732. { "Wacom ISDv4 100", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
  1733. 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1734. static const struct wacom_features wacom_features_0x101 =
  1735. { "Wacom ISDv4 101", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
  1736. 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1737. static const struct wacom_features wacom_features_0x4001 =
  1738. { "Wacom ISDv4 4001", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
  1739. 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1740. static const struct wacom_features wacom_features_0x47 =
  1741. { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
  1742. 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1743. static const struct wacom_features wacom_features_0x84 =
  1744. { "Wacom Wireless Receiver", WACOM_PKGLEN_WIRELESS, 0, 0, 0,
  1745. 0, WIRELESS, 0, 0, .touch_max = 16 };
  1746. static const struct wacom_features wacom_features_0xD0 =
  1747. { "Wacom Bamboo 2FG", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1748. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1749. .touch_max = 2 };
  1750. static const struct wacom_features wacom_features_0xD1 =
  1751. { "Wacom Bamboo 2FG 4x5", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1752. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1753. .touch_max = 2 };
  1754. static const struct wacom_features wacom_features_0xD2 =
  1755. { "Wacom Bamboo Craft", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1756. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1757. static const struct wacom_features wacom_features_0xD3 =
  1758. { "Wacom Bamboo 2FG 6x8", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1759. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1760. .touch_max = 2 };
  1761. static const struct wacom_features wacom_features_0xD4 =
  1762. { "Wacom Bamboo Pen", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1763. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1764. static const struct wacom_features wacom_features_0xD5 =
  1765. { "Wacom Bamboo Pen 6x8", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1766. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1767. static const struct wacom_features wacom_features_0xD6 =
  1768. { "Wacom BambooPT 2FG 4x5", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1769. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1770. .touch_max = 2 };
  1771. static const struct wacom_features wacom_features_0xD7 =
  1772. { "Wacom BambooPT 2FG Small", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1773. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1774. .touch_max = 2 };
  1775. static const struct wacom_features wacom_features_0xD8 =
  1776. { "Wacom Bamboo Comic 2FG", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1777. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1778. .touch_max = 2 };
  1779. static const struct wacom_features wacom_features_0xDA =
  1780. { "Wacom Bamboo 2FG 4x5 SE", WACOM_PKGLEN_BBFUN, 14720, 9200, 1023,
  1781. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1782. .touch_max = 2 };
  1783. static struct wacom_features wacom_features_0xDB =
  1784. { "Wacom Bamboo 2FG 6x8 SE", WACOM_PKGLEN_BBFUN, 21648, 13700, 1023,
  1785. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1786. .touch_max = 2 };
  1787. static const struct wacom_features wacom_features_0xDD =
  1788. { "Wacom Bamboo Connect", WACOM_PKGLEN_BBPEN, 14720, 9200, 1023,
  1789. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1790. static const struct wacom_features wacom_features_0xDE =
  1791. { "Wacom Bamboo 16FG 4x5", WACOM_PKGLEN_BBPEN, 14720, 9200, 1023,
  1792. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1793. .touch_max = 16 };
  1794. static const struct wacom_features wacom_features_0xDF =
  1795. { "Wacom Bamboo 16FG 6x8", WACOM_PKGLEN_BBPEN, 21648, 13700, 1023,
  1796. 31, BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  1797. .touch_max = 16 };
  1798. static const struct wacom_features wacom_features_0x6004 =
  1799. { "ISD-V4", WACOM_PKGLEN_GRAPHIRE, 12800, 8000, 255,
  1800. 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  1801. #define USB_DEVICE_WACOM(prod) \
  1802. USB_DEVICE(USB_VENDOR_ID_WACOM, prod), \
  1803. .driver_info = (kernel_ulong_t)&wacom_features_##prod
  1804. #define USB_DEVICE_DETAILED(prod, class, sub, proto) \
  1805. USB_DEVICE_AND_INTERFACE_INFO(USB_VENDOR_ID_WACOM, prod, class, \
  1806. sub, proto), \
  1807. .driver_info = (kernel_ulong_t)&wacom_features_##prod
  1808. #define USB_DEVICE_LENOVO(prod) \
  1809. USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
  1810. .driver_info = (kernel_ulong_t)&wacom_features_##prod
  1811. const struct usb_device_id wacom_ids[] = {
  1812. { USB_DEVICE_WACOM(0x00) },
  1813. { USB_DEVICE_WACOM(0x10) },
  1814. { USB_DEVICE_WACOM(0x11) },
  1815. { USB_DEVICE_WACOM(0x12) },
  1816. { USB_DEVICE_WACOM(0x13) },
  1817. { USB_DEVICE_WACOM(0x14) },
  1818. { USB_DEVICE_WACOM(0x15) },
  1819. { USB_DEVICE_WACOM(0x16) },
  1820. { USB_DEVICE_WACOM(0x17) },
  1821. { USB_DEVICE_WACOM(0x18) },
  1822. { USB_DEVICE_WACOM(0x19) },
  1823. { USB_DEVICE_WACOM(0x60) },
  1824. { USB_DEVICE_WACOM(0x61) },
  1825. { USB_DEVICE_WACOM(0x62) },
  1826. { USB_DEVICE_WACOM(0x63) },
  1827. { USB_DEVICE_WACOM(0x64) },
  1828. { USB_DEVICE_WACOM(0x65) },
  1829. { USB_DEVICE_WACOM(0x69) },
  1830. { USB_DEVICE_WACOM(0x6A) },
  1831. { USB_DEVICE_WACOM(0x6B) },
  1832. { USB_DEVICE_WACOM(0x20) },
  1833. { USB_DEVICE_WACOM(0x21) },
  1834. { USB_DEVICE_WACOM(0x22) },
  1835. { USB_DEVICE_WACOM(0x23) },
  1836. { USB_DEVICE_WACOM(0x24) },
  1837. { USB_DEVICE_WACOM(0x30) },
  1838. { USB_DEVICE_WACOM(0x31) },
  1839. { USB_DEVICE_WACOM(0x32) },
  1840. { USB_DEVICE_WACOM(0x33) },
  1841. { USB_DEVICE_WACOM(0x34) },
  1842. { USB_DEVICE_WACOM(0x35) },
  1843. { USB_DEVICE_WACOM(0x37) },
  1844. { USB_DEVICE_WACOM(0x38) },
  1845. { USB_DEVICE_WACOM(0x39) },
  1846. { USB_DEVICE_WACOM(0xC4) },
  1847. { USB_DEVICE_WACOM(0xC0) },
  1848. { USB_DEVICE_WACOM(0xC2) },
  1849. { USB_DEVICE_WACOM(0x03) },
  1850. { USB_DEVICE_WACOM(0x41) },
  1851. { USB_DEVICE_WACOM(0x42) },
  1852. { USB_DEVICE_WACOM(0x43) },
  1853. { USB_DEVICE_WACOM(0x44) },
  1854. { USB_DEVICE_WACOM(0x45) },
  1855. { USB_DEVICE_WACOM(0xB0) },
  1856. { USB_DEVICE_WACOM(0xB1) },
  1857. { USB_DEVICE_WACOM(0xB2) },
  1858. { USB_DEVICE_WACOM(0xB3) },
  1859. { USB_DEVICE_WACOM(0xB4) },
  1860. { USB_DEVICE_WACOM(0xB5) },
  1861. { USB_DEVICE_WACOM(0xB7) },
  1862. { USB_DEVICE_WACOM(0xB8) },
  1863. { USB_DEVICE_WACOM(0xB9) },
  1864. { USB_DEVICE_WACOM(0xBA) },
  1865. { USB_DEVICE_WACOM(0xBB) },
  1866. { USB_DEVICE_WACOM(0xBC) },
  1867. { USB_DEVICE_WACOM(0x26) },
  1868. { USB_DEVICE_WACOM(0x27) },
  1869. { USB_DEVICE_WACOM(0x28) },
  1870. { USB_DEVICE_WACOM(0x29) },
  1871. { USB_DEVICE_WACOM(0x2A) },
  1872. { USB_DEVICE_WACOM(0x3F) },
  1873. { USB_DEVICE_WACOM(0xC5) },
  1874. { USB_DEVICE_WACOM(0xC6) },
  1875. { USB_DEVICE_WACOM(0xC7) },
  1876. /*
  1877. * DTU-2231 has two interfaces on the same configuration,
  1878. * only one is used.
  1879. */
  1880. { USB_DEVICE_DETAILED(0xCE, USB_CLASS_HID,
  1881. USB_INTERFACE_SUBCLASS_BOOT,
  1882. USB_INTERFACE_PROTOCOL_MOUSE) },
  1883. { USB_DEVICE_WACOM(0x84) },
  1884. { USB_DEVICE_WACOM(0xD0) },
  1885. { USB_DEVICE_WACOM(0xD1) },
  1886. { USB_DEVICE_WACOM(0xD2) },
  1887. { USB_DEVICE_WACOM(0xD3) },
  1888. { USB_DEVICE_WACOM(0xD4) },
  1889. { USB_DEVICE_WACOM(0xD5) },
  1890. { USB_DEVICE_WACOM(0xD6) },
  1891. { USB_DEVICE_WACOM(0xD7) },
  1892. { USB_DEVICE_WACOM(0xD8) },
  1893. { USB_DEVICE_WACOM(0xDA) },
  1894. { USB_DEVICE_WACOM(0xDB) },
  1895. { USB_DEVICE_WACOM(0xDD) },
  1896. { USB_DEVICE_WACOM(0xDE) },
  1897. { USB_DEVICE_WACOM(0xDF) },
  1898. { USB_DEVICE_WACOM(0xF0) },
  1899. { USB_DEVICE_WACOM(0xCC) },
  1900. { USB_DEVICE_WACOM(0x90) },
  1901. { USB_DEVICE_WACOM(0x93) },
  1902. { USB_DEVICE_WACOM(0x97) },
  1903. { USB_DEVICE_WACOM(0x9A) },
  1904. { USB_DEVICE_WACOM(0x9F) },
  1905. { USB_DEVICE_WACOM(0xE2) },
  1906. { USB_DEVICE_WACOM(0xE3) },
  1907. { USB_DEVICE_WACOM(0xE5) },
  1908. { USB_DEVICE_WACOM(0xE6) },
  1909. { USB_DEVICE_WACOM(0xEC) },
  1910. { USB_DEVICE_WACOM(0xED) },
  1911. { USB_DEVICE_WACOM(0xEF) },
  1912. { USB_DEVICE_WACOM(0x100) },
  1913. { USB_DEVICE_WACOM(0x101) },
  1914. { USB_DEVICE_WACOM(0x4001) },
  1915. { USB_DEVICE_WACOM(0x47) },
  1916. { USB_DEVICE_WACOM(0xF4) },
  1917. { USB_DEVICE_WACOM(0xF8) },
  1918. { USB_DEVICE_WACOM(0xF6) },
  1919. { USB_DEVICE_WACOM(0xFA) },
  1920. { USB_DEVICE_LENOVO(0x6004) },
  1921. { }
  1922. };
  1923. MODULE_DEVICE_TABLE(usb, wacom_ids);