iqs7222.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Azoteq IQS7222A/B/C/D Capacitive Touch Controller
  4. *
  5. * Copyright (C) 2022 Jeff LaBundy <jeff@labundy.com>
  6. */
  7. #include <linux/bits.h>
  8. #include <linux/delay.h>
  9. #include <linux/device.h>
  10. #include <linux/err.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/i2c.h>
  13. #include <linux/input.h>
  14. #include <linux/input/touchscreen.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <linux/ktime.h>
  18. #include <linux/mod_devicetable.h>
  19. #include <linux/module.h>
  20. #include <linux/property.h>
  21. #include <linux/slab.h>
  22. #include <linux/unaligned.h>
  23. #define IQS7222_PROD_NUM 0x00
  24. #define IQS7222_PROD_NUM_A 840
  25. #define IQS7222_PROD_NUM_B 698
  26. #define IQS7222_PROD_NUM_C 863
  27. #define IQS7222_PROD_NUM_D 1046
  28. #define IQS7222_SYS_STATUS 0x10
  29. #define IQS7222_SYS_STATUS_RESET BIT(3)
  30. #define IQS7222_SYS_STATUS_ATI_ERROR BIT(1)
  31. #define IQS7222_SYS_STATUS_ATI_ACTIVE BIT(0)
  32. #define IQS7222_CHAN_SETUP_0_REF_MODE_MASK GENMASK(15, 14)
  33. #define IQS7222_CHAN_SETUP_0_REF_MODE_FOLLOW BIT(15)
  34. #define IQS7222_CHAN_SETUP_0_REF_MODE_REF BIT(14)
  35. #define IQS7222_CHAN_SETUP_0_CHAN_EN BIT(8)
  36. #define IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK GENMASK(2, 0)
  37. #define IQS7222_SLDR_SETUP_2_RES_MASK GENMASK(15, 8)
  38. #define IQS7222_SLDR_SETUP_2_RES_SHIFT 8
  39. #define IQS7222_SLDR_SETUP_2_TOP_SPEED_MASK GENMASK(7, 0)
  40. #define IQS7222_GPIO_SETUP_0_GPIO_EN BIT(0)
  41. #define IQS7222_SYS_SETUP 0xD0
  42. #define IQS7222_SYS_SETUP_INTF_MODE_MASK GENMASK(7, 6)
  43. #define IQS7222_SYS_SETUP_INTF_MODE_TOUCH BIT(7)
  44. #define IQS7222_SYS_SETUP_INTF_MODE_EVENT BIT(6)
  45. #define IQS7222_SYS_SETUP_PWR_MODE_MASK GENMASK(5, 4)
  46. #define IQS7222_SYS_SETUP_PWR_MODE_AUTO IQS7222_SYS_SETUP_PWR_MODE_MASK
  47. #define IQS7222_SYS_SETUP_REDO_ATI BIT(2)
  48. #define IQS7222_SYS_SETUP_ACK_RESET BIT(0)
  49. #define IQS7222_EVENT_MASK_ATI BIT(12)
  50. #define IQS7222_EVENT_MASK_SLDR BIT(10)
  51. #define IQS7222_EVENT_MASK_TPAD IQS7222_EVENT_MASK_SLDR
  52. #define IQS7222_EVENT_MASK_TOUCH BIT(1)
  53. #define IQS7222_EVENT_MASK_PROX BIT(0)
  54. #define IQS7222_COMMS_HOLD BIT(0)
  55. #define IQS7222_COMMS_ERROR 0xEEEE
  56. #define IQS7222_COMMS_RETRY_MS 50
  57. #define IQS7222_COMMS_TIMEOUT_MS 100
  58. #define IQS7222_RESET_TIMEOUT_MS 250
  59. #define IQS7222_ATI_TIMEOUT_MS 2000
  60. #define IQS7222_MAX_COLS_STAT 8
  61. #define IQS7222_MAX_COLS_CYCLE 3
  62. #define IQS7222_MAX_COLS_GLBL 3
  63. #define IQS7222_MAX_COLS_BTN 3
  64. #define IQS7222_MAX_COLS_CHAN 6
  65. #define IQS7222_MAX_COLS_FILT 2
  66. #define IQS7222_MAX_COLS_SLDR 11
  67. #define IQS7222_MAX_COLS_TPAD 24
  68. #define IQS7222_MAX_COLS_GPIO 3
  69. #define IQS7222_MAX_COLS_SYS 13
  70. #define IQS7222_MAX_CHAN 20
  71. #define IQS7222_MAX_SLDR 2
  72. #define IQS7222_NUM_RETRIES 5
  73. #define IQS7222_REG_OFFSET 0x100
  74. enum iqs7222_reg_key_id {
  75. IQS7222_REG_KEY_NONE,
  76. IQS7222_REG_KEY_PROX,
  77. IQS7222_REG_KEY_TOUCH,
  78. IQS7222_REG_KEY_DEBOUNCE,
  79. IQS7222_REG_KEY_TAP,
  80. IQS7222_REG_KEY_TAP_LEGACY,
  81. IQS7222_REG_KEY_AXIAL,
  82. IQS7222_REG_KEY_AXIAL_LEGACY,
  83. IQS7222_REG_KEY_WHEEL,
  84. IQS7222_REG_KEY_NO_WHEEL,
  85. IQS7222_REG_KEY_RESERVED
  86. };
  87. enum iqs7222_reg_grp_id {
  88. IQS7222_REG_GRP_STAT,
  89. IQS7222_REG_GRP_CYCLE,
  90. IQS7222_REG_GRP_GLBL,
  91. IQS7222_REG_GRP_BTN,
  92. IQS7222_REG_GRP_CHAN,
  93. IQS7222_REG_GRP_FILT,
  94. IQS7222_REG_GRP_SLDR,
  95. IQS7222_REG_GRP_TPAD,
  96. IQS7222_REG_GRP_GPIO,
  97. IQS7222_REG_GRP_SYS,
  98. IQS7222_NUM_REG_GRPS
  99. };
  100. static const char * const iqs7222_reg_grp_names[IQS7222_NUM_REG_GRPS] = {
  101. [IQS7222_REG_GRP_CYCLE] = "cycle-%d",
  102. [IQS7222_REG_GRP_CHAN] = "channel-%d",
  103. [IQS7222_REG_GRP_SLDR] = "slider-%d",
  104. [IQS7222_REG_GRP_TPAD] = "trackpad",
  105. [IQS7222_REG_GRP_GPIO] = "gpio-%d",
  106. };
  107. static const unsigned int iqs7222_max_cols[IQS7222_NUM_REG_GRPS] = {
  108. [IQS7222_REG_GRP_STAT] = IQS7222_MAX_COLS_STAT,
  109. [IQS7222_REG_GRP_CYCLE] = IQS7222_MAX_COLS_CYCLE,
  110. [IQS7222_REG_GRP_GLBL] = IQS7222_MAX_COLS_GLBL,
  111. [IQS7222_REG_GRP_BTN] = IQS7222_MAX_COLS_BTN,
  112. [IQS7222_REG_GRP_CHAN] = IQS7222_MAX_COLS_CHAN,
  113. [IQS7222_REG_GRP_FILT] = IQS7222_MAX_COLS_FILT,
  114. [IQS7222_REG_GRP_SLDR] = IQS7222_MAX_COLS_SLDR,
  115. [IQS7222_REG_GRP_TPAD] = IQS7222_MAX_COLS_TPAD,
  116. [IQS7222_REG_GRP_GPIO] = IQS7222_MAX_COLS_GPIO,
  117. [IQS7222_REG_GRP_SYS] = IQS7222_MAX_COLS_SYS,
  118. };
  119. static const unsigned int iqs7222_gpio_links[] = { 2, 5, 6, };
  120. struct iqs7222_event_desc {
  121. const char *name;
  122. u16 link;
  123. u16 mask;
  124. u16 val;
  125. u16 strict;
  126. u16 enable;
  127. enum iqs7222_reg_key_id reg_key;
  128. };
  129. static const struct iqs7222_event_desc iqs7222_kp_events[] = {
  130. {
  131. .name = "event-prox",
  132. .enable = IQS7222_EVENT_MASK_PROX,
  133. .reg_key = IQS7222_REG_KEY_PROX,
  134. },
  135. {
  136. .name = "event-touch",
  137. .enable = IQS7222_EVENT_MASK_TOUCH,
  138. .reg_key = IQS7222_REG_KEY_TOUCH,
  139. },
  140. };
  141. static const struct iqs7222_event_desc iqs7222_sl_events[] = {
  142. { .name = "event-press", },
  143. {
  144. .name = "event-tap",
  145. .mask = BIT(0),
  146. .val = BIT(0),
  147. .enable = BIT(0),
  148. .reg_key = IQS7222_REG_KEY_TAP,
  149. },
  150. {
  151. .name = "event-swipe-pos",
  152. .mask = BIT(5) | BIT(1),
  153. .val = BIT(1),
  154. .enable = BIT(1),
  155. .reg_key = IQS7222_REG_KEY_AXIAL,
  156. },
  157. {
  158. .name = "event-swipe-neg",
  159. .mask = BIT(5) | BIT(1),
  160. .val = BIT(5) | BIT(1),
  161. .enable = BIT(1),
  162. .reg_key = IQS7222_REG_KEY_AXIAL,
  163. },
  164. {
  165. .name = "event-flick-pos",
  166. .mask = BIT(5) | BIT(2),
  167. .val = BIT(2),
  168. .enable = BIT(2),
  169. .reg_key = IQS7222_REG_KEY_AXIAL,
  170. },
  171. {
  172. .name = "event-flick-neg",
  173. .mask = BIT(5) | BIT(2),
  174. .val = BIT(5) | BIT(2),
  175. .enable = BIT(2),
  176. .reg_key = IQS7222_REG_KEY_AXIAL,
  177. },
  178. };
  179. static const struct iqs7222_event_desc iqs7222_tp_events[] = {
  180. {
  181. .name = "event-press",
  182. .link = BIT(7),
  183. },
  184. {
  185. .name = "event-tap",
  186. .link = BIT(0),
  187. .mask = BIT(0),
  188. .val = BIT(0),
  189. .enable = BIT(0),
  190. .reg_key = IQS7222_REG_KEY_TAP,
  191. },
  192. {
  193. .name = "event-swipe-x-pos",
  194. .link = BIT(2),
  195. .mask = BIT(2) | BIT(1),
  196. .val = BIT(2),
  197. .strict = BIT(4),
  198. .enable = BIT(1),
  199. .reg_key = IQS7222_REG_KEY_AXIAL,
  200. },
  201. {
  202. .name = "event-swipe-y-pos",
  203. .link = BIT(3),
  204. .mask = BIT(3) | BIT(1),
  205. .val = BIT(3),
  206. .strict = BIT(3),
  207. .enable = BIT(1),
  208. .reg_key = IQS7222_REG_KEY_AXIAL,
  209. },
  210. {
  211. .name = "event-swipe-x-neg",
  212. .link = BIT(4),
  213. .mask = BIT(4) | BIT(1),
  214. .val = BIT(4),
  215. .strict = BIT(4),
  216. .enable = BIT(1),
  217. .reg_key = IQS7222_REG_KEY_AXIAL,
  218. },
  219. {
  220. .name = "event-swipe-y-neg",
  221. .link = BIT(5),
  222. .mask = BIT(5) | BIT(1),
  223. .val = BIT(5),
  224. .strict = BIT(3),
  225. .enable = BIT(1),
  226. .reg_key = IQS7222_REG_KEY_AXIAL,
  227. },
  228. {
  229. .name = "event-flick-x-pos",
  230. .link = BIT(2),
  231. .mask = BIT(2) | BIT(1),
  232. .val = BIT(2) | BIT(1),
  233. .strict = BIT(4),
  234. .enable = BIT(2),
  235. .reg_key = IQS7222_REG_KEY_AXIAL,
  236. },
  237. {
  238. .name = "event-flick-y-pos",
  239. .link = BIT(3),
  240. .mask = BIT(3) | BIT(1),
  241. .val = BIT(3) | BIT(1),
  242. .strict = BIT(3),
  243. .enable = BIT(2),
  244. .reg_key = IQS7222_REG_KEY_AXIAL,
  245. },
  246. {
  247. .name = "event-flick-x-neg",
  248. .link = BIT(4),
  249. .mask = BIT(4) | BIT(1),
  250. .val = BIT(4) | BIT(1),
  251. .strict = BIT(4),
  252. .enable = BIT(2),
  253. .reg_key = IQS7222_REG_KEY_AXIAL,
  254. },
  255. {
  256. .name = "event-flick-y-neg",
  257. .link = BIT(5),
  258. .mask = BIT(5) | BIT(1),
  259. .val = BIT(5) | BIT(1),
  260. .strict = BIT(3),
  261. .enable = BIT(2),
  262. .reg_key = IQS7222_REG_KEY_AXIAL,
  263. },
  264. };
  265. struct iqs7222_reg_grp_desc {
  266. u16 base;
  267. u16 val_len;
  268. int num_row;
  269. int num_col;
  270. };
  271. struct iqs7222_dev_desc {
  272. u16 prod_num;
  273. u16 fw_major;
  274. u16 fw_minor;
  275. u16 sldr_res;
  276. u16 touch_link;
  277. u16 wheel_enable;
  278. int allow_offset;
  279. int event_offset;
  280. int comms_offset;
  281. int ext_chan;
  282. bool legacy_gesture;
  283. struct iqs7222_reg_grp_desc reg_grps[IQS7222_NUM_REG_GRPS];
  284. };
  285. static const struct iqs7222_dev_desc iqs7222_devs[] = {
  286. {
  287. .prod_num = IQS7222_PROD_NUM_A,
  288. .fw_major = 1,
  289. .fw_minor = 13,
  290. .sldr_res = U8_MAX * 16,
  291. .touch_link = 1768,
  292. .allow_offset = 9,
  293. .event_offset = 10,
  294. .comms_offset = 12,
  295. .ext_chan = 10,
  296. .reg_grps = {
  297. [IQS7222_REG_GRP_STAT] = {
  298. .base = IQS7222_SYS_STATUS,
  299. .num_row = 1,
  300. .num_col = 8,
  301. },
  302. [IQS7222_REG_GRP_CYCLE] = {
  303. .base = 0x8000,
  304. .num_row = 7,
  305. .num_col = 3,
  306. },
  307. [IQS7222_REG_GRP_GLBL] = {
  308. .base = 0x8700,
  309. .num_row = 1,
  310. .num_col = 3,
  311. },
  312. [IQS7222_REG_GRP_BTN] = {
  313. .base = 0x9000,
  314. .num_row = 12,
  315. .num_col = 3,
  316. },
  317. [IQS7222_REG_GRP_CHAN] = {
  318. .base = 0xA000,
  319. .num_row = 12,
  320. .num_col = 6,
  321. },
  322. [IQS7222_REG_GRP_FILT] = {
  323. .base = 0xAC00,
  324. .val_len = 3,
  325. .num_row = 1,
  326. .num_col = 2,
  327. },
  328. [IQS7222_REG_GRP_SLDR] = {
  329. .base = 0xB000,
  330. .num_row = 2,
  331. .num_col = 11,
  332. },
  333. [IQS7222_REG_GRP_GPIO] = {
  334. .base = 0xC000,
  335. .num_row = 1,
  336. .num_col = 3,
  337. },
  338. [IQS7222_REG_GRP_SYS] = {
  339. .base = IQS7222_SYS_SETUP,
  340. .num_row = 1,
  341. .num_col = 13,
  342. },
  343. },
  344. },
  345. {
  346. .prod_num = IQS7222_PROD_NUM_A,
  347. .fw_major = 1,
  348. .fw_minor = 12,
  349. .sldr_res = U8_MAX * 16,
  350. .touch_link = 1768,
  351. .allow_offset = 9,
  352. .event_offset = 10,
  353. .comms_offset = 12,
  354. .ext_chan = 10,
  355. .legacy_gesture = true,
  356. .reg_grps = {
  357. [IQS7222_REG_GRP_STAT] = {
  358. .base = IQS7222_SYS_STATUS,
  359. .num_row = 1,
  360. .num_col = 8,
  361. },
  362. [IQS7222_REG_GRP_CYCLE] = {
  363. .base = 0x8000,
  364. .num_row = 7,
  365. .num_col = 3,
  366. },
  367. [IQS7222_REG_GRP_GLBL] = {
  368. .base = 0x8700,
  369. .num_row = 1,
  370. .num_col = 3,
  371. },
  372. [IQS7222_REG_GRP_BTN] = {
  373. .base = 0x9000,
  374. .num_row = 12,
  375. .num_col = 3,
  376. },
  377. [IQS7222_REG_GRP_CHAN] = {
  378. .base = 0xA000,
  379. .num_row = 12,
  380. .num_col = 6,
  381. },
  382. [IQS7222_REG_GRP_FILT] = {
  383. .base = 0xAC00,
  384. .val_len = 3,
  385. .num_row = 1,
  386. .num_col = 2,
  387. },
  388. [IQS7222_REG_GRP_SLDR] = {
  389. .base = 0xB000,
  390. .num_row = 2,
  391. .num_col = 11,
  392. },
  393. [IQS7222_REG_GRP_GPIO] = {
  394. .base = 0xC000,
  395. .num_row = 1,
  396. .num_col = 3,
  397. },
  398. [IQS7222_REG_GRP_SYS] = {
  399. .base = IQS7222_SYS_SETUP,
  400. .num_row = 1,
  401. .num_col = 13,
  402. },
  403. },
  404. },
  405. {
  406. .prod_num = IQS7222_PROD_NUM_B,
  407. .fw_major = 1,
  408. .fw_minor = 43,
  409. .event_offset = 10,
  410. .comms_offset = 11,
  411. .reg_grps = {
  412. [IQS7222_REG_GRP_STAT] = {
  413. .base = IQS7222_SYS_STATUS,
  414. .num_row = 1,
  415. .num_col = 6,
  416. },
  417. [IQS7222_REG_GRP_CYCLE] = {
  418. .base = 0x8000,
  419. .num_row = 10,
  420. .num_col = 2,
  421. },
  422. [IQS7222_REG_GRP_GLBL] = {
  423. .base = 0x8A00,
  424. .num_row = 1,
  425. .num_col = 3,
  426. },
  427. [IQS7222_REG_GRP_BTN] = {
  428. .base = 0x9000,
  429. .num_row = 20,
  430. .num_col = 2,
  431. },
  432. [IQS7222_REG_GRP_CHAN] = {
  433. .base = 0xB000,
  434. .num_row = 20,
  435. .num_col = 4,
  436. },
  437. [IQS7222_REG_GRP_FILT] = {
  438. .base = 0xC400,
  439. .val_len = 3,
  440. .num_row = 1,
  441. .num_col = 2,
  442. },
  443. [IQS7222_REG_GRP_SYS] = {
  444. .base = IQS7222_SYS_SETUP,
  445. .num_row = 1,
  446. .num_col = 13,
  447. },
  448. },
  449. },
  450. {
  451. .prod_num = IQS7222_PROD_NUM_B,
  452. .fw_major = 1,
  453. .fw_minor = 27,
  454. .reg_grps = {
  455. [IQS7222_REG_GRP_STAT] = {
  456. .base = IQS7222_SYS_STATUS,
  457. .num_row = 1,
  458. .num_col = 6,
  459. },
  460. [IQS7222_REG_GRP_CYCLE] = {
  461. .base = 0x8000,
  462. .num_row = 10,
  463. .num_col = 2,
  464. },
  465. [IQS7222_REG_GRP_GLBL] = {
  466. .base = 0x8A00,
  467. .num_row = 1,
  468. .num_col = 3,
  469. },
  470. [IQS7222_REG_GRP_BTN] = {
  471. .base = 0x9000,
  472. .num_row = 20,
  473. .num_col = 2,
  474. },
  475. [IQS7222_REG_GRP_CHAN] = {
  476. .base = 0xB000,
  477. .num_row = 20,
  478. .num_col = 4,
  479. },
  480. [IQS7222_REG_GRP_FILT] = {
  481. .base = 0xC400,
  482. .val_len = 3,
  483. .num_row = 1,
  484. .num_col = 2,
  485. },
  486. [IQS7222_REG_GRP_SYS] = {
  487. .base = IQS7222_SYS_SETUP,
  488. .num_row = 1,
  489. .num_col = 10,
  490. },
  491. },
  492. },
  493. {
  494. .prod_num = IQS7222_PROD_NUM_C,
  495. .fw_major = 2,
  496. .fw_minor = 6,
  497. .sldr_res = U16_MAX,
  498. .touch_link = 1686,
  499. .wheel_enable = BIT(3),
  500. .event_offset = 9,
  501. .comms_offset = 10,
  502. .reg_grps = {
  503. [IQS7222_REG_GRP_STAT] = {
  504. .base = IQS7222_SYS_STATUS,
  505. .num_row = 1,
  506. .num_col = 6,
  507. },
  508. [IQS7222_REG_GRP_CYCLE] = {
  509. .base = 0x8000,
  510. .num_row = 5,
  511. .num_col = 3,
  512. },
  513. [IQS7222_REG_GRP_GLBL] = {
  514. .base = 0x8500,
  515. .num_row = 1,
  516. .num_col = 3,
  517. },
  518. [IQS7222_REG_GRP_BTN] = {
  519. .base = 0x9000,
  520. .num_row = 10,
  521. .num_col = 3,
  522. },
  523. [IQS7222_REG_GRP_CHAN] = {
  524. .base = 0xA000,
  525. .num_row = 10,
  526. .num_col = 6,
  527. },
  528. [IQS7222_REG_GRP_FILT] = {
  529. .base = 0xAA00,
  530. .val_len = 3,
  531. .num_row = 1,
  532. .num_col = 2,
  533. },
  534. [IQS7222_REG_GRP_SLDR] = {
  535. .base = 0xB000,
  536. .num_row = 2,
  537. .num_col = 10,
  538. },
  539. [IQS7222_REG_GRP_GPIO] = {
  540. .base = 0xC000,
  541. .num_row = 3,
  542. .num_col = 3,
  543. },
  544. [IQS7222_REG_GRP_SYS] = {
  545. .base = IQS7222_SYS_SETUP,
  546. .num_row = 1,
  547. .num_col = 12,
  548. },
  549. },
  550. },
  551. {
  552. .prod_num = IQS7222_PROD_NUM_C,
  553. .fw_major = 1,
  554. .fw_minor = 13,
  555. .sldr_res = U16_MAX,
  556. .touch_link = 1674,
  557. .wheel_enable = BIT(3),
  558. .event_offset = 9,
  559. .comms_offset = 10,
  560. .reg_grps = {
  561. [IQS7222_REG_GRP_STAT] = {
  562. .base = IQS7222_SYS_STATUS,
  563. .num_row = 1,
  564. .num_col = 6,
  565. },
  566. [IQS7222_REG_GRP_CYCLE] = {
  567. .base = 0x8000,
  568. .num_row = 5,
  569. .num_col = 3,
  570. },
  571. [IQS7222_REG_GRP_GLBL] = {
  572. .base = 0x8500,
  573. .num_row = 1,
  574. .num_col = 3,
  575. },
  576. [IQS7222_REG_GRP_BTN] = {
  577. .base = 0x9000,
  578. .num_row = 10,
  579. .num_col = 3,
  580. },
  581. [IQS7222_REG_GRP_CHAN] = {
  582. .base = 0xA000,
  583. .num_row = 10,
  584. .num_col = 6,
  585. },
  586. [IQS7222_REG_GRP_FILT] = {
  587. .base = 0xAA00,
  588. .val_len = 3,
  589. .num_row = 1,
  590. .num_col = 2,
  591. },
  592. [IQS7222_REG_GRP_SLDR] = {
  593. .base = 0xB000,
  594. .num_row = 2,
  595. .num_col = 10,
  596. },
  597. [IQS7222_REG_GRP_GPIO] = {
  598. .base = 0xC000,
  599. .num_row = 1,
  600. .num_col = 3,
  601. },
  602. [IQS7222_REG_GRP_SYS] = {
  603. .base = IQS7222_SYS_SETUP,
  604. .num_row = 1,
  605. .num_col = 11,
  606. },
  607. },
  608. },
  609. {
  610. .prod_num = IQS7222_PROD_NUM_D,
  611. .fw_major = 1,
  612. .fw_minor = 2,
  613. .touch_link = 1770,
  614. .allow_offset = 9,
  615. .event_offset = 10,
  616. .comms_offset = 11,
  617. .reg_grps = {
  618. [IQS7222_REG_GRP_STAT] = {
  619. .base = IQS7222_SYS_STATUS,
  620. .num_row = 1,
  621. .num_col = 7,
  622. },
  623. [IQS7222_REG_GRP_CYCLE] = {
  624. .base = 0x8000,
  625. .num_row = 7,
  626. .num_col = 2,
  627. },
  628. [IQS7222_REG_GRP_GLBL] = {
  629. .base = 0x8700,
  630. .num_row = 1,
  631. .num_col = 3,
  632. },
  633. [IQS7222_REG_GRP_BTN] = {
  634. .base = 0x9000,
  635. .num_row = 14,
  636. .num_col = 3,
  637. },
  638. [IQS7222_REG_GRP_CHAN] = {
  639. .base = 0xA000,
  640. .num_row = 14,
  641. .num_col = 4,
  642. },
  643. [IQS7222_REG_GRP_FILT] = {
  644. .base = 0xAE00,
  645. .val_len = 3,
  646. .num_row = 1,
  647. .num_col = 2,
  648. },
  649. [IQS7222_REG_GRP_TPAD] = {
  650. .base = 0xB000,
  651. .num_row = 1,
  652. .num_col = 24,
  653. },
  654. [IQS7222_REG_GRP_GPIO] = {
  655. .base = 0xC000,
  656. .num_row = 3,
  657. .num_col = 3,
  658. },
  659. [IQS7222_REG_GRP_SYS] = {
  660. .base = IQS7222_SYS_SETUP,
  661. .num_row = 1,
  662. .num_col = 12,
  663. },
  664. },
  665. },
  666. {
  667. .prod_num = IQS7222_PROD_NUM_D,
  668. .fw_major = 1,
  669. .fw_minor = 1,
  670. .touch_link = 1774,
  671. .allow_offset = 9,
  672. .event_offset = 10,
  673. .comms_offset = 11,
  674. .reg_grps = {
  675. [IQS7222_REG_GRP_STAT] = {
  676. .base = IQS7222_SYS_STATUS,
  677. .num_row = 1,
  678. .num_col = 7,
  679. },
  680. [IQS7222_REG_GRP_CYCLE] = {
  681. .base = 0x8000,
  682. .num_row = 7,
  683. .num_col = 2,
  684. },
  685. [IQS7222_REG_GRP_GLBL] = {
  686. .base = 0x8700,
  687. .num_row = 1,
  688. .num_col = 3,
  689. },
  690. [IQS7222_REG_GRP_BTN] = {
  691. .base = 0x9000,
  692. .num_row = 14,
  693. .num_col = 3,
  694. },
  695. [IQS7222_REG_GRP_CHAN] = {
  696. .base = 0xA000,
  697. .num_row = 14,
  698. .num_col = 4,
  699. },
  700. [IQS7222_REG_GRP_FILT] = {
  701. .base = 0xAE00,
  702. .val_len = 3,
  703. .num_row = 1,
  704. .num_col = 2,
  705. },
  706. [IQS7222_REG_GRP_TPAD] = {
  707. .base = 0xB000,
  708. .num_row = 1,
  709. .num_col = 24,
  710. },
  711. [IQS7222_REG_GRP_GPIO] = {
  712. .base = 0xC000,
  713. .num_row = 3,
  714. .num_col = 3,
  715. },
  716. [IQS7222_REG_GRP_SYS] = {
  717. .base = IQS7222_SYS_SETUP,
  718. .num_row = 1,
  719. .num_col = 12,
  720. },
  721. },
  722. },
  723. {
  724. .prod_num = IQS7222_PROD_NUM_D,
  725. .fw_major = 0,
  726. .fw_minor = 37,
  727. .touch_link = 1770,
  728. .allow_offset = 9,
  729. .event_offset = 10,
  730. .comms_offset = 11,
  731. .reg_grps = {
  732. [IQS7222_REG_GRP_STAT] = {
  733. .base = IQS7222_SYS_STATUS,
  734. .num_row = 1,
  735. .num_col = 7,
  736. },
  737. [IQS7222_REG_GRP_CYCLE] = {
  738. .base = 0x8000,
  739. .num_row = 7,
  740. .num_col = 2,
  741. },
  742. [IQS7222_REG_GRP_GLBL] = {
  743. .base = 0x8700,
  744. .num_row = 1,
  745. .num_col = 3,
  746. },
  747. [IQS7222_REG_GRP_BTN] = {
  748. .base = 0x9000,
  749. .num_row = 14,
  750. .num_col = 3,
  751. },
  752. [IQS7222_REG_GRP_CHAN] = {
  753. .base = 0xA000,
  754. .num_row = 14,
  755. .num_col = 4,
  756. },
  757. [IQS7222_REG_GRP_FILT] = {
  758. .base = 0xAE00,
  759. .val_len = 3,
  760. .num_row = 1,
  761. .num_col = 2,
  762. },
  763. [IQS7222_REG_GRP_TPAD] = {
  764. .base = 0xB000,
  765. .num_row = 1,
  766. .num_col = 24,
  767. },
  768. [IQS7222_REG_GRP_GPIO] = {
  769. .base = 0xC000,
  770. .num_row = 3,
  771. .num_col = 3,
  772. },
  773. [IQS7222_REG_GRP_SYS] = {
  774. .base = IQS7222_SYS_SETUP,
  775. .num_row = 1,
  776. .num_col = 12,
  777. },
  778. },
  779. },
  780. };
  781. struct iqs7222_prop_desc {
  782. const char *name;
  783. enum iqs7222_reg_grp_id reg_grp;
  784. enum iqs7222_reg_key_id reg_key;
  785. int reg_offset;
  786. int reg_shift;
  787. int reg_width;
  788. int val_pitch;
  789. int val_min;
  790. int val_max;
  791. bool invert;
  792. const char *label;
  793. };
  794. static const struct iqs7222_prop_desc iqs7222_props[] = {
  795. {
  796. .name = "azoteq,conv-period",
  797. .reg_grp = IQS7222_REG_GRP_CYCLE,
  798. .reg_offset = 0,
  799. .reg_shift = 8,
  800. .reg_width = 8,
  801. .label = "conversion period",
  802. },
  803. {
  804. .name = "azoteq,conv-frac",
  805. .reg_grp = IQS7222_REG_GRP_CYCLE,
  806. .reg_offset = 0,
  807. .reg_shift = 0,
  808. .reg_width = 8,
  809. .label = "conversion frequency fractional divider",
  810. },
  811. {
  812. .name = "azoteq,rx-float-inactive",
  813. .reg_grp = IQS7222_REG_GRP_CYCLE,
  814. .reg_offset = 1,
  815. .reg_shift = 6,
  816. .reg_width = 1,
  817. .invert = true,
  818. },
  819. {
  820. .name = "azoteq,dead-time-enable",
  821. .reg_grp = IQS7222_REG_GRP_CYCLE,
  822. .reg_offset = 1,
  823. .reg_shift = 5,
  824. .reg_width = 1,
  825. },
  826. {
  827. .name = "azoteq,tx-freq-fosc",
  828. .reg_grp = IQS7222_REG_GRP_CYCLE,
  829. .reg_offset = 1,
  830. .reg_shift = 4,
  831. .reg_width = 1,
  832. },
  833. {
  834. .name = "azoteq,vbias-enable",
  835. .reg_grp = IQS7222_REG_GRP_CYCLE,
  836. .reg_offset = 1,
  837. .reg_shift = 3,
  838. .reg_width = 1,
  839. },
  840. {
  841. .name = "azoteq,sense-mode",
  842. .reg_grp = IQS7222_REG_GRP_CYCLE,
  843. .reg_offset = 1,
  844. .reg_shift = 0,
  845. .reg_width = 3,
  846. .val_max = 3,
  847. .label = "sensing mode",
  848. },
  849. {
  850. .name = "azoteq,iref-enable",
  851. .reg_grp = IQS7222_REG_GRP_CYCLE,
  852. .reg_offset = 2,
  853. .reg_shift = 10,
  854. .reg_width = 1,
  855. },
  856. {
  857. .name = "azoteq,iref-level",
  858. .reg_grp = IQS7222_REG_GRP_CYCLE,
  859. .reg_offset = 2,
  860. .reg_shift = 4,
  861. .reg_width = 4,
  862. .label = "current reference level",
  863. },
  864. {
  865. .name = "azoteq,iref-trim",
  866. .reg_grp = IQS7222_REG_GRP_CYCLE,
  867. .reg_offset = 2,
  868. .reg_shift = 0,
  869. .reg_width = 4,
  870. .label = "current reference trim",
  871. },
  872. {
  873. .name = "azoteq,max-counts",
  874. .reg_grp = IQS7222_REG_GRP_GLBL,
  875. .reg_offset = 0,
  876. .reg_shift = 13,
  877. .reg_width = 2,
  878. .label = "maximum counts",
  879. },
  880. {
  881. .name = "azoteq,auto-mode",
  882. .reg_grp = IQS7222_REG_GRP_GLBL,
  883. .reg_offset = 0,
  884. .reg_shift = 2,
  885. .reg_width = 2,
  886. .label = "number of conversions",
  887. },
  888. {
  889. .name = "azoteq,ati-frac-div-fine",
  890. .reg_grp = IQS7222_REG_GRP_GLBL,
  891. .reg_offset = 1,
  892. .reg_shift = 9,
  893. .reg_width = 5,
  894. .label = "ATI fine fractional divider",
  895. },
  896. {
  897. .name = "azoteq,ati-frac-div-coarse",
  898. .reg_grp = IQS7222_REG_GRP_GLBL,
  899. .reg_offset = 1,
  900. .reg_shift = 0,
  901. .reg_width = 5,
  902. .label = "ATI coarse fractional divider",
  903. },
  904. {
  905. .name = "azoteq,ati-comp-select",
  906. .reg_grp = IQS7222_REG_GRP_GLBL,
  907. .reg_offset = 2,
  908. .reg_shift = 0,
  909. .reg_width = 10,
  910. .label = "ATI compensation selection",
  911. },
  912. {
  913. .name = "azoteq,ati-band",
  914. .reg_grp = IQS7222_REG_GRP_CHAN,
  915. .reg_offset = 0,
  916. .reg_shift = 12,
  917. .reg_width = 2,
  918. .label = "ATI band",
  919. },
  920. {
  921. .name = "azoteq,global-halt",
  922. .reg_grp = IQS7222_REG_GRP_CHAN,
  923. .reg_offset = 0,
  924. .reg_shift = 11,
  925. .reg_width = 1,
  926. },
  927. {
  928. .name = "azoteq,invert-enable",
  929. .reg_grp = IQS7222_REG_GRP_CHAN,
  930. .reg_offset = 0,
  931. .reg_shift = 10,
  932. .reg_width = 1,
  933. },
  934. {
  935. .name = "azoteq,dual-direction",
  936. .reg_grp = IQS7222_REG_GRP_CHAN,
  937. .reg_offset = 0,
  938. .reg_shift = 9,
  939. .reg_width = 1,
  940. },
  941. {
  942. .name = "azoteq,samp-cap-double",
  943. .reg_grp = IQS7222_REG_GRP_CHAN,
  944. .reg_offset = 0,
  945. .reg_shift = 3,
  946. .reg_width = 1,
  947. },
  948. {
  949. .name = "azoteq,vref-half",
  950. .reg_grp = IQS7222_REG_GRP_CHAN,
  951. .reg_offset = 0,
  952. .reg_shift = 2,
  953. .reg_width = 1,
  954. },
  955. {
  956. .name = "azoteq,proj-bias",
  957. .reg_grp = IQS7222_REG_GRP_CHAN,
  958. .reg_offset = 0,
  959. .reg_shift = 0,
  960. .reg_width = 2,
  961. .label = "projected bias current",
  962. },
  963. {
  964. .name = "azoteq,ati-target",
  965. .reg_grp = IQS7222_REG_GRP_CHAN,
  966. .reg_offset = 1,
  967. .reg_shift = 8,
  968. .reg_width = 8,
  969. .val_pitch = 8,
  970. .label = "ATI target",
  971. },
  972. {
  973. .name = "azoteq,ati-base",
  974. .reg_grp = IQS7222_REG_GRP_CHAN,
  975. .reg_offset = 1,
  976. .reg_shift = 3,
  977. .reg_width = 5,
  978. .val_pitch = 16,
  979. .label = "ATI base",
  980. },
  981. {
  982. .name = "azoteq,ati-mode",
  983. .reg_grp = IQS7222_REG_GRP_CHAN,
  984. .reg_offset = 1,
  985. .reg_shift = 0,
  986. .reg_width = 3,
  987. .val_max = 5,
  988. .label = "ATI mode",
  989. },
  990. {
  991. .name = "azoteq,ati-frac-div-fine",
  992. .reg_grp = IQS7222_REG_GRP_CHAN,
  993. .reg_offset = 2,
  994. .reg_shift = 9,
  995. .reg_width = 5,
  996. .label = "ATI fine fractional divider",
  997. },
  998. {
  999. .name = "azoteq,ati-frac-mult-coarse",
  1000. .reg_grp = IQS7222_REG_GRP_CHAN,
  1001. .reg_offset = 2,
  1002. .reg_shift = 5,
  1003. .reg_width = 4,
  1004. .label = "ATI coarse fractional multiplier",
  1005. },
  1006. {
  1007. .name = "azoteq,ati-frac-div-coarse",
  1008. .reg_grp = IQS7222_REG_GRP_CHAN,
  1009. .reg_offset = 2,
  1010. .reg_shift = 0,
  1011. .reg_width = 5,
  1012. .label = "ATI coarse fractional divider",
  1013. },
  1014. {
  1015. .name = "azoteq,ati-comp-div",
  1016. .reg_grp = IQS7222_REG_GRP_CHAN,
  1017. .reg_offset = 3,
  1018. .reg_shift = 11,
  1019. .reg_width = 5,
  1020. .label = "ATI compensation divider",
  1021. },
  1022. {
  1023. .name = "azoteq,ati-comp-select",
  1024. .reg_grp = IQS7222_REG_GRP_CHAN,
  1025. .reg_offset = 3,
  1026. .reg_shift = 0,
  1027. .reg_width = 10,
  1028. .label = "ATI compensation selection",
  1029. },
  1030. {
  1031. .name = "azoteq,debounce-exit",
  1032. .reg_grp = IQS7222_REG_GRP_BTN,
  1033. .reg_key = IQS7222_REG_KEY_DEBOUNCE,
  1034. .reg_offset = 0,
  1035. .reg_shift = 12,
  1036. .reg_width = 4,
  1037. .label = "debounce exit factor",
  1038. },
  1039. {
  1040. .name = "azoteq,debounce-enter",
  1041. .reg_grp = IQS7222_REG_GRP_BTN,
  1042. .reg_key = IQS7222_REG_KEY_DEBOUNCE,
  1043. .reg_offset = 0,
  1044. .reg_shift = 8,
  1045. .reg_width = 4,
  1046. .label = "debounce entrance factor",
  1047. },
  1048. {
  1049. .name = "azoteq,thresh",
  1050. .reg_grp = IQS7222_REG_GRP_BTN,
  1051. .reg_key = IQS7222_REG_KEY_PROX,
  1052. .reg_offset = 0,
  1053. .reg_shift = 0,
  1054. .reg_width = 8,
  1055. .val_max = 127,
  1056. .label = "threshold",
  1057. },
  1058. {
  1059. .name = "azoteq,thresh",
  1060. .reg_grp = IQS7222_REG_GRP_BTN,
  1061. .reg_key = IQS7222_REG_KEY_TOUCH,
  1062. .reg_offset = 1,
  1063. .reg_shift = 0,
  1064. .reg_width = 8,
  1065. .label = "threshold",
  1066. },
  1067. {
  1068. .name = "azoteq,hyst",
  1069. .reg_grp = IQS7222_REG_GRP_BTN,
  1070. .reg_key = IQS7222_REG_KEY_TOUCH,
  1071. .reg_offset = 1,
  1072. .reg_shift = 8,
  1073. .reg_width = 8,
  1074. .label = "hysteresis",
  1075. },
  1076. {
  1077. .name = "azoteq,lta-beta-lp",
  1078. .reg_grp = IQS7222_REG_GRP_FILT,
  1079. .reg_offset = 0,
  1080. .reg_shift = 12,
  1081. .reg_width = 4,
  1082. .label = "low-power mode long-term average beta",
  1083. },
  1084. {
  1085. .name = "azoteq,lta-beta-np",
  1086. .reg_grp = IQS7222_REG_GRP_FILT,
  1087. .reg_offset = 0,
  1088. .reg_shift = 8,
  1089. .reg_width = 4,
  1090. .label = "normal-power mode long-term average beta",
  1091. },
  1092. {
  1093. .name = "azoteq,counts-beta-lp",
  1094. .reg_grp = IQS7222_REG_GRP_FILT,
  1095. .reg_offset = 0,
  1096. .reg_shift = 4,
  1097. .reg_width = 4,
  1098. .label = "low-power mode counts beta",
  1099. },
  1100. {
  1101. .name = "azoteq,counts-beta-np",
  1102. .reg_grp = IQS7222_REG_GRP_FILT,
  1103. .reg_offset = 0,
  1104. .reg_shift = 0,
  1105. .reg_width = 4,
  1106. .label = "normal-power mode counts beta",
  1107. },
  1108. {
  1109. .name = "azoteq,lta-fast-beta-lp",
  1110. .reg_grp = IQS7222_REG_GRP_FILT,
  1111. .reg_offset = 1,
  1112. .reg_shift = 4,
  1113. .reg_width = 4,
  1114. .label = "low-power mode long-term average fast beta",
  1115. },
  1116. {
  1117. .name = "azoteq,lta-fast-beta-np",
  1118. .reg_grp = IQS7222_REG_GRP_FILT,
  1119. .reg_offset = 1,
  1120. .reg_shift = 0,
  1121. .reg_width = 4,
  1122. .label = "normal-power mode long-term average fast beta",
  1123. },
  1124. {
  1125. .name = "azoteq,lower-cal",
  1126. .reg_grp = IQS7222_REG_GRP_SLDR,
  1127. .reg_offset = 0,
  1128. .reg_shift = 8,
  1129. .reg_width = 8,
  1130. .label = "lower calibration",
  1131. },
  1132. {
  1133. .name = "azoteq,static-beta",
  1134. .reg_grp = IQS7222_REG_GRP_SLDR,
  1135. .reg_key = IQS7222_REG_KEY_NO_WHEEL,
  1136. .reg_offset = 0,
  1137. .reg_shift = 6,
  1138. .reg_width = 1,
  1139. },
  1140. {
  1141. .name = "azoteq,bottom-beta",
  1142. .reg_grp = IQS7222_REG_GRP_SLDR,
  1143. .reg_key = IQS7222_REG_KEY_NO_WHEEL,
  1144. .reg_offset = 0,
  1145. .reg_shift = 3,
  1146. .reg_width = 3,
  1147. .label = "bottom beta",
  1148. },
  1149. {
  1150. .name = "azoteq,static-beta",
  1151. .reg_grp = IQS7222_REG_GRP_SLDR,
  1152. .reg_key = IQS7222_REG_KEY_WHEEL,
  1153. .reg_offset = 0,
  1154. .reg_shift = 7,
  1155. .reg_width = 1,
  1156. },
  1157. {
  1158. .name = "azoteq,bottom-beta",
  1159. .reg_grp = IQS7222_REG_GRP_SLDR,
  1160. .reg_key = IQS7222_REG_KEY_WHEEL,
  1161. .reg_offset = 0,
  1162. .reg_shift = 4,
  1163. .reg_width = 3,
  1164. .label = "bottom beta",
  1165. },
  1166. {
  1167. .name = "azoteq,bottom-speed",
  1168. .reg_grp = IQS7222_REG_GRP_SLDR,
  1169. .reg_offset = 1,
  1170. .reg_shift = 8,
  1171. .reg_width = 8,
  1172. .label = "bottom speed",
  1173. },
  1174. {
  1175. .name = "azoteq,upper-cal",
  1176. .reg_grp = IQS7222_REG_GRP_SLDR,
  1177. .reg_offset = 1,
  1178. .reg_shift = 0,
  1179. .reg_width = 8,
  1180. .label = "upper calibration",
  1181. },
  1182. {
  1183. .name = "azoteq,gesture-max-ms",
  1184. .reg_grp = IQS7222_REG_GRP_SLDR,
  1185. .reg_key = IQS7222_REG_KEY_TAP,
  1186. .reg_offset = 9,
  1187. .reg_shift = 8,
  1188. .reg_width = 8,
  1189. .val_pitch = 16,
  1190. .label = "maximum gesture time",
  1191. },
  1192. {
  1193. .name = "azoteq,gesture-max-ms",
  1194. .reg_grp = IQS7222_REG_GRP_SLDR,
  1195. .reg_key = IQS7222_REG_KEY_TAP_LEGACY,
  1196. .reg_offset = 9,
  1197. .reg_shift = 8,
  1198. .reg_width = 8,
  1199. .val_pitch = 4,
  1200. .label = "maximum gesture time",
  1201. },
  1202. {
  1203. .name = "azoteq,gesture-min-ms",
  1204. .reg_grp = IQS7222_REG_GRP_SLDR,
  1205. .reg_key = IQS7222_REG_KEY_TAP,
  1206. .reg_offset = 9,
  1207. .reg_shift = 3,
  1208. .reg_width = 5,
  1209. .val_pitch = 16,
  1210. .label = "minimum gesture time",
  1211. },
  1212. {
  1213. .name = "azoteq,gesture-min-ms",
  1214. .reg_grp = IQS7222_REG_GRP_SLDR,
  1215. .reg_key = IQS7222_REG_KEY_TAP_LEGACY,
  1216. .reg_offset = 9,
  1217. .reg_shift = 3,
  1218. .reg_width = 5,
  1219. .val_pitch = 4,
  1220. .label = "minimum gesture time",
  1221. },
  1222. {
  1223. .name = "azoteq,gesture-dist",
  1224. .reg_grp = IQS7222_REG_GRP_SLDR,
  1225. .reg_key = IQS7222_REG_KEY_AXIAL,
  1226. .reg_offset = 10,
  1227. .reg_shift = 8,
  1228. .reg_width = 8,
  1229. .val_pitch = 16,
  1230. .label = "gesture distance",
  1231. },
  1232. {
  1233. .name = "azoteq,gesture-dist",
  1234. .reg_grp = IQS7222_REG_GRP_SLDR,
  1235. .reg_key = IQS7222_REG_KEY_AXIAL_LEGACY,
  1236. .reg_offset = 10,
  1237. .reg_shift = 8,
  1238. .reg_width = 8,
  1239. .val_pitch = 16,
  1240. .label = "gesture distance",
  1241. },
  1242. {
  1243. .name = "azoteq,gesture-max-ms",
  1244. .reg_grp = IQS7222_REG_GRP_SLDR,
  1245. .reg_key = IQS7222_REG_KEY_AXIAL,
  1246. .reg_offset = 10,
  1247. .reg_shift = 0,
  1248. .reg_width = 8,
  1249. .val_pitch = 16,
  1250. .label = "maximum gesture time",
  1251. },
  1252. {
  1253. .name = "azoteq,gesture-max-ms",
  1254. .reg_grp = IQS7222_REG_GRP_SLDR,
  1255. .reg_key = IQS7222_REG_KEY_AXIAL_LEGACY,
  1256. .reg_offset = 10,
  1257. .reg_shift = 0,
  1258. .reg_width = 8,
  1259. .val_pitch = 4,
  1260. .label = "maximum gesture time",
  1261. },
  1262. {
  1263. .name = "azoteq,num-rows",
  1264. .reg_grp = IQS7222_REG_GRP_TPAD,
  1265. .reg_offset = 0,
  1266. .reg_shift = 4,
  1267. .reg_width = 4,
  1268. .val_min = 1,
  1269. .val_max = 12,
  1270. .label = "number of rows",
  1271. },
  1272. {
  1273. .name = "azoteq,num-cols",
  1274. .reg_grp = IQS7222_REG_GRP_TPAD,
  1275. .reg_offset = 0,
  1276. .reg_shift = 0,
  1277. .reg_width = 4,
  1278. .val_min = 1,
  1279. .val_max = 12,
  1280. .label = "number of columns",
  1281. },
  1282. {
  1283. .name = "azoteq,lower-cal-y",
  1284. .reg_grp = IQS7222_REG_GRP_TPAD,
  1285. .reg_offset = 1,
  1286. .reg_shift = 8,
  1287. .reg_width = 8,
  1288. .label = "lower vertical calibration",
  1289. },
  1290. {
  1291. .name = "azoteq,lower-cal-x",
  1292. .reg_grp = IQS7222_REG_GRP_TPAD,
  1293. .reg_offset = 1,
  1294. .reg_shift = 0,
  1295. .reg_width = 8,
  1296. .label = "lower horizontal calibration",
  1297. },
  1298. {
  1299. .name = "azoteq,upper-cal-y",
  1300. .reg_grp = IQS7222_REG_GRP_TPAD,
  1301. .reg_offset = 2,
  1302. .reg_shift = 8,
  1303. .reg_width = 8,
  1304. .label = "upper vertical calibration",
  1305. },
  1306. {
  1307. .name = "azoteq,upper-cal-x",
  1308. .reg_grp = IQS7222_REG_GRP_TPAD,
  1309. .reg_offset = 2,
  1310. .reg_shift = 0,
  1311. .reg_width = 8,
  1312. .label = "upper horizontal calibration",
  1313. },
  1314. {
  1315. .name = "azoteq,top-speed",
  1316. .reg_grp = IQS7222_REG_GRP_TPAD,
  1317. .reg_offset = 3,
  1318. .reg_shift = 8,
  1319. .reg_width = 8,
  1320. .val_pitch = 4,
  1321. .label = "top speed",
  1322. },
  1323. {
  1324. .name = "azoteq,bottom-speed",
  1325. .reg_grp = IQS7222_REG_GRP_TPAD,
  1326. .reg_offset = 3,
  1327. .reg_shift = 0,
  1328. .reg_width = 8,
  1329. .label = "bottom speed",
  1330. },
  1331. {
  1332. .name = "azoteq,gesture-min-ms",
  1333. .reg_grp = IQS7222_REG_GRP_TPAD,
  1334. .reg_key = IQS7222_REG_KEY_TAP,
  1335. .reg_offset = 20,
  1336. .reg_shift = 8,
  1337. .reg_width = 8,
  1338. .val_pitch = 16,
  1339. .label = "minimum gesture time",
  1340. },
  1341. {
  1342. .name = "azoteq,gesture-max-ms",
  1343. .reg_grp = IQS7222_REG_GRP_TPAD,
  1344. .reg_key = IQS7222_REG_KEY_AXIAL,
  1345. .reg_offset = 21,
  1346. .reg_shift = 8,
  1347. .reg_width = 8,
  1348. .val_pitch = 16,
  1349. .label = "maximum gesture time",
  1350. },
  1351. {
  1352. .name = "azoteq,gesture-max-ms",
  1353. .reg_grp = IQS7222_REG_GRP_TPAD,
  1354. .reg_key = IQS7222_REG_KEY_TAP,
  1355. .reg_offset = 21,
  1356. .reg_shift = 0,
  1357. .reg_width = 8,
  1358. .val_pitch = 16,
  1359. .label = "maximum gesture time",
  1360. },
  1361. {
  1362. .name = "azoteq,gesture-dist",
  1363. .reg_grp = IQS7222_REG_GRP_TPAD,
  1364. .reg_key = IQS7222_REG_KEY_TAP,
  1365. .reg_offset = 22,
  1366. .reg_shift = 0,
  1367. .reg_width = 16,
  1368. .label = "gesture distance",
  1369. },
  1370. {
  1371. .name = "azoteq,gesture-dist",
  1372. .reg_grp = IQS7222_REG_GRP_TPAD,
  1373. .reg_key = IQS7222_REG_KEY_AXIAL,
  1374. .reg_offset = 23,
  1375. .reg_shift = 0,
  1376. .reg_width = 16,
  1377. .label = "gesture distance",
  1378. },
  1379. {
  1380. .name = "drive-open-drain",
  1381. .reg_grp = IQS7222_REG_GRP_GPIO,
  1382. .reg_offset = 0,
  1383. .reg_shift = 1,
  1384. .reg_width = 1,
  1385. },
  1386. {
  1387. .name = "azoteq,timeout-ati-ms",
  1388. .reg_grp = IQS7222_REG_GRP_SYS,
  1389. .reg_offset = 1,
  1390. .reg_shift = 0,
  1391. .reg_width = 16,
  1392. .val_pitch = 500,
  1393. .label = "ATI error timeout",
  1394. },
  1395. {
  1396. .name = "azoteq,rate-ati-ms",
  1397. .reg_grp = IQS7222_REG_GRP_SYS,
  1398. .reg_offset = 2,
  1399. .reg_shift = 0,
  1400. .reg_width = 16,
  1401. .label = "ATI report rate",
  1402. },
  1403. {
  1404. .name = "azoteq,timeout-np-ms",
  1405. .reg_grp = IQS7222_REG_GRP_SYS,
  1406. .reg_offset = 3,
  1407. .reg_shift = 0,
  1408. .reg_width = 16,
  1409. .label = "normal-power mode timeout",
  1410. },
  1411. {
  1412. .name = "azoteq,rate-np-ms",
  1413. .reg_grp = IQS7222_REG_GRP_SYS,
  1414. .reg_offset = 4,
  1415. .reg_shift = 0,
  1416. .reg_width = 16,
  1417. .val_max = 3000,
  1418. .label = "normal-power mode report rate",
  1419. },
  1420. {
  1421. .name = "azoteq,timeout-lp-ms",
  1422. .reg_grp = IQS7222_REG_GRP_SYS,
  1423. .reg_offset = 5,
  1424. .reg_shift = 0,
  1425. .reg_width = 16,
  1426. .label = "low-power mode timeout",
  1427. },
  1428. {
  1429. .name = "azoteq,rate-lp-ms",
  1430. .reg_grp = IQS7222_REG_GRP_SYS,
  1431. .reg_offset = 6,
  1432. .reg_shift = 0,
  1433. .reg_width = 16,
  1434. .val_max = 3000,
  1435. .label = "low-power mode report rate",
  1436. },
  1437. {
  1438. .name = "azoteq,timeout-ulp-ms",
  1439. .reg_grp = IQS7222_REG_GRP_SYS,
  1440. .reg_offset = 7,
  1441. .reg_shift = 0,
  1442. .reg_width = 16,
  1443. .label = "ultra-low-power mode timeout",
  1444. },
  1445. {
  1446. .name = "azoteq,rate-ulp-ms",
  1447. .reg_grp = IQS7222_REG_GRP_SYS,
  1448. .reg_offset = 8,
  1449. .reg_shift = 0,
  1450. .reg_width = 16,
  1451. .val_max = 3000,
  1452. .label = "ultra-low-power mode report rate",
  1453. },
  1454. };
  1455. struct iqs7222_private {
  1456. const struct iqs7222_dev_desc *dev_desc;
  1457. struct gpio_desc *reset_gpio;
  1458. struct gpio_desc *irq_gpio;
  1459. struct i2c_client *client;
  1460. struct input_dev *keypad;
  1461. struct touchscreen_properties prop;
  1462. unsigned int kp_type[IQS7222_MAX_CHAN][ARRAY_SIZE(iqs7222_kp_events)];
  1463. unsigned int kp_code[IQS7222_MAX_CHAN][ARRAY_SIZE(iqs7222_kp_events)];
  1464. unsigned int sl_code[IQS7222_MAX_SLDR][ARRAY_SIZE(iqs7222_sl_events)];
  1465. unsigned int sl_axis[IQS7222_MAX_SLDR];
  1466. unsigned int tp_code[ARRAY_SIZE(iqs7222_tp_events)];
  1467. u16 cycle_setup[IQS7222_MAX_CHAN / 2][IQS7222_MAX_COLS_CYCLE];
  1468. u16 glbl_setup[IQS7222_MAX_COLS_GLBL];
  1469. u16 btn_setup[IQS7222_MAX_CHAN][IQS7222_MAX_COLS_BTN];
  1470. u16 chan_setup[IQS7222_MAX_CHAN][IQS7222_MAX_COLS_CHAN];
  1471. u16 filt_setup[IQS7222_MAX_COLS_FILT];
  1472. u16 sldr_setup[IQS7222_MAX_SLDR][IQS7222_MAX_COLS_SLDR];
  1473. u16 tpad_setup[IQS7222_MAX_COLS_TPAD];
  1474. u16 gpio_setup[ARRAY_SIZE(iqs7222_gpio_links)][IQS7222_MAX_COLS_GPIO];
  1475. u16 sys_setup[IQS7222_MAX_COLS_SYS];
  1476. };
  1477. static u16 *iqs7222_setup(struct iqs7222_private *iqs7222,
  1478. enum iqs7222_reg_grp_id reg_grp, int row)
  1479. {
  1480. switch (reg_grp) {
  1481. case IQS7222_REG_GRP_CYCLE:
  1482. return iqs7222->cycle_setup[row];
  1483. case IQS7222_REG_GRP_GLBL:
  1484. return iqs7222->glbl_setup;
  1485. case IQS7222_REG_GRP_BTN:
  1486. return iqs7222->btn_setup[row];
  1487. case IQS7222_REG_GRP_CHAN:
  1488. return iqs7222->chan_setup[row];
  1489. case IQS7222_REG_GRP_FILT:
  1490. return iqs7222->filt_setup;
  1491. case IQS7222_REG_GRP_SLDR:
  1492. return iqs7222->sldr_setup[row];
  1493. case IQS7222_REG_GRP_TPAD:
  1494. return iqs7222->tpad_setup;
  1495. case IQS7222_REG_GRP_GPIO:
  1496. return iqs7222->gpio_setup[row];
  1497. case IQS7222_REG_GRP_SYS:
  1498. return iqs7222->sys_setup;
  1499. default:
  1500. return NULL;
  1501. }
  1502. }
  1503. static int iqs7222_irq_poll(struct iqs7222_private *iqs7222, u16 timeout_ms)
  1504. {
  1505. ktime_t irq_timeout = ktime_add_ms(ktime_get(), timeout_ms);
  1506. int ret;
  1507. do {
  1508. usleep_range(1000, 1100);
  1509. ret = gpiod_get_value_cansleep(iqs7222->irq_gpio);
  1510. if (ret < 0)
  1511. return ret;
  1512. else if (ret > 0)
  1513. return 0;
  1514. } while (ktime_compare(ktime_get(), irq_timeout) < 0);
  1515. return -EBUSY;
  1516. }
  1517. static int iqs7222_hard_reset(struct iqs7222_private *iqs7222)
  1518. {
  1519. struct i2c_client *client = iqs7222->client;
  1520. int error;
  1521. if (!iqs7222->reset_gpio)
  1522. return 0;
  1523. gpiod_set_value_cansleep(iqs7222->reset_gpio, 1);
  1524. usleep_range(1000, 1100);
  1525. gpiod_set_value_cansleep(iqs7222->reset_gpio, 0);
  1526. error = iqs7222_irq_poll(iqs7222, IQS7222_RESET_TIMEOUT_MS);
  1527. if (error)
  1528. dev_err(&client->dev, "Failed to reset device: %d\n", error);
  1529. return error;
  1530. }
  1531. static int iqs7222_force_comms(struct iqs7222_private *iqs7222)
  1532. {
  1533. u8 msg_buf[] = { 0xFF, };
  1534. int ret;
  1535. /*
  1536. * The device cannot communicate until it asserts its interrupt (RDY)
  1537. * pin. Attempts to do so while RDY is deasserted return an ACK; how-
  1538. * ever all write data is ignored, and all read data returns 0xEE.
  1539. *
  1540. * Unsolicited communication must be preceded by a special force com-
  1541. * munication command, after which the device eventually asserts its
  1542. * RDY pin and agrees to communicate.
  1543. *
  1544. * Regardless of whether communication is forced or the result of an
  1545. * interrupt, the device automatically deasserts its RDY pin once it
  1546. * detects an I2C stop condition, or a timeout expires.
  1547. */
  1548. ret = gpiod_get_value_cansleep(iqs7222->irq_gpio);
  1549. if (ret < 0)
  1550. return ret;
  1551. else if (ret > 0)
  1552. return 0;
  1553. ret = i2c_master_send(iqs7222->client, msg_buf, sizeof(msg_buf));
  1554. if (ret < (int)sizeof(msg_buf)) {
  1555. if (ret >= 0)
  1556. ret = -EIO;
  1557. /*
  1558. * The datasheet states that the host must wait to retry any
  1559. * failed attempt to communicate over I2C.
  1560. */
  1561. msleep(IQS7222_COMMS_RETRY_MS);
  1562. return ret;
  1563. }
  1564. return iqs7222_irq_poll(iqs7222, IQS7222_COMMS_TIMEOUT_MS);
  1565. }
  1566. static int iqs7222_read_burst(struct iqs7222_private *iqs7222,
  1567. u16 reg, void *val, u16 val_len)
  1568. {
  1569. u8 reg_buf[sizeof(__be16)];
  1570. int ret, i;
  1571. struct i2c_client *client = iqs7222->client;
  1572. struct i2c_msg msg[] = {
  1573. {
  1574. .addr = client->addr,
  1575. .flags = 0,
  1576. .len = reg > U8_MAX ? sizeof(reg) : sizeof(u8),
  1577. .buf = reg_buf,
  1578. },
  1579. {
  1580. .addr = client->addr,
  1581. .flags = I2C_M_RD,
  1582. .len = val_len,
  1583. .buf = (u8 *)val,
  1584. },
  1585. };
  1586. if (reg > U8_MAX)
  1587. put_unaligned_be16(reg, reg_buf);
  1588. else
  1589. *reg_buf = (u8)reg;
  1590. /*
  1591. * The following loop protects against an edge case in which the RDY
  1592. * pin is automatically deasserted just as the read is initiated. In
  1593. * that case, the read must be retried using forced communication.
  1594. */
  1595. for (i = 0; i < IQS7222_NUM_RETRIES; i++) {
  1596. ret = iqs7222_force_comms(iqs7222);
  1597. if (ret < 0)
  1598. continue;
  1599. ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
  1600. if (ret < (int)ARRAY_SIZE(msg)) {
  1601. if (ret >= 0)
  1602. ret = -EIO;
  1603. msleep(IQS7222_COMMS_RETRY_MS);
  1604. continue;
  1605. }
  1606. if (get_unaligned_le16(msg[1].buf) == IQS7222_COMMS_ERROR) {
  1607. ret = -ENODATA;
  1608. continue;
  1609. }
  1610. ret = 0;
  1611. break;
  1612. }
  1613. /*
  1614. * The following delay ensures the device has deasserted the RDY pin
  1615. * following the I2C stop condition.
  1616. */
  1617. usleep_range(50, 100);
  1618. if (ret < 0)
  1619. dev_err(&client->dev,
  1620. "Failed to read from address 0x%04X: %d\n", reg, ret);
  1621. return ret;
  1622. }
  1623. static int iqs7222_read_word(struct iqs7222_private *iqs7222, u16 reg, u16 *val)
  1624. {
  1625. __le16 val_buf;
  1626. int error;
  1627. error = iqs7222_read_burst(iqs7222, reg, &val_buf, sizeof(val_buf));
  1628. if (error)
  1629. return error;
  1630. *val = le16_to_cpu(val_buf);
  1631. return 0;
  1632. }
  1633. static int iqs7222_write_burst(struct iqs7222_private *iqs7222,
  1634. u16 reg, const void *val, u16 val_len)
  1635. {
  1636. int reg_len = reg > U8_MAX ? sizeof(reg) : sizeof(u8);
  1637. int msg_len = reg_len + val_len;
  1638. int ret, i;
  1639. struct i2c_client *client = iqs7222->client;
  1640. u8 *msg_buf;
  1641. msg_buf = kzalloc(msg_len, GFP_KERNEL);
  1642. if (!msg_buf)
  1643. return -ENOMEM;
  1644. if (reg > U8_MAX)
  1645. put_unaligned_be16(reg, msg_buf);
  1646. else
  1647. *msg_buf = (u8)reg;
  1648. memcpy(msg_buf + reg_len, val, val_len);
  1649. /*
  1650. * The following loop protects against an edge case in which the RDY
  1651. * pin is automatically asserted just before the force communication
  1652. * command is sent.
  1653. *
  1654. * In that case, the subsequent I2C stop condition tricks the device
  1655. * into preemptively deasserting the RDY pin and the command must be
  1656. * sent again.
  1657. */
  1658. for (i = 0; i < IQS7222_NUM_RETRIES; i++) {
  1659. ret = iqs7222_force_comms(iqs7222);
  1660. if (ret < 0)
  1661. continue;
  1662. ret = i2c_master_send(client, msg_buf, msg_len);
  1663. if (ret < msg_len) {
  1664. if (ret >= 0)
  1665. ret = -EIO;
  1666. msleep(IQS7222_COMMS_RETRY_MS);
  1667. continue;
  1668. }
  1669. ret = 0;
  1670. break;
  1671. }
  1672. kfree(msg_buf);
  1673. usleep_range(50, 100);
  1674. if (ret < 0)
  1675. dev_err(&client->dev,
  1676. "Failed to write to address 0x%04X: %d\n", reg, ret);
  1677. return ret;
  1678. }
  1679. static int iqs7222_write_word(struct iqs7222_private *iqs7222, u16 reg, u16 val)
  1680. {
  1681. __le16 val_buf = cpu_to_le16(val);
  1682. return iqs7222_write_burst(iqs7222, reg, &val_buf, sizeof(val_buf));
  1683. }
  1684. static int iqs7222_ati_trigger(struct iqs7222_private *iqs7222)
  1685. {
  1686. struct i2c_client *client = iqs7222->client;
  1687. ktime_t ati_timeout;
  1688. u16 sys_status = 0;
  1689. u16 sys_setup;
  1690. int error, i;
  1691. /*
  1692. * The reserved fields of the system setup register may have changed
  1693. * as a result of other registers having been written. As such, read
  1694. * the register's latest value to avoid unexpected behavior when the
  1695. * register is written in the loop that follows.
  1696. */
  1697. error = iqs7222_read_word(iqs7222, IQS7222_SYS_SETUP, &sys_setup);
  1698. if (error)
  1699. return error;
  1700. for (i = 0; i < IQS7222_NUM_RETRIES; i++) {
  1701. /*
  1702. * Trigger ATI from streaming and normal-power modes so that
  1703. * the RDY pin continues to be asserted during ATI.
  1704. */
  1705. error = iqs7222_write_word(iqs7222, IQS7222_SYS_SETUP,
  1706. sys_setup |
  1707. IQS7222_SYS_SETUP_REDO_ATI);
  1708. if (error)
  1709. return error;
  1710. ati_timeout = ktime_add_ms(ktime_get(), IQS7222_ATI_TIMEOUT_MS);
  1711. do {
  1712. error = iqs7222_irq_poll(iqs7222,
  1713. IQS7222_COMMS_TIMEOUT_MS);
  1714. if (error)
  1715. continue;
  1716. error = iqs7222_read_word(iqs7222, IQS7222_SYS_STATUS,
  1717. &sys_status);
  1718. if (error)
  1719. return error;
  1720. if (sys_status & IQS7222_SYS_STATUS_RESET)
  1721. return 0;
  1722. if (sys_status & IQS7222_SYS_STATUS_ATI_ERROR)
  1723. break;
  1724. if (sys_status & IQS7222_SYS_STATUS_ATI_ACTIVE)
  1725. continue;
  1726. /*
  1727. * Use stream-in-touch mode if either slider reports
  1728. * absolute position.
  1729. */
  1730. sys_setup |= test_bit(EV_ABS, iqs7222->keypad->evbit)
  1731. ? IQS7222_SYS_SETUP_INTF_MODE_TOUCH
  1732. : IQS7222_SYS_SETUP_INTF_MODE_EVENT;
  1733. sys_setup |= IQS7222_SYS_SETUP_PWR_MODE_AUTO;
  1734. return iqs7222_write_word(iqs7222, IQS7222_SYS_SETUP,
  1735. sys_setup);
  1736. } while (ktime_compare(ktime_get(), ati_timeout) < 0);
  1737. dev_err(&client->dev,
  1738. "ATI attempt %d of %d failed with status 0x%02X, %s\n",
  1739. i + 1, IQS7222_NUM_RETRIES, (u8)sys_status,
  1740. i + 1 < IQS7222_NUM_RETRIES ? "retrying" : "stopping");
  1741. }
  1742. return -ETIMEDOUT;
  1743. }
  1744. static int iqs7222_dev_init(struct iqs7222_private *iqs7222, int dir)
  1745. {
  1746. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  1747. int comms_offset = dev_desc->comms_offset;
  1748. int error, i, j, k;
  1749. /*
  1750. * Acknowledge reset before writing any registers in case the device
  1751. * suffers a spurious reset during initialization.
  1752. */
  1753. if (dir == WRITE) {
  1754. error = iqs7222_write_word(iqs7222, IQS7222_SYS_SETUP,
  1755. iqs7222->sys_setup[0] |
  1756. IQS7222_SYS_SETUP_ACK_RESET);
  1757. if (error)
  1758. return error;
  1759. }
  1760. /*
  1761. * Take advantage of the stop-bit disable function, if available, to
  1762. * save the trouble of having to reopen a communication window after
  1763. * each burst read or write.
  1764. */
  1765. if (comms_offset) {
  1766. u16 comms_setup;
  1767. error = iqs7222_read_word(iqs7222,
  1768. IQS7222_SYS_SETUP + comms_offset,
  1769. &comms_setup);
  1770. if (error)
  1771. return error;
  1772. error = iqs7222_write_word(iqs7222,
  1773. IQS7222_SYS_SETUP + comms_offset,
  1774. comms_setup | IQS7222_COMMS_HOLD);
  1775. if (error)
  1776. return error;
  1777. }
  1778. for (i = 0; i < IQS7222_NUM_REG_GRPS; i++) {
  1779. int num_row = dev_desc->reg_grps[i].num_row;
  1780. int num_col = dev_desc->reg_grps[i].num_col;
  1781. u16 reg = dev_desc->reg_grps[i].base;
  1782. __le16 *val_buf;
  1783. u16 val_len = dev_desc->reg_grps[i].val_len ? : num_col * sizeof(*val_buf);
  1784. u16 *val;
  1785. if (!num_col)
  1786. continue;
  1787. val = iqs7222_setup(iqs7222, i, 0);
  1788. if (!val)
  1789. continue;
  1790. val_buf = kcalloc(num_col, sizeof(__le16), GFP_KERNEL);
  1791. if (!val_buf)
  1792. return -ENOMEM;
  1793. for (j = 0; j < num_row; j++) {
  1794. switch (dir) {
  1795. case READ:
  1796. error = iqs7222_read_burst(iqs7222, reg,
  1797. val_buf, val_len);
  1798. for (k = 0; k < num_col; k++)
  1799. val[k] = le16_to_cpu(val_buf[k]);
  1800. break;
  1801. case WRITE:
  1802. for (k = 0; k < num_col; k++)
  1803. val_buf[k] = cpu_to_le16(val[k]);
  1804. error = iqs7222_write_burst(iqs7222, reg,
  1805. val_buf, val_len);
  1806. break;
  1807. default:
  1808. error = -EINVAL;
  1809. }
  1810. if (error)
  1811. break;
  1812. reg += IQS7222_REG_OFFSET;
  1813. val += iqs7222_max_cols[i];
  1814. }
  1815. kfree(val_buf);
  1816. if (error)
  1817. return error;
  1818. }
  1819. if (comms_offset) {
  1820. u16 comms_setup;
  1821. error = iqs7222_read_word(iqs7222,
  1822. IQS7222_SYS_SETUP + comms_offset,
  1823. &comms_setup);
  1824. if (error)
  1825. return error;
  1826. error = iqs7222_write_word(iqs7222,
  1827. IQS7222_SYS_SETUP + comms_offset,
  1828. comms_setup & ~IQS7222_COMMS_HOLD);
  1829. if (error)
  1830. return error;
  1831. }
  1832. if (dir == READ) {
  1833. iqs7222->sys_setup[0] &= ~IQS7222_SYS_SETUP_INTF_MODE_MASK;
  1834. iqs7222->sys_setup[0] &= ~IQS7222_SYS_SETUP_PWR_MODE_MASK;
  1835. return 0;
  1836. }
  1837. return iqs7222_ati_trigger(iqs7222);
  1838. }
  1839. static int iqs7222_dev_info(struct iqs7222_private *iqs7222)
  1840. {
  1841. struct i2c_client *client = iqs7222->client;
  1842. bool prod_num_valid = false;
  1843. __le16 dev_id[3];
  1844. int error, i;
  1845. error = iqs7222_read_burst(iqs7222, IQS7222_PROD_NUM, dev_id,
  1846. sizeof(dev_id));
  1847. if (error)
  1848. return error;
  1849. for (i = 0; i < ARRAY_SIZE(iqs7222_devs); i++) {
  1850. if (le16_to_cpu(dev_id[0]) != iqs7222_devs[i].prod_num)
  1851. continue;
  1852. prod_num_valid = true;
  1853. if (le16_to_cpu(dev_id[1]) < iqs7222_devs[i].fw_major)
  1854. continue;
  1855. if (le16_to_cpu(dev_id[2]) < iqs7222_devs[i].fw_minor)
  1856. continue;
  1857. iqs7222->dev_desc = &iqs7222_devs[i];
  1858. return 0;
  1859. }
  1860. if (prod_num_valid)
  1861. dev_err(&client->dev, "Unsupported firmware revision: %u.%u\n",
  1862. le16_to_cpu(dev_id[1]), le16_to_cpu(dev_id[2]));
  1863. else
  1864. dev_err(&client->dev, "Unrecognized product number: %u\n",
  1865. le16_to_cpu(dev_id[0]));
  1866. return -EINVAL;
  1867. }
  1868. static int iqs7222_gpio_select(struct iqs7222_private *iqs7222,
  1869. struct fwnode_handle *child_node,
  1870. int child_enable, u16 child_link)
  1871. {
  1872. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  1873. struct i2c_client *client = iqs7222->client;
  1874. int num_gpio = dev_desc->reg_grps[IQS7222_REG_GRP_GPIO].num_row;
  1875. int error, count, i;
  1876. unsigned int gpio_sel[ARRAY_SIZE(iqs7222_gpio_links)];
  1877. if (!num_gpio)
  1878. return 0;
  1879. if (!fwnode_property_present(child_node, "azoteq,gpio-select"))
  1880. return 0;
  1881. count = fwnode_property_count_u32(child_node, "azoteq,gpio-select");
  1882. if (count > num_gpio) {
  1883. dev_err(&client->dev, "Invalid number of %s GPIOs\n",
  1884. fwnode_get_name(child_node));
  1885. return -EINVAL;
  1886. } else if (count < 0) {
  1887. dev_err(&client->dev, "Failed to count %s GPIOs: %d\n",
  1888. fwnode_get_name(child_node), count);
  1889. return count;
  1890. }
  1891. error = fwnode_property_read_u32_array(child_node,
  1892. "azoteq,gpio-select",
  1893. gpio_sel, count);
  1894. if (error) {
  1895. dev_err(&client->dev, "Failed to read %s GPIOs: %d\n",
  1896. fwnode_get_name(child_node), error);
  1897. return error;
  1898. }
  1899. for (i = 0; i < count; i++) {
  1900. u16 *gpio_setup;
  1901. if (gpio_sel[i] >= num_gpio) {
  1902. dev_err(&client->dev, "Invalid %s GPIO: %u\n",
  1903. fwnode_get_name(child_node), gpio_sel[i]);
  1904. return -EINVAL;
  1905. }
  1906. gpio_setup = iqs7222->gpio_setup[gpio_sel[i]];
  1907. if (gpio_setup[2] && child_link != gpio_setup[2]) {
  1908. dev_err(&client->dev,
  1909. "Conflicting GPIO %u event types\n",
  1910. gpio_sel[i]);
  1911. return -EINVAL;
  1912. }
  1913. gpio_setup[0] |= IQS7222_GPIO_SETUP_0_GPIO_EN;
  1914. gpio_setup[1] |= child_enable;
  1915. gpio_setup[2] = child_link;
  1916. }
  1917. return 0;
  1918. }
  1919. static int iqs7222_parse_props(struct iqs7222_private *iqs7222,
  1920. struct fwnode_handle *reg_grp_node,
  1921. int reg_grp_index,
  1922. enum iqs7222_reg_grp_id reg_grp,
  1923. enum iqs7222_reg_key_id reg_key)
  1924. {
  1925. u16 *setup = iqs7222_setup(iqs7222, reg_grp, reg_grp_index);
  1926. struct i2c_client *client = iqs7222->client;
  1927. int i;
  1928. if (!setup)
  1929. return 0;
  1930. for (i = 0; i < ARRAY_SIZE(iqs7222_props); i++) {
  1931. const char *name = iqs7222_props[i].name;
  1932. int reg_offset = iqs7222_props[i].reg_offset;
  1933. int reg_shift = iqs7222_props[i].reg_shift;
  1934. int reg_width = iqs7222_props[i].reg_width;
  1935. int val_pitch = iqs7222_props[i].val_pitch ? : 1;
  1936. int val_min = iqs7222_props[i].val_min;
  1937. int val_max = iqs7222_props[i].val_max;
  1938. bool invert = iqs7222_props[i].invert;
  1939. const char *label = iqs7222_props[i].label ? : name;
  1940. unsigned int val;
  1941. int error;
  1942. if (iqs7222_props[i].reg_grp != reg_grp ||
  1943. iqs7222_props[i].reg_key != reg_key)
  1944. continue;
  1945. /*
  1946. * Boolean register fields are one bit wide; they are forcibly
  1947. * reset to provide a means to undo changes by a bootloader if
  1948. * necessary.
  1949. *
  1950. * Scalar fields, on the other hand, are left untouched unless
  1951. * their corresponding properties are present.
  1952. */
  1953. if (reg_width == 1) {
  1954. if (invert)
  1955. setup[reg_offset] |= BIT(reg_shift);
  1956. else
  1957. setup[reg_offset] &= ~BIT(reg_shift);
  1958. }
  1959. if (!fwnode_property_present(reg_grp_node, name))
  1960. continue;
  1961. if (reg_width == 1) {
  1962. if (invert)
  1963. setup[reg_offset] &= ~BIT(reg_shift);
  1964. else
  1965. setup[reg_offset] |= BIT(reg_shift);
  1966. continue;
  1967. }
  1968. error = fwnode_property_read_u32(reg_grp_node, name, &val);
  1969. if (error) {
  1970. dev_err(&client->dev, "Failed to read %s %s: %d\n",
  1971. fwnode_get_name(reg_grp_node), label, error);
  1972. return error;
  1973. }
  1974. if (!val_max)
  1975. val_max = GENMASK(reg_width - 1, 0) * val_pitch;
  1976. if (val < val_min || val > val_max) {
  1977. dev_err(&client->dev, "Invalid %s %s: %u\n",
  1978. fwnode_get_name(reg_grp_node), label, val);
  1979. return -EINVAL;
  1980. }
  1981. setup[reg_offset] &= ~GENMASK(reg_shift + reg_width - 1,
  1982. reg_shift);
  1983. setup[reg_offset] |= (val / val_pitch << reg_shift);
  1984. }
  1985. return 0;
  1986. }
  1987. static int iqs7222_parse_event(struct iqs7222_private *iqs7222,
  1988. struct fwnode_handle *event_node,
  1989. int reg_grp_index,
  1990. enum iqs7222_reg_grp_id reg_grp,
  1991. enum iqs7222_reg_key_id reg_key,
  1992. u16 event_enable, u16 event_link,
  1993. unsigned int *event_type,
  1994. unsigned int *event_code)
  1995. {
  1996. struct i2c_client *client = iqs7222->client;
  1997. int error;
  1998. error = iqs7222_parse_props(iqs7222, event_node, reg_grp_index,
  1999. reg_grp, reg_key);
  2000. if (error)
  2001. return error;
  2002. error = iqs7222_gpio_select(iqs7222, event_node, event_enable,
  2003. event_link);
  2004. if (error)
  2005. return error;
  2006. error = fwnode_property_read_u32(event_node, "linux,code", event_code);
  2007. if (error == -EINVAL) {
  2008. return 0;
  2009. } else if (error) {
  2010. dev_err(&client->dev, "Failed to read %s code: %d\n",
  2011. fwnode_get_name(event_node), error);
  2012. return error;
  2013. }
  2014. if (!event_type) {
  2015. input_set_capability(iqs7222->keypad, EV_KEY, *event_code);
  2016. return 0;
  2017. }
  2018. error = fwnode_property_read_u32(event_node, "linux,input-type",
  2019. event_type);
  2020. if (error == -EINVAL) {
  2021. *event_type = EV_KEY;
  2022. } else if (error) {
  2023. dev_err(&client->dev, "Failed to read %s input type: %d\n",
  2024. fwnode_get_name(event_node), error);
  2025. return error;
  2026. } else if (*event_type != EV_KEY && *event_type != EV_SW) {
  2027. dev_err(&client->dev, "Invalid %s input type: %d\n",
  2028. fwnode_get_name(event_node), *event_type);
  2029. return -EINVAL;
  2030. }
  2031. input_set_capability(iqs7222->keypad, *event_type, *event_code);
  2032. return 0;
  2033. }
  2034. static int iqs7222_parse_cycle(struct iqs7222_private *iqs7222,
  2035. struct fwnode_handle *cycle_node, int cycle_index)
  2036. {
  2037. u16 *cycle_setup = iqs7222->cycle_setup[cycle_index];
  2038. struct i2c_client *client = iqs7222->client;
  2039. unsigned int pins[9];
  2040. int error, count, i;
  2041. /*
  2042. * Each channel shares a cycle with one other channel; the mapping of
  2043. * channels to cycles is fixed. Properties defined for a cycle impact
  2044. * both channels tied to the cycle.
  2045. *
  2046. * Unlike channels which are restricted to a select range of CRx pins
  2047. * based on channel number, any cycle can claim any of the device's 9
  2048. * CTx pins (CTx0-8).
  2049. */
  2050. if (!fwnode_property_present(cycle_node, "azoteq,tx-enable"))
  2051. return 0;
  2052. count = fwnode_property_count_u32(cycle_node, "azoteq,tx-enable");
  2053. if (count < 0) {
  2054. dev_err(&client->dev, "Failed to count %s CTx pins: %d\n",
  2055. fwnode_get_name(cycle_node), count);
  2056. return count;
  2057. } else if (count > ARRAY_SIZE(pins)) {
  2058. dev_err(&client->dev, "Invalid number of %s CTx pins\n",
  2059. fwnode_get_name(cycle_node));
  2060. return -EINVAL;
  2061. }
  2062. error = fwnode_property_read_u32_array(cycle_node, "azoteq,tx-enable",
  2063. pins, count);
  2064. if (error) {
  2065. dev_err(&client->dev, "Failed to read %s CTx pins: %d\n",
  2066. fwnode_get_name(cycle_node), error);
  2067. return error;
  2068. }
  2069. cycle_setup[1] &= ~GENMASK(7 + ARRAY_SIZE(pins) - 1, 7);
  2070. for (i = 0; i < count; i++) {
  2071. if (pins[i] > 8) {
  2072. dev_err(&client->dev, "Invalid %s CTx pin: %u\n",
  2073. fwnode_get_name(cycle_node), pins[i]);
  2074. return -EINVAL;
  2075. }
  2076. cycle_setup[1] |= BIT(pins[i] + 7);
  2077. }
  2078. return 0;
  2079. }
  2080. static int iqs7222_parse_chan(struct iqs7222_private *iqs7222,
  2081. struct fwnode_handle *chan_node, int chan_index)
  2082. {
  2083. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2084. struct i2c_client *client = iqs7222->client;
  2085. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2086. int ext_chan = dev_desc->ext_chan ? : num_chan;
  2087. int error, i;
  2088. u16 *chan_setup = iqs7222->chan_setup[chan_index];
  2089. u16 *sys_setup = iqs7222->sys_setup;
  2090. unsigned int val;
  2091. if (dev_desc->allow_offset &&
  2092. fwnode_property_present(chan_node, "azoteq,ulp-allow"))
  2093. sys_setup[dev_desc->allow_offset] &= ~BIT(chan_index);
  2094. chan_setup[0] |= IQS7222_CHAN_SETUP_0_CHAN_EN;
  2095. /*
  2096. * The reference channel function allows for differential measurements
  2097. * and is only available in the case of IQS7222A or IQS7222C.
  2098. */
  2099. if (dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_col > 4 &&
  2100. fwnode_property_present(chan_node, "azoteq,ref-select")) {
  2101. u16 *ref_setup;
  2102. error = fwnode_property_read_u32(chan_node, "azoteq,ref-select",
  2103. &val);
  2104. if (error) {
  2105. dev_err(&client->dev,
  2106. "Failed to read %s reference channel: %d\n",
  2107. fwnode_get_name(chan_node), error);
  2108. return error;
  2109. }
  2110. if (val >= ext_chan) {
  2111. dev_err(&client->dev,
  2112. "Invalid %s reference channel: %u\n",
  2113. fwnode_get_name(chan_node), val);
  2114. return -EINVAL;
  2115. }
  2116. ref_setup = iqs7222->chan_setup[val];
  2117. /*
  2118. * Configure the current channel as a follower of the selected
  2119. * reference channel.
  2120. */
  2121. chan_setup[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_FOLLOW;
  2122. chan_setup[4] = val * 42 + 1048;
  2123. error = fwnode_property_read_u32(chan_node, "azoteq,ref-weight",
  2124. &val);
  2125. if (!error) {
  2126. if (val > U16_MAX) {
  2127. dev_err(&client->dev,
  2128. "Invalid %s reference weight: %u\n",
  2129. fwnode_get_name(chan_node), val);
  2130. return -EINVAL;
  2131. }
  2132. chan_setup[5] = val;
  2133. } else if (error != -EINVAL) {
  2134. dev_err(&client->dev,
  2135. "Failed to read %s reference weight: %d\n",
  2136. fwnode_get_name(chan_node), error);
  2137. return error;
  2138. }
  2139. /*
  2140. * Configure the selected channel as a reference channel which
  2141. * serves the current channel.
  2142. */
  2143. ref_setup[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_REF;
  2144. ref_setup[5] |= BIT(chan_index);
  2145. ref_setup[4] = dev_desc->touch_link;
  2146. if (fwnode_property_present(chan_node, "azoteq,use-prox"))
  2147. ref_setup[4] -= 2;
  2148. } else if (dev_desc->reg_grps[IQS7222_REG_GRP_TPAD].num_row &&
  2149. fwnode_property_present(chan_node,
  2150. "azoteq,counts-filt-enable")) {
  2151. /*
  2152. * In the case of IQS7222D, however, the reference mode field
  2153. * is partially repurposed as a counts filter enable control.
  2154. */
  2155. chan_setup[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_REF;
  2156. }
  2157. if (fwnode_property_present(chan_node, "azoteq,rx-enable")) {
  2158. /*
  2159. * Each channel can claim up to 4 CRx pins. The first half of
  2160. * the channels can use CRx0-3, while the second half can use
  2161. * CRx4-7.
  2162. */
  2163. unsigned int pins[4];
  2164. int count;
  2165. count = fwnode_property_count_u32(chan_node,
  2166. "azoteq,rx-enable");
  2167. if (count < 0) {
  2168. dev_err(&client->dev,
  2169. "Failed to count %s CRx pins: %d\n",
  2170. fwnode_get_name(chan_node), count);
  2171. return count;
  2172. } else if (count > ARRAY_SIZE(pins)) {
  2173. dev_err(&client->dev,
  2174. "Invalid number of %s CRx pins\n",
  2175. fwnode_get_name(chan_node));
  2176. return -EINVAL;
  2177. }
  2178. error = fwnode_property_read_u32_array(chan_node,
  2179. "azoteq,rx-enable",
  2180. pins, count);
  2181. if (error) {
  2182. dev_err(&client->dev,
  2183. "Failed to read %s CRx pins: %d\n",
  2184. fwnode_get_name(chan_node), error);
  2185. return error;
  2186. }
  2187. chan_setup[0] &= ~GENMASK(4 + ARRAY_SIZE(pins) - 1, 4);
  2188. for (i = 0; i < count; i++) {
  2189. int min_crx = chan_index < ext_chan / 2 ? 0 : 4;
  2190. if (pins[i] < min_crx || pins[i] > min_crx + 3) {
  2191. dev_err(&client->dev,
  2192. "Invalid %s CRx pin: %u\n",
  2193. fwnode_get_name(chan_node), pins[i]);
  2194. return -EINVAL;
  2195. }
  2196. chan_setup[0] |= BIT(pins[i] + 4 - min_crx);
  2197. }
  2198. }
  2199. for (i = 0; i < ARRAY_SIZE(iqs7222_kp_events); i++) {
  2200. const char *event_name = iqs7222_kp_events[i].name;
  2201. u16 event_enable = iqs7222_kp_events[i].enable;
  2202. struct fwnode_handle *event_node __free(fwnode_handle) =
  2203. fwnode_get_named_child_node(chan_node, event_name);
  2204. if (!event_node)
  2205. continue;
  2206. error = fwnode_property_read_u32(event_node,
  2207. "azoteq,timeout-press-ms",
  2208. &val);
  2209. if (!error) {
  2210. /*
  2211. * The IQS7222B employs a global pair of press timeout
  2212. * registers as opposed to channel-specific registers.
  2213. */
  2214. u16 *setup = dev_desc->reg_grps
  2215. [IQS7222_REG_GRP_BTN].num_col > 2 ?
  2216. &iqs7222->btn_setup[chan_index][2] :
  2217. &sys_setup[9];
  2218. if (val > U8_MAX * 500) {
  2219. dev_err(&client->dev,
  2220. "Invalid %s press timeout: %u\n",
  2221. fwnode_get_name(event_node), val);
  2222. return -EINVAL;
  2223. }
  2224. *setup &= ~(U8_MAX << i * 8);
  2225. *setup |= (val / 500 << i * 8);
  2226. } else if (error != -EINVAL) {
  2227. dev_err(&client->dev,
  2228. "Failed to read %s press timeout: %d\n",
  2229. fwnode_get_name(event_node), error);
  2230. return error;
  2231. }
  2232. error = iqs7222_parse_event(iqs7222, event_node, chan_index,
  2233. IQS7222_REG_GRP_BTN,
  2234. iqs7222_kp_events[i].reg_key,
  2235. BIT(chan_index),
  2236. dev_desc->touch_link - (i ? 0 : 2),
  2237. &iqs7222->kp_type[chan_index][i],
  2238. &iqs7222->kp_code[chan_index][i]);
  2239. if (error)
  2240. return error;
  2241. if (!iqs7222->kp_type[chan_index][i])
  2242. continue;
  2243. if (!dev_desc->event_offset)
  2244. continue;
  2245. sys_setup[dev_desc->event_offset] |= event_enable;
  2246. }
  2247. /*
  2248. * The following call handles a special pair of properties that apply
  2249. * to a channel node, but reside within the button (event) group.
  2250. */
  2251. return iqs7222_parse_props(iqs7222, chan_node, chan_index,
  2252. IQS7222_REG_GRP_BTN,
  2253. IQS7222_REG_KEY_DEBOUNCE);
  2254. }
  2255. static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222,
  2256. struct fwnode_handle *sldr_node, int sldr_index)
  2257. {
  2258. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2259. struct i2c_client *client = iqs7222->client;
  2260. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2261. int ext_chan = dev_desc->ext_chan ? : num_chan;
  2262. int count, error, reg_offset, i;
  2263. u16 *event_mask = &iqs7222->sys_setup[dev_desc->event_offset];
  2264. u16 *sldr_setup = iqs7222->sldr_setup[sldr_index];
  2265. unsigned int chan_sel[4], val;
  2266. /*
  2267. * Each slider can be spread across 3 to 4 channels. It is possible to
  2268. * select only 2 channels, but doing so prevents the slider from using
  2269. * the specified resolution.
  2270. */
  2271. count = fwnode_property_count_u32(sldr_node, "azoteq,channel-select");
  2272. if (count < 0) {
  2273. dev_err(&client->dev, "Failed to count %s channels: %d\n",
  2274. fwnode_get_name(sldr_node), count);
  2275. return count;
  2276. } else if (count < 3 || count > ARRAY_SIZE(chan_sel)) {
  2277. dev_err(&client->dev, "Invalid number of %s channels\n",
  2278. fwnode_get_name(sldr_node));
  2279. return -EINVAL;
  2280. }
  2281. error = fwnode_property_read_u32_array(sldr_node,
  2282. "azoteq,channel-select",
  2283. chan_sel, count);
  2284. if (error) {
  2285. dev_err(&client->dev, "Failed to read %s channels: %d\n",
  2286. fwnode_get_name(sldr_node), error);
  2287. return error;
  2288. }
  2289. /*
  2290. * Resolution and top speed, if small enough, are packed into a single
  2291. * register. Otherwise, each occupies its own register and the rest of
  2292. * the slider-related register addresses are offset by one.
  2293. */
  2294. reg_offset = dev_desc->sldr_res < U16_MAX ? 0 : 1;
  2295. sldr_setup[0] |= count;
  2296. sldr_setup[3 + reg_offset] &= ~GENMASK(ext_chan - 1, 0);
  2297. for (i = 0; i < ARRAY_SIZE(chan_sel); i++) {
  2298. sldr_setup[5 + reg_offset + i] = 0;
  2299. if (i >= count)
  2300. continue;
  2301. if (chan_sel[i] >= ext_chan) {
  2302. dev_err(&client->dev, "Invalid %s channel: %u\n",
  2303. fwnode_get_name(sldr_node), chan_sel[i]);
  2304. return -EINVAL;
  2305. }
  2306. /*
  2307. * The following fields indicate which channels participate in
  2308. * the slider, as well as each channel's relative placement.
  2309. */
  2310. sldr_setup[3 + reg_offset] |= BIT(chan_sel[i]);
  2311. sldr_setup[5 + reg_offset + i] = chan_sel[i] * 42 + 1080;
  2312. }
  2313. sldr_setup[4 + reg_offset] = dev_desc->touch_link;
  2314. if (fwnode_property_present(sldr_node, "azoteq,use-prox"))
  2315. sldr_setup[4 + reg_offset] -= 2;
  2316. error = fwnode_property_read_u32(sldr_node, "azoteq,slider-size", &val);
  2317. if (!error) {
  2318. if (val > dev_desc->sldr_res) {
  2319. dev_err(&client->dev, "Invalid %s size: %u\n",
  2320. fwnode_get_name(sldr_node), val);
  2321. return -EINVAL;
  2322. }
  2323. if (reg_offset) {
  2324. sldr_setup[3] = val;
  2325. } else {
  2326. sldr_setup[2] &= ~IQS7222_SLDR_SETUP_2_RES_MASK;
  2327. sldr_setup[2] |= (val / 16 <<
  2328. IQS7222_SLDR_SETUP_2_RES_SHIFT);
  2329. }
  2330. } else if (error != -EINVAL) {
  2331. dev_err(&client->dev, "Failed to read %s size: %d\n",
  2332. fwnode_get_name(sldr_node), error);
  2333. return error;
  2334. }
  2335. if (!(reg_offset ? sldr_setup[3]
  2336. : sldr_setup[2] & IQS7222_SLDR_SETUP_2_RES_MASK)) {
  2337. dev_err(&client->dev, "Undefined %s size\n",
  2338. fwnode_get_name(sldr_node));
  2339. return -EINVAL;
  2340. }
  2341. error = fwnode_property_read_u32(sldr_node, "azoteq,top-speed", &val);
  2342. if (!error) {
  2343. if (val > (reg_offset ? U16_MAX : U8_MAX * 4)) {
  2344. dev_err(&client->dev, "Invalid %s top speed: %u\n",
  2345. fwnode_get_name(sldr_node), val);
  2346. return -EINVAL;
  2347. }
  2348. if (reg_offset) {
  2349. sldr_setup[2] = val;
  2350. } else {
  2351. sldr_setup[2] &= ~IQS7222_SLDR_SETUP_2_TOP_SPEED_MASK;
  2352. sldr_setup[2] |= (val / 4);
  2353. }
  2354. } else if (error != -EINVAL) {
  2355. dev_err(&client->dev, "Failed to read %s top speed: %d\n",
  2356. fwnode_get_name(sldr_node), error);
  2357. return error;
  2358. }
  2359. error = fwnode_property_read_u32(sldr_node, "linux,axis", &val);
  2360. if (!error) {
  2361. u16 sldr_max = sldr_setup[3] - 1;
  2362. if (!reg_offset) {
  2363. sldr_max = sldr_setup[2];
  2364. sldr_max &= IQS7222_SLDR_SETUP_2_RES_MASK;
  2365. sldr_max >>= IQS7222_SLDR_SETUP_2_RES_SHIFT;
  2366. sldr_max = sldr_max * 16 - 1;
  2367. }
  2368. input_set_abs_params(iqs7222->keypad, val, 0, sldr_max, 0, 0);
  2369. iqs7222->sl_axis[sldr_index] = val;
  2370. } else if (error != -EINVAL) {
  2371. dev_err(&client->dev, "Failed to read %s axis: %d\n",
  2372. fwnode_get_name(sldr_node), error);
  2373. return error;
  2374. }
  2375. if (dev_desc->wheel_enable) {
  2376. sldr_setup[0] &= ~dev_desc->wheel_enable;
  2377. if (iqs7222->sl_axis[sldr_index] == ABS_WHEEL)
  2378. sldr_setup[0] |= dev_desc->wheel_enable;
  2379. }
  2380. /*
  2381. * The absence of a register offset makes it safe to assume the device
  2382. * supports gestures, each of which is first disabled until explicitly
  2383. * enabled.
  2384. */
  2385. if (!reg_offset)
  2386. for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++)
  2387. sldr_setup[9] &= ~iqs7222_sl_events[i].enable;
  2388. for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++) {
  2389. const char *event_name = iqs7222_sl_events[i].name;
  2390. enum iqs7222_reg_key_id reg_key;
  2391. struct fwnode_handle *event_node __free(fwnode_handle) =
  2392. fwnode_get_named_child_node(sldr_node, event_name);
  2393. if (!event_node)
  2394. continue;
  2395. /*
  2396. * Depending on the device, gestures are either offered using
  2397. * one of two timing resolutions, or are not supported at all.
  2398. */
  2399. if (reg_offset)
  2400. reg_key = IQS7222_REG_KEY_RESERVED;
  2401. else if (dev_desc->legacy_gesture &&
  2402. iqs7222_sl_events[i].reg_key == IQS7222_REG_KEY_TAP)
  2403. reg_key = IQS7222_REG_KEY_TAP_LEGACY;
  2404. else if (dev_desc->legacy_gesture &&
  2405. iqs7222_sl_events[i].reg_key == IQS7222_REG_KEY_AXIAL)
  2406. reg_key = IQS7222_REG_KEY_AXIAL_LEGACY;
  2407. else
  2408. reg_key = iqs7222_sl_events[i].reg_key;
  2409. /*
  2410. * The press/release event does not expose a direct GPIO link,
  2411. * but one can be emulated by tying each of the participating
  2412. * channels to the same GPIO.
  2413. */
  2414. error = iqs7222_parse_event(iqs7222, event_node, sldr_index,
  2415. IQS7222_REG_GRP_SLDR, reg_key,
  2416. i ? iqs7222_sl_events[i].enable
  2417. : sldr_setup[3 + reg_offset],
  2418. i ? 1568 + sldr_index * 30
  2419. : sldr_setup[4 + reg_offset],
  2420. NULL,
  2421. &iqs7222->sl_code[sldr_index][i]);
  2422. if (error)
  2423. return error;
  2424. if (!reg_offset)
  2425. sldr_setup[9] |= iqs7222_sl_events[i].enable;
  2426. if (!dev_desc->event_offset)
  2427. continue;
  2428. /*
  2429. * The press/release event is determined based on whether the
  2430. * coordinate field reports 0xFFFF and solely relies on touch
  2431. * or proximity interrupts to be unmasked.
  2432. */
  2433. if (i && !reg_offset)
  2434. *event_mask |= (IQS7222_EVENT_MASK_SLDR << sldr_index);
  2435. else if (sldr_setup[4 + reg_offset] == dev_desc->touch_link)
  2436. *event_mask |= IQS7222_EVENT_MASK_TOUCH;
  2437. else
  2438. *event_mask |= IQS7222_EVENT_MASK_PROX;
  2439. }
  2440. /*
  2441. * The following call handles a special pair of properties that shift
  2442. * to make room for a wheel enable control in the case of IQS7222C.
  2443. */
  2444. return iqs7222_parse_props(iqs7222, sldr_node, sldr_index,
  2445. IQS7222_REG_GRP_SLDR,
  2446. dev_desc->wheel_enable ?
  2447. IQS7222_REG_KEY_WHEEL :
  2448. IQS7222_REG_KEY_NO_WHEEL);
  2449. }
  2450. static int iqs7222_parse_tpad(struct iqs7222_private *iqs7222,
  2451. struct fwnode_handle *tpad_node, int tpad_index)
  2452. {
  2453. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2454. struct touchscreen_properties *prop = &iqs7222->prop;
  2455. struct i2c_client *client = iqs7222->client;
  2456. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2457. int count, error, i;
  2458. u16 *event_mask = &iqs7222->sys_setup[dev_desc->event_offset];
  2459. u16 *tpad_setup = iqs7222->tpad_setup;
  2460. unsigned int chan_sel[12];
  2461. error = iqs7222_parse_props(iqs7222, tpad_node, tpad_index,
  2462. IQS7222_REG_GRP_TPAD,
  2463. IQS7222_REG_KEY_NONE);
  2464. if (error)
  2465. return error;
  2466. count = fwnode_property_count_u32(tpad_node, "azoteq,channel-select");
  2467. if (count < 0) {
  2468. dev_err(&client->dev, "Failed to count %s channels: %d\n",
  2469. fwnode_get_name(tpad_node), count);
  2470. return count;
  2471. } else if (!count || count > ARRAY_SIZE(chan_sel)) {
  2472. dev_err(&client->dev, "Invalid number of %s channels\n",
  2473. fwnode_get_name(tpad_node));
  2474. return -EINVAL;
  2475. }
  2476. error = fwnode_property_read_u32_array(tpad_node,
  2477. "azoteq,channel-select",
  2478. chan_sel, count);
  2479. if (error) {
  2480. dev_err(&client->dev, "Failed to read %s channels: %d\n",
  2481. fwnode_get_name(tpad_node), error);
  2482. return error;
  2483. }
  2484. tpad_setup[6] &= ~GENMASK(num_chan - 1, 0);
  2485. for (i = 0; i < ARRAY_SIZE(chan_sel); i++) {
  2486. tpad_setup[8 + i] = 0;
  2487. if (i >= count || chan_sel[i] == U8_MAX)
  2488. continue;
  2489. if (chan_sel[i] >= num_chan) {
  2490. dev_err(&client->dev, "Invalid %s channel: %u\n",
  2491. fwnode_get_name(tpad_node), chan_sel[i]);
  2492. return -EINVAL;
  2493. }
  2494. /*
  2495. * The following fields indicate which channels participate in
  2496. * the trackpad, as well as each channel's relative placement.
  2497. */
  2498. tpad_setup[6] |= BIT(chan_sel[i]);
  2499. tpad_setup[8 + i] = chan_sel[i] * 34 + 1072;
  2500. }
  2501. tpad_setup[7] = dev_desc->touch_link;
  2502. if (fwnode_property_present(tpad_node, "azoteq,use-prox"))
  2503. tpad_setup[7] -= 2;
  2504. for (i = 0; i < ARRAY_SIZE(iqs7222_tp_events); i++)
  2505. tpad_setup[20] &= ~(iqs7222_tp_events[i].strict |
  2506. iqs7222_tp_events[i].enable);
  2507. for (i = 0; i < ARRAY_SIZE(iqs7222_tp_events); i++) {
  2508. const char *event_name = iqs7222_tp_events[i].name;
  2509. struct fwnode_handle *event_node __free(fwnode_handle) =
  2510. fwnode_get_named_child_node(tpad_node, event_name);
  2511. if (!event_node)
  2512. continue;
  2513. if (fwnode_property_present(event_node,
  2514. "azoteq,gesture-angle-tighten"))
  2515. tpad_setup[20] |= iqs7222_tp_events[i].strict;
  2516. tpad_setup[20] |= iqs7222_tp_events[i].enable;
  2517. error = iqs7222_parse_event(iqs7222, event_node, tpad_index,
  2518. IQS7222_REG_GRP_TPAD,
  2519. iqs7222_tp_events[i].reg_key,
  2520. iqs7222_tp_events[i].link, 1566,
  2521. NULL,
  2522. &iqs7222->tp_code[i]);
  2523. if (error)
  2524. return error;
  2525. if (!dev_desc->event_offset)
  2526. continue;
  2527. /*
  2528. * The press/release event is determined based on whether the
  2529. * coordinate fields report 0xFFFF and solely relies on touch
  2530. * or proximity interrupts to be unmasked.
  2531. */
  2532. if (i)
  2533. *event_mask |= IQS7222_EVENT_MASK_TPAD;
  2534. else if (tpad_setup[7] == dev_desc->touch_link)
  2535. *event_mask |= IQS7222_EVENT_MASK_TOUCH;
  2536. else
  2537. *event_mask |= IQS7222_EVENT_MASK_PROX;
  2538. }
  2539. if (!iqs7222->tp_code[0])
  2540. return 0;
  2541. input_set_abs_params(iqs7222->keypad, ABS_X,
  2542. 0, (tpad_setup[4] ? : 1) - 1, 0, 0);
  2543. input_set_abs_params(iqs7222->keypad, ABS_Y,
  2544. 0, (tpad_setup[5] ? : 1) - 1, 0, 0);
  2545. touchscreen_parse_properties(iqs7222->keypad, false, prop);
  2546. if (prop->max_x >= U16_MAX || prop->max_y >= U16_MAX) {
  2547. dev_err(&client->dev, "Invalid trackpad size: %u*%u\n",
  2548. prop->max_x, prop->max_y);
  2549. return -EINVAL;
  2550. }
  2551. tpad_setup[4] = prop->max_x + 1;
  2552. tpad_setup[5] = prop->max_y + 1;
  2553. return 0;
  2554. }
  2555. static int (*iqs7222_parse_extra[IQS7222_NUM_REG_GRPS])
  2556. (struct iqs7222_private *iqs7222,
  2557. struct fwnode_handle *reg_grp_node,
  2558. int reg_grp_index) = {
  2559. [IQS7222_REG_GRP_CYCLE] = iqs7222_parse_cycle,
  2560. [IQS7222_REG_GRP_CHAN] = iqs7222_parse_chan,
  2561. [IQS7222_REG_GRP_SLDR] = iqs7222_parse_sldr,
  2562. [IQS7222_REG_GRP_TPAD] = iqs7222_parse_tpad,
  2563. };
  2564. static int iqs7222_parse_reg_grp(struct iqs7222_private *iqs7222,
  2565. enum iqs7222_reg_grp_id reg_grp,
  2566. int reg_grp_index)
  2567. {
  2568. struct i2c_client *client = iqs7222->client;
  2569. int error;
  2570. struct fwnode_handle *reg_grp_node __free(fwnode_handle) = NULL;
  2571. if (iqs7222_reg_grp_names[reg_grp]) {
  2572. char reg_grp_name[16];
  2573. snprintf(reg_grp_name, sizeof(reg_grp_name),
  2574. iqs7222_reg_grp_names[reg_grp], reg_grp_index);
  2575. reg_grp_node = device_get_named_child_node(&client->dev,
  2576. reg_grp_name);
  2577. } else {
  2578. reg_grp_node = fwnode_handle_get(dev_fwnode(&client->dev));
  2579. }
  2580. if (!reg_grp_node)
  2581. return 0;
  2582. error = iqs7222_parse_props(iqs7222, reg_grp_node, reg_grp_index,
  2583. reg_grp, IQS7222_REG_KEY_NONE);
  2584. if (error)
  2585. return error;
  2586. if (iqs7222_parse_extra[reg_grp]) {
  2587. error = iqs7222_parse_extra[reg_grp](iqs7222, reg_grp_node,
  2588. reg_grp_index);
  2589. if (error)
  2590. return error;
  2591. }
  2592. return 0;
  2593. }
  2594. static int iqs7222_parse_all(struct iqs7222_private *iqs7222)
  2595. {
  2596. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2597. const struct iqs7222_reg_grp_desc *reg_grps = dev_desc->reg_grps;
  2598. u16 *sys_setup = iqs7222->sys_setup;
  2599. int error, i, j;
  2600. if (dev_desc->allow_offset)
  2601. sys_setup[dev_desc->allow_offset] = U16_MAX;
  2602. if (dev_desc->event_offset)
  2603. sys_setup[dev_desc->event_offset] = IQS7222_EVENT_MASK_ATI;
  2604. for (i = 0; i < reg_grps[IQS7222_REG_GRP_GPIO].num_row; i++) {
  2605. u16 *gpio_setup = iqs7222->gpio_setup[i];
  2606. gpio_setup[0] &= ~IQS7222_GPIO_SETUP_0_GPIO_EN;
  2607. gpio_setup[1] = 0;
  2608. gpio_setup[2] = 0;
  2609. if (reg_grps[IQS7222_REG_GRP_GPIO].num_row == 1)
  2610. continue;
  2611. /*
  2612. * The IQS7222C and IQS7222D expose multiple GPIO and must be
  2613. * informed as to which GPIO this group represents.
  2614. */
  2615. for (j = 0; j < ARRAY_SIZE(iqs7222_gpio_links); j++)
  2616. gpio_setup[0] &= ~BIT(iqs7222_gpio_links[j]);
  2617. gpio_setup[0] |= BIT(iqs7222_gpio_links[i]);
  2618. }
  2619. for (i = 0; i < reg_grps[IQS7222_REG_GRP_CHAN].num_row; i++) {
  2620. u16 *chan_setup = iqs7222->chan_setup[i];
  2621. chan_setup[0] &= ~IQS7222_CHAN_SETUP_0_REF_MODE_MASK;
  2622. chan_setup[0] &= ~IQS7222_CHAN_SETUP_0_CHAN_EN;
  2623. chan_setup[5] = 0;
  2624. }
  2625. for (i = 0; i < reg_grps[IQS7222_REG_GRP_SLDR].num_row; i++) {
  2626. u16 *sldr_setup = iqs7222->sldr_setup[i];
  2627. sldr_setup[0] &= ~IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK;
  2628. }
  2629. for (i = 0; i < IQS7222_NUM_REG_GRPS; i++) {
  2630. for (j = 0; j < reg_grps[i].num_row; j++) {
  2631. error = iqs7222_parse_reg_grp(iqs7222, i, j);
  2632. if (error)
  2633. return error;
  2634. }
  2635. }
  2636. return 0;
  2637. }
  2638. static int iqs7222_report(struct iqs7222_private *iqs7222)
  2639. {
  2640. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2641. struct i2c_client *client = iqs7222->client;
  2642. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2643. int num_stat = dev_desc->reg_grps[IQS7222_REG_GRP_STAT].num_col;
  2644. int error, i, j;
  2645. __le16 status[IQS7222_MAX_COLS_STAT];
  2646. error = iqs7222_read_burst(iqs7222, IQS7222_SYS_STATUS, status,
  2647. num_stat * sizeof(*status));
  2648. if (error)
  2649. return error;
  2650. if (le16_to_cpu(status[0]) & IQS7222_SYS_STATUS_RESET) {
  2651. dev_err(&client->dev, "Unexpected device reset\n");
  2652. return iqs7222_dev_init(iqs7222, WRITE);
  2653. }
  2654. if (le16_to_cpu(status[0]) & IQS7222_SYS_STATUS_ATI_ERROR) {
  2655. dev_err(&client->dev, "Unexpected ATI error\n");
  2656. return iqs7222_ati_trigger(iqs7222);
  2657. }
  2658. if (le16_to_cpu(status[0]) & IQS7222_SYS_STATUS_ATI_ACTIVE)
  2659. return 0;
  2660. for (i = 0; i < num_chan; i++) {
  2661. u16 *chan_setup = iqs7222->chan_setup[i];
  2662. if (!(chan_setup[0] & IQS7222_CHAN_SETUP_0_CHAN_EN))
  2663. continue;
  2664. for (j = 0; j < ARRAY_SIZE(iqs7222_kp_events); j++) {
  2665. /*
  2666. * Proximity state begins at offset 2 and spills into
  2667. * offset 3 for devices with more than 16 channels.
  2668. *
  2669. * Touch state begins at the first offset immediately
  2670. * following proximity state.
  2671. */
  2672. int k = 2 + j * (num_chan > 16 ? 2 : 1);
  2673. u16 state = le16_to_cpu(status[k + i / 16]);
  2674. if (!iqs7222->kp_type[i][j])
  2675. continue;
  2676. input_event(iqs7222->keypad,
  2677. iqs7222->kp_type[i][j],
  2678. iqs7222->kp_code[i][j],
  2679. !!(state & BIT(i % 16)));
  2680. }
  2681. }
  2682. for (i = 0; i < dev_desc->reg_grps[IQS7222_REG_GRP_SLDR].num_row; i++) {
  2683. u16 *sldr_setup = iqs7222->sldr_setup[i];
  2684. u16 sldr_pos = le16_to_cpu(status[4 + i]);
  2685. u16 state = le16_to_cpu(status[6 + i]);
  2686. if (!(sldr_setup[0] & IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK))
  2687. continue;
  2688. if (sldr_pos < dev_desc->sldr_res)
  2689. input_report_abs(iqs7222->keypad, iqs7222->sl_axis[i],
  2690. sldr_pos);
  2691. input_report_key(iqs7222->keypad, iqs7222->sl_code[i][0],
  2692. sldr_pos < dev_desc->sldr_res);
  2693. /*
  2694. * A maximum resolution indicates the device does not support
  2695. * gestures, in which case the remaining fields are ignored.
  2696. */
  2697. if (dev_desc->sldr_res == U16_MAX)
  2698. continue;
  2699. if (!(le16_to_cpu(status[1]) & IQS7222_EVENT_MASK_SLDR << i))
  2700. continue;
  2701. /*
  2702. * Skip the press/release event, as it does not have separate
  2703. * status fields and is handled separately.
  2704. */
  2705. for (j = 1; j < ARRAY_SIZE(iqs7222_sl_events); j++) {
  2706. u16 mask = iqs7222_sl_events[j].mask;
  2707. u16 val = iqs7222_sl_events[j].val;
  2708. input_report_key(iqs7222->keypad,
  2709. iqs7222->sl_code[i][j],
  2710. (state & mask) == val);
  2711. }
  2712. input_sync(iqs7222->keypad);
  2713. for (j = 1; j < ARRAY_SIZE(iqs7222_sl_events); j++)
  2714. input_report_key(iqs7222->keypad,
  2715. iqs7222->sl_code[i][j], 0);
  2716. }
  2717. for (i = 0; i < dev_desc->reg_grps[IQS7222_REG_GRP_TPAD].num_row; i++) {
  2718. u16 tpad_pos_x = le16_to_cpu(status[4]);
  2719. u16 tpad_pos_y = le16_to_cpu(status[5]);
  2720. u16 state = le16_to_cpu(status[6]);
  2721. input_report_key(iqs7222->keypad, iqs7222->tp_code[0],
  2722. tpad_pos_x < U16_MAX);
  2723. if (tpad_pos_x < U16_MAX)
  2724. touchscreen_report_pos(iqs7222->keypad, &iqs7222->prop,
  2725. tpad_pos_x, tpad_pos_y, false);
  2726. if (!(le16_to_cpu(status[1]) & IQS7222_EVENT_MASK_TPAD))
  2727. continue;
  2728. /*
  2729. * Skip the press/release event, as it does not have separate
  2730. * status fields and is handled separately.
  2731. */
  2732. for (j = 1; j < ARRAY_SIZE(iqs7222_tp_events); j++) {
  2733. u16 mask = iqs7222_tp_events[j].mask;
  2734. u16 val = iqs7222_tp_events[j].val;
  2735. input_report_key(iqs7222->keypad,
  2736. iqs7222->tp_code[j],
  2737. (state & mask) == val);
  2738. }
  2739. input_sync(iqs7222->keypad);
  2740. for (j = 1; j < ARRAY_SIZE(iqs7222_tp_events); j++)
  2741. input_report_key(iqs7222->keypad,
  2742. iqs7222->tp_code[j], 0);
  2743. }
  2744. input_sync(iqs7222->keypad);
  2745. return 0;
  2746. }
  2747. static irqreturn_t iqs7222_irq(int irq, void *context)
  2748. {
  2749. struct iqs7222_private *iqs7222 = context;
  2750. return iqs7222_report(iqs7222) ? IRQ_NONE : IRQ_HANDLED;
  2751. }
  2752. static int iqs7222_probe(struct i2c_client *client)
  2753. {
  2754. struct iqs7222_private *iqs7222;
  2755. unsigned long irq_flags;
  2756. int error, irq;
  2757. iqs7222 = devm_kzalloc(&client->dev, sizeof(*iqs7222), GFP_KERNEL);
  2758. if (!iqs7222)
  2759. return -ENOMEM;
  2760. i2c_set_clientdata(client, iqs7222);
  2761. iqs7222->client = client;
  2762. iqs7222->keypad = devm_input_allocate_device(&client->dev);
  2763. if (!iqs7222->keypad)
  2764. return -ENOMEM;
  2765. iqs7222->keypad->name = client->name;
  2766. iqs7222->keypad->id.bustype = BUS_I2C;
  2767. /*
  2768. * The RDY pin behaves as an interrupt, but must also be polled ahead
  2769. * of unsolicited I2C communication. As such, it is first opened as a
  2770. * GPIO and then passed to gpiod_to_irq() to register the interrupt.
  2771. */
  2772. iqs7222->irq_gpio = devm_gpiod_get(&client->dev, "irq", GPIOD_IN);
  2773. if (IS_ERR(iqs7222->irq_gpio)) {
  2774. error = PTR_ERR(iqs7222->irq_gpio);
  2775. dev_err(&client->dev, "Failed to request IRQ GPIO: %d\n",
  2776. error);
  2777. return error;
  2778. }
  2779. iqs7222->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
  2780. GPIOD_OUT_HIGH);
  2781. if (IS_ERR(iqs7222->reset_gpio)) {
  2782. error = PTR_ERR(iqs7222->reset_gpio);
  2783. dev_err(&client->dev, "Failed to request reset GPIO: %d\n",
  2784. error);
  2785. return error;
  2786. }
  2787. error = iqs7222_hard_reset(iqs7222);
  2788. if (error)
  2789. return error;
  2790. error = iqs7222_dev_info(iqs7222);
  2791. if (error)
  2792. return error;
  2793. error = iqs7222_dev_init(iqs7222, READ);
  2794. if (error)
  2795. return error;
  2796. error = iqs7222_parse_all(iqs7222);
  2797. if (error)
  2798. return error;
  2799. error = iqs7222_dev_init(iqs7222, WRITE);
  2800. if (error)
  2801. return error;
  2802. error = iqs7222_report(iqs7222);
  2803. if (error)
  2804. return error;
  2805. error = input_register_device(iqs7222->keypad);
  2806. if (error) {
  2807. dev_err(&client->dev, "Failed to register device: %d\n", error);
  2808. return error;
  2809. }
  2810. irq = gpiod_to_irq(iqs7222->irq_gpio);
  2811. if (irq < 0)
  2812. return irq;
  2813. irq_flags = gpiod_is_active_low(iqs7222->irq_gpio) ? IRQF_TRIGGER_LOW
  2814. : IRQF_TRIGGER_HIGH;
  2815. irq_flags |= IRQF_ONESHOT;
  2816. error = devm_request_threaded_irq(&client->dev, irq, NULL, iqs7222_irq,
  2817. irq_flags, client->name, iqs7222);
  2818. if (error)
  2819. dev_err(&client->dev, "Failed to request IRQ: %d\n", error);
  2820. return error;
  2821. }
  2822. static const struct of_device_id iqs7222_of_match[] = {
  2823. { .compatible = "azoteq,iqs7222a" },
  2824. { .compatible = "azoteq,iqs7222b" },
  2825. { .compatible = "azoteq,iqs7222c" },
  2826. { .compatible = "azoteq,iqs7222d" },
  2827. { }
  2828. };
  2829. MODULE_DEVICE_TABLE(of, iqs7222_of_match);
  2830. static struct i2c_driver iqs7222_i2c_driver = {
  2831. .driver = {
  2832. .name = "iqs7222",
  2833. .of_match_table = iqs7222_of_match,
  2834. },
  2835. .probe = iqs7222_probe,
  2836. };
  2837. module_i2c_driver(iqs7222_i2c_driver);
  2838. MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
  2839. MODULE_DESCRIPTION("Azoteq IQS7222A/B/C/D Capacitive Touch Controller");
  2840. MODULE_LICENSE("GPL");