wacom_wac.c 160 KB

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