wacom_wac.c 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641
  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. /* resolution for penabled devices */
  17. #define WACOM_PL_RES 20
  18. #define WACOM_PENPRTN_RES 40
  19. #define WACOM_VOLITO_RES 50
  20. #define WACOM_GRAPHIRE_RES 80
  21. #define WACOM_INTUOS_RES 100
  22. #define WACOM_INTUOS3_RES 200
  23. /* Newer Cintiq and DTU have an offset between tablet and screen areas */
  24. #define WACOM_DTU_OFFSET 200
  25. #define WACOM_CINTIQ_OFFSET 400
  26. /*
  27. * Scale factor relating reported contact size to logical contact area.
  28. * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
  29. */
  30. #define WACOM_CONTACT_AREA_SCALE 2607
  31. /*
  32. * Percent of battery capacity for Graphire.
  33. * 8th value means AC online and show 100% capacity.
  34. */
  35. static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
  36. /*
  37. * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
  38. */
  39. static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
  40. static void wacom_notify_battery(struct wacom_wac *wacom_wac,
  41. int bat_capacity, bool bat_charging, bool bat_connected,
  42. bool ps_connected)
  43. {
  44. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  45. bool changed = wacom_wac->battery_capacity != bat_capacity ||
  46. wacom_wac->bat_charging != bat_charging ||
  47. wacom_wac->bat_connected != bat_connected ||
  48. wacom_wac->ps_connected != ps_connected;
  49. if (changed) {
  50. wacom_wac->battery_capacity = bat_capacity;
  51. wacom_wac->bat_charging = bat_charging;
  52. wacom_wac->bat_connected = bat_connected;
  53. wacom_wac->ps_connected = ps_connected;
  54. if (wacom->battery)
  55. power_supply_changed(wacom->battery);
  56. }
  57. }
  58. static int wacom_penpartner_irq(struct wacom_wac *wacom)
  59. {
  60. unsigned char *data = wacom->data;
  61. struct input_dev *input = wacom->pen_input;
  62. switch (data[0]) {
  63. case 1:
  64. if (data[5] & 0x80) {
  65. wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  66. wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
  67. input_report_key(input, wacom->tool[0], 1);
  68. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  69. input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
  70. input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
  71. input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
  72. input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
  73. input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
  74. } else {
  75. input_report_key(input, wacom->tool[0], 0);
  76. input_report_abs(input, ABS_MISC, 0); /* report tool id */
  77. input_report_abs(input, ABS_PRESSURE, -1);
  78. input_report_key(input, BTN_TOUCH, 0);
  79. }
  80. break;
  81. case 2:
  82. input_report_key(input, BTN_TOOL_PEN, 1);
  83. input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
  84. input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
  85. input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
  86. input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
  87. input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
  88. input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
  89. break;
  90. default:
  91. dev_dbg(input->dev.parent,
  92. "%s: received unknown report #%d\n", __func__, data[0]);
  93. return 0;
  94. }
  95. return 1;
  96. }
  97. static int wacom_pl_irq(struct wacom_wac *wacom)
  98. {
  99. struct wacom_features *features = &wacom->features;
  100. unsigned char *data = wacom->data;
  101. struct input_dev *input = wacom->pen_input;
  102. int prox, pressure;
  103. if (data[0] != WACOM_REPORT_PENABLED) {
  104. dev_dbg(input->dev.parent,
  105. "%s: received unknown report #%d\n", __func__, data[0]);
  106. return 0;
  107. }
  108. prox = data[1] & 0x40;
  109. if (!wacom->id[0]) {
  110. if ((data[0] & 0x10) || (data[4] & 0x20)) {
  111. wacom->tool[0] = BTN_TOOL_RUBBER;
  112. wacom->id[0] = ERASER_DEVICE_ID;
  113. }
  114. else {
  115. wacom->tool[0] = BTN_TOOL_PEN;
  116. wacom->id[0] = STYLUS_DEVICE_ID;
  117. }
  118. }
  119. /* If the eraser is in prox, STYLUS2 is always set. If we
  120. * mis-detected the type and notice that STYLUS2 isn't set
  121. * then force the eraser out of prox and let the pen in.
  122. */
  123. if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
  124. input_report_key(input, BTN_TOOL_RUBBER, 0);
  125. input_report_abs(input, ABS_MISC, 0);
  126. input_sync(input);
  127. wacom->tool[0] = BTN_TOOL_PEN;
  128. wacom->id[0] = STYLUS_DEVICE_ID;
  129. }
  130. if (prox) {
  131. pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
  132. if (features->pressure_max > 255)
  133. pressure = (pressure << 1) | ((data[4] >> 6) & 1);
  134. pressure += (features->pressure_max + 1) / 2;
  135. input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
  136. input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
  137. input_report_abs(input, ABS_PRESSURE, pressure);
  138. input_report_key(input, BTN_TOUCH, data[4] & 0x08);
  139. input_report_key(input, BTN_STYLUS, data[4] & 0x10);
  140. /* Only allow the stylus2 button to be reported for the pen tool. */
  141. input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
  142. }
  143. if (!prox)
  144. wacom->id[0] = 0;
  145. input_report_key(input, wacom->tool[0], prox);
  146. input_report_abs(input, ABS_MISC, wacom->id[0]);
  147. return 1;
  148. }
  149. static int wacom_ptu_irq(struct wacom_wac *wacom)
  150. {
  151. unsigned char *data = wacom->data;
  152. struct input_dev *input = wacom->pen_input;
  153. if (data[0] != WACOM_REPORT_PENABLED) {
  154. dev_dbg(input->dev.parent,
  155. "%s: received unknown report #%d\n", __func__, data[0]);
  156. return 0;
  157. }
  158. if (data[1] & 0x04) {
  159. input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
  160. input_report_key(input, BTN_TOUCH, data[1] & 0x08);
  161. wacom->id[0] = ERASER_DEVICE_ID;
  162. } else {
  163. input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
  164. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  165. wacom->id[0] = STYLUS_DEVICE_ID;
  166. }
  167. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  168. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  169. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  170. input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
  171. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  172. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  173. return 1;
  174. }
  175. static int wacom_dtu_irq(struct wacom_wac *wacom)
  176. {
  177. unsigned char *data = wacom->data;
  178. struct input_dev *input = wacom->pen_input;
  179. int prox = data[1] & 0x20;
  180. dev_dbg(input->dev.parent,
  181. "%s: received report #%d", __func__, data[0]);
  182. if (prox) {
  183. /* Going into proximity select tool */
  184. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  185. if (wacom->tool[0] == BTN_TOOL_PEN)
  186. wacom->id[0] = STYLUS_DEVICE_ID;
  187. else
  188. wacom->id[0] = ERASER_DEVICE_ID;
  189. }
  190. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  191. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  192. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  193. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  194. input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
  195. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  196. if (!prox) /* out-prox */
  197. wacom->id[0] = 0;
  198. input_report_key(input, wacom->tool[0], prox);
  199. input_report_abs(input, ABS_MISC, wacom->id[0]);
  200. return 1;
  201. }
  202. static int wacom_dtus_irq(struct wacom_wac *wacom)
  203. {
  204. char *data = wacom->data;
  205. struct input_dev *input = wacom->pen_input;
  206. unsigned short prox, pressure = 0;
  207. if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
  208. dev_dbg(input->dev.parent,
  209. "%s: received unknown report #%d", __func__, data[0]);
  210. return 0;
  211. } else if (data[0] == WACOM_REPORT_DTUSPAD) {
  212. input = wacom->pad_input;
  213. input_report_key(input, BTN_0, (data[1] & 0x01));
  214. input_report_key(input, BTN_1, (data[1] & 0x02));
  215. input_report_key(input, BTN_2, (data[1] & 0x04));
  216. input_report_key(input, BTN_3, (data[1] & 0x08));
  217. input_report_abs(input, ABS_MISC,
  218. data[1] & 0x0f ? PAD_DEVICE_ID : 0);
  219. return 1;
  220. } else {
  221. prox = data[1] & 0x80;
  222. if (prox) {
  223. switch ((data[1] >> 3) & 3) {
  224. case 1: /* Rubber */
  225. wacom->tool[0] = BTN_TOOL_RUBBER;
  226. wacom->id[0] = ERASER_DEVICE_ID;
  227. break;
  228. case 2: /* Pen */
  229. wacom->tool[0] = BTN_TOOL_PEN;
  230. wacom->id[0] = STYLUS_DEVICE_ID;
  231. break;
  232. }
  233. }
  234. input_report_key(input, BTN_STYLUS, data[1] & 0x20);
  235. input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
  236. input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
  237. input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
  238. pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
  239. input_report_abs(input, ABS_PRESSURE, pressure);
  240. input_report_key(input, BTN_TOUCH, pressure > 10);
  241. if (!prox) /* out-prox */
  242. wacom->id[0] = 0;
  243. input_report_key(input, wacom->tool[0], prox);
  244. input_report_abs(input, ABS_MISC, wacom->id[0]);
  245. return 1;
  246. }
  247. }
  248. static int wacom_graphire_irq(struct wacom_wac *wacom)
  249. {
  250. struct wacom_features *features = &wacom->features;
  251. unsigned char *data = wacom->data;
  252. struct input_dev *input = wacom->pen_input;
  253. struct input_dev *pad_input = wacom->pad_input;
  254. int battery_capacity, ps_connected;
  255. int prox;
  256. int rw = 0;
  257. int retval = 0;
  258. if (features->type == GRAPHIRE_BT) {
  259. if (data[0] != WACOM_REPORT_PENABLED_BT) {
  260. dev_dbg(input->dev.parent,
  261. "%s: received unknown report #%d\n", __func__,
  262. data[0]);
  263. goto exit;
  264. }
  265. } else if (data[0] != WACOM_REPORT_PENABLED) {
  266. dev_dbg(input->dev.parent,
  267. "%s: received unknown report #%d\n", __func__, data[0]);
  268. goto exit;
  269. }
  270. prox = data[1] & 0x80;
  271. if (prox || wacom->id[0]) {
  272. if (prox) {
  273. switch ((data[1] >> 5) & 3) {
  274. case 0: /* Pen */
  275. wacom->tool[0] = BTN_TOOL_PEN;
  276. wacom->id[0] = STYLUS_DEVICE_ID;
  277. break;
  278. case 1: /* Rubber */
  279. wacom->tool[0] = BTN_TOOL_RUBBER;
  280. wacom->id[0] = ERASER_DEVICE_ID;
  281. break;
  282. case 2: /* Mouse with wheel */
  283. input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
  284. /* fall through */
  285. case 3: /* Mouse without wheel */
  286. wacom->tool[0] = BTN_TOOL_MOUSE;
  287. wacom->id[0] = CURSOR_DEVICE_ID;
  288. break;
  289. }
  290. }
  291. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  292. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  293. if (wacom->tool[0] != BTN_TOOL_MOUSE) {
  294. if (features->type == GRAPHIRE_BT)
  295. input_report_abs(input, ABS_PRESSURE, data[6] |
  296. (((__u16) (data[1] & 0x08)) << 5));
  297. else
  298. input_report_abs(input, ABS_PRESSURE, data[6] |
  299. ((data[7] & 0x03) << 8));
  300. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  301. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  302. input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
  303. } else {
  304. input_report_key(input, BTN_LEFT, data[1] & 0x01);
  305. input_report_key(input, BTN_RIGHT, data[1] & 0x02);
  306. if (features->type == WACOM_G4 ||
  307. features->type == WACOM_MO) {
  308. input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
  309. rw = (data[7] & 0x04) - (data[7] & 0x03);
  310. } else if (features->type == GRAPHIRE_BT) {
  311. /* Compute distance between mouse and tablet */
  312. rw = 44 - (data[6] >> 2);
  313. rw = clamp_val(rw, 0, 31);
  314. input_report_abs(input, ABS_DISTANCE, rw);
  315. if (((data[1] >> 5) & 3) == 2) {
  316. /* Mouse with wheel */
  317. input_report_key(input, BTN_MIDDLE,
  318. data[1] & 0x04);
  319. rw = (data[6] & 0x01) ? -1 :
  320. (data[6] & 0x02) ? 1 : 0;
  321. } else {
  322. rw = 0;
  323. }
  324. } else {
  325. input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
  326. rw = -(signed char)data[6];
  327. }
  328. input_report_rel(input, REL_WHEEL, rw);
  329. }
  330. if (!prox)
  331. wacom->id[0] = 0;
  332. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  333. input_report_key(input, wacom->tool[0], prox);
  334. input_sync(input); /* sync last event */
  335. }
  336. /* send pad data */
  337. switch (features->type) {
  338. case WACOM_G4:
  339. prox = data[7] & 0xf8;
  340. if (prox || wacom->id[1]) {
  341. wacom->id[1] = PAD_DEVICE_ID;
  342. input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
  343. input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
  344. rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
  345. input_report_rel(pad_input, REL_WHEEL, rw);
  346. if (!prox)
  347. wacom->id[1] = 0;
  348. input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
  349. retval = 1;
  350. }
  351. break;
  352. case WACOM_MO:
  353. prox = (data[7] & 0xf8) || data[8];
  354. if (prox || wacom->id[1]) {
  355. wacom->id[1] = PAD_DEVICE_ID;
  356. input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
  357. input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
  358. input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
  359. input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
  360. input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
  361. if (!prox)
  362. wacom->id[1] = 0;
  363. input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
  364. retval = 1;
  365. }
  366. break;
  367. case GRAPHIRE_BT:
  368. prox = data[7] & 0x03;
  369. if (prox || wacom->id[1]) {
  370. wacom->id[1] = PAD_DEVICE_ID;
  371. input_report_key(pad_input, BTN_0, (data[7] & 0x02));
  372. input_report_key(pad_input, BTN_1, (data[7] & 0x01));
  373. if (!prox)
  374. wacom->id[1] = 0;
  375. input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
  376. retval = 1;
  377. }
  378. break;
  379. }
  380. /* Store current battery capacity and power supply state */
  381. if (features->type == GRAPHIRE_BT) {
  382. rw = (data[7] >> 2 & 0x07);
  383. battery_capacity = batcap_gr[rw];
  384. ps_connected = rw == 7;
  385. wacom_notify_battery(wacom, battery_capacity, ps_connected,
  386. 1, ps_connected);
  387. }
  388. exit:
  389. return retval;
  390. }
  391. static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
  392. {
  393. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  394. struct hid_report *r;
  395. struct hid_report_enum *re;
  396. re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
  397. r = re->report_id_hash[WACOM_REPORT_INTUOSREAD];
  398. if (r) {
  399. hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
  400. }
  401. }
  402. static int wacom_intuos_inout(struct wacom_wac *wacom)
  403. {
  404. struct wacom_features *features = &wacom->features;
  405. unsigned char *data = wacom->data;
  406. struct input_dev *input = wacom->pen_input;
  407. int idx = 0;
  408. /* tool number */
  409. if (features->type == INTUOS)
  410. idx = data[1] & 0x01;
  411. /* Enter report */
  412. if ((data[1] & 0xfc) == 0xc0) {
  413. /* serial number of the tool */
  414. wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
  415. (data[4] << 20) + (data[5] << 12) +
  416. (data[6] << 4) + (data[7] >> 4);
  417. wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
  418. ((data[7] & 0x0f) << 20) | ((data[8] & 0xf0) << 12);
  419. switch (wacom->id[idx]) {
  420. case 0x812: /* Inking pen */
  421. case 0x801: /* Intuos3 Inking pen */
  422. case 0x120802: /* Intuos4/5 Inking Pen */
  423. case 0x012:
  424. wacom->tool[idx] = BTN_TOOL_PENCIL;
  425. break;
  426. case 0x822: /* Pen */
  427. case 0x842:
  428. case 0x852:
  429. case 0x823: /* Intuos3 Grip Pen */
  430. case 0x813: /* Intuos3 Classic Pen */
  431. case 0x885: /* Intuos3 Marker Pen */
  432. case 0x802: /* Intuos4/5 13HD/24HD General Pen */
  433. case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
  434. case 0x022:
  435. case 0x100804: /* Intuos4/5 13HD/24HD Art Pen */
  436. case 0x140802: /* Intuos4/5 13HD/24HD Classic Pen */
  437. case 0x160802: /* Cintiq 13HD Pro Pen */
  438. case 0x180802: /* DTH2242 Pen */
  439. case 0x100802: /* Intuos4/5 13HD/24HD General Pen */
  440. wacom->tool[idx] = BTN_TOOL_PEN;
  441. break;
  442. case 0x832: /* Stroke pen */
  443. case 0x032:
  444. wacom->tool[idx] = BTN_TOOL_BRUSH;
  445. break;
  446. case 0x007: /* Mouse 4D and 2D */
  447. case 0x09c:
  448. case 0x094:
  449. case 0x017: /* Intuos3 2D Mouse */
  450. case 0x806: /* Intuos4 Mouse */
  451. wacom->tool[idx] = BTN_TOOL_MOUSE;
  452. break;
  453. case 0x096: /* Lens cursor */
  454. case 0x097: /* Intuos3 Lens cursor */
  455. case 0x006: /* Intuos4 Lens cursor */
  456. wacom->tool[idx] = BTN_TOOL_LENS;
  457. break;
  458. case 0x82a: /* Eraser */
  459. case 0x85a:
  460. case 0x91a:
  461. case 0xd1a:
  462. case 0x0fa:
  463. case 0x82b: /* Intuos3 Grip Pen Eraser */
  464. case 0x81b: /* Intuos3 Classic Pen Eraser */
  465. case 0x91b: /* Intuos3 Airbrush Eraser */
  466. case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
  467. case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
  468. case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
  469. case 0x14080a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
  470. case 0x10090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
  471. case 0x10080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
  472. case 0x16080a: /* Cintiq 13HD Pro Pen Eraser */
  473. case 0x18080a: /* DTH2242 Eraser */
  474. case 0x10080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
  475. wacom->tool[idx] = BTN_TOOL_RUBBER;
  476. break;
  477. case 0xd12:
  478. case 0x912:
  479. case 0x112:
  480. case 0x913: /* Intuos3 Airbrush */
  481. case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
  482. case 0x100902: /* Intuos4/5 13HD/24HD Airbrush */
  483. wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
  484. break;
  485. default: /* Unknown tool */
  486. wacom->tool[idx] = BTN_TOOL_PEN;
  487. break;
  488. }
  489. return 1;
  490. }
  491. /*
  492. * don't report events for invalid data
  493. */
  494. /* older I4 styli don't work with new Cintiqs */
  495. if ((!((wacom->id[idx] >> 20) & 0x01) &&
  496. (features->type == WACOM_21UX2)) ||
  497. /* Only large Intuos support Lense Cursor */
  498. (wacom->tool[idx] == BTN_TOOL_LENS &&
  499. (features->type == INTUOS3 ||
  500. features->type == INTUOS3S ||
  501. features->type == INTUOS4 ||
  502. features->type == INTUOS4S ||
  503. features->type == INTUOS5 ||
  504. features->type == INTUOS5S ||
  505. features->type == INTUOSPM ||
  506. features->type == INTUOSPS)) ||
  507. /* Cintiq doesn't send data when RDY bit isn't set */
  508. (features->type == CINTIQ && !(data[1] & 0x40)))
  509. return 1;
  510. wacom->shared->stylus_in_proximity = true;
  511. if (wacom->shared->touch_down)
  512. return 1;
  513. /* in Range while exiting */
  514. if (((data[1] & 0xfe) == 0x20) && wacom->reporting_data) {
  515. input_report_key(input, BTN_TOUCH, 0);
  516. input_report_abs(input, ABS_PRESSURE, 0);
  517. input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
  518. return 2;
  519. }
  520. /* Exit report */
  521. if ((data[1] & 0xfe) == 0x80) {
  522. wacom->shared->stylus_in_proximity = false;
  523. wacom->reporting_data = false;
  524. /* don't report exit if we don't know the ID */
  525. if (!wacom->id[idx])
  526. return 1;
  527. /*
  528. * Reset all states otherwise we lose the initial states
  529. * when in-prox next time
  530. */
  531. input_report_abs(input, ABS_X, 0);
  532. input_report_abs(input, ABS_Y, 0);
  533. input_report_abs(input, ABS_DISTANCE, 0);
  534. input_report_abs(input, ABS_TILT_X, 0);
  535. input_report_abs(input, ABS_TILT_Y, 0);
  536. if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
  537. input_report_key(input, BTN_LEFT, 0);
  538. input_report_key(input, BTN_MIDDLE, 0);
  539. input_report_key(input, BTN_RIGHT, 0);
  540. input_report_key(input, BTN_SIDE, 0);
  541. input_report_key(input, BTN_EXTRA, 0);
  542. input_report_abs(input, ABS_THROTTLE, 0);
  543. input_report_abs(input, ABS_RZ, 0);
  544. } else {
  545. input_report_abs(input, ABS_PRESSURE, 0);
  546. input_report_key(input, BTN_STYLUS, 0);
  547. input_report_key(input, BTN_STYLUS2, 0);
  548. input_report_key(input, BTN_TOUCH, 0);
  549. input_report_abs(input, ABS_WHEEL, 0);
  550. if (features->type >= INTUOS3S)
  551. input_report_abs(input, ABS_Z, 0);
  552. }
  553. input_report_key(input, wacom->tool[idx], 0);
  554. input_report_abs(input, ABS_MISC, 0); /* reset tool id */
  555. input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  556. wacom->id[idx] = 0;
  557. return 2;
  558. }
  559. /* don't report other events if we don't know the ID */
  560. if (!wacom->id[idx]) {
  561. /* but reschedule a read of the current tool */
  562. wacom_intuos_schedule_prox_event(wacom);
  563. return 1;
  564. }
  565. return 0;
  566. }
  567. static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
  568. {
  569. unsigned char *data = wacom_wac->data;
  570. struct input_dev *input = wacom_wac->pad_input;
  571. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  572. struct wacom_features *features = &wacom_wac->features;
  573. int bat_charging, bat_percent, touch_ring_mode;
  574. __u32 serial;
  575. int i;
  576. if (data[0] != WACOM_REPORT_REMOTE) {
  577. dev_dbg(input->dev.parent,
  578. "%s: received unknown report #%d", __func__, data[0]);
  579. return 0;
  580. }
  581. serial = data[3] + (data[4] << 8) + (data[5] << 16);
  582. wacom_wac->id[0] = PAD_DEVICE_ID;
  583. input_report_key(input, BTN_0, (data[9] & 0x01));
  584. input_report_key(input, BTN_1, (data[9] & 0x02));
  585. input_report_key(input, BTN_2, (data[9] & 0x04));
  586. input_report_key(input, BTN_3, (data[9] & 0x08));
  587. input_report_key(input, BTN_4, (data[9] & 0x10));
  588. input_report_key(input, BTN_5, (data[9] & 0x20));
  589. input_report_key(input, BTN_6, (data[9] & 0x40));
  590. input_report_key(input, BTN_7, (data[9] & 0x80));
  591. input_report_key(input, BTN_8, (data[10] & 0x01));
  592. input_report_key(input, BTN_9, (data[10] & 0x02));
  593. input_report_key(input, BTN_A, (data[10] & 0x04));
  594. input_report_key(input, BTN_B, (data[10] & 0x08));
  595. input_report_key(input, BTN_C, (data[10] & 0x10));
  596. input_report_key(input, BTN_X, (data[10] & 0x20));
  597. input_report_key(input, BTN_Y, (data[10] & 0x40));
  598. input_report_key(input, BTN_Z, (data[10] & 0x80));
  599. input_report_key(input, BTN_BASE, (data[11] & 0x01));
  600. input_report_key(input, BTN_BASE2, (data[11] & 0x02));
  601. if (data[12] & 0x80)
  602. input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f));
  603. else
  604. input_report_abs(input, ABS_WHEEL, 0);
  605. bat_percent = data[7] & 0x7f;
  606. bat_charging = !!(data[7] & 0x80);
  607. if (data[9] | data[10] | (data[11] & 0x03) | data[12])
  608. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  609. else
  610. input_report_abs(input, ABS_MISC, 0);
  611. input_event(input, EV_MSC, MSC_SERIAL, serial);
  612. /*Which mode select (LED light) is currently on?*/
  613. touch_ring_mode = (data[11] & 0xC0) >> 6;
  614. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  615. if (wacom_wac->serial[i] == serial)
  616. wacom->led.select[i] = touch_ring_mode;
  617. }
  618. if (!wacom->battery &&
  619. !(features->quirks & WACOM_QUIRK_BATTERY)) {
  620. features->quirks |= WACOM_QUIRK_BATTERY;
  621. INIT_WORK(&wacom->work, wacom_battery_work);
  622. wacom_schedule_work(wacom_wac);
  623. }
  624. wacom_notify_battery(wacom_wac, bat_percent, bat_charging, 1,
  625. bat_charging);
  626. return 1;
  627. }
  628. static int wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
  629. {
  630. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  631. unsigned char *data = wacom_wac->data;
  632. int i;
  633. if (data[0] != WACOM_REPORT_DEVICE_LIST)
  634. return 0;
  635. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  636. int j = i * 6;
  637. int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
  638. bool connected = data[j+2];
  639. if (connected) {
  640. int k;
  641. if (wacom_wac->serial[i] == serial)
  642. continue;
  643. if (wacom_wac->serial[i]) {
  644. wacom_remote_destroy_attr_group(wacom,
  645. wacom_wac->serial[i]);
  646. }
  647. /* A remote can pair more than once with an EKR,
  648. * check to make sure this serial isn't already paired.
  649. */
  650. for (k = 0; k < WACOM_MAX_REMOTES; k++) {
  651. if (wacom_wac->serial[k] == serial)
  652. break;
  653. }
  654. if (k < WACOM_MAX_REMOTES) {
  655. wacom_wac->serial[i] = serial;
  656. continue;
  657. }
  658. wacom_remote_create_attr_group(wacom, serial, i);
  659. } else if (wacom_wac->serial[i]) {
  660. wacom_remote_destroy_attr_group(wacom,
  661. wacom_wac->serial[i]);
  662. }
  663. }
  664. return 0;
  665. }
  666. static void wacom_intuos_general(struct wacom_wac *wacom)
  667. {
  668. struct wacom_features *features = &wacom->features;
  669. unsigned char *data = wacom->data;
  670. struct input_dev *input = wacom->pen_input;
  671. unsigned int t;
  672. /* general pen packet */
  673. if ((data[1] & 0xb8) == 0xa0) {
  674. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  675. if (features->pressure_max == 2047) {
  676. t = (t << 1) | (data[1] & 1);
  677. }
  678. input_report_abs(input, ABS_PRESSURE, t);
  679. if (features->type != INTUOSHT2) {
  680. input_report_abs(input, ABS_TILT_X,
  681. (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
  682. input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
  683. }
  684. input_report_key(input, BTN_STYLUS, data[1] & 2);
  685. input_report_key(input, BTN_STYLUS2, data[1] & 4);
  686. input_report_key(input, BTN_TOUCH, t > 10);
  687. }
  688. /* airbrush second packet */
  689. if ((data[1] & 0xbc) == 0xb4) {
  690. input_report_abs(input, ABS_WHEEL,
  691. (data[6] << 2) | ((data[7] >> 6) & 3));
  692. input_report_abs(input, ABS_TILT_X,
  693. (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
  694. input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
  695. }
  696. }
  697. static int wacom_intuos_irq(struct wacom_wac *wacom)
  698. {
  699. struct wacom_features *features = &wacom->features;
  700. unsigned char *data = wacom->data;
  701. struct input_dev *input = wacom->pen_input;
  702. unsigned int t;
  703. int idx = 0, result;
  704. if (data[0] != WACOM_REPORT_PENABLED &&
  705. data[0] != WACOM_REPORT_INTUOSREAD &&
  706. data[0] != WACOM_REPORT_INTUOSWRITE &&
  707. data[0] != WACOM_REPORT_INTUOSPAD &&
  708. data[0] != WACOM_REPORT_INTUOS_PEN &&
  709. data[0] != WACOM_REPORT_CINTIQ &&
  710. data[0] != WACOM_REPORT_CINTIQPAD &&
  711. data[0] != WACOM_REPORT_INTUOS5PAD) {
  712. dev_dbg(input->dev.parent,
  713. "%s: received unknown report #%d\n", __func__, data[0]);
  714. return 0;
  715. }
  716. /* tool number */
  717. if (features->type == INTUOS)
  718. idx = data[1] & 0x01;
  719. /* pad packets. Works as a second tool and is always in prox */
  720. if (data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
  721. data[0] == WACOM_REPORT_CINTIQPAD) {
  722. input = wacom->pad_input;
  723. if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
  724. input_report_key(input, BTN_0, (data[2] & 0x01));
  725. input_report_key(input, BTN_1, (data[3] & 0x01));
  726. input_report_key(input, BTN_2, (data[3] & 0x02));
  727. input_report_key(input, BTN_3, (data[3] & 0x04));
  728. input_report_key(input, BTN_4, (data[3] & 0x08));
  729. input_report_key(input, BTN_5, (data[3] & 0x10));
  730. input_report_key(input, BTN_6, (data[3] & 0x20));
  731. if (data[1] & 0x80) {
  732. input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
  733. } else {
  734. /* Out of proximity, clear wheel value. */
  735. input_report_abs(input, ABS_WHEEL, 0);
  736. }
  737. if (features->type != INTUOS4S) {
  738. input_report_key(input, BTN_7, (data[3] & 0x40));
  739. input_report_key(input, BTN_8, (data[3] & 0x80));
  740. }
  741. if (data[1] | (data[2] & 0x01) | data[3]) {
  742. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  743. } else {
  744. input_report_abs(input, ABS_MISC, 0);
  745. }
  746. } else if (features->type == DTK) {
  747. input_report_key(input, BTN_0, (data[6] & 0x01));
  748. input_report_key(input, BTN_1, (data[6] & 0x02));
  749. input_report_key(input, BTN_2, (data[6] & 0x04));
  750. input_report_key(input, BTN_3, (data[6] & 0x08));
  751. input_report_key(input, BTN_4, (data[6] & 0x10));
  752. input_report_key(input, BTN_5, (data[6] & 0x20));
  753. if (data[6] & 0x3f) {
  754. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  755. } else {
  756. input_report_abs(input, ABS_MISC, 0);
  757. }
  758. } else if (features->type == WACOM_13HD) {
  759. input_report_key(input, BTN_0, (data[3] & 0x01));
  760. input_report_key(input, BTN_1, (data[4] & 0x01));
  761. input_report_key(input, BTN_2, (data[4] & 0x02));
  762. input_report_key(input, BTN_3, (data[4] & 0x04));
  763. input_report_key(input, BTN_4, (data[4] & 0x08));
  764. input_report_key(input, BTN_5, (data[4] & 0x10));
  765. input_report_key(input, BTN_6, (data[4] & 0x20));
  766. input_report_key(input, BTN_7, (data[4] & 0x40));
  767. input_report_key(input, BTN_8, (data[4] & 0x80));
  768. if ((data[3] & 0x01) | data[4]) {
  769. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  770. } else {
  771. input_report_abs(input, ABS_MISC, 0);
  772. }
  773. } else if (features->type == WACOM_24HD) {
  774. input_report_key(input, BTN_0, (data[6] & 0x01));
  775. input_report_key(input, BTN_1, (data[6] & 0x02));
  776. input_report_key(input, BTN_2, (data[6] & 0x04));
  777. input_report_key(input, BTN_3, (data[6] & 0x08));
  778. input_report_key(input, BTN_4, (data[6] & 0x10));
  779. input_report_key(input, BTN_5, (data[6] & 0x20));
  780. input_report_key(input, BTN_6, (data[6] & 0x40));
  781. input_report_key(input, BTN_7, (data[6] & 0x80));
  782. input_report_key(input, BTN_8, (data[8] & 0x01));
  783. input_report_key(input, BTN_9, (data[8] & 0x02));
  784. input_report_key(input, BTN_A, (data[8] & 0x04));
  785. input_report_key(input, BTN_B, (data[8] & 0x08));
  786. input_report_key(input, BTN_C, (data[8] & 0x10));
  787. input_report_key(input, BTN_X, (data[8] & 0x20));
  788. input_report_key(input, BTN_Y, (data[8] & 0x40));
  789. input_report_key(input, BTN_Z, (data[8] & 0x80));
  790. /*
  791. * Three "buttons" are available on the 24HD which are
  792. * physically implemented as a touchstrip. Each button
  793. * is approximately 3 bits wide with a 2 bit spacing.
  794. * The raw touchstrip bits are stored at:
  795. * ((data[3] & 0x1f) << 8) | data[4])
  796. */
  797. input_report_key(input, KEY_PROG1, data[4] & 0x07);
  798. input_report_key(input, KEY_PROG2, data[4] & 0xE0);
  799. input_report_key(input, KEY_PROG3, data[3] & 0x1C);
  800. if (data[1] & 0x80) {
  801. input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
  802. } else {
  803. /* Out of proximity, clear wheel value. */
  804. input_report_abs(input, ABS_WHEEL, 0);
  805. }
  806. if (data[2] & 0x80) {
  807. input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
  808. } else {
  809. /* Out of proximity, clear second wheel value. */
  810. input_report_abs(input, ABS_THROTTLE, 0);
  811. }
  812. if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
  813. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  814. } else {
  815. input_report_abs(input, ABS_MISC, 0);
  816. }
  817. } else if (features->type == WACOM_27QHD) {
  818. input_report_key(input, KEY_PROG1, data[2] & 0x01);
  819. input_report_key(input, KEY_PROG2, data[2] & 0x02);
  820. input_report_key(input, KEY_PROG3, data[2] & 0x04);
  821. input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
  822. input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
  823. input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
  824. if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) {
  825. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  826. } else {
  827. input_report_abs(input, ABS_MISC, 0);
  828. }
  829. } else if (features->type == CINTIQ_HYBRID) {
  830. /*
  831. * Do not send hardware buttons under Android. They
  832. * are already sent to the system through GPIO (and
  833. * have different meaning).
  834. */
  835. input_report_key(input, BTN_1, (data[4] & 0x01));
  836. input_report_key(input, BTN_2, (data[4] & 0x02));
  837. input_report_key(input, BTN_3, (data[4] & 0x04));
  838. input_report_key(input, BTN_4, (data[4] & 0x08));
  839. input_report_key(input, BTN_5, (data[4] & 0x10)); /* Right */
  840. input_report_key(input, BTN_6, (data[4] & 0x20)); /* Up */
  841. input_report_key(input, BTN_7, (data[4] & 0x40)); /* Left */
  842. input_report_key(input, BTN_8, (data[4] & 0x80)); /* Down */
  843. input_report_key(input, BTN_0, (data[3] & 0x01)); /* Center */
  844. if (data[4] | (data[3] & 0x01)) {
  845. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  846. } else {
  847. input_report_abs(input, ABS_MISC, 0);
  848. }
  849. } else if (features->type == CINTIQ_COMPANION_2) {
  850. input_report_key(input, BTN_1, (data[1] & 0x02));
  851. input_report_key(input, BTN_2, (data[2] & 0x01));
  852. input_report_key(input, BTN_3, (data[2] & 0x02));
  853. input_report_key(input, BTN_4, (data[2] & 0x04));
  854. input_report_key(input, BTN_5, (data[2] & 0x08));
  855. input_report_key(input, BTN_6, (data[1] & 0x04));
  856. input_report_key(input, BTN_7, (data[2] & 0x10)); /* Right */
  857. input_report_key(input, BTN_8, (data[2] & 0x20)); /* Up */
  858. input_report_key(input, BTN_9, (data[2] & 0x40)); /* Left */
  859. input_report_key(input, BTN_A, (data[2] & 0x80)); /* Down */
  860. input_report_key(input, BTN_0, (data[1] & 0x01)); /* Center */
  861. if (data[2] | (data[1] & 0x07)) {
  862. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  863. } else {
  864. input_report_abs(input, ABS_MISC, 0);
  865. }
  866. } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
  867. int i;
  868. /* Touch ring mode switch has no capacitive sensor */
  869. input_report_key(input, BTN_0, (data[3] & 0x01));
  870. /*
  871. * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
  872. * addition to the mechanical switch. Switch data is
  873. * stored in data[4], capacitive data in data[5].
  874. */
  875. for (i = 0; i < 8; i++)
  876. input_report_key(input, BTN_1 + i, data[4] & (1 << i));
  877. if (data[2] & 0x80) {
  878. input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
  879. } else {
  880. /* Out of proximity, clear wheel value. */
  881. input_report_abs(input, ABS_WHEEL, 0);
  882. }
  883. if (data[2] | (data[3] & 0x01) | data[4] | data[5]) {
  884. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  885. } else {
  886. input_report_abs(input, ABS_MISC, 0);
  887. }
  888. } else {
  889. if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
  890. input_report_key(input, BTN_0, (data[5] & 0x01));
  891. input_report_key(input, BTN_1, (data[6] & 0x01));
  892. input_report_key(input, BTN_2, (data[6] & 0x02));
  893. input_report_key(input, BTN_3, (data[6] & 0x04));
  894. input_report_key(input, BTN_4, (data[6] & 0x08));
  895. input_report_key(input, BTN_5, (data[6] & 0x10));
  896. input_report_key(input, BTN_6, (data[6] & 0x20));
  897. input_report_key(input, BTN_7, (data[6] & 0x40));
  898. input_report_key(input, BTN_8, (data[6] & 0x80));
  899. input_report_key(input, BTN_9, (data[7] & 0x01));
  900. input_report_key(input, BTN_A, (data[8] & 0x01));
  901. input_report_key(input, BTN_B, (data[8] & 0x02));
  902. input_report_key(input, BTN_C, (data[8] & 0x04));
  903. input_report_key(input, BTN_X, (data[8] & 0x08));
  904. input_report_key(input, BTN_Y, (data[8] & 0x10));
  905. input_report_key(input, BTN_Z, (data[8] & 0x20));
  906. input_report_key(input, BTN_BASE, (data[8] & 0x40));
  907. input_report_key(input, BTN_BASE2, (data[8] & 0x80));
  908. if (features->type == WACOM_22HD) {
  909. input_report_key(input, KEY_PROG1, data[9] & 0x01);
  910. input_report_key(input, KEY_PROG2, data[9] & 0x02);
  911. input_report_key(input, KEY_PROG3, data[9] & 0x04);
  912. }
  913. } else {
  914. input_report_key(input, BTN_0, (data[5] & 0x01));
  915. input_report_key(input, BTN_1, (data[5] & 0x02));
  916. input_report_key(input, BTN_2, (data[5] & 0x04));
  917. input_report_key(input, BTN_3, (data[5] & 0x08));
  918. input_report_key(input, BTN_4, (data[6] & 0x01));
  919. input_report_key(input, BTN_5, (data[6] & 0x02));
  920. input_report_key(input, BTN_6, (data[6] & 0x04));
  921. input_report_key(input, BTN_7, (data[6] & 0x08));
  922. input_report_key(input, BTN_8, (data[5] & 0x10));
  923. input_report_key(input, BTN_9, (data[6] & 0x10));
  924. }
  925. input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
  926. input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
  927. if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
  928. data[2] | (data[3] & 0x1f) | data[4] | data[8] |
  929. (data[7] & 0x01)) {
  930. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  931. } else {
  932. input_report_abs(input, ABS_MISC, 0);
  933. }
  934. }
  935. return 1;
  936. }
  937. /* process in/out prox events */
  938. result = wacom_intuos_inout(wacom);
  939. if (result)
  940. return result - 1;
  941. if (features->type >= INTUOS3S) {
  942. input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
  943. input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
  944. input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
  945. } else {
  946. input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
  947. input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
  948. input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
  949. }
  950. /* process general packets */
  951. wacom_intuos_general(wacom);
  952. /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
  953. if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
  954. if (data[1] & 0x02) {
  955. /* Rotation packet */
  956. if (features->type >= INTUOS3S) {
  957. /* I3 marker pen rotation */
  958. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  959. t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
  960. ((t-1) / 2 + 450)) : (450 - t / 2) ;
  961. input_report_abs(input, ABS_Z, t);
  962. } else {
  963. /* 4D mouse rotation packet */
  964. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  965. input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
  966. ((t - 1) / 2) : -t / 2);
  967. }
  968. } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
  969. /* 4D mouse packet */
  970. input_report_key(input, BTN_LEFT, data[8] & 0x01);
  971. input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
  972. input_report_key(input, BTN_RIGHT, data[8] & 0x04);
  973. input_report_key(input, BTN_SIDE, data[8] & 0x20);
  974. input_report_key(input, BTN_EXTRA, data[8] & 0x10);
  975. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  976. input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
  977. } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
  978. /* I4 mouse */
  979. if (features->type >= INTUOS4S && features->type <= INTUOSPL) {
  980. input_report_key(input, BTN_LEFT, data[6] & 0x01);
  981. input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
  982. input_report_key(input, BTN_RIGHT, data[6] & 0x04);
  983. input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
  984. - ((data[7] & 0x40) >> 6));
  985. input_report_key(input, BTN_SIDE, data[6] & 0x08);
  986. input_report_key(input, BTN_EXTRA, data[6] & 0x10);
  987. input_report_abs(input, ABS_TILT_X,
  988. (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
  989. input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
  990. } else {
  991. /* 2D mouse packet */
  992. input_report_key(input, BTN_LEFT, data[8] & 0x04);
  993. input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
  994. input_report_key(input, BTN_RIGHT, data[8] & 0x10);
  995. input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
  996. - ((data[8] & 0x02) >> 1));
  997. /* I3 2D mouse side buttons */
  998. if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
  999. input_report_key(input, BTN_SIDE, data[8] & 0x40);
  1000. input_report_key(input, BTN_EXTRA, data[8] & 0x20);
  1001. }
  1002. }
  1003. } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
  1004. features->type == INTUOS4L || features->type == INTUOS5L ||
  1005. features->type == INTUOSPL) &&
  1006. wacom->tool[idx] == BTN_TOOL_LENS) {
  1007. /* Lens cursor packets */
  1008. input_report_key(input, BTN_LEFT, data[8] & 0x01);
  1009. input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
  1010. input_report_key(input, BTN_RIGHT, data[8] & 0x04);
  1011. input_report_key(input, BTN_SIDE, data[8] & 0x10);
  1012. input_report_key(input, BTN_EXTRA, data[8] & 0x08);
  1013. }
  1014. }
  1015. input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
  1016. input_report_key(input, wacom->tool[idx], 1);
  1017. input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  1018. wacom->reporting_data = true;
  1019. return 1;
  1020. }
  1021. static int int_dist(int x1, int y1, int x2, int y2)
  1022. {
  1023. int x = x2 - x1;
  1024. int y = y2 - y1;
  1025. return int_sqrt(x*x + y*y);
  1026. }
  1027. static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
  1028. unsigned char *data)
  1029. {
  1030. memcpy(wacom->data, data, 10);
  1031. wacom_intuos_irq(wacom);
  1032. input_sync(wacom->pen_input);
  1033. if (wacom->pad_input)
  1034. input_sync(wacom->pad_input);
  1035. }
  1036. static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
  1037. {
  1038. unsigned char data[WACOM_PKGLEN_MAX];
  1039. int i = 1;
  1040. unsigned power_raw, battery_capacity, bat_charging, ps_connected;
  1041. memcpy(data, wacom->data, len);
  1042. switch (data[0]) {
  1043. case 0x04:
  1044. wacom_intuos_bt_process_data(wacom, data + i);
  1045. i += 10;
  1046. /* fall through */
  1047. case 0x03:
  1048. wacom_intuos_bt_process_data(wacom, data + i);
  1049. i += 10;
  1050. wacom_intuos_bt_process_data(wacom, data + i);
  1051. i += 10;
  1052. power_raw = data[i];
  1053. bat_charging = (power_raw & 0x08) ? 1 : 0;
  1054. ps_connected = (power_raw & 0x10) ? 1 : 0;
  1055. battery_capacity = batcap_i4[power_raw & 0x07];
  1056. wacom_notify_battery(wacom, battery_capacity, bat_charging,
  1057. battery_capacity || bat_charging,
  1058. ps_connected);
  1059. break;
  1060. default:
  1061. dev_dbg(wacom->pen_input->dev.parent,
  1062. "Unknown report: %d,%d size:%zu\n",
  1063. data[0], data[1], len);
  1064. return 0;
  1065. }
  1066. return 0;
  1067. }
  1068. static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
  1069. {
  1070. struct input_dev *input = wacom->touch_input;
  1071. unsigned touch_max = wacom->features.touch_max;
  1072. int count = 0;
  1073. int i;
  1074. if (!touch_max)
  1075. return 0;
  1076. if (touch_max == 1)
  1077. return test_bit(BTN_TOUCH, input->key) &&
  1078. !wacom->shared->stylus_in_proximity;
  1079. for (i = 0; i < input->mt->num_slots; i++) {
  1080. struct input_mt_slot *ps = &input->mt->slots[i];
  1081. int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
  1082. if (id >= 0)
  1083. count++;
  1084. }
  1085. return count;
  1086. }
  1087. static int wacom_24hdt_irq(struct wacom_wac *wacom)
  1088. {
  1089. struct input_dev *input = wacom->touch_input;
  1090. unsigned char *data = wacom->data;
  1091. int i;
  1092. int current_num_contacts = data[61];
  1093. int contacts_to_send = 0;
  1094. int num_contacts_left = 4; /* maximum contacts per packet */
  1095. int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
  1096. int y_offset = 2;
  1097. if (wacom->features.type == WACOM_27QHDT) {
  1098. current_num_contacts = data[63];
  1099. num_contacts_left = 10;
  1100. byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
  1101. y_offset = 0;
  1102. }
  1103. /*
  1104. * First packet resets the counter since only the first
  1105. * packet in series will have non-zero current_num_contacts.
  1106. */
  1107. if (current_num_contacts)
  1108. wacom->num_contacts_left = current_num_contacts;
  1109. contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
  1110. for (i = 0; i < contacts_to_send; i++) {
  1111. int offset = (byte_per_packet * i) + 1;
  1112. bool touch = (data[offset] & 0x1) && !wacom->shared->stylus_in_proximity;
  1113. int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
  1114. if (slot < 0)
  1115. continue;
  1116. input_mt_slot(input, slot);
  1117. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1118. if (touch) {
  1119. int t_x = get_unaligned_le16(&data[offset + 2]);
  1120. int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
  1121. input_report_abs(input, ABS_MT_POSITION_X, t_x);
  1122. input_report_abs(input, ABS_MT_POSITION_Y, t_y);
  1123. if (wacom->features.type != WACOM_27QHDT) {
  1124. int c_x = get_unaligned_le16(&data[offset + 4]);
  1125. int c_y = get_unaligned_le16(&data[offset + 8]);
  1126. int w = get_unaligned_le16(&data[offset + 10]);
  1127. int h = get_unaligned_le16(&data[offset + 12]);
  1128. input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
  1129. input_report_abs(input, ABS_MT_WIDTH_MAJOR,
  1130. min(w, h) + int_dist(t_x, t_y, c_x, c_y));
  1131. input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
  1132. input_report_abs(input, ABS_MT_ORIENTATION, w > h);
  1133. }
  1134. }
  1135. }
  1136. input_mt_sync_frame(input);
  1137. wacom->num_contacts_left -= contacts_to_send;
  1138. if (wacom->num_contacts_left <= 0) {
  1139. wacom->num_contacts_left = 0;
  1140. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1141. }
  1142. return 1;
  1143. }
  1144. static int wacom_mt_touch(struct wacom_wac *wacom)
  1145. {
  1146. struct input_dev *input = wacom->touch_input;
  1147. unsigned char *data = wacom->data;
  1148. int i;
  1149. int current_num_contacts = data[2];
  1150. int contacts_to_send = 0;
  1151. int x_offset = 0;
  1152. /* MTTPC does not support Height and Width */
  1153. if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
  1154. x_offset = -4;
  1155. /*
  1156. * First packet resets the counter since only the first
  1157. * packet in series will have non-zero current_num_contacts.
  1158. */
  1159. if (current_num_contacts)
  1160. wacom->num_contacts_left = current_num_contacts;
  1161. /* There are at most 5 contacts per packet */
  1162. contacts_to_send = min(5, wacom->num_contacts_left);
  1163. for (i = 0; i < contacts_to_send; i++) {
  1164. int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
  1165. bool touch = (data[offset] & 0x1) && !wacom->shared->stylus_in_proximity;
  1166. int id = get_unaligned_le16(&data[offset + 1]);
  1167. int slot = input_mt_get_slot_by_key(input, id);
  1168. if (slot < 0)
  1169. continue;
  1170. input_mt_slot(input, slot);
  1171. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1172. if (touch) {
  1173. int x = get_unaligned_le16(&data[offset + x_offset + 7]);
  1174. int y = get_unaligned_le16(&data[offset + x_offset + 9]);
  1175. input_report_abs(input, ABS_MT_POSITION_X, x);
  1176. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1177. }
  1178. }
  1179. input_mt_sync_frame(input);
  1180. wacom->num_contacts_left -= contacts_to_send;
  1181. if (wacom->num_contacts_left <= 0) {
  1182. wacom->num_contacts_left = 0;
  1183. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1184. }
  1185. return 1;
  1186. }
  1187. static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
  1188. {
  1189. struct input_dev *input = wacom->touch_input;
  1190. unsigned char *data = wacom->data;
  1191. int i;
  1192. for (i = 0; i < 2; i++) {
  1193. int p = data[1] & (1 << i);
  1194. bool touch = p && !wacom->shared->stylus_in_proximity;
  1195. input_mt_slot(input, i);
  1196. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1197. if (touch) {
  1198. int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
  1199. int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
  1200. input_report_abs(input, ABS_MT_POSITION_X, x);
  1201. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1202. }
  1203. }
  1204. input_mt_sync_frame(input);
  1205. /* keep touch state for pen event */
  1206. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1207. return 1;
  1208. }
  1209. static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
  1210. {
  1211. unsigned char *data = wacom->data;
  1212. struct input_dev *input = wacom->touch_input;
  1213. bool prox = !wacom->shared->stylus_in_proximity;
  1214. int x = 0, y = 0;
  1215. if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
  1216. return 0;
  1217. if (len == WACOM_PKGLEN_TPC1FG) {
  1218. prox = prox && (data[0] & 0x01);
  1219. x = get_unaligned_le16(&data[1]);
  1220. y = get_unaligned_le16(&data[3]);
  1221. } else if (len == WACOM_PKGLEN_TPC1FG_B) {
  1222. prox = prox && (data[2] & 0x01);
  1223. x = get_unaligned_le16(&data[3]);
  1224. y = get_unaligned_le16(&data[5]);
  1225. } else {
  1226. prox = prox && (data[1] & 0x01);
  1227. x = le16_to_cpup((__le16 *)&data[2]);
  1228. y = le16_to_cpup((__le16 *)&data[4]);
  1229. }
  1230. if (prox) {
  1231. input_report_abs(input, ABS_X, x);
  1232. input_report_abs(input, ABS_Y, y);
  1233. }
  1234. input_report_key(input, BTN_TOUCH, prox);
  1235. /* keep touch state for pen events */
  1236. wacom->shared->touch_down = prox;
  1237. return 1;
  1238. }
  1239. static int wacom_tpc_pen(struct wacom_wac *wacom)
  1240. {
  1241. unsigned char *data = wacom->data;
  1242. struct input_dev *input = wacom->pen_input;
  1243. bool prox = data[1] & 0x20;
  1244. if (!wacom->shared->stylus_in_proximity) /* first in prox */
  1245. /* Going into proximity select tool */
  1246. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  1247. /* keep pen state for touch events */
  1248. wacom->shared->stylus_in_proximity = prox;
  1249. /* send pen events only when touch is up or forced out */
  1250. if (!wacom->shared->touch_down) {
  1251. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  1252. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  1253. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  1254. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  1255. input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
  1256. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  1257. input_report_key(input, wacom->tool[0], prox);
  1258. return 1;
  1259. }
  1260. return 0;
  1261. }
  1262. static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
  1263. {
  1264. unsigned char *data = wacom->data;
  1265. if (wacom->pen_input) {
  1266. dev_dbg(wacom->pen_input->dev.parent,
  1267. "%s: received report #%d\n", __func__, data[0]);
  1268. if (len == WACOM_PKGLEN_PENABLED ||
  1269. data[0] == WACOM_REPORT_PENABLED)
  1270. return wacom_tpc_pen(wacom);
  1271. }
  1272. else if (wacom->touch_input) {
  1273. dev_dbg(wacom->touch_input->dev.parent,
  1274. "%s: received report #%d\n", __func__, data[0]);
  1275. switch (len) {
  1276. case WACOM_PKGLEN_TPC1FG:
  1277. return wacom_tpc_single_touch(wacom, len);
  1278. case WACOM_PKGLEN_TPC2FG:
  1279. return wacom_tpc_mt_touch(wacom);
  1280. default:
  1281. switch (data[0]) {
  1282. case WACOM_REPORT_TPC1FG:
  1283. case WACOM_REPORT_TPCHID:
  1284. case WACOM_REPORT_TPCST:
  1285. case WACOM_REPORT_TPC1FGE:
  1286. return wacom_tpc_single_touch(wacom, len);
  1287. case WACOM_REPORT_TPCMT:
  1288. case WACOM_REPORT_TPCMT2:
  1289. return wacom_mt_touch(wacom);
  1290. }
  1291. }
  1292. }
  1293. return 0;
  1294. }
  1295. static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
  1296. struct hid_field *field, __u8 type, __u16 code, int fuzz)
  1297. {
  1298. int fmin = field->logical_minimum;
  1299. int fmax = field->logical_maximum;
  1300. usage->type = type;
  1301. usage->code = code;
  1302. set_bit(type, input->evbit);
  1303. switch (type) {
  1304. case EV_ABS:
  1305. input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
  1306. input_abs_set_res(input, code,
  1307. hidinput_calc_abs_res(field, code));
  1308. break;
  1309. case EV_KEY:
  1310. input_set_capability(input, EV_KEY, code);
  1311. break;
  1312. case EV_MSC:
  1313. input_set_capability(input, EV_MSC, code);
  1314. break;
  1315. }
  1316. }
  1317. static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
  1318. struct hid_field *field, struct hid_usage *usage)
  1319. {
  1320. struct wacom *wacom = hid_get_drvdata(hdev);
  1321. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1322. struct input_dev *input = wacom_wac->pen_input;
  1323. switch (usage->hid) {
  1324. case HID_GD_X:
  1325. wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
  1326. break;
  1327. case HID_GD_Y:
  1328. wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
  1329. break;
  1330. case HID_DG_TIPPRESSURE:
  1331. wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
  1332. break;
  1333. case HID_DG_INRANGE:
  1334. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
  1335. break;
  1336. case HID_DG_INVERT:
  1337. wacom_map_usage(input, usage, field, EV_KEY,
  1338. BTN_TOOL_RUBBER, 0);
  1339. break;
  1340. case HID_DG_ERASER:
  1341. case HID_DG_TIPSWITCH:
  1342. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
  1343. break;
  1344. case HID_DG_BARRELSWITCH:
  1345. wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
  1346. break;
  1347. case HID_DG_BARRELSWITCH2:
  1348. wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
  1349. break;
  1350. case HID_DG_TOOLSERIALNUMBER:
  1351. wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
  1352. break;
  1353. }
  1354. }
  1355. static int wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
  1356. struct hid_usage *usage, __s32 value)
  1357. {
  1358. struct wacom *wacom = hid_get_drvdata(hdev);
  1359. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1360. struct input_dev *input = wacom_wac->pen_input;
  1361. /* checking which Tool / tip switch to send */
  1362. switch (usage->hid) {
  1363. case HID_DG_INRANGE:
  1364. wacom_wac->hid_data.inrange_state = value;
  1365. return 0;
  1366. case HID_DG_INVERT:
  1367. wacom_wac->hid_data.invert_state = value;
  1368. return 0;
  1369. case HID_DG_ERASER:
  1370. case HID_DG_TIPSWITCH:
  1371. wacom_wac->hid_data.tipswitch |= value;
  1372. return 0;
  1373. }
  1374. /* send pen events only when touch is up or forced out */
  1375. if (!usage->type || wacom_wac->shared->touch_down)
  1376. return 0;
  1377. input_event(input, usage->type, usage->code, value);
  1378. return 0;
  1379. }
  1380. static void wacom_wac_pen_pre_report(struct hid_device *hdev,
  1381. struct hid_report *report)
  1382. {
  1383. return;
  1384. }
  1385. static void wacom_wac_pen_report(struct hid_device *hdev,
  1386. struct hid_report *report)
  1387. {
  1388. struct wacom *wacom = hid_get_drvdata(hdev);
  1389. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1390. struct input_dev *input = wacom_wac->pen_input;
  1391. bool prox = wacom_wac->hid_data.inrange_state;
  1392. if (!wacom_wac->shared->stylus_in_proximity) /* first in prox */
  1393. /* Going into proximity select tool */
  1394. wacom_wac->tool[0] = wacom_wac->hid_data.invert_state ?
  1395. BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  1396. /* keep pen state for touch events */
  1397. wacom_wac->shared->stylus_in_proximity = prox;
  1398. /* send pen events only when touch is up or forced out */
  1399. if (!wacom_wac->shared->touch_down) {
  1400. input_report_key(input, BTN_TOUCH,
  1401. wacom_wac->hid_data.tipswitch);
  1402. input_report_key(input, wacom_wac->tool[0], prox);
  1403. wacom_wac->hid_data.tipswitch = false;
  1404. input_sync(input);
  1405. }
  1406. }
  1407. static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
  1408. struct hid_field *field, struct hid_usage *usage)
  1409. {
  1410. struct wacom *wacom = hid_get_drvdata(hdev);
  1411. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1412. struct wacom_features *features = &wacom_wac->features;
  1413. struct input_dev *input = wacom_wac->touch_input;
  1414. unsigned touch_max = wacom_wac->features.touch_max;
  1415. switch (usage->hid) {
  1416. case HID_GD_X:
  1417. features->last_slot_field = usage->hid;
  1418. if (touch_max == 1)
  1419. wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
  1420. else
  1421. wacom_map_usage(input, usage, field, EV_ABS,
  1422. ABS_MT_POSITION_X, 4);
  1423. break;
  1424. case HID_GD_Y:
  1425. features->last_slot_field = usage->hid;
  1426. if (touch_max == 1)
  1427. wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
  1428. else
  1429. wacom_map_usage(input, usage, field, EV_ABS,
  1430. ABS_MT_POSITION_Y, 4);
  1431. break;
  1432. case HID_DG_WIDTH:
  1433. case HID_DG_HEIGHT:
  1434. features->last_slot_field = usage->hid;
  1435. wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
  1436. wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
  1437. input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  1438. break;
  1439. case HID_DG_CONTACTID:
  1440. features->last_slot_field = usage->hid;
  1441. break;
  1442. case HID_DG_INRANGE:
  1443. features->last_slot_field = usage->hid;
  1444. break;
  1445. case HID_DG_INVERT:
  1446. features->last_slot_field = usage->hid;
  1447. break;
  1448. case HID_DG_TIPSWITCH:
  1449. features->last_slot_field = usage->hid;
  1450. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
  1451. break;
  1452. case HID_DG_CONTACTCOUNT:
  1453. wacom_wac->hid_data.cc_report = field->report->id;
  1454. wacom_wac->hid_data.cc_index = field->index;
  1455. wacom_wac->hid_data.cc_value_index = usage->usage_index;
  1456. break;
  1457. }
  1458. }
  1459. static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
  1460. struct input_dev *input)
  1461. {
  1462. struct hid_data *hid_data = &wacom_wac->hid_data;
  1463. bool mt = wacom_wac->features.touch_max > 1;
  1464. bool prox = hid_data->tipswitch &&
  1465. !wacom_wac->shared->stylus_in_proximity;
  1466. wacom_wac->hid_data.num_received++;
  1467. if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
  1468. return;
  1469. if (mt) {
  1470. int slot;
  1471. slot = input_mt_get_slot_by_key(input, hid_data->id);
  1472. input_mt_slot(input, slot);
  1473. input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
  1474. }
  1475. else {
  1476. input_report_key(input, BTN_TOUCH, prox);
  1477. }
  1478. if (prox) {
  1479. input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
  1480. hid_data->x);
  1481. input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
  1482. hid_data->y);
  1483. if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
  1484. input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
  1485. input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
  1486. if (hid_data->width != hid_data->height)
  1487. input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
  1488. }
  1489. }
  1490. }
  1491. static int wacom_wac_finger_event(struct hid_device *hdev,
  1492. struct hid_field *field, struct hid_usage *usage, __s32 value)
  1493. {
  1494. struct wacom *wacom = hid_get_drvdata(hdev);
  1495. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1496. switch (usage->hid) {
  1497. case HID_GD_X:
  1498. wacom_wac->hid_data.x = value;
  1499. break;
  1500. case HID_GD_Y:
  1501. wacom_wac->hid_data.y = value;
  1502. break;
  1503. case HID_DG_WIDTH:
  1504. wacom_wac->hid_data.width = value;
  1505. break;
  1506. case HID_DG_HEIGHT:
  1507. wacom_wac->hid_data.height = value;
  1508. break;
  1509. case HID_DG_CONTACTID:
  1510. wacom_wac->hid_data.id = value;
  1511. break;
  1512. case HID_DG_TIPSWITCH:
  1513. wacom_wac->hid_data.tipswitch = value;
  1514. break;
  1515. }
  1516. if (usage->usage_index + 1 == field->report_count) {
  1517. if (usage->hid == wacom_wac->features.last_slot_field)
  1518. wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
  1519. }
  1520. return 0;
  1521. }
  1522. static void wacom_wac_finger_pre_report(struct hid_device *hdev,
  1523. struct hid_report *report)
  1524. {
  1525. struct wacom *wacom = hid_get_drvdata(hdev);
  1526. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1527. struct hid_data* hid_data = &wacom_wac->hid_data;
  1528. if (hid_data->cc_report != 0 &&
  1529. hid_data->cc_report != report->id) {
  1530. int i;
  1531. hid_data->cc_report = report->id;
  1532. hid_data->cc_index = -1;
  1533. hid_data->cc_value_index = -1;
  1534. for (i = 0; i < report->maxfield; i++) {
  1535. struct hid_field *field = report->field[i];
  1536. int j;
  1537. for (j = 0; j < field->maxusage; j++) {
  1538. if (field->usage[j].hid == HID_DG_CONTACTCOUNT) {
  1539. hid_data->cc_index = i;
  1540. hid_data->cc_value_index = j;
  1541. /* break */
  1542. i = report->maxfield;
  1543. j = field->maxusage;
  1544. }
  1545. }
  1546. }
  1547. }
  1548. if (hid_data->cc_report != 0 &&
  1549. hid_data->cc_index >= 0) {
  1550. struct hid_field *field = report->field[hid_data->cc_index];
  1551. int value = field->value[hid_data->cc_value_index];
  1552. if (value)
  1553. hid_data->num_expected = value;
  1554. }
  1555. else {
  1556. hid_data->num_expected = wacom_wac->features.touch_max;
  1557. }
  1558. }
  1559. static void wacom_wac_finger_report(struct hid_device *hdev,
  1560. struct hid_report *report)
  1561. {
  1562. struct wacom *wacom = hid_get_drvdata(hdev);
  1563. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1564. struct input_dev *input = wacom_wac->touch_input;
  1565. unsigned touch_max = wacom_wac->features.touch_max;
  1566. /* If more packets of data are expected, give us a chance to
  1567. * process them rather than immediately syncing a partial
  1568. * update.
  1569. */
  1570. if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
  1571. return;
  1572. if (touch_max > 1)
  1573. input_mt_sync_frame(input);
  1574. input_sync(input);
  1575. wacom_wac->hid_data.num_received = 0;
  1576. /* keep touch state for pen event */
  1577. wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
  1578. }
  1579. void wacom_wac_usage_mapping(struct hid_device *hdev,
  1580. struct hid_field *field, struct hid_usage *usage)
  1581. {
  1582. struct wacom *wacom = hid_get_drvdata(hdev);
  1583. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1584. /* currently, only direct devices have proper hid report descriptors */
  1585. __set_bit(INPUT_PROP_DIRECT, wacom_wac->pen_input->propbit);
  1586. __set_bit(INPUT_PROP_DIRECT, wacom_wac->touch_input->propbit);
  1587. if (WACOM_PEN_FIELD(field))
  1588. return wacom_wac_pen_usage_mapping(hdev, field, usage);
  1589. if (WACOM_FINGER_FIELD(field))
  1590. return wacom_wac_finger_usage_mapping(hdev, field, usage);
  1591. }
  1592. int wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
  1593. struct hid_usage *usage, __s32 value)
  1594. {
  1595. struct wacom *wacom = hid_get_drvdata(hdev);
  1596. if (wacom->wacom_wac.features.type != HID_GENERIC)
  1597. return 0;
  1598. if (WACOM_PEN_FIELD(field))
  1599. return wacom_wac_pen_event(hdev, field, usage, value);
  1600. if (WACOM_FINGER_FIELD(field))
  1601. return wacom_wac_finger_event(hdev, field, usage, value);
  1602. return 0;
  1603. }
  1604. static void wacom_report_events(struct hid_device *hdev, struct hid_report *report)
  1605. {
  1606. int r;
  1607. for (r = 0; r < report->maxfield; r++) {
  1608. struct hid_field *field;
  1609. unsigned count, n;
  1610. field = report->field[r];
  1611. count = field->report_count;
  1612. if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
  1613. continue;
  1614. for (n = 0; n < count; n++)
  1615. wacom_wac_event(hdev, field, &field->usage[n], field->value[n]);
  1616. }
  1617. }
  1618. void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
  1619. {
  1620. struct wacom *wacom = hid_get_drvdata(hdev);
  1621. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1622. struct hid_field *field = report->field[0];
  1623. if (wacom_wac->features.type != HID_GENERIC)
  1624. return;
  1625. if (WACOM_PEN_FIELD(field))
  1626. wacom_wac_pen_pre_report(hdev, report);
  1627. if (WACOM_FINGER_FIELD(field))
  1628. wacom_wac_finger_pre_report(hdev, report);
  1629. wacom_report_events(hdev, report);
  1630. if (WACOM_PEN_FIELD(field))
  1631. return wacom_wac_pen_report(hdev, report);
  1632. if (WACOM_FINGER_FIELD(field))
  1633. return wacom_wac_finger_report(hdev, report);
  1634. }
  1635. static int wacom_bpt_touch(struct wacom_wac *wacom)
  1636. {
  1637. struct wacom_features *features = &wacom->features;
  1638. struct input_dev *input = wacom->touch_input;
  1639. struct input_dev *pad_input = wacom->pad_input;
  1640. unsigned char *data = wacom->data;
  1641. int i;
  1642. if (data[0] != 0x02)
  1643. return 0;
  1644. for (i = 0; i < 2; i++) {
  1645. int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
  1646. bool touch = data[offset + 3] & 0x80;
  1647. /*
  1648. * Touch events need to be disabled while stylus is
  1649. * in proximity because user's hand is resting on touchpad
  1650. * and sending unwanted events. User expects tablet buttons
  1651. * to continue working though.
  1652. */
  1653. touch = touch && !wacom->shared->stylus_in_proximity;
  1654. input_mt_slot(input, i);
  1655. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1656. if (touch) {
  1657. int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
  1658. int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
  1659. if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
  1660. x <<= 5;
  1661. y <<= 5;
  1662. }
  1663. input_report_abs(input, ABS_MT_POSITION_X, x);
  1664. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1665. }
  1666. }
  1667. input_mt_sync_frame(input);
  1668. input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
  1669. input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
  1670. input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
  1671. input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
  1672. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1673. return 1;
  1674. }
  1675. static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
  1676. {
  1677. struct wacom_features *features = &wacom->features;
  1678. struct input_dev *input = wacom->touch_input;
  1679. bool touch = data[1] & 0x80;
  1680. int slot = input_mt_get_slot_by_key(input, data[0]);
  1681. if (slot < 0)
  1682. return;
  1683. touch = touch && !wacom->shared->stylus_in_proximity;
  1684. input_mt_slot(input, slot);
  1685. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1686. if (touch) {
  1687. int x = (data[2] << 4) | (data[4] >> 4);
  1688. int y = (data[3] << 4) | (data[4] & 0x0f);
  1689. int width, height;
  1690. if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
  1691. width = data[5] * 100;
  1692. height = data[6] * 100;
  1693. } else {
  1694. /*
  1695. * "a" is a scaled-down area which we assume is
  1696. * roughly circular and which can be described as:
  1697. * a=(pi*r^2)/C.
  1698. */
  1699. int a = data[5];
  1700. int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
  1701. int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
  1702. width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
  1703. height = width * y_res / x_res;
  1704. }
  1705. input_report_abs(input, ABS_MT_POSITION_X, x);
  1706. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1707. input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
  1708. input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
  1709. }
  1710. }
  1711. static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
  1712. {
  1713. struct input_dev *input = wacom->pad_input;
  1714. struct wacom_features *features = &wacom->features;
  1715. if (features->type == INTUOSHT || features->type == INTUOSHT2) {
  1716. input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
  1717. input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
  1718. } else {
  1719. input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
  1720. input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
  1721. }
  1722. input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
  1723. input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
  1724. }
  1725. static int wacom_bpt3_touch(struct wacom_wac *wacom)
  1726. {
  1727. unsigned char *data = wacom->data;
  1728. int count = data[1] & 0x07;
  1729. int touch_changed = 0, i;
  1730. if (data[0] != 0x02)
  1731. return 0;
  1732. /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
  1733. for (i = 0; i < count; i++) {
  1734. int offset = (8 * i) + 2;
  1735. int msg_id = data[offset];
  1736. if (msg_id >= 2 && msg_id <= 17) {
  1737. wacom_bpt3_touch_msg(wacom, data + offset);
  1738. touch_changed++;
  1739. } else if (msg_id == 128)
  1740. wacom_bpt3_button_msg(wacom, data + offset);
  1741. }
  1742. /* only update touch if we actually have a touchpad and touch data changed */
  1743. if (wacom->touch_registered && touch_changed) {
  1744. input_mt_sync_frame(wacom->touch_input);
  1745. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1746. }
  1747. return 1;
  1748. }
  1749. static int wacom_bpt_pen(struct wacom_wac *wacom)
  1750. {
  1751. struct wacom_features *features = &wacom->features;
  1752. struct input_dev *input = wacom->pen_input;
  1753. unsigned char *data = wacom->data;
  1754. int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
  1755. if (data[0] != WACOM_REPORT_PENABLED)
  1756. return 0;
  1757. prox = (data[1] & 0x20) == 0x20;
  1758. /*
  1759. * All reports shared between PEN and RUBBER tool must be
  1760. * forced to a known starting value (zero) when transitioning to
  1761. * out-of-prox.
  1762. *
  1763. * If not reset then, to userspace, it will look like lost events
  1764. * if new tool comes in-prox with same values as previous tool sent.
  1765. *
  1766. * Hardware does report zero in most out-of-prox cases but not all.
  1767. */
  1768. if (!wacom->shared->stylus_in_proximity) {
  1769. if (data[1] & 0x08) {
  1770. wacom->tool[0] = BTN_TOOL_RUBBER;
  1771. wacom->id[0] = ERASER_DEVICE_ID;
  1772. } else {
  1773. wacom->tool[0] = BTN_TOOL_PEN;
  1774. wacom->id[0] = STYLUS_DEVICE_ID;
  1775. }
  1776. }
  1777. wacom->shared->stylus_in_proximity = prox;
  1778. if (wacom->shared->touch_down)
  1779. return 0;
  1780. if (prox) {
  1781. x = le16_to_cpup((__le16 *)&data[2]);
  1782. y = le16_to_cpup((__le16 *)&data[4]);
  1783. p = le16_to_cpup((__le16 *)&data[6]);
  1784. /*
  1785. * Convert distance from out prox to distance from tablet.
  1786. * distance will be greater than distance_max once
  1787. * touching and applying pressure; do not report negative
  1788. * distance.
  1789. */
  1790. if (data[8] <= features->distance_max)
  1791. d = features->distance_max - data[8];
  1792. pen = data[1] & 0x01;
  1793. btn1 = data[1] & 0x02;
  1794. btn2 = data[1] & 0x04;
  1795. } else {
  1796. wacom->id[0] = 0;
  1797. }
  1798. input_report_key(input, BTN_TOUCH, pen);
  1799. input_report_key(input, BTN_STYLUS, btn1);
  1800. input_report_key(input, BTN_STYLUS2, btn2);
  1801. input_report_abs(input, ABS_X, x);
  1802. input_report_abs(input, ABS_Y, y);
  1803. input_report_abs(input, ABS_PRESSURE, p);
  1804. input_report_abs(input, ABS_DISTANCE, d);
  1805. input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
  1806. input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
  1807. return 1;
  1808. }
  1809. static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
  1810. {
  1811. struct wacom_features *features = &wacom->features;
  1812. if ((features->type == INTUOSHT2) &&
  1813. (features->device_type & WACOM_DEVICETYPE_PEN))
  1814. return wacom_intuos_irq(wacom);
  1815. else if (len == WACOM_PKGLEN_BBTOUCH)
  1816. return wacom_bpt_touch(wacom);
  1817. else if (len == WACOM_PKGLEN_BBTOUCH3)
  1818. return wacom_bpt3_touch(wacom);
  1819. else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
  1820. return wacom_bpt_pen(wacom);
  1821. return 0;
  1822. }
  1823. static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
  1824. unsigned char *data)
  1825. {
  1826. unsigned char prefix;
  1827. /*
  1828. * We need to reroute the event from the debug interface to the
  1829. * pen interface.
  1830. * We need to add the report ID to the actual pen report, so we
  1831. * temporary overwrite the first byte to prevent having to kzalloc/kfree
  1832. * and memcpy the report.
  1833. */
  1834. prefix = data[0];
  1835. data[0] = WACOM_REPORT_BPAD_PEN;
  1836. /*
  1837. * actually reroute the event.
  1838. * No need to check if wacom->shared->pen is valid, hid_input_report()
  1839. * will check for us.
  1840. */
  1841. hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
  1842. WACOM_PKGLEN_PENABLED, 1);
  1843. data[0] = prefix;
  1844. }
  1845. static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
  1846. unsigned char *data)
  1847. {
  1848. struct input_dev *input = wacom->touch_input;
  1849. unsigned char *finger_data, prefix;
  1850. unsigned id;
  1851. int x, y;
  1852. bool valid;
  1853. prefix = data[0];
  1854. for (id = 0; id < wacom->features.touch_max; id++) {
  1855. valid = !!(prefix & BIT(id)) &&
  1856. !wacom->shared->stylus_in_proximity;
  1857. input_mt_slot(input, id);
  1858. input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
  1859. if (!valid)
  1860. continue;
  1861. finger_data = data + 1 + id * 3;
  1862. x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
  1863. y = (finger_data[2] << 4) | (finger_data[1] >> 4);
  1864. input_report_abs(input, ABS_MT_POSITION_X, x);
  1865. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1866. }
  1867. input_mt_sync_frame(input);
  1868. input_report_key(input, BTN_LEFT, prefix & 0x40);
  1869. input_report_key(input, BTN_RIGHT, prefix & 0x80);
  1870. /* keep touch state for pen event */
  1871. wacom->shared->touch_down = !!prefix &&
  1872. !wacom->shared->stylus_in_proximity;
  1873. return 1;
  1874. }
  1875. static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
  1876. {
  1877. unsigned char *data = wacom->data;
  1878. if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
  1879. (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
  1880. (data[0] != WACOM_REPORT_BPAD_TOUCH))
  1881. return 0;
  1882. if (data[1] & 0x01)
  1883. wacom_bamboo_pad_pen_event(wacom, &data[1]);
  1884. if (data[1] & 0x02)
  1885. return wacom_bamboo_pad_touch_event(wacom, &data[9]);
  1886. return 0;
  1887. }
  1888. static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
  1889. {
  1890. unsigned char *data = wacom->data;
  1891. int connected;
  1892. if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
  1893. return 0;
  1894. connected = data[1] & 0x01;
  1895. if (connected) {
  1896. int pid, battery, charging;
  1897. if ((wacom->shared->type == INTUOSHT ||
  1898. wacom->shared->type == INTUOSHT2) &&
  1899. wacom->shared->touch_input &&
  1900. wacom->shared->touch_max) {
  1901. input_report_switch(wacom->shared->touch_input,
  1902. SW_MUTE_DEVICE, data[5] & 0x40);
  1903. input_sync(wacom->shared->touch_input);
  1904. }
  1905. pid = get_unaligned_be16(&data[6]);
  1906. battery = (data[5] & 0x3f) * 100 / 31;
  1907. charging = !!(data[5] & 0x80);
  1908. if (wacom->pid != pid) {
  1909. wacom->pid = pid;
  1910. wacom_schedule_work(wacom);
  1911. }
  1912. if (wacom->shared->type)
  1913. wacom_notify_battery(wacom, battery, charging, 1, 0);
  1914. } else if (wacom->pid != 0) {
  1915. /* disconnected while previously connected */
  1916. wacom->pid = 0;
  1917. wacom_schedule_work(wacom);
  1918. wacom_notify_battery(wacom, 0, 0, 0, 0);
  1919. }
  1920. return 0;
  1921. }
  1922. static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
  1923. {
  1924. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  1925. struct wacom_features *features = &wacom_wac->features;
  1926. unsigned char *data = wacom_wac->data;
  1927. if (data[0] != WACOM_REPORT_USB)
  1928. return 0;
  1929. if ((features->type == INTUOSHT ||
  1930. features->type == INTUOSHT2) &&
  1931. wacom_wac->shared->touch_input &&
  1932. features->touch_max) {
  1933. input_report_switch(wacom_wac->shared->touch_input,
  1934. SW_MUTE_DEVICE, data[8] & 0x40);
  1935. input_sync(wacom_wac->shared->touch_input);
  1936. }
  1937. if (data[9] & 0x02) { /* wireless module is attached */
  1938. int battery = (data[8] & 0x3f) * 100 / 31;
  1939. bool charging = !!(data[8] & 0x80);
  1940. wacom_notify_battery(wacom_wac, battery, charging,
  1941. battery || charging, 1);
  1942. if (!wacom->battery &&
  1943. !(features->quirks & WACOM_QUIRK_BATTERY)) {
  1944. features->quirks |= WACOM_QUIRK_BATTERY;
  1945. INIT_WORK(&wacom->work, wacom_battery_work);
  1946. wacom_schedule_work(wacom_wac);
  1947. }
  1948. }
  1949. else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
  1950. wacom->battery) {
  1951. features->quirks &= ~WACOM_QUIRK_BATTERY;
  1952. INIT_WORK(&wacom->work, wacom_battery_work);
  1953. wacom_schedule_work(wacom_wac);
  1954. wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
  1955. }
  1956. return 0;
  1957. }
  1958. void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
  1959. {
  1960. bool sync;
  1961. switch (wacom_wac->features.type) {
  1962. case PENPARTNER:
  1963. sync = wacom_penpartner_irq(wacom_wac);
  1964. break;
  1965. case PL:
  1966. sync = wacom_pl_irq(wacom_wac);
  1967. break;
  1968. case WACOM_G4:
  1969. case GRAPHIRE:
  1970. case GRAPHIRE_BT:
  1971. case WACOM_MO:
  1972. sync = wacom_graphire_irq(wacom_wac);
  1973. break;
  1974. case PTU:
  1975. sync = wacom_ptu_irq(wacom_wac);
  1976. break;
  1977. case DTU:
  1978. sync = wacom_dtu_irq(wacom_wac);
  1979. break;
  1980. case DTUS:
  1981. case DTUSX:
  1982. sync = wacom_dtus_irq(wacom_wac);
  1983. break;
  1984. case INTUOS:
  1985. case INTUOS3S:
  1986. case INTUOS3:
  1987. case INTUOS3L:
  1988. case INTUOS4S:
  1989. case INTUOS4:
  1990. case INTUOS4L:
  1991. case CINTIQ:
  1992. case WACOM_BEE:
  1993. case WACOM_13HD:
  1994. case WACOM_21UX2:
  1995. case WACOM_22HD:
  1996. case WACOM_24HD:
  1997. case WACOM_27QHD:
  1998. case DTK:
  1999. case CINTIQ_HYBRID:
  2000. case CINTIQ_COMPANION_2:
  2001. sync = wacom_intuos_irq(wacom_wac);
  2002. break;
  2003. case INTUOS4WL:
  2004. sync = wacom_intuos_bt_irq(wacom_wac, len);
  2005. break;
  2006. case WACOM_24HDT:
  2007. case WACOM_27QHDT:
  2008. sync = wacom_24hdt_irq(wacom_wac);
  2009. break;
  2010. case INTUOS5S:
  2011. case INTUOS5:
  2012. case INTUOS5L:
  2013. case INTUOSPS:
  2014. case INTUOSPM:
  2015. case INTUOSPL:
  2016. if (len == WACOM_PKGLEN_BBTOUCH3)
  2017. sync = wacom_bpt3_touch(wacom_wac);
  2018. else if (wacom_wac->data[0] == WACOM_REPORT_USB)
  2019. sync = wacom_status_irq(wacom_wac, len);
  2020. else
  2021. sync = wacom_intuos_irq(wacom_wac);
  2022. break;
  2023. case TABLETPC:
  2024. case TABLETPCE:
  2025. case TABLETPC2FG:
  2026. case MTSCREEN:
  2027. case MTTPC:
  2028. case MTTPC_B:
  2029. sync = wacom_tpc_irq(wacom_wac, len);
  2030. break;
  2031. case BAMBOO_PT:
  2032. case BAMBOO_PEN:
  2033. case BAMBOO_TOUCH:
  2034. case INTUOSHT:
  2035. case INTUOSHT2:
  2036. if (wacom_wac->data[0] == WACOM_REPORT_USB)
  2037. sync = wacom_status_irq(wacom_wac, len);
  2038. else
  2039. sync = wacom_bpt_irq(wacom_wac, len);
  2040. break;
  2041. case BAMBOO_PAD:
  2042. sync = wacom_bamboo_pad_irq(wacom_wac, len);
  2043. break;
  2044. case WIRELESS:
  2045. sync = wacom_wireless_irq(wacom_wac, len);
  2046. break;
  2047. case REMOTE:
  2048. if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
  2049. sync = wacom_remote_status_irq(wacom_wac, len);
  2050. else
  2051. sync = wacom_remote_irq(wacom_wac, len);
  2052. break;
  2053. default:
  2054. sync = false;
  2055. break;
  2056. }
  2057. if (sync) {
  2058. if (wacom_wac->pen_input)
  2059. input_sync(wacom_wac->pen_input);
  2060. if (wacom_wac->touch_input)
  2061. input_sync(wacom_wac->touch_input);
  2062. if (wacom_wac->pad_input)
  2063. input_sync(wacom_wac->pad_input);
  2064. }
  2065. }
  2066. static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
  2067. {
  2068. struct input_dev *input_dev = wacom_wac->pen_input;
  2069. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  2070. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  2071. __set_bit(BTN_STYLUS, input_dev->keybit);
  2072. __set_bit(BTN_STYLUS2, input_dev->keybit);
  2073. input_set_abs_params(input_dev, ABS_DISTANCE,
  2074. 0, wacom_wac->features.distance_max, 0, 0);
  2075. }
  2076. static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
  2077. {
  2078. struct input_dev *input_dev = wacom_wac->pen_input;
  2079. wacom_setup_basic_pro_pen(wacom_wac);
  2080. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  2081. __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
  2082. __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
  2083. __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
  2084. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  2085. input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, 0, 0);
  2086. input_abs_set_res(input_dev, ABS_TILT_X, 57);
  2087. input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, 0, 0);
  2088. input_abs_set_res(input_dev, ABS_TILT_Y, 57);
  2089. }
  2090. static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
  2091. {
  2092. struct input_dev *input_dev = wacom_wac->pen_input;
  2093. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  2094. wacom_setup_cintiq(wacom_wac);
  2095. __set_bit(BTN_LEFT, input_dev->keybit);
  2096. __set_bit(BTN_RIGHT, input_dev->keybit);
  2097. __set_bit(BTN_MIDDLE, input_dev->keybit);
  2098. __set_bit(BTN_SIDE, input_dev->keybit);
  2099. __set_bit(BTN_EXTRA, input_dev->keybit);
  2100. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  2101. __set_bit(BTN_TOOL_LENS, input_dev->keybit);
  2102. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  2103. input_abs_set_res(input_dev, ABS_RZ, 287);
  2104. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  2105. }
  2106. void wacom_setup_device_quirks(struct wacom *wacom)
  2107. {
  2108. struct wacom_features *features = &wacom->wacom_wac.features;
  2109. /* The pen and pad share the same interface on most devices */
  2110. if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
  2111. features->type == DTUS ||
  2112. (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
  2113. if (features->device_type & WACOM_DEVICETYPE_PEN)
  2114. features->device_type |= WACOM_DEVICETYPE_PAD;
  2115. }
  2116. /* touch device found but size is not defined. use default */
  2117. if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
  2118. features->x_max = 1023;
  2119. features->y_max = 1023;
  2120. }
  2121. /*
  2122. * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
  2123. * touch interface in its HID descriptor. If this is the touch
  2124. * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
  2125. * tablet values.
  2126. */
  2127. if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
  2128. (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
  2129. if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
  2130. if (features->touch_max)
  2131. features->device_type |= WACOM_DEVICETYPE_TOUCH;
  2132. if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
  2133. features->device_type |= WACOM_DEVICETYPE_PAD;
  2134. if (features->type == INTUOSHT2) {
  2135. features->x_max = features->x_max / 10;
  2136. features->y_max = features->y_max / 10;
  2137. }
  2138. else {
  2139. features->x_max = 4096;
  2140. features->y_max = 4096;
  2141. }
  2142. }
  2143. else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
  2144. features->device_type |= WACOM_DEVICETYPE_PAD;
  2145. }
  2146. }
  2147. /*
  2148. * Hack for the Bamboo One:
  2149. * the device presents a PAD/Touch interface as most Bamboos and even
  2150. * sends ghosts PAD data on it. However, later, we must disable this
  2151. * ghost interface, and we can not detect it unless we set it here
  2152. * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
  2153. */
  2154. if (features->type == BAMBOO_PEN &&
  2155. features->pktlen == WACOM_PKGLEN_BBTOUCH3)
  2156. features->device_type |= WACOM_DEVICETYPE_PAD;
  2157. /*
  2158. * Raw Wacom-mode pen and touch events both come from interface
  2159. * 0, whose HID descriptor has an application usage of 0xFF0D
  2160. * (i.e., WACOM_VENDORDEFINED_PEN). We route pen packets back
  2161. * out through the HID_GENERIC device created for interface 1,
  2162. * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
  2163. */
  2164. if (features->type == BAMBOO_PAD)
  2165. features->device_type = WACOM_DEVICETYPE_TOUCH;
  2166. if (features->type == REMOTE)
  2167. features->device_type = WACOM_DEVICETYPE_PAD;
  2168. if (wacom->hdev->bus == BUS_BLUETOOTH)
  2169. features->quirks |= WACOM_QUIRK_BATTERY;
  2170. /* quirk for bamboo touch with 2 low res touches */
  2171. if (features->type == BAMBOO_PT &&
  2172. features->pktlen == WACOM_PKGLEN_BBTOUCH) {
  2173. features->x_max <<= 5;
  2174. features->y_max <<= 5;
  2175. features->x_fuzz <<= 5;
  2176. features->y_fuzz <<= 5;
  2177. features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
  2178. }
  2179. if (features->type == WIRELESS) {
  2180. if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
  2181. features->quirks |= WACOM_QUIRK_BATTERY;
  2182. }
  2183. }
  2184. }
  2185. int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
  2186. struct wacom_wac *wacom_wac)
  2187. {
  2188. struct wacom_features *features = &wacom_wac->features;
  2189. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  2190. if (!(features->device_type & WACOM_DEVICETYPE_PEN))
  2191. return -ENODEV;
  2192. if (features->type == HID_GENERIC)
  2193. /* setup has already been done */
  2194. return 0;
  2195. __set_bit(BTN_TOUCH, input_dev->keybit);
  2196. __set_bit(ABS_MISC, input_dev->absbit);
  2197. input_set_abs_params(input_dev, ABS_X, features->x_min,
  2198. features->x_max, features->x_fuzz, 0);
  2199. input_set_abs_params(input_dev, ABS_Y, features->y_min,
  2200. features->y_max, features->y_fuzz, 0);
  2201. input_set_abs_params(input_dev, ABS_PRESSURE, 0,
  2202. features->pressure_max, features->pressure_fuzz, 0);
  2203. /* penabled devices have fixed resolution for each model */
  2204. input_abs_set_res(input_dev, ABS_X, features->x_resolution);
  2205. input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
  2206. switch (features->type) {
  2207. case GRAPHIRE_BT:
  2208. __clear_bit(ABS_MISC, input_dev->absbit);
  2209. case WACOM_MO:
  2210. case WACOM_G4:
  2211. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  2212. features->distance_max,
  2213. 0, 0);
  2214. /* fall through */
  2215. case GRAPHIRE:
  2216. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  2217. __set_bit(BTN_LEFT, input_dev->keybit);
  2218. __set_bit(BTN_RIGHT, input_dev->keybit);
  2219. __set_bit(BTN_MIDDLE, input_dev->keybit);
  2220. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  2221. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  2222. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  2223. __set_bit(BTN_STYLUS, input_dev->keybit);
  2224. __set_bit(BTN_STYLUS2, input_dev->keybit);
  2225. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  2226. break;
  2227. case WACOM_27QHD:
  2228. case WACOM_24HD:
  2229. case DTK:
  2230. case WACOM_22HD:
  2231. case WACOM_21UX2:
  2232. case WACOM_BEE:
  2233. case CINTIQ:
  2234. case WACOM_13HD:
  2235. case CINTIQ_HYBRID:
  2236. case CINTIQ_COMPANION_2:
  2237. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  2238. input_abs_set_res(input_dev, ABS_Z, 287);
  2239. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  2240. wacom_setup_cintiq(wacom_wac);
  2241. break;
  2242. case INTUOS3:
  2243. case INTUOS3L:
  2244. case INTUOS3S:
  2245. case INTUOS4:
  2246. case INTUOS4WL:
  2247. case INTUOS4L:
  2248. case INTUOS4S:
  2249. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  2250. input_abs_set_res(input_dev, ABS_Z, 287);
  2251. /* fall through */
  2252. case INTUOS:
  2253. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  2254. wacom_setup_intuos(wacom_wac);
  2255. break;
  2256. case INTUOS5:
  2257. case INTUOS5L:
  2258. case INTUOSPM:
  2259. case INTUOSPL:
  2260. case INTUOS5S:
  2261. case INTUOSPS:
  2262. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  2263. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  2264. features->distance_max,
  2265. 0, 0);
  2266. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  2267. input_abs_set_res(input_dev, ABS_Z, 287);
  2268. wacom_setup_intuos(wacom_wac);
  2269. break;
  2270. case WACOM_24HDT:
  2271. case WACOM_27QHDT:
  2272. case MTSCREEN:
  2273. case MTTPC:
  2274. case MTTPC_B:
  2275. case TABLETPC2FG:
  2276. case TABLETPC:
  2277. case TABLETPCE:
  2278. __clear_bit(ABS_MISC, input_dev->absbit);
  2279. /* fall through */
  2280. case DTUS:
  2281. case DTUSX:
  2282. case PL:
  2283. case DTU:
  2284. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  2285. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  2286. __set_bit(BTN_STYLUS, input_dev->keybit);
  2287. __set_bit(BTN_STYLUS2, input_dev->keybit);
  2288. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  2289. break;
  2290. case PTU:
  2291. __set_bit(BTN_STYLUS2, input_dev->keybit);
  2292. /* fall through */
  2293. case PENPARTNER:
  2294. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  2295. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  2296. __set_bit(BTN_STYLUS, input_dev->keybit);
  2297. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  2298. break;
  2299. case INTUOSHT:
  2300. case BAMBOO_PT:
  2301. case BAMBOO_PEN:
  2302. case INTUOSHT2:
  2303. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  2304. if (features->type == INTUOSHT2) {
  2305. wacom_setup_basic_pro_pen(wacom_wac);
  2306. } else {
  2307. __clear_bit(ABS_MISC, input_dev->absbit);
  2308. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  2309. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  2310. __set_bit(BTN_STYLUS, input_dev->keybit);
  2311. __set_bit(BTN_STYLUS2, input_dev->keybit);
  2312. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  2313. features->distance_max,
  2314. 0, 0);
  2315. }
  2316. break;
  2317. case BAMBOO_PAD:
  2318. __clear_bit(ABS_MISC, input_dev->absbit);
  2319. break;
  2320. }
  2321. return 0;
  2322. }
  2323. int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
  2324. struct wacom_wac *wacom_wac)
  2325. {
  2326. struct wacom_features *features = &wacom_wac->features;
  2327. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  2328. if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
  2329. return -ENODEV;
  2330. if (features->type == HID_GENERIC)
  2331. /* setup has already been done */
  2332. return 0;
  2333. __set_bit(BTN_TOUCH, input_dev->keybit);
  2334. if (features->touch_max == 1) {
  2335. input_set_abs_params(input_dev, ABS_X, 0,
  2336. features->x_max, features->x_fuzz, 0);
  2337. input_set_abs_params(input_dev, ABS_Y, 0,
  2338. features->y_max, features->y_fuzz, 0);
  2339. input_abs_set_res(input_dev, ABS_X,
  2340. features->x_resolution);
  2341. input_abs_set_res(input_dev, ABS_Y,
  2342. features->y_resolution);
  2343. }
  2344. else if (features->touch_max > 1) {
  2345. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
  2346. features->x_max, features->x_fuzz, 0);
  2347. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
  2348. features->y_max, features->y_fuzz, 0);
  2349. input_abs_set_res(input_dev, ABS_MT_POSITION_X,
  2350. features->x_resolution);
  2351. input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
  2352. features->y_resolution);
  2353. }
  2354. switch (features->type) {
  2355. case INTUOS5:
  2356. case INTUOS5L:
  2357. case INTUOSPM:
  2358. case INTUOSPL:
  2359. case INTUOS5S:
  2360. case INTUOSPS:
  2361. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  2362. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
  2363. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
  2364. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
  2365. break;
  2366. case WACOM_24HDT:
  2367. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
  2368. input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
  2369. input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
  2370. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  2371. /* fall through */
  2372. case WACOM_27QHDT:
  2373. case MTSCREEN:
  2374. case MTTPC:
  2375. case MTTPC_B:
  2376. case TABLETPC2FG:
  2377. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
  2378. /*fall through */
  2379. case TABLETPC:
  2380. case TABLETPCE:
  2381. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  2382. break;
  2383. case INTUOSHT:
  2384. case INTUOSHT2:
  2385. input_dev->evbit[0] |= BIT_MASK(EV_SW);
  2386. __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
  2387. /* fall through */
  2388. case BAMBOO_PT:
  2389. case BAMBOO_TOUCH:
  2390. if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
  2391. input_set_abs_params(input_dev,
  2392. ABS_MT_TOUCH_MAJOR,
  2393. 0, features->x_max, 0, 0);
  2394. input_set_abs_params(input_dev,
  2395. ABS_MT_TOUCH_MINOR,
  2396. 0, features->y_max, 0, 0);
  2397. }
  2398. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
  2399. break;
  2400. case BAMBOO_PAD:
  2401. input_mt_init_slots(input_dev, features->touch_max,
  2402. INPUT_MT_POINTER);
  2403. __set_bit(BTN_LEFT, input_dev->keybit);
  2404. __set_bit(BTN_RIGHT, input_dev->keybit);
  2405. break;
  2406. }
  2407. return 0;
  2408. }
  2409. static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
  2410. int button_count)
  2411. {
  2412. int i;
  2413. for (i = 0; i < button_count && i < 10; i++)
  2414. __set_bit(BTN_0 + i, input_dev->keybit);
  2415. for (i = 10; i < button_count && i < 16; i++)
  2416. __set_bit(BTN_A + (i-10), input_dev->keybit);
  2417. for (i = 16; i < button_count && i < 18; i++)
  2418. __set_bit(BTN_BASE + (i-16), input_dev->keybit);
  2419. }
  2420. int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
  2421. struct wacom_wac *wacom_wac)
  2422. {
  2423. struct wacom_features *features = &wacom_wac->features;
  2424. if (!(features->device_type & WACOM_DEVICETYPE_PAD))
  2425. return -ENODEV;
  2426. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  2427. /* kept for making legacy xf86-input-wacom working with the wheels */
  2428. __set_bit(ABS_MISC, input_dev->absbit);
  2429. /* kept for making legacy xf86-input-wacom accepting the pad */
  2430. input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
  2431. input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
  2432. /* kept for making udev and libwacom accepting the pad */
  2433. __set_bit(BTN_STYLUS, input_dev->keybit);
  2434. wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
  2435. switch (features->type) {
  2436. case CINTIQ_HYBRID:
  2437. case CINTIQ_COMPANION_2:
  2438. case DTK:
  2439. case DTUS:
  2440. case GRAPHIRE_BT:
  2441. break;
  2442. case WACOM_MO:
  2443. __set_bit(BTN_BACK, input_dev->keybit);
  2444. __set_bit(BTN_LEFT, input_dev->keybit);
  2445. __set_bit(BTN_FORWARD, input_dev->keybit);
  2446. __set_bit(BTN_RIGHT, input_dev->keybit);
  2447. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  2448. break;
  2449. case WACOM_G4:
  2450. __set_bit(BTN_BACK, input_dev->keybit);
  2451. __set_bit(BTN_FORWARD, input_dev->keybit);
  2452. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  2453. break;
  2454. case WACOM_24HD:
  2455. __set_bit(KEY_PROG1, input_dev->keybit);
  2456. __set_bit(KEY_PROG2, input_dev->keybit);
  2457. __set_bit(KEY_PROG3, input_dev->keybit);
  2458. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  2459. input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
  2460. break;
  2461. case WACOM_27QHD:
  2462. __set_bit(KEY_PROG1, input_dev->keybit);
  2463. __set_bit(KEY_PROG2, input_dev->keybit);
  2464. __set_bit(KEY_PROG3, input_dev->keybit);
  2465. input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
  2466. input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
  2467. input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
  2468. input_abs_set_res(input_dev, ABS_Y, 1024);
  2469. input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
  2470. input_abs_set_res(input_dev, ABS_Z, 1024);
  2471. __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
  2472. break;
  2473. case WACOM_22HD:
  2474. __set_bit(KEY_PROG1, input_dev->keybit);
  2475. __set_bit(KEY_PROG2, input_dev->keybit);
  2476. __set_bit(KEY_PROG3, input_dev->keybit);
  2477. /* fall through */
  2478. case WACOM_21UX2:
  2479. case WACOM_BEE:
  2480. case CINTIQ:
  2481. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  2482. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  2483. break;
  2484. case WACOM_13HD:
  2485. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  2486. break;
  2487. case INTUOS3:
  2488. case INTUOS3L:
  2489. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  2490. /* fall through */
  2491. case INTUOS3S:
  2492. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  2493. break;
  2494. case INTUOS5:
  2495. case INTUOS5L:
  2496. case INTUOSPM:
  2497. case INTUOSPL:
  2498. case INTUOS5S:
  2499. case INTUOSPS:
  2500. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  2501. break;
  2502. case INTUOS4WL:
  2503. /*
  2504. * For Bluetooth devices, the udev rule does not work correctly
  2505. * for pads unless we add a stylus capability, which forces
  2506. * ID_INPUT_TABLET to be set.
  2507. */
  2508. __set_bit(BTN_STYLUS, input_dev->keybit);
  2509. /* fall through */
  2510. case INTUOS4:
  2511. case INTUOS4L:
  2512. case INTUOS4S:
  2513. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  2514. break;
  2515. case INTUOSHT:
  2516. case BAMBOO_PT:
  2517. case BAMBOO_TOUCH:
  2518. case INTUOSHT2:
  2519. __clear_bit(ABS_MISC, input_dev->absbit);
  2520. __set_bit(BTN_LEFT, input_dev->keybit);
  2521. __set_bit(BTN_FORWARD, input_dev->keybit);
  2522. __set_bit(BTN_BACK, input_dev->keybit);
  2523. __set_bit(BTN_RIGHT, input_dev->keybit);
  2524. break;
  2525. case REMOTE:
  2526. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  2527. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  2528. break;
  2529. default:
  2530. /* no pad supported */
  2531. return -ENODEV;
  2532. }
  2533. return 0;
  2534. }
  2535. static const struct wacom_features wacom_features_0x00 =
  2536. { "Wacom Penpartner", 5040, 3780, 255, 0,
  2537. PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  2538. static const struct wacom_features wacom_features_0x10 =
  2539. { "Wacom Graphire", 10206, 7422, 511, 63,
  2540. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2541. static const struct wacom_features wacom_features_0x81 =
  2542. { "Wacom Graphire BT", 16704, 12064, 511, 32,
  2543. GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
  2544. static const struct wacom_features wacom_features_0x11 =
  2545. { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
  2546. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2547. static const struct wacom_features wacom_features_0x12 =
  2548. { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
  2549. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2550. static const struct wacom_features wacom_features_0x13 =
  2551. { "Wacom Graphire3", 10208, 7424, 511, 63,
  2552. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2553. static const struct wacom_features wacom_features_0x14 =
  2554. { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
  2555. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2556. static const struct wacom_features wacom_features_0x15 =
  2557. { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
  2558. WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2559. static const struct wacom_features wacom_features_0x16 =
  2560. { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
  2561. WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2562. static const struct wacom_features wacom_features_0x17 =
  2563. { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
  2564. WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2565. static const struct wacom_features wacom_features_0x18 =
  2566. { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
  2567. WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2568. static const struct wacom_features wacom_features_0x19 =
  2569. { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
  2570. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  2571. static const struct wacom_features wacom_features_0x60 =
  2572. { "Wacom Volito", 5104, 3712, 511, 63,
  2573. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  2574. static const struct wacom_features wacom_features_0x61 =
  2575. { "Wacom PenStation2", 3250, 2320, 255, 63,
  2576. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  2577. static const struct wacom_features wacom_features_0x62 =
  2578. { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
  2579. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  2580. static const struct wacom_features wacom_features_0x63 =
  2581. { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
  2582. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  2583. static const struct wacom_features wacom_features_0x64 =
  2584. { "Wacom PenPartner2", 3250, 2320, 511, 63,
  2585. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  2586. static const struct wacom_features wacom_features_0x65 =
  2587. { "Wacom Bamboo", 14760, 9225, 511, 63,
  2588. WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2589. static const struct wacom_features wacom_features_0x69 =
  2590. { "Wacom Bamboo1", 5104, 3712, 511, 63,
  2591. GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  2592. static const struct wacom_features wacom_features_0x6A =
  2593. { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
  2594. GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2595. static const struct wacom_features wacom_features_0x6B =
  2596. { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
  2597. GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2598. static const struct wacom_features wacom_features_0x20 =
  2599. { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
  2600. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2601. static const struct wacom_features wacom_features_0x21 =
  2602. { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
  2603. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2604. static const struct wacom_features wacom_features_0x22 =
  2605. { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
  2606. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2607. static const struct wacom_features wacom_features_0x23 =
  2608. { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
  2609. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2610. static const struct wacom_features wacom_features_0x24 =
  2611. { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
  2612. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2613. static const struct wacom_features wacom_features_0x30 =
  2614. { "Wacom PL400", 5408, 4056, 255, 0,
  2615. PL, WACOM_PL_RES, WACOM_PL_RES };
  2616. static const struct wacom_features wacom_features_0x31 =
  2617. { "Wacom PL500", 6144, 4608, 255, 0,
  2618. PL, WACOM_PL_RES, WACOM_PL_RES };
  2619. static const struct wacom_features wacom_features_0x32 =
  2620. { "Wacom PL600", 6126, 4604, 255, 0,
  2621. PL, WACOM_PL_RES, WACOM_PL_RES };
  2622. static const struct wacom_features wacom_features_0x33 =
  2623. { "Wacom PL600SX", 6260, 5016, 255, 0,
  2624. PL, WACOM_PL_RES, WACOM_PL_RES };
  2625. static const struct wacom_features wacom_features_0x34 =
  2626. { "Wacom PL550", 6144, 4608, 511, 0,
  2627. PL, WACOM_PL_RES, WACOM_PL_RES };
  2628. static const struct wacom_features wacom_features_0x35 =
  2629. { "Wacom PL800", 7220, 5780, 511, 0,
  2630. PL, WACOM_PL_RES, WACOM_PL_RES };
  2631. static const struct wacom_features wacom_features_0x37 =
  2632. { "Wacom PL700", 6758, 5406, 511, 0,
  2633. PL, WACOM_PL_RES, WACOM_PL_RES };
  2634. static const struct wacom_features wacom_features_0x38 =
  2635. { "Wacom PL510", 6282, 4762, 511, 0,
  2636. PL, WACOM_PL_RES, WACOM_PL_RES };
  2637. static const struct wacom_features wacom_features_0x39 =
  2638. { "Wacom DTU710", 34080, 27660, 511, 0,
  2639. PL, WACOM_PL_RES, WACOM_PL_RES };
  2640. static const struct wacom_features wacom_features_0xC4 =
  2641. { "Wacom DTF521", 6282, 4762, 511, 0,
  2642. PL, WACOM_PL_RES, WACOM_PL_RES };
  2643. static const struct wacom_features wacom_features_0xC0 =
  2644. { "Wacom DTF720", 6858, 5506, 511, 0,
  2645. PL, WACOM_PL_RES, WACOM_PL_RES };
  2646. static const struct wacom_features wacom_features_0xC2 =
  2647. { "Wacom DTF720a", 6858, 5506, 511, 0,
  2648. PL, WACOM_PL_RES, WACOM_PL_RES };
  2649. static const struct wacom_features wacom_features_0x03 =
  2650. { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
  2651. PTU, WACOM_PL_RES, WACOM_PL_RES };
  2652. static const struct wacom_features wacom_features_0x41 =
  2653. { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
  2654. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2655. static const struct wacom_features wacom_features_0x42 =
  2656. { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
  2657. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2658. static const struct wacom_features wacom_features_0x43 =
  2659. { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
  2660. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2661. static const struct wacom_features wacom_features_0x44 =
  2662. { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
  2663. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2664. static const struct wacom_features wacom_features_0x45 =
  2665. { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
  2666. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2667. static const struct wacom_features wacom_features_0xB0 =
  2668. { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
  2669. INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
  2670. static const struct wacom_features wacom_features_0xB1 =
  2671. { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
  2672. INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  2673. static const struct wacom_features wacom_features_0xB2 =
  2674. { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
  2675. INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  2676. static const struct wacom_features wacom_features_0xB3 =
  2677. { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
  2678. INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  2679. static const struct wacom_features wacom_features_0xB4 =
  2680. { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
  2681. INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  2682. static const struct wacom_features wacom_features_0xB5 =
  2683. { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
  2684. INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  2685. static const struct wacom_features wacom_features_0xB7 =
  2686. { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
  2687. INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
  2688. static const struct wacom_features wacom_features_0xB8 =
  2689. { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
  2690. INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
  2691. static const struct wacom_features wacom_features_0xB9 =
  2692. { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
  2693. INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  2694. static const struct wacom_features wacom_features_0xBA =
  2695. { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
  2696. INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  2697. static const struct wacom_features wacom_features_0xBB =
  2698. { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
  2699. INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  2700. static const struct wacom_features wacom_features_0xBC =
  2701. { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
  2702. INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  2703. static const struct wacom_features wacom_features_0xBD =
  2704. { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
  2705. INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  2706. static const struct wacom_features wacom_features_0x26 =
  2707. { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
  2708. INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
  2709. static const struct wacom_features wacom_features_0x27 =
  2710. { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
  2711. INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
  2712. static const struct wacom_features wacom_features_0x28 =
  2713. { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
  2714. INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
  2715. static const struct wacom_features wacom_features_0x29 =
  2716. { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
  2717. INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
  2718. static const struct wacom_features wacom_features_0x2A =
  2719. { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
  2720. INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  2721. static const struct wacom_features wacom_features_0x314 =
  2722. { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
  2723. INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
  2724. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2725. static const struct wacom_features wacom_features_0x315 =
  2726. { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
  2727. INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
  2728. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2729. static const struct wacom_features wacom_features_0x317 =
  2730. { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
  2731. INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
  2732. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2733. static const struct wacom_features wacom_features_0xF4 =
  2734. { "Wacom Cintiq 24HD", 104080, 65200, 2047, 63,
  2735. WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
  2736. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  2737. static const struct wacom_features wacom_features_0xF8 =
  2738. { "Wacom Cintiq 24HD touch", 104080, 65200, 2047, 63, /* Pen */
  2739. WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
  2740. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2741. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
  2742. static const struct wacom_features wacom_features_0xF6 =
  2743. { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
  2744. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
  2745. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2746. static const struct wacom_features wacom_features_0x32A =
  2747. { "Wacom Cintiq 27QHD", 119740, 67520, 2047, 63,
  2748. WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
  2749. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  2750. static const struct wacom_features wacom_features_0x32B =
  2751. { "Wacom Cintiq 27QHD touch", 119740, 67520, 2047, 63,
  2752. WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
  2753. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2754. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
  2755. static const struct wacom_features wacom_features_0x32C =
  2756. { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
  2757. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
  2758. static const struct wacom_features wacom_features_0x3F =
  2759. { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
  2760. CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  2761. static const struct wacom_features wacom_features_0xC5 =
  2762. { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
  2763. WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
  2764. static const struct wacom_features wacom_features_0xC6 =
  2765. { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
  2766. WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
  2767. static const struct wacom_features wacom_features_0x304 =
  2768. { "Wacom Cintiq 13HD", 59152, 33448, 1023, 63,
  2769. WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  2770. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  2771. static const struct wacom_features wacom_features_0x333 =
  2772. { "Wacom Cintiq 13HD touch", 59152, 33448, 2047, 63,
  2773. WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  2774. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2775. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
  2776. static const struct wacom_features wacom_features_0x335 =
  2777. { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
  2778. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
  2779. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2780. static const struct wacom_features wacom_features_0xC7 =
  2781. { "Wacom DTU1931", 37832, 30305, 511, 0,
  2782. PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2783. static const struct wacom_features wacom_features_0xCE =
  2784. { "Wacom DTU2231", 47864, 27011, 511, 0,
  2785. DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  2786. .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
  2787. static const struct wacom_features wacom_features_0xF0 =
  2788. { "Wacom DTU1631", 34623, 19553, 511, 0,
  2789. DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2790. static const struct wacom_features wacom_features_0xFB =
  2791. { "Wacom DTU1031", 21896, 13760, 511, 0,
  2792. DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
  2793. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  2794. static const struct wacom_features wacom_features_0x32F =
  2795. { "Wacom DTU1031X", 22472, 12728, 511, 0,
  2796. DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
  2797. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  2798. static const struct wacom_features wacom_features_0x336 =
  2799. { "Wacom DTU1141", 23472, 13203, 1023, 0,
  2800. DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
  2801. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  2802. static const struct wacom_features wacom_features_0x57 =
  2803. { "Wacom DTK2241", 95640, 54060, 2047, 63,
  2804. DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
  2805. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  2806. static const struct wacom_features wacom_features_0x59 = /* Pen */
  2807. { "Wacom DTH2242", 95640, 54060, 2047, 63,
  2808. DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
  2809. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2810. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
  2811. static const struct wacom_features wacom_features_0x5D = /* Touch */
  2812. { "Wacom DTH2242", .type = WACOM_24HDT,
  2813. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
  2814. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2815. static const struct wacom_features wacom_features_0xCC =
  2816. { "Wacom Cintiq 21UX2", 86800, 65200, 2047, 63,
  2817. WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
  2818. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  2819. static const struct wacom_features wacom_features_0xFA =
  2820. { "Wacom Cintiq 22HD", 95440, 53860, 2047, 63,
  2821. WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
  2822. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  2823. static const struct wacom_features wacom_features_0x5B =
  2824. { "Wacom Cintiq 22HDT", 95440, 53860, 2047, 63,
  2825. WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
  2826. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2827. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
  2828. static const struct wacom_features wacom_features_0x5E =
  2829. { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
  2830. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
  2831. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2832. static const struct wacom_features wacom_features_0x90 =
  2833. { "Wacom ISDv4 90", 26202, 16325, 255, 0,
  2834. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2835. static const struct wacom_features wacom_features_0x93 =
  2836. { "Wacom ISDv4 93", 26202, 16325, 255, 0,
  2837. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2838. static const struct wacom_features wacom_features_0x97 =
  2839. { "Wacom ISDv4 97", 26202, 16325, 511, 0,
  2840. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2841. static const struct wacom_features wacom_features_0x9A =
  2842. { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
  2843. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2844. static const struct wacom_features wacom_features_0x9F =
  2845. { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
  2846. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2847. static const struct wacom_features wacom_features_0xE2 =
  2848. { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
  2849. TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2850. static const struct wacom_features wacom_features_0xE3 =
  2851. { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
  2852. TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2853. static const struct wacom_features wacom_features_0xE5 =
  2854. { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
  2855. MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2856. static const struct wacom_features wacom_features_0xE6 =
  2857. { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
  2858. TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2859. static const struct wacom_features wacom_features_0xEC =
  2860. { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
  2861. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2862. static const struct wacom_features wacom_features_0xED =
  2863. { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
  2864. TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2865. static const struct wacom_features wacom_features_0xEF =
  2866. { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
  2867. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2868. static const struct wacom_features wacom_features_0x100 =
  2869. { "Wacom ISDv4 100", 26202, 16325, 255, 0,
  2870. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2871. static const struct wacom_features wacom_features_0x101 =
  2872. { "Wacom ISDv4 101", 26202, 16325, 255, 0,
  2873. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2874. static const struct wacom_features wacom_features_0x10D =
  2875. { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
  2876. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2877. static const struct wacom_features wacom_features_0x10E =
  2878. { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
  2879. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2880. static const struct wacom_features wacom_features_0x10F =
  2881. { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
  2882. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2883. static const struct wacom_features wacom_features_0x116 =
  2884. { "Wacom ISDv4 116", 26202, 16325, 255, 0,
  2885. TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2886. static const struct wacom_features wacom_features_0x12C =
  2887. { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
  2888. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2889. static const struct wacom_features wacom_features_0x4001 =
  2890. { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
  2891. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2892. static const struct wacom_features wacom_features_0x4004 =
  2893. { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
  2894. MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2895. static const struct wacom_features wacom_features_0x5000 =
  2896. { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
  2897. MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2898. static const struct wacom_features wacom_features_0x5002 =
  2899. { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
  2900. MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2901. static const struct wacom_features wacom_features_0x47 =
  2902. { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
  2903. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2904. static const struct wacom_features wacom_features_0x84 =
  2905. { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
  2906. static const struct wacom_features wacom_features_0xD0 =
  2907. { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
  2908. BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2909. static const struct wacom_features wacom_features_0xD1 =
  2910. { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
  2911. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2912. static const struct wacom_features wacom_features_0xD2 =
  2913. { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
  2914. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2915. static const struct wacom_features wacom_features_0xD3 =
  2916. { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
  2917. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2918. static const struct wacom_features wacom_features_0xD4 =
  2919. { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
  2920. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2921. static const struct wacom_features wacom_features_0xD5 =
  2922. { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
  2923. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2924. static const struct wacom_features wacom_features_0xD6 =
  2925. { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
  2926. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2927. static const struct wacom_features wacom_features_0xD7 =
  2928. { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
  2929. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2930. static const struct wacom_features wacom_features_0xD8 =
  2931. { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
  2932. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2933. static const struct wacom_features wacom_features_0xDA =
  2934. { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
  2935. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2936. static const struct wacom_features wacom_features_0xDB =
  2937. { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
  2938. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  2939. static const struct wacom_features wacom_features_0xDD =
  2940. { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
  2941. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2942. static const struct wacom_features wacom_features_0xDE =
  2943. { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
  2944. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
  2945. static const struct wacom_features wacom_features_0xDF =
  2946. { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
  2947. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
  2948. static const struct wacom_features wacom_features_0x300 =
  2949. { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
  2950. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2951. static const struct wacom_features wacom_features_0x301 =
  2952. { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
  2953. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2954. static const struct wacom_features wacom_features_0x302 =
  2955. { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
  2956. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  2957. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2958. static const struct wacom_features wacom_features_0x303 =
  2959. { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
  2960. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  2961. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2962. static const struct wacom_features wacom_features_0x30E =
  2963. { "Wacom Intuos S", 15200, 9500, 1023, 31,
  2964. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  2965. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2966. static const struct wacom_features wacom_features_0x6004 =
  2967. { "ISD-V4", 12800, 8000, 255, 0,
  2968. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  2969. static const struct wacom_features wacom_features_0x307 =
  2970. { "Wacom ISDv5 307", 59152, 33448, 2047, 63,
  2971. CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  2972. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2973. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
  2974. static const struct wacom_features wacom_features_0x309 =
  2975. { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
  2976. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
  2977. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2978. static const struct wacom_features wacom_features_0x30A =
  2979. { "Wacom ISDv5 30A", 59152, 33448, 2047, 63,
  2980. CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  2981. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2982. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
  2983. static const struct wacom_features wacom_features_0x30C =
  2984. { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
  2985. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
  2986. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  2987. static const struct wacom_features wacom_features_0x318 =
  2988. { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
  2989. .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
  2990. static const struct wacom_features wacom_features_0x319 =
  2991. { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
  2992. .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
  2993. static const struct wacom_features wacom_features_0x325 =
  2994. { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
  2995. CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
  2996. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  2997. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
  2998. static const struct wacom_features wacom_features_0x326 = /* Touch */
  2999. { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
  3000. .oPid = 0x325 };
  3001. static const struct wacom_features wacom_features_0x323 =
  3002. { "Wacom Intuos P M", 21600, 13500, 1023, 31,
  3003. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  3004. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3005. static const struct wacom_features wacom_features_0x331 =
  3006. { "Wacom Express Key Remote", .type = REMOTE,
  3007. .numbered_buttons = 18, .check_for_hid_type = true,
  3008. .hid_type = HID_TYPE_USBNONE };
  3009. static const struct wacom_features wacom_features_0x33B =
  3010. { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
  3011. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  3012. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3013. static const struct wacom_features wacom_features_0x33C =
  3014. { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
  3015. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  3016. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3017. static const struct wacom_features wacom_features_0x33D =
  3018. { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
  3019. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  3020. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3021. static const struct wacom_features wacom_features_0x33E =
  3022. { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
  3023. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  3024. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3025. static const struct wacom_features wacom_features_0x343 =
  3026. { "Wacom DTK1651", 34616, 19559, 1023, 0,
  3027. DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
  3028. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  3029. static const struct wacom_features wacom_features_HID_ANY_ID =
  3030. { "Wacom HID", .type = HID_GENERIC };
  3031. #define USB_DEVICE_WACOM(prod) \
  3032. HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
  3033. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  3034. #define BT_DEVICE_WACOM(prod) \
  3035. HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
  3036. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  3037. #define I2C_DEVICE_WACOM(prod) \
  3038. HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
  3039. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  3040. #define USB_DEVICE_LENOVO(prod) \
  3041. HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
  3042. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  3043. const struct hid_device_id wacom_ids[] = {
  3044. { USB_DEVICE_WACOM(0x00) },
  3045. { USB_DEVICE_WACOM(0x03) },
  3046. { USB_DEVICE_WACOM(0x10) },
  3047. { USB_DEVICE_WACOM(0x11) },
  3048. { USB_DEVICE_WACOM(0x12) },
  3049. { USB_DEVICE_WACOM(0x13) },
  3050. { USB_DEVICE_WACOM(0x14) },
  3051. { USB_DEVICE_WACOM(0x15) },
  3052. { USB_DEVICE_WACOM(0x16) },
  3053. { USB_DEVICE_WACOM(0x17) },
  3054. { USB_DEVICE_WACOM(0x18) },
  3055. { USB_DEVICE_WACOM(0x19) },
  3056. { USB_DEVICE_WACOM(0x20) },
  3057. { USB_DEVICE_WACOM(0x21) },
  3058. { USB_DEVICE_WACOM(0x22) },
  3059. { USB_DEVICE_WACOM(0x23) },
  3060. { USB_DEVICE_WACOM(0x24) },
  3061. { USB_DEVICE_WACOM(0x26) },
  3062. { USB_DEVICE_WACOM(0x27) },
  3063. { USB_DEVICE_WACOM(0x28) },
  3064. { USB_DEVICE_WACOM(0x29) },
  3065. { USB_DEVICE_WACOM(0x2A) },
  3066. { USB_DEVICE_WACOM(0x30) },
  3067. { USB_DEVICE_WACOM(0x31) },
  3068. { USB_DEVICE_WACOM(0x32) },
  3069. { USB_DEVICE_WACOM(0x33) },
  3070. { USB_DEVICE_WACOM(0x34) },
  3071. { USB_DEVICE_WACOM(0x35) },
  3072. { USB_DEVICE_WACOM(0x37) },
  3073. { USB_DEVICE_WACOM(0x38) },
  3074. { USB_DEVICE_WACOM(0x39) },
  3075. { USB_DEVICE_WACOM(0x3F) },
  3076. { USB_DEVICE_WACOM(0x41) },
  3077. { USB_DEVICE_WACOM(0x42) },
  3078. { USB_DEVICE_WACOM(0x43) },
  3079. { USB_DEVICE_WACOM(0x44) },
  3080. { USB_DEVICE_WACOM(0x45) },
  3081. { USB_DEVICE_WACOM(0x47) },
  3082. { USB_DEVICE_WACOM(0x57) },
  3083. { USB_DEVICE_WACOM(0x59) },
  3084. { USB_DEVICE_WACOM(0x5B) },
  3085. { USB_DEVICE_WACOM(0x5D) },
  3086. { USB_DEVICE_WACOM(0x5E) },
  3087. { USB_DEVICE_WACOM(0x60) },
  3088. { USB_DEVICE_WACOM(0x61) },
  3089. { USB_DEVICE_WACOM(0x62) },
  3090. { USB_DEVICE_WACOM(0x63) },
  3091. { USB_DEVICE_WACOM(0x64) },
  3092. { USB_DEVICE_WACOM(0x65) },
  3093. { USB_DEVICE_WACOM(0x69) },
  3094. { USB_DEVICE_WACOM(0x6A) },
  3095. { USB_DEVICE_WACOM(0x6B) },
  3096. { BT_DEVICE_WACOM(0x81) },
  3097. { USB_DEVICE_WACOM(0x84) },
  3098. { USB_DEVICE_WACOM(0x90) },
  3099. { USB_DEVICE_WACOM(0x93) },
  3100. { USB_DEVICE_WACOM(0x97) },
  3101. { USB_DEVICE_WACOM(0x9A) },
  3102. { USB_DEVICE_WACOM(0x9F) },
  3103. { USB_DEVICE_WACOM(0xB0) },
  3104. { USB_DEVICE_WACOM(0xB1) },
  3105. { USB_DEVICE_WACOM(0xB2) },
  3106. { USB_DEVICE_WACOM(0xB3) },
  3107. { USB_DEVICE_WACOM(0xB4) },
  3108. { USB_DEVICE_WACOM(0xB5) },
  3109. { USB_DEVICE_WACOM(0xB7) },
  3110. { USB_DEVICE_WACOM(0xB8) },
  3111. { USB_DEVICE_WACOM(0xB9) },
  3112. { USB_DEVICE_WACOM(0xBA) },
  3113. { USB_DEVICE_WACOM(0xBB) },
  3114. { USB_DEVICE_WACOM(0xBC) },
  3115. { BT_DEVICE_WACOM(0xBD) },
  3116. { USB_DEVICE_WACOM(0xC0) },
  3117. { USB_DEVICE_WACOM(0xC2) },
  3118. { USB_DEVICE_WACOM(0xC4) },
  3119. { USB_DEVICE_WACOM(0xC5) },
  3120. { USB_DEVICE_WACOM(0xC6) },
  3121. { USB_DEVICE_WACOM(0xC7) },
  3122. { USB_DEVICE_WACOM(0xCC) },
  3123. { USB_DEVICE_WACOM(0xCE) },
  3124. { USB_DEVICE_WACOM(0xD0) },
  3125. { USB_DEVICE_WACOM(0xD1) },
  3126. { USB_DEVICE_WACOM(0xD2) },
  3127. { USB_DEVICE_WACOM(0xD3) },
  3128. { USB_DEVICE_WACOM(0xD4) },
  3129. { USB_DEVICE_WACOM(0xD5) },
  3130. { USB_DEVICE_WACOM(0xD6) },
  3131. { USB_DEVICE_WACOM(0xD7) },
  3132. { USB_DEVICE_WACOM(0xD8) },
  3133. { USB_DEVICE_WACOM(0xDA) },
  3134. { USB_DEVICE_WACOM(0xDB) },
  3135. { USB_DEVICE_WACOM(0xDD) },
  3136. { USB_DEVICE_WACOM(0xDE) },
  3137. { USB_DEVICE_WACOM(0xDF) },
  3138. { USB_DEVICE_WACOM(0xE2) },
  3139. { USB_DEVICE_WACOM(0xE3) },
  3140. { USB_DEVICE_WACOM(0xE5) },
  3141. { USB_DEVICE_WACOM(0xE6) },
  3142. { USB_DEVICE_WACOM(0xEC) },
  3143. { USB_DEVICE_WACOM(0xED) },
  3144. { USB_DEVICE_WACOM(0xEF) },
  3145. { USB_DEVICE_WACOM(0xF0) },
  3146. { USB_DEVICE_WACOM(0xF4) },
  3147. { USB_DEVICE_WACOM(0xF6) },
  3148. { USB_DEVICE_WACOM(0xF8) },
  3149. { USB_DEVICE_WACOM(0xFA) },
  3150. { USB_DEVICE_WACOM(0xFB) },
  3151. { USB_DEVICE_WACOM(0x100) },
  3152. { USB_DEVICE_WACOM(0x101) },
  3153. { USB_DEVICE_WACOM(0x10D) },
  3154. { USB_DEVICE_WACOM(0x10E) },
  3155. { USB_DEVICE_WACOM(0x10F) },
  3156. { USB_DEVICE_WACOM(0x116) },
  3157. { USB_DEVICE_WACOM(0x12C) },
  3158. { USB_DEVICE_WACOM(0x300) },
  3159. { USB_DEVICE_WACOM(0x301) },
  3160. { USB_DEVICE_WACOM(0x302) },
  3161. { USB_DEVICE_WACOM(0x303) },
  3162. { USB_DEVICE_WACOM(0x304) },
  3163. { USB_DEVICE_WACOM(0x307) },
  3164. { USB_DEVICE_WACOM(0x309) },
  3165. { USB_DEVICE_WACOM(0x30A) },
  3166. { USB_DEVICE_WACOM(0x30C) },
  3167. { USB_DEVICE_WACOM(0x30E) },
  3168. { USB_DEVICE_WACOM(0x314) },
  3169. { USB_DEVICE_WACOM(0x315) },
  3170. { USB_DEVICE_WACOM(0x317) },
  3171. { USB_DEVICE_WACOM(0x318) },
  3172. { USB_DEVICE_WACOM(0x319) },
  3173. { USB_DEVICE_WACOM(0x323) },
  3174. { USB_DEVICE_WACOM(0x325) },
  3175. { USB_DEVICE_WACOM(0x326) },
  3176. { USB_DEVICE_WACOM(0x32A) },
  3177. { USB_DEVICE_WACOM(0x32B) },
  3178. { USB_DEVICE_WACOM(0x32C) },
  3179. { USB_DEVICE_WACOM(0x32F) },
  3180. { USB_DEVICE_WACOM(0x331) },
  3181. { USB_DEVICE_WACOM(0x333) },
  3182. { USB_DEVICE_WACOM(0x335) },
  3183. { USB_DEVICE_WACOM(0x336) },
  3184. { USB_DEVICE_WACOM(0x33B) },
  3185. { USB_DEVICE_WACOM(0x33C) },
  3186. { USB_DEVICE_WACOM(0x33D) },
  3187. { USB_DEVICE_WACOM(0x33E) },
  3188. { USB_DEVICE_WACOM(0x343) },
  3189. { USB_DEVICE_WACOM(0x4001) },
  3190. { USB_DEVICE_WACOM(0x4004) },
  3191. { USB_DEVICE_WACOM(0x5000) },
  3192. { USB_DEVICE_WACOM(0x5002) },
  3193. { USB_DEVICE_LENOVO(0x6004) },
  3194. { USB_DEVICE_WACOM(HID_ANY_ID) },
  3195. { I2C_DEVICE_WACOM(HID_ANY_ID) },
  3196. { }
  3197. };
  3198. MODULE_DEVICE_TABLE(hid, wacom_ids);