wacom_wac.c 74 KB

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