wacom_wac.c 158 KB

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