wacom_wac.c 129 KB

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