iqs7222.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164
  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;
  2203. event_node = 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. fwnode_handle_put(event_node);
  2223. return -EINVAL;
  2224. }
  2225. *setup &= ~(U8_MAX << i * 8);
  2226. *setup |= (val / 500 << i * 8);
  2227. } else if (error != -EINVAL) {
  2228. dev_err(&client->dev,
  2229. "Failed to read %s press timeout: %d\n",
  2230. fwnode_get_name(event_node), error);
  2231. fwnode_handle_put(event_node);
  2232. return error;
  2233. }
  2234. error = iqs7222_parse_event(iqs7222, event_node, chan_index,
  2235. IQS7222_REG_GRP_BTN,
  2236. iqs7222_kp_events[i].reg_key,
  2237. BIT(chan_index),
  2238. dev_desc->touch_link - (i ? 0 : 2),
  2239. &iqs7222->kp_type[chan_index][i],
  2240. &iqs7222->kp_code[chan_index][i]);
  2241. fwnode_handle_put(event_node);
  2242. if (error)
  2243. return error;
  2244. if (!iqs7222->kp_type[chan_index][i])
  2245. continue;
  2246. if (!dev_desc->event_offset)
  2247. continue;
  2248. sys_setup[dev_desc->event_offset] |= event_enable;
  2249. }
  2250. /*
  2251. * The following call handles a special pair of properties that apply
  2252. * to a channel node, but reside within the button (event) group.
  2253. */
  2254. return iqs7222_parse_props(iqs7222, chan_node, chan_index,
  2255. IQS7222_REG_GRP_BTN,
  2256. IQS7222_REG_KEY_DEBOUNCE);
  2257. }
  2258. static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222,
  2259. struct fwnode_handle *sldr_node, int sldr_index)
  2260. {
  2261. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2262. struct i2c_client *client = iqs7222->client;
  2263. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2264. int ext_chan = dev_desc->ext_chan ? : num_chan;
  2265. int count, error, reg_offset, i;
  2266. u16 *event_mask = &iqs7222->sys_setup[dev_desc->event_offset];
  2267. u16 *sldr_setup = iqs7222->sldr_setup[sldr_index];
  2268. unsigned int chan_sel[4], val;
  2269. /*
  2270. * Each slider can be spread across 3 to 4 channels. It is possible to
  2271. * select only 2 channels, but doing so prevents the slider from using
  2272. * the specified resolution.
  2273. */
  2274. count = fwnode_property_count_u32(sldr_node, "azoteq,channel-select");
  2275. if (count < 0) {
  2276. dev_err(&client->dev, "Failed to count %s channels: %d\n",
  2277. fwnode_get_name(sldr_node), count);
  2278. return count;
  2279. } else if (count < 3 || count > ARRAY_SIZE(chan_sel)) {
  2280. dev_err(&client->dev, "Invalid number of %s channels\n",
  2281. fwnode_get_name(sldr_node));
  2282. return -EINVAL;
  2283. }
  2284. error = fwnode_property_read_u32_array(sldr_node,
  2285. "azoteq,channel-select",
  2286. chan_sel, count);
  2287. if (error) {
  2288. dev_err(&client->dev, "Failed to read %s channels: %d\n",
  2289. fwnode_get_name(sldr_node), error);
  2290. return error;
  2291. }
  2292. /*
  2293. * Resolution and top speed, if small enough, are packed into a single
  2294. * register. Otherwise, each occupies its own register and the rest of
  2295. * the slider-related register addresses are offset by one.
  2296. */
  2297. reg_offset = dev_desc->sldr_res < U16_MAX ? 0 : 1;
  2298. sldr_setup[0] |= count;
  2299. sldr_setup[3 + reg_offset] &= ~GENMASK(ext_chan - 1, 0);
  2300. for (i = 0; i < ARRAY_SIZE(chan_sel); i++) {
  2301. sldr_setup[5 + reg_offset + i] = 0;
  2302. if (i >= count)
  2303. continue;
  2304. if (chan_sel[i] >= ext_chan) {
  2305. dev_err(&client->dev, "Invalid %s channel: %u\n",
  2306. fwnode_get_name(sldr_node), chan_sel[i]);
  2307. return -EINVAL;
  2308. }
  2309. /*
  2310. * The following fields indicate which channels participate in
  2311. * the slider, as well as each channel's relative placement.
  2312. */
  2313. sldr_setup[3 + reg_offset] |= BIT(chan_sel[i]);
  2314. sldr_setup[5 + reg_offset + i] = chan_sel[i] * 42 + 1080;
  2315. }
  2316. sldr_setup[4 + reg_offset] = dev_desc->touch_link;
  2317. if (fwnode_property_present(sldr_node, "azoteq,use-prox"))
  2318. sldr_setup[4 + reg_offset] -= 2;
  2319. error = fwnode_property_read_u32(sldr_node, "azoteq,slider-size", &val);
  2320. if (!error) {
  2321. if (val > dev_desc->sldr_res) {
  2322. dev_err(&client->dev, "Invalid %s size: %u\n",
  2323. fwnode_get_name(sldr_node), val);
  2324. return -EINVAL;
  2325. }
  2326. if (reg_offset) {
  2327. sldr_setup[3] = val;
  2328. } else {
  2329. sldr_setup[2] &= ~IQS7222_SLDR_SETUP_2_RES_MASK;
  2330. sldr_setup[2] |= (val / 16 <<
  2331. IQS7222_SLDR_SETUP_2_RES_SHIFT);
  2332. }
  2333. } else if (error != -EINVAL) {
  2334. dev_err(&client->dev, "Failed to read %s size: %d\n",
  2335. fwnode_get_name(sldr_node), error);
  2336. return error;
  2337. }
  2338. if (!(reg_offset ? sldr_setup[3]
  2339. : sldr_setup[2] & IQS7222_SLDR_SETUP_2_RES_MASK)) {
  2340. dev_err(&client->dev, "Undefined %s size\n",
  2341. fwnode_get_name(sldr_node));
  2342. return -EINVAL;
  2343. }
  2344. error = fwnode_property_read_u32(sldr_node, "azoteq,top-speed", &val);
  2345. if (!error) {
  2346. if (val > (reg_offset ? U16_MAX : U8_MAX * 4)) {
  2347. dev_err(&client->dev, "Invalid %s top speed: %u\n",
  2348. fwnode_get_name(sldr_node), val);
  2349. return -EINVAL;
  2350. }
  2351. if (reg_offset) {
  2352. sldr_setup[2] = val;
  2353. } else {
  2354. sldr_setup[2] &= ~IQS7222_SLDR_SETUP_2_TOP_SPEED_MASK;
  2355. sldr_setup[2] |= (val / 4);
  2356. }
  2357. } else if (error != -EINVAL) {
  2358. dev_err(&client->dev, "Failed to read %s top speed: %d\n",
  2359. fwnode_get_name(sldr_node), error);
  2360. return error;
  2361. }
  2362. error = fwnode_property_read_u32(sldr_node, "linux,axis", &val);
  2363. if (!error) {
  2364. u16 sldr_max = sldr_setup[3] - 1;
  2365. if (!reg_offset) {
  2366. sldr_max = sldr_setup[2];
  2367. sldr_max &= IQS7222_SLDR_SETUP_2_RES_MASK;
  2368. sldr_max >>= IQS7222_SLDR_SETUP_2_RES_SHIFT;
  2369. sldr_max = sldr_max * 16 - 1;
  2370. }
  2371. input_set_abs_params(iqs7222->keypad, val, 0, sldr_max, 0, 0);
  2372. iqs7222->sl_axis[sldr_index] = val;
  2373. } else if (error != -EINVAL) {
  2374. dev_err(&client->dev, "Failed to read %s axis: %d\n",
  2375. fwnode_get_name(sldr_node), error);
  2376. return error;
  2377. }
  2378. if (dev_desc->wheel_enable) {
  2379. sldr_setup[0] &= ~dev_desc->wheel_enable;
  2380. if (iqs7222->sl_axis[sldr_index] == ABS_WHEEL)
  2381. sldr_setup[0] |= dev_desc->wheel_enable;
  2382. }
  2383. /*
  2384. * The absence of a register offset makes it safe to assume the device
  2385. * supports gestures, each of which is first disabled until explicitly
  2386. * enabled.
  2387. */
  2388. if (!reg_offset)
  2389. for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++)
  2390. sldr_setup[9] &= ~iqs7222_sl_events[i].enable;
  2391. for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++) {
  2392. const char *event_name = iqs7222_sl_events[i].name;
  2393. struct fwnode_handle *event_node;
  2394. enum iqs7222_reg_key_id reg_key;
  2395. event_node = fwnode_get_named_child_node(sldr_node, event_name);
  2396. if (!event_node)
  2397. continue;
  2398. /*
  2399. * Depending on the device, gestures are either offered using
  2400. * one of two timing resolutions, or are not supported at all.
  2401. */
  2402. if (reg_offset)
  2403. reg_key = IQS7222_REG_KEY_RESERVED;
  2404. else if (dev_desc->legacy_gesture &&
  2405. iqs7222_sl_events[i].reg_key == IQS7222_REG_KEY_TAP)
  2406. reg_key = IQS7222_REG_KEY_TAP_LEGACY;
  2407. else if (dev_desc->legacy_gesture &&
  2408. iqs7222_sl_events[i].reg_key == IQS7222_REG_KEY_AXIAL)
  2409. reg_key = IQS7222_REG_KEY_AXIAL_LEGACY;
  2410. else
  2411. reg_key = iqs7222_sl_events[i].reg_key;
  2412. /*
  2413. * The press/release event does not expose a direct GPIO link,
  2414. * but one can be emulated by tying each of the participating
  2415. * channels to the same GPIO.
  2416. */
  2417. error = iqs7222_parse_event(iqs7222, event_node, sldr_index,
  2418. IQS7222_REG_GRP_SLDR, reg_key,
  2419. i ? iqs7222_sl_events[i].enable
  2420. : sldr_setup[3 + reg_offset],
  2421. i ? 1568 + sldr_index * 30
  2422. : sldr_setup[4 + reg_offset],
  2423. NULL,
  2424. &iqs7222->sl_code[sldr_index][i]);
  2425. fwnode_handle_put(event_node);
  2426. if (error)
  2427. return error;
  2428. if (!reg_offset)
  2429. sldr_setup[9] |= iqs7222_sl_events[i].enable;
  2430. if (!dev_desc->event_offset)
  2431. continue;
  2432. /*
  2433. * The press/release event is determined based on whether the
  2434. * coordinate field reports 0xFFFF and solely relies on touch
  2435. * or proximity interrupts to be unmasked.
  2436. */
  2437. if (i && !reg_offset)
  2438. *event_mask |= (IQS7222_EVENT_MASK_SLDR << sldr_index);
  2439. else if (sldr_setup[4 + reg_offset] == dev_desc->touch_link)
  2440. *event_mask |= IQS7222_EVENT_MASK_TOUCH;
  2441. else
  2442. *event_mask |= IQS7222_EVENT_MASK_PROX;
  2443. }
  2444. /*
  2445. * The following call handles a special pair of properties that shift
  2446. * to make room for a wheel enable control in the case of IQS7222C.
  2447. */
  2448. return iqs7222_parse_props(iqs7222, sldr_node, sldr_index,
  2449. IQS7222_REG_GRP_SLDR,
  2450. dev_desc->wheel_enable ?
  2451. IQS7222_REG_KEY_WHEEL :
  2452. IQS7222_REG_KEY_NO_WHEEL);
  2453. }
  2454. static int iqs7222_parse_tpad(struct iqs7222_private *iqs7222,
  2455. struct fwnode_handle *tpad_node, int tpad_index)
  2456. {
  2457. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2458. struct touchscreen_properties *prop = &iqs7222->prop;
  2459. struct i2c_client *client = iqs7222->client;
  2460. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2461. int count, error, i;
  2462. u16 *event_mask = &iqs7222->sys_setup[dev_desc->event_offset];
  2463. u16 *tpad_setup = iqs7222->tpad_setup;
  2464. unsigned int chan_sel[12];
  2465. error = iqs7222_parse_props(iqs7222, tpad_node, tpad_index,
  2466. IQS7222_REG_GRP_TPAD,
  2467. IQS7222_REG_KEY_NONE);
  2468. if (error)
  2469. return error;
  2470. count = fwnode_property_count_u32(tpad_node, "azoteq,channel-select");
  2471. if (count < 0) {
  2472. dev_err(&client->dev, "Failed to count %s channels: %d\n",
  2473. fwnode_get_name(tpad_node), count);
  2474. return count;
  2475. } else if (!count || count > ARRAY_SIZE(chan_sel)) {
  2476. dev_err(&client->dev, "Invalid number of %s channels\n",
  2477. fwnode_get_name(tpad_node));
  2478. return -EINVAL;
  2479. }
  2480. error = fwnode_property_read_u32_array(tpad_node,
  2481. "azoteq,channel-select",
  2482. chan_sel, count);
  2483. if (error) {
  2484. dev_err(&client->dev, "Failed to read %s channels: %d\n",
  2485. fwnode_get_name(tpad_node), error);
  2486. return error;
  2487. }
  2488. tpad_setup[6] &= ~GENMASK(num_chan - 1, 0);
  2489. for (i = 0; i < ARRAY_SIZE(chan_sel); i++) {
  2490. tpad_setup[8 + i] = 0;
  2491. if (i >= count || chan_sel[i] == U8_MAX)
  2492. continue;
  2493. if (chan_sel[i] >= num_chan) {
  2494. dev_err(&client->dev, "Invalid %s channel: %u\n",
  2495. fwnode_get_name(tpad_node), chan_sel[i]);
  2496. return -EINVAL;
  2497. }
  2498. /*
  2499. * The following fields indicate which channels participate in
  2500. * the trackpad, as well as each channel's relative placement.
  2501. */
  2502. tpad_setup[6] |= BIT(chan_sel[i]);
  2503. tpad_setup[8 + i] = chan_sel[i] * 34 + 1072;
  2504. }
  2505. tpad_setup[7] = dev_desc->touch_link;
  2506. if (fwnode_property_present(tpad_node, "azoteq,use-prox"))
  2507. tpad_setup[7] -= 2;
  2508. for (i = 0; i < ARRAY_SIZE(iqs7222_tp_events); i++)
  2509. tpad_setup[20] &= ~(iqs7222_tp_events[i].strict |
  2510. iqs7222_tp_events[i].enable);
  2511. for (i = 0; i < ARRAY_SIZE(iqs7222_tp_events); i++) {
  2512. const char *event_name = iqs7222_tp_events[i].name;
  2513. struct fwnode_handle *event_node;
  2514. event_node = fwnode_get_named_child_node(tpad_node, event_name);
  2515. if (!event_node)
  2516. continue;
  2517. if (fwnode_property_present(event_node,
  2518. "azoteq,gesture-angle-tighten"))
  2519. tpad_setup[20] |= iqs7222_tp_events[i].strict;
  2520. tpad_setup[20] |= iqs7222_tp_events[i].enable;
  2521. error = iqs7222_parse_event(iqs7222, event_node, tpad_index,
  2522. IQS7222_REG_GRP_TPAD,
  2523. iqs7222_tp_events[i].reg_key,
  2524. iqs7222_tp_events[i].link, 1566,
  2525. NULL,
  2526. &iqs7222->tp_code[i]);
  2527. fwnode_handle_put(event_node);
  2528. if (error)
  2529. return error;
  2530. if (!dev_desc->event_offset)
  2531. continue;
  2532. /*
  2533. * The press/release event is determined based on whether the
  2534. * coordinate fields report 0xFFFF and solely relies on touch
  2535. * or proximity interrupts to be unmasked.
  2536. */
  2537. if (i)
  2538. *event_mask |= IQS7222_EVENT_MASK_TPAD;
  2539. else if (tpad_setup[7] == dev_desc->touch_link)
  2540. *event_mask |= IQS7222_EVENT_MASK_TOUCH;
  2541. else
  2542. *event_mask |= IQS7222_EVENT_MASK_PROX;
  2543. }
  2544. if (!iqs7222->tp_code[0])
  2545. return 0;
  2546. input_set_abs_params(iqs7222->keypad, ABS_X,
  2547. 0, (tpad_setup[4] ? : 1) - 1, 0, 0);
  2548. input_set_abs_params(iqs7222->keypad, ABS_Y,
  2549. 0, (tpad_setup[5] ? : 1) - 1, 0, 0);
  2550. touchscreen_parse_properties(iqs7222->keypad, false, prop);
  2551. if (prop->max_x >= U16_MAX || prop->max_y >= U16_MAX) {
  2552. dev_err(&client->dev, "Invalid trackpad size: %u*%u\n",
  2553. prop->max_x, prop->max_y);
  2554. return -EINVAL;
  2555. }
  2556. tpad_setup[4] = prop->max_x + 1;
  2557. tpad_setup[5] = prop->max_y + 1;
  2558. return 0;
  2559. }
  2560. static int (*iqs7222_parse_extra[IQS7222_NUM_REG_GRPS])
  2561. (struct iqs7222_private *iqs7222,
  2562. struct fwnode_handle *reg_grp_node,
  2563. int reg_grp_index) = {
  2564. [IQS7222_REG_GRP_CYCLE] = iqs7222_parse_cycle,
  2565. [IQS7222_REG_GRP_CHAN] = iqs7222_parse_chan,
  2566. [IQS7222_REG_GRP_SLDR] = iqs7222_parse_sldr,
  2567. [IQS7222_REG_GRP_TPAD] = iqs7222_parse_tpad,
  2568. };
  2569. static int iqs7222_parse_reg_grp(struct iqs7222_private *iqs7222,
  2570. enum iqs7222_reg_grp_id reg_grp,
  2571. int reg_grp_index)
  2572. {
  2573. struct i2c_client *client = iqs7222->client;
  2574. struct fwnode_handle *reg_grp_node;
  2575. int error;
  2576. if (iqs7222_reg_grp_names[reg_grp]) {
  2577. char reg_grp_name[16];
  2578. snprintf(reg_grp_name, sizeof(reg_grp_name),
  2579. iqs7222_reg_grp_names[reg_grp], reg_grp_index);
  2580. reg_grp_node = device_get_named_child_node(&client->dev,
  2581. reg_grp_name);
  2582. } else {
  2583. reg_grp_node = fwnode_handle_get(dev_fwnode(&client->dev));
  2584. }
  2585. if (!reg_grp_node)
  2586. return 0;
  2587. error = iqs7222_parse_props(iqs7222, reg_grp_node, reg_grp_index,
  2588. reg_grp, IQS7222_REG_KEY_NONE);
  2589. if (!error && iqs7222_parse_extra[reg_grp])
  2590. error = iqs7222_parse_extra[reg_grp](iqs7222, reg_grp_node,
  2591. reg_grp_index);
  2592. fwnode_handle_put(reg_grp_node);
  2593. return error;
  2594. }
  2595. static int iqs7222_parse_all(struct iqs7222_private *iqs7222)
  2596. {
  2597. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2598. const struct iqs7222_reg_grp_desc *reg_grps = dev_desc->reg_grps;
  2599. u16 *sys_setup = iqs7222->sys_setup;
  2600. int error, i, j;
  2601. if (dev_desc->allow_offset)
  2602. sys_setup[dev_desc->allow_offset] = U16_MAX;
  2603. if (dev_desc->event_offset)
  2604. sys_setup[dev_desc->event_offset] = IQS7222_EVENT_MASK_ATI;
  2605. for (i = 0; i < reg_grps[IQS7222_REG_GRP_GPIO].num_row; i++) {
  2606. u16 *gpio_setup = iqs7222->gpio_setup[i];
  2607. gpio_setup[0] &= ~IQS7222_GPIO_SETUP_0_GPIO_EN;
  2608. gpio_setup[1] = 0;
  2609. gpio_setup[2] = 0;
  2610. if (reg_grps[IQS7222_REG_GRP_GPIO].num_row == 1)
  2611. continue;
  2612. /*
  2613. * The IQS7222C and IQS7222D expose multiple GPIO and must be
  2614. * informed as to which GPIO this group represents.
  2615. */
  2616. for (j = 0; j < ARRAY_SIZE(iqs7222_gpio_links); j++)
  2617. gpio_setup[0] &= ~BIT(iqs7222_gpio_links[j]);
  2618. gpio_setup[0] |= BIT(iqs7222_gpio_links[i]);
  2619. }
  2620. for (i = 0; i < reg_grps[IQS7222_REG_GRP_CHAN].num_row; i++) {
  2621. u16 *chan_setup = iqs7222->chan_setup[i];
  2622. chan_setup[0] &= ~IQS7222_CHAN_SETUP_0_REF_MODE_MASK;
  2623. chan_setup[0] &= ~IQS7222_CHAN_SETUP_0_CHAN_EN;
  2624. chan_setup[5] = 0;
  2625. }
  2626. for (i = 0; i < reg_grps[IQS7222_REG_GRP_SLDR].num_row; i++) {
  2627. u16 *sldr_setup = iqs7222->sldr_setup[i];
  2628. sldr_setup[0] &= ~IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK;
  2629. }
  2630. for (i = 0; i < IQS7222_NUM_REG_GRPS; i++) {
  2631. for (j = 0; j < reg_grps[i].num_row; j++) {
  2632. error = iqs7222_parse_reg_grp(iqs7222, i, j);
  2633. if (error)
  2634. return error;
  2635. }
  2636. }
  2637. return 0;
  2638. }
  2639. static int iqs7222_report(struct iqs7222_private *iqs7222)
  2640. {
  2641. const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
  2642. struct i2c_client *client = iqs7222->client;
  2643. int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
  2644. int num_stat = dev_desc->reg_grps[IQS7222_REG_GRP_STAT].num_col;
  2645. int error, i, j;
  2646. __le16 status[IQS7222_MAX_COLS_STAT];
  2647. error = iqs7222_read_burst(iqs7222, IQS7222_SYS_STATUS, status,
  2648. num_stat * sizeof(*status));
  2649. if (error)
  2650. return error;
  2651. if (le16_to_cpu(status[0]) & IQS7222_SYS_STATUS_RESET) {
  2652. dev_err(&client->dev, "Unexpected device reset\n");
  2653. return iqs7222_dev_init(iqs7222, WRITE);
  2654. }
  2655. if (le16_to_cpu(status[0]) & IQS7222_SYS_STATUS_ATI_ERROR) {
  2656. dev_err(&client->dev, "Unexpected ATI error\n");
  2657. return iqs7222_ati_trigger(iqs7222);
  2658. }
  2659. if (le16_to_cpu(status[0]) & IQS7222_SYS_STATUS_ATI_ACTIVE)
  2660. return 0;
  2661. for (i = 0; i < num_chan; i++) {
  2662. u16 *chan_setup = iqs7222->chan_setup[i];
  2663. if (!(chan_setup[0] & IQS7222_CHAN_SETUP_0_CHAN_EN))
  2664. continue;
  2665. for (j = 0; j < ARRAY_SIZE(iqs7222_kp_events); j++) {
  2666. /*
  2667. * Proximity state begins at offset 2 and spills into
  2668. * offset 3 for devices with more than 16 channels.
  2669. *
  2670. * Touch state begins at the first offset immediately
  2671. * following proximity state.
  2672. */
  2673. int k = 2 + j * (num_chan > 16 ? 2 : 1);
  2674. u16 state = le16_to_cpu(status[k + i / 16]);
  2675. if (!iqs7222->kp_type[i][j])
  2676. continue;
  2677. input_event(iqs7222->keypad,
  2678. iqs7222->kp_type[i][j],
  2679. iqs7222->kp_code[i][j],
  2680. !!(state & BIT(i % 16)));
  2681. }
  2682. }
  2683. for (i = 0; i < dev_desc->reg_grps[IQS7222_REG_GRP_SLDR].num_row; i++) {
  2684. u16 *sldr_setup = iqs7222->sldr_setup[i];
  2685. u16 sldr_pos = le16_to_cpu(status[4 + i]);
  2686. u16 state = le16_to_cpu(status[6 + i]);
  2687. if (!(sldr_setup[0] & IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK))
  2688. continue;
  2689. if (sldr_pos < dev_desc->sldr_res)
  2690. input_report_abs(iqs7222->keypad, iqs7222->sl_axis[i],
  2691. sldr_pos);
  2692. input_report_key(iqs7222->keypad, iqs7222->sl_code[i][0],
  2693. sldr_pos < dev_desc->sldr_res);
  2694. /*
  2695. * A maximum resolution indicates the device does not support
  2696. * gestures, in which case the remaining fields are ignored.
  2697. */
  2698. if (dev_desc->sldr_res == U16_MAX)
  2699. continue;
  2700. if (!(le16_to_cpu(status[1]) & IQS7222_EVENT_MASK_SLDR << i))
  2701. continue;
  2702. /*
  2703. * Skip the press/release event, as it does not have separate
  2704. * status fields and is handled separately.
  2705. */
  2706. for (j = 1; j < ARRAY_SIZE(iqs7222_sl_events); j++) {
  2707. u16 mask = iqs7222_sl_events[j].mask;
  2708. u16 val = iqs7222_sl_events[j].val;
  2709. input_report_key(iqs7222->keypad,
  2710. iqs7222->sl_code[i][j],
  2711. (state & mask) == val);
  2712. }
  2713. input_sync(iqs7222->keypad);
  2714. for (j = 1; j < ARRAY_SIZE(iqs7222_sl_events); j++)
  2715. input_report_key(iqs7222->keypad,
  2716. iqs7222->sl_code[i][j], 0);
  2717. }
  2718. for (i = 0; i < dev_desc->reg_grps[IQS7222_REG_GRP_TPAD].num_row; i++) {
  2719. u16 tpad_pos_x = le16_to_cpu(status[4]);
  2720. u16 tpad_pos_y = le16_to_cpu(status[5]);
  2721. u16 state = le16_to_cpu(status[6]);
  2722. input_report_key(iqs7222->keypad, iqs7222->tp_code[0],
  2723. tpad_pos_x < U16_MAX);
  2724. if (tpad_pos_x < U16_MAX)
  2725. touchscreen_report_pos(iqs7222->keypad, &iqs7222->prop,
  2726. tpad_pos_x, tpad_pos_y, false);
  2727. if (!(le16_to_cpu(status[1]) & IQS7222_EVENT_MASK_TPAD))
  2728. continue;
  2729. /*
  2730. * Skip the press/release event, as it does not have separate
  2731. * status fields and is handled separately.
  2732. */
  2733. for (j = 1; j < ARRAY_SIZE(iqs7222_tp_events); j++) {
  2734. u16 mask = iqs7222_tp_events[j].mask;
  2735. u16 val = iqs7222_tp_events[j].val;
  2736. input_report_key(iqs7222->keypad,
  2737. iqs7222->tp_code[j],
  2738. (state & mask) == val);
  2739. }
  2740. input_sync(iqs7222->keypad);
  2741. for (j = 1; j < ARRAY_SIZE(iqs7222_tp_events); j++)
  2742. input_report_key(iqs7222->keypad,
  2743. iqs7222->tp_code[j], 0);
  2744. }
  2745. input_sync(iqs7222->keypad);
  2746. return 0;
  2747. }
  2748. static irqreturn_t iqs7222_irq(int irq, void *context)
  2749. {
  2750. struct iqs7222_private *iqs7222 = context;
  2751. return iqs7222_report(iqs7222) ? IRQ_NONE : IRQ_HANDLED;
  2752. }
  2753. static int iqs7222_probe(struct i2c_client *client)
  2754. {
  2755. struct iqs7222_private *iqs7222;
  2756. unsigned long irq_flags;
  2757. int error, irq;
  2758. iqs7222 = devm_kzalloc(&client->dev, sizeof(*iqs7222), GFP_KERNEL);
  2759. if (!iqs7222)
  2760. return -ENOMEM;
  2761. i2c_set_clientdata(client, iqs7222);
  2762. iqs7222->client = client;
  2763. iqs7222->keypad = devm_input_allocate_device(&client->dev);
  2764. if (!iqs7222->keypad)
  2765. return -ENOMEM;
  2766. iqs7222->keypad->name = client->name;
  2767. iqs7222->keypad->id.bustype = BUS_I2C;
  2768. /*
  2769. * The RDY pin behaves as an interrupt, but must also be polled ahead
  2770. * of unsolicited I2C communication. As such, it is first opened as a
  2771. * GPIO and then passed to gpiod_to_irq() to register the interrupt.
  2772. */
  2773. iqs7222->irq_gpio = devm_gpiod_get(&client->dev, "irq", GPIOD_IN);
  2774. if (IS_ERR(iqs7222->irq_gpio)) {
  2775. error = PTR_ERR(iqs7222->irq_gpio);
  2776. dev_err(&client->dev, "Failed to request IRQ GPIO: %d\n",
  2777. error);
  2778. return error;
  2779. }
  2780. iqs7222->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
  2781. GPIOD_OUT_HIGH);
  2782. if (IS_ERR(iqs7222->reset_gpio)) {
  2783. error = PTR_ERR(iqs7222->reset_gpio);
  2784. dev_err(&client->dev, "Failed to request reset GPIO: %d\n",
  2785. error);
  2786. return error;
  2787. }
  2788. error = iqs7222_hard_reset(iqs7222);
  2789. if (error)
  2790. return error;
  2791. error = iqs7222_dev_info(iqs7222);
  2792. if (error)
  2793. return error;
  2794. error = iqs7222_dev_init(iqs7222, READ);
  2795. if (error)
  2796. return error;
  2797. error = iqs7222_parse_all(iqs7222);
  2798. if (error)
  2799. return error;
  2800. error = iqs7222_dev_init(iqs7222, WRITE);
  2801. if (error)
  2802. return error;
  2803. error = iqs7222_report(iqs7222);
  2804. if (error)
  2805. return error;
  2806. error = input_register_device(iqs7222->keypad);
  2807. if (error) {
  2808. dev_err(&client->dev, "Failed to register device: %d\n", error);
  2809. return error;
  2810. }
  2811. irq = gpiod_to_irq(iqs7222->irq_gpio);
  2812. if (irq < 0)
  2813. return irq;
  2814. irq_flags = gpiod_is_active_low(iqs7222->irq_gpio) ? IRQF_TRIGGER_LOW
  2815. : IRQF_TRIGGER_HIGH;
  2816. irq_flags |= IRQF_ONESHOT;
  2817. error = devm_request_threaded_irq(&client->dev, irq, NULL, iqs7222_irq,
  2818. irq_flags, client->name, iqs7222);
  2819. if (error)
  2820. dev_err(&client->dev, "Failed to request IRQ: %d\n", error);
  2821. return error;
  2822. }
  2823. static const struct of_device_id iqs7222_of_match[] = {
  2824. { .compatible = "azoteq,iqs7222a" },
  2825. { .compatible = "azoteq,iqs7222b" },
  2826. { .compatible = "azoteq,iqs7222c" },
  2827. { .compatible = "azoteq,iqs7222d" },
  2828. { }
  2829. };
  2830. MODULE_DEVICE_TABLE(of, iqs7222_of_match);
  2831. static struct i2c_driver iqs7222_i2c_driver = {
  2832. .driver = {
  2833. .name = "iqs7222",
  2834. .of_match_table = iqs7222_of_match,
  2835. },
  2836. .probe = iqs7222_probe,
  2837. };
  2838. module_i2c_driver(iqs7222_i2c_driver);
  2839. MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
  2840. MODULE_DESCRIPTION("Azoteq IQS7222A/B/C/D Capacitive Touch Controller");
  2841. MODULE_LICENSE("GPL");