wacom_wac.c 153 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * drivers/input/tablet/wacom_wac.c
  4. *
  5. * USB Wacom tablet support - Wacom specific code
  6. */
  7. /*
  8. */
  9. #include "wacom_wac.h"
  10. #include "wacom.h"
  11. #include <linux/input/mt.h>
  12. /* resolution for penabled devices */
  13. #define WACOM_PL_RES 20
  14. #define WACOM_PENPRTN_RES 40
  15. #define WACOM_VOLITO_RES 50
  16. #define WACOM_GRAPHIRE_RES 80
  17. #define WACOM_INTUOS_RES 100
  18. #define WACOM_INTUOS3_RES 200
  19. /* Newer Cintiq and DTU have an offset between tablet and screen areas */
  20. #define WACOM_DTU_OFFSET 200
  21. #define WACOM_CINTIQ_OFFSET 400
  22. /*
  23. * Scale factor relating reported contact size to logical contact area.
  24. * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
  25. */
  26. #define WACOM_CONTACT_AREA_SCALE 2607
  27. static bool touch_arbitration = 1;
  28. module_param(touch_arbitration, bool, 0644);
  29. MODULE_PARM_DESC(touch_arbitration, " on (Y) off (N)");
  30. static void wacom_report_numbered_buttons(struct input_dev *input_dev,
  31. int button_count, int mask);
  32. static int wacom_numbered_button_to_key(int n);
  33. static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
  34. int group);
  35. /*
  36. * Percent of battery capacity for Graphire.
  37. * 8th value means AC online and show 100% capacity.
  38. */
  39. static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
  40. /*
  41. * Percent of battery capacity for Intuos4 WL, AC has a separate bit.
  42. */
  43. static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
  44. static void __wacom_notify_battery(struct wacom_battery *battery,
  45. int bat_status, int bat_capacity,
  46. bool bat_charging, bool bat_connected,
  47. bool ps_connected)
  48. {
  49. bool changed = battery->bat_status != bat_status ||
  50. battery->battery_capacity != bat_capacity ||
  51. battery->bat_charging != bat_charging ||
  52. battery->bat_connected != bat_connected ||
  53. battery->ps_connected != ps_connected;
  54. if (changed) {
  55. battery->bat_status = bat_status;
  56. battery->battery_capacity = bat_capacity;
  57. battery->bat_charging = bat_charging;
  58. battery->bat_connected = bat_connected;
  59. battery->ps_connected = ps_connected;
  60. if (battery->battery)
  61. power_supply_changed(battery->battery);
  62. }
  63. }
  64. static void wacom_notify_battery(struct wacom_wac *wacom_wac,
  65. int bat_status, int bat_capacity, bool bat_charging,
  66. bool bat_connected, bool ps_connected)
  67. {
  68. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  69. __wacom_notify_battery(&wacom->battery, bat_status, bat_capacity,
  70. bat_charging, bat_connected, ps_connected);
  71. }
  72. static int wacom_penpartner_irq(struct wacom_wac *wacom)
  73. {
  74. unsigned char *data = wacom->data;
  75. struct input_dev *input = wacom->pen_input;
  76. switch (data[0]) {
  77. case 1:
  78. if (data[5] & 0x80) {
  79. wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  80. wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
  81. input_report_key(input, wacom->tool[0], 1);
  82. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  83. input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
  84. input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
  85. input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
  86. input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
  87. input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
  88. } else {
  89. input_report_key(input, wacom->tool[0], 0);
  90. input_report_abs(input, ABS_MISC, 0); /* report tool id */
  91. input_report_abs(input, ABS_PRESSURE, -1);
  92. input_report_key(input, BTN_TOUCH, 0);
  93. }
  94. break;
  95. case 2:
  96. input_report_key(input, BTN_TOOL_PEN, 1);
  97. input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
  98. input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
  99. input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
  100. input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
  101. input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
  102. input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
  103. break;
  104. default:
  105. dev_dbg(input->dev.parent,
  106. "%s: received unknown report #%d\n", __func__, data[0]);
  107. return 0;
  108. }
  109. return 1;
  110. }
  111. static int wacom_pl_irq(struct wacom_wac *wacom)
  112. {
  113. struct wacom_features *features = &wacom->features;
  114. unsigned char *data = wacom->data;
  115. struct input_dev *input = wacom->pen_input;
  116. int prox, pressure;
  117. if (data[0] != WACOM_REPORT_PENABLED) {
  118. dev_dbg(input->dev.parent,
  119. "%s: received unknown report #%d\n", __func__, data[0]);
  120. return 0;
  121. }
  122. prox = data[1] & 0x40;
  123. if (!wacom->id[0]) {
  124. if ((data[0] & 0x10) || (data[4] & 0x20)) {
  125. wacom->tool[0] = BTN_TOOL_RUBBER;
  126. wacom->id[0] = ERASER_DEVICE_ID;
  127. }
  128. else {
  129. wacom->tool[0] = BTN_TOOL_PEN;
  130. wacom->id[0] = STYLUS_DEVICE_ID;
  131. }
  132. }
  133. /* If the eraser is in prox, STYLUS2 is always set. If we
  134. * mis-detected the type and notice that STYLUS2 isn't set
  135. * then force the eraser out of prox and let the pen in.
  136. */
  137. if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
  138. input_report_key(input, BTN_TOOL_RUBBER, 0);
  139. input_report_abs(input, ABS_MISC, 0);
  140. input_sync(input);
  141. wacom->tool[0] = BTN_TOOL_PEN;
  142. wacom->id[0] = STYLUS_DEVICE_ID;
  143. }
  144. if (prox) {
  145. pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
  146. if (features->pressure_max > 255)
  147. pressure = (pressure << 1) | ((data[4] >> 6) & 1);
  148. pressure += (features->pressure_max + 1) / 2;
  149. input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
  150. input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
  151. input_report_abs(input, ABS_PRESSURE, pressure);
  152. input_report_key(input, BTN_TOUCH, data[4] & 0x08);
  153. input_report_key(input, BTN_STYLUS, data[4] & 0x10);
  154. /* Only allow the stylus2 button to be reported for the pen tool. */
  155. input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20));
  156. }
  157. if (!prox)
  158. wacom->id[0] = 0;
  159. input_report_key(input, wacom->tool[0], prox);
  160. input_report_abs(input, ABS_MISC, wacom->id[0]);
  161. return 1;
  162. }
  163. static int wacom_ptu_irq(struct wacom_wac *wacom)
  164. {
  165. unsigned char *data = wacom->data;
  166. struct input_dev *input = wacom->pen_input;
  167. if (data[0] != WACOM_REPORT_PENABLED) {
  168. dev_dbg(input->dev.parent,
  169. "%s: received unknown report #%d\n", __func__, data[0]);
  170. return 0;
  171. }
  172. if (data[1] & 0x04) {
  173. input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
  174. input_report_key(input, BTN_TOUCH, data[1] & 0x08);
  175. wacom->id[0] = ERASER_DEVICE_ID;
  176. } else {
  177. input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
  178. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  179. wacom->id[0] = STYLUS_DEVICE_ID;
  180. }
  181. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  182. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  183. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  184. input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
  185. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  186. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  187. return 1;
  188. }
  189. static int wacom_dtu_irq(struct wacom_wac *wacom)
  190. {
  191. unsigned char *data = wacom->data;
  192. struct input_dev *input = wacom->pen_input;
  193. int prox = data[1] & 0x20;
  194. dev_dbg(input->dev.parent,
  195. "%s: received report #%d", __func__, data[0]);
  196. if (prox) {
  197. /* Going into proximity select tool */
  198. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  199. if (wacom->tool[0] == BTN_TOOL_PEN)
  200. wacom->id[0] = STYLUS_DEVICE_ID;
  201. else
  202. wacom->id[0] = ERASER_DEVICE_ID;
  203. }
  204. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  205. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  206. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  207. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  208. input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x01) << 8) | data[6]);
  209. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  210. if (!prox) /* out-prox */
  211. wacom->id[0] = 0;
  212. input_report_key(input, wacom->tool[0], prox);
  213. input_report_abs(input, ABS_MISC, wacom->id[0]);
  214. return 1;
  215. }
  216. static int wacom_dtus_irq(struct wacom_wac *wacom)
  217. {
  218. unsigned char *data = wacom->data;
  219. struct input_dev *input = wacom->pen_input;
  220. unsigned short prox, pressure = 0;
  221. if (data[0] != WACOM_REPORT_DTUS && data[0] != WACOM_REPORT_DTUSPAD) {
  222. dev_dbg(input->dev.parent,
  223. "%s: received unknown report #%d", __func__, data[0]);
  224. return 0;
  225. } else if (data[0] == WACOM_REPORT_DTUSPAD) {
  226. input = wacom->pad_input;
  227. input_report_key(input, BTN_0, (data[1] & 0x01));
  228. input_report_key(input, BTN_1, (data[1] & 0x02));
  229. input_report_key(input, BTN_2, (data[1] & 0x04));
  230. input_report_key(input, BTN_3, (data[1] & 0x08));
  231. input_report_abs(input, ABS_MISC,
  232. data[1] & 0x0f ? PAD_DEVICE_ID : 0);
  233. return 1;
  234. } else {
  235. prox = data[1] & 0x80;
  236. if (prox) {
  237. switch ((data[1] >> 3) & 3) {
  238. case 1: /* Rubber */
  239. wacom->tool[0] = BTN_TOOL_RUBBER;
  240. wacom->id[0] = ERASER_DEVICE_ID;
  241. break;
  242. case 2: /* Pen */
  243. wacom->tool[0] = BTN_TOOL_PEN;
  244. wacom->id[0] = STYLUS_DEVICE_ID;
  245. break;
  246. }
  247. }
  248. input_report_key(input, BTN_STYLUS, data[1] & 0x20);
  249. input_report_key(input, BTN_STYLUS2, data[1] & 0x40);
  250. input_report_abs(input, ABS_X, get_unaligned_be16(&data[3]));
  251. input_report_abs(input, ABS_Y, get_unaligned_be16(&data[5]));
  252. pressure = ((data[1] & 0x03) << 8) | (data[2] & 0xff);
  253. input_report_abs(input, ABS_PRESSURE, pressure);
  254. input_report_key(input, BTN_TOUCH, pressure > 10);
  255. if (!prox) /* out-prox */
  256. wacom->id[0] = 0;
  257. input_report_key(input, wacom->tool[0], prox);
  258. input_report_abs(input, ABS_MISC, wacom->id[0]);
  259. return 1;
  260. }
  261. }
  262. static int wacom_graphire_irq(struct wacom_wac *wacom)
  263. {
  264. struct wacom_features *features = &wacom->features;
  265. unsigned char *data = wacom->data;
  266. struct input_dev *input = wacom->pen_input;
  267. struct input_dev *pad_input = wacom->pad_input;
  268. int battery_capacity, ps_connected;
  269. int prox;
  270. int rw = 0;
  271. int retval = 0;
  272. if (features->type == GRAPHIRE_BT) {
  273. if (data[0] != WACOM_REPORT_PENABLED_BT) {
  274. dev_dbg(input->dev.parent,
  275. "%s: received unknown report #%d\n", __func__,
  276. data[0]);
  277. goto exit;
  278. }
  279. } else if (data[0] != WACOM_REPORT_PENABLED) {
  280. dev_dbg(input->dev.parent,
  281. "%s: received unknown report #%d\n", __func__, data[0]);
  282. goto exit;
  283. }
  284. prox = data[1] & 0x80;
  285. if (prox || wacom->id[0]) {
  286. if (prox) {
  287. switch ((data[1] >> 5) & 3) {
  288. case 0: /* Pen */
  289. wacom->tool[0] = BTN_TOOL_PEN;
  290. wacom->id[0] = STYLUS_DEVICE_ID;
  291. break;
  292. case 1: /* Rubber */
  293. wacom->tool[0] = BTN_TOOL_RUBBER;
  294. wacom->id[0] = ERASER_DEVICE_ID;
  295. break;
  296. case 2: /* Mouse with wheel */
  297. input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
  298. fallthrough;
  299. case 3: /* Mouse without wheel */
  300. wacom->tool[0] = BTN_TOOL_MOUSE;
  301. wacom->id[0] = CURSOR_DEVICE_ID;
  302. break;
  303. }
  304. }
  305. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  306. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  307. if (wacom->tool[0] != BTN_TOOL_MOUSE) {
  308. if (features->type == GRAPHIRE_BT)
  309. input_report_abs(input, ABS_PRESSURE, data[6] |
  310. (((__u16) (data[1] & 0x08)) << 5));
  311. else
  312. input_report_abs(input, ABS_PRESSURE, data[6] |
  313. ((data[7] & 0x03) << 8));
  314. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  315. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  316. input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
  317. } else {
  318. input_report_key(input, BTN_LEFT, data[1] & 0x01);
  319. input_report_key(input, BTN_RIGHT, data[1] & 0x02);
  320. if (features->type == WACOM_G4 ||
  321. features->type == WACOM_MO) {
  322. input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
  323. rw = (data[7] & 0x04) - (data[7] & 0x03);
  324. } else if (features->type == GRAPHIRE_BT) {
  325. /* Compute distance between mouse and tablet */
  326. rw = 44 - (data[6] >> 2);
  327. rw = clamp_val(rw, 0, 31);
  328. input_report_abs(input, ABS_DISTANCE, rw);
  329. if (((data[1] >> 5) & 3) == 2) {
  330. /* Mouse with wheel */
  331. input_report_key(input, BTN_MIDDLE,
  332. data[1] & 0x04);
  333. rw = (data[6] & 0x01) ? -1 :
  334. (data[6] & 0x02) ? 1 : 0;
  335. } else {
  336. rw = 0;
  337. }
  338. } else {
  339. input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
  340. rw = -(signed char)data[6];
  341. }
  342. input_report_rel(input, REL_WHEEL, rw);
  343. }
  344. if (!prox)
  345. wacom->id[0] = 0;
  346. input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
  347. input_report_key(input, wacom->tool[0], prox);
  348. input_sync(input); /* sync last event */
  349. }
  350. /* send pad data */
  351. switch (features->type) {
  352. case WACOM_G4:
  353. prox = data[7] & 0xf8;
  354. if (prox || wacom->id[1]) {
  355. wacom->id[1] = PAD_DEVICE_ID;
  356. input_report_key(pad_input, BTN_BACK, (data[7] & 0x40));
  357. input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x80));
  358. rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
  359. input_report_rel(pad_input, REL_WHEEL, rw);
  360. if (!prox)
  361. wacom->id[1] = 0;
  362. input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
  363. retval = 1;
  364. }
  365. break;
  366. case WACOM_MO:
  367. prox = (data[7] & 0xf8) || data[8];
  368. if (prox || wacom->id[1]) {
  369. wacom->id[1] = PAD_DEVICE_ID;
  370. input_report_key(pad_input, BTN_BACK, (data[7] & 0x08));
  371. input_report_key(pad_input, BTN_LEFT, (data[7] & 0x20));
  372. input_report_key(pad_input, BTN_FORWARD, (data[7] & 0x10));
  373. input_report_key(pad_input, BTN_RIGHT, (data[7] & 0x40));
  374. input_report_abs(pad_input, ABS_WHEEL, (data[8] & 0x7f));
  375. if (!prox)
  376. wacom->id[1] = 0;
  377. input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
  378. retval = 1;
  379. }
  380. break;
  381. case GRAPHIRE_BT:
  382. prox = data[7] & 0x03;
  383. if (prox || wacom->id[1]) {
  384. wacom->id[1] = PAD_DEVICE_ID;
  385. input_report_key(pad_input, BTN_0, (data[7] & 0x02));
  386. input_report_key(pad_input, BTN_1, (data[7] & 0x01));
  387. if (!prox)
  388. wacom->id[1] = 0;
  389. input_report_abs(pad_input, ABS_MISC, wacom->id[1]);
  390. retval = 1;
  391. }
  392. break;
  393. }
  394. /* Store current battery capacity and power supply state */
  395. if (features->type == GRAPHIRE_BT) {
  396. rw = (data[7] >> 2 & 0x07);
  397. battery_capacity = batcap_gr[rw];
  398. ps_connected = rw == 7;
  399. wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
  400. battery_capacity, ps_connected, 1,
  401. ps_connected);
  402. }
  403. exit:
  404. return retval;
  405. }
  406. static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
  407. {
  408. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  409. struct wacom_features *features = &wacom_wac->features;
  410. struct hid_report *r;
  411. struct hid_report_enum *re;
  412. re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
  413. if (features->type == INTUOSHT2)
  414. r = re->report_id_hash[WACOM_REPORT_INTUOSHT2_ID];
  415. else
  416. r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1];
  417. if (r) {
  418. hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
  419. }
  420. }
  421. static int wacom_intuos_pad(struct wacom_wac *wacom)
  422. {
  423. struct wacom_features *features = &wacom->features;
  424. unsigned char *data = wacom->data;
  425. struct input_dev *input = wacom->pad_input;
  426. int i;
  427. int buttons = 0, nbuttons = features->numbered_buttons;
  428. int keys = 0, nkeys = 0;
  429. int ring1 = 0, ring2 = 0;
  430. int strip1 = 0, strip2 = 0;
  431. bool prox = false;
  432. bool wrench = false, keyboard = false, mute_touch = false, menu = false,
  433. info = false;
  434. /* pad packets. Works as a second tool and is always in prox */
  435. if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
  436. data[0] == WACOM_REPORT_CINTIQPAD))
  437. return 0;
  438. if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
  439. buttons = (data[3] << 1) | (data[2] & 0x01);
  440. ring1 = data[1];
  441. } else if (features->type == DTK) {
  442. buttons = data[6];
  443. } else if (features->type == WACOM_13HD) {
  444. buttons = (data[4] << 1) | (data[3] & 0x01);
  445. } else if (features->type == WACOM_24HD) {
  446. buttons = (data[8] << 8) | data[6];
  447. ring1 = data[1];
  448. ring2 = data[2];
  449. /*
  450. * Three "buttons" are available on the 24HD which are
  451. * physically implemented as a touchstrip. Each button
  452. * is approximately 3 bits wide with a 2 bit spacing.
  453. * The raw touchstrip bits are stored at:
  454. * ((data[3] & 0x1f) << 8) | data[4])
  455. */
  456. nkeys = 3;
  457. keys = ((data[3] & 0x1C) ? 1<<2 : 0) |
  458. ((data[4] & 0xE0) ? 1<<1 : 0) |
  459. ((data[4] & 0x07) ? 1<<0 : 0);
  460. keyboard = !!(data[4] & 0xE0);
  461. info = !!(data[3] & 0x1C);
  462. if (features->oPid) {
  463. mute_touch = !!(data[4] & 0x07);
  464. if (mute_touch)
  465. wacom->shared->is_touch_on =
  466. !wacom->shared->is_touch_on;
  467. } else {
  468. wrench = !!(data[4] & 0x07);
  469. }
  470. } else if (features->type == WACOM_27QHD) {
  471. nkeys = 3;
  472. keys = data[2] & 0x07;
  473. wrench = !!(data[2] & 0x01);
  474. keyboard = !!(data[2] & 0x02);
  475. if (features->oPid) {
  476. mute_touch = !!(data[2] & 0x04);
  477. if (mute_touch)
  478. wacom->shared->is_touch_on =
  479. !wacom->shared->is_touch_on;
  480. } else {
  481. menu = !!(data[2] & 0x04);
  482. }
  483. input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
  484. input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
  485. input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
  486. } else if (features->type == CINTIQ_HYBRID) {
  487. /*
  488. * Do not send hardware buttons under Android. They
  489. * are already sent to the system through GPIO (and
  490. * have different meaning).
  491. *
  492. * d-pad right -> data[4] & 0x10
  493. * d-pad up -> data[4] & 0x20
  494. * d-pad left -> data[4] & 0x40
  495. * d-pad down -> data[4] & 0x80
  496. * d-pad center -> data[3] & 0x01
  497. */
  498. buttons = (data[4] << 1) | (data[3] & 0x01);
  499. } else if (features->type == CINTIQ_COMPANION_2) {
  500. /* d-pad right -> data[2] & 0x10
  501. * d-pad up -> data[2] & 0x20
  502. * d-pad left -> data[2] & 0x40
  503. * d-pad down -> data[2] & 0x80
  504. * d-pad center -> data[1] & 0x01
  505. */
  506. buttons = ((data[2] >> 4) << 7) |
  507. ((data[1] & 0x04) << 4) |
  508. ((data[2] & 0x0F) << 2) |
  509. (data[1] & 0x03);
  510. } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
  511. /*
  512. * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
  513. * addition to the mechanical switch. Switch data is
  514. * stored in data[4], capacitive data in data[5].
  515. *
  516. * Touch ring mode switch (data[3]) has no capacitive sensor
  517. */
  518. buttons = (data[4] << 1) | (data[3] & 0x01);
  519. ring1 = data[2];
  520. } else {
  521. if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
  522. buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) |
  523. (data[6] << 1) | (data[5] & 0x01);
  524. if (features->type == WACOM_22HD) {
  525. nkeys = 3;
  526. keys = data[9] & 0x07;
  527. info = !!(data[9] & 0x01);
  528. wrench = !!(data[9] & 0x02);
  529. }
  530. } else {
  531. buttons = ((data[6] & 0x10) << 5) |
  532. ((data[5] & 0x10) << 4) |
  533. ((data[6] & 0x0F) << 4) |
  534. (data[5] & 0x0F);
  535. }
  536. strip1 = ((data[1] & 0x1f) << 8) | data[2];
  537. strip2 = ((data[3] & 0x1f) << 8) | data[4];
  538. }
  539. prox = (buttons & ~(~0U << nbuttons)) | (keys & ~(~0U << nkeys)) |
  540. (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2;
  541. wacom_report_numbered_buttons(input, nbuttons, buttons);
  542. for (i = 0; i < nkeys; i++)
  543. input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
  544. input_report_key(input, KEY_BUTTONCONFIG, wrench);
  545. input_report_key(input, KEY_ONSCREEN_KEYBOARD, keyboard);
  546. input_report_key(input, KEY_CONTROLPANEL, menu);
  547. input_report_key(input, KEY_INFO, info);
  548. if (wacom->shared && wacom->shared->touch_input) {
  549. input_report_switch(wacom->shared->touch_input,
  550. SW_MUTE_DEVICE,
  551. !wacom->shared->is_touch_on);
  552. input_sync(wacom->shared->touch_input);
  553. }
  554. input_report_abs(input, ABS_RX, strip1);
  555. input_report_abs(input, ABS_RY, strip2);
  556. input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0);
  557. input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0);
  558. input_report_key(input, wacom->tool[1], prox ? 1 : 0);
  559. input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
  560. input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
  561. return 1;
  562. }
  563. static int wacom_intuos_id_mangle(int tool_id)
  564. {
  565. return (tool_id & ~0xFFF) << 4 | (tool_id & 0xFFF);
  566. }
  567. static int wacom_intuos_get_tool_type(int tool_id)
  568. {
  569. int tool_type;
  570. switch (tool_id) {
  571. case 0x812: /* Inking pen */
  572. case 0x801: /* Intuos3 Inking pen */
  573. case 0x12802: /* Intuos4/5 Inking Pen */
  574. case 0x012:
  575. tool_type = BTN_TOOL_PENCIL;
  576. break;
  577. case 0x822: /* Pen */
  578. case 0x842:
  579. case 0x852:
  580. case 0x823: /* Intuos3 Grip Pen */
  581. case 0x813: /* Intuos3 Classic Pen */
  582. case 0x885: /* Intuos3 Marker Pen */
  583. case 0x802: /* Intuos4/5 13HD/24HD General Pen */
  584. case 0x804: /* Intuos4/5 13HD/24HD Marker Pen */
  585. case 0x8e2: /* IntuosHT2 pen */
  586. case 0x022:
  587. case 0x10804: /* Intuos4/5 13HD/24HD Art Pen */
  588. case 0x10842: /* MobileStudio Pro Pro Pen slim */
  589. case 0x14802: /* Intuos4/5 13HD/24HD Classic Pen */
  590. case 0x16802: /* Cintiq 13HD Pro Pen */
  591. case 0x18802: /* DTH2242 Pen */
  592. case 0x10802: /* Intuos4/5 13HD/24HD General Pen */
  593. tool_type = BTN_TOOL_PEN;
  594. break;
  595. case 0x832: /* Stroke pen */
  596. case 0x032:
  597. tool_type = BTN_TOOL_BRUSH;
  598. break;
  599. case 0x007: /* Mouse 4D and 2D */
  600. case 0x09c:
  601. case 0x094:
  602. case 0x017: /* Intuos3 2D Mouse */
  603. case 0x806: /* Intuos4 Mouse */
  604. tool_type = BTN_TOOL_MOUSE;
  605. break;
  606. case 0x096: /* Lens cursor */
  607. case 0x097: /* Intuos3 Lens cursor */
  608. case 0x006: /* Intuos4 Lens cursor */
  609. tool_type = BTN_TOOL_LENS;
  610. break;
  611. case 0x82a: /* Eraser */
  612. case 0x84a:
  613. case 0x85a:
  614. case 0x91a:
  615. case 0xd1a:
  616. case 0x0fa:
  617. case 0x82b: /* Intuos3 Grip Pen Eraser */
  618. case 0x81b: /* Intuos3 Classic Pen Eraser */
  619. case 0x91b: /* Intuos3 Airbrush Eraser */
  620. case 0x80c: /* Intuos4/5 13HD/24HD Marker Pen Eraser */
  621. case 0x80a: /* Intuos4/5 13HD/24HD General Pen Eraser */
  622. case 0x90a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
  623. case 0x1480a: /* Intuos4/5 13HD/24HD Classic Pen Eraser */
  624. case 0x1090a: /* Intuos4/5 13HD/24HD Airbrush Eraser */
  625. case 0x1080c: /* Intuos4/5 13HD/24HD Art Pen Eraser */
  626. case 0x1084a: /* MobileStudio Pro Pro Pen slim Eraser */
  627. case 0x1680a: /* Cintiq 13HD Pro Pen Eraser */
  628. case 0x1880a: /* DTH2242 Eraser */
  629. case 0x1080a: /* Intuos4/5 13HD/24HD General Pen Eraser */
  630. tool_type = BTN_TOOL_RUBBER;
  631. break;
  632. case 0xd12:
  633. case 0x912:
  634. case 0x112:
  635. case 0x913: /* Intuos3 Airbrush */
  636. case 0x902: /* Intuos4/5 13HD/24HD Airbrush */
  637. case 0x10902: /* Intuos4/5 13HD/24HD Airbrush */
  638. tool_type = BTN_TOOL_AIRBRUSH;
  639. break;
  640. default: /* Unknown tool */
  641. tool_type = BTN_TOOL_PEN;
  642. break;
  643. }
  644. return tool_type;
  645. }
  646. static void wacom_exit_report(struct wacom_wac *wacom)
  647. {
  648. struct input_dev *input = wacom->pen_input;
  649. struct wacom_features *features = &wacom->features;
  650. unsigned char *data = wacom->data;
  651. int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
  652. /*
  653. * Reset all states otherwise we lose the initial states
  654. * when in-prox next time
  655. */
  656. input_report_abs(input, ABS_X, 0);
  657. input_report_abs(input, ABS_Y, 0);
  658. input_report_abs(input, ABS_DISTANCE, 0);
  659. input_report_abs(input, ABS_TILT_X, 0);
  660. input_report_abs(input, ABS_TILT_Y, 0);
  661. if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
  662. input_report_key(input, BTN_LEFT, 0);
  663. input_report_key(input, BTN_MIDDLE, 0);
  664. input_report_key(input, BTN_RIGHT, 0);
  665. input_report_key(input, BTN_SIDE, 0);
  666. input_report_key(input, BTN_EXTRA, 0);
  667. input_report_abs(input, ABS_THROTTLE, 0);
  668. input_report_abs(input, ABS_RZ, 0);
  669. } else {
  670. input_report_abs(input, ABS_PRESSURE, 0);
  671. input_report_key(input, BTN_STYLUS, 0);
  672. input_report_key(input, BTN_STYLUS2, 0);
  673. input_report_key(input, BTN_TOUCH, 0);
  674. input_report_abs(input, ABS_WHEEL, 0);
  675. if (features->type >= INTUOS3S)
  676. input_report_abs(input, ABS_Z, 0);
  677. }
  678. input_report_key(input, wacom->tool[idx], 0);
  679. input_report_abs(input, ABS_MISC, 0); /* reset tool id */
  680. input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  681. wacom->id[idx] = 0;
  682. }
  683. static int wacom_intuos_inout(struct wacom_wac *wacom)
  684. {
  685. struct wacom_features *features = &wacom->features;
  686. unsigned char *data = wacom->data;
  687. struct input_dev *input = wacom->pen_input;
  688. int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
  689. if (!(((data[1] & 0xfc) == 0xc0) || /* in prox */
  690. ((data[1] & 0xfe) == 0x20) || /* in range */
  691. ((data[1] & 0xfe) == 0x80))) /* out prox */
  692. return 0;
  693. /* Enter report */
  694. if ((data[1] & 0xfc) == 0xc0) {
  695. /* serial number of the tool */
  696. wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
  697. (data[4] << 20) + (data[5] << 12) +
  698. (data[6] << 4) + (data[7] >> 4);
  699. wacom->id[idx] = (data[2] << 4) | (data[3] >> 4) |
  700. ((data[7] & 0x0f) << 16) | ((data[8] & 0xf0) << 8);
  701. wacom->tool[idx] = wacom_intuos_get_tool_type(wacom->id[idx]);
  702. wacom->shared->stylus_in_proximity = true;
  703. return 1;
  704. }
  705. /* in Range */
  706. if ((data[1] & 0xfe) == 0x20) {
  707. if (features->type != INTUOSHT2)
  708. wacom->shared->stylus_in_proximity = true;
  709. /* in Range while exiting */
  710. if (wacom->reporting_data) {
  711. input_report_key(input, BTN_TOUCH, 0);
  712. input_report_abs(input, ABS_PRESSURE, 0);
  713. input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
  714. return 2;
  715. }
  716. return 1;
  717. }
  718. /* Exit report */
  719. if ((data[1] & 0xfe) == 0x80) {
  720. wacom->shared->stylus_in_proximity = false;
  721. wacom->reporting_data = false;
  722. /* don't report exit if we don't know the ID */
  723. if (!wacom->id[idx])
  724. return 1;
  725. wacom_exit_report(wacom);
  726. return 2;
  727. }
  728. return 0;
  729. }
  730. static inline bool report_touch_events(struct wacom_wac *wacom)
  731. {
  732. return (touch_arbitration ? !wacom->shared->stylus_in_proximity : 1);
  733. }
  734. static inline bool delay_pen_events(struct wacom_wac *wacom)
  735. {
  736. return (wacom->shared->touch_down && touch_arbitration);
  737. }
  738. static int wacom_intuos_general(struct wacom_wac *wacom)
  739. {
  740. struct wacom_features *features = &wacom->features;
  741. unsigned char *data = wacom->data;
  742. struct input_dev *input = wacom->pen_input;
  743. int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
  744. unsigned char type = (data[1] >> 1) & 0x0F;
  745. unsigned int x, y, distance, t;
  746. if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
  747. data[0] != WACOM_REPORT_INTUOS_PEN)
  748. return 0;
  749. if (delay_pen_events(wacom))
  750. return 1;
  751. /* don't report events if we don't know the tool ID */
  752. if (!wacom->id[idx]) {
  753. /* but reschedule a read of the current tool */
  754. wacom_intuos_schedule_prox_event(wacom);
  755. return 1;
  756. }
  757. /*
  758. * don't report events for invalid data
  759. */
  760. /* older I4 styli don't work with new Cintiqs */
  761. if ((!((wacom->id[idx] >> 16) & 0x01) &&
  762. (features->type == WACOM_21UX2)) ||
  763. /* Only large Intuos support Lense Cursor */
  764. (wacom->tool[idx] == BTN_TOOL_LENS &&
  765. (features->type == INTUOS3 ||
  766. features->type == INTUOS3S ||
  767. features->type == INTUOS4 ||
  768. features->type == INTUOS4S ||
  769. features->type == INTUOS5 ||
  770. features->type == INTUOS5S ||
  771. features->type == INTUOSPM ||
  772. features->type == INTUOSPS)) ||
  773. /* Cintiq doesn't send data when RDY bit isn't set */
  774. (features->type == CINTIQ && !(data[1] & 0x40)))
  775. return 1;
  776. x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
  777. y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
  778. distance = data[9] >> 2;
  779. if (features->type < INTUOS3S) {
  780. x >>= 1;
  781. y >>= 1;
  782. distance >>= 1;
  783. }
  784. if (features->type == INTUOSHT2)
  785. distance = features->distance_max - distance;
  786. input_report_abs(input, ABS_X, x);
  787. input_report_abs(input, ABS_Y, y);
  788. input_report_abs(input, ABS_DISTANCE, distance);
  789. switch (type) {
  790. case 0x00:
  791. case 0x01:
  792. case 0x02:
  793. case 0x03:
  794. /* general pen packet */
  795. t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
  796. if (features->pressure_max < 2047)
  797. t >>= 1;
  798. input_report_abs(input, ABS_PRESSURE, t);
  799. if (features->type != INTUOSHT2) {
  800. input_report_abs(input, ABS_TILT_X,
  801. (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
  802. input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
  803. }
  804. input_report_key(input, BTN_STYLUS, data[1] & 2);
  805. input_report_key(input, BTN_STYLUS2, data[1] & 4);
  806. input_report_key(input, BTN_TOUCH, t > 10);
  807. break;
  808. case 0x0a:
  809. /* airbrush second packet */
  810. input_report_abs(input, ABS_WHEEL,
  811. (data[6] << 2) | ((data[7] >> 6) & 3));
  812. input_report_abs(input, ABS_TILT_X,
  813. (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
  814. input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
  815. break;
  816. case 0x05:
  817. /* Rotation packet */
  818. if (features->type >= INTUOS3S) {
  819. /* I3 marker pen rotation */
  820. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  821. t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
  822. ((t-1) / 2 + 450)) : (450 - t / 2) ;
  823. input_report_abs(input, ABS_Z, t);
  824. } else {
  825. /* 4D mouse 2nd packet */
  826. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  827. input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
  828. ((t - 1) / 2) : -t / 2);
  829. }
  830. break;
  831. case 0x04:
  832. /* 4D mouse 1st packet */
  833. input_report_key(input, BTN_LEFT, data[8] & 0x01);
  834. input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
  835. input_report_key(input, BTN_RIGHT, data[8] & 0x04);
  836. input_report_key(input, BTN_SIDE, data[8] & 0x20);
  837. input_report_key(input, BTN_EXTRA, data[8] & 0x10);
  838. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  839. input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
  840. break;
  841. case 0x06:
  842. /* I4 mouse */
  843. input_report_key(input, BTN_LEFT, data[6] & 0x01);
  844. input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
  845. input_report_key(input, BTN_RIGHT, data[6] & 0x04);
  846. input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
  847. - ((data[7] & 0x40) >> 6));
  848. input_report_key(input, BTN_SIDE, data[6] & 0x08);
  849. input_report_key(input, BTN_EXTRA, data[6] & 0x10);
  850. input_report_abs(input, ABS_TILT_X,
  851. (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
  852. input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
  853. break;
  854. case 0x08:
  855. if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
  856. /* 2D mouse packet */
  857. input_report_key(input, BTN_LEFT, data[8] & 0x04);
  858. input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
  859. input_report_key(input, BTN_RIGHT, data[8] & 0x10);
  860. input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
  861. - ((data[8] & 0x02) >> 1));
  862. /* I3 2D mouse side buttons */
  863. if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
  864. input_report_key(input, BTN_SIDE, data[8] & 0x40);
  865. input_report_key(input, BTN_EXTRA, data[8] & 0x20);
  866. }
  867. }
  868. else if (wacom->tool[idx] == BTN_TOOL_LENS) {
  869. /* Lens cursor packets */
  870. input_report_key(input, BTN_LEFT, data[8] & 0x01);
  871. input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
  872. input_report_key(input, BTN_RIGHT, data[8] & 0x04);
  873. input_report_key(input, BTN_SIDE, data[8] & 0x10);
  874. input_report_key(input, BTN_EXTRA, data[8] & 0x08);
  875. }
  876. break;
  877. case 0x07:
  878. case 0x09:
  879. case 0x0b:
  880. case 0x0c:
  881. case 0x0d:
  882. case 0x0e:
  883. case 0x0f:
  884. /* unhandled */
  885. break;
  886. }
  887. input_report_abs(input, ABS_MISC,
  888. wacom_intuos_id_mangle(wacom->id[idx])); /* report tool id */
  889. input_report_key(input, wacom->tool[idx], 1);
  890. input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  891. wacom->reporting_data = true;
  892. return 2;
  893. }
  894. static int wacom_intuos_irq(struct wacom_wac *wacom)
  895. {
  896. unsigned char *data = wacom->data;
  897. struct input_dev *input = wacom->pen_input;
  898. int result;
  899. if (data[0] != WACOM_REPORT_PENABLED &&
  900. data[0] != WACOM_REPORT_INTUOS_ID1 &&
  901. data[0] != WACOM_REPORT_INTUOS_ID2 &&
  902. data[0] != WACOM_REPORT_INTUOSPAD &&
  903. data[0] != WACOM_REPORT_INTUOS_PEN &&
  904. data[0] != WACOM_REPORT_CINTIQ &&
  905. data[0] != WACOM_REPORT_CINTIQPAD &&
  906. data[0] != WACOM_REPORT_INTUOS5PAD) {
  907. dev_dbg(input->dev.parent,
  908. "%s: received unknown report #%d\n", __func__, data[0]);
  909. return 0;
  910. }
  911. /* process pad events */
  912. result = wacom_intuos_pad(wacom);
  913. if (result)
  914. return result;
  915. /* process in/out prox events */
  916. result = wacom_intuos_inout(wacom);
  917. if (result)
  918. return result - 1;
  919. /* process general packets */
  920. result = wacom_intuos_general(wacom);
  921. if (result)
  922. return result - 1;
  923. return 0;
  924. }
  925. static int wacom_remote_irq(struct wacom_wac *wacom_wac, size_t len)
  926. {
  927. unsigned char *data = wacom_wac->data;
  928. struct input_dev *input;
  929. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  930. struct wacom_remote *remote = wacom->remote;
  931. int bat_charging, bat_percent, touch_ring_mode;
  932. __u32 serial;
  933. int i, index = -1;
  934. unsigned long flags;
  935. if (data[0] != WACOM_REPORT_REMOTE) {
  936. hid_dbg(wacom->hdev, "%s: received unknown report #%d",
  937. __func__, data[0]);
  938. return 0;
  939. }
  940. serial = data[3] + (data[4] << 8) + (data[5] << 16);
  941. wacom_wac->id[0] = PAD_DEVICE_ID;
  942. spin_lock_irqsave(&remote->remote_lock, flags);
  943. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  944. if (remote->remotes[i].serial == serial) {
  945. index = i;
  946. break;
  947. }
  948. }
  949. if (index < 0 || !remote->remotes[index].registered)
  950. goto out;
  951. input = remote->remotes[index].input;
  952. input_report_key(input, BTN_0, (data[9] & 0x01));
  953. input_report_key(input, BTN_1, (data[9] & 0x02));
  954. input_report_key(input, BTN_2, (data[9] & 0x04));
  955. input_report_key(input, BTN_3, (data[9] & 0x08));
  956. input_report_key(input, BTN_4, (data[9] & 0x10));
  957. input_report_key(input, BTN_5, (data[9] & 0x20));
  958. input_report_key(input, BTN_6, (data[9] & 0x40));
  959. input_report_key(input, BTN_7, (data[9] & 0x80));
  960. input_report_key(input, BTN_8, (data[10] & 0x01));
  961. input_report_key(input, BTN_9, (data[10] & 0x02));
  962. input_report_key(input, BTN_A, (data[10] & 0x04));
  963. input_report_key(input, BTN_B, (data[10] & 0x08));
  964. input_report_key(input, BTN_C, (data[10] & 0x10));
  965. input_report_key(input, BTN_X, (data[10] & 0x20));
  966. input_report_key(input, BTN_Y, (data[10] & 0x40));
  967. input_report_key(input, BTN_Z, (data[10] & 0x80));
  968. input_report_key(input, BTN_BASE, (data[11] & 0x01));
  969. input_report_key(input, BTN_BASE2, (data[11] & 0x02));
  970. if (data[12] & 0x80)
  971. input_report_abs(input, ABS_WHEEL, (data[12] & 0x7f) - 1);
  972. else
  973. input_report_abs(input, ABS_WHEEL, 0);
  974. bat_percent = data[7] & 0x7f;
  975. bat_charging = !!(data[7] & 0x80);
  976. if (data[9] | data[10] | (data[11] & 0x03) | data[12])
  977. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  978. else
  979. input_report_abs(input, ABS_MISC, 0);
  980. input_event(input, EV_MSC, MSC_SERIAL, serial);
  981. input_sync(input);
  982. /*Which mode select (LED light) is currently on?*/
  983. touch_ring_mode = (data[11] & 0xC0) >> 6;
  984. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  985. if (remote->remotes[i].serial == serial)
  986. wacom->led.groups[i].select = touch_ring_mode;
  987. }
  988. __wacom_notify_battery(&remote->remotes[index].battery,
  989. WACOM_POWER_SUPPLY_STATUS_AUTO, bat_percent,
  990. bat_charging, 1, bat_charging);
  991. out:
  992. spin_unlock_irqrestore(&remote->remote_lock, flags);
  993. return 0;
  994. }
  995. static void wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
  996. {
  997. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  998. unsigned char *data = wacom_wac->data;
  999. struct wacom_remote *remote = wacom->remote;
  1000. struct wacom_remote_data remote_data;
  1001. unsigned long flags;
  1002. int i, ret;
  1003. if (data[0] != WACOM_REPORT_DEVICE_LIST)
  1004. return;
  1005. memset(&remote_data, 0, sizeof(struct wacom_remote_data));
  1006. for (i = 0; i < WACOM_MAX_REMOTES; i++) {
  1007. int j = i * 6;
  1008. int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4];
  1009. bool connected = data[j+2];
  1010. remote_data.remote[i].serial = serial;
  1011. remote_data.remote[i].connected = connected;
  1012. }
  1013. spin_lock_irqsave(&remote->remote_lock, flags);
  1014. ret = kfifo_in(&remote->remote_fifo, &remote_data, sizeof(remote_data));
  1015. if (ret != sizeof(remote_data)) {
  1016. spin_unlock_irqrestore(&remote->remote_lock, flags);
  1017. hid_err(wacom->hdev, "Can't queue Remote status event.\n");
  1018. return;
  1019. }
  1020. spin_unlock_irqrestore(&remote->remote_lock, flags);
  1021. wacom_schedule_work(wacom_wac, WACOM_WORKER_REMOTE);
  1022. }
  1023. static int int_dist(int x1, int y1, int x2, int y2)
  1024. {
  1025. int x = x2 - x1;
  1026. int y = y2 - y1;
  1027. return int_sqrt(x*x + y*y);
  1028. }
  1029. static void wacom_intuos_bt_process_data(struct wacom_wac *wacom,
  1030. unsigned char *data)
  1031. {
  1032. memcpy(wacom->data, data, 10);
  1033. wacom_intuos_irq(wacom);
  1034. input_sync(wacom->pen_input);
  1035. if (wacom->pad_input)
  1036. input_sync(wacom->pad_input);
  1037. }
  1038. static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
  1039. {
  1040. unsigned char data[WACOM_PKGLEN_MAX];
  1041. int i = 1;
  1042. unsigned power_raw, battery_capacity, bat_charging, ps_connected;
  1043. memcpy(data, wacom->data, len);
  1044. switch (data[0]) {
  1045. case 0x04:
  1046. wacom_intuos_bt_process_data(wacom, data + i);
  1047. i += 10;
  1048. fallthrough;
  1049. case 0x03:
  1050. wacom_intuos_bt_process_data(wacom, data + i);
  1051. i += 10;
  1052. wacom_intuos_bt_process_data(wacom, data + i);
  1053. i += 10;
  1054. power_raw = data[i];
  1055. bat_charging = (power_raw & 0x08) ? 1 : 0;
  1056. ps_connected = (power_raw & 0x10) ? 1 : 0;
  1057. battery_capacity = batcap_i4[power_raw & 0x07];
  1058. wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
  1059. battery_capacity, bat_charging,
  1060. battery_capacity || bat_charging,
  1061. ps_connected);
  1062. break;
  1063. default:
  1064. dev_dbg(wacom->pen_input->dev.parent,
  1065. "Unknown report: %d,%d size:%zu\n",
  1066. data[0], data[1], len);
  1067. return 0;
  1068. }
  1069. return 0;
  1070. }
  1071. static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
  1072. {
  1073. struct input_dev *input = wacom->touch_input;
  1074. unsigned touch_max = wacom->features.touch_max;
  1075. int count = 0;
  1076. int i;
  1077. if (!touch_max)
  1078. return 0;
  1079. if (touch_max == 1)
  1080. return test_bit(BTN_TOUCH, input->key) &&
  1081. report_touch_events(wacom);
  1082. for (i = 0; i < input->mt->num_slots; i++) {
  1083. struct input_mt_slot *ps = &input->mt->slots[i];
  1084. int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
  1085. if (id >= 0)
  1086. count++;
  1087. }
  1088. return count;
  1089. }
  1090. static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
  1091. {
  1092. int pen_frame_len, pen_frames;
  1093. struct input_dev *pen_input = wacom->pen_input;
  1094. unsigned char *data = wacom->data;
  1095. int i;
  1096. if (wacom->features.type == INTUOSP2_BT ||
  1097. wacom->features.type == INTUOSP2S_BT) {
  1098. wacom->serial[0] = get_unaligned_le64(&data[99]);
  1099. wacom->id[0] = get_unaligned_le16(&data[107]);
  1100. pen_frame_len = 14;
  1101. pen_frames = 7;
  1102. } else {
  1103. wacom->serial[0] = get_unaligned_le64(&data[33]);
  1104. wacom->id[0] = get_unaligned_le16(&data[41]);
  1105. pen_frame_len = 8;
  1106. pen_frames = 4;
  1107. }
  1108. if (wacom->serial[0] >> 52 == 1) {
  1109. /* Add back in missing bits of ID for non-USI pens */
  1110. wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
  1111. }
  1112. for (i = 0; i < pen_frames; i++) {
  1113. unsigned char *frame = &data[i*pen_frame_len + 1];
  1114. bool valid = frame[0] & 0x80;
  1115. bool prox = frame[0] & 0x40;
  1116. bool range = frame[0] & 0x20;
  1117. bool invert = frame[0] & 0x10;
  1118. if (!valid)
  1119. continue;
  1120. if (!prox) {
  1121. wacom->shared->stylus_in_proximity = false;
  1122. wacom_exit_report(wacom);
  1123. input_sync(pen_input);
  1124. wacom->tool[0] = 0;
  1125. wacom->id[0] = 0;
  1126. wacom->serial[0] = 0;
  1127. return;
  1128. }
  1129. if (range) {
  1130. if (!wacom->tool[0]) { /* first in range */
  1131. /* Going into range select tool */
  1132. if (invert)
  1133. wacom->tool[0] = BTN_TOOL_RUBBER;
  1134. else if (wacom->id[0])
  1135. wacom->tool[0] = wacom_intuos_get_tool_type(wacom->id[0]);
  1136. else
  1137. wacom->tool[0] = BTN_TOOL_PEN;
  1138. }
  1139. input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1]));
  1140. input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3]));
  1141. if (wacom->features.type == INTUOSP2_BT ||
  1142. wacom->features.type == INTUOSP2S_BT) {
  1143. /* Fix rotation alignment: userspace expects zero at left */
  1144. int16_t rotation =
  1145. (int16_t)get_unaligned_le16(&frame[9]);
  1146. rotation += 1800/4;
  1147. if (rotation > 899)
  1148. rotation -= 1800;
  1149. input_report_abs(pen_input, ABS_TILT_X,
  1150. (char)frame[7]);
  1151. input_report_abs(pen_input, ABS_TILT_Y,
  1152. (char)frame[8]);
  1153. input_report_abs(pen_input, ABS_Z, rotation);
  1154. input_report_abs(pen_input, ABS_WHEEL,
  1155. get_unaligned_le16(&frame[11]));
  1156. }
  1157. }
  1158. if (wacom->tool[0]) {
  1159. input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
  1160. if (wacom->features.type == INTUOSP2_BT ||
  1161. wacom->features.type == INTUOSP2S_BT) {
  1162. input_report_abs(pen_input, ABS_DISTANCE,
  1163. range ? frame[13] : wacom->features.distance_max);
  1164. } else {
  1165. input_report_abs(pen_input, ABS_DISTANCE,
  1166. range ? frame[7] : wacom->features.distance_max);
  1167. }
  1168. input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x09);
  1169. input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02);
  1170. input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04);
  1171. input_report_key(pen_input, wacom->tool[0], prox);
  1172. input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]);
  1173. input_report_abs(pen_input, ABS_MISC,
  1174. wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */
  1175. }
  1176. wacom->shared->stylus_in_proximity = prox;
  1177. input_sync(pen_input);
  1178. }
  1179. }
  1180. static void wacom_intuos_pro2_bt_touch(struct wacom_wac *wacom)
  1181. {
  1182. const int finger_touch_len = 8;
  1183. const int finger_frames = 4;
  1184. const int finger_frame_len = 43;
  1185. struct input_dev *touch_input = wacom->touch_input;
  1186. unsigned char *data = wacom->data;
  1187. int num_contacts_left = 5;
  1188. int i, j;
  1189. for (i = 0; i < finger_frames; i++) {
  1190. unsigned char *frame = &data[i*finger_frame_len + 109];
  1191. int current_num_contacts = frame[0] & 0x7F;
  1192. int contacts_to_send;
  1193. if (!(frame[0] & 0x80))
  1194. continue;
  1195. /*
  1196. * First packet resets the counter since only the first
  1197. * packet in series will have non-zero current_num_contacts.
  1198. */
  1199. if (current_num_contacts)
  1200. wacom->num_contacts_left = current_num_contacts;
  1201. contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
  1202. for (j = 0; j < contacts_to_send; j++) {
  1203. unsigned char *touch = &frame[j*finger_touch_len + 1];
  1204. int slot = input_mt_get_slot_by_key(touch_input, touch[0]);
  1205. int x = get_unaligned_le16(&touch[2]);
  1206. int y = get_unaligned_le16(&touch[4]);
  1207. int w = touch[6] * input_abs_get_res(touch_input, ABS_MT_POSITION_X);
  1208. int h = touch[7] * input_abs_get_res(touch_input, ABS_MT_POSITION_Y);
  1209. if (slot < 0)
  1210. continue;
  1211. input_mt_slot(touch_input, slot);
  1212. input_mt_report_slot_state(touch_input, MT_TOOL_FINGER, touch[1] & 0x01);
  1213. input_report_abs(touch_input, ABS_MT_POSITION_X, x);
  1214. input_report_abs(touch_input, ABS_MT_POSITION_Y, y);
  1215. input_report_abs(touch_input, ABS_MT_TOUCH_MAJOR, max(w, h));
  1216. input_report_abs(touch_input, ABS_MT_TOUCH_MINOR, min(w, h));
  1217. input_report_abs(touch_input, ABS_MT_ORIENTATION, w > h);
  1218. }
  1219. input_mt_sync_frame(touch_input);
  1220. wacom->num_contacts_left -= contacts_to_send;
  1221. if (wacom->num_contacts_left <= 0) {
  1222. wacom->num_contacts_left = 0;
  1223. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1224. input_sync(touch_input);
  1225. }
  1226. }
  1227. if (wacom->num_contacts_left == 0) {
  1228. // Be careful that we don't accidentally call input_sync with
  1229. // only a partial set of fingers of processed
  1230. input_report_switch(touch_input, SW_MUTE_DEVICE, !(data[281] >> 7));
  1231. input_sync(touch_input);
  1232. }
  1233. }
  1234. static void wacom_intuos_pro2_bt_pad(struct wacom_wac *wacom)
  1235. {
  1236. struct input_dev *pad_input = wacom->pad_input;
  1237. unsigned char *data = wacom->data;
  1238. int nbuttons = wacom->features.numbered_buttons;
  1239. int expresskeys = data[282];
  1240. int center = (data[281] & 0x40) >> 6;
  1241. int ring = data[285] & 0x7F;
  1242. bool ringstatus = data[285] & 0x80;
  1243. bool prox = expresskeys || center || ringstatus;
  1244. /* Fix touchring data: userspace expects 0 at left and increasing clockwise */
  1245. ring = 71 - ring;
  1246. ring += 3*72/16;
  1247. if (ring > 71)
  1248. ring -= 72;
  1249. wacom_report_numbered_buttons(pad_input, nbuttons,
  1250. expresskeys | (center << (nbuttons - 1)));
  1251. input_report_abs(pad_input, ABS_WHEEL, ringstatus ? ring : 0);
  1252. input_report_key(pad_input, wacom->tool[1], prox ? 1 : 0);
  1253. input_report_abs(pad_input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
  1254. input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
  1255. input_sync(pad_input);
  1256. }
  1257. static void wacom_intuos_pro2_bt_battery(struct wacom_wac *wacom)
  1258. {
  1259. unsigned char *data = wacom->data;
  1260. bool chg = data[284] & 0x80;
  1261. int battery_status = data[284] & 0x7F;
  1262. wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
  1263. battery_status, chg, 1, chg);
  1264. }
  1265. static void wacom_intuos_gen3_bt_pad(struct wacom_wac *wacom)
  1266. {
  1267. struct input_dev *pad_input = wacom->pad_input;
  1268. unsigned char *data = wacom->data;
  1269. int buttons = data[44];
  1270. wacom_report_numbered_buttons(pad_input, 4, buttons);
  1271. input_report_key(pad_input, wacom->tool[1], buttons ? 1 : 0);
  1272. input_report_abs(pad_input, ABS_MISC, buttons ? PAD_DEVICE_ID : 0);
  1273. input_event(pad_input, EV_MSC, MSC_SERIAL, 0xffffffff);
  1274. input_sync(pad_input);
  1275. }
  1276. static void wacom_intuos_gen3_bt_battery(struct wacom_wac *wacom)
  1277. {
  1278. unsigned char *data = wacom->data;
  1279. bool chg = data[45] & 0x80;
  1280. int battery_status = data[45] & 0x7F;
  1281. wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
  1282. battery_status, chg, 1, chg);
  1283. }
  1284. static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
  1285. {
  1286. unsigned char *data = wacom->data;
  1287. if (data[0] != 0x80 && data[0] != 0x81) {
  1288. dev_dbg(wacom->pen_input->dev.parent,
  1289. "%s: received unknown report #%d\n", __func__, data[0]);
  1290. return 0;
  1291. }
  1292. wacom_intuos_pro2_bt_pen(wacom);
  1293. if (wacom->features.type == INTUOSP2_BT ||
  1294. wacom->features.type == INTUOSP2S_BT) {
  1295. wacom_intuos_pro2_bt_touch(wacom);
  1296. wacom_intuos_pro2_bt_pad(wacom);
  1297. wacom_intuos_pro2_bt_battery(wacom);
  1298. } else {
  1299. wacom_intuos_gen3_bt_pad(wacom);
  1300. wacom_intuos_gen3_bt_battery(wacom);
  1301. }
  1302. return 0;
  1303. }
  1304. static int wacom_24hdt_irq(struct wacom_wac *wacom)
  1305. {
  1306. struct input_dev *input = wacom->touch_input;
  1307. unsigned char *data = wacom->data;
  1308. int i;
  1309. int current_num_contacts = data[61];
  1310. int contacts_to_send = 0;
  1311. int num_contacts_left = 4; /* maximum contacts per packet */
  1312. int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
  1313. int y_offset = 2;
  1314. if (wacom->shared->has_mute_touch_switch &&
  1315. !wacom->shared->is_touch_on) {
  1316. if (!wacom->shared->touch_down)
  1317. return 0;
  1318. }
  1319. if (wacom->features.type == WACOM_27QHDT) {
  1320. current_num_contacts = data[63];
  1321. num_contacts_left = 10;
  1322. byte_per_packet = WACOM_BYTES_PER_QHDTHID_PACKET;
  1323. y_offset = 0;
  1324. }
  1325. /*
  1326. * First packet resets the counter since only the first
  1327. * packet in series will have non-zero current_num_contacts.
  1328. */
  1329. if (current_num_contacts)
  1330. wacom->num_contacts_left = current_num_contacts;
  1331. contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
  1332. for (i = 0; i < contacts_to_send; i++) {
  1333. int offset = (byte_per_packet * i) + 1;
  1334. bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
  1335. int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
  1336. if (slot < 0)
  1337. continue;
  1338. input_mt_slot(input, slot);
  1339. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1340. if (touch) {
  1341. int t_x = get_unaligned_le16(&data[offset + 2]);
  1342. int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]);
  1343. input_report_abs(input, ABS_MT_POSITION_X, t_x);
  1344. input_report_abs(input, ABS_MT_POSITION_Y, t_y);
  1345. if (wacom->features.type != WACOM_27QHDT) {
  1346. int c_x = get_unaligned_le16(&data[offset + 4]);
  1347. int c_y = get_unaligned_le16(&data[offset + 8]);
  1348. int w = get_unaligned_le16(&data[offset + 10]);
  1349. int h = get_unaligned_le16(&data[offset + 12]);
  1350. input_report_abs(input, ABS_MT_TOUCH_MAJOR, min(w,h));
  1351. input_report_abs(input, ABS_MT_WIDTH_MAJOR,
  1352. min(w, h) + int_dist(t_x, t_y, c_x, c_y));
  1353. input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
  1354. input_report_abs(input, ABS_MT_ORIENTATION, w > h);
  1355. }
  1356. }
  1357. }
  1358. input_mt_sync_frame(input);
  1359. wacom->num_contacts_left -= contacts_to_send;
  1360. if (wacom->num_contacts_left <= 0) {
  1361. wacom->num_contacts_left = 0;
  1362. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1363. }
  1364. return 1;
  1365. }
  1366. static int wacom_mt_touch(struct wacom_wac *wacom)
  1367. {
  1368. struct input_dev *input = wacom->touch_input;
  1369. unsigned char *data = wacom->data;
  1370. int i;
  1371. int current_num_contacts = data[2];
  1372. int contacts_to_send = 0;
  1373. int x_offset = 0;
  1374. /* MTTPC does not support Height and Width */
  1375. if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
  1376. x_offset = -4;
  1377. /*
  1378. * First packet resets the counter since only the first
  1379. * packet in series will have non-zero current_num_contacts.
  1380. */
  1381. if (current_num_contacts)
  1382. wacom->num_contacts_left = current_num_contacts;
  1383. /* There are at most 5 contacts per packet */
  1384. contacts_to_send = min(5, wacom->num_contacts_left);
  1385. for (i = 0; i < contacts_to_send; i++) {
  1386. int offset = (WACOM_BYTES_PER_MT_PACKET + x_offset) * i + 3;
  1387. bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
  1388. int id = get_unaligned_le16(&data[offset + 1]);
  1389. int slot = input_mt_get_slot_by_key(input, id);
  1390. if (slot < 0)
  1391. continue;
  1392. input_mt_slot(input, slot);
  1393. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1394. if (touch) {
  1395. int x = get_unaligned_le16(&data[offset + x_offset + 7]);
  1396. int y = get_unaligned_le16(&data[offset + x_offset + 9]);
  1397. input_report_abs(input, ABS_MT_POSITION_X, x);
  1398. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1399. }
  1400. }
  1401. input_mt_sync_frame(input);
  1402. wacom->num_contacts_left -= contacts_to_send;
  1403. if (wacom->num_contacts_left <= 0) {
  1404. wacom->num_contacts_left = 0;
  1405. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1406. }
  1407. return 1;
  1408. }
  1409. static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
  1410. {
  1411. struct input_dev *input = wacom->touch_input;
  1412. unsigned char *data = wacom->data;
  1413. int i;
  1414. for (i = 0; i < 2; i++) {
  1415. int p = data[1] & (1 << i);
  1416. bool touch = p && report_touch_events(wacom);
  1417. input_mt_slot(input, i);
  1418. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  1419. if (touch) {
  1420. int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff;
  1421. int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff;
  1422. input_report_abs(input, ABS_MT_POSITION_X, x);
  1423. input_report_abs(input, ABS_MT_POSITION_Y, y);
  1424. }
  1425. }
  1426. input_mt_sync_frame(input);
  1427. /* keep touch state for pen event */
  1428. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  1429. return 1;
  1430. }
  1431. static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
  1432. {
  1433. unsigned char *data = wacom->data;
  1434. struct input_dev *input = wacom->touch_input;
  1435. bool prox = report_touch_events(wacom);
  1436. int x = 0, y = 0;
  1437. if (wacom->features.touch_max > 1 || len > WACOM_PKGLEN_TPC2FG)
  1438. return 0;
  1439. if (len == WACOM_PKGLEN_TPC1FG) {
  1440. prox = prox && (data[0] & 0x01);
  1441. x = get_unaligned_le16(&data[1]);
  1442. y = get_unaligned_le16(&data[3]);
  1443. } else if (len == WACOM_PKGLEN_TPC1FG_B) {
  1444. prox = prox && (data[2] & 0x01);
  1445. x = get_unaligned_le16(&data[3]);
  1446. y = get_unaligned_le16(&data[5]);
  1447. } else {
  1448. prox = prox && (data[1] & 0x01);
  1449. x = le16_to_cpup((__le16 *)&data[2]);
  1450. y = le16_to_cpup((__le16 *)&data[4]);
  1451. }
  1452. if (prox) {
  1453. input_report_abs(input, ABS_X, x);
  1454. input_report_abs(input, ABS_Y, y);
  1455. }
  1456. input_report_key(input, BTN_TOUCH, prox);
  1457. /* keep touch state for pen events */
  1458. wacom->shared->touch_down = prox;
  1459. return 1;
  1460. }
  1461. static int wacom_tpc_pen(struct wacom_wac *wacom)
  1462. {
  1463. unsigned char *data = wacom->data;
  1464. struct input_dev *input = wacom->pen_input;
  1465. bool prox = data[1] & 0x20;
  1466. if (!wacom->shared->stylus_in_proximity) /* first in prox */
  1467. /* Going into proximity select tool */
  1468. wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  1469. /* keep pen state for touch events */
  1470. wacom->shared->stylus_in_proximity = prox;
  1471. /* send pen events only when touch is up or forced out
  1472. * or touch arbitration is off
  1473. */
  1474. if (!delay_pen_events(wacom)) {
  1475. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  1476. input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
  1477. input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
  1478. input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
  1479. input_report_abs(input, ABS_PRESSURE, ((data[7] & 0x07) << 8) | data[6]);
  1480. input_report_key(input, BTN_TOUCH, data[1] & 0x05);
  1481. input_report_key(input, wacom->tool[0], prox);
  1482. return 1;
  1483. }
  1484. return 0;
  1485. }
  1486. static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
  1487. {
  1488. unsigned char *data = wacom->data;
  1489. if (wacom->pen_input) {
  1490. dev_dbg(wacom->pen_input->dev.parent,
  1491. "%s: received report #%d\n", __func__, data[0]);
  1492. if (len == WACOM_PKGLEN_PENABLED ||
  1493. data[0] == WACOM_REPORT_PENABLED)
  1494. return wacom_tpc_pen(wacom);
  1495. }
  1496. else if (wacom->touch_input) {
  1497. dev_dbg(wacom->touch_input->dev.parent,
  1498. "%s: received report #%d\n", __func__, data[0]);
  1499. switch (len) {
  1500. case WACOM_PKGLEN_TPC1FG:
  1501. return wacom_tpc_single_touch(wacom, len);
  1502. case WACOM_PKGLEN_TPC2FG:
  1503. return wacom_tpc_mt_touch(wacom);
  1504. default:
  1505. switch (data[0]) {
  1506. case WACOM_REPORT_TPC1FG:
  1507. case WACOM_REPORT_TPCHID:
  1508. case WACOM_REPORT_TPCST:
  1509. case WACOM_REPORT_TPC1FGE:
  1510. return wacom_tpc_single_touch(wacom, len);
  1511. case WACOM_REPORT_TPCMT:
  1512. case WACOM_REPORT_TPCMT2:
  1513. return wacom_mt_touch(wacom);
  1514. }
  1515. }
  1516. }
  1517. return 0;
  1518. }
  1519. static int wacom_offset_rotation(struct input_dev *input, struct hid_usage *usage,
  1520. int value, int num, int denom)
  1521. {
  1522. struct input_absinfo *abs = &input->absinfo[usage->code];
  1523. int range = (abs->maximum - abs->minimum + 1);
  1524. value += num*range/denom;
  1525. if (value > abs->maximum)
  1526. value -= range;
  1527. else if (value < abs->minimum)
  1528. value += range;
  1529. return value;
  1530. }
  1531. int wacom_equivalent_usage(int usage)
  1532. {
  1533. if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) {
  1534. int subpage = (usage & 0xFF00) << 8;
  1535. int subusage = (usage & 0xFF);
  1536. if (subpage == WACOM_HID_SP_PAD ||
  1537. subpage == WACOM_HID_SP_BUTTON ||
  1538. subpage == WACOM_HID_SP_DIGITIZER ||
  1539. subpage == WACOM_HID_SP_DIGITIZERINFO ||
  1540. usage == WACOM_HID_WD_SENSE ||
  1541. usage == WACOM_HID_WD_SERIALHI ||
  1542. usage == WACOM_HID_WD_TOOLTYPE ||
  1543. usage == WACOM_HID_WD_DISTANCE ||
  1544. usage == WACOM_HID_WD_TOUCHSTRIP ||
  1545. usage == WACOM_HID_WD_TOUCHSTRIP2 ||
  1546. usage == WACOM_HID_WD_TOUCHRING ||
  1547. usage == WACOM_HID_WD_TOUCHRINGSTATUS ||
  1548. usage == WACOM_HID_WD_REPORT_VALID) {
  1549. return usage;
  1550. }
  1551. if (subpage == HID_UP_UNDEFINED)
  1552. subpage = HID_UP_DIGITIZER;
  1553. return subpage | subusage;
  1554. }
  1555. if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMTOUCH) {
  1556. int subpage = (usage & 0xFF00) << 8;
  1557. int subusage = (usage & 0xFF);
  1558. if (usage == WACOM_HID_WT_REPORT_VALID)
  1559. return usage;
  1560. if (subpage == HID_UP_UNDEFINED)
  1561. subpage = WACOM_HID_SP_DIGITIZER;
  1562. return subpage | subusage;
  1563. }
  1564. return usage;
  1565. }
  1566. static void wacom_map_usage(struct input_dev *input, struct hid_usage *usage,
  1567. struct hid_field *field, __u8 type, __u16 code, int fuzz)
  1568. {
  1569. struct wacom *wacom = input_get_drvdata(input);
  1570. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1571. struct wacom_features *features = &wacom_wac->features;
  1572. int fmin = field->logical_minimum;
  1573. int fmax = field->logical_maximum;
  1574. unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
  1575. int resolution_code = code;
  1576. if (equivalent_usage == HID_DG_TWIST) {
  1577. resolution_code = ABS_RZ;
  1578. }
  1579. if (equivalent_usage == HID_GD_X) {
  1580. fmin += features->offset_left;
  1581. fmax -= features->offset_right;
  1582. }
  1583. if (equivalent_usage == HID_GD_Y) {
  1584. fmin += features->offset_top;
  1585. fmax -= features->offset_bottom;
  1586. }
  1587. usage->type = type;
  1588. usage->code = code;
  1589. set_bit(type, input->evbit);
  1590. switch (type) {
  1591. case EV_ABS:
  1592. input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
  1593. input_abs_set_res(input, code,
  1594. hidinput_calc_abs_res(field, resolution_code));
  1595. break;
  1596. case EV_KEY:
  1597. input_set_capability(input, EV_KEY, code);
  1598. break;
  1599. case EV_MSC:
  1600. input_set_capability(input, EV_MSC, code);
  1601. break;
  1602. case EV_SW:
  1603. input_set_capability(input, EV_SW, code);
  1604. break;
  1605. }
  1606. }
  1607. static void wacom_wac_battery_usage_mapping(struct hid_device *hdev,
  1608. struct hid_field *field, struct hid_usage *usage)
  1609. {
  1610. struct wacom *wacom = hid_get_drvdata(hdev);
  1611. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1612. struct wacom_features *features = &wacom_wac->features;
  1613. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  1614. switch (equivalent_usage) {
  1615. case HID_DG_BATTERYSTRENGTH:
  1616. case WACOM_HID_WD_BATTERY_LEVEL:
  1617. case WACOM_HID_WD_BATTERY_CHARGING:
  1618. features->quirks |= WACOM_QUIRK_BATTERY;
  1619. break;
  1620. }
  1621. }
  1622. static void wacom_wac_battery_event(struct hid_device *hdev, struct hid_field *field,
  1623. struct hid_usage *usage, __s32 value)
  1624. {
  1625. struct wacom *wacom = hid_get_drvdata(hdev);
  1626. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1627. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  1628. switch (equivalent_usage) {
  1629. case HID_DG_BATTERYSTRENGTH:
  1630. if (value == 0) {
  1631. wacom_wac->hid_data.bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
  1632. }
  1633. else {
  1634. value = value * 100 / (field->logical_maximum - field->logical_minimum);
  1635. wacom_wac->hid_data.battery_capacity = value;
  1636. wacom_wac->hid_data.bat_connected = 1;
  1637. wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
  1638. }
  1639. break;
  1640. case WACOM_HID_WD_BATTERY_LEVEL:
  1641. value = value * 100 / (field->logical_maximum - field->logical_minimum);
  1642. wacom_wac->hid_data.battery_capacity = value;
  1643. wacom_wac->hid_data.bat_connected = 1;
  1644. wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
  1645. break;
  1646. case WACOM_HID_WD_BATTERY_CHARGING:
  1647. wacom_wac->hid_data.bat_charging = value;
  1648. wacom_wac->hid_data.ps_connected = value;
  1649. wacom_wac->hid_data.bat_connected = 1;
  1650. wacom_wac->hid_data.bat_status = WACOM_POWER_SUPPLY_STATUS_AUTO;
  1651. break;
  1652. }
  1653. }
  1654. static void wacom_wac_battery_pre_report(struct hid_device *hdev,
  1655. struct hid_report *report)
  1656. {
  1657. return;
  1658. }
  1659. static void wacom_wac_battery_report(struct hid_device *hdev,
  1660. struct hid_report *report)
  1661. {
  1662. struct wacom *wacom = hid_get_drvdata(hdev);
  1663. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1664. struct wacom_features *features = &wacom_wac->features;
  1665. if (features->quirks & WACOM_QUIRK_BATTERY) {
  1666. int status = wacom_wac->hid_data.bat_status;
  1667. int capacity = wacom_wac->hid_data.battery_capacity;
  1668. bool charging = wacom_wac->hid_data.bat_charging;
  1669. bool connected = wacom_wac->hid_data.bat_connected;
  1670. bool powered = wacom_wac->hid_data.ps_connected;
  1671. wacom_notify_battery(wacom_wac, status, capacity, charging,
  1672. connected, powered);
  1673. }
  1674. }
  1675. static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
  1676. struct hid_field *field, struct hid_usage *usage)
  1677. {
  1678. struct wacom *wacom = hid_get_drvdata(hdev);
  1679. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1680. struct wacom_features *features = &wacom_wac->features;
  1681. struct input_dev *input = wacom_wac->pad_input;
  1682. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  1683. switch (equivalent_usage) {
  1684. case WACOM_HID_WD_ACCELEROMETER_X:
  1685. __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
  1686. wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 0);
  1687. features->device_type |= WACOM_DEVICETYPE_PAD;
  1688. break;
  1689. case WACOM_HID_WD_ACCELEROMETER_Y:
  1690. __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
  1691. wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 0);
  1692. features->device_type |= WACOM_DEVICETYPE_PAD;
  1693. break;
  1694. case WACOM_HID_WD_ACCELEROMETER_Z:
  1695. __set_bit(INPUT_PROP_ACCELEROMETER, input->propbit);
  1696. wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
  1697. features->device_type |= WACOM_DEVICETYPE_PAD;
  1698. break;
  1699. case WACOM_HID_WD_BUTTONCENTER:
  1700. case WACOM_HID_WD_BUTTONHOME:
  1701. case WACOM_HID_WD_BUTTONUP:
  1702. case WACOM_HID_WD_BUTTONDOWN:
  1703. case WACOM_HID_WD_BUTTONLEFT:
  1704. case WACOM_HID_WD_BUTTONRIGHT:
  1705. wacom_map_usage(input, usage, field, EV_KEY,
  1706. wacom_numbered_button_to_key(features->numbered_buttons),
  1707. 0);
  1708. features->numbered_buttons++;
  1709. features->device_type |= WACOM_DEVICETYPE_PAD;
  1710. break;
  1711. case WACOM_HID_WD_TOUCHONOFF:
  1712. case WACOM_HID_WD_MUTE_DEVICE:
  1713. /*
  1714. * This usage, which is used to mute touch events, comes
  1715. * from the pad packet, but is reported on the touch
  1716. * interface. Because the touch interface may not have
  1717. * been created yet, we cannot call wacom_map_usage(). In
  1718. * order to process this usage when we receive it, we set
  1719. * the usage type and code directly.
  1720. */
  1721. wacom_wac->has_mute_touch_switch = true;
  1722. usage->type = EV_SW;
  1723. usage->code = SW_MUTE_DEVICE;
  1724. features->device_type |= WACOM_DEVICETYPE_PAD;
  1725. break;
  1726. case WACOM_HID_WD_TOUCHSTRIP:
  1727. wacom_map_usage(input, usage, field, EV_ABS, ABS_RX, 0);
  1728. features->device_type |= WACOM_DEVICETYPE_PAD;
  1729. break;
  1730. case WACOM_HID_WD_TOUCHSTRIP2:
  1731. wacom_map_usage(input, usage, field, EV_ABS, ABS_RY, 0);
  1732. features->device_type |= WACOM_DEVICETYPE_PAD;
  1733. break;
  1734. case WACOM_HID_WD_TOUCHRING:
  1735. wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
  1736. features->device_type |= WACOM_DEVICETYPE_PAD;
  1737. break;
  1738. case WACOM_HID_WD_TOUCHRINGSTATUS:
  1739. /*
  1740. * Only set up type/code association. Completely mapping
  1741. * this usage may overwrite the axis resolution and range.
  1742. */
  1743. usage->type = EV_ABS;
  1744. usage->code = ABS_WHEEL;
  1745. set_bit(EV_ABS, input->evbit);
  1746. features->device_type |= WACOM_DEVICETYPE_PAD;
  1747. break;
  1748. case WACOM_HID_WD_BUTTONCONFIG:
  1749. wacom_map_usage(input, usage, field, EV_KEY, KEY_BUTTONCONFIG, 0);
  1750. features->device_type |= WACOM_DEVICETYPE_PAD;
  1751. break;
  1752. case WACOM_HID_WD_ONSCREEN_KEYBOARD:
  1753. wacom_map_usage(input, usage, field, EV_KEY, KEY_ONSCREEN_KEYBOARD, 0);
  1754. features->device_type |= WACOM_DEVICETYPE_PAD;
  1755. break;
  1756. case WACOM_HID_WD_CONTROLPANEL:
  1757. wacom_map_usage(input, usage, field, EV_KEY, KEY_CONTROLPANEL, 0);
  1758. features->device_type |= WACOM_DEVICETYPE_PAD;
  1759. break;
  1760. case WACOM_HID_WD_MODE_CHANGE:
  1761. /* do not overwrite previous data */
  1762. if (!wacom_wac->has_mode_change) {
  1763. wacom_wac->has_mode_change = true;
  1764. wacom_wac->is_direct_mode = true;
  1765. }
  1766. features->device_type |= WACOM_DEVICETYPE_PAD;
  1767. break;
  1768. }
  1769. switch (equivalent_usage & 0xfffffff0) {
  1770. case WACOM_HID_WD_EXPRESSKEY00:
  1771. wacom_map_usage(input, usage, field, EV_KEY,
  1772. wacom_numbered_button_to_key(features->numbered_buttons),
  1773. 0);
  1774. features->numbered_buttons++;
  1775. features->device_type |= WACOM_DEVICETYPE_PAD;
  1776. break;
  1777. }
  1778. }
  1779. static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field,
  1780. struct hid_usage *usage, __s32 value)
  1781. {
  1782. struct wacom *wacom = hid_get_drvdata(hdev);
  1783. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1784. struct input_dev *input = wacom_wac->pad_input;
  1785. struct wacom_features *features = &wacom_wac->features;
  1786. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  1787. int i;
  1788. bool do_report = false;
  1789. /*
  1790. * Avoid reporting this event and setting inrange_state if this usage
  1791. * hasn't been mapped.
  1792. */
  1793. if (!usage->type && equivalent_usage != WACOM_HID_WD_MODE_CHANGE)
  1794. return;
  1795. if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY) {
  1796. if (usage->hid != WACOM_HID_WD_TOUCHRING)
  1797. wacom_wac->hid_data.inrange_state |= value;
  1798. }
  1799. switch (equivalent_usage) {
  1800. case WACOM_HID_WD_TOUCHRING:
  1801. /*
  1802. * Userspace expects touchrings to increase in value with
  1803. * clockwise gestures and have their zero point at the
  1804. * tablet's left. HID events "should" be clockwise-
  1805. * increasing and zero at top, though the MobileStudio
  1806. * Pro and 2nd-gen Intuos Pro don't do this...
  1807. */
  1808. if (hdev->vendor == 0x56a &&
  1809. (hdev->product == 0x34d || hdev->product == 0x34e || /* MobileStudio Pro */
  1810. hdev->product == 0x357 || hdev->product == 0x358 || /* Intuos Pro 2 */
  1811. hdev->product == 0x392 || /* Intuos Pro 2 */
  1812. hdev->product == 0x398 || hdev->product == 0x399 || /* MobileStudio Pro */
  1813. hdev->product == 0x3AA)) { /* MobileStudio Pro */
  1814. value = (field->logical_maximum - value);
  1815. if (hdev->product == 0x357 || hdev->product == 0x358 ||
  1816. hdev->product == 0x392)
  1817. value = wacom_offset_rotation(input, usage, value, 3, 16);
  1818. else if (hdev->product == 0x34d || hdev->product == 0x34e ||
  1819. hdev->product == 0x398 || hdev->product == 0x399 ||
  1820. hdev->product == 0x3AA)
  1821. value = wacom_offset_rotation(input, usage, value, 1, 2);
  1822. }
  1823. else {
  1824. value = wacom_offset_rotation(input, usage, value, 1, 4);
  1825. }
  1826. do_report = true;
  1827. break;
  1828. case WACOM_HID_WD_TOUCHRINGSTATUS:
  1829. if (!value)
  1830. input_event(input, usage->type, usage->code, 0);
  1831. break;
  1832. case WACOM_HID_WD_MUTE_DEVICE:
  1833. case WACOM_HID_WD_TOUCHONOFF:
  1834. if (wacom_wac->shared->touch_input) {
  1835. bool *is_touch_on = &wacom_wac->shared->is_touch_on;
  1836. if (equivalent_usage == WACOM_HID_WD_MUTE_DEVICE && value)
  1837. *is_touch_on = !(*is_touch_on);
  1838. else if (equivalent_usage == WACOM_HID_WD_TOUCHONOFF)
  1839. *is_touch_on = value;
  1840. input_report_switch(wacom_wac->shared->touch_input,
  1841. SW_MUTE_DEVICE, !(*is_touch_on));
  1842. input_sync(wacom_wac->shared->touch_input);
  1843. }
  1844. break;
  1845. case WACOM_HID_WD_MODE_CHANGE:
  1846. if (wacom_wac->is_direct_mode != value) {
  1847. wacom_wac->is_direct_mode = value;
  1848. wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_MODE_CHANGE);
  1849. }
  1850. break;
  1851. case WACOM_HID_WD_BUTTONCENTER:
  1852. for (i = 0; i < wacom->led.count; i++)
  1853. wacom_update_led(wacom, features->numbered_buttons,
  1854. value, i);
  1855. fallthrough;
  1856. default:
  1857. do_report = true;
  1858. break;
  1859. }
  1860. if (do_report) {
  1861. input_event(input, usage->type, usage->code, value);
  1862. if (value)
  1863. wacom_wac->hid_data.pad_input_event_flag = true;
  1864. }
  1865. }
  1866. static void wacom_wac_pad_pre_report(struct hid_device *hdev,
  1867. struct hid_report *report)
  1868. {
  1869. struct wacom *wacom = hid_get_drvdata(hdev);
  1870. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1871. wacom_wac->hid_data.inrange_state = 0;
  1872. }
  1873. static void wacom_wac_pad_report(struct hid_device *hdev,
  1874. struct hid_report *report, struct hid_field *field)
  1875. {
  1876. struct wacom *wacom = hid_get_drvdata(hdev);
  1877. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1878. struct input_dev *input = wacom_wac->pad_input;
  1879. bool active = wacom_wac->hid_data.inrange_state != 0;
  1880. /* report prox for expresskey events */
  1881. if (wacom_wac->hid_data.pad_input_event_flag) {
  1882. input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 0);
  1883. input_sync(input);
  1884. if (!active)
  1885. wacom_wac->hid_data.pad_input_event_flag = false;
  1886. }
  1887. }
  1888. static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
  1889. struct hid_field *field, struct hid_usage *usage)
  1890. {
  1891. struct wacom *wacom = hid_get_drvdata(hdev);
  1892. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1893. struct wacom_features *features = &wacom_wac->features;
  1894. struct input_dev *input = wacom_wac->pen_input;
  1895. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  1896. switch (equivalent_usage) {
  1897. case HID_GD_X:
  1898. wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
  1899. break;
  1900. case HID_GD_Y:
  1901. wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
  1902. break;
  1903. case WACOM_HID_WD_DISTANCE:
  1904. case HID_GD_Z:
  1905. wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
  1906. break;
  1907. case HID_DG_TIPPRESSURE:
  1908. wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
  1909. break;
  1910. case HID_DG_INRANGE:
  1911. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
  1912. break;
  1913. case HID_DG_INVERT:
  1914. wacom_map_usage(input, usage, field, EV_KEY,
  1915. BTN_TOOL_RUBBER, 0);
  1916. break;
  1917. case HID_DG_TILT_X:
  1918. wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
  1919. break;
  1920. case HID_DG_TILT_Y:
  1921. wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
  1922. break;
  1923. case HID_DG_TWIST:
  1924. wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
  1925. break;
  1926. case HID_DG_ERASER:
  1927. case HID_DG_TIPSWITCH:
  1928. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
  1929. break;
  1930. case HID_DG_BARRELSWITCH:
  1931. wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS, 0);
  1932. break;
  1933. case HID_DG_BARRELSWITCH2:
  1934. wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS2, 0);
  1935. break;
  1936. case HID_DG_TOOLSERIALNUMBER:
  1937. features->quirks |= WACOM_QUIRK_TOOLSERIAL;
  1938. wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0);
  1939. break;
  1940. case WACOM_HID_WD_SENSE:
  1941. features->quirks |= WACOM_QUIRK_SENSE;
  1942. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
  1943. break;
  1944. case WACOM_HID_WD_SERIALHI:
  1945. wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
  1946. if (!(features->quirks & WACOM_QUIRK_AESPEN)) {
  1947. set_bit(EV_KEY, input->evbit);
  1948. input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
  1949. input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
  1950. input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
  1951. input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
  1952. input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
  1953. if (!(features->device_type & WACOM_DEVICETYPE_DIRECT)) {
  1954. input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
  1955. input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
  1956. }
  1957. }
  1958. break;
  1959. case WACOM_HID_WD_FINGERWHEEL:
  1960. wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
  1961. break;
  1962. }
  1963. }
  1964. static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
  1965. struct hid_usage *usage, __s32 value)
  1966. {
  1967. struct wacom *wacom = hid_get_drvdata(hdev);
  1968. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  1969. struct wacom_features *features = &wacom_wac->features;
  1970. struct input_dev *input = wacom_wac->pen_input;
  1971. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  1972. if (wacom_wac->is_invalid_bt_frame)
  1973. return;
  1974. switch (equivalent_usage) {
  1975. case HID_GD_Z:
  1976. /*
  1977. * HID_GD_Z "should increase as the control's position is
  1978. * moved from high to low", while ABS_DISTANCE instead
  1979. * increases in value as the tool moves from low to high.
  1980. */
  1981. value = field->logical_maximum - value;
  1982. break;
  1983. case HID_DG_INRANGE:
  1984. wacom_wac->hid_data.inrange_state = value;
  1985. if (!(features->quirks & WACOM_QUIRK_SENSE))
  1986. wacom_wac->hid_data.sense_state = value;
  1987. return;
  1988. case HID_DG_INVERT:
  1989. wacom_wac->hid_data.invert_state = value;
  1990. return;
  1991. case HID_DG_ERASER:
  1992. case HID_DG_TIPSWITCH:
  1993. wacom_wac->hid_data.tipswitch |= value;
  1994. return;
  1995. case HID_DG_BARRELSWITCH:
  1996. wacom_wac->hid_data.barrelswitch = value;
  1997. return;
  1998. case HID_DG_BARRELSWITCH2:
  1999. wacom_wac->hid_data.barrelswitch2 = value;
  2000. return;
  2001. case HID_DG_TOOLSERIALNUMBER:
  2002. if (value) {
  2003. wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
  2004. wacom_wac->serial[0] |= wacom_s32tou(value, field->report_size);
  2005. }
  2006. return;
  2007. case HID_DG_TWIST:
  2008. /*
  2009. * Userspace expects pen twist to have its zero point when
  2010. * the buttons/finger is on the tablet's left. HID values
  2011. * are zero when buttons are toward the top.
  2012. */
  2013. value = wacom_offset_rotation(input, usage, value, 1, 4);
  2014. break;
  2015. case WACOM_HID_WD_SENSE:
  2016. wacom_wac->hid_data.sense_state = value;
  2017. return;
  2018. case WACOM_HID_WD_SERIALHI:
  2019. if (value) {
  2020. __u32 raw_value = wacom_s32tou(value, field->report_size);
  2021. wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
  2022. wacom_wac->serial[0] |= ((__u64)raw_value) << 32;
  2023. /*
  2024. * Non-USI EMR devices may contain additional tool type
  2025. * information here. See WACOM_HID_WD_TOOLTYPE case for
  2026. * more details.
  2027. */
  2028. if (value >> 20 == 1) {
  2029. wacom_wac->id[0] |= raw_value & 0xFFFFF;
  2030. }
  2031. }
  2032. return;
  2033. case WACOM_HID_WD_TOOLTYPE:
  2034. /*
  2035. * Some devices (MobileStudio Pro, and possibly later
  2036. * devices as well) do not return the complete tool
  2037. * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
  2038. * bitwise OR so the complete value can be built
  2039. * up over time :(
  2040. */
  2041. wacom_wac->id[0] |= wacom_s32tou(value, field->report_size);
  2042. return;
  2043. case WACOM_HID_WD_OFFSETLEFT:
  2044. if (features->offset_left && value != features->offset_left)
  2045. hid_warn(hdev, "%s: overriding existing left offset "
  2046. "%d -> %d\n", __func__, value,
  2047. features->offset_left);
  2048. features->offset_left = value;
  2049. return;
  2050. case WACOM_HID_WD_OFFSETRIGHT:
  2051. if (features->offset_right && value != features->offset_right)
  2052. hid_warn(hdev, "%s: overriding existing right offset "
  2053. "%d -> %d\n", __func__, value,
  2054. features->offset_right);
  2055. features->offset_right = value;
  2056. return;
  2057. case WACOM_HID_WD_OFFSETTOP:
  2058. if (features->offset_top && value != features->offset_top)
  2059. hid_warn(hdev, "%s: overriding existing top offset "
  2060. "%d -> %d\n", __func__, value,
  2061. features->offset_top);
  2062. features->offset_top = value;
  2063. return;
  2064. case WACOM_HID_WD_OFFSETBOTTOM:
  2065. if (features->offset_bottom && value != features->offset_bottom)
  2066. hid_warn(hdev, "%s: overriding existing bottom offset "
  2067. "%d -> %d\n", __func__, value,
  2068. features->offset_bottom);
  2069. features->offset_bottom = value;
  2070. return;
  2071. case WACOM_HID_WD_REPORT_VALID:
  2072. wacom_wac->is_invalid_bt_frame = !value;
  2073. return;
  2074. }
  2075. /* send pen events only when touch is up or forced out
  2076. * or touch arbitration is off
  2077. */
  2078. if (!usage->type || delay_pen_events(wacom_wac))
  2079. return;
  2080. /* send pen events only when the pen is in range */
  2081. if (wacom_wac->hid_data.inrange_state)
  2082. input_event(input, usage->type, usage->code, value);
  2083. else if (wacom_wac->shared->stylus_in_proximity && !wacom_wac->hid_data.sense_state)
  2084. input_event(input, usage->type, usage->code, 0);
  2085. }
  2086. static void wacom_wac_pen_pre_report(struct hid_device *hdev,
  2087. struct hid_report *report)
  2088. {
  2089. struct wacom *wacom = hid_get_drvdata(hdev);
  2090. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2091. wacom_wac->is_invalid_bt_frame = false;
  2092. return;
  2093. }
  2094. static void wacom_wac_pen_report(struct hid_device *hdev,
  2095. struct hid_report *report)
  2096. {
  2097. struct wacom *wacom = hid_get_drvdata(hdev);
  2098. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2099. struct input_dev *input = wacom_wac->pen_input;
  2100. bool range = wacom_wac->hid_data.inrange_state;
  2101. bool sense = wacom_wac->hid_data.sense_state;
  2102. if (wacom_wac->is_invalid_bt_frame)
  2103. return;
  2104. if (!wacom_wac->tool[0] && range) { /* first in range */
  2105. /* Going into range select tool */
  2106. if (wacom_wac->hid_data.invert_state)
  2107. wacom_wac->tool[0] = BTN_TOOL_RUBBER;
  2108. else if (wacom_wac->id[0])
  2109. wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
  2110. else
  2111. wacom_wac->tool[0] = BTN_TOOL_PEN;
  2112. }
  2113. /* keep pen state for touch events */
  2114. wacom_wac->shared->stylus_in_proximity = sense;
  2115. if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
  2116. int id = wacom_wac->id[0];
  2117. int sw_state = wacom_wac->hid_data.barrelswitch |
  2118. (wacom_wac->hid_data.barrelswitch2 << 1);
  2119. input_report_key(input, BTN_STYLUS, sw_state == 1);
  2120. input_report_key(input, BTN_STYLUS2, sw_state == 2);
  2121. input_report_key(input, BTN_STYLUS3, sw_state == 3);
  2122. /*
  2123. * Non-USI EMR tools should have their IDs mangled to
  2124. * match the legacy behavior of wacom_intuos_general
  2125. */
  2126. if (wacom_wac->serial[0] >> 52 == 1)
  2127. id = wacom_intuos_id_mangle(id);
  2128. /*
  2129. * To ensure compatibility with xf86-input-wacom, we should
  2130. * report the BTN_TOOL_* event prior to the ABS_MISC or
  2131. * MSC_SERIAL events.
  2132. */
  2133. input_report_key(input, BTN_TOUCH,
  2134. wacom_wac->hid_data.tipswitch);
  2135. input_report_key(input, wacom_wac->tool[0], sense);
  2136. if (wacom_wac->serial[0]) {
  2137. input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
  2138. input_report_abs(input, ABS_MISC, sense ? id : 0);
  2139. }
  2140. wacom_wac->hid_data.tipswitch = false;
  2141. input_sync(input);
  2142. }
  2143. if (!sense) {
  2144. wacom_wac->tool[0] = 0;
  2145. wacom_wac->id[0] = 0;
  2146. wacom_wac->serial[0] = 0;
  2147. }
  2148. }
  2149. static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
  2150. struct hid_field *field, struct hid_usage *usage)
  2151. {
  2152. struct wacom *wacom = hid_get_drvdata(hdev);
  2153. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2154. struct input_dev *input = wacom_wac->touch_input;
  2155. unsigned touch_max = wacom_wac->features.touch_max;
  2156. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  2157. switch (equivalent_usage) {
  2158. case HID_GD_X:
  2159. if (touch_max == 1)
  2160. wacom_map_usage(input, usage, field, EV_ABS, ABS_X, 4);
  2161. else
  2162. wacom_map_usage(input, usage, field, EV_ABS,
  2163. ABS_MT_POSITION_X, 4);
  2164. break;
  2165. case HID_GD_Y:
  2166. if (touch_max == 1)
  2167. wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
  2168. else
  2169. wacom_map_usage(input, usage, field, EV_ABS,
  2170. ABS_MT_POSITION_Y, 4);
  2171. break;
  2172. case HID_DG_WIDTH:
  2173. case HID_DG_HEIGHT:
  2174. wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
  2175. wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
  2176. input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  2177. break;
  2178. case HID_DG_TIPSWITCH:
  2179. wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
  2180. break;
  2181. case HID_DG_CONTACTCOUNT:
  2182. wacom_wac->hid_data.cc_report = field->report->id;
  2183. wacom_wac->hid_data.cc_index = field->index;
  2184. wacom_wac->hid_data.cc_value_index = usage->usage_index;
  2185. break;
  2186. case HID_DG_CONTACTID:
  2187. if ((field->logical_maximum - field->logical_minimum) < touch_max) {
  2188. /*
  2189. * The HID descriptor for G11 sensors leaves logical
  2190. * maximum set to '1' despite it being a multitouch
  2191. * device. Override to a sensible number.
  2192. */
  2193. field->logical_maximum = 255;
  2194. }
  2195. break;
  2196. }
  2197. }
  2198. static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
  2199. struct input_dev *input)
  2200. {
  2201. struct hid_data *hid_data = &wacom_wac->hid_data;
  2202. bool mt = wacom_wac->features.touch_max > 1;
  2203. bool prox = hid_data->tipswitch &&
  2204. report_touch_events(wacom_wac);
  2205. if (wacom_wac->shared->has_mute_touch_switch &&
  2206. !wacom_wac->shared->is_touch_on) {
  2207. if (!wacom_wac->shared->touch_down)
  2208. return;
  2209. prox = false;
  2210. }
  2211. wacom_wac->hid_data.num_received++;
  2212. if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
  2213. return;
  2214. if (mt) {
  2215. int slot;
  2216. slot = input_mt_get_slot_by_key(input, hid_data->id);
  2217. input_mt_slot(input, slot);
  2218. input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
  2219. }
  2220. else {
  2221. input_report_key(input, BTN_TOUCH, prox);
  2222. }
  2223. if (prox) {
  2224. input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
  2225. hid_data->x);
  2226. input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
  2227. hid_data->y);
  2228. if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
  2229. input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
  2230. input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
  2231. if (hid_data->width != hid_data->height)
  2232. input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
  2233. }
  2234. }
  2235. }
  2236. static bool wacom_wac_slot_is_active(struct input_dev *dev, int key)
  2237. {
  2238. struct input_mt *mt = dev->mt;
  2239. struct input_mt_slot *s;
  2240. if (!mt)
  2241. return false;
  2242. for (s = mt->slots; s != mt->slots + mt->num_slots; s++) {
  2243. if (s->key == key &&
  2244. input_mt_get_value(s, ABS_MT_TRACKING_ID) >= 0) {
  2245. return true;
  2246. }
  2247. }
  2248. return false;
  2249. }
  2250. static void wacom_wac_finger_event(struct hid_device *hdev,
  2251. struct hid_field *field, struct hid_usage *usage, __s32 value)
  2252. {
  2253. struct wacom *wacom = hid_get_drvdata(hdev);
  2254. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2255. unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
  2256. struct wacom_features *features = &wacom->wacom_wac.features;
  2257. if (wacom_wac->is_invalid_bt_frame)
  2258. return;
  2259. switch (equivalent_usage) {
  2260. case HID_DG_CONFIDENCE:
  2261. wacom_wac->hid_data.confidence = value;
  2262. break;
  2263. case HID_GD_X:
  2264. wacom_wac->hid_data.x = value;
  2265. break;
  2266. case HID_GD_Y:
  2267. wacom_wac->hid_data.y = value;
  2268. break;
  2269. case HID_DG_WIDTH:
  2270. wacom_wac->hid_data.width = value;
  2271. break;
  2272. case HID_DG_HEIGHT:
  2273. wacom_wac->hid_data.height = value;
  2274. break;
  2275. case HID_DG_CONTACTID:
  2276. wacom_wac->hid_data.id = value;
  2277. break;
  2278. case HID_DG_TIPSWITCH:
  2279. wacom_wac->hid_data.tipswitch = value;
  2280. break;
  2281. case WACOM_HID_WT_REPORT_VALID:
  2282. wacom_wac->is_invalid_bt_frame = !value;
  2283. return;
  2284. case HID_DG_CONTACTMAX:
  2285. if (!features->touch_max) {
  2286. features->touch_max = value;
  2287. } else {
  2288. hid_warn(hdev, "%s: ignoring attempt to overwrite non-zero touch_max "
  2289. "%d -> %d\n", __func__, features->touch_max, value);
  2290. }
  2291. return;
  2292. }
  2293. if (usage->usage_index + 1 == field->report_count) {
  2294. if (equivalent_usage == wacom_wac->hid_data.last_slot_field) {
  2295. bool touch_removed = wacom_wac_slot_is_active(wacom_wac->touch_input,
  2296. wacom_wac->hid_data.id) && !wacom_wac->hid_data.tipswitch;
  2297. if (wacom_wac->hid_data.confidence || touch_removed) {
  2298. wacom_wac_finger_slot(wacom_wac, wacom_wac->touch_input);
  2299. }
  2300. }
  2301. }
  2302. }
  2303. static void wacom_wac_finger_pre_report(struct hid_device *hdev,
  2304. struct hid_report *report)
  2305. {
  2306. struct wacom *wacom = hid_get_drvdata(hdev);
  2307. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2308. struct hid_data* hid_data = &wacom_wac->hid_data;
  2309. int i;
  2310. wacom_wac->is_invalid_bt_frame = false;
  2311. hid_data->confidence = true;
  2312. hid_data->cc_report = 0;
  2313. hid_data->cc_index = -1;
  2314. hid_data->cc_value_index = -1;
  2315. for (i = 0; i < report->maxfield; i++) {
  2316. struct hid_field *field = report->field[i];
  2317. int j;
  2318. for (j = 0; j < field->maxusage; j++) {
  2319. struct hid_usage *usage = &field->usage[j];
  2320. unsigned int equivalent_usage =
  2321. wacom_equivalent_usage(usage->hid);
  2322. switch (equivalent_usage) {
  2323. case HID_GD_X:
  2324. case HID_GD_Y:
  2325. case HID_DG_WIDTH:
  2326. case HID_DG_HEIGHT:
  2327. case HID_DG_CONTACTID:
  2328. case HID_DG_INRANGE:
  2329. case HID_DG_INVERT:
  2330. case HID_DG_TIPSWITCH:
  2331. hid_data->last_slot_field = equivalent_usage;
  2332. break;
  2333. case HID_DG_CONTACTCOUNT:
  2334. hid_data->cc_report = report->id;
  2335. hid_data->cc_index = i;
  2336. hid_data->cc_value_index = j;
  2337. break;
  2338. }
  2339. }
  2340. }
  2341. if (hid_data->cc_report != 0 &&
  2342. hid_data->cc_index >= 0) {
  2343. struct hid_field *field = report->field[hid_data->cc_index];
  2344. int value = field->value[hid_data->cc_value_index];
  2345. if (value) {
  2346. hid_data->num_expected = value;
  2347. hid_data->num_received = 0;
  2348. }
  2349. }
  2350. else {
  2351. hid_data->num_expected = wacom_wac->features.touch_max;
  2352. hid_data->num_received = 0;
  2353. }
  2354. }
  2355. static void wacom_wac_finger_report(struct hid_device *hdev,
  2356. struct hid_report *report)
  2357. {
  2358. struct wacom *wacom = hid_get_drvdata(hdev);
  2359. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2360. struct input_dev *input = wacom_wac->touch_input;
  2361. unsigned touch_max = wacom_wac->features.touch_max;
  2362. /* If more packets of data are expected, give us a chance to
  2363. * process them rather than immediately syncing a partial
  2364. * update.
  2365. */
  2366. if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
  2367. return;
  2368. if (touch_max > 1)
  2369. input_mt_sync_frame(input);
  2370. input_sync(input);
  2371. wacom_wac->hid_data.num_received = 0;
  2372. wacom_wac->hid_data.num_expected = 0;
  2373. /* keep touch state for pen event */
  2374. wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
  2375. }
  2376. void wacom_wac_usage_mapping(struct hid_device *hdev,
  2377. struct hid_field *field, struct hid_usage *usage)
  2378. {
  2379. struct wacom *wacom = hid_get_drvdata(hdev);
  2380. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2381. struct wacom_features *features = &wacom_wac->features;
  2382. if (WACOM_DIRECT_DEVICE(field))
  2383. features->device_type |= WACOM_DEVICETYPE_DIRECT;
  2384. /* usage tests must precede field tests */
  2385. if (WACOM_BATTERY_USAGE(usage))
  2386. wacom_wac_battery_usage_mapping(hdev, field, usage);
  2387. else if (WACOM_PAD_FIELD(field))
  2388. wacom_wac_pad_usage_mapping(hdev, field, usage);
  2389. else if (WACOM_PEN_FIELD(field))
  2390. wacom_wac_pen_usage_mapping(hdev, field, usage);
  2391. else if (WACOM_FINGER_FIELD(field))
  2392. wacom_wac_finger_usage_mapping(hdev, field, usage);
  2393. }
  2394. void wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
  2395. struct hid_usage *usage, __s32 value)
  2396. {
  2397. struct wacom *wacom = hid_get_drvdata(hdev);
  2398. if (wacom->wacom_wac.features.type != HID_GENERIC)
  2399. return;
  2400. if (value > field->logical_maximum || value < field->logical_minimum)
  2401. return;
  2402. /* usage tests must precede field tests */
  2403. if (WACOM_BATTERY_USAGE(usage))
  2404. wacom_wac_battery_event(hdev, field, usage, value);
  2405. else if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
  2406. wacom_wac_pad_event(hdev, field, usage, value);
  2407. else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
  2408. wacom_wac_pen_event(hdev, field, usage, value);
  2409. else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
  2410. wacom_wac_finger_event(hdev, field, usage, value);
  2411. }
  2412. static void wacom_report_events(struct hid_device *hdev,
  2413. struct hid_report *report, int collection_index,
  2414. int field_index)
  2415. {
  2416. int r;
  2417. for (r = field_index; r < report->maxfield; r++) {
  2418. struct hid_field *field;
  2419. unsigned count, n;
  2420. field = report->field[r];
  2421. count = field->report_count;
  2422. if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
  2423. continue;
  2424. for (n = 0 ; n < count; n++) {
  2425. if (field->usage[n].collection_index == collection_index)
  2426. wacom_wac_event(hdev, field, &field->usage[n],
  2427. field->value[n]);
  2428. else
  2429. return;
  2430. }
  2431. }
  2432. }
  2433. static int wacom_wac_collection(struct hid_device *hdev, struct hid_report *report,
  2434. int collection_index, struct hid_field *field,
  2435. int field_index)
  2436. {
  2437. struct wacom *wacom = hid_get_drvdata(hdev);
  2438. wacom_report_events(hdev, report, collection_index, field_index);
  2439. /*
  2440. * Non-input reports may be sent prior to the device being
  2441. * completely initialized. Since only their events need
  2442. * to be processed, exit after 'wacom_report_events' has
  2443. * been called to prevent potential crashes in the report-
  2444. * processing functions.
  2445. */
  2446. if (report->type != HID_INPUT_REPORT)
  2447. return -1;
  2448. if (WACOM_PAD_FIELD(field))
  2449. return 0;
  2450. else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
  2451. wacom_wac_pen_report(hdev, report);
  2452. else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
  2453. wacom_wac_finger_report(hdev, report);
  2454. return 0;
  2455. }
  2456. void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
  2457. {
  2458. struct wacom *wacom = hid_get_drvdata(hdev);
  2459. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2460. struct hid_field *field;
  2461. bool pad_in_hid_field = false, pen_in_hid_field = false,
  2462. finger_in_hid_field = false, true_pad = false;
  2463. int r;
  2464. int prev_collection = -1;
  2465. if (wacom_wac->features.type != HID_GENERIC)
  2466. return;
  2467. for (r = 0; r < report->maxfield; r++) {
  2468. field = report->field[r];
  2469. if (WACOM_PAD_FIELD(field))
  2470. pad_in_hid_field = true;
  2471. if (WACOM_PEN_FIELD(field))
  2472. pen_in_hid_field = true;
  2473. if (WACOM_FINGER_FIELD(field))
  2474. finger_in_hid_field = true;
  2475. if (wacom_equivalent_usage(field->physical) == HID_DG_TABLETFUNCTIONKEY)
  2476. true_pad = true;
  2477. }
  2478. wacom_wac_battery_pre_report(hdev, report);
  2479. if (pad_in_hid_field && wacom->wacom_wac.pad_input)
  2480. wacom_wac_pad_pre_report(hdev, report);
  2481. if (pen_in_hid_field && wacom->wacom_wac.pen_input)
  2482. wacom_wac_pen_pre_report(hdev, report);
  2483. if (finger_in_hid_field && wacom->wacom_wac.touch_input)
  2484. wacom_wac_finger_pre_report(hdev, report);
  2485. for (r = 0; r < report->maxfield; r++) {
  2486. field = report->field[r];
  2487. if (field->usage[0].collection_index != prev_collection) {
  2488. if (wacom_wac_collection(hdev, report,
  2489. field->usage[0].collection_index, field, r) < 0)
  2490. return;
  2491. prev_collection = field->usage[0].collection_index;
  2492. }
  2493. }
  2494. wacom_wac_battery_report(hdev, report);
  2495. if (true_pad && wacom->wacom_wac.pad_input)
  2496. wacom_wac_pad_report(hdev, report, field);
  2497. }
  2498. static int wacom_bpt_touch(struct wacom_wac *wacom)
  2499. {
  2500. struct wacom_features *features = &wacom->features;
  2501. struct input_dev *input = wacom->touch_input;
  2502. struct input_dev *pad_input = wacom->pad_input;
  2503. unsigned char *data = wacom->data;
  2504. int i;
  2505. if (data[0] != 0x02)
  2506. return 0;
  2507. for (i = 0; i < 2; i++) {
  2508. int offset = (data[1] & 0x80) ? (8 * i) : (9 * i);
  2509. bool touch = report_touch_events(wacom)
  2510. && (data[offset + 3] & 0x80);
  2511. input_mt_slot(input, i);
  2512. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  2513. if (touch) {
  2514. int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff;
  2515. int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff;
  2516. if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) {
  2517. x <<= 5;
  2518. y <<= 5;
  2519. }
  2520. input_report_abs(input, ABS_MT_POSITION_X, x);
  2521. input_report_abs(input, ABS_MT_POSITION_Y, y);
  2522. }
  2523. }
  2524. input_mt_sync_frame(input);
  2525. input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
  2526. input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
  2527. input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
  2528. input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
  2529. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  2530. return 1;
  2531. }
  2532. static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
  2533. {
  2534. struct wacom_features *features = &wacom->features;
  2535. struct input_dev *input = wacom->touch_input;
  2536. bool touch = data[1] & 0x80;
  2537. int slot = input_mt_get_slot_by_key(input, data[0]);
  2538. if (slot < 0)
  2539. return;
  2540. touch = touch && report_touch_events(wacom);
  2541. input_mt_slot(input, slot);
  2542. input_mt_report_slot_state(input, MT_TOOL_FINGER, touch);
  2543. if (touch) {
  2544. int x = (data[2] << 4) | (data[4] >> 4);
  2545. int y = (data[3] << 4) | (data[4] & 0x0f);
  2546. int width, height;
  2547. if (features->type >= INTUOSPS && features->type <= INTUOSHT2) {
  2548. width = data[5] * 100;
  2549. height = data[6] * 100;
  2550. } else {
  2551. /*
  2552. * "a" is a scaled-down area which we assume is
  2553. * roughly circular and which can be described as:
  2554. * a=(pi*r^2)/C.
  2555. */
  2556. int a = data[5];
  2557. int x_res = input_abs_get_res(input, ABS_MT_POSITION_X);
  2558. int y_res = input_abs_get_res(input, ABS_MT_POSITION_Y);
  2559. width = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
  2560. height = width * y_res / x_res;
  2561. }
  2562. input_report_abs(input, ABS_MT_POSITION_X, x);
  2563. input_report_abs(input, ABS_MT_POSITION_Y, y);
  2564. input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
  2565. input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
  2566. }
  2567. }
  2568. static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
  2569. {
  2570. struct input_dev *input = wacom->pad_input;
  2571. struct wacom_features *features = &wacom->features;
  2572. if (features->type == INTUOSHT || features->type == INTUOSHT2) {
  2573. input_report_key(input, BTN_LEFT, (data[1] & 0x02) != 0);
  2574. input_report_key(input, BTN_BACK, (data[1] & 0x08) != 0);
  2575. } else {
  2576. input_report_key(input, BTN_BACK, (data[1] & 0x02) != 0);
  2577. input_report_key(input, BTN_LEFT, (data[1] & 0x08) != 0);
  2578. }
  2579. input_report_key(input, BTN_FORWARD, (data[1] & 0x04) != 0);
  2580. input_report_key(input, BTN_RIGHT, (data[1] & 0x01) != 0);
  2581. }
  2582. static int wacom_bpt3_touch(struct wacom_wac *wacom)
  2583. {
  2584. unsigned char *data = wacom->data;
  2585. int count = data[1] & 0x07;
  2586. int touch_changed = 0, i;
  2587. if (data[0] != 0x02)
  2588. return 0;
  2589. /* data has up to 7 fixed sized 8-byte messages starting at data[2] */
  2590. for (i = 0; i < count; i++) {
  2591. int offset = (8 * i) + 2;
  2592. int msg_id = data[offset];
  2593. if (msg_id >= 2 && msg_id <= 17) {
  2594. wacom_bpt3_touch_msg(wacom, data + offset);
  2595. touch_changed++;
  2596. } else if (msg_id == 128)
  2597. wacom_bpt3_button_msg(wacom, data + offset);
  2598. }
  2599. /* only update touch if we actually have a touchpad and touch data changed */
  2600. if (wacom->touch_input && touch_changed) {
  2601. input_mt_sync_frame(wacom->touch_input);
  2602. wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
  2603. }
  2604. return 1;
  2605. }
  2606. static int wacom_bpt_pen(struct wacom_wac *wacom)
  2607. {
  2608. struct wacom_features *features = &wacom->features;
  2609. struct input_dev *input = wacom->pen_input;
  2610. unsigned char *data = wacom->data;
  2611. int x = 0, y = 0, p = 0, d = 0;
  2612. bool pen = false, btn1 = false, btn2 = false;
  2613. bool range, prox, rdy;
  2614. if (data[0] != WACOM_REPORT_PENABLED)
  2615. return 0;
  2616. range = (data[1] & 0x80) == 0x80;
  2617. prox = (data[1] & 0x40) == 0x40;
  2618. rdy = (data[1] & 0x20) == 0x20;
  2619. wacom->shared->stylus_in_proximity = range;
  2620. if (delay_pen_events(wacom))
  2621. return 0;
  2622. if (rdy) {
  2623. p = le16_to_cpup((__le16 *)&data[6]);
  2624. pen = data[1] & 0x01;
  2625. btn1 = data[1] & 0x02;
  2626. btn2 = data[1] & 0x04;
  2627. }
  2628. if (prox) {
  2629. x = le16_to_cpup((__le16 *)&data[2]);
  2630. y = le16_to_cpup((__le16 *)&data[4]);
  2631. if (data[1] & 0x08) {
  2632. wacom->tool[0] = BTN_TOOL_RUBBER;
  2633. wacom->id[0] = ERASER_DEVICE_ID;
  2634. } else {
  2635. wacom->tool[0] = BTN_TOOL_PEN;
  2636. wacom->id[0] = STYLUS_DEVICE_ID;
  2637. }
  2638. wacom->reporting_data = true;
  2639. }
  2640. if (range) {
  2641. /*
  2642. * Convert distance from out prox to distance from tablet.
  2643. * distance will be greater than distance_max once
  2644. * touching and applying pressure; do not report negative
  2645. * distance.
  2646. */
  2647. if (data[8] <= features->distance_max)
  2648. d = features->distance_max - data[8];
  2649. } else {
  2650. wacom->id[0] = 0;
  2651. }
  2652. if (wacom->reporting_data) {
  2653. input_report_key(input, BTN_TOUCH, pen);
  2654. input_report_key(input, BTN_STYLUS, btn1);
  2655. input_report_key(input, BTN_STYLUS2, btn2);
  2656. if (prox || !range) {
  2657. input_report_abs(input, ABS_X, x);
  2658. input_report_abs(input, ABS_Y, y);
  2659. }
  2660. input_report_abs(input, ABS_PRESSURE, p);
  2661. input_report_abs(input, ABS_DISTANCE, d);
  2662. input_report_key(input, wacom->tool[0], range); /* PEN or RUBBER */
  2663. input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
  2664. }
  2665. if (!range) {
  2666. wacom->reporting_data = false;
  2667. }
  2668. return 1;
  2669. }
  2670. static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
  2671. {
  2672. struct wacom_features *features = &wacom->features;
  2673. if ((features->type == INTUOSHT2) &&
  2674. (features->device_type & WACOM_DEVICETYPE_PEN))
  2675. return wacom_intuos_irq(wacom);
  2676. else if (len == WACOM_PKGLEN_BBTOUCH)
  2677. return wacom_bpt_touch(wacom);
  2678. else if (len == WACOM_PKGLEN_BBTOUCH3)
  2679. return wacom_bpt3_touch(wacom);
  2680. else if (len == WACOM_PKGLEN_BBFUN || len == WACOM_PKGLEN_BBPEN)
  2681. return wacom_bpt_pen(wacom);
  2682. return 0;
  2683. }
  2684. static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
  2685. unsigned char *data)
  2686. {
  2687. unsigned char prefix;
  2688. /*
  2689. * We need to reroute the event from the debug interface to the
  2690. * pen interface.
  2691. * We need to add the report ID to the actual pen report, so we
  2692. * temporary overwrite the first byte to prevent having to kzalloc/kfree
  2693. * and memcpy the report.
  2694. */
  2695. prefix = data[0];
  2696. data[0] = WACOM_REPORT_BPAD_PEN;
  2697. /*
  2698. * actually reroute the event.
  2699. * No need to check if wacom->shared->pen is valid, hid_input_report()
  2700. * will check for us.
  2701. */
  2702. hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
  2703. WACOM_PKGLEN_PENABLED, 1);
  2704. data[0] = prefix;
  2705. }
  2706. static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
  2707. unsigned char *data)
  2708. {
  2709. struct input_dev *input = wacom->touch_input;
  2710. unsigned char *finger_data, prefix;
  2711. unsigned id;
  2712. int x, y;
  2713. bool valid;
  2714. prefix = data[0];
  2715. for (id = 0; id < wacom->features.touch_max; id++) {
  2716. valid = !!(prefix & BIT(id)) &&
  2717. report_touch_events(wacom);
  2718. input_mt_slot(input, id);
  2719. input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
  2720. if (!valid)
  2721. continue;
  2722. finger_data = data + 1 + id * 3;
  2723. x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
  2724. y = (finger_data[2] << 4) | (finger_data[1] >> 4);
  2725. input_report_abs(input, ABS_MT_POSITION_X, x);
  2726. input_report_abs(input, ABS_MT_POSITION_Y, y);
  2727. }
  2728. input_mt_sync_frame(input);
  2729. input_report_key(input, BTN_LEFT, prefix & 0x40);
  2730. input_report_key(input, BTN_RIGHT, prefix & 0x80);
  2731. /* keep touch state for pen event */
  2732. wacom->shared->touch_down = !!prefix && report_touch_events(wacom);
  2733. return 1;
  2734. }
  2735. static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
  2736. {
  2737. unsigned char *data = wacom->data;
  2738. if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
  2739. (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
  2740. (data[0] != WACOM_REPORT_BPAD_TOUCH))
  2741. return 0;
  2742. if (data[1] & 0x01)
  2743. wacom_bamboo_pad_pen_event(wacom, &data[1]);
  2744. if (data[1] & 0x02)
  2745. return wacom_bamboo_pad_touch_event(wacom, &data[9]);
  2746. return 0;
  2747. }
  2748. static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
  2749. {
  2750. unsigned char *data = wacom->data;
  2751. int connected;
  2752. if (len != WACOM_PKGLEN_WIRELESS || data[0] != WACOM_REPORT_WL)
  2753. return 0;
  2754. connected = data[1] & 0x01;
  2755. if (connected) {
  2756. int pid, battery, charging;
  2757. if ((wacom->shared->type == INTUOSHT ||
  2758. wacom->shared->type == INTUOSHT2) &&
  2759. wacom->shared->touch_input &&
  2760. wacom->shared->touch_max) {
  2761. input_report_switch(wacom->shared->touch_input,
  2762. SW_MUTE_DEVICE, data[5] & 0x40);
  2763. input_sync(wacom->shared->touch_input);
  2764. }
  2765. pid = get_unaligned_be16(&data[6]);
  2766. battery = (data[5] & 0x3f) * 100 / 31;
  2767. charging = !!(data[5] & 0x80);
  2768. if (wacom->pid != pid) {
  2769. wacom->pid = pid;
  2770. wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
  2771. }
  2772. wacom_notify_battery(wacom, WACOM_POWER_SUPPLY_STATUS_AUTO,
  2773. battery, charging, 1, 0);
  2774. } else if (wacom->pid != 0) {
  2775. /* disconnected while previously connected */
  2776. wacom->pid = 0;
  2777. wacom_schedule_work(wacom, WACOM_WORKER_WIRELESS);
  2778. wacom_notify_battery(wacom, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
  2779. }
  2780. return 0;
  2781. }
  2782. static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
  2783. {
  2784. struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
  2785. struct wacom_features *features = &wacom_wac->features;
  2786. unsigned char *data = wacom_wac->data;
  2787. if (data[0] != WACOM_REPORT_USB)
  2788. return 0;
  2789. if ((features->type == INTUOSHT ||
  2790. features->type == INTUOSHT2) &&
  2791. wacom_wac->shared->touch_input &&
  2792. features->touch_max) {
  2793. input_report_switch(wacom_wac->shared->touch_input,
  2794. SW_MUTE_DEVICE, data[8] & 0x40);
  2795. input_sync(wacom_wac->shared->touch_input);
  2796. }
  2797. if (data[9] & 0x02) { /* wireless module is attached */
  2798. int battery = (data[8] & 0x3f) * 100 / 31;
  2799. bool charging = !!(data[8] & 0x80);
  2800. wacom_notify_battery(wacom_wac, WACOM_POWER_SUPPLY_STATUS_AUTO,
  2801. battery, charging, battery || charging, 1);
  2802. if (!wacom->battery.battery &&
  2803. !(features->quirks & WACOM_QUIRK_BATTERY)) {
  2804. features->quirks |= WACOM_QUIRK_BATTERY;
  2805. wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
  2806. }
  2807. }
  2808. else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
  2809. wacom->battery.battery) {
  2810. features->quirks &= ~WACOM_QUIRK_BATTERY;
  2811. wacom_schedule_work(wacom_wac, WACOM_WORKER_BATTERY);
  2812. wacom_notify_battery(wacom_wac, POWER_SUPPLY_STATUS_UNKNOWN, 0, 0, 0, 0);
  2813. }
  2814. return 0;
  2815. }
  2816. void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
  2817. {
  2818. bool sync;
  2819. switch (wacom_wac->features.type) {
  2820. case PENPARTNER:
  2821. sync = wacom_penpartner_irq(wacom_wac);
  2822. break;
  2823. case PL:
  2824. sync = wacom_pl_irq(wacom_wac);
  2825. break;
  2826. case WACOM_G4:
  2827. case GRAPHIRE:
  2828. case GRAPHIRE_BT:
  2829. case WACOM_MO:
  2830. sync = wacom_graphire_irq(wacom_wac);
  2831. break;
  2832. case PTU:
  2833. sync = wacom_ptu_irq(wacom_wac);
  2834. break;
  2835. case DTU:
  2836. sync = wacom_dtu_irq(wacom_wac);
  2837. break;
  2838. case DTUS:
  2839. case DTUSX:
  2840. sync = wacom_dtus_irq(wacom_wac);
  2841. break;
  2842. case INTUOS:
  2843. case INTUOS3S:
  2844. case INTUOS3:
  2845. case INTUOS3L:
  2846. case INTUOS4S:
  2847. case INTUOS4:
  2848. case INTUOS4L:
  2849. case CINTIQ:
  2850. case WACOM_BEE:
  2851. case WACOM_13HD:
  2852. case WACOM_21UX2:
  2853. case WACOM_22HD:
  2854. case WACOM_24HD:
  2855. case WACOM_27QHD:
  2856. case DTK:
  2857. case CINTIQ_HYBRID:
  2858. case CINTIQ_COMPANION_2:
  2859. sync = wacom_intuos_irq(wacom_wac);
  2860. break;
  2861. case INTUOS4WL:
  2862. sync = wacom_intuos_bt_irq(wacom_wac, len);
  2863. break;
  2864. case WACOM_24HDT:
  2865. case WACOM_27QHDT:
  2866. sync = wacom_24hdt_irq(wacom_wac);
  2867. break;
  2868. case INTUOS5S:
  2869. case INTUOS5:
  2870. case INTUOS5L:
  2871. case INTUOSPS:
  2872. case INTUOSPM:
  2873. case INTUOSPL:
  2874. if (len == WACOM_PKGLEN_BBTOUCH3)
  2875. sync = wacom_bpt3_touch(wacom_wac);
  2876. else if (wacom_wac->data[0] == WACOM_REPORT_USB)
  2877. sync = wacom_status_irq(wacom_wac, len);
  2878. else
  2879. sync = wacom_intuos_irq(wacom_wac);
  2880. break;
  2881. case INTUOSP2_BT:
  2882. case INTUOSP2S_BT:
  2883. case INTUOSHT3_BT:
  2884. sync = wacom_intuos_pro2_bt_irq(wacom_wac, len);
  2885. break;
  2886. case TABLETPC:
  2887. case TABLETPCE:
  2888. case TABLETPC2FG:
  2889. case MTSCREEN:
  2890. case MTTPC:
  2891. case MTTPC_B:
  2892. sync = wacom_tpc_irq(wacom_wac, len);
  2893. break;
  2894. case BAMBOO_PT:
  2895. case BAMBOO_PEN:
  2896. case BAMBOO_TOUCH:
  2897. case INTUOSHT:
  2898. case INTUOSHT2:
  2899. if (wacom_wac->data[0] == WACOM_REPORT_USB)
  2900. sync = wacom_status_irq(wacom_wac, len);
  2901. else
  2902. sync = wacom_bpt_irq(wacom_wac, len);
  2903. break;
  2904. case BAMBOO_PAD:
  2905. sync = wacom_bamboo_pad_irq(wacom_wac, len);
  2906. break;
  2907. case WIRELESS:
  2908. sync = wacom_wireless_irq(wacom_wac, len);
  2909. break;
  2910. case REMOTE:
  2911. sync = false;
  2912. if (wacom_wac->data[0] == WACOM_REPORT_DEVICE_LIST)
  2913. wacom_remote_status_irq(wacom_wac, len);
  2914. else
  2915. sync = wacom_remote_irq(wacom_wac, len);
  2916. break;
  2917. default:
  2918. sync = false;
  2919. break;
  2920. }
  2921. if (sync) {
  2922. if (wacom_wac->pen_input)
  2923. input_sync(wacom_wac->pen_input);
  2924. if (wacom_wac->touch_input)
  2925. input_sync(wacom_wac->touch_input);
  2926. if (wacom_wac->pad_input)
  2927. input_sync(wacom_wac->pad_input);
  2928. }
  2929. }
  2930. static void wacom_setup_basic_pro_pen(struct wacom_wac *wacom_wac)
  2931. {
  2932. struct input_dev *input_dev = wacom_wac->pen_input;
  2933. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  2934. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  2935. __set_bit(BTN_STYLUS, input_dev->keybit);
  2936. __set_bit(BTN_STYLUS2, input_dev->keybit);
  2937. input_set_abs_params(input_dev, ABS_DISTANCE,
  2938. 0, wacom_wac->features.distance_max, wacom_wac->features.distance_fuzz, 0);
  2939. }
  2940. static void wacom_setup_cintiq(struct wacom_wac *wacom_wac)
  2941. {
  2942. struct input_dev *input_dev = wacom_wac->pen_input;
  2943. struct wacom_features *features = &wacom_wac->features;
  2944. wacom_setup_basic_pro_pen(wacom_wac);
  2945. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  2946. __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
  2947. __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
  2948. __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
  2949. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  2950. input_set_abs_params(input_dev, ABS_TILT_X, -64, 63, features->tilt_fuzz, 0);
  2951. input_abs_set_res(input_dev, ABS_TILT_X, 57);
  2952. input_set_abs_params(input_dev, ABS_TILT_Y, -64, 63, features->tilt_fuzz, 0);
  2953. input_abs_set_res(input_dev, ABS_TILT_Y, 57);
  2954. }
  2955. static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
  2956. {
  2957. struct input_dev *input_dev = wacom_wac->pen_input;
  2958. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  2959. wacom_setup_cintiq(wacom_wac);
  2960. __set_bit(BTN_LEFT, input_dev->keybit);
  2961. __set_bit(BTN_RIGHT, input_dev->keybit);
  2962. __set_bit(BTN_MIDDLE, input_dev->keybit);
  2963. __set_bit(BTN_SIDE, input_dev->keybit);
  2964. __set_bit(BTN_EXTRA, input_dev->keybit);
  2965. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  2966. __set_bit(BTN_TOOL_LENS, input_dev->keybit);
  2967. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  2968. input_abs_set_res(input_dev, ABS_RZ, 287);
  2969. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  2970. }
  2971. void wacom_setup_device_quirks(struct wacom *wacom)
  2972. {
  2973. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  2974. struct wacom_features *features = &wacom->wacom_wac.features;
  2975. /* The pen and pad share the same interface on most devices */
  2976. if (features->type == GRAPHIRE_BT || features->type == WACOM_G4 ||
  2977. features->type == DTUS ||
  2978. (features->type >= INTUOS3S && features->type <= WACOM_MO)) {
  2979. if (features->device_type & WACOM_DEVICETYPE_PEN)
  2980. features->device_type |= WACOM_DEVICETYPE_PAD;
  2981. }
  2982. /* touch device found but size is not defined. use default */
  2983. if (features->device_type & WACOM_DEVICETYPE_TOUCH && !features->x_max) {
  2984. features->x_max = 1023;
  2985. features->y_max = 1023;
  2986. }
  2987. /*
  2988. * Intuos5/Pro and Bamboo 3rd gen have no useful data about its
  2989. * touch interface in its HID descriptor. If this is the touch
  2990. * interface (PacketSize of WACOM_PKGLEN_BBTOUCH3), override the
  2991. * tablet values.
  2992. */
  2993. if ((features->type >= INTUOS5S && features->type <= INTUOSPL) ||
  2994. (features->type >= INTUOSHT && features->type <= BAMBOO_PT)) {
  2995. if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
  2996. if (features->touch_max)
  2997. features->device_type |= WACOM_DEVICETYPE_TOUCH;
  2998. if (features->type >= INTUOSHT && features->type <= BAMBOO_PT)
  2999. features->device_type |= WACOM_DEVICETYPE_PAD;
  3000. if (features->type == INTUOSHT2) {
  3001. features->x_max = features->x_max / 10;
  3002. features->y_max = features->y_max / 10;
  3003. }
  3004. else {
  3005. features->x_max = 4096;
  3006. features->y_max = 4096;
  3007. }
  3008. }
  3009. else if (features->pktlen == WACOM_PKGLEN_BBTOUCH) {
  3010. features->device_type |= WACOM_DEVICETYPE_PAD;
  3011. }
  3012. }
  3013. /*
  3014. * Hack for the Bamboo One:
  3015. * the device presents a PAD/Touch interface as most Bamboos and even
  3016. * sends ghosts PAD data on it. However, later, we must disable this
  3017. * ghost interface, and we can not detect it unless we set it here
  3018. * to WACOM_DEVICETYPE_PAD or WACOM_DEVICETYPE_TOUCH.
  3019. */
  3020. if (features->type == BAMBOO_PEN &&
  3021. features->pktlen == WACOM_PKGLEN_BBTOUCH3)
  3022. features->device_type |= WACOM_DEVICETYPE_PAD;
  3023. /*
  3024. * Raw Wacom-mode pen and touch events both come from interface
  3025. * 0, whose HID descriptor has an application usage of 0xFF0D
  3026. * (i.e., WACOM_HID_WD_DIGITIZER). We route pen packets back
  3027. * out through the HID_GENERIC device created for interface 1,
  3028. * so rewrite this one to be of type WACOM_DEVICETYPE_TOUCH.
  3029. */
  3030. if (features->type == BAMBOO_PAD)
  3031. features->device_type = WACOM_DEVICETYPE_TOUCH;
  3032. if (features->type == REMOTE)
  3033. features->device_type = WACOM_DEVICETYPE_PAD;
  3034. if (features->type == INTUOSP2_BT ||
  3035. features->type == INTUOSP2S_BT) {
  3036. features->device_type |= WACOM_DEVICETYPE_PEN |
  3037. WACOM_DEVICETYPE_PAD |
  3038. WACOM_DEVICETYPE_TOUCH;
  3039. features->quirks |= WACOM_QUIRK_BATTERY;
  3040. }
  3041. if (features->type == INTUOSHT3_BT) {
  3042. features->device_type |= WACOM_DEVICETYPE_PEN |
  3043. WACOM_DEVICETYPE_PAD;
  3044. features->quirks |= WACOM_QUIRK_BATTERY;
  3045. }
  3046. switch (features->type) {
  3047. case PL:
  3048. case DTU:
  3049. case DTUS:
  3050. case DTUSX:
  3051. case WACOM_21UX2:
  3052. case WACOM_22HD:
  3053. case DTK:
  3054. case WACOM_24HD:
  3055. case WACOM_27QHD:
  3056. case CINTIQ_HYBRID:
  3057. case CINTIQ_COMPANION_2:
  3058. case CINTIQ:
  3059. case WACOM_BEE:
  3060. case WACOM_13HD:
  3061. case WACOM_24HDT:
  3062. case WACOM_27QHDT:
  3063. case TABLETPC:
  3064. case TABLETPCE:
  3065. case TABLETPC2FG:
  3066. case MTSCREEN:
  3067. case MTTPC:
  3068. case MTTPC_B:
  3069. features->device_type |= WACOM_DEVICETYPE_DIRECT;
  3070. break;
  3071. }
  3072. if (wacom->hdev->bus == BUS_BLUETOOTH)
  3073. features->quirks |= WACOM_QUIRK_BATTERY;
  3074. /* quirk for bamboo touch with 2 low res touches */
  3075. if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) &&
  3076. features->pktlen == WACOM_PKGLEN_BBTOUCH) {
  3077. features->x_max <<= 5;
  3078. features->y_max <<= 5;
  3079. features->x_fuzz <<= 5;
  3080. features->y_fuzz <<= 5;
  3081. features->quirks |= WACOM_QUIRK_BBTOUCH_LOWRES;
  3082. }
  3083. if (features->type == WIRELESS) {
  3084. if (features->device_type == WACOM_DEVICETYPE_WL_MONITOR) {
  3085. features->quirks |= WACOM_QUIRK_BATTERY;
  3086. }
  3087. }
  3088. if (features->type == REMOTE)
  3089. features->device_type |= WACOM_DEVICETYPE_WL_MONITOR;
  3090. /* HID descriptor for DTK-2451 / DTH-2452 claims to report lots
  3091. * of things it shouldn't. Lets fix up the damage...
  3092. */
  3093. if (wacom->hdev->product == 0x382 || wacom->hdev->product == 0x37d) {
  3094. features->quirks &= ~WACOM_QUIRK_TOOLSERIAL;
  3095. __clear_bit(BTN_TOOL_BRUSH, wacom_wac->pen_input->keybit);
  3096. __clear_bit(BTN_TOOL_PENCIL, wacom_wac->pen_input->keybit);
  3097. __clear_bit(BTN_TOOL_AIRBRUSH, wacom_wac->pen_input->keybit);
  3098. __clear_bit(ABS_Z, wacom_wac->pen_input->absbit);
  3099. __clear_bit(ABS_DISTANCE, wacom_wac->pen_input->absbit);
  3100. __clear_bit(ABS_TILT_X, wacom_wac->pen_input->absbit);
  3101. __clear_bit(ABS_TILT_Y, wacom_wac->pen_input->absbit);
  3102. __clear_bit(ABS_WHEEL, wacom_wac->pen_input->absbit);
  3103. __clear_bit(ABS_MISC, wacom_wac->pen_input->absbit);
  3104. __clear_bit(MSC_SERIAL, wacom_wac->pen_input->mscbit);
  3105. __clear_bit(EV_MSC, wacom_wac->pen_input->evbit);
  3106. }
  3107. }
  3108. int wacom_setup_pen_input_capabilities(struct input_dev *input_dev,
  3109. struct wacom_wac *wacom_wac)
  3110. {
  3111. struct wacom_features *features = &wacom_wac->features;
  3112. if (!(features->device_type & WACOM_DEVICETYPE_PEN))
  3113. return -ENODEV;
  3114. if (features->device_type & WACOM_DEVICETYPE_DIRECT)
  3115. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  3116. else
  3117. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  3118. if (features->type == HID_GENERIC) {
  3119. /* setup has already been done; apply otherwise-undetectible quirks */
  3120. input_set_capability(input_dev, EV_KEY, BTN_STYLUS3);
  3121. return 0;
  3122. }
  3123. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  3124. __set_bit(BTN_TOUCH, input_dev->keybit);
  3125. __set_bit(ABS_MISC, input_dev->absbit);
  3126. input_set_abs_params(input_dev, ABS_X, 0 + features->offset_left,
  3127. features->x_max - features->offset_right,
  3128. features->x_fuzz, 0);
  3129. input_set_abs_params(input_dev, ABS_Y, 0 + features->offset_top,
  3130. features->y_max - features->offset_bottom,
  3131. features->y_fuzz, 0);
  3132. input_set_abs_params(input_dev, ABS_PRESSURE, 0,
  3133. features->pressure_max, features->pressure_fuzz, 0);
  3134. /* penabled devices have fixed resolution for each model */
  3135. input_abs_set_res(input_dev, ABS_X, features->x_resolution);
  3136. input_abs_set_res(input_dev, ABS_Y, features->y_resolution);
  3137. switch (features->type) {
  3138. case GRAPHIRE_BT:
  3139. __clear_bit(ABS_MISC, input_dev->absbit);
  3140. fallthrough;
  3141. case WACOM_MO:
  3142. case WACOM_G4:
  3143. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  3144. features->distance_max,
  3145. features->distance_fuzz, 0);
  3146. fallthrough;
  3147. case GRAPHIRE:
  3148. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  3149. __set_bit(BTN_LEFT, input_dev->keybit);
  3150. __set_bit(BTN_RIGHT, input_dev->keybit);
  3151. __set_bit(BTN_MIDDLE, input_dev->keybit);
  3152. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  3153. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  3154. __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
  3155. __set_bit(BTN_STYLUS, input_dev->keybit);
  3156. __set_bit(BTN_STYLUS2, input_dev->keybit);
  3157. break;
  3158. case WACOM_27QHD:
  3159. case WACOM_24HD:
  3160. case DTK:
  3161. case WACOM_22HD:
  3162. case WACOM_21UX2:
  3163. case WACOM_BEE:
  3164. case CINTIQ:
  3165. case WACOM_13HD:
  3166. case CINTIQ_HYBRID:
  3167. case CINTIQ_COMPANION_2:
  3168. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  3169. input_abs_set_res(input_dev, ABS_Z, 287);
  3170. wacom_setup_cintiq(wacom_wac);
  3171. break;
  3172. case INTUOS3:
  3173. case INTUOS3L:
  3174. case INTUOS3S:
  3175. case INTUOS4:
  3176. case INTUOS4WL:
  3177. case INTUOS4L:
  3178. case INTUOS4S:
  3179. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  3180. input_abs_set_res(input_dev, ABS_Z, 287);
  3181. fallthrough;
  3182. case INTUOS:
  3183. wacom_setup_intuos(wacom_wac);
  3184. break;
  3185. case INTUOS5:
  3186. case INTUOS5L:
  3187. case INTUOSPM:
  3188. case INTUOSPL:
  3189. case INTUOS5S:
  3190. case INTUOSPS:
  3191. case INTUOSP2_BT:
  3192. case INTUOSP2S_BT:
  3193. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  3194. features->distance_max,
  3195. features->distance_fuzz, 0);
  3196. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  3197. input_abs_set_res(input_dev, ABS_Z, 287);
  3198. wacom_setup_intuos(wacom_wac);
  3199. break;
  3200. case WACOM_24HDT:
  3201. case WACOM_27QHDT:
  3202. case MTSCREEN:
  3203. case MTTPC:
  3204. case MTTPC_B:
  3205. case TABLETPC2FG:
  3206. case TABLETPC:
  3207. case TABLETPCE:
  3208. __clear_bit(ABS_MISC, input_dev->absbit);
  3209. fallthrough;
  3210. case DTUS:
  3211. case DTUSX:
  3212. case PL:
  3213. case DTU:
  3214. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  3215. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  3216. __set_bit(BTN_STYLUS, input_dev->keybit);
  3217. __set_bit(BTN_STYLUS2, input_dev->keybit);
  3218. break;
  3219. case PTU:
  3220. __set_bit(BTN_STYLUS2, input_dev->keybit);
  3221. fallthrough;
  3222. case PENPARTNER:
  3223. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  3224. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  3225. __set_bit(BTN_STYLUS, input_dev->keybit);
  3226. break;
  3227. case INTUOSHT:
  3228. case BAMBOO_PT:
  3229. case BAMBOO_PEN:
  3230. case INTUOSHT2:
  3231. case INTUOSHT3_BT:
  3232. if (features->type == INTUOSHT2 ||
  3233. features->type == INTUOSHT3_BT) {
  3234. wacom_setup_basic_pro_pen(wacom_wac);
  3235. } else {
  3236. __clear_bit(ABS_MISC, input_dev->absbit);
  3237. __set_bit(BTN_TOOL_PEN, input_dev->keybit);
  3238. __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
  3239. __set_bit(BTN_STYLUS, input_dev->keybit);
  3240. __set_bit(BTN_STYLUS2, input_dev->keybit);
  3241. input_set_abs_params(input_dev, ABS_DISTANCE, 0,
  3242. features->distance_max,
  3243. features->distance_fuzz, 0);
  3244. }
  3245. break;
  3246. case BAMBOO_PAD:
  3247. __clear_bit(ABS_MISC, input_dev->absbit);
  3248. break;
  3249. }
  3250. return 0;
  3251. }
  3252. int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
  3253. struct wacom_wac *wacom_wac)
  3254. {
  3255. struct wacom_features *features = &wacom_wac->features;
  3256. if (!(features->device_type & WACOM_DEVICETYPE_TOUCH))
  3257. return -ENODEV;
  3258. if (features->device_type & WACOM_DEVICETYPE_DIRECT)
  3259. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  3260. else
  3261. __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
  3262. if (features->type == HID_GENERIC)
  3263. /* setup has already been done */
  3264. return 0;
  3265. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  3266. __set_bit(BTN_TOUCH, input_dev->keybit);
  3267. if (features->touch_max == 1) {
  3268. input_set_abs_params(input_dev, ABS_X, 0,
  3269. features->x_max, features->x_fuzz, 0);
  3270. input_set_abs_params(input_dev, ABS_Y, 0,
  3271. features->y_max, features->y_fuzz, 0);
  3272. input_abs_set_res(input_dev, ABS_X,
  3273. features->x_resolution);
  3274. input_abs_set_res(input_dev, ABS_Y,
  3275. features->y_resolution);
  3276. }
  3277. else if (features->touch_max > 1) {
  3278. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
  3279. features->x_max, features->x_fuzz, 0);
  3280. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
  3281. features->y_max, features->y_fuzz, 0);
  3282. input_abs_set_res(input_dev, ABS_MT_POSITION_X,
  3283. features->x_resolution);
  3284. input_abs_set_res(input_dev, ABS_MT_POSITION_Y,
  3285. features->y_resolution);
  3286. }
  3287. switch (features->type) {
  3288. case INTUOSP2_BT:
  3289. case INTUOSP2S_BT:
  3290. input_dev->evbit[0] |= BIT_MASK(EV_SW);
  3291. __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
  3292. if (wacom_wac->shared->touch->product == 0x361) {
  3293. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  3294. 0, 12440, 4, 0);
  3295. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  3296. 0, 8640, 4, 0);
  3297. }
  3298. else if (wacom_wac->shared->touch->product == 0x360) {
  3299. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  3300. 0, 8960, 4, 0);
  3301. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  3302. 0, 5920, 4, 0);
  3303. }
  3304. else if (wacom_wac->shared->touch->product == 0x393) {
  3305. input_set_abs_params(input_dev, ABS_MT_POSITION_X,
  3306. 0, 6400, 4, 0);
  3307. input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
  3308. 0, 4000, 4, 0);
  3309. }
  3310. input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
  3311. input_abs_set_res(input_dev, ABS_MT_POSITION_Y, 40);
  3312. fallthrough;
  3313. case INTUOS5:
  3314. case INTUOS5L:
  3315. case INTUOSPM:
  3316. case INTUOSPL:
  3317. case INTUOS5S:
  3318. case INTUOSPS:
  3319. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
  3320. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, features->y_max, 0, 0);
  3321. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
  3322. break;
  3323. case WACOM_24HDT:
  3324. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, features->x_max, 0, 0);
  3325. input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, features->x_max, 0, 0);
  3326. input_set_abs_params(input_dev, ABS_MT_WIDTH_MINOR, 0, features->y_max, 0, 0);
  3327. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  3328. fallthrough;
  3329. case WACOM_27QHDT:
  3330. if (wacom_wac->shared->touch->product == 0x32C ||
  3331. wacom_wac->shared->touch->product == 0xF6) {
  3332. input_dev->evbit[0] |= BIT_MASK(EV_SW);
  3333. __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
  3334. wacom_wac->has_mute_touch_switch = true;
  3335. }
  3336. fallthrough;
  3337. case MTSCREEN:
  3338. case MTTPC:
  3339. case MTTPC_B:
  3340. case TABLETPC2FG:
  3341. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_DIRECT);
  3342. fallthrough;
  3343. case TABLETPC:
  3344. case TABLETPCE:
  3345. break;
  3346. case INTUOSHT:
  3347. case INTUOSHT2:
  3348. input_dev->evbit[0] |= BIT_MASK(EV_SW);
  3349. __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
  3350. fallthrough;
  3351. case BAMBOO_PT:
  3352. case BAMBOO_TOUCH:
  3353. if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
  3354. input_set_abs_params(input_dev,
  3355. ABS_MT_TOUCH_MAJOR,
  3356. 0, features->x_max, 0, 0);
  3357. input_set_abs_params(input_dev,
  3358. ABS_MT_TOUCH_MINOR,
  3359. 0, features->y_max, 0, 0);
  3360. }
  3361. input_mt_init_slots(input_dev, features->touch_max, INPUT_MT_POINTER);
  3362. break;
  3363. case BAMBOO_PAD:
  3364. input_mt_init_slots(input_dev, features->touch_max,
  3365. INPUT_MT_POINTER);
  3366. __set_bit(BTN_LEFT, input_dev->keybit);
  3367. __set_bit(BTN_RIGHT, input_dev->keybit);
  3368. break;
  3369. }
  3370. return 0;
  3371. }
  3372. static int wacom_numbered_button_to_key(int n)
  3373. {
  3374. if (n < 10)
  3375. return BTN_0 + n;
  3376. else if (n < 16)
  3377. return BTN_A + (n-10);
  3378. else if (n < 18)
  3379. return BTN_BASE + (n-16);
  3380. else
  3381. return 0;
  3382. }
  3383. static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
  3384. int button_count)
  3385. {
  3386. int i;
  3387. for (i = 0; i < button_count; i++) {
  3388. int key = wacom_numbered_button_to_key(i);
  3389. if (key)
  3390. __set_bit(key, input_dev->keybit);
  3391. }
  3392. }
  3393. static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group)
  3394. {
  3395. struct wacom_led *led;
  3396. int i;
  3397. bool updated = false;
  3398. /*
  3399. * 24HD has LED group 1 to the left and LED group 0 to the right.
  3400. * So group 0 matches the second half of the buttons and thus the mask
  3401. * needs to be shifted.
  3402. */
  3403. if (group == 0)
  3404. mask >>= 8;
  3405. for (i = 0; i < 3; i++) {
  3406. led = wacom_led_find(wacom, group, i);
  3407. if (!led) {
  3408. hid_err(wacom->hdev, "can't find LED %d in group %d\n",
  3409. i, group);
  3410. continue;
  3411. }
  3412. if (!updated && mask & BIT(i)) {
  3413. led->held = true;
  3414. led_trigger_event(&led->trigger, LED_FULL);
  3415. } else {
  3416. led->held = false;
  3417. }
  3418. }
  3419. }
  3420. static bool wacom_is_led_toggled(struct wacom *wacom, int button_count,
  3421. int mask, int group)
  3422. {
  3423. int group_button;
  3424. /*
  3425. * 21UX2 has LED group 1 to the left and LED group 0
  3426. * to the right. We need to reverse the group to match this
  3427. * historical behavior.
  3428. */
  3429. if (wacom->wacom_wac.features.type == WACOM_21UX2)
  3430. group = 1 - group;
  3431. group_button = group * (button_count/wacom->led.count);
  3432. if (wacom->wacom_wac.features.type == INTUOSP2_BT)
  3433. group_button = 8;
  3434. return mask & (1 << group_button);
  3435. }
  3436. static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
  3437. int group)
  3438. {
  3439. struct wacom_led *led, *next_led;
  3440. int cur;
  3441. bool pressed;
  3442. if (wacom->wacom_wac.features.type == WACOM_24HD)
  3443. return wacom_24hd_update_leds(wacom, mask, group);
  3444. pressed = wacom_is_led_toggled(wacom, button_count, mask, group);
  3445. cur = wacom->led.groups[group].select;
  3446. led = wacom_led_find(wacom, group, cur);
  3447. if (!led) {
  3448. hid_err(wacom->hdev, "can't find current LED %d in group %d\n",
  3449. cur, group);
  3450. return;
  3451. }
  3452. if (!pressed) {
  3453. led->held = false;
  3454. return;
  3455. }
  3456. if (led->held && pressed)
  3457. return;
  3458. next_led = wacom_led_next(wacom, led);
  3459. if (!next_led) {
  3460. hid_err(wacom->hdev, "can't find next LED in group %d\n",
  3461. group);
  3462. return;
  3463. }
  3464. if (next_led == led)
  3465. return;
  3466. next_led->held = true;
  3467. led_trigger_event(&next_led->trigger,
  3468. wacom_leds_brightness_get(next_led));
  3469. }
  3470. static void wacom_report_numbered_buttons(struct input_dev *input_dev,
  3471. int button_count, int mask)
  3472. {
  3473. struct wacom *wacom = input_get_drvdata(input_dev);
  3474. int i;
  3475. for (i = 0; i < wacom->led.count; i++)
  3476. wacom_update_led(wacom, button_count, mask, i);
  3477. for (i = 0; i < button_count; i++) {
  3478. int key = wacom_numbered_button_to_key(i);
  3479. if (key)
  3480. input_report_key(input_dev, key, mask & (1 << i));
  3481. }
  3482. }
  3483. int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
  3484. struct wacom_wac *wacom_wac)
  3485. {
  3486. struct wacom_features *features = &wacom_wac->features;
  3487. if ((features->type == HID_GENERIC) && features->numbered_buttons > 0)
  3488. features->device_type |= WACOM_DEVICETYPE_PAD;
  3489. if (!(features->device_type & WACOM_DEVICETYPE_PAD))
  3490. return -ENODEV;
  3491. if (features->type == REMOTE && input_dev == wacom_wac->pad_input)
  3492. return -ENODEV;
  3493. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  3494. /* kept for making legacy xf86-input-wacom working with the wheels */
  3495. __set_bit(ABS_MISC, input_dev->absbit);
  3496. /* kept for making legacy xf86-input-wacom accepting the pad */
  3497. if (!(input_dev->absinfo && (input_dev->absinfo[ABS_X].minimum ||
  3498. input_dev->absinfo[ABS_X].maximum)))
  3499. input_set_abs_params(input_dev, ABS_X, 0, 1, 0, 0);
  3500. if (!(input_dev->absinfo && (input_dev->absinfo[ABS_Y].minimum ||
  3501. input_dev->absinfo[ABS_Y].maximum)))
  3502. input_set_abs_params(input_dev, ABS_Y, 0, 1, 0, 0);
  3503. /* kept for making udev and libwacom accepting the pad */
  3504. __set_bit(BTN_STYLUS, input_dev->keybit);
  3505. wacom_setup_numbered_buttons(input_dev, features->numbered_buttons);
  3506. switch (features->type) {
  3507. case CINTIQ_HYBRID:
  3508. case CINTIQ_COMPANION_2:
  3509. case DTK:
  3510. case DTUS:
  3511. case GRAPHIRE_BT:
  3512. break;
  3513. case WACOM_MO:
  3514. __set_bit(BTN_BACK, input_dev->keybit);
  3515. __set_bit(BTN_LEFT, input_dev->keybit);
  3516. __set_bit(BTN_FORWARD, input_dev->keybit);
  3517. __set_bit(BTN_RIGHT, input_dev->keybit);
  3518. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  3519. break;
  3520. case WACOM_G4:
  3521. __set_bit(BTN_BACK, input_dev->keybit);
  3522. __set_bit(BTN_FORWARD, input_dev->keybit);
  3523. input_set_capability(input_dev, EV_REL, REL_WHEEL);
  3524. break;
  3525. case WACOM_24HD:
  3526. __set_bit(KEY_PROG1, input_dev->keybit);
  3527. __set_bit(KEY_PROG2, input_dev->keybit);
  3528. __set_bit(KEY_PROG3, input_dev->keybit);
  3529. __set_bit(KEY_ONSCREEN_KEYBOARD, input_dev->keybit);
  3530. __set_bit(KEY_INFO, input_dev->keybit);
  3531. if (!features->oPid)
  3532. __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
  3533. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  3534. input_set_abs_params(input_dev, ABS_THROTTLE, 0, 71, 0, 0);
  3535. break;
  3536. case WACOM_27QHD:
  3537. __set_bit(KEY_PROG1, input_dev->keybit);
  3538. __set_bit(KEY_PROG2, input_dev->keybit);
  3539. __set_bit(KEY_PROG3, input_dev->keybit);
  3540. __set_bit(KEY_ONSCREEN_KEYBOARD, input_dev->keybit);
  3541. __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
  3542. if (!features->oPid)
  3543. __set_bit(KEY_CONTROLPANEL, input_dev->keybit);
  3544. input_set_abs_params(input_dev, ABS_X, -2048, 2048, 0, 0);
  3545. input_abs_set_res(input_dev, ABS_X, 1024); /* points/g */
  3546. input_set_abs_params(input_dev, ABS_Y, -2048, 2048, 0, 0);
  3547. input_abs_set_res(input_dev, ABS_Y, 1024);
  3548. input_set_abs_params(input_dev, ABS_Z, -2048, 2048, 0, 0);
  3549. input_abs_set_res(input_dev, ABS_Z, 1024);
  3550. __set_bit(INPUT_PROP_ACCELEROMETER, input_dev->propbit);
  3551. break;
  3552. case WACOM_22HD:
  3553. __set_bit(KEY_PROG1, input_dev->keybit);
  3554. __set_bit(KEY_PROG2, input_dev->keybit);
  3555. __set_bit(KEY_PROG3, input_dev->keybit);
  3556. __set_bit(KEY_BUTTONCONFIG, input_dev->keybit);
  3557. __set_bit(KEY_INFO, input_dev->keybit);
  3558. fallthrough;
  3559. case WACOM_21UX2:
  3560. case WACOM_BEE:
  3561. case CINTIQ:
  3562. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  3563. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  3564. break;
  3565. case WACOM_13HD:
  3566. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  3567. break;
  3568. case INTUOS3:
  3569. case INTUOS3L:
  3570. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  3571. fallthrough;
  3572. case INTUOS3S:
  3573. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  3574. break;
  3575. case INTUOS5:
  3576. case INTUOS5L:
  3577. case INTUOSPM:
  3578. case INTUOSPL:
  3579. case INTUOS5S:
  3580. case INTUOSPS:
  3581. case INTUOSP2_BT:
  3582. case INTUOSP2S_BT:
  3583. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  3584. break;
  3585. case INTUOS4WL:
  3586. /*
  3587. * For Bluetooth devices, the udev rule does not work correctly
  3588. * for pads unless we add a stylus capability, which forces
  3589. * ID_INPUT_TABLET to be set.
  3590. */
  3591. __set_bit(BTN_STYLUS, input_dev->keybit);
  3592. fallthrough;
  3593. case INTUOS4:
  3594. case INTUOS4L:
  3595. case INTUOS4S:
  3596. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  3597. break;
  3598. case INTUOSHT:
  3599. case BAMBOO_PT:
  3600. case BAMBOO_TOUCH:
  3601. case INTUOSHT2:
  3602. __clear_bit(ABS_MISC, input_dev->absbit);
  3603. __set_bit(BTN_LEFT, input_dev->keybit);
  3604. __set_bit(BTN_FORWARD, input_dev->keybit);
  3605. __set_bit(BTN_BACK, input_dev->keybit);
  3606. __set_bit(BTN_RIGHT, input_dev->keybit);
  3607. break;
  3608. case REMOTE:
  3609. input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
  3610. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  3611. break;
  3612. case INTUOSHT3_BT:
  3613. case HID_GENERIC:
  3614. break;
  3615. default:
  3616. /* no pad supported */
  3617. return -ENODEV;
  3618. }
  3619. return 0;
  3620. }
  3621. static const struct wacom_features wacom_features_0x00 =
  3622. { "Wacom Penpartner", 5040, 3780, 255, 0,
  3623. PENPARTNER, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  3624. static const struct wacom_features wacom_features_0x10 =
  3625. { "Wacom Graphire", 10206, 7422, 511, 63,
  3626. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3627. static const struct wacom_features wacom_features_0x81 =
  3628. { "Wacom Graphire BT", 16704, 12064, 511, 32,
  3629. GRAPHIRE_BT, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES, 2 };
  3630. static const struct wacom_features wacom_features_0x11 =
  3631. { "Wacom Graphire2 4x5", 10206, 7422, 511, 63,
  3632. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3633. static const struct wacom_features wacom_features_0x12 =
  3634. { "Wacom Graphire2 5x7", 13918, 10206, 511, 63,
  3635. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3636. static const struct wacom_features wacom_features_0x13 =
  3637. { "Wacom Graphire3", 10208, 7424, 511, 63,
  3638. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3639. static const struct wacom_features wacom_features_0x14 =
  3640. { "Wacom Graphire3 6x8", 16704, 12064, 511, 63,
  3641. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3642. static const struct wacom_features wacom_features_0x15 =
  3643. { "Wacom Graphire4 4x5", 10208, 7424, 511, 63,
  3644. WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3645. static const struct wacom_features wacom_features_0x16 =
  3646. { "Wacom Graphire4 6x8", 16704, 12064, 511, 63,
  3647. WACOM_G4, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3648. static const struct wacom_features wacom_features_0x17 =
  3649. { "Wacom BambooFun 4x5", 14760, 9225, 511, 63,
  3650. WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3651. static const struct wacom_features wacom_features_0x18 =
  3652. { "Wacom BambooFun 6x8", 21648, 13530, 511, 63,
  3653. WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3654. static const struct wacom_features wacom_features_0x19 =
  3655. { "Wacom Bamboo1 Medium", 16704, 12064, 511, 63,
  3656. GRAPHIRE, WACOM_GRAPHIRE_RES, WACOM_GRAPHIRE_RES };
  3657. static const struct wacom_features wacom_features_0x60 =
  3658. { "Wacom Volito", 5104, 3712, 511, 63,
  3659. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  3660. static const struct wacom_features wacom_features_0x61 =
  3661. { "Wacom PenStation2", 3250, 2320, 255, 63,
  3662. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  3663. static const struct wacom_features wacom_features_0x62 =
  3664. { "Wacom Volito2 4x5", 5104, 3712, 511, 63,
  3665. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  3666. static const struct wacom_features wacom_features_0x63 =
  3667. { "Wacom Volito2 2x3", 3248, 2320, 511, 63,
  3668. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  3669. static const struct wacom_features wacom_features_0x64 =
  3670. { "Wacom PenPartner2", 3250, 2320, 511, 63,
  3671. GRAPHIRE, WACOM_VOLITO_RES, WACOM_VOLITO_RES };
  3672. static const struct wacom_features wacom_features_0x65 =
  3673. { "Wacom Bamboo", 14760, 9225, 511, 63,
  3674. WACOM_MO, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3675. static const struct wacom_features wacom_features_0x69 =
  3676. { "Wacom Bamboo1", 5104, 3712, 511, 63,
  3677. GRAPHIRE, WACOM_PENPRTN_RES, WACOM_PENPRTN_RES };
  3678. static const struct wacom_features wacom_features_0x6A =
  3679. { "Wacom Bamboo1 4x6", 14760, 9225, 1023, 63,
  3680. GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3681. static const struct wacom_features wacom_features_0x6B =
  3682. { "Wacom Bamboo1 5x8", 21648, 13530, 1023, 63,
  3683. GRAPHIRE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3684. static const struct wacom_features wacom_features_0x20 =
  3685. { "Wacom Intuos 4x5", 12700, 10600, 1023, 31,
  3686. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3687. static const struct wacom_features wacom_features_0x21 =
  3688. { "Wacom Intuos 6x8", 20320, 16240, 1023, 31,
  3689. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3690. static const struct wacom_features wacom_features_0x22 =
  3691. { "Wacom Intuos 9x12", 30480, 24060, 1023, 31,
  3692. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3693. static const struct wacom_features wacom_features_0x23 =
  3694. { "Wacom Intuos 12x12", 30480, 31680, 1023, 31,
  3695. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3696. static const struct wacom_features wacom_features_0x24 =
  3697. { "Wacom Intuos 12x18", 45720, 31680, 1023, 31,
  3698. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3699. static const struct wacom_features wacom_features_0x30 =
  3700. { "Wacom PL400", 5408, 4056, 255, 0,
  3701. PL, WACOM_PL_RES, WACOM_PL_RES };
  3702. static const struct wacom_features wacom_features_0x31 =
  3703. { "Wacom PL500", 6144, 4608, 255, 0,
  3704. PL, WACOM_PL_RES, WACOM_PL_RES };
  3705. static const struct wacom_features wacom_features_0x32 =
  3706. { "Wacom PL600", 6126, 4604, 255, 0,
  3707. PL, WACOM_PL_RES, WACOM_PL_RES };
  3708. static const struct wacom_features wacom_features_0x33 =
  3709. { "Wacom PL600SX", 6260, 5016, 255, 0,
  3710. PL, WACOM_PL_RES, WACOM_PL_RES };
  3711. static const struct wacom_features wacom_features_0x34 =
  3712. { "Wacom PL550", 6144, 4608, 511, 0,
  3713. PL, WACOM_PL_RES, WACOM_PL_RES };
  3714. static const struct wacom_features wacom_features_0x35 =
  3715. { "Wacom PL800", 7220, 5780, 511, 0,
  3716. PL, WACOM_PL_RES, WACOM_PL_RES };
  3717. static const struct wacom_features wacom_features_0x37 =
  3718. { "Wacom PL700", 6758, 5406, 511, 0,
  3719. PL, WACOM_PL_RES, WACOM_PL_RES };
  3720. static const struct wacom_features wacom_features_0x38 =
  3721. { "Wacom PL510", 6282, 4762, 511, 0,
  3722. PL, WACOM_PL_RES, WACOM_PL_RES };
  3723. static const struct wacom_features wacom_features_0x39 =
  3724. { "Wacom DTU710", 34080, 27660, 511, 0,
  3725. PL, WACOM_PL_RES, WACOM_PL_RES };
  3726. static const struct wacom_features wacom_features_0xC4 =
  3727. { "Wacom DTF521", 6282, 4762, 511, 0,
  3728. PL, WACOM_PL_RES, WACOM_PL_RES };
  3729. static const struct wacom_features wacom_features_0xC0 =
  3730. { "Wacom DTF720", 6858, 5506, 511, 0,
  3731. PL, WACOM_PL_RES, WACOM_PL_RES };
  3732. static const struct wacom_features wacom_features_0xC2 =
  3733. { "Wacom DTF720a", 6858, 5506, 511, 0,
  3734. PL, WACOM_PL_RES, WACOM_PL_RES };
  3735. static const struct wacom_features wacom_features_0x03 =
  3736. { "Wacom Cintiq Partner", 20480, 15360, 511, 0,
  3737. PTU, WACOM_PL_RES, WACOM_PL_RES };
  3738. static const struct wacom_features wacom_features_0x41 =
  3739. { "Wacom Intuos2 4x5", 12700, 10600, 1023, 31,
  3740. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3741. static const struct wacom_features wacom_features_0x42 =
  3742. { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
  3743. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3744. static const struct wacom_features wacom_features_0x43 =
  3745. { "Wacom Intuos2 9x12", 30480, 24060, 1023, 31,
  3746. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3747. static const struct wacom_features wacom_features_0x44 =
  3748. { "Wacom Intuos2 12x12", 30480, 31680, 1023, 31,
  3749. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3750. static const struct wacom_features wacom_features_0x45 =
  3751. { "Wacom Intuos2 12x18", 45720, 31680, 1023, 31,
  3752. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3753. static const struct wacom_features wacom_features_0xB0 =
  3754. { "Wacom Intuos3 4x5", 25400, 20320, 1023, 63,
  3755. INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
  3756. static const struct wacom_features wacom_features_0xB1 =
  3757. { "Wacom Intuos3 6x8", 40640, 30480, 1023, 63,
  3758. INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  3759. static const struct wacom_features wacom_features_0xB2 =
  3760. { "Wacom Intuos3 9x12", 60960, 45720, 1023, 63,
  3761. INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  3762. static const struct wacom_features wacom_features_0xB3 =
  3763. { "Wacom Intuos3 12x12", 60960, 60960, 1023, 63,
  3764. INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  3765. static const struct wacom_features wacom_features_0xB4 =
  3766. { "Wacom Intuos3 12x19", 97536, 60960, 1023, 63,
  3767. INTUOS3L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  3768. static const struct wacom_features wacom_features_0xB5 =
  3769. { "Wacom Intuos3 6x11", 54204, 31750, 1023, 63,
  3770. INTUOS3, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  3771. static const struct wacom_features wacom_features_0xB7 =
  3772. { "Wacom Intuos3 4x6", 31496, 19685, 1023, 63,
  3773. INTUOS3S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 4 };
  3774. static const struct wacom_features wacom_features_0xB8 =
  3775. { "Wacom Intuos4 4x6", 31496, 19685, 2047, 63,
  3776. INTUOS4S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
  3777. static const struct wacom_features wacom_features_0xB9 =
  3778. { "Wacom Intuos4 6x9", 44704, 27940, 2047, 63,
  3779. INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  3780. static const struct wacom_features wacom_features_0xBA =
  3781. { "Wacom Intuos4 8x13", 65024, 40640, 2047, 63,
  3782. INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  3783. static const struct wacom_features wacom_features_0xBB =
  3784. { "Wacom Intuos4 12x19", 97536, 60960, 2047, 63,
  3785. INTUOS4L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  3786. static const struct wacom_features wacom_features_0xBC =
  3787. { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
  3788. INTUOS4, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  3789. static const struct wacom_features wacom_features_0xBD =
  3790. { "Wacom Intuos4 WL", 40640, 25400, 2047, 63,
  3791. INTUOS4WL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  3792. static const struct wacom_features wacom_features_0x26 =
  3793. { "Wacom Intuos5 touch S", 31496, 19685, 2047, 63,
  3794. INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16 };
  3795. static const struct wacom_features wacom_features_0x27 =
  3796. { "Wacom Intuos5 touch M", 44704, 27940, 2047, 63,
  3797. INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
  3798. static const struct wacom_features wacom_features_0x28 =
  3799. { "Wacom Intuos5 touch L", 65024, 40640, 2047, 63,
  3800. INTUOS5L, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16 };
  3801. static const struct wacom_features wacom_features_0x29 =
  3802. { "Wacom Intuos5 S", 31496, 19685, 2047, 63,
  3803. INTUOS5S, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7 };
  3804. static const struct wacom_features wacom_features_0x2A =
  3805. { "Wacom Intuos5 M", 44704, 27940, 2047, 63,
  3806. INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9 };
  3807. static const struct wacom_features wacom_features_0x314 =
  3808. { "Wacom Intuos Pro S", 31496, 19685, 2047, 63,
  3809. INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7, .touch_max = 16,
  3810. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3811. static const struct wacom_features wacom_features_0x315 =
  3812. { "Wacom Intuos Pro M", 44704, 27940, 2047, 63,
  3813. INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
  3814. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3815. static const struct wacom_features wacom_features_0x317 =
  3816. { "Wacom Intuos Pro L", 65024, 40640, 2047, 63,
  3817. INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 16,
  3818. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3819. static const struct wacom_features wacom_features_0xF4 =
  3820. { "Wacom Cintiq 24HD", 104480, 65600, 2047, 63,
  3821. WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
  3822. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3823. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  3824. static const struct wacom_features wacom_features_0xF8 =
  3825. { "Wacom Cintiq 24HD touch", 104480, 65600, 2047, 63, /* Pen */
  3826. WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 16,
  3827. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3828. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3829. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf6 };
  3830. static const struct wacom_features wacom_features_0xF6 =
  3831. { "Wacom Cintiq 24HD touch", .type = WACOM_24HDT, /* Touch */
  3832. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0xf8, .touch_max = 10,
  3833. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3834. static const struct wacom_features wacom_features_0x32A =
  3835. { "Wacom Cintiq 27QHD", 120140, 67920, 2047, 63,
  3836. WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
  3837. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3838. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  3839. static const struct wacom_features wacom_features_0x32B =
  3840. { "Wacom Cintiq 27QHD touch", 120140, 67920, 2047, 63,
  3841. WACOM_27QHD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 0,
  3842. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3843. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3844. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32C };
  3845. static const struct wacom_features wacom_features_0x32C =
  3846. { "Wacom Cintiq 27QHD touch", .type = WACOM_27QHDT,
  3847. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x32B, .touch_max = 10 };
  3848. static const struct wacom_features wacom_features_0x3F =
  3849. { "Wacom Cintiq 21UX", 87200, 65600, 1023, 63,
  3850. CINTIQ, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 8 };
  3851. static const struct wacom_features wacom_features_0xC5 =
  3852. { "Wacom Cintiq 20WSX", 86680, 54180, 1023, 63,
  3853. WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
  3854. static const struct wacom_features wacom_features_0xC6 =
  3855. { "Wacom Cintiq 12WX", 53020, 33440, 1023, 63,
  3856. WACOM_BEE, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 10 };
  3857. static const struct wacom_features wacom_features_0x304 =
  3858. { "Wacom Cintiq 13HD", 59552, 33848, 1023, 63,
  3859. WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  3860. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3861. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  3862. static const struct wacom_features wacom_features_0x333 =
  3863. { "Wacom Cintiq 13HD touch", 59552, 33848, 2047, 63,
  3864. WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  3865. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3866. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3867. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
  3868. static const struct wacom_features wacom_features_0x335 =
  3869. { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
  3870. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
  3871. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3872. static const struct wacom_features wacom_features_0xC7 =
  3873. { "Wacom DTU1931", 37832, 30305, 511, 0,
  3874. PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3875. static const struct wacom_features wacom_features_0xCE =
  3876. { "Wacom DTU2231", 47864, 27011, 511, 0,
  3877. DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  3878. .check_for_hid_type = true, .hid_type = HID_TYPE_USBMOUSE };
  3879. static const struct wacom_features wacom_features_0xF0 =
  3880. { "Wacom DTU1631", 34623, 19553, 511, 0,
  3881. DTU, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3882. static const struct wacom_features wacom_features_0xFB =
  3883. { "Wacom DTU1031", 22096, 13960, 511, 0,
  3884. DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
  3885. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
  3886. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  3887. static const struct wacom_features wacom_features_0x32F =
  3888. { "Wacom DTU1031X", 22672, 12928, 511, 0,
  3889. DTUSX, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 0,
  3890. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
  3891. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  3892. static const struct wacom_features wacom_features_0x336 =
  3893. { "Wacom DTU1141", 23672, 13403, 1023, 0,
  3894. DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
  3895. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
  3896. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  3897. static const struct wacom_features wacom_features_0x57 =
  3898. { "Wacom DTK2241", 95840, 54260, 2047, 63,
  3899. DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
  3900. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3901. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  3902. static const struct wacom_features wacom_features_0x59 = /* Pen */
  3903. { "Wacom DTH2242", 95840, 54260, 2047, 63,
  3904. DTK, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 6,
  3905. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3906. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3907. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5D };
  3908. static const struct wacom_features wacom_features_0x5D = /* Touch */
  3909. { "Wacom DTH2242", .type = WACOM_24HDT,
  3910. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x59, .touch_max = 10,
  3911. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3912. static const struct wacom_features wacom_features_0xCC =
  3913. { "Wacom Cintiq 21UX2", 87200, 65600, 2047, 63,
  3914. WACOM_21UX2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
  3915. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3916. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  3917. static const struct wacom_features wacom_features_0xFA =
  3918. { "Wacom Cintiq 22HD", 95840, 54260, 2047, 63,
  3919. WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
  3920. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3921. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
  3922. static const struct wacom_features wacom_features_0x5B =
  3923. { "Wacom Cintiq 22HDT", 95840, 54260, 2047, 63,
  3924. WACOM_22HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 18,
  3925. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3926. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  3927. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5e };
  3928. static const struct wacom_features wacom_features_0x5E =
  3929. { "Wacom Cintiq 22HDT", .type = WACOM_24HDT,
  3930. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x5b, .touch_max = 10,
  3931. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  3932. static const struct wacom_features wacom_features_0x90 =
  3933. { "Wacom ISDv4 90", 26202, 16325, 255, 0,
  3934. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
  3935. static const struct wacom_features wacom_features_0x93 =
  3936. { "Wacom ISDv4 93", 26202, 16325, 255, 0,
  3937. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
  3938. static const struct wacom_features wacom_features_0x97 =
  3939. { "Wacom ISDv4 97", 26202, 16325, 511, 0,
  3940. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
  3941. static const struct wacom_features wacom_features_0x9A =
  3942. { "Wacom ISDv4 9A", 26202, 16325, 255, 0,
  3943. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
  3944. static const struct wacom_features wacom_features_0x9F =
  3945. { "Wacom ISDv4 9F", 26202, 16325, 255, 0,
  3946. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
  3947. static const struct wacom_features wacom_features_0xE2 =
  3948. { "Wacom ISDv4 E2", 26202, 16325, 255, 0,
  3949. TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  3950. static const struct wacom_features wacom_features_0xE3 =
  3951. { "Wacom ISDv4 E3", 26202, 16325, 255, 0,
  3952. TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  3953. static const struct wacom_features wacom_features_0xE5 =
  3954. { "Wacom ISDv4 E5", 26202, 16325, 255, 0,
  3955. MTSCREEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3956. static const struct wacom_features wacom_features_0xE6 =
  3957. { "Wacom ISDv4 E6", 27760, 15694, 255, 0,
  3958. TABLETPC2FG, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  3959. static const struct wacom_features wacom_features_0xEC =
  3960. { "Wacom ISDv4 EC", 25710, 14500, 255, 0,
  3961. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
  3962. static const struct wacom_features wacom_features_0xED =
  3963. { "Wacom ISDv4 ED", 26202, 16325, 255, 0,
  3964. TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
  3965. static const struct wacom_features wacom_features_0xEF =
  3966. { "Wacom ISDv4 EF", 26202, 16325, 255, 0,
  3967. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
  3968. static const struct wacom_features wacom_features_0x100 =
  3969. { "Wacom ISDv4 100", 26202, 16325, 255, 0,
  3970. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3971. static const struct wacom_features wacom_features_0x101 =
  3972. { "Wacom ISDv4 101", 26202, 16325, 255, 0,
  3973. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3974. static const struct wacom_features wacom_features_0x10D =
  3975. { "Wacom ISDv4 10D", 26202, 16325, 255, 0,
  3976. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3977. static const struct wacom_features wacom_features_0x10E =
  3978. { "Wacom ISDv4 10E", 27760, 15694, 255, 0,
  3979. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3980. static const struct wacom_features wacom_features_0x10F =
  3981. { "Wacom ISDv4 10F", 27760, 15694, 255, 0,
  3982. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3983. static const struct wacom_features wacom_features_0x116 =
  3984. { "Wacom ISDv4 116", 26202, 16325, 255, 0,
  3985. TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 1 };
  3986. static const struct wacom_features wacom_features_0x12C =
  3987. { "Wacom ISDv4 12C", 27848, 15752, 2047, 0,
  3988. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; /* Pen-only */
  3989. static const struct wacom_features wacom_features_0x4001 =
  3990. { "Wacom ISDv4 4001", 26202, 16325, 255, 0,
  3991. MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3992. static const struct wacom_features wacom_features_0x4004 =
  3993. { "Wacom ISDv4 4004", 11060, 6220, 255, 0,
  3994. MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3995. static const struct wacom_features wacom_features_0x5000 =
  3996. { "Wacom ISDv4 5000", 27848, 15752, 1023, 0,
  3997. MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  3998. static const struct wacom_features wacom_features_0x5002 =
  3999. { "Wacom ISDv4 5002", 29576, 16724, 1023, 0,
  4000. MTTPC_B, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4001. static const struct wacom_features wacom_features_0x47 =
  4002. { "Wacom Intuos2 6x8", 20320, 16240, 1023, 31,
  4003. INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4004. static const struct wacom_features wacom_features_0x84 =
  4005. { "Wacom Wireless Receiver", .type = WIRELESS, .touch_max = 16 };
  4006. static const struct wacom_features wacom_features_0xD0 =
  4007. { "Wacom Bamboo 2FG", 14720, 9200, 1023, 31,
  4008. BAMBOO_TOUCH, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4009. static const struct wacom_features wacom_features_0xD1 =
  4010. { "Wacom Bamboo 2FG 4x5", 14720, 9200, 1023, 31,
  4011. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4012. static const struct wacom_features wacom_features_0xD2 =
  4013. { "Wacom Bamboo Craft", 14720, 9200, 1023, 31,
  4014. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4015. static const struct wacom_features wacom_features_0xD3 =
  4016. { "Wacom Bamboo 2FG 6x8", 21648, 13700, 1023, 31,
  4017. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4018. static const struct wacom_features wacom_features_0xD4 =
  4019. { "Wacom Bamboo Pen", 14720, 9200, 1023, 31,
  4020. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4021. static const struct wacom_features wacom_features_0xD5 =
  4022. { "Wacom Bamboo Pen 6x8", 21648, 13700, 1023, 31,
  4023. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4024. static const struct wacom_features wacom_features_0xD6 =
  4025. { "Wacom BambooPT 2FG 4x5", 14720, 9200, 1023, 31,
  4026. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4027. static const struct wacom_features wacom_features_0xD7 =
  4028. { "Wacom BambooPT 2FG Small", 14720, 9200, 1023, 31,
  4029. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4030. static const struct wacom_features wacom_features_0xD8 =
  4031. { "Wacom Bamboo Comic 2FG", 21648, 13700, 1023, 31,
  4032. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4033. static const struct wacom_features wacom_features_0xDA =
  4034. { "Wacom Bamboo 2FG 4x5 SE", 14720, 9200, 1023, 31,
  4035. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4036. static const struct wacom_features wacom_features_0xDB =
  4037. { "Wacom Bamboo 2FG 6x8 SE", 21648, 13700, 1023, 31,
  4038. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 2 };
  4039. static const struct wacom_features wacom_features_0xDD =
  4040. { "Wacom Bamboo Connect", 14720, 9200, 1023, 31,
  4041. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4042. static const struct wacom_features wacom_features_0xDE =
  4043. { "Wacom Bamboo 16FG 4x5", 14720, 9200, 1023, 31,
  4044. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
  4045. static const struct wacom_features wacom_features_0xDF =
  4046. { "Wacom Bamboo 16FG 6x8", 21648, 13700, 1023, 31,
  4047. BAMBOO_PT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16 };
  4048. static const struct wacom_features wacom_features_0x300 =
  4049. { "Wacom Bamboo One S", 14720, 9225, 1023, 31,
  4050. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4051. static const struct wacom_features wacom_features_0x301 =
  4052. { "Wacom Bamboo One M", 21648, 13530, 1023, 31,
  4053. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4054. static const struct wacom_features wacom_features_0x302 =
  4055. { "Wacom Intuos PT S", 15200, 9500, 1023, 31,
  4056. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  4057. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4058. static const struct wacom_features wacom_features_0x303 =
  4059. { "Wacom Intuos PT M", 21600, 13500, 1023, 31,
  4060. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  4061. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4062. static const struct wacom_features wacom_features_0x30E =
  4063. { "Wacom Intuos S", 15200, 9500, 1023, 31,
  4064. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  4065. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4066. static const struct wacom_features wacom_features_0x6004 =
  4067. { "ISD-V4", 12800, 8000, 255, 0,
  4068. TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4069. static const struct wacom_features wacom_features_0x307 =
  4070. { "Wacom ISDv5 307", 59552, 33848, 2047, 63,
  4071. CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  4072. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  4073. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  4074. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
  4075. static const struct wacom_features wacom_features_0x309 =
  4076. { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
  4077. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10,
  4078. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4079. static const struct wacom_features wacom_features_0x30A =
  4080. { "Wacom ISDv5 30A", 59552, 33848, 2047, 63,
  4081. CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9,
  4082. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  4083. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  4084. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30C };
  4085. static const struct wacom_features wacom_features_0x30C =
  4086. { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
  4087. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
  4088. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4089. static const struct wacom_features wacom_features_0x318 =
  4090. { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
  4091. .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
  4092. static const struct wacom_features wacom_features_0x319 =
  4093. { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
  4094. .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
  4095. static const struct wacom_features wacom_features_0x325 =
  4096. { "Wacom ISDv5 325", 59552, 33848, 2047, 63,
  4097. CINTIQ_COMPANION_2, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 11,
  4098. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  4099. WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
  4100. .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x326 };
  4101. static const struct wacom_features wacom_features_0x326 = /* Touch */
  4102. { "Wacom ISDv5 326", .type = HID_GENERIC, .oVid = USB_VENDOR_ID_WACOM,
  4103. .oPid = 0x325 };
  4104. static const struct wacom_features wacom_features_0x323 =
  4105. { "Wacom Intuos P M", 21600, 13500, 1023, 31,
  4106. INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  4107. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4108. static const struct wacom_features wacom_features_0x331 =
  4109. { "Wacom Express Key Remote", .type = REMOTE,
  4110. .numbered_buttons = 18, .check_for_hid_type = true,
  4111. .hid_type = HID_TYPE_USBNONE };
  4112. static const struct wacom_features wacom_features_0x33B =
  4113. { "Wacom Intuos S 2", 15200, 9500, 2047, 63,
  4114. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  4115. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4116. static const struct wacom_features wacom_features_0x33C =
  4117. { "Wacom Intuos PT S 2", 15200, 9500, 2047, 63,
  4118. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  4119. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4120. static const struct wacom_features wacom_features_0x33D =
  4121. { "Wacom Intuos P M 2", 21600, 13500, 2047, 63,
  4122. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
  4123. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4124. static const struct wacom_features wacom_features_0x33E =
  4125. { "Wacom Intuos PT M 2", 21600, 13500, 2047, 63,
  4126. INTUOSHT2, WACOM_INTUOS_RES, WACOM_INTUOS_RES, .touch_max = 16,
  4127. .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
  4128. static const struct wacom_features wacom_features_0x343 =
  4129. { "Wacom DTK1651", 34816, 19759, 1023, 0,
  4130. DTUS, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4,
  4131. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET,
  4132. WACOM_DTU_OFFSET, WACOM_DTU_OFFSET };
  4133. static const struct wacom_features wacom_features_0x360 =
  4134. { "Wacom Intuos Pro M", 44800, 29600, 8191, 63,
  4135. INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
  4136. static const struct wacom_features wacom_features_0x361 =
  4137. { "Wacom Intuos Pro L", 62200, 43200, 8191, 63,
  4138. INTUOSP2_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 9, .touch_max = 10 };
  4139. static const struct wacom_features wacom_features_0x377 =
  4140. { "Wacom Intuos BT S", 15200, 9500, 4095, 63,
  4141. INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
  4142. static const struct wacom_features wacom_features_0x379 =
  4143. { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
  4144. INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
  4145. static const struct wacom_features wacom_features_0x37A =
  4146. { "Wacom One by Wacom S", 15200, 9500, 2047, 63,
  4147. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4148. static const struct wacom_features wacom_features_0x37B =
  4149. { "Wacom One by Wacom M", 21600, 13500, 2047, 63,
  4150. BAMBOO_PEN, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
  4151. static const struct wacom_features wacom_features_0x393 =
  4152. { "Wacom Intuos Pro S", 31920, 19950, 8191, 63,
  4153. INTUOSP2S_BT, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 7,
  4154. .touch_max = 10 };
  4155. static const struct wacom_features wacom_features_0x3c6 =
  4156. { "Wacom Intuos BT S", 15200, 9500, 4095, 63,
  4157. INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
  4158. static const struct wacom_features wacom_features_0x3c8 =
  4159. { "Wacom Intuos BT M", 21600, 13500, 4095, 63,
  4160. INTUOSHT3_BT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 4 };
  4161. static const struct wacom_features wacom_features_HID_ANY_ID =
  4162. { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
  4163. #define USB_DEVICE_WACOM(prod) \
  4164. HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
  4165. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  4166. #define BT_DEVICE_WACOM(prod) \
  4167. HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
  4168. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  4169. #define I2C_DEVICE_WACOM(prod) \
  4170. HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
  4171. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  4172. #define USB_DEVICE_LENOVO(prod) \
  4173. HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
  4174. .driver_data = (kernel_ulong_t)&wacom_features_##prod
  4175. const struct hid_device_id wacom_ids[] = {
  4176. { USB_DEVICE_WACOM(0x00) },
  4177. { USB_DEVICE_WACOM(0x03) },
  4178. { USB_DEVICE_WACOM(0x10) },
  4179. { USB_DEVICE_WACOM(0x11) },
  4180. { USB_DEVICE_WACOM(0x12) },
  4181. { USB_DEVICE_WACOM(0x13) },
  4182. { USB_DEVICE_WACOM(0x14) },
  4183. { USB_DEVICE_WACOM(0x15) },
  4184. { USB_DEVICE_WACOM(0x16) },
  4185. { USB_DEVICE_WACOM(0x17) },
  4186. { USB_DEVICE_WACOM(0x18) },
  4187. { USB_DEVICE_WACOM(0x19) },
  4188. { USB_DEVICE_WACOM(0x20) },
  4189. { USB_DEVICE_WACOM(0x21) },
  4190. { USB_DEVICE_WACOM(0x22) },
  4191. { USB_DEVICE_WACOM(0x23) },
  4192. { USB_DEVICE_WACOM(0x24) },
  4193. { USB_DEVICE_WACOM(0x26) },
  4194. { USB_DEVICE_WACOM(0x27) },
  4195. { USB_DEVICE_WACOM(0x28) },
  4196. { USB_DEVICE_WACOM(0x29) },
  4197. { USB_DEVICE_WACOM(0x2A) },
  4198. { USB_DEVICE_WACOM(0x30) },
  4199. { USB_DEVICE_WACOM(0x31) },
  4200. { USB_DEVICE_WACOM(0x32) },
  4201. { USB_DEVICE_WACOM(0x33) },
  4202. { USB_DEVICE_WACOM(0x34) },
  4203. { USB_DEVICE_WACOM(0x35) },
  4204. { USB_DEVICE_WACOM(0x37) },
  4205. { USB_DEVICE_WACOM(0x38) },
  4206. { USB_DEVICE_WACOM(0x39) },
  4207. { USB_DEVICE_WACOM(0x3F) },
  4208. { USB_DEVICE_WACOM(0x41) },
  4209. { USB_DEVICE_WACOM(0x42) },
  4210. { USB_DEVICE_WACOM(0x43) },
  4211. { USB_DEVICE_WACOM(0x44) },
  4212. { USB_DEVICE_WACOM(0x45) },
  4213. { USB_DEVICE_WACOM(0x47) },
  4214. { USB_DEVICE_WACOM(0x57) },
  4215. { USB_DEVICE_WACOM(0x59) },
  4216. { USB_DEVICE_WACOM(0x5B) },
  4217. { USB_DEVICE_WACOM(0x5D) },
  4218. { USB_DEVICE_WACOM(0x5E) },
  4219. { USB_DEVICE_WACOM(0x60) },
  4220. { USB_DEVICE_WACOM(0x61) },
  4221. { USB_DEVICE_WACOM(0x62) },
  4222. { USB_DEVICE_WACOM(0x63) },
  4223. { USB_DEVICE_WACOM(0x64) },
  4224. { USB_DEVICE_WACOM(0x65) },
  4225. { USB_DEVICE_WACOM(0x69) },
  4226. { USB_DEVICE_WACOM(0x6A) },
  4227. { USB_DEVICE_WACOM(0x6B) },
  4228. { BT_DEVICE_WACOM(0x81) },
  4229. { USB_DEVICE_WACOM(0x84) },
  4230. { USB_DEVICE_WACOM(0x90) },
  4231. { USB_DEVICE_WACOM(0x93) },
  4232. { USB_DEVICE_WACOM(0x97) },
  4233. { USB_DEVICE_WACOM(0x9A) },
  4234. { USB_DEVICE_WACOM(0x9F) },
  4235. { USB_DEVICE_WACOM(0xB0) },
  4236. { USB_DEVICE_WACOM(0xB1) },
  4237. { USB_DEVICE_WACOM(0xB2) },
  4238. { USB_DEVICE_WACOM(0xB3) },
  4239. { USB_DEVICE_WACOM(0xB4) },
  4240. { USB_DEVICE_WACOM(0xB5) },
  4241. { USB_DEVICE_WACOM(0xB7) },
  4242. { USB_DEVICE_WACOM(0xB8) },
  4243. { USB_DEVICE_WACOM(0xB9) },
  4244. { USB_DEVICE_WACOM(0xBA) },
  4245. { USB_DEVICE_WACOM(0xBB) },
  4246. { USB_DEVICE_WACOM(0xBC) },
  4247. { BT_DEVICE_WACOM(0xBD) },
  4248. { USB_DEVICE_WACOM(0xC0) },
  4249. { USB_DEVICE_WACOM(0xC2) },
  4250. { USB_DEVICE_WACOM(0xC4) },
  4251. { USB_DEVICE_WACOM(0xC5) },
  4252. { USB_DEVICE_WACOM(0xC6) },
  4253. { USB_DEVICE_WACOM(0xC7) },
  4254. { USB_DEVICE_WACOM(0xCC) },
  4255. { USB_DEVICE_WACOM(0xCE) },
  4256. { USB_DEVICE_WACOM(0xD0) },
  4257. { USB_DEVICE_WACOM(0xD1) },
  4258. { USB_DEVICE_WACOM(0xD2) },
  4259. { USB_DEVICE_WACOM(0xD3) },
  4260. { USB_DEVICE_WACOM(0xD4) },
  4261. { USB_DEVICE_WACOM(0xD5) },
  4262. { USB_DEVICE_WACOM(0xD6) },
  4263. { USB_DEVICE_WACOM(0xD7) },
  4264. { USB_DEVICE_WACOM(0xD8) },
  4265. { USB_DEVICE_WACOM(0xDA) },
  4266. { USB_DEVICE_WACOM(0xDB) },
  4267. { USB_DEVICE_WACOM(0xDD) },
  4268. { USB_DEVICE_WACOM(0xDE) },
  4269. { USB_DEVICE_WACOM(0xDF) },
  4270. { USB_DEVICE_WACOM(0xE2) },
  4271. { USB_DEVICE_WACOM(0xE3) },
  4272. { USB_DEVICE_WACOM(0xE5) },
  4273. { USB_DEVICE_WACOM(0xE6) },
  4274. { USB_DEVICE_WACOM(0xEC) },
  4275. { USB_DEVICE_WACOM(0xED) },
  4276. { USB_DEVICE_WACOM(0xEF) },
  4277. { USB_DEVICE_WACOM(0xF0) },
  4278. { USB_DEVICE_WACOM(0xF4) },
  4279. { USB_DEVICE_WACOM(0xF6) },
  4280. { USB_DEVICE_WACOM(0xF8) },
  4281. { USB_DEVICE_WACOM(0xFA) },
  4282. { USB_DEVICE_WACOM(0xFB) },
  4283. { USB_DEVICE_WACOM(0x100) },
  4284. { USB_DEVICE_WACOM(0x101) },
  4285. { USB_DEVICE_WACOM(0x10D) },
  4286. { USB_DEVICE_WACOM(0x10E) },
  4287. { USB_DEVICE_WACOM(0x10F) },
  4288. { USB_DEVICE_WACOM(0x116) },
  4289. { USB_DEVICE_WACOM(0x12C) },
  4290. { USB_DEVICE_WACOM(0x300) },
  4291. { USB_DEVICE_WACOM(0x301) },
  4292. { USB_DEVICE_WACOM(0x302) },
  4293. { USB_DEVICE_WACOM(0x303) },
  4294. { USB_DEVICE_WACOM(0x304) },
  4295. { USB_DEVICE_WACOM(0x307) },
  4296. { USB_DEVICE_WACOM(0x309) },
  4297. { USB_DEVICE_WACOM(0x30A) },
  4298. { USB_DEVICE_WACOM(0x30C) },
  4299. { USB_DEVICE_WACOM(0x30E) },
  4300. { USB_DEVICE_WACOM(0x314) },
  4301. { USB_DEVICE_WACOM(0x315) },
  4302. { USB_DEVICE_WACOM(0x317) },
  4303. { USB_DEVICE_WACOM(0x318) },
  4304. { USB_DEVICE_WACOM(0x319) },
  4305. { USB_DEVICE_WACOM(0x323) },
  4306. { USB_DEVICE_WACOM(0x325) },
  4307. { USB_DEVICE_WACOM(0x326) },
  4308. { USB_DEVICE_WACOM(0x32A) },
  4309. { USB_DEVICE_WACOM(0x32B) },
  4310. { USB_DEVICE_WACOM(0x32C) },
  4311. { USB_DEVICE_WACOM(0x32F) },
  4312. { USB_DEVICE_WACOM(0x331) },
  4313. { USB_DEVICE_WACOM(0x333) },
  4314. { USB_DEVICE_WACOM(0x335) },
  4315. { USB_DEVICE_WACOM(0x336) },
  4316. { USB_DEVICE_WACOM(0x33B) },
  4317. { USB_DEVICE_WACOM(0x33C) },
  4318. { USB_DEVICE_WACOM(0x33D) },
  4319. { USB_DEVICE_WACOM(0x33E) },
  4320. { USB_DEVICE_WACOM(0x343) },
  4321. { BT_DEVICE_WACOM(0x360) },
  4322. { BT_DEVICE_WACOM(0x361) },
  4323. { BT_DEVICE_WACOM(0x377) },
  4324. { BT_DEVICE_WACOM(0x379) },
  4325. { USB_DEVICE_WACOM(0x37A) },
  4326. { USB_DEVICE_WACOM(0x37B) },
  4327. { BT_DEVICE_WACOM(0x393) },
  4328. { BT_DEVICE_WACOM(0x3c6) },
  4329. { BT_DEVICE_WACOM(0x3c8) },
  4330. { USB_DEVICE_WACOM(0x4001) },
  4331. { USB_DEVICE_WACOM(0x4004) },
  4332. { USB_DEVICE_WACOM(0x5000) },
  4333. { USB_DEVICE_WACOM(0x5002) },
  4334. { USB_DEVICE_LENOVO(0x6004) },
  4335. { USB_DEVICE_WACOM(HID_ANY_ID) },
  4336. { I2C_DEVICE_WACOM(HID_ANY_ID) },
  4337. { BT_DEVICE_WACOM(HID_ANY_ID) },
  4338. { }
  4339. };
  4340. MODULE_DEVICE_TABLE(hid, wacom_ids);