iqs7211.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Azoteq IQS7210A/7211A/E Trackpad/Touchscreen Controller
  4. *
  5. * Copyright (C) 2023 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/mt.h>
  15. #include <linux/input/touchscreen.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/iopoll.h>
  18. #include <linux/kernel.h>
  19. #include <linux/list.h>
  20. #include <linux/module.h>
  21. #include <linux/of_device.h>
  22. #include <linux/property.h>
  23. #include <linux/slab.h>
  24. #include <linux/unaligned.h>
  25. #define IQS7211_PROD_NUM 0x00
  26. #define IQS7211_EVENT_MASK_ALL GENMASK(14, 8)
  27. #define IQS7211_EVENT_MASK_ALP BIT(13)
  28. #define IQS7211_EVENT_MASK_BTN BIT(12)
  29. #define IQS7211_EVENT_MASK_ATI BIT(11)
  30. #define IQS7211_EVENT_MASK_MOVE BIT(10)
  31. #define IQS7211_EVENT_MASK_GSTR BIT(9)
  32. #define IQS7211_EVENT_MODE BIT(8)
  33. #define IQS7211_COMMS_ERROR 0xEEEE
  34. #define IQS7211_COMMS_RETRY_MS 50
  35. #define IQS7211_COMMS_SLEEP_US 100
  36. #define IQS7211_COMMS_TIMEOUT_US (100 * USEC_PER_MSEC)
  37. #define IQS7211_RESET_TIMEOUT_MS 150
  38. #define IQS7211_START_TIMEOUT_US (1 * USEC_PER_SEC)
  39. #define IQS7211_NUM_RETRIES 5
  40. #define IQS7211_NUM_CRX 8
  41. #define IQS7211_MAX_CTX 13
  42. #define IQS7211_MAX_CONTACTS 2
  43. #define IQS7211_MAX_CYCLES 21
  44. /*
  45. * The following delay is used during instances that must wait for the open-
  46. * drain RDY pin to settle. Its value is calculated as 5*R*C, where R and C
  47. * represent typical datasheet values of 4.7k and 100 nF, respectively.
  48. */
  49. #define iqs7211_irq_wait() usleep_range(2500, 2600)
  50. enum iqs7211_dev_id {
  51. IQS7210A,
  52. IQS7211A,
  53. IQS7211E,
  54. };
  55. enum iqs7211_comms_mode {
  56. IQS7211_COMMS_MODE_WAIT,
  57. IQS7211_COMMS_MODE_FREE,
  58. IQS7211_COMMS_MODE_FORCE,
  59. };
  60. struct iqs7211_reg_field_desc {
  61. struct list_head list;
  62. u8 addr;
  63. u16 mask;
  64. u16 val;
  65. };
  66. enum iqs7211_reg_key_id {
  67. IQS7211_REG_KEY_NONE,
  68. IQS7211_REG_KEY_PROX,
  69. IQS7211_REG_KEY_TOUCH,
  70. IQS7211_REG_KEY_TAP,
  71. IQS7211_REG_KEY_HOLD,
  72. IQS7211_REG_KEY_PALM,
  73. IQS7211_REG_KEY_AXIAL_X,
  74. IQS7211_REG_KEY_AXIAL_Y,
  75. IQS7211_REG_KEY_RESERVED
  76. };
  77. enum iqs7211_reg_grp_id {
  78. IQS7211_REG_GRP_TP,
  79. IQS7211_REG_GRP_BTN,
  80. IQS7211_REG_GRP_ALP,
  81. IQS7211_REG_GRP_SYS,
  82. IQS7211_NUM_REG_GRPS
  83. };
  84. static const char * const iqs7211_reg_grp_names[IQS7211_NUM_REG_GRPS] = {
  85. [IQS7211_REG_GRP_TP] = "trackpad",
  86. [IQS7211_REG_GRP_BTN] = "button",
  87. [IQS7211_REG_GRP_ALP] = "alp",
  88. };
  89. static const u16 iqs7211_reg_grp_masks[IQS7211_NUM_REG_GRPS] = {
  90. [IQS7211_REG_GRP_TP] = IQS7211_EVENT_MASK_GSTR,
  91. [IQS7211_REG_GRP_BTN] = IQS7211_EVENT_MASK_BTN,
  92. [IQS7211_REG_GRP_ALP] = IQS7211_EVENT_MASK_ALP,
  93. };
  94. struct iqs7211_event_desc {
  95. const char *name;
  96. u16 mask;
  97. u16 enable;
  98. enum iqs7211_reg_grp_id reg_grp;
  99. enum iqs7211_reg_key_id reg_key;
  100. };
  101. static const struct iqs7211_event_desc iqs7210a_kp_events[] = {
  102. {
  103. .mask = BIT(10),
  104. .enable = BIT(13) | BIT(12),
  105. .reg_grp = IQS7211_REG_GRP_ALP,
  106. },
  107. {
  108. .name = "event-prox",
  109. .mask = BIT(2),
  110. .enable = BIT(5) | BIT(4),
  111. .reg_grp = IQS7211_REG_GRP_BTN,
  112. .reg_key = IQS7211_REG_KEY_PROX,
  113. },
  114. {
  115. .name = "event-touch",
  116. .mask = BIT(3),
  117. .enable = BIT(5) | BIT(4),
  118. .reg_grp = IQS7211_REG_GRP_BTN,
  119. .reg_key = IQS7211_REG_KEY_TOUCH,
  120. },
  121. {
  122. .name = "event-tap",
  123. .mask = BIT(0),
  124. .enable = BIT(0),
  125. .reg_grp = IQS7211_REG_GRP_TP,
  126. .reg_key = IQS7211_REG_KEY_TAP,
  127. },
  128. {
  129. .name = "event-hold",
  130. .mask = BIT(1),
  131. .enable = BIT(1),
  132. .reg_grp = IQS7211_REG_GRP_TP,
  133. .reg_key = IQS7211_REG_KEY_HOLD,
  134. },
  135. {
  136. .name = "event-swipe-x-neg",
  137. .mask = BIT(2),
  138. .enable = BIT(2),
  139. .reg_grp = IQS7211_REG_GRP_TP,
  140. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  141. },
  142. {
  143. .name = "event-swipe-x-pos",
  144. .mask = BIT(3),
  145. .enable = BIT(3),
  146. .reg_grp = IQS7211_REG_GRP_TP,
  147. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  148. },
  149. {
  150. .name = "event-swipe-y-pos",
  151. .mask = BIT(4),
  152. .enable = BIT(4),
  153. .reg_grp = IQS7211_REG_GRP_TP,
  154. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  155. },
  156. {
  157. .name = "event-swipe-y-neg",
  158. .mask = BIT(5),
  159. .enable = BIT(5),
  160. .reg_grp = IQS7211_REG_GRP_TP,
  161. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  162. },
  163. };
  164. static const struct iqs7211_event_desc iqs7211a_kp_events[] = {
  165. {
  166. .mask = BIT(14),
  167. .reg_grp = IQS7211_REG_GRP_ALP,
  168. },
  169. {
  170. .name = "event-tap",
  171. .mask = BIT(0),
  172. .enable = BIT(0),
  173. .reg_grp = IQS7211_REG_GRP_TP,
  174. .reg_key = IQS7211_REG_KEY_TAP,
  175. },
  176. {
  177. .name = "event-hold",
  178. .mask = BIT(1),
  179. .enable = BIT(1),
  180. .reg_grp = IQS7211_REG_GRP_TP,
  181. .reg_key = IQS7211_REG_KEY_HOLD,
  182. },
  183. {
  184. .name = "event-swipe-x-neg",
  185. .mask = BIT(2),
  186. .enable = BIT(2),
  187. .reg_grp = IQS7211_REG_GRP_TP,
  188. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  189. },
  190. {
  191. .name = "event-swipe-x-pos",
  192. .mask = BIT(3),
  193. .enable = BIT(3),
  194. .reg_grp = IQS7211_REG_GRP_TP,
  195. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  196. },
  197. {
  198. .name = "event-swipe-y-pos",
  199. .mask = BIT(4),
  200. .enable = BIT(4),
  201. .reg_grp = IQS7211_REG_GRP_TP,
  202. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  203. },
  204. {
  205. .name = "event-swipe-y-neg",
  206. .mask = BIT(5),
  207. .enable = BIT(5),
  208. .reg_grp = IQS7211_REG_GRP_TP,
  209. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  210. },
  211. };
  212. static const struct iqs7211_event_desc iqs7211e_kp_events[] = {
  213. {
  214. .mask = BIT(14),
  215. .reg_grp = IQS7211_REG_GRP_ALP,
  216. },
  217. {
  218. .name = "event-tap",
  219. .mask = BIT(0),
  220. .enable = BIT(0),
  221. .reg_grp = IQS7211_REG_GRP_TP,
  222. .reg_key = IQS7211_REG_KEY_TAP,
  223. },
  224. {
  225. .name = "event-tap-double",
  226. .mask = BIT(1),
  227. .enable = BIT(1),
  228. .reg_grp = IQS7211_REG_GRP_TP,
  229. .reg_key = IQS7211_REG_KEY_TAP,
  230. },
  231. {
  232. .name = "event-tap-triple",
  233. .mask = BIT(2),
  234. .enable = BIT(2),
  235. .reg_grp = IQS7211_REG_GRP_TP,
  236. .reg_key = IQS7211_REG_KEY_TAP,
  237. },
  238. {
  239. .name = "event-hold",
  240. .mask = BIT(3),
  241. .enable = BIT(3),
  242. .reg_grp = IQS7211_REG_GRP_TP,
  243. .reg_key = IQS7211_REG_KEY_HOLD,
  244. },
  245. {
  246. .name = "event-palm",
  247. .mask = BIT(4),
  248. .enable = BIT(4),
  249. .reg_grp = IQS7211_REG_GRP_TP,
  250. .reg_key = IQS7211_REG_KEY_PALM,
  251. },
  252. {
  253. .name = "event-swipe-x-pos",
  254. .mask = BIT(8),
  255. .enable = BIT(8),
  256. .reg_grp = IQS7211_REG_GRP_TP,
  257. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  258. },
  259. {
  260. .name = "event-swipe-x-neg",
  261. .mask = BIT(9),
  262. .enable = BIT(9),
  263. .reg_grp = IQS7211_REG_GRP_TP,
  264. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  265. },
  266. {
  267. .name = "event-swipe-y-pos",
  268. .mask = BIT(10),
  269. .enable = BIT(10),
  270. .reg_grp = IQS7211_REG_GRP_TP,
  271. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  272. },
  273. {
  274. .name = "event-swipe-y-neg",
  275. .mask = BIT(11),
  276. .enable = BIT(11),
  277. .reg_grp = IQS7211_REG_GRP_TP,
  278. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  279. },
  280. {
  281. .name = "event-swipe-x-pos-hold",
  282. .mask = BIT(12),
  283. .enable = BIT(12),
  284. .reg_grp = IQS7211_REG_GRP_TP,
  285. .reg_key = IQS7211_REG_KEY_HOLD,
  286. },
  287. {
  288. .name = "event-swipe-x-neg-hold",
  289. .mask = BIT(13),
  290. .enable = BIT(13),
  291. .reg_grp = IQS7211_REG_GRP_TP,
  292. .reg_key = IQS7211_REG_KEY_HOLD,
  293. },
  294. {
  295. .name = "event-swipe-y-pos-hold",
  296. .mask = BIT(14),
  297. .enable = BIT(14),
  298. .reg_grp = IQS7211_REG_GRP_TP,
  299. .reg_key = IQS7211_REG_KEY_HOLD,
  300. },
  301. {
  302. .name = "event-swipe-y-neg-hold",
  303. .mask = BIT(15),
  304. .enable = BIT(15),
  305. .reg_grp = IQS7211_REG_GRP_TP,
  306. .reg_key = IQS7211_REG_KEY_HOLD,
  307. },
  308. };
  309. struct iqs7211_dev_desc {
  310. const char *tp_name;
  311. const char *kp_name;
  312. u16 prod_num;
  313. u16 show_reset;
  314. u16 ati_error[IQS7211_NUM_REG_GRPS];
  315. u16 ati_start[IQS7211_NUM_REG_GRPS];
  316. u16 suspend;
  317. u16 ack_reset;
  318. u16 comms_end;
  319. u16 comms_req;
  320. int charge_shift;
  321. int info_offs;
  322. int gesture_offs;
  323. int contact_offs;
  324. u8 sys_stat;
  325. u8 sys_ctrl;
  326. u8 alp_config;
  327. u8 tp_config;
  328. u8 exp_file;
  329. u8 kp_enable[IQS7211_NUM_REG_GRPS];
  330. u8 gesture_angle;
  331. u8 rx_tx_map;
  332. u8 cycle_alloc[2];
  333. u8 cycle_limit[2];
  334. const struct iqs7211_event_desc *kp_events;
  335. int num_kp_events;
  336. int min_crx_alp;
  337. int num_ctx;
  338. };
  339. static const struct iqs7211_dev_desc iqs7211_devs[] = {
  340. [IQS7210A] = {
  341. .tp_name = "iqs7210a_trackpad",
  342. .kp_name = "iqs7210a_keys",
  343. .prod_num = 944,
  344. .show_reset = BIT(15),
  345. .ati_error = {
  346. [IQS7211_REG_GRP_TP] = BIT(12),
  347. [IQS7211_REG_GRP_BTN] = BIT(0),
  348. [IQS7211_REG_GRP_ALP] = BIT(8),
  349. },
  350. .ati_start = {
  351. [IQS7211_REG_GRP_TP] = BIT(13),
  352. [IQS7211_REG_GRP_BTN] = BIT(1),
  353. [IQS7211_REG_GRP_ALP] = BIT(9),
  354. },
  355. .suspend = BIT(11),
  356. .ack_reset = BIT(7),
  357. .comms_end = BIT(2),
  358. .comms_req = BIT(1),
  359. .charge_shift = 4,
  360. .info_offs = 0,
  361. .gesture_offs = 1,
  362. .contact_offs = 4,
  363. .sys_stat = 0x0A,
  364. .sys_ctrl = 0x35,
  365. .alp_config = 0x39,
  366. .tp_config = 0x4E,
  367. .exp_file = 0x57,
  368. .kp_enable = {
  369. [IQS7211_REG_GRP_TP] = 0x58,
  370. [IQS7211_REG_GRP_BTN] = 0x37,
  371. [IQS7211_REG_GRP_ALP] = 0x37,
  372. },
  373. .gesture_angle = 0x5F,
  374. .rx_tx_map = 0x60,
  375. .cycle_alloc = { 0x66, 0x75, },
  376. .cycle_limit = { 10, 6, },
  377. .kp_events = iqs7210a_kp_events,
  378. .num_kp_events = ARRAY_SIZE(iqs7210a_kp_events),
  379. .min_crx_alp = 4,
  380. .num_ctx = IQS7211_MAX_CTX - 1,
  381. },
  382. [IQS7211A] = {
  383. .tp_name = "iqs7211a_trackpad",
  384. .kp_name = "iqs7211a_keys",
  385. .prod_num = 763,
  386. .show_reset = BIT(7),
  387. .ati_error = {
  388. [IQS7211_REG_GRP_TP] = BIT(3),
  389. [IQS7211_REG_GRP_ALP] = BIT(5),
  390. },
  391. .ati_start = {
  392. [IQS7211_REG_GRP_TP] = BIT(5),
  393. [IQS7211_REG_GRP_ALP] = BIT(6),
  394. },
  395. .ack_reset = BIT(7),
  396. .comms_req = BIT(4),
  397. .charge_shift = 0,
  398. .info_offs = 0,
  399. .gesture_offs = 1,
  400. .contact_offs = 4,
  401. .sys_stat = 0x10,
  402. .sys_ctrl = 0x50,
  403. .tp_config = 0x60,
  404. .alp_config = 0x72,
  405. .exp_file = 0x74,
  406. .kp_enable = {
  407. [IQS7211_REG_GRP_TP] = 0x80,
  408. },
  409. .gesture_angle = 0x87,
  410. .rx_tx_map = 0x90,
  411. .cycle_alloc = { 0xA0, 0xB0, },
  412. .cycle_limit = { 10, 8, },
  413. .kp_events = iqs7211a_kp_events,
  414. .num_kp_events = ARRAY_SIZE(iqs7211a_kp_events),
  415. .num_ctx = IQS7211_MAX_CTX - 1,
  416. },
  417. [IQS7211E] = {
  418. .tp_name = "iqs7211e_trackpad",
  419. .kp_name = "iqs7211e_keys",
  420. .prod_num = 1112,
  421. .show_reset = BIT(7),
  422. .ati_error = {
  423. [IQS7211_REG_GRP_TP] = BIT(3),
  424. [IQS7211_REG_GRP_ALP] = BIT(5),
  425. },
  426. .ati_start = {
  427. [IQS7211_REG_GRP_TP] = BIT(5),
  428. [IQS7211_REG_GRP_ALP] = BIT(6),
  429. },
  430. .suspend = BIT(11),
  431. .ack_reset = BIT(7),
  432. .comms_end = BIT(6),
  433. .comms_req = BIT(4),
  434. .charge_shift = 0,
  435. .info_offs = 1,
  436. .gesture_offs = 0,
  437. .contact_offs = 2,
  438. .sys_stat = 0x0E,
  439. .sys_ctrl = 0x33,
  440. .tp_config = 0x41,
  441. .alp_config = 0x36,
  442. .exp_file = 0x4A,
  443. .kp_enable = {
  444. [IQS7211_REG_GRP_TP] = 0x4B,
  445. },
  446. .gesture_angle = 0x55,
  447. .rx_tx_map = 0x56,
  448. .cycle_alloc = { 0x5D, 0x6C, },
  449. .cycle_limit = { 10, 11, },
  450. .kp_events = iqs7211e_kp_events,
  451. .num_kp_events = ARRAY_SIZE(iqs7211e_kp_events),
  452. .num_ctx = IQS7211_MAX_CTX,
  453. },
  454. };
  455. struct iqs7211_prop_desc {
  456. const char *name;
  457. enum iqs7211_reg_key_id reg_key;
  458. u8 reg_addr[IQS7211_NUM_REG_GRPS][ARRAY_SIZE(iqs7211_devs)];
  459. int reg_shift;
  460. int reg_width;
  461. int val_pitch;
  462. int val_min;
  463. int val_max;
  464. const char *label;
  465. };
  466. static const struct iqs7211_prop_desc iqs7211_props[] = {
  467. {
  468. .name = "azoteq,ati-frac-div-fine",
  469. .reg_addr = {
  470. [IQS7211_REG_GRP_TP] = {
  471. [IQS7210A] = 0x1E,
  472. [IQS7211A] = 0x30,
  473. [IQS7211E] = 0x21,
  474. },
  475. [IQS7211_REG_GRP_BTN] = {
  476. [IQS7210A] = 0x22,
  477. },
  478. [IQS7211_REG_GRP_ALP] = {
  479. [IQS7210A] = 0x23,
  480. [IQS7211A] = 0x36,
  481. [IQS7211E] = 0x25,
  482. },
  483. },
  484. .reg_shift = 9,
  485. .reg_width = 5,
  486. .label = "ATI fine fractional divider",
  487. },
  488. {
  489. .name = "azoteq,ati-frac-mult-coarse",
  490. .reg_addr = {
  491. [IQS7211_REG_GRP_TP] = {
  492. [IQS7210A] = 0x1E,
  493. [IQS7211A] = 0x30,
  494. [IQS7211E] = 0x21,
  495. },
  496. [IQS7211_REG_GRP_BTN] = {
  497. [IQS7210A] = 0x22,
  498. },
  499. [IQS7211_REG_GRP_ALP] = {
  500. [IQS7210A] = 0x23,
  501. [IQS7211A] = 0x36,
  502. [IQS7211E] = 0x25,
  503. },
  504. },
  505. .reg_shift = 5,
  506. .reg_width = 4,
  507. .label = "ATI coarse fractional multiplier",
  508. },
  509. {
  510. .name = "azoteq,ati-frac-div-coarse",
  511. .reg_addr = {
  512. [IQS7211_REG_GRP_TP] = {
  513. [IQS7210A] = 0x1E,
  514. [IQS7211A] = 0x30,
  515. [IQS7211E] = 0x21,
  516. },
  517. [IQS7211_REG_GRP_BTN] = {
  518. [IQS7210A] = 0x22,
  519. },
  520. [IQS7211_REG_GRP_ALP] = {
  521. [IQS7210A] = 0x23,
  522. [IQS7211A] = 0x36,
  523. [IQS7211E] = 0x25,
  524. },
  525. },
  526. .reg_shift = 0,
  527. .reg_width = 5,
  528. .label = "ATI coarse fractional divider",
  529. },
  530. {
  531. .name = "azoteq,ati-comp-div",
  532. .reg_addr = {
  533. [IQS7211_REG_GRP_TP] = {
  534. [IQS7210A] = 0x1F,
  535. [IQS7211E] = 0x22,
  536. },
  537. [IQS7211_REG_GRP_BTN] = {
  538. [IQS7210A] = 0x24,
  539. },
  540. [IQS7211_REG_GRP_ALP] = {
  541. [IQS7211E] = 0x26,
  542. },
  543. },
  544. .reg_shift = 0,
  545. .reg_width = 8,
  546. .val_max = 31,
  547. .label = "ATI compensation divider",
  548. },
  549. {
  550. .name = "azoteq,ati-comp-div",
  551. .reg_addr = {
  552. [IQS7211_REG_GRP_ALP] = {
  553. [IQS7210A] = 0x24,
  554. },
  555. },
  556. .reg_shift = 8,
  557. .reg_width = 8,
  558. .val_max = 31,
  559. .label = "ATI compensation divider",
  560. },
  561. {
  562. .name = "azoteq,ati-comp-div",
  563. .reg_addr = {
  564. [IQS7211_REG_GRP_TP] = {
  565. [IQS7211A] = 0x31,
  566. },
  567. [IQS7211_REG_GRP_ALP] = {
  568. [IQS7211A] = 0x37,
  569. },
  570. },
  571. .val_max = 31,
  572. .label = "ATI compensation divider",
  573. },
  574. {
  575. .name = "azoteq,ati-target",
  576. .reg_addr = {
  577. [IQS7211_REG_GRP_TP] = {
  578. [IQS7210A] = 0x20,
  579. [IQS7211A] = 0x32,
  580. [IQS7211E] = 0x23,
  581. },
  582. [IQS7211_REG_GRP_BTN] = {
  583. [IQS7210A] = 0x27,
  584. },
  585. [IQS7211_REG_GRP_ALP] = {
  586. [IQS7210A] = 0x28,
  587. [IQS7211A] = 0x38,
  588. [IQS7211E] = 0x27,
  589. },
  590. },
  591. .label = "ATI target",
  592. },
  593. {
  594. .name = "azoteq,ati-base",
  595. .reg_addr[IQS7211_REG_GRP_ALP] = {
  596. [IQS7210A] = 0x26,
  597. },
  598. .reg_shift = 8,
  599. .reg_width = 8,
  600. .val_pitch = 8,
  601. .label = "ATI base",
  602. },
  603. {
  604. .name = "azoteq,ati-base",
  605. .reg_addr[IQS7211_REG_GRP_BTN] = {
  606. [IQS7210A] = 0x26,
  607. },
  608. .reg_shift = 0,
  609. .reg_width = 8,
  610. .val_pitch = 8,
  611. .label = "ATI base",
  612. },
  613. {
  614. .name = "azoteq,rate-active-ms",
  615. .reg_addr[IQS7211_REG_GRP_SYS] = {
  616. [IQS7210A] = 0x29,
  617. [IQS7211A] = 0x40,
  618. [IQS7211E] = 0x28,
  619. },
  620. .label = "active mode report rate",
  621. },
  622. {
  623. .name = "azoteq,rate-touch-ms",
  624. .reg_addr[IQS7211_REG_GRP_SYS] = {
  625. [IQS7210A] = 0x2A,
  626. [IQS7211A] = 0x41,
  627. [IQS7211E] = 0x29,
  628. },
  629. .label = "idle-touch mode report rate",
  630. },
  631. {
  632. .name = "azoteq,rate-idle-ms",
  633. .reg_addr[IQS7211_REG_GRP_SYS] = {
  634. [IQS7210A] = 0x2B,
  635. [IQS7211A] = 0x42,
  636. [IQS7211E] = 0x2A,
  637. },
  638. .label = "idle mode report rate",
  639. },
  640. {
  641. .name = "azoteq,rate-lp1-ms",
  642. .reg_addr[IQS7211_REG_GRP_SYS] = {
  643. [IQS7210A] = 0x2C,
  644. [IQS7211A] = 0x43,
  645. [IQS7211E] = 0x2B,
  646. },
  647. .label = "low-power mode 1 report rate",
  648. },
  649. {
  650. .name = "azoteq,rate-lp2-ms",
  651. .reg_addr[IQS7211_REG_GRP_SYS] = {
  652. [IQS7210A] = 0x2D,
  653. [IQS7211A] = 0x44,
  654. [IQS7211E] = 0x2C,
  655. },
  656. .label = "low-power mode 2 report rate",
  657. },
  658. {
  659. .name = "azoteq,timeout-active-ms",
  660. .reg_addr[IQS7211_REG_GRP_SYS] = {
  661. [IQS7210A] = 0x2E,
  662. [IQS7211A] = 0x45,
  663. [IQS7211E] = 0x2D,
  664. },
  665. .val_pitch = 1000,
  666. .label = "active mode timeout",
  667. },
  668. {
  669. .name = "azoteq,timeout-touch-ms",
  670. .reg_addr[IQS7211_REG_GRP_SYS] = {
  671. [IQS7210A] = 0x2F,
  672. [IQS7211A] = 0x46,
  673. [IQS7211E] = 0x2E,
  674. },
  675. .val_pitch = 1000,
  676. .label = "idle-touch mode timeout",
  677. },
  678. {
  679. .name = "azoteq,timeout-idle-ms",
  680. .reg_addr[IQS7211_REG_GRP_SYS] = {
  681. [IQS7210A] = 0x30,
  682. [IQS7211A] = 0x47,
  683. [IQS7211E] = 0x2F,
  684. },
  685. .val_pitch = 1000,
  686. .label = "idle mode timeout",
  687. },
  688. {
  689. .name = "azoteq,timeout-lp1-ms",
  690. .reg_addr[IQS7211_REG_GRP_SYS] = {
  691. [IQS7210A] = 0x31,
  692. [IQS7211A] = 0x48,
  693. [IQS7211E] = 0x30,
  694. },
  695. .val_pitch = 1000,
  696. .label = "low-power mode 1 timeout",
  697. },
  698. {
  699. .name = "azoteq,timeout-lp2-ms",
  700. .reg_addr[IQS7211_REG_GRP_SYS] = {
  701. [IQS7210A] = 0x32,
  702. [IQS7211E] = 0x31,
  703. },
  704. .reg_shift = 8,
  705. .reg_width = 8,
  706. .val_pitch = 1000,
  707. .val_max = 60000,
  708. .label = "trackpad reference value update rate",
  709. },
  710. {
  711. .name = "azoteq,timeout-lp2-ms",
  712. .reg_addr[IQS7211_REG_GRP_SYS] = {
  713. [IQS7211A] = 0x49,
  714. },
  715. .val_pitch = 1000,
  716. .val_max = 60000,
  717. .label = "trackpad reference value update rate",
  718. },
  719. {
  720. .name = "azoteq,timeout-ati-ms",
  721. .reg_addr[IQS7211_REG_GRP_SYS] = {
  722. [IQS7210A] = 0x32,
  723. [IQS7211E] = 0x31,
  724. },
  725. .reg_width = 8,
  726. .val_pitch = 1000,
  727. .val_max = 60000,
  728. .label = "ATI error timeout",
  729. },
  730. {
  731. .name = "azoteq,timeout-ati-ms",
  732. .reg_addr[IQS7211_REG_GRP_SYS] = {
  733. [IQS7211A] = 0x35,
  734. },
  735. .val_pitch = 1000,
  736. .val_max = 60000,
  737. .label = "ATI error timeout",
  738. },
  739. {
  740. .name = "azoteq,timeout-comms-ms",
  741. .reg_addr[IQS7211_REG_GRP_SYS] = {
  742. [IQS7210A] = 0x33,
  743. [IQS7211A] = 0x4A,
  744. [IQS7211E] = 0x32,
  745. },
  746. .label = "communication timeout",
  747. },
  748. {
  749. .name = "azoteq,timeout-press-ms",
  750. .reg_addr[IQS7211_REG_GRP_SYS] = {
  751. [IQS7210A] = 0x34,
  752. },
  753. .reg_width = 8,
  754. .val_pitch = 1000,
  755. .val_max = 60000,
  756. .label = "press timeout",
  757. },
  758. {
  759. .name = "azoteq,ati-mode",
  760. .reg_addr[IQS7211_REG_GRP_ALP] = {
  761. [IQS7210A] = 0x37,
  762. },
  763. .reg_shift = 15,
  764. .reg_width = 1,
  765. .label = "ATI mode",
  766. },
  767. {
  768. .name = "azoteq,ati-mode",
  769. .reg_addr[IQS7211_REG_GRP_BTN] = {
  770. [IQS7210A] = 0x37,
  771. },
  772. .reg_shift = 7,
  773. .reg_width = 1,
  774. .label = "ATI mode",
  775. },
  776. {
  777. .name = "azoteq,sense-mode",
  778. .reg_addr[IQS7211_REG_GRP_ALP] = {
  779. [IQS7210A] = 0x37,
  780. [IQS7211A] = 0x72,
  781. [IQS7211E] = 0x36,
  782. },
  783. .reg_shift = 8,
  784. .reg_width = 1,
  785. .label = "sensing mode",
  786. },
  787. {
  788. .name = "azoteq,sense-mode",
  789. .reg_addr[IQS7211_REG_GRP_BTN] = {
  790. [IQS7210A] = 0x37,
  791. },
  792. .reg_shift = 0,
  793. .reg_width = 2,
  794. .val_max = 2,
  795. .label = "sensing mode",
  796. },
  797. {
  798. .name = "azoteq,fosc-freq",
  799. .reg_addr[IQS7211_REG_GRP_SYS] = {
  800. [IQS7210A] = 0x38,
  801. [IQS7211A] = 0x52,
  802. [IQS7211E] = 0x35,
  803. },
  804. .reg_shift = 4,
  805. .reg_width = 1,
  806. .label = "core clock frequency selection",
  807. },
  808. {
  809. .name = "azoteq,fosc-trim",
  810. .reg_addr[IQS7211_REG_GRP_SYS] = {
  811. [IQS7210A] = 0x38,
  812. [IQS7211A] = 0x52,
  813. [IQS7211E] = 0x35,
  814. },
  815. .reg_shift = 0,
  816. .reg_width = 4,
  817. .label = "core clock frequency trim",
  818. },
  819. {
  820. .name = "azoteq,touch-exit",
  821. .reg_addr = {
  822. [IQS7211_REG_GRP_TP] = {
  823. [IQS7210A] = 0x3B,
  824. [IQS7211A] = 0x53,
  825. [IQS7211E] = 0x38,
  826. },
  827. [IQS7211_REG_GRP_BTN] = {
  828. [IQS7210A] = 0x3E,
  829. },
  830. },
  831. .reg_shift = 8,
  832. .reg_width = 8,
  833. .label = "touch exit factor",
  834. },
  835. {
  836. .name = "azoteq,touch-enter",
  837. .reg_addr = {
  838. [IQS7211_REG_GRP_TP] = {
  839. [IQS7210A] = 0x3B,
  840. [IQS7211A] = 0x53,
  841. [IQS7211E] = 0x38,
  842. },
  843. [IQS7211_REG_GRP_BTN] = {
  844. [IQS7210A] = 0x3E,
  845. },
  846. },
  847. .reg_shift = 0,
  848. .reg_width = 8,
  849. .label = "touch entrance factor",
  850. },
  851. {
  852. .name = "azoteq,thresh",
  853. .reg_addr = {
  854. [IQS7211_REG_GRP_BTN] = {
  855. [IQS7210A] = 0x3C,
  856. },
  857. [IQS7211_REG_GRP_ALP] = {
  858. [IQS7210A] = 0x3D,
  859. [IQS7211A] = 0x54,
  860. [IQS7211E] = 0x39,
  861. },
  862. },
  863. .label = "threshold",
  864. },
  865. {
  866. .name = "azoteq,debounce-exit",
  867. .reg_addr = {
  868. [IQS7211_REG_GRP_BTN] = {
  869. [IQS7210A] = 0x3F,
  870. },
  871. [IQS7211_REG_GRP_ALP] = {
  872. [IQS7210A] = 0x40,
  873. [IQS7211A] = 0x56,
  874. [IQS7211E] = 0x3A,
  875. },
  876. },
  877. .reg_shift = 8,
  878. .reg_width = 8,
  879. .label = "debounce exit factor",
  880. },
  881. {
  882. .name = "azoteq,debounce-enter",
  883. .reg_addr = {
  884. [IQS7211_REG_GRP_BTN] = {
  885. [IQS7210A] = 0x3F,
  886. },
  887. [IQS7211_REG_GRP_ALP] = {
  888. [IQS7210A] = 0x40,
  889. [IQS7211A] = 0x56,
  890. [IQS7211E] = 0x3A,
  891. },
  892. },
  893. .reg_shift = 0,
  894. .reg_width = 8,
  895. .label = "debounce entrance factor",
  896. },
  897. {
  898. .name = "azoteq,conv-frac",
  899. .reg_addr = {
  900. [IQS7211_REG_GRP_TP] = {
  901. [IQS7210A] = 0x48,
  902. [IQS7211A] = 0x58,
  903. [IQS7211E] = 0x3D,
  904. },
  905. [IQS7211_REG_GRP_BTN] = {
  906. [IQS7210A] = 0x49,
  907. },
  908. [IQS7211_REG_GRP_ALP] = {
  909. [IQS7210A] = 0x4A,
  910. [IQS7211A] = 0x59,
  911. [IQS7211E] = 0x3E,
  912. },
  913. },
  914. .reg_shift = 8,
  915. .reg_width = 8,
  916. .label = "conversion frequency fractional divider",
  917. },
  918. {
  919. .name = "azoteq,conv-period",
  920. .reg_addr = {
  921. [IQS7211_REG_GRP_TP] = {
  922. [IQS7210A] = 0x48,
  923. [IQS7211A] = 0x58,
  924. [IQS7211E] = 0x3D,
  925. },
  926. [IQS7211_REG_GRP_BTN] = {
  927. [IQS7210A] = 0x49,
  928. },
  929. [IQS7211_REG_GRP_ALP] = {
  930. [IQS7210A] = 0x4A,
  931. [IQS7211A] = 0x59,
  932. [IQS7211E] = 0x3E,
  933. },
  934. },
  935. .reg_shift = 0,
  936. .reg_width = 8,
  937. .label = "conversion period",
  938. },
  939. {
  940. .name = "azoteq,thresh",
  941. .reg_addr[IQS7211_REG_GRP_TP] = {
  942. [IQS7210A] = 0x55,
  943. [IQS7211A] = 0x67,
  944. [IQS7211E] = 0x48,
  945. },
  946. .reg_shift = 0,
  947. .reg_width = 8,
  948. .label = "threshold",
  949. },
  950. {
  951. .name = "azoteq,contact-split",
  952. .reg_addr[IQS7211_REG_GRP_SYS] = {
  953. [IQS7210A] = 0x55,
  954. [IQS7211A] = 0x67,
  955. [IQS7211E] = 0x48,
  956. },
  957. .reg_shift = 8,
  958. .reg_width = 8,
  959. .label = "contact split factor",
  960. },
  961. {
  962. .name = "azoteq,trim-x",
  963. .reg_addr[IQS7211_REG_GRP_SYS] = {
  964. [IQS7210A] = 0x56,
  965. [IQS7211E] = 0x49,
  966. },
  967. .reg_shift = 0,
  968. .reg_width = 8,
  969. .label = "horizontal trim width",
  970. },
  971. {
  972. .name = "azoteq,trim-x",
  973. .reg_addr[IQS7211_REG_GRP_SYS] = {
  974. [IQS7211A] = 0x68,
  975. },
  976. .label = "horizontal trim width",
  977. },
  978. {
  979. .name = "azoteq,trim-y",
  980. .reg_addr[IQS7211_REG_GRP_SYS] = {
  981. [IQS7210A] = 0x56,
  982. [IQS7211E] = 0x49,
  983. },
  984. .reg_shift = 8,
  985. .reg_width = 8,
  986. .label = "vertical trim height",
  987. },
  988. {
  989. .name = "azoteq,trim-y",
  990. .reg_addr[IQS7211_REG_GRP_SYS] = {
  991. [IQS7211A] = 0x69,
  992. },
  993. .label = "vertical trim height",
  994. },
  995. {
  996. .name = "azoteq,gesture-max-ms",
  997. .reg_key = IQS7211_REG_KEY_TAP,
  998. .reg_addr[IQS7211_REG_GRP_TP] = {
  999. [IQS7210A] = 0x59,
  1000. [IQS7211A] = 0x81,
  1001. [IQS7211E] = 0x4C,
  1002. },
  1003. .label = "maximum gesture time",
  1004. },
  1005. {
  1006. .name = "azoteq,gesture-mid-ms",
  1007. .reg_key = IQS7211_REG_KEY_TAP,
  1008. .reg_addr[IQS7211_REG_GRP_TP] = {
  1009. [IQS7211E] = 0x4D,
  1010. },
  1011. .label = "repeated gesture time",
  1012. },
  1013. {
  1014. .name = "azoteq,gesture-dist",
  1015. .reg_key = IQS7211_REG_KEY_TAP,
  1016. .reg_addr[IQS7211_REG_GRP_TP] = {
  1017. [IQS7210A] = 0x5A,
  1018. [IQS7211A] = 0x82,
  1019. [IQS7211E] = 0x4E,
  1020. },
  1021. .label = "gesture distance",
  1022. },
  1023. {
  1024. .name = "azoteq,gesture-dist",
  1025. .reg_key = IQS7211_REG_KEY_HOLD,
  1026. .reg_addr[IQS7211_REG_GRP_TP] = {
  1027. [IQS7210A] = 0x5A,
  1028. [IQS7211A] = 0x82,
  1029. [IQS7211E] = 0x4E,
  1030. },
  1031. .label = "gesture distance",
  1032. },
  1033. {
  1034. .name = "azoteq,gesture-min-ms",
  1035. .reg_key = IQS7211_REG_KEY_HOLD,
  1036. .reg_addr[IQS7211_REG_GRP_TP] = {
  1037. [IQS7210A] = 0x5B,
  1038. [IQS7211A] = 0x83,
  1039. [IQS7211E] = 0x4F,
  1040. },
  1041. .label = "minimum gesture time",
  1042. },
  1043. {
  1044. .name = "azoteq,gesture-max-ms",
  1045. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  1046. .reg_addr[IQS7211_REG_GRP_TP] = {
  1047. [IQS7210A] = 0x5C,
  1048. [IQS7211A] = 0x84,
  1049. [IQS7211E] = 0x50,
  1050. },
  1051. .label = "maximum gesture time",
  1052. },
  1053. {
  1054. .name = "azoteq,gesture-max-ms",
  1055. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  1056. .reg_addr[IQS7211_REG_GRP_TP] = {
  1057. [IQS7210A] = 0x5C,
  1058. [IQS7211A] = 0x84,
  1059. [IQS7211E] = 0x50,
  1060. },
  1061. .label = "maximum gesture time",
  1062. },
  1063. {
  1064. .name = "azoteq,gesture-dist",
  1065. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  1066. .reg_addr[IQS7211_REG_GRP_TP] = {
  1067. [IQS7210A] = 0x5D,
  1068. [IQS7211A] = 0x85,
  1069. [IQS7211E] = 0x51,
  1070. },
  1071. .label = "gesture distance",
  1072. },
  1073. {
  1074. .name = "azoteq,gesture-dist",
  1075. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  1076. .reg_addr[IQS7211_REG_GRP_TP] = {
  1077. [IQS7210A] = 0x5E,
  1078. [IQS7211A] = 0x86,
  1079. [IQS7211E] = 0x52,
  1080. },
  1081. .label = "gesture distance",
  1082. },
  1083. {
  1084. .name = "azoteq,gesture-dist-rep",
  1085. .reg_key = IQS7211_REG_KEY_AXIAL_X,
  1086. .reg_addr[IQS7211_REG_GRP_TP] = {
  1087. [IQS7211E] = 0x53,
  1088. },
  1089. .label = "repeated gesture distance",
  1090. },
  1091. {
  1092. .name = "azoteq,gesture-dist-rep",
  1093. .reg_key = IQS7211_REG_KEY_AXIAL_Y,
  1094. .reg_addr[IQS7211_REG_GRP_TP] = {
  1095. [IQS7211E] = 0x54,
  1096. },
  1097. .label = "repeated gesture distance",
  1098. },
  1099. {
  1100. .name = "azoteq,thresh",
  1101. .reg_key = IQS7211_REG_KEY_PALM,
  1102. .reg_addr[IQS7211_REG_GRP_TP] = {
  1103. [IQS7211E] = 0x55,
  1104. },
  1105. .reg_shift = 8,
  1106. .reg_width = 8,
  1107. .val_max = 42,
  1108. .label = "threshold",
  1109. },
  1110. };
  1111. static const u8 iqs7211_gesture_angle[] = {
  1112. 0x00, 0x01, 0x02, 0x03,
  1113. 0x04, 0x06, 0x07, 0x08,
  1114. 0x09, 0x0A, 0x0B, 0x0C,
  1115. 0x0E, 0x0F, 0x10, 0x11,
  1116. 0x12, 0x14, 0x15, 0x16,
  1117. 0x17, 0x19, 0x1A, 0x1B,
  1118. 0x1C, 0x1E, 0x1F, 0x21,
  1119. 0x22, 0x23, 0x25, 0x26,
  1120. 0x28, 0x2A, 0x2B, 0x2D,
  1121. 0x2E, 0x30, 0x32, 0x34,
  1122. 0x36, 0x38, 0x3A, 0x3C,
  1123. 0x3E, 0x40, 0x42, 0x45,
  1124. 0x47, 0x4A, 0x4C, 0x4F,
  1125. 0x52, 0x55, 0x58, 0x5B,
  1126. 0x5F, 0x63, 0x66, 0x6B,
  1127. 0x6F, 0x73, 0x78, 0x7E,
  1128. 0x83, 0x89, 0x90, 0x97,
  1129. 0x9E, 0xA7, 0xB0, 0xBA,
  1130. 0xC5, 0xD1, 0xDF, 0xEF,
  1131. };
  1132. struct iqs7211_ver_info {
  1133. __le16 prod_num;
  1134. __le16 major;
  1135. __le16 minor;
  1136. __le32 patch;
  1137. } __packed;
  1138. struct iqs7211_touch_data {
  1139. __le16 abs_x;
  1140. __le16 abs_y;
  1141. __le16 pressure;
  1142. __le16 area;
  1143. } __packed;
  1144. struct iqs7211_tp_config {
  1145. u8 tp_settings;
  1146. u8 total_rx;
  1147. u8 total_tx;
  1148. u8 num_contacts;
  1149. __le16 max_x;
  1150. __le16 max_y;
  1151. } __packed;
  1152. struct iqs7211_private {
  1153. const struct iqs7211_dev_desc *dev_desc;
  1154. struct gpio_desc *reset_gpio;
  1155. struct gpio_desc *irq_gpio;
  1156. struct i2c_client *client;
  1157. struct input_dev *tp_idev;
  1158. struct input_dev *kp_idev;
  1159. struct iqs7211_ver_info ver_info;
  1160. struct iqs7211_tp_config tp_config;
  1161. struct touchscreen_properties prop;
  1162. struct list_head reg_field_head;
  1163. enum iqs7211_comms_mode comms_init;
  1164. enum iqs7211_comms_mode comms_mode;
  1165. unsigned int num_contacts;
  1166. unsigned int kp_code[ARRAY_SIZE(iqs7211e_kp_events)];
  1167. u8 rx_tx_map[IQS7211_MAX_CTX + 1];
  1168. u8 cycle_alloc[2][33];
  1169. u8 exp_file[2];
  1170. u16 event_mask;
  1171. u16 ati_start;
  1172. u16 gesture_cache;
  1173. };
  1174. static int iqs7211_irq_poll(struct iqs7211_private *iqs7211, u64 timeout_us)
  1175. {
  1176. int error, val;
  1177. error = readx_poll_timeout(gpiod_get_value_cansleep, iqs7211->irq_gpio,
  1178. val, val, IQS7211_COMMS_SLEEP_US, timeout_us);
  1179. return val < 0 ? val : error;
  1180. }
  1181. static int iqs7211_hard_reset(struct iqs7211_private *iqs7211)
  1182. {
  1183. if (!iqs7211->reset_gpio)
  1184. return 0;
  1185. gpiod_set_value_cansleep(iqs7211->reset_gpio, 1);
  1186. /*
  1187. * The following delay ensures the shared RDY/MCLR pin is sampled in
  1188. * between periodic assertions by the device and assumes the default
  1189. * communication timeout has not been overwritten in OTP memory.
  1190. */
  1191. if (iqs7211->reset_gpio == iqs7211->irq_gpio)
  1192. msleep(IQS7211_RESET_TIMEOUT_MS);
  1193. else
  1194. usleep_range(1000, 1100);
  1195. gpiod_set_value_cansleep(iqs7211->reset_gpio, 0);
  1196. if (iqs7211->reset_gpio == iqs7211->irq_gpio)
  1197. iqs7211_irq_wait();
  1198. return iqs7211_irq_poll(iqs7211, IQS7211_START_TIMEOUT_US);
  1199. }
  1200. static int iqs7211_force_comms(struct iqs7211_private *iqs7211)
  1201. {
  1202. u8 msg_buf[] = { 0xFF, };
  1203. int ret;
  1204. switch (iqs7211->comms_mode) {
  1205. case IQS7211_COMMS_MODE_WAIT:
  1206. return iqs7211_irq_poll(iqs7211, IQS7211_START_TIMEOUT_US);
  1207. case IQS7211_COMMS_MODE_FREE:
  1208. return 0;
  1209. case IQS7211_COMMS_MODE_FORCE:
  1210. break;
  1211. default:
  1212. return -EINVAL;
  1213. }
  1214. /*
  1215. * The device cannot communicate until it asserts its interrupt (RDY)
  1216. * pin. Attempts to do so while RDY is deasserted return an ACK; how-
  1217. * ever all write data is ignored, and all read data returns 0xEE.
  1218. *
  1219. * Unsolicited communication must be preceded by a special force com-
  1220. * munication command, after which the device eventually asserts its
  1221. * RDY pin and agrees to communicate.
  1222. *
  1223. * Regardless of whether communication is forced or the result of an
  1224. * interrupt, the device automatically deasserts its RDY pin once it
  1225. * detects an I2C stop condition, or a timeout expires.
  1226. */
  1227. ret = gpiod_get_value_cansleep(iqs7211->irq_gpio);
  1228. if (ret < 0)
  1229. return ret;
  1230. else if (ret > 0)
  1231. return 0;
  1232. ret = i2c_master_send(iqs7211->client, msg_buf, sizeof(msg_buf));
  1233. if (ret < (int)sizeof(msg_buf)) {
  1234. if (ret >= 0)
  1235. ret = -EIO;
  1236. msleep(IQS7211_COMMS_RETRY_MS);
  1237. return ret;
  1238. }
  1239. iqs7211_irq_wait();
  1240. return iqs7211_irq_poll(iqs7211, IQS7211_COMMS_TIMEOUT_US);
  1241. }
  1242. static int iqs7211_read_burst(struct iqs7211_private *iqs7211,
  1243. u8 reg, void *val, u16 val_len)
  1244. {
  1245. int ret, i;
  1246. struct i2c_client *client = iqs7211->client;
  1247. struct i2c_msg msg[] = {
  1248. {
  1249. .addr = client->addr,
  1250. .flags = 0,
  1251. .len = sizeof(reg),
  1252. .buf = &reg,
  1253. },
  1254. {
  1255. .addr = client->addr,
  1256. .flags = I2C_M_RD,
  1257. .len = val_len,
  1258. .buf = (u8 *)val,
  1259. },
  1260. };
  1261. /*
  1262. * The following loop protects against an edge case in which the RDY
  1263. * pin is automatically deasserted just as the read is initiated. In
  1264. * that case, the read must be retried using forced communication.
  1265. */
  1266. for (i = 0; i < IQS7211_NUM_RETRIES; i++) {
  1267. ret = iqs7211_force_comms(iqs7211);
  1268. if (ret < 0)
  1269. continue;
  1270. ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
  1271. if (ret < (int)ARRAY_SIZE(msg)) {
  1272. if (ret >= 0)
  1273. ret = -EIO;
  1274. msleep(IQS7211_COMMS_RETRY_MS);
  1275. continue;
  1276. }
  1277. if (get_unaligned_le16(msg[1].buf) == IQS7211_COMMS_ERROR) {
  1278. ret = -ENODATA;
  1279. continue;
  1280. }
  1281. ret = 0;
  1282. break;
  1283. }
  1284. iqs7211_irq_wait();
  1285. if (ret < 0)
  1286. dev_err(&client->dev,
  1287. "Failed to read from address 0x%02X: %d\n", reg, ret);
  1288. return ret;
  1289. }
  1290. static int iqs7211_read_word(struct iqs7211_private *iqs7211, u8 reg, u16 *val)
  1291. {
  1292. __le16 val_buf;
  1293. int error;
  1294. error = iqs7211_read_burst(iqs7211, reg, &val_buf, sizeof(val_buf));
  1295. if (error)
  1296. return error;
  1297. *val = le16_to_cpu(val_buf);
  1298. return 0;
  1299. }
  1300. static int iqs7211_write_burst(struct iqs7211_private *iqs7211,
  1301. u8 reg, const void *val, u16 val_len)
  1302. {
  1303. int msg_len = sizeof(reg) + val_len;
  1304. int ret, i;
  1305. struct i2c_client *client = iqs7211->client;
  1306. u8 *msg_buf;
  1307. msg_buf = kzalloc(msg_len, GFP_KERNEL);
  1308. if (!msg_buf)
  1309. return -ENOMEM;
  1310. *msg_buf = reg;
  1311. memcpy(msg_buf + sizeof(reg), val, val_len);
  1312. /*
  1313. * The following loop protects against an edge case in which the RDY
  1314. * pin is automatically asserted just before the force communication
  1315. * command is sent.
  1316. *
  1317. * In that case, the subsequent I2C stop condition tricks the device
  1318. * into preemptively deasserting the RDY pin and the command must be
  1319. * sent again.
  1320. */
  1321. for (i = 0; i < IQS7211_NUM_RETRIES; i++) {
  1322. ret = iqs7211_force_comms(iqs7211);
  1323. if (ret < 0)
  1324. continue;
  1325. ret = i2c_master_send(client, msg_buf, msg_len);
  1326. if (ret < msg_len) {
  1327. if (ret >= 0)
  1328. ret = -EIO;
  1329. msleep(IQS7211_COMMS_RETRY_MS);
  1330. continue;
  1331. }
  1332. ret = 0;
  1333. break;
  1334. }
  1335. kfree(msg_buf);
  1336. iqs7211_irq_wait();
  1337. if (ret < 0)
  1338. dev_err(&client->dev,
  1339. "Failed to write to address 0x%02X: %d\n", reg, ret);
  1340. return ret;
  1341. }
  1342. static int iqs7211_write_word(struct iqs7211_private *iqs7211, u8 reg, u16 val)
  1343. {
  1344. __le16 val_buf = cpu_to_le16(val);
  1345. return iqs7211_write_burst(iqs7211, reg, &val_buf, sizeof(val_buf));
  1346. }
  1347. static int iqs7211_start_comms(struct iqs7211_private *iqs7211)
  1348. {
  1349. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1350. struct i2c_client *client = iqs7211->client;
  1351. bool forced_comms;
  1352. unsigned int val;
  1353. u16 comms_setup;
  1354. int error;
  1355. /*
  1356. * Until forced communication can be enabled, the host must wait for a
  1357. * communication window each time it intends to elicit a response from
  1358. * the device.
  1359. *
  1360. * Forced communication is not necessary, however, if the host adapter
  1361. * can support clock stretching. In that case, the device freely clock
  1362. * stretches until all pending conversions are complete.
  1363. */
  1364. forced_comms = device_property_present(&client->dev,
  1365. "azoteq,forced-comms");
  1366. error = device_property_read_u32(&client->dev,
  1367. "azoteq,forced-comms-default", &val);
  1368. if (error == -EINVAL) {
  1369. iqs7211->comms_init = IQS7211_COMMS_MODE_WAIT;
  1370. } else if (error) {
  1371. dev_err(&client->dev,
  1372. "Failed to read default communication mode: %d\n",
  1373. error);
  1374. return error;
  1375. } else if (val) {
  1376. iqs7211->comms_init = forced_comms ? IQS7211_COMMS_MODE_FORCE
  1377. : IQS7211_COMMS_MODE_WAIT;
  1378. } else {
  1379. iqs7211->comms_init = forced_comms ? IQS7211_COMMS_MODE_WAIT
  1380. : IQS7211_COMMS_MODE_FREE;
  1381. }
  1382. iqs7211->comms_mode = iqs7211->comms_init;
  1383. error = iqs7211_hard_reset(iqs7211);
  1384. if (error) {
  1385. dev_err(&client->dev, "Failed to reset device: %d\n", error);
  1386. return error;
  1387. }
  1388. error = iqs7211_read_burst(iqs7211, IQS7211_PROD_NUM,
  1389. &iqs7211->ver_info,
  1390. sizeof(iqs7211->ver_info));
  1391. if (error)
  1392. return error;
  1393. if (le16_to_cpu(iqs7211->ver_info.prod_num) != dev_desc->prod_num) {
  1394. dev_err(&client->dev, "Invalid product number: %u\n",
  1395. le16_to_cpu(iqs7211->ver_info.prod_num));
  1396. return -EINVAL;
  1397. }
  1398. error = iqs7211_read_word(iqs7211, dev_desc->sys_ctrl + 1,
  1399. &comms_setup);
  1400. if (error)
  1401. return error;
  1402. if (forced_comms)
  1403. comms_setup |= dev_desc->comms_req;
  1404. else
  1405. comms_setup &= ~dev_desc->comms_req;
  1406. error = iqs7211_write_word(iqs7211, dev_desc->sys_ctrl + 1,
  1407. comms_setup | dev_desc->comms_end);
  1408. if (error)
  1409. return error;
  1410. if (forced_comms)
  1411. iqs7211->comms_mode = IQS7211_COMMS_MODE_FORCE;
  1412. else
  1413. iqs7211->comms_mode = IQS7211_COMMS_MODE_FREE;
  1414. error = iqs7211_read_burst(iqs7211, dev_desc->exp_file,
  1415. iqs7211->exp_file,
  1416. sizeof(iqs7211->exp_file));
  1417. if (error)
  1418. return error;
  1419. error = iqs7211_read_burst(iqs7211, dev_desc->tp_config,
  1420. &iqs7211->tp_config,
  1421. sizeof(iqs7211->tp_config));
  1422. if (error)
  1423. return error;
  1424. error = iqs7211_write_word(iqs7211, dev_desc->sys_ctrl + 1,
  1425. comms_setup);
  1426. if (error)
  1427. return error;
  1428. iqs7211->event_mask = comms_setup & ~IQS7211_EVENT_MASK_ALL;
  1429. iqs7211->event_mask |= (IQS7211_EVENT_MASK_ATI | IQS7211_EVENT_MODE);
  1430. return 0;
  1431. }
  1432. static int iqs7211_init_device(struct iqs7211_private *iqs7211)
  1433. {
  1434. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1435. struct iqs7211_reg_field_desc *reg_field;
  1436. __le16 sys_ctrl[] = {
  1437. cpu_to_le16(dev_desc->ack_reset),
  1438. cpu_to_le16(iqs7211->event_mask),
  1439. };
  1440. int error, i;
  1441. /*
  1442. * Acknowledge reset before writing any registers in case the device
  1443. * suffers a spurious reset during initialization. The communication
  1444. * mode is configured at this time as well.
  1445. */
  1446. error = iqs7211_write_burst(iqs7211, dev_desc->sys_ctrl, sys_ctrl,
  1447. sizeof(sys_ctrl));
  1448. if (error)
  1449. return error;
  1450. if (iqs7211->event_mask & dev_desc->comms_req)
  1451. iqs7211->comms_mode = IQS7211_COMMS_MODE_FORCE;
  1452. else
  1453. iqs7211->comms_mode = IQS7211_COMMS_MODE_FREE;
  1454. /*
  1455. * Take advantage of the stop-bit disable function, if available, to
  1456. * save the trouble of having to reopen a communication window after
  1457. * each read or write.
  1458. */
  1459. error = iqs7211_write_word(iqs7211, dev_desc->sys_ctrl + 1,
  1460. iqs7211->event_mask | dev_desc->comms_end);
  1461. if (error)
  1462. return error;
  1463. list_for_each_entry(reg_field, &iqs7211->reg_field_head, list) {
  1464. u16 new_val = reg_field->val;
  1465. if (reg_field->mask < U16_MAX) {
  1466. u16 old_val;
  1467. error = iqs7211_read_word(iqs7211, reg_field->addr,
  1468. &old_val);
  1469. if (error)
  1470. return error;
  1471. new_val = old_val & ~reg_field->mask;
  1472. new_val |= reg_field->val;
  1473. if (new_val == old_val)
  1474. continue;
  1475. }
  1476. error = iqs7211_write_word(iqs7211, reg_field->addr, new_val);
  1477. if (error)
  1478. return error;
  1479. }
  1480. error = iqs7211_write_burst(iqs7211, dev_desc->tp_config,
  1481. &iqs7211->tp_config,
  1482. sizeof(iqs7211->tp_config));
  1483. if (error)
  1484. return error;
  1485. if (**iqs7211->cycle_alloc) {
  1486. error = iqs7211_write_burst(iqs7211, dev_desc->rx_tx_map,
  1487. &iqs7211->rx_tx_map,
  1488. dev_desc->num_ctx);
  1489. if (error)
  1490. return error;
  1491. for (i = 0; i < sizeof(dev_desc->cycle_limit); i++) {
  1492. error = iqs7211_write_burst(iqs7211,
  1493. dev_desc->cycle_alloc[i],
  1494. iqs7211->cycle_alloc[i],
  1495. dev_desc->cycle_limit[i] * 3);
  1496. if (error)
  1497. return error;
  1498. }
  1499. }
  1500. *sys_ctrl = cpu_to_le16(iqs7211->ati_start);
  1501. return iqs7211_write_burst(iqs7211, dev_desc->sys_ctrl, sys_ctrl,
  1502. sizeof(sys_ctrl));
  1503. }
  1504. static int iqs7211_add_field(struct iqs7211_private *iqs7211,
  1505. struct iqs7211_reg_field_desc new_field)
  1506. {
  1507. struct i2c_client *client = iqs7211->client;
  1508. struct iqs7211_reg_field_desc *reg_field;
  1509. if (!new_field.addr)
  1510. return 0;
  1511. list_for_each_entry(reg_field, &iqs7211->reg_field_head, list) {
  1512. if (reg_field->addr != new_field.addr)
  1513. continue;
  1514. reg_field->mask |= new_field.mask;
  1515. reg_field->val |= new_field.val;
  1516. return 0;
  1517. }
  1518. reg_field = devm_kzalloc(&client->dev, sizeof(*reg_field), GFP_KERNEL);
  1519. if (!reg_field)
  1520. return -ENOMEM;
  1521. reg_field->addr = new_field.addr;
  1522. reg_field->mask = new_field.mask;
  1523. reg_field->val = new_field.val;
  1524. list_add(&reg_field->list, &iqs7211->reg_field_head);
  1525. return 0;
  1526. }
  1527. static int iqs7211_parse_props(struct iqs7211_private *iqs7211,
  1528. struct fwnode_handle *reg_grp_node,
  1529. enum iqs7211_reg_grp_id reg_grp,
  1530. enum iqs7211_reg_key_id reg_key)
  1531. {
  1532. struct i2c_client *client = iqs7211->client;
  1533. int i;
  1534. for (i = 0; i < ARRAY_SIZE(iqs7211_props); i++) {
  1535. const char *name = iqs7211_props[i].name;
  1536. u8 reg_addr = iqs7211_props[i].reg_addr[reg_grp]
  1537. [iqs7211->dev_desc -
  1538. iqs7211_devs];
  1539. int reg_shift = iqs7211_props[i].reg_shift;
  1540. int reg_width = iqs7211_props[i].reg_width ? : 16;
  1541. int val_pitch = iqs7211_props[i].val_pitch ? : 1;
  1542. int val_min = iqs7211_props[i].val_min;
  1543. int val_max = iqs7211_props[i].val_max;
  1544. const char *label = iqs7211_props[i].label ? : name;
  1545. struct iqs7211_reg_field_desc reg_field;
  1546. unsigned int val;
  1547. int error;
  1548. if (iqs7211_props[i].reg_key != reg_key)
  1549. continue;
  1550. if (!reg_addr)
  1551. continue;
  1552. error = fwnode_property_read_u32(reg_grp_node, name, &val);
  1553. if (error == -EINVAL) {
  1554. continue;
  1555. } else if (error) {
  1556. dev_err(&client->dev, "Failed to read %s %s: %d\n",
  1557. fwnode_get_name(reg_grp_node), label, error);
  1558. return error;
  1559. }
  1560. if (!val_max)
  1561. val_max = GENMASK(reg_width - 1, 0) * val_pitch;
  1562. if (val < val_min || val > val_max) {
  1563. dev_err(&client->dev, "Invalid %s: %u\n", label, val);
  1564. return -EINVAL;
  1565. }
  1566. reg_field.addr = reg_addr;
  1567. reg_field.mask = GENMASK(reg_shift + reg_width - 1, reg_shift);
  1568. reg_field.val = val / val_pitch << reg_shift;
  1569. error = iqs7211_add_field(iqs7211, reg_field);
  1570. if (error)
  1571. return error;
  1572. }
  1573. return 0;
  1574. }
  1575. static int iqs7211_parse_event(struct iqs7211_private *iqs7211,
  1576. struct fwnode_handle *event_node,
  1577. enum iqs7211_reg_grp_id reg_grp,
  1578. enum iqs7211_reg_key_id reg_key,
  1579. unsigned int *event_code)
  1580. {
  1581. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1582. struct i2c_client *client = iqs7211->client;
  1583. struct iqs7211_reg_field_desc reg_field;
  1584. unsigned int val;
  1585. int error;
  1586. error = iqs7211_parse_props(iqs7211, event_node, reg_grp, reg_key);
  1587. if (error)
  1588. return error;
  1589. if (reg_key == IQS7211_REG_KEY_AXIAL_X ||
  1590. reg_key == IQS7211_REG_KEY_AXIAL_Y) {
  1591. error = fwnode_property_read_u32(event_node,
  1592. "azoteq,gesture-angle", &val);
  1593. if (!error) {
  1594. if (val >= ARRAY_SIZE(iqs7211_gesture_angle)) {
  1595. dev_err(&client->dev,
  1596. "Invalid %s gesture angle: %u\n",
  1597. fwnode_get_name(event_node), val);
  1598. return -EINVAL;
  1599. }
  1600. reg_field.addr = dev_desc->gesture_angle;
  1601. reg_field.mask = U8_MAX;
  1602. reg_field.val = iqs7211_gesture_angle[val];
  1603. error = iqs7211_add_field(iqs7211, reg_field);
  1604. if (error)
  1605. return error;
  1606. } else if (error != -EINVAL) {
  1607. dev_err(&client->dev,
  1608. "Failed to read %s gesture angle: %d\n",
  1609. fwnode_get_name(event_node), error);
  1610. return error;
  1611. }
  1612. }
  1613. error = fwnode_property_read_u32(event_node, "linux,code", event_code);
  1614. if (error == -EINVAL)
  1615. error = 0;
  1616. else if (error)
  1617. dev_err(&client->dev, "Failed to read %s code: %d\n",
  1618. fwnode_get_name(event_node), error);
  1619. return error;
  1620. }
  1621. static int iqs7211_parse_cycles(struct iqs7211_private *iqs7211,
  1622. struct fwnode_handle *tp_node)
  1623. {
  1624. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1625. struct i2c_client *client = iqs7211->client;
  1626. int num_cycles = dev_desc->cycle_limit[0] + dev_desc->cycle_limit[1];
  1627. int error, count, i, j, k, cycle_start;
  1628. unsigned int cycle_alloc[IQS7211_MAX_CYCLES][2];
  1629. u8 total_rx = iqs7211->tp_config.total_rx;
  1630. u8 total_tx = iqs7211->tp_config.total_tx;
  1631. for (i = 0; i < IQS7211_MAX_CYCLES * 2; i++)
  1632. *(cycle_alloc[0] + i) = U8_MAX;
  1633. count = fwnode_property_count_u32(tp_node, "azoteq,channel-select");
  1634. if (count == -EINVAL) {
  1635. /*
  1636. * Assign each sensing cycle's slots (0 and 1) to a channel,
  1637. * defined as the intersection between two CRx and CTx pins.
  1638. * A channel assignment of 255 means the slot is unused.
  1639. */
  1640. for (i = 0, cycle_start = 0; i < total_tx; i++) {
  1641. int cycle_stop = 0;
  1642. for (j = 0; j < total_rx; j++) {
  1643. /*
  1644. * Channels formed by CRx0-3 and CRx4-7 are
  1645. * bound to slots 0 and 1, respectively.
  1646. */
  1647. int slot = iqs7211->rx_tx_map[j] < 4 ? 0 : 1;
  1648. int chan = i * total_rx + j;
  1649. for (k = cycle_start; k < num_cycles; k++) {
  1650. if (cycle_alloc[k][slot] < U8_MAX)
  1651. continue;
  1652. cycle_alloc[k][slot] = chan;
  1653. break;
  1654. }
  1655. if (k < num_cycles) {
  1656. cycle_stop = max(k, cycle_stop);
  1657. continue;
  1658. }
  1659. dev_err(&client->dev,
  1660. "Insufficient number of cycles\n");
  1661. return -EINVAL;
  1662. }
  1663. /*
  1664. * Sensing cycles cannot straddle more than one CTx
  1665. * pin. As such, the next row's starting cycle must
  1666. * be greater than the previous row's highest cycle.
  1667. */
  1668. cycle_start = cycle_stop + 1;
  1669. }
  1670. } else if (count < 0) {
  1671. dev_err(&client->dev, "Failed to count channels: %d\n", count);
  1672. return count;
  1673. } else if (count > num_cycles * 2) {
  1674. dev_err(&client->dev, "Insufficient number of cycles\n");
  1675. return -EINVAL;
  1676. } else if (count > 0) {
  1677. error = fwnode_property_read_u32_array(tp_node,
  1678. "azoteq,channel-select",
  1679. cycle_alloc[0], count);
  1680. if (error) {
  1681. dev_err(&client->dev, "Failed to read channels: %d\n",
  1682. error);
  1683. return error;
  1684. }
  1685. for (i = 0; i < count; i++) {
  1686. int chan = *(cycle_alloc[0] + i);
  1687. if (chan == U8_MAX)
  1688. continue;
  1689. if (chan >= total_rx * total_tx) {
  1690. dev_err(&client->dev, "Invalid channel: %d\n",
  1691. chan);
  1692. return -EINVAL;
  1693. }
  1694. for (j = 0; j < count; j++) {
  1695. if (j == i || *(cycle_alloc[0] + j) != chan)
  1696. continue;
  1697. dev_err(&client->dev, "Duplicate channel: %d\n",
  1698. chan);
  1699. return -EINVAL;
  1700. }
  1701. }
  1702. }
  1703. /*
  1704. * Once the raw channel assignments have been derived, they must be
  1705. * packed according to the device's register map.
  1706. */
  1707. for (i = 0, cycle_start = 0; i < sizeof(dev_desc->cycle_limit); i++) {
  1708. int offs = 0;
  1709. for (j = cycle_start;
  1710. j < cycle_start + dev_desc->cycle_limit[i]; j++) {
  1711. iqs7211->cycle_alloc[i][offs++] = 0x05;
  1712. iqs7211->cycle_alloc[i][offs++] = cycle_alloc[j][0];
  1713. iqs7211->cycle_alloc[i][offs++] = cycle_alloc[j][1];
  1714. }
  1715. cycle_start += dev_desc->cycle_limit[i];
  1716. }
  1717. return 0;
  1718. }
  1719. static int iqs7211_parse_tp(struct iqs7211_private *iqs7211,
  1720. struct fwnode_handle *tp_node)
  1721. {
  1722. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1723. struct i2c_client *client = iqs7211->client;
  1724. unsigned int pins[IQS7211_MAX_CTX];
  1725. int error, count, i, j;
  1726. count = fwnode_property_count_u32(tp_node, "azoteq,rx-enable");
  1727. if (count == -EINVAL) {
  1728. return 0;
  1729. } else if (count < 0) {
  1730. dev_err(&client->dev, "Failed to count CRx pins: %d\n", count);
  1731. return count;
  1732. } else if (count > IQS7211_NUM_CRX) {
  1733. dev_err(&client->dev, "Invalid number of CRx pins\n");
  1734. return -EINVAL;
  1735. }
  1736. error = fwnode_property_read_u32_array(tp_node, "azoteq,rx-enable",
  1737. pins, count);
  1738. if (error) {
  1739. dev_err(&client->dev, "Failed to read CRx pins: %d\n", error);
  1740. return error;
  1741. }
  1742. for (i = 0; i < count; i++) {
  1743. if (pins[i] >= IQS7211_NUM_CRX) {
  1744. dev_err(&client->dev, "Invalid CRx pin: %u\n", pins[i]);
  1745. return -EINVAL;
  1746. }
  1747. iqs7211->rx_tx_map[i] = pins[i];
  1748. }
  1749. iqs7211->tp_config.total_rx = count;
  1750. count = fwnode_property_count_u32(tp_node, "azoteq,tx-enable");
  1751. if (count < 0) {
  1752. dev_err(&client->dev, "Failed to count CTx pins: %d\n", count);
  1753. return count;
  1754. } else if (count > dev_desc->num_ctx) {
  1755. dev_err(&client->dev, "Invalid number of CTx pins\n");
  1756. return -EINVAL;
  1757. }
  1758. error = fwnode_property_read_u32_array(tp_node, "azoteq,tx-enable",
  1759. pins, count);
  1760. if (error) {
  1761. dev_err(&client->dev, "Failed to read CTx pins: %d\n", error);
  1762. return error;
  1763. }
  1764. for (i = 0; i < count; i++) {
  1765. if (pins[i] >= dev_desc->num_ctx) {
  1766. dev_err(&client->dev, "Invalid CTx pin: %u\n", pins[i]);
  1767. return -EINVAL;
  1768. }
  1769. for (j = 0; j < iqs7211->tp_config.total_rx; j++) {
  1770. if (iqs7211->rx_tx_map[j] != pins[i])
  1771. continue;
  1772. dev_err(&client->dev, "Conflicting CTx pin: %u\n",
  1773. pins[i]);
  1774. return -EINVAL;
  1775. }
  1776. iqs7211->rx_tx_map[iqs7211->tp_config.total_rx + i] = pins[i];
  1777. }
  1778. iqs7211->tp_config.total_tx = count;
  1779. return iqs7211_parse_cycles(iqs7211, tp_node);
  1780. }
  1781. static int iqs7211_parse_alp(struct iqs7211_private *iqs7211,
  1782. struct fwnode_handle *alp_node)
  1783. {
  1784. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1785. struct i2c_client *client = iqs7211->client;
  1786. struct iqs7211_reg_field_desc reg_field;
  1787. int error, count, i;
  1788. count = fwnode_property_count_u32(alp_node, "azoteq,rx-enable");
  1789. if (count < 0 && count != -EINVAL) {
  1790. dev_err(&client->dev, "Failed to count CRx pins: %d\n", count);
  1791. return count;
  1792. } else if (count > IQS7211_NUM_CRX) {
  1793. dev_err(&client->dev, "Invalid number of CRx pins\n");
  1794. return -EINVAL;
  1795. } else if (count >= 0) {
  1796. unsigned int pins[IQS7211_NUM_CRX];
  1797. error = fwnode_property_read_u32_array(alp_node,
  1798. "azoteq,rx-enable",
  1799. pins, count);
  1800. if (error) {
  1801. dev_err(&client->dev, "Failed to read CRx pins: %d\n",
  1802. error);
  1803. return error;
  1804. }
  1805. reg_field.addr = dev_desc->alp_config;
  1806. reg_field.mask = GENMASK(IQS7211_NUM_CRX - 1, 0);
  1807. reg_field.val = 0;
  1808. for (i = 0; i < count; i++) {
  1809. if (pins[i] < dev_desc->min_crx_alp ||
  1810. pins[i] >= IQS7211_NUM_CRX) {
  1811. dev_err(&client->dev, "Invalid CRx pin: %u\n",
  1812. pins[i]);
  1813. return -EINVAL;
  1814. }
  1815. reg_field.val |= BIT(pins[i]);
  1816. }
  1817. error = iqs7211_add_field(iqs7211, reg_field);
  1818. if (error)
  1819. return error;
  1820. }
  1821. count = fwnode_property_count_u32(alp_node, "azoteq,tx-enable");
  1822. if (count < 0 && count != -EINVAL) {
  1823. dev_err(&client->dev, "Failed to count CTx pins: %d\n", count);
  1824. return count;
  1825. } else if (count > dev_desc->num_ctx) {
  1826. dev_err(&client->dev, "Invalid number of CTx pins\n");
  1827. return -EINVAL;
  1828. } else if (count >= 0) {
  1829. unsigned int pins[IQS7211_MAX_CTX];
  1830. error = fwnode_property_read_u32_array(alp_node,
  1831. "azoteq,tx-enable",
  1832. pins, count);
  1833. if (error) {
  1834. dev_err(&client->dev, "Failed to read CTx pins: %d\n",
  1835. error);
  1836. return error;
  1837. }
  1838. reg_field.addr = dev_desc->alp_config + 1;
  1839. reg_field.mask = GENMASK(dev_desc->num_ctx - 1, 0);
  1840. reg_field.val = 0;
  1841. for (i = 0; i < count; i++) {
  1842. if (pins[i] >= dev_desc->num_ctx) {
  1843. dev_err(&client->dev, "Invalid CTx pin: %u\n",
  1844. pins[i]);
  1845. return -EINVAL;
  1846. }
  1847. reg_field.val |= BIT(pins[i]);
  1848. }
  1849. error = iqs7211_add_field(iqs7211, reg_field);
  1850. if (error)
  1851. return error;
  1852. }
  1853. return 0;
  1854. }
  1855. static int (*iqs7211_parse_extra[IQS7211_NUM_REG_GRPS])
  1856. (struct iqs7211_private *iqs7211,
  1857. struct fwnode_handle *reg_grp_node) = {
  1858. [IQS7211_REG_GRP_TP] = iqs7211_parse_tp,
  1859. [IQS7211_REG_GRP_ALP] = iqs7211_parse_alp,
  1860. };
  1861. static int iqs7211_parse_reg_grp(struct iqs7211_private *iqs7211,
  1862. struct fwnode_handle *reg_grp_node,
  1863. enum iqs7211_reg_grp_id reg_grp)
  1864. {
  1865. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1866. struct iqs7211_reg_field_desc reg_field;
  1867. int error, i;
  1868. error = iqs7211_parse_props(iqs7211, reg_grp_node, reg_grp,
  1869. IQS7211_REG_KEY_NONE);
  1870. if (error)
  1871. return error;
  1872. if (iqs7211_parse_extra[reg_grp]) {
  1873. error = iqs7211_parse_extra[reg_grp](iqs7211, reg_grp_node);
  1874. if (error)
  1875. return error;
  1876. }
  1877. iqs7211->ati_start |= dev_desc->ati_start[reg_grp];
  1878. reg_field.addr = dev_desc->kp_enable[reg_grp];
  1879. reg_field.mask = 0;
  1880. reg_field.val = 0;
  1881. for (i = 0; i < dev_desc->num_kp_events; i++) {
  1882. const char *event_name = dev_desc->kp_events[i].name;
  1883. struct fwnode_handle *event_node;
  1884. if (dev_desc->kp_events[i].reg_grp != reg_grp)
  1885. continue;
  1886. reg_field.mask |= dev_desc->kp_events[i].enable;
  1887. if (event_name)
  1888. event_node = fwnode_get_named_child_node(reg_grp_node,
  1889. event_name);
  1890. else
  1891. event_node = fwnode_handle_get(reg_grp_node);
  1892. if (!event_node)
  1893. continue;
  1894. error = iqs7211_parse_event(iqs7211, event_node,
  1895. dev_desc->kp_events[i].reg_grp,
  1896. dev_desc->kp_events[i].reg_key,
  1897. &iqs7211->kp_code[i]);
  1898. fwnode_handle_put(event_node);
  1899. if (error)
  1900. return error;
  1901. reg_field.val |= dev_desc->kp_events[i].enable;
  1902. iqs7211->event_mask |= iqs7211_reg_grp_masks[reg_grp];
  1903. }
  1904. return iqs7211_add_field(iqs7211, reg_field);
  1905. }
  1906. static int iqs7211_register_kp(struct iqs7211_private *iqs7211)
  1907. {
  1908. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1909. struct input_dev *kp_idev = iqs7211->kp_idev;
  1910. struct i2c_client *client = iqs7211->client;
  1911. int error, i;
  1912. for (i = 0; i < dev_desc->num_kp_events; i++)
  1913. if (iqs7211->kp_code[i])
  1914. break;
  1915. if (i == dev_desc->num_kp_events)
  1916. return 0;
  1917. kp_idev = devm_input_allocate_device(&client->dev);
  1918. if (!kp_idev)
  1919. return -ENOMEM;
  1920. iqs7211->kp_idev = kp_idev;
  1921. kp_idev->name = dev_desc->kp_name;
  1922. kp_idev->id.bustype = BUS_I2C;
  1923. for (i = 0; i < dev_desc->num_kp_events; i++)
  1924. if (iqs7211->kp_code[i])
  1925. input_set_capability(iqs7211->kp_idev, EV_KEY,
  1926. iqs7211->kp_code[i]);
  1927. error = input_register_device(kp_idev);
  1928. if (error)
  1929. dev_err(&client->dev, "Failed to register %s: %d\n",
  1930. kp_idev->name, error);
  1931. return error;
  1932. }
  1933. static int iqs7211_register_tp(struct iqs7211_private *iqs7211)
  1934. {
  1935. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1936. struct touchscreen_properties *prop = &iqs7211->prop;
  1937. struct input_dev *tp_idev = iqs7211->tp_idev;
  1938. struct i2c_client *client = iqs7211->client;
  1939. int error;
  1940. error = device_property_read_u32(&client->dev, "azoteq,num-contacts",
  1941. &iqs7211->num_contacts);
  1942. if (error == -EINVAL) {
  1943. return 0;
  1944. } else if (error) {
  1945. dev_err(&client->dev, "Failed to read number of contacts: %d\n",
  1946. error);
  1947. return error;
  1948. } else if (iqs7211->num_contacts > IQS7211_MAX_CONTACTS) {
  1949. dev_err(&client->dev, "Invalid number of contacts: %u\n",
  1950. iqs7211->num_contacts);
  1951. return -EINVAL;
  1952. }
  1953. iqs7211->tp_config.num_contacts = iqs7211->num_contacts ? : 1;
  1954. if (!iqs7211->num_contacts)
  1955. return 0;
  1956. iqs7211->event_mask |= IQS7211_EVENT_MASK_MOVE;
  1957. tp_idev = devm_input_allocate_device(&client->dev);
  1958. if (!tp_idev)
  1959. return -ENOMEM;
  1960. iqs7211->tp_idev = tp_idev;
  1961. tp_idev->name = dev_desc->tp_name;
  1962. tp_idev->id.bustype = BUS_I2C;
  1963. input_set_abs_params(tp_idev, ABS_MT_POSITION_X,
  1964. 0, le16_to_cpu(iqs7211->tp_config.max_x), 0, 0);
  1965. input_set_abs_params(tp_idev, ABS_MT_POSITION_Y,
  1966. 0, le16_to_cpu(iqs7211->tp_config.max_y), 0, 0);
  1967. input_set_abs_params(tp_idev, ABS_MT_PRESSURE, 0, U16_MAX, 0, 0);
  1968. touchscreen_parse_properties(tp_idev, true, prop);
  1969. /*
  1970. * The device reserves 0xFFFF for coordinates that correspond to slots
  1971. * which are not in a state of touch.
  1972. */
  1973. if (prop->max_x >= U16_MAX || prop->max_y >= U16_MAX) {
  1974. dev_err(&client->dev, "Invalid trackpad size: %u*%u\n",
  1975. prop->max_x, prop->max_y);
  1976. return -EINVAL;
  1977. }
  1978. iqs7211->tp_config.max_x = cpu_to_le16(prop->max_x);
  1979. iqs7211->tp_config.max_y = cpu_to_le16(prop->max_y);
  1980. error = input_mt_init_slots(tp_idev, iqs7211->num_contacts,
  1981. INPUT_MT_DIRECT);
  1982. if (error) {
  1983. dev_err(&client->dev, "Failed to initialize slots: %d\n",
  1984. error);
  1985. return error;
  1986. }
  1987. error = input_register_device(tp_idev);
  1988. if (error)
  1989. dev_err(&client->dev, "Failed to register %s: %d\n",
  1990. tp_idev->name, error);
  1991. return error;
  1992. }
  1993. static int iqs7211_report(struct iqs7211_private *iqs7211)
  1994. {
  1995. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  1996. struct i2c_client *client = iqs7211->client;
  1997. struct iqs7211_touch_data *touch_data;
  1998. u16 info_flags, charge_mode, gesture_flags;
  1999. __le16 status[12];
  2000. int error, i;
  2001. error = iqs7211_read_burst(iqs7211, dev_desc->sys_stat, status,
  2002. dev_desc->contact_offs * sizeof(__le16) +
  2003. iqs7211->num_contacts * sizeof(*touch_data));
  2004. if (error)
  2005. return error;
  2006. info_flags = le16_to_cpu(status[dev_desc->info_offs]);
  2007. if (info_flags & dev_desc->show_reset) {
  2008. dev_err(&client->dev, "Unexpected device reset\n");
  2009. /*
  2010. * The device may or may not expect forced communication after
  2011. * it exits hardware reset, so the corresponding state machine
  2012. * must be reset as well.
  2013. */
  2014. iqs7211->comms_mode = iqs7211->comms_init;
  2015. return iqs7211_init_device(iqs7211);
  2016. }
  2017. for (i = 0; i < ARRAY_SIZE(dev_desc->ati_error); i++) {
  2018. if (!(info_flags & dev_desc->ati_error[i]))
  2019. continue;
  2020. dev_err(&client->dev, "Unexpected %s ATI error\n",
  2021. iqs7211_reg_grp_names[i]);
  2022. return 0;
  2023. }
  2024. for (i = 0; i < iqs7211->num_contacts; i++) {
  2025. u16 pressure;
  2026. touch_data = (struct iqs7211_touch_data *)
  2027. &status[dev_desc->contact_offs] + i;
  2028. pressure = le16_to_cpu(touch_data->pressure);
  2029. input_mt_slot(iqs7211->tp_idev, i);
  2030. if (input_mt_report_slot_state(iqs7211->tp_idev, MT_TOOL_FINGER,
  2031. pressure != 0)) {
  2032. touchscreen_report_pos(iqs7211->tp_idev, &iqs7211->prop,
  2033. le16_to_cpu(touch_data->abs_x),
  2034. le16_to_cpu(touch_data->abs_y),
  2035. true);
  2036. input_report_abs(iqs7211->tp_idev, ABS_MT_PRESSURE,
  2037. pressure);
  2038. }
  2039. }
  2040. if (iqs7211->num_contacts) {
  2041. input_mt_sync_frame(iqs7211->tp_idev);
  2042. input_sync(iqs7211->tp_idev);
  2043. }
  2044. if (!iqs7211->kp_idev)
  2045. return 0;
  2046. charge_mode = info_flags & GENMASK(dev_desc->charge_shift + 2,
  2047. dev_desc->charge_shift);
  2048. charge_mode >>= dev_desc->charge_shift;
  2049. /*
  2050. * A charging mode higher than 2 (idle mode) indicates the device last
  2051. * operated in low-power mode and intends to express an ALP event.
  2052. */
  2053. if (info_flags & dev_desc->kp_events->mask && charge_mode > 2) {
  2054. input_report_key(iqs7211->kp_idev, *iqs7211->kp_code, 1);
  2055. input_sync(iqs7211->kp_idev);
  2056. input_report_key(iqs7211->kp_idev, *iqs7211->kp_code, 0);
  2057. }
  2058. for (i = 0; i < dev_desc->num_kp_events; i++) {
  2059. if (dev_desc->kp_events[i].reg_grp != IQS7211_REG_GRP_BTN)
  2060. continue;
  2061. input_report_key(iqs7211->kp_idev, iqs7211->kp_code[i],
  2062. info_flags & dev_desc->kp_events[i].mask);
  2063. }
  2064. gesture_flags = le16_to_cpu(status[dev_desc->gesture_offs]);
  2065. for (i = 0; i < dev_desc->num_kp_events; i++) {
  2066. enum iqs7211_reg_key_id reg_key = dev_desc->kp_events[i].reg_key;
  2067. u16 mask = dev_desc->kp_events[i].mask;
  2068. if (dev_desc->kp_events[i].reg_grp != IQS7211_REG_GRP_TP)
  2069. continue;
  2070. if ((gesture_flags ^ iqs7211->gesture_cache) & mask)
  2071. input_report_key(iqs7211->kp_idev, iqs7211->kp_code[i],
  2072. gesture_flags & mask);
  2073. iqs7211->gesture_cache &= ~mask;
  2074. /*
  2075. * Hold and palm gestures persist while the contact remains in
  2076. * place; all others are momentary and hence are followed by a
  2077. * complementary release event.
  2078. */
  2079. if (reg_key == IQS7211_REG_KEY_HOLD ||
  2080. reg_key == IQS7211_REG_KEY_PALM) {
  2081. iqs7211->gesture_cache |= gesture_flags & mask;
  2082. gesture_flags &= ~mask;
  2083. }
  2084. }
  2085. if (gesture_flags) {
  2086. input_sync(iqs7211->kp_idev);
  2087. for (i = 0; i < dev_desc->num_kp_events; i++)
  2088. if (dev_desc->kp_events[i].reg_grp == IQS7211_REG_GRP_TP &&
  2089. gesture_flags & dev_desc->kp_events[i].mask)
  2090. input_report_key(iqs7211->kp_idev,
  2091. iqs7211->kp_code[i], 0);
  2092. }
  2093. input_sync(iqs7211->kp_idev);
  2094. return 0;
  2095. }
  2096. static irqreturn_t iqs7211_irq(int irq, void *context)
  2097. {
  2098. struct iqs7211_private *iqs7211 = context;
  2099. return iqs7211_report(iqs7211) ? IRQ_NONE : IRQ_HANDLED;
  2100. }
  2101. static int iqs7211_suspend(struct device *dev)
  2102. {
  2103. struct iqs7211_private *iqs7211 = dev_get_drvdata(dev);
  2104. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  2105. int error;
  2106. if (!dev_desc->suspend || device_may_wakeup(dev))
  2107. return 0;
  2108. /*
  2109. * I2C communication prompts the device to assert its RDY pin if it is
  2110. * not already asserted. As such, the interrupt must be disabled so as
  2111. * to prevent reentrant interrupts.
  2112. */
  2113. disable_irq(gpiod_to_irq(iqs7211->irq_gpio));
  2114. error = iqs7211_write_word(iqs7211, dev_desc->sys_ctrl,
  2115. dev_desc->suspend);
  2116. enable_irq(gpiod_to_irq(iqs7211->irq_gpio));
  2117. return error;
  2118. }
  2119. static int iqs7211_resume(struct device *dev)
  2120. {
  2121. struct iqs7211_private *iqs7211 = dev_get_drvdata(dev);
  2122. const struct iqs7211_dev_desc *dev_desc = iqs7211->dev_desc;
  2123. __le16 sys_ctrl[] = {
  2124. 0,
  2125. cpu_to_le16(iqs7211->event_mask),
  2126. };
  2127. int error;
  2128. if (!dev_desc->suspend || device_may_wakeup(dev))
  2129. return 0;
  2130. disable_irq(gpiod_to_irq(iqs7211->irq_gpio));
  2131. /*
  2132. * Forced communication, if in use, must be explicitly enabled as part
  2133. * of the wake-up command.
  2134. */
  2135. error = iqs7211_write_burst(iqs7211, dev_desc->sys_ctrl, sys_ctrl,
  2136. sizeof(sys_ctrl));
  2137. enable_irq(gpiod_to_irq(iqs7211->irq_gpio));
  2138. return error;
  2139. }
  2140. static DEFINE_SIMPLE_DEV_PM_OPS(iqs7211_pm, iqs7211_suspend, iqs7211_resume);
  2141. static ssize_t fw_info_show(struct device *dev,
  2142. struct device_attribute *attr, char *buf)
  2143. {
  2144. struct iqs7211_private *iqs7211 = dev_get_drvdata(dev);
  2145. return sysfs_emit(buf, "%u.%u.%u.%u:%u.%u\n",
  2146. le16_to_cpu(iqs7211->ver_info.prod_num),
  2147. le32_to_cpu(iqs7211->ver_info.patch),
  2148. le16_to_cpu(iqs7211->ver_info.major),
  2149. le16_to_cpu(iqs7211->ver_info.minor),
  2150. iqs7211->exp_file[1], iqs7211->exp_file[0]);
  2151. }
  2152. static DEVICE_ATTR_RO(fw_info);
  2153. static struct attribute *iqs7211_attrs[] = {
  2154. &dev_attr_fw_info.attr,
  2155. NULL
  2156. };
  2157. ATTRIBUTE_GROUPS(iqs7211);
  2158. static const struct of_device_id iqs7211_of_match[] = {
  2159. {
  2160. .compatible = "azoteq,iqs7210a",
  2161. .data = &iqs7211_devs[IQS7210A],
  2162. },
  2163. {
  2164. .compatible = "azoteq,iqs7211a",
  2165. .data = &iqs7211_devs[IQS7211A],
  2166. },
  2167. {
  2168. .compatible = "azoteq,iqs7211e",
  2169. .data = &iqs7211_devs[IQS7211E],
  2170. },
  2171. { }
  2172. };
  2173. MODULE_DEVICE_TABLE(of, iqs7211_of_match);
  2174. static int iqs7211_probe(struct i2c_client *client)
  2175. {
  2176. struct iqs7211_private *iqs7211;
  2177. enum iqs7211_reg_grp_id reg_grp;
  2178. unsigned long irq_flags;
  2179. bool shared_irq;
  2180. int error, irq;
  2181. iqs7211 = devm_kzalloc(&client->dev, sizeof(*iqs7211), GFP_KERNEL);
  2182. if (!iqs7211)
  2183. return -ENOMEM;
  2184. i2c_set_clientdata(client, iqs7211);
  2185. iqs7211->client = client;
  2186. INIT_LIST_HEAD(&iqs7211->reg_field_head);
  2187. iqs7211->dev_desc = device_get_match_data(&client->dev);
  2188. if (!iqs7211->dev_desc)
  2189. return -ENODEV;
  2190. shared_irq = iqs7211->dev_desc->num_ctx == IQS7211_MAX_CTX;
  2191. /*
  2192. * The RDY pin behaves as an interrupt, but must also be polled ahead
  2193. * of unsolicited I2C communication. As such, it is first opened as a
  2194. * GPIO and then passed to gpiod_to_irq() to register the interrupt.
  2195. *
  2196. * If an extra CTx pin is present, the RDY and MCLR pins are combined
  2197. * into a single bidirectional pin. In that case, the platform's GPIO
  2198. * must be configured as an open-drain output.
  2199. */
  2200. iqs7211->irq_gpio = devm_gpiod_get(&client->dev, "irq",
  2201. shared_irq ? GPIOD_OUT_LOW
  2202. : GPIOD_IN);
  2203. if (IS_ERR(iqs7211->irq_gpio)) {
  2204. error = PTR_ERR(iqs7211->irq_gpio);
  2205. dev_err(&client->dev, "Failed to request IRQ GPIO: %d\n",
  2206. error);
  2207. return error;
  2208. }
  2209. if (shared_irq) {
  2210. iqs7211->reset_gpio = iqs7211->irq_gpio;
  2211. } else {
  2212. iqs7211->reset_gpio = devm_gpiod_get_optional(&client->dev,
  2213. "reset",
  2214. GPIOD_OUT_HIGH);
  2215. if (IS_ERR(iqs7211->reset_gpio)) {
  2216. error = PTR_ERR(iqs7211->reset_gpio);
  2217. dev_err(&client->dev,
  2218. "Failed to request reset GPIO: %d\n", error);
  2219. return error;
  2220. }
  2221. }
  2222. error = iqs7211_start_comms(iqs7211);
  2223. if (error)
  2224. return error;
  2225. for (reg_grp = 0; reg_grp < IQS7211_NUM_REG_GRPS; reg_grp++) {
  2226. const char *reg_grp_name = iqs7211_reg_grp_names[reg_grp];
  2227. struct fwnode_handle *reg_grp_node;
  2228. if (reg_grp_name)
  2229. reg_grp_node = device_get_named_child_node(&client->dev,
  2230. reg_grp_name);
  2231. else
  2232. reg_grp_node = fwnode_handle_get(dev_fwnode(&client->dev));
  2233. if (!reg_grp_node)
  2234. continue;
  2235. error = iqs7211_parse_reg_grp(iqs7211, reg_grp_node, reg_grp);
  2236. fwnode_handle_put(reg_grp_node);
  2237. if (error)
  2238. return error;
  2239. }
  2240. error = iqs7211_register_kp(iqs7211);
  2241. if (error)
  2242. return error;
  2243. error = iqs7211_register_tp(iqs7211);
  2244. if (error)
  2245. return error;
  2246. error = iqs7211_init_device(iqs7211);
  2247. if (error)
  2248. return error;
  2249. irq = gpiod_to_irq(iqs7211->irq_gpio);
  2250. if (irq < 0)
  2251. return irq;
  2252. irq_flags = gpiod_is_active_low(iqs7211->irq_gpio) ? IRQF_TRIGGER_LOW
  2253. : IRQF_TRIGGER_HIGH;
  2254. irq_flags |= IRQF_ONESHOT;
  2255. error = devm_request_threaded_irq(&client->dev, irq, NULL, iqs7211_irq,
  2256. irq_flags, client->name, iqs7211);
  2257. if (error)
  2258. dev_err(&client->dev, "Failed to request IRQ: %d\n", error);
  2259. return error;
  2260. }
  2261. static struct i2c_driver iqs7211_i2c_driver = {
  2262. .probe = iqs7211_probe,
  2263. .driver = {
  2264. .name = "iqs7211",
  2265. .of_match_table = iqs7211_of_match,
  2266. .dev_groups = iqs7211_groups,
  2267. .pm = pm_sleep_ptr(&iqs7211_pm),
  2268. },
  2269. };
  2270. module_i2c_driver(iqs7211_i2c_driver);
  2271. MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
  2272. MODULE_DESCRIPTION("Azoteq IQS7210A/7211A/E Trackpad/Touchscreen Controller");
  2273. MODULE_LICENSE("GPL");