wacom_wac.c 115 KB

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