cyttsp4_core.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163
  1. /*
  2. * cyttsp4_core.c
  3. * Cypress TrueTouch(TM) Standard Product V4 Core driver module.
  4. * For use with Cypress Txx4xx parts.
  5. * Supported parts include:
  6. * TMA4XX
  7. * TMA1036
  8. *
  9. * Copyright (C) 2012 Cypress Semiconductor
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * version 2, and only version 2, as published by the
  14. * Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
  22. *
  23. */
  24. #include "cyttsp4_core.h"
  25. #include <linux/delay.h>
  26. #include <linux/gpio.h>
  27. #include <linux/input/mt.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/sched.h>
  31. #include <linux/slab.h>
  32. /* Timeout in ms. */
  33. #define CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT 500
  34. #define CY_CORE_SLEEP_REQUEST_EXCLUSIVE_TIMEOUT 5000
  35. #define CY_CORE_MODE_CHANGE_TIMEOUT 1000
  36. #define CY_CORE_RESET_AND_WAIT_TIMEOUT 500
  37. #define CY_CORE_WAKEUP_TIMEOUT 500
  38. #define CY_CORE_STARTUP_RETRY_COUNT 3
  39. static const u8 ldr_exit[] = {
  40. 0xFF, 0x01, 0x3B, 0x00, 0x00, 0x4F, 0x6D, 0x17
  41. };
  42. static const u8 ldr_err_app[] = {
  43. 0x01, 0x02, 0x00, 0x00, 0x55, 0xDD, 0x17
  44. };
  45. static inline size_t merge_bytes(u8 high, u8 low)
  46. {
  47. return (high << 8) + low;
  48. }
  49. #ifdef VERBOSE_DEBUG
  50. static void cyttsp4_pr_buf(struct device *dev, u8 *pr_buf, u8 *dptr, int size,
  51. const char *data_name)
  52. {
  53. int i, k;
  54. const char fmt[] = "%02X ";
  55. int max;
  56. if (!size)
  57. return;
  58. max = (CY_MAX_PRBUF_SIZE - 1) - sizeof(CY_PR_TRUNCATED);
  59. pr_buf[0] = 0;
  60. for (i = k = 0; i < size && k < max; i++, k += 3)
  61. scnprintf(pr_buf + k, CY_MAX_PRBUF_SIZE, fmt, dptr[i]);
  62. dev_vdbg(dev, "%s: %s[0..%d]=%s%s\n", __func__, data_name, size - 1,
  63. pr_buf, size <= max ? "" : CY_PR_TRUNCATED);
  64. }
  65. #else
  66. #define cyttsp4_pr_buf(dev, pr_buf, dptr, size, data_name) do { } while (0)
  67. #endif
  68. static int cyttsp4_load_status_regs(struct cyttsp4 *cd)
  69. {
  70. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  71. struct device *dev = cd->dev;
  72. int rc;
  73. rc = cyttsp4_adap_read(cd, CY_REG_BASE, si->si_ofs.mode_size,
  74. si->xy_mode);
  75. if (rc < 0)
  76. dev_err(dev, "%s: fail read mode regs r=%d\n",
  77. __func__, rc);
  78. else
  79. cyttsp4_pr_buf(dev, cd->pr_buf, si->xy_mode,
  80. si->si_ofs.mode_size, "xy_mode");
  81. return rc;
  82. }
  83. static int cyttsp4_handshake(struct cyttsp4 *cd, u8 mode)
  84. {
  85. u8 cmd = mode ^ CY_HST_TOGGLE;
  86. int rc;
  87. /*
  88. * Mode change issued, handshaking now will cause endless mode change
  89. * requests, for sync mode modechange will do same with handshake
  90. * */
  91. if (mode & CY_HST_MODE_CHANGE)
  92. return 0;
  93. rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(cmd), &cmd);
  94. if (rc < 0)
  95. dev_err(cd->dev, "%s: bus write fail on handshake (ret=%d)\n",
  96. __func__, rc);
  97. return rc;
  98. }
  99. static int cyttsp4_hw_soft_reset(struct cyttsp4 *cd)
  100. {
  101. u8 cmd = CY_HST_RESET;
  102. int rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(cmd), &cmd);
  103. if (rc < 0) {
  104. dev_err(cd->dev, "%s: FAILED to execute SOFT reset\n",
  105. __func__);
  106. return rc;
  107. }
  108. return 0;
  109. }
  110. static int cyttsp4_hw_hard_reset(struct cyttsp4 *cd)
  111. {
  112. if (cd->cpdata->xres) {
  113. cd->cpdata->xres(cd->cpdata, cd->dev);
  114. dev_dbg(cd->dev, "%s: execute HARD reset\n", __func__);
  115. return 0;
  116. }
  117. dev_err(cd->dev, "%s: FAILED to execute HARD reset\n", __func__);
  118. return -ENOSYS;
  119. }
  120. static int cyttsp4_hw_reset(struct cyttsp4 *cd)
  121. {
  122. int rc = cyttsp4_hw_hard_reset(cd);
  123. if (rc == -ENOSYS)
  124. rc = cyttsp4_hw_soft_reset(cd);
  125. return rc;
  126. }
  127. /*
  128. * Gets number of bits for a touch filed as parameter,
  129. * sets maximum value for field which is used as bit mask
  130. * and returns number of bytes required for that field
  131. */
  132. static int cyttsp4_bits_2_bytes(unsigned int nbits, size_t *max)
  133. {
  134. *max = 1UL << nbits;
  135. return (nbits + 7) / 8;
  136. }
  137. static int cyttsp4_si_data_offsets(struct cyttsp4 *cd)
  138. {
  139. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  140. int rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(si->si_data),
  141. &si->si_data);
  142. if (rc < 0) {
  143. dev_err(cd->dev, "%s: fail read sysinfo data offsets r=%d\n",
  144. __func__, rc);
  145. return rc;
  146. }
  147. /* Print sysinfo data offsets */
  148. cyttsp4_pr_buf(cd->dev, cd->pr_buf, (u8 *)&si->si_data,
  149. sizeof(si->si_data), "sysinfo_data_offsets");
  150. /* convert sysinfo data offset bytes into integers */
  151. si->si_ofs.map_sz = merge_bytes(si->si_data.map_szh,
  152. si->si_data.map_szl);
  153. si->si_ofs.map_sz = merge_bytes(si->si_data.map_szh,
  154. si->si_data.map_szl);
  155. si->si_ofs.cydata_ofs = merge_bytes(si->si_data.cydata_ofsh,
  156. si->si_data.cydata_ofsl);
  157. si->si_ofs.test_ofs = merge_bytes(si->si_data.test_ofsh,
  158. si->si_data.test_ofsl);
  159. si->si_ofs.pcfg_ofs = merge_bytes(si->si_data.pcfg_ofsh,
  160. si->si_data.pcfg_ofsl);
  161. si->si_ofs.opcfg_ofs = merge_bytes(si->si_data.opcfg_ofsh,
  162. si->si_data.opcfg_ofsl);
  163. si->si_ofs.ddata_ofs = merge_bytes(si->si_data.ddata_ofsh,
  164. si->si_data.ddata_ofsl);
  165. si->si_ofs.mdata_ofs = merge_bytes(si->si_data.mdata_ofsh,
  166. si->si_data.mdata_ofsl);
  167. return rc;
  168. }
  169. static int cyttsp4_si_get_cydata(struct cyttsp4 *cd)
  170. {
  171. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  172. int read_offset;
  173. int mfgid_sz, calc_mfgid_sz;
  174. void *p;
  175. int rc;
  176. si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs;
  177. dev_dbg(cd->dev, "%s: cydata size: %Zd\n", __func__,
  178. si->si_ofs.cydata_size);
  179. p = krealloc(si->si_ptrs.cydata, si->si_ofs.cydata_size, GFP_KERNEL);
  180. if (p == NULL) {
  181. dev_err(cd->dev, "%s: fail alloc cydata memory\n", __func__);
  182. return -ENOMEM;
  183. }
  184. si->si_ptrs.cydata = p;
  185. read_offset = si->si_ofs.cydata_ofs;
  186. /* Read the CYDA registers up to MFGID field */
  187. rc = cyttsp4_adap_read(cd, read_offset,
  188. offsetof(struct cyttsp4_cydata, mfgid_sz)
  189. + sizeof(si->si_ptrs.cydata->mfgid_sz),
  190. si->si_ptrs.cydata);
  191. if (rc < 0) {
  192. dev_err(cd->dev, "%s: fail read cydata r=%d\n",
  193. __func__, rc);
  194. return rc;
  195. }
  196. /* Check MFGID size */
  197. mfgid_sz = si->si_ptrs.cydata->mfgid_sz;
  198. calc_mfgid_sz = si->si_ofs.cydata_size - sizeof(struct cyttsp4_cydata);
  199. if (mfgid_sz != calc_mfgid_sz) {
  200. dev_err(cd->dev, "%s: mismatch in MFGID size, reported:%d calculated:%d\n",
  201. __func__, mfgid_sz, calc_mfgid_sz);
  202. return -EINVAL;
  203. }
  204. read_offset += offsetof(struct cyttsp4_cydata, mfgid_sz)
  205. + sizeof(si->si_ptrs.cydata->mfgid_sz);
  206. /* Read the CYDA registers for MFGID field */
  207. rc = cyttsp4_adap_read(cd, read_offset, si->si_ptrs.cydata->mfgid_sz,
  208. si->si_ptrs.cydata->mfg_id);
  209. if (rc < 0) {
  210. dev_err(cd->dev, "%s: fail read cydata r=%d\n",
  211. __func__, rc);
  212. return rc;
  213. }
  214. read_offset += si->si_ptrs.cydata->mfgid_sz;
  215. /* Read the rest of the CYDA registers */
  216. rc = cyttsp4_adap_read(cd, read_offset,
  217. sizeof(struct cyttsp4_cydata)
  218. - offsetof(struct cyttsp4_cydata, cyito_idh),
  219. &si->si_ptrs.cydata->cyito_idh);
  220. if (rc < 0) {
  221. dev_err(cd->dev, "%s: fail read cydata r=%d\n",
  222. __func__, rc);
  223. return rc;
  224. }
  225. cyttsp4_pr_buf(cd->dev, cd->pr_buf, (u8 *)si->si_ptrs.cydata,
  226. si->si_ofs.cydata_size, "sysinfo_cydata");
  227. return rc;
  228. }
  229. static int cyttsp4_si_get_test_data(struct cyttsp4 *cd)
  230. {
  231. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  232. void *p;
  233. int rc;
  234. si->si_ofs.test_size = si->si_ofs.pcfg_ofs - si->si_ofs.test_ofs;
  235. p = krealloc(si->si_ptrs.test, si->si_ofs.test_size, GFP_KERNEL);
  236. if (p == NULL) {
  237. dev_err(cd->dev, "%s: fail alloc test memory\n", __func__);
  238. return -ENOMEM;
  239. }
  240. si->si_ptrs.test = p;
  241. rc = cyttsp4_adap_read(cd, si->si_ofs.test_ofs, si->si_ofs.test_size,
  242. si->si_ptrs.test);
  243. if (rc < 0) {
  244. dev_err(cd->dev, "%s: fail read test data r=%d\n",
  245. __func__, rc);
  246. return rc;
  247. }
  248. cyttsp4_pr_buf(cd->dev, cd->pr_buf,
  249. (u8 *)si->si_ptrs.test, si->si_ofs.test_size,
  250. "sysinfo_test_data");
  251. if (si->si_ptrs.test->post_codel &
  252. CY_POST_CODEL_WDG_RST)
  253. dev_info(cd->dev, "%s: %s codel=%02X\n",
  254. __func__, "Reset was a WATCHDOG RESET",
  255. si->si_ptrs.test->post_codel);
  256. if (!(si->si_ptrs.test->post_codel &
  257. CY_POST_CODEL_CFG_DATA_CRC_FAIL))
  258. dev_info(cd->dev, "%s: %s codel=%02X\n", __func__,
  259. "Config Data CRC FAIL",
  260. si->si_ptrs.test->post_codel);
  261. if (!(si->si_ptrs.test->post_codel &
  262. CY_POST_CODEL_PANEL_TEST_FAIL))
  263. dev_info(cd->dev, "%s: %s codel=%02X\n",
  264. __func__, "PANEL TEST FAIL",
  265. si->si_ptrs.test->post_codel);
  266. dev_info(cd->dev, "%s: SCANNING is %s codel=%02X\n",
  267. __func__, si->si_ptrs.test->post_codel & 0x08 ?
  268. "ENABLED" : "DISABLED",
  269. si->si_ptrs.test->post_codel);
  270. return rc;
  271. }
  272. static int cyttsp4_si_get_pcfg_data(struct cyttsp4 *cd)
  273. {
  274. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  275. void *p;
  276. int rc;
  277. si->si_ofs.pcfg_size = si->si_ofs.opcfg_ofs - si->si_ofs.pcfg_ofs;
  278. p = krealloc(si->si_ptrs.pcfg, si->si_ofs.pcfg_size, GFP_KERNEL);
  279. if (p == NULL) {
  280. rc = -ENOMEM;
  281. dev_err(cd->dev, "%s: fail alloc pcfg memory r=%d\n",
  282. __func__, rc);
  283. return rc;
  284. }
  285. si->si_ptrs.pcfg = p;
  286. rc = cyttsp4_adap_read(cd, si->si_ofs.pcfg_ofs, si->si_ofs.pcfg_size,
  287. si->si_ptrs.pcfg);
  288. if (rc < 0) {
  289. dev_err(cd->dev, "%s: fail read pcfg data r=%d\n",
  290. __func__, rc);
  291. return rc;
  292. }
  293. si->si_ofs.max_x = merge_bytes((si->si_ptrs.pcfg->res_xh
  294. & CY_PCFG_RESOLUTION_X_MASK), si->si_ptrs.pcfg->res_xl);
  295. si->si_ofs.x_origin = !!(si->si_ptrs.pcfg->res_xh
  296. & CY_PCFG_ORIGIN_X_MASK);
  297. si->si_ofs.max_y = merge_bytes((si->si_ptrs.pcfg->res_yh
  298. & CY_PCFG_RESOLUTION_Y_MASK), si->si_ptrs.pcfg->res_yl);
  299. si->si_ofs.y_origin = !!(si->si_ptrs.pcfg->res_yh
  300. & CY_PCFG_ORIGIN_Y_MASK);
  301. si->si_ofs.max_p = merge_bytes(si->si_ptrs.pcfg->max_zh,
  302. si->si_ptrs.pcfg->max_zl);
  303. cyttsp4_pr_buf(cd->dev, cd->pr_buf,
  304. (u8 *)si->si_ptrs.pcfg,
  305. si->si_ofs.pcfg_size, "sysinfo_pcfg_data");
  306. return rc;
  307. }
  308. static int cyttsp4_si_get_opcfg_data(struct cyttsp4 *cd)
  309. {
  310. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  311. struct cyttsp4_tch_abs_params *tch;
  312. struct cyttsp4_tch_rec_params *tch_old, *tch_new;
  313. enum cyttsp4_tch_abs abs;
  314. int i;
  315. void *p;
  316. int rc;
  317. si->si_ofs.opcfg_size = si->si_ofs.ddata_ofs - si->si_ofs.opcfg_ofs;
  318. p = krealloc(si->si_ptrs.opcfg, si->si_ofs.opcfg_size, GFP_KERNEL);
  319. if (p == NULL) {
  320. dev_err(cd->dev, "%s: fail alloc opcfg memory\n", __func__);
  321. rc = -ENOMEM;
  322. goto cyttsp4_si_get_opcfg_data_exit;
  323. }
  324. si->si_ptrs.opcfg = p;
  325. rc = cyttsp4_adap_read(cd, si->si_ofs.opcfg_ofs, si->si_ofs.opcfg_size,
  326. si->si_ptrs.opcfg);
  327. if (rc < 0) {
  328. dev_err(cd->dev, "%s: fail read opcfg data r=%d\n",
  329. __func__, rc);
  330. goto cyttsp4_si_get_opcfg_data_exit;
  331. }
  332. si->si_ofs.cmd_ofs = si->si_ptrs.opcfg->cmd_ofs;
  333. si->si_ofs.rep_ofs = si->si_ptrs.opcfg->rep_ofs;
  334. si->si_ofs.rep_sz = (si->si_ptrs.opcfg->rep_szh * 256) +
  335. si->si_ptrs.opcfg->rep_szl;
  336. si->si_ofs.num_btns = si->si_ptrs.opcfg->num_btns;
  337. si->si_ofs.num_btn_regs = (si->si_ofs.num_btns +
  338. CY_NUM_BTN_PER_REG - 1) / CY_NUM_BTN_PER_REG;
  339. si->si_ofs.tt_stat_ofs = si->si_ptrs.opcfg->tt_stat_ofs;
  340. si->si_ofs.obj_cfg0 = si->si_ptrs.opcfg->obj_cfg0;
  341. si->si_ofs.max_tchs = si->si_ptrs.opcfg->max_tchs &
  342. CY_BYTE_OFS_MASK;
  343. si->si_ofs.tch_rec_size = si->si_ptrs.opcfg->tch_rec_size &
  344. CY_BYTE_OFS_MASK;
  345. /* Get the old touch fields */
  346. for (abs = CY_TCH_X; abs < CY_NUM_TCH_FIELDS; abs++) {
  347. tch = &si->si_ofs.tch_abs[abs];
  348. tch_old = &si->si_ptrs.opcfg->tch_rec_old[abs];
  349. tch->ofs = tch_old->loc & CY_BYTE_OFS_MASK;
  350. tch->size = cyttsp4_bits_2_bytes(tch_old->size,
  351. &tch->max);
  352. tch->bofs = (tch_old->loc & CY_BOFS_MASK) >> CY_BOFS_SHIFT;
  353. }
  354. /* button fields */
  355. si->si_ofs.btn_rec_size = si->si_ptrs.opcfg->btn_rec_size;
  356. si->si_ofs.btn_diff_ofs = si->si_ptrs.opcfg->btn_diff_ofs;
  357. si->si_ofs.btn_diff_size = si->si_ptrs.opcfg->btn_diff_size;
  358. if (si->si_ofs.tch_rec_size > CY_TMA1036_TCH_REC_SIZE) {
  359. /* Get the extended touch fields */
  360. for (i = 0; i < CY_NUM_EXT_TCH_FIELDS; abs++, i++) {
  361. tch = &si->si_ofs.tch_abs[abs];
  362. tch_new = &si->si_ptrs.opcfg->tch_rec_new[i];
  363. tch->ofs = tch_new->loc & CY_BYTE_OFS_MASK;
  364. tch->size = cyttsp4_bits_2_bytes(tch_new->size,
  365. &tch->max);
  366. tch->bofs = (tch_new->loc & CY_BOFS_MASK) >> CY_BOFS_SHIFT;
  367. }
  368. }
  369. for (abs = 0; abs < CY_TCH_NUM_ABS; abs++) {
  370. dev_dbg(cd->dev, "%s: tch_rec_%s\n", __func__,
  371. cyttsp4_tch_abs_string[abs]);
  372. dev_dbg(cd->dev, "%s: ofs =%2Zd\n", __func__,
  373. si->si_ofs.tch_abs[abs].ofs);
  374. dev_dbg(cd->dev, "%s: siz =%2Zd\n", __func__,
  375. si->si_ofs.tch_abs[abs].size);
  376. dev_dbg(cd->dev, "%s: max =%2Zd\n", __func__,
  377. si->si_ofs.tch_abs[abs].max);
  378. dev_dbg(cd->dev, "%s: bofs=%2Zd\n", __func__,
  379. si->si_ofs.tch_abs[abs].bofs);
  380. }
  381. si->si_ofs.mode_size = si->si_ofs.tt_stat_ofs + 1;
  382. si->si_ofs.data_size = si->si_ofs.max_tchs *
  383. si->si_ptrs.opcfg->tch_rec_size;
  384. cyttsp4_pr_buf(cd->dev, cd->pr_buf, (u8 *)si->si_ptrs.opcfg,
  385. si->si_ofs.opcfg_size, "sysinfo_opcfg_data");
  386. cyttsp4_si_get_opcfg_data_exit:
  387. return rc;
  388. }
  389. static int cyttsp4_si_get_ddata(struct cyttsp4 *cd)
  390. {
  391. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  392. void *p;
  393. int rc;
  394. si->si_ofs.ddata_size = si->si_ofs.mdata_ofs - si->si_ofs.ddata_ofs;
  395. p = krealloc(si->si_ptrs.ddata, si->si_ofs.ddata_size, GFP_KERNEL);
  396. if (p == NULL) {
  397. dev_err(cd->dev, "%s: fail alloc ddata memory\n", __func__);
  398. return -ENOMEM;
  399. }
  400. si->si_ptrs.ddata = p;
  401. rc = cyttsp4_adap_read(cd, si->si_ofs.ddata_ofs, si->si_ofs.ddata_size,
  402. si->si_ptrs.ddata);
  403. if (rc < 0)
  404. dev_err(cd->dev, "%s: fail read ddata data r=%d\n",
  405. __func__, rc);
  406. else
  407. cyttsp4_pr_buf(cd->dev, cd->pr_buf,
  408. (u8 *)si->si_ptrs.ddata,
  409. si->si_ofs.ddata_size, "sysinfo_ddata");
  410. return rc;
  411. }
  412. static int cyttsp4_si_get_mdata(struct cyttsp4 *cd)
  413. {
  414. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  415. void *p;
  416. int rc;
  417. si->si_ofs.mdata_size = si->si_ofs.map_sz - si->si_ofs.mdata_ofs;
  418. p = krealloc(si->si_ptrs.mdata, si->si_ofs.mdata_size, GFP_KERNEL);
  419. if (p == NULL) {
  420. dev_err(cd->dev, "%s: fail alloc mdata memory\n", __func__);
  421. return -ENOMEM;
  422. }
  423. si->si_ptrs.mdata = p;
  424. rc = cyttsp4_adap_read(cd, si->si_ofs.mdata_ofs, si->si_ofs.mdata_size,
  425. si->si_ptrs.mdata);
  426. if (rc < 0)
  427. dev_err(cd->dev, "%s: fail read mdata data r=%d\n",
  428. __func__, rc);
  429. else
  430. cyttsp4_pr_buf(cd->dev, cd->pr_buf,
  431. (u8 *)si->si_ptrs.mdata,
  432. si->si_ofs.mdata_size, "sysinfo_mdata");
  433. return rc;
  434. }
  435. static int cyttsp4_si_get_btn_data(struct cyttsp4 *cd)
  436. {
  437. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  438. int btn;
  439. int num_defined_keys;
  440. u16 *key_table;
  441. void *p;
  442. int rc = 0;
  443. if (si->si_ofs.num_btns) {
  444. si->si_ofs.btn_keys_size = si->si_ofs.num_btns *
  445. sizeof(struct cyttsp4_btn);
  446. p = krealloc(si->btn, si->si_ofs.btn_keys_size,
  447. GFP_KERNEL|__GFP_ZERO);
  448. if (p == NULL) {
  449. dev_err(cd->dev, "%s: %s\n", __func__,
  450. "fail alloc btn_keys memory");
  451. return -ENOMEM;
  452. }
  453. si->btn = p;
  454. if (cd->cpdata->sett[CY_IC_GRPNUM_BTN_KEYS] == NULL)
  455. num_defined_keys = 0;
  456. else if (cd->cpdata->sett[CY_IC_GRPNUM_BTN_KEYS]->data == NULL)
  457. num_defined_keys = 0;
  458. else
  459. num_defined_keys = cd->cpdata->sett
  460. [CY_IC_GRPNUM_BTN_KEYS]->size;
  461. for (btn = 0; btn < si->si_ofs.num_btns &&
  462. btn < num_defined_keys; btn++) {
  463. key_table = (u16 *)cd->cpdata->sett
  464. [CY_IC_GRPNUM_BTN_KEYS]->data;
  465. si->btn[btn].key_code = key_table[btn];
  466. si->btn[btn].state = CY_BTN_RELEASED;
  467. si->btn[btn].enabled = true;
  468. }
  469. for (; btn < si->si_ofs.num_btns; btn++) {
  470. si->btn[btn].key_code = KEY_RESERVED;
  471. si->btn[btn].state = CY_BTN_RELEASED;
  472. si->btn[btn].enabled = true;
  473. }
  474. return rc;
  475. }
  476. si->si_ofs.btn_keys_size = 0;
  477. kfree(si->btn);
  478. si->btn = NULL;
  479. return rc;
  480. }
  481. static int cyttsp4_si_get_op_data_ptrs(struct cyttsp4 *cd)
  482. {
  483. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  484. void *p;
  485. p = krealloc(si->xy_mode, si->si_ofs.mode_size, GFP_KERNEL|__GFP_ZERO);
  486. if (p == NULL)
  487. return -ENOMEM;
  488. si->xy_mode = p;
  489. p = krealloc(si->xy_data, si->si_ofs.data_size, GFP_KERNEL|__GFP_ZERO);
  490. if (p == NULL)
  491. return -ENOMEM;
  492. si->xy_data = p;
  493. p = krealloc(si->btn_rec_data,
  494. si->si_ofs.btn_rec_size * si->si_ofs.num_btns,
  495. GFP_KERNEL|__GFP_ZERO);
  496. if (p == NULL)
  497. return -ENOMEM;
  498. si->btn_rec_data = p;
  499. return 0;
  500. }
  501. static void cyttsp4_si_put_log_data(struct cyttsp4 *cd)
  502. {
  503. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  504. dev_dbg(cd->dev, "%s: cydata_ofs =%4Zd siz=%4Zd\n", __func__,
  505. si->si_ofs.cydata_ofs, si->si_ofs.cydata_size);
  506. dev_dbg(cd->dev, "%s: test_ofs =%4Zd siz=%4Zd\n", __func__,
  507. si->si_ofs.test_ofs, si->si_ofs.test_size);
  508. dev_dbg(cd->dev, "%s: pcfg_ofs =%4Zd siz=%4Zd\n", __func__,
  509. si->si_ofs.pcfg_ofs, si->si_ofs.pcfg_size);
  510. dev_dbg(cd->dev, "%s: opcfg_ofs =%4Zd siz=%4Zd\n", __func__,
  511. si->si_ofs.opcfg_ofs, si->si_ofs.opcfg_size);
  512. dev_dbg(cd->dev, "%s: ddata_ofs =%4Zd siz=%4Zd\n", __func__,
  513. si->si_ofs.ddata_ofs, si->si_ofs.ddata_size);
  514. dev_dbg(cd->dev, "%s: mdata_ofs =%4Zd siz=%4Zd\n", __func__,
  515. si->si_ofs.mdata_ofs, si->si_ofs.mdata_size);
  516. dev_dbg(cd->dev, "%s: cmd_ofs =%4Zd\n", __func__,
  517. si->si_ofs.cmd_ofs);
  518. dev_dbg(cd->dev, "%s: rep_ofs =%4Zd\n", __func__,
  519. si->si_ofs.rep_ofs);
  520. dev_dbg(cd->dev, "%s: rep_sz =%4Zd\n", __func__,
  521. si->si_ofs.rep_sz);
  522. dev_dbg(cd->dev, "%s: num_btns =%4Zd\n", __func__,
  523. si->si_ofs.num_btns);
  524. dev_dbg(cd->dev, "%s: num_btn_regs =%4Zd\n", __func__,
  525. si->si_ofs.num_btn_regs);
  526. dev_dbg(cd->dev, "%s: tt_stat_ofs =%4Zd\n", __func__,
  527. si->si_ofs.tt_stat_ofs);
  528. dev_dbg(cd->dev, "%s: tch_rec_size =%4Zd\n", __func__,
  529. si->si_ofs.tch_rec_size);
  530. dev_dbg(cd->dev, "%s: max_tchs =%4Zd\n", __func__,
  531. si->si_ofs.max_tchs);
  532. dev_dbg(cd->dev, "%s: mode_size =%4Zd\n", __func__,
  533. si->si_ofs.mode_size);
  534. dev_dbg(cd->dev, "%s: data_size =%4Zd\n", __func__,
  535. si->si_ofs.data_size);
  536. dev_dbg(cd->dev, "%s: map_sz =%4Zd\n", __func__,
  537. si->si_ofs.map_sz);
  538. dev_dbg(cd->dev, "%s: btn_rec_size =%2Zd\n", __func__,
  539. si->si_ofs.btn_rec_size);
  540. dev_dbg(cd->dev, "%s: btn_diff_ofs =%2Zd\n", __func__,
  541. si->si_ofs.btn_diff_ofs);
  542. dev_dbg(cd->dev, "%s: btn_diff_size =%2Zd\n", __func__,
  543. si->si_ofs.btn_diff_size);
  544. dev_dbg(cd->dev, "%s: max_x = 0x%04ZX (%Zd)\n", __func__,
  545. si->si_ofs.max_x, si->si_ofs.max_x);
  546. dev_dbg(cd->dev, "%s: x_origin = %Zd (%s)\n", __func__,
  547. si->si_ofs.x_origin,
  548. si->si_ofs.x_origin == CY_NORMAL_ORIGIN ?
  549. "left corner" : "right corner");
  550. dev_dbg(cd->dev, "%s: max_y = 0x%04ZX (%Zd)\n", __func__,
  551. si->si_ofs.max_y, si->si_ofs.max_y);
  552. dev_dbg(cd->dev, "%s: y_origin = %Zd (%s)\n", __func__,
  553. si->si_ofs.y_origin,
  554. si->si_ofs.y_origin == CY_NORMAL_ORIGIN ?
  555. "upper corner" : "lower corner");
  556. dev_dbg(cd->dev, "%s: max_p = 0x%04ZX (%Zd)\n", __func__,
  557. si->si_ofs.max_p, si->si_ofs.max_p);
  558. dev_dbg(cd->dev, "%s: xy_mode=%p xy_data=%p\n", __func__,
  559. si->xy_mode, si->xy_data);
  560. }
  561. static int cyttsp4_get_sysinfo_regs(struct cyttsp4 *cd)
  562. {
  563. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  564. int rc;
  565. rc = cyttsp4_si_data_offsets(cd);
  566. if (rc < 0)
  567. return rc;
  568. rc = cyttsp4_si_get_cydata(cd);
  569. if (rc < 0)
  570. return rc;
  571. rc = cyttsp4_si_get_test_data(cd);
  572. if (rc < 0)
  573. return rc;
  574. rc = cyttsp4_si_get_pcfg_data(cd);
  575. if (rc < 0)
  576. return rc;
  577. rc = cyttsp4_si_get_opcfg_data(cd);
  578. if (rc < 0)
  579. return rc;
  580. rc = cyttsp4_si_get_ddata(cd);
  581. if (rc < 0)
  582. return rc;
  583. rc = cyttsp4_si_get_mdata(cd);
  584. if (rc < 0)
  585. return rc;
  586. rc = cyttsp4_si_get_btn_data(cd);
  587. if (rc < 0)
  588. return rc;
  589. rc = cyttsp4_si_get_op_data_ptrs(cd);
  590. if (rc < 0) {
  591. dev_err(cd->dev, "%s: failed to get_op_data\n",
  592. __func__);
  593. return rc;
  594. }
  595. cyttsp4_si_put_log_data(cd);
  596. /* provide flow control handshake */
  597. rc = cyttsp4_handshake(cd, si->si_data.hst_mode);
  598. if (rc < 0)
  599. dev_err(cd->dev, "%s: handshake fail on sysinfo reg\n",
  600. __func__);
  601. si->ready = true;
  602. return rc;
  603. }
  604. static void cyttsp4_queue_startup_(struct cyttsp4 *cd)
  605. {
  606. if (cd->startup_state == STARTUP_NONE) {
  607. cd->startup_state = STARTUP_QUEUED;
  608. schedule_work(&cd->startup_work);
  609. dev_dbg(cd->dev, "%s: cyttsp4_startup queued\n", __func__);
  610. } else {
  611. dev_dbg(cd->dev, "%s: startup_state = %d\n", __func__,
  612. cd->startup_state);
  613. }
  614. }
  615. static void cyttsp4_report_slot_liftoff(struct cyttsp4_mt_data *md,
  616. int max_slots)
  617. {
  618. int t;
  619. if (md->num_prv_tch == 0)
  620. return;
  621. for (t = 0; t < max_slots; t++) {
  622. input_mt_slot(md->input, t);
  623. input_mt_report_slot_state(md->input,
  624. MT_TOOL_FINGER, false);
  625. }
  626. }
  627. static void cyttsp4_lift_all(struct cyttsp4_mt_data *md)
  628. {
  629. if (!md->si)
  630. return;
  631. if (md->num_prv_tch != 0) {
  632. cyttsp4_report_slot_liftoff(md,
  633. md->si->si_ofs.tch_abs[CY_TCH_T].max);
  634. input_sync(md->input);
  635. md->num_prv_tch = 0;
  636. }
  637. }
  638. static void cyttsp4_get_touch_axis(struct cyttsp4_mt_data *md,
  639. int *axis, int size, int max, u8 *xy_data, int bofs)
  640. {
  641. int nbyte;
  642. int next;
  643. for (nbyte = 0, *axis = 0, next = 0; nbyte < size; nbyte++) {
  644. dev_vdbg(&md->input->dev,
  645. "%s: *axis=%02X(%d) size=%d max=%08X xy_data=%p"
  646. " xy_data[%d]=%02X(%d) bofs=%d\n",
  647. __func__, *axis, *axis, size, max, xy_data, next,
  648. xy_data[next], xy_data[next], bofs);
  649. *axis = (*axis * 256) + (xy_data[next] >> bofs);
  650. next++;
  651. }
  652. *axis &= max - 1;
  653. dev_vdbg(&md->input->dev,
  654. "%s: *axis=%02X(%d) size=%d max=%08X xy_data=%p"
  655. " xy_data[%d]=%02X(%d)\n",
  656. __func__, *axis, *axis, size, max, xy_data, next,
  657. xy_data[next], xy_data[next]);
  658. }
  659. static void cyttsp4_get_touch(struct cyttsp4_mt_data *md,
  660. struct cyttsp4_touch *touch, u8 *xy_data)
  661. {
  662. struct device *dev = &md->input->dev;
  663. struct cyttsp4_sysinfo *si = md->si;
  664. enum cyttsp4_tch_abs abs;
  665. int tmp;
  666. bool flipped;
  667. for (abs = CY_TCH_X; abs < CY_TCH_NUM_ABS; abs++) {
  668. cyttsp4_get_touch_axis(md, &touch->abs[abs],
  669. si->si_ofs.tch_abs[abs].size,
  670. si->si_ofs.tch_abs[abs].max,
  671. xy_data + si->si_ofs.tch_abs[abs].ofs,
  672. si->si_ofs.tch_abs[abs].bofs);
  673. dev_vdbg(dev, "%s: get %s=%04X(%d)\n", __func__,
  674. cyttsp4_tch_abs_string[abs],
  675. touch->abs[abs], touch->abs[abs]);
  676. }
  677. if (md->pdata->flags & CY_FLAG_FLIP) {
  678. tmp = touch->abs[CY_TCH_X];
  679. touch->abs[CY_TCH_X] = touch->abs[CY_TCH_Y];
  680. touch->abs[CY_TCH_Y] = tmp;
  681. flipped = true;
  682. } else
  683. flipped = false;
  684. if (md->pdata->flags & CY_FLAG_INV_X) {
  685. if (flipped)
  686. touch->abs[CY_TCH_X] = md->si->si_ofs.max_y -
  687. touch->abs[CY_TCH_X];
  688. else
  689. touch->abs[CY_TCH_X] = md->si->si_ofs.max_x -
  690. touch->abs[CY_TCH_X];
  691. }
  692. if (md->pdata->flags & CY_FLAG_INV_Y) {
  693. if (flipped)
  694. touch->abs[CY_TCH_Y] = md->si->si_ofs.max_x -
  695. touch->abs[CY_TCH_Y];
  696. else
  697. touch->abs[CY_TCH_Y] = md->si->si_ofs.max_y -
  698. touch->abs[CY_TCH_Y];
  699. }
  700. dev_vdbg(dev, "%s: flip=%s inv-x=%s inv-y=%s x=%04X(%d) y=%04X(%d)\n",
  701. __func__, flipped ? "true" : "false",
  702. md->pdata->flags & CY_FLAG_INV_X ? "true" : "false",
  703. md->pdata->flags & CY_FLAG_INV_Y ? "true" : "false",
  704. touch->abs[CY_TCH_X], touch->abs[CY_TCH_X],
  705. touch->abs[CY_TCH_Y], touch->abs[CY_TCH_Y]);
  706. }
  707. static void cyttsp4_final_sync(struct input_dev *input, int max_slots, int *ids)
  708. {
  709. int t;
  710. for (t = 0; t < max_slots; t++) {
  711. if (ids[t])
  712. continue;
  713. input_mt_slot(input, t);
  714. input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
  715. }
  716. input_sync(input);
  717. }
  718. static void cyttsp4_get_mt_touches(struct cyttsp4_mt_data *md, int num_cur_tch)
  719. {
  720. struct device *dev = &md->input->dev;
  721. struct cyttsp4_sysinfo *si = md->si;
  722. struct cyttsp4_touch tch;
  723. int sig;
  724. int i, j, t = 0;
  725. int ids[max(CY_TMA1036_MAX_TCH, CY_TMA4XX_MAX_TCH)];
  726. memset(ids, 0, si->si_ofs.tch_abs[CY_TCH_T].max * sizeof(int));
  727. for (i = 0; i < num_cur_tch; i++) {
  728. cyttsp4_get_touch(md, &tch, si->xy_data +
  729. (i * si->si_ofs.tch_rec_size));
  730. if ((tch.abs[CY_TCH_T] < md->pdata->frmwrk->abs
  731. [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + CY_MIN_OST]) ||
  732. (tch.abs[CY_TCH_T] > md->pdata->frmwrk->abs
  733. [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + CY_MAX_OST])) {
  734. dev_err(dev, "%s: tch=%d -> bad trk_id=%d max_id=%d\n",
  735. __func__, i, tch.abs[CY_TCH_T],
  736. md->pdata->frmwrk->abs[(CY_ABS_ID_OST *
  737. CY_NUM_ABS_SET) + CY_MAX_OST]);
  738. continue;
  739. }
  740. /* use 0 based track id's */
  741. sig = md->pdata->frmwrk->abs
  742. [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + 0];
  743. if (sig != CY_IGNORE_VALUE) {
  744. t = tch.abs[CY_TCH_T] - md->pdata->frmwrk->abs
  745. [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + CY_MIN_OST];
  746. if (tch.abs[CY_TCH_E] == CY_EV_LIFTOFF) {
  747. dev_dbg(dev, "%s: t=%d e=%d lift-off\n",
  748. __func__, t, tch.abs[CY_TCH_E]);
  749. goto cyttsp4_get_mt_touches_pr_tch;
  750. }
  751. input_mt_slot(md->input, t);
  752. input_mt_report_slot_state(md->input, MT_TOOL_FINGER,
  753. true);
  754. ids[t] = true;
  755. }
  756. /* all devices: position and pressure fields */
  757. for (j = 0; j <= CY_ABS_W_OST; j++) {
  758. sig = md->pdata->frmwrk->abs[((CY_ABS_X_OST + j) *
  759. CY_NUM_ABS_SET) + 0];
  760. if (sig != CY_IGNORE_VALUE)
  761. input_report_abs(md->input, sig,
  762. tch.abs[CY_TCH_X + j]);
  763. }
  764. if (si->si_ofs.tch_rec_size > CY_TMA1036_TCH_REC_SIZE) {
  765. /*
  766. * TMA400 size and orientation fields:
  767. * if pressure is non-zero and major touch
  768. * signal is zero, then set major and minor touch
  769. * signals to minimum non-zero value
  770. */
  771. if (tch.abs[CY_TCH_P] > 0 && tch.abs[CY_TCH_MAJ] == 0)
  772. tch.abs[CY_TCH_MAJ] = tch.abs[CY_TCH_MIN] = 1;
  773. /* Get the extended touch fields */
  774. for (j = 0; j < CY_NUM_EXT_TCH_FIELDS; j++) {
  775. sig = md->pdata->frmwrk->abs
  776. [((CY_ABS_MAJ_OST + j) *
  777. CY_NUM_ABS_SET) + 0];
  778. if (sig != CY_IGNORE_VALUE)
  779. input_report_abs(md->input, sig,
  780. tch.abs[CY_TCH_MAJ + j]);
  781. }
  782. }
  783. cyttsp4_get_mt_touches_pr_tch:
  784. if (si->si_ofs.tch_rec_size > CY_TMA1036_TCH_REC_SIZE)
  785. dev_dbg(dev,
  786. "%s: t=%d x=%d y=%d z=%d M=%d m=%d o=%d e=%d\n",
  787. __func__, t,
  788. tch.abs[CY_TCH_X],
  789. tch.abs[CY_TCH_Y],
  790. tch.abs[CY_TCH_P],
  791. tch.abs[CY_TCH_MAJ],
  792. tch.abs[CY_TCH_MIN],
  793. tch.abs[CY_TCH_OR],
  794. tch.abs[CY_TCH_E]);
  795. else
  796. dev_dbg(dev,
  797. "%s: t=%d x=%d y=%d z=%d e=%d\n", __func__,
  798. t,
  799. tch.abs[CY_TCH_X],
  800. tch.abs[CY_TCH_Y],
  801. tch.abs[CY_TCH_P],
  802. tch.abs[CY_TCH_E]);
  803. }
  804. cyttsp4_final_sync(md->input, si->si_ofs.tch_abs[CY_TCH_T].max, ids);
  805. md->num_prv_tch = num_cur_tch;
  806. return;
  807. }
  808. /* read xy_data for all current touches */
  809. static int cyttsp4_xy_worker(struct cyttsp4 *cd)
  810. {
  811. struct cyttsp4_mt_data *md = &cd->md;
  812. struct device *dev = &md->input->dev;
  813. struct cyttsp4_sysinfo *si = md->si;
  814. u8 num_cur_tch;
  815. u8 hst_mode;
  816. u8 rep_len;
  817. u8 rep_stat;
  818. u8 tt_stat;
  819. int rc = 0;
  820. /*
  821. * Get event data from cyttsp4 device.
  822. * The event data includes all data
  823. * for all active touches.
  824. * Event data also includes button data
  825. */
  826. /*
  827. * Use 2 reads:
  828. * 1st read to get mode + button bytes + touch count (core)
  829. * 2nd read (optional) to get touch 1 - touch n data
  830. */
  831. hst_mode = si->xy_mode[CY_REG_BASE];
  832. rep_len = si->xy_mode[si->si_ofs.rep_ofs];
  833. rep_stat = si->xy_mode[si->si_ofs.rep_ofs + 1];
  834. tt_stat = si->xy_mode[si->si_ofs.tt_stat_ofs];
  835. dev_vdbg(dev, "%s: %s%02X %s%d %s%02X %s%02X\n", __func__,
  836. "hst_mode=", hst_mode, "rep_len=", rep_len,
  837. "rep_stat=", rep_stat, "tt_stat=", tt_stat);
  838. num_cur_tch = GET_NUM_TOUCHES(tt_stat);
  839. dev_vdbg(dev, "%s: num_cur_tch=%d\n", __func__, num_cur_tch);
  840. if (rep_len == 0 && num_cur_tch > 0) {
  841. dev_err(dev, "%s: report length error rep_len=%d num_tch=%d\n",
  842. __func__, rep_len, num_cur_tch);
  843. goto cyttsp4_xy_worker_exit;
  844. }
  845. /* read touches */
  846. if (num_cur_tch > 0) {
  847. rc = cyttsp4_adap_read(cd, si->si_ofs.tt_stat_ofs + 1,
  848. num_cur_tch * si->si_ofs.tch_rec_size,
  849. si->xy_data);
  850. if (rc < 0) {
  851. dev_err(dev, "%s: read fail on touch regs r=%d\n",
  852. __func__, rc);
  853. goto cyttsp4_xy_worker_exit;
  854. }
  855. }
  856. /* print xy data */
  857. cyttsp4_pr_buf(dev, cd->pr_buf, si->xy_data, num_cur_tch *
  858. si->si_ofs.tch_rec_size, "xy_data");
  859. /* check any error conditions */
  860. if (IS_BAD_PKT(rep_stat)) {
  861. dev_dbg(dev, "%s: Invalid buffer detected\n", __func__);
  862. rc = 0;
  863. goto cyttsp4_xy_worker_exit;
  864. }
  865. if (IS_LARGE_AREA(tt_stat))
  866. dev_dbg(dev, "%s: Large area detected\n", __func__);
  867. if (num_cur_tch > si->si_ofs.max_tchs) {
  868. dev_err(dev, "%s: too many tch; set to max tch (n=%d c=%Zd)\n",
  869. __func__, num_cur_tch, si->si_ofs.max_tchs);
  870. num_cur_tch = si->si_ofs.max_tchs;
  871. }
  872. /* extract xy_data for all currently reported touches */
  873. dev_vdbg(dev, "%s: extract data num_cur_tch=%d\n", __func__,
  874. num_cur_tch);
  875. if (num_cur_tch)
  876. cyttsp4_get_mt_touches(md, num_cur_tch);
  877. else
  878. cyttsp4_lift_all(md);
  879. rc = 0;
  880. cyttsp4_xy_worker_exit:
  881. return rc;
  882. }
  883. static int cyttsp4_mt_attention(struct cyttsp4 *cd)
  884. {
  885. struct device *dev = cd->dev;
  886. struct cyttsp4_mt_data *md = &cd->md;
  887. int rc = 0;
  888. if (!md->si)
  889. return 0;
  890. mutex_lock(&md->report_lock);
  891. if (!md->is_suspended) {
  892. /* core handles handshake */
  893. rc = cyttsp4_xy_worker(cd);
  894. } else {
  895. dev_vdbg(dev, "%s: Ignoring report while suspended\n",
  896. __func__);
  897. }
  898. mutex_unlock(&md->report_lock);
  899. if (rc < 0)
  900. dev_err(dev, "%s: xy_worker error r=%d\n", __func__, rc);
  901. return rc;
  902. }
  903. static irqreturn_t cyttsp4_irq(int irq, void *handle)
  904. {
  905. struct cyttsp4 *cd = handle;
  906. struct device *dev = cd->dev;
  907. enum cyttsp4_mode cur_mode;
  908. u8 cmd_ofs = cd->sysinfo.si_ofs.cmd_ofs;
  909. u8 mode[3];
  910. int rc;
  911. /*
  912. * Check whether this IRQ should be ignored (external)
  913. * This should be the very first thing to check since
  914. * ignore_irq may be set for a very short period of time
  915. */
  916. if (atomic_read(&cd->ignore_irq)) {
  917. dev_vdbg(dev, "%s: Ignoring IRQ\n", __func__);
  918. return IRQ_HANDLED;
  919. }
  920. dev_dbg(dev, "%s int:0x%x\n", __func__, cd->int_status);
  921. mutex_lock(&cd->system_lock);
  922. /* Just to debug */
  923. if (cd->sleep_state == SS_SLEEP_ON || cd->sleep_state == SS_SLEEPING)
  924. dev_vdbg(dev, "%s: Received IRQ while in sleep\n", __func__);
  925. rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), mode);
  926. if (rc) {
  927. dev_err(cd->dev, "%s: Fail read adapter r=%d\n", __func__, rc);
  928. goto cyttsp4_irq_exit;
  929. }
  930. dev_vdbg(dev, "%s mode[0-2]:0x%X 0x%X 0x%X\n", __func__,
  931. mode[0], mode[1], mode[2]);
  932. if (IS_BOOTLOADER(mode[0], mode[1])) {
  933. cur_mode = CY_MODE_BOOTLOADER;
  934. dev_vdbg(dev, "%s: bl running\n", __func__);
  935. if (cd->mode == CY_MODE_BOOTLOADER) {
  936. /* Signal bootloader heartbeat heard */
  937. wake_up(&cd->wait_q);
  938. goto cyttsp4_irq_exit;
  939. }
  940. /* switch to bootloader */
  941. dev_dbg(dev, "%s: restart switch to bl m=%d -> m=%d\n",
  942. __func__, cd->mode, cur_mode);
  943. /* catch operation->bl glitch */
  944. if (cd->mode != CY_MODE_UNKNOWN) {
  945. /* Incase startup_state do not let startup_() */
  946. cd->mode = CY_MODE_UNKNOWN;
  947. cyttsp4_queue_startup_(cd);
  948. goto cyttsp4_irq_exit;
  949. }
  950. /*
  951. * do not wake thread on this switch since
  952. * it is possible to get an early heartbeat
  953. * prior to performing the reset
  954. */
  955. cd->mode = cur_mode;
  956. goto cyttsp4_irq_exit;
  957. }
  958. switch (mode[0] & CY_HST_MODE) {
  959. case CY_HST_OPERATE:
  960. cur_mode = CY_MODE_OPERATIONAL;
  961. dev_vdbg(dev, "%s: operational\n", __func__);
  962. break;
  963. case CY_HST_CAT:
  964. cur_mode = CY_MODE_CAT;
  965. dev_vdbg(dev, "%s: CaT\n", __func__);
  966. break;
  967. case CY_HST_SYSINFO:
  968. cur_mode = CY_MODE_SYSINFO;
  969. dev_vdbg(dev, "%s: sysinfo\n", __func__);
  970. break;
  971. default:
  972. cur_mode = CY_MODE_UNKNOWN;
  973. dev_err(dev, "%s: unknown HST mode 0x%02X\n", __func__,
  974. mode[0]);
  975. break;
  976. }
  977. /* Check whether this IRQ should be ignored (internal) */
  978. if (cd->int_status & CY_INT_IGNORE) {
  979. dev_vdbg(dev, "%s: Ignoring IRQ\n", __func__);
  980. goto cyttsp4_irq_exit;
  981. }
  982. /* Check for wake up interrupt */
  983. if (cd->int_status & CY_INT_AWAKE) {
  984. cd->int_status &= ~CY_INT_AWAKE;
  985. wake_up(&cd->wait_q);
  986. dev_vdbg(dev, "%s: Received wake up interrupt\n", __func__);
  987. goto cyttsp4_irq_handshake;
  988. }
  989. /* Expecting mode change interrupt */
  990. if ((cd->int_status & CY_INT_MODE_CHANGE)
  991. && (mode[0] & CY_HST_MODE_CHANGE) == 0) {
  992. cd->int_status &= ~CY_INT_MODE_CHANGE;
  993. dev_dbg(dev, "%s: finish mode switch m=%d -> m=%d\n",
  994. __func__, cd->mode, cur_mode);
  995. cd->mode = cur_mode;
  996. wake_up(&cd->wait_q);
  997. goto cyttsp4_irq_handshake;
  998. }
  999. /* compare current core mode to current device mode */
  1000. dev_vdbg(dev, "%s: cd->mode=%d cur_mode=%d\n",
  1001. __func__, cd->mode, cur_mode);
  1002. if ((mode[0] & CY_HST_MODE_CHANGE) == 0 && cd->mode != cur_mode) {
  1003. /* Unexpected mode change occurred */
  1004. dev_err(dev, "%s %d->%d 0x%x\n", __func__, cd->mode,
  1005. cur_mode, cd->int_status);
  1006. dev_dbg(dev, "%s: Unexpected mode change, startup\n",
  1007. __func__);
  1008. cyttsp4_queue_startup_(cd);
  1009. goto cyttsp4_irq_exit;
  1010. }
  1011. /* Expecting command complete interrupt */
  1012. dev_vdbg(dev, "%s: command byte:0x%x\n", __func__, mode[cmd_ofs]);
  1013. if ((cd->int_status & CY_INT_EXEC_CMD)
  1014. && mode[cmd_ofs] & CY_CMD_COMPLETE) {
  1015. cd->int_status &= ~CY_INT_EXEC_CMD;
  1016. dev_vdbg(dev, "%s: Received command complete interrupt\n",
  1017. __func__);
  1018. wake_up(&cd->wait_q);
  1019. /*
  1020. * It is possible to receive a single interrupt for
  1021. * command complete and touch/button status report.
  1022. * Continue processing for a possible status report.
  1023. */
  1024. }
  1025. /* This should be status report, read status regs */
  1026. if (cd->mode == CY_MODE_OPERATIONAL) {
  1027. dev_vdbg(dev, "%s: Read status registers\n", __func__);
  1028. rc = cyttsp4_load_status_regs(cd);
  1029. if (rc < 0)
  1030. dev_err(dev, "%s: fail read mode regs r=%d\n",
  1031. __func__, rc);
  1032. }
  1033. cyttsp4_mt_attention(cd);
  1034. cyttsp4_irq_handshake:
  1035. /* handshake the event */
  1036. dev_vdbg(dev, "%s: Handshake mode=0x%02X r=%d\n",
  1037. __func__, mode[0], rc);
  1038. rc = cyttsp4_handshake(cd, mode[0]);
  1039. if (rc < 0)
  1040. dev_err(dev, "%s: Fail handshake mode=0x%02X r=%d\n",
  1041. __func__, mode[0], rc);
  1042. /*
  1043. * a non-zero udelay period is required for using
  1044. * IRQF_TRIGGER_LOW in order to delay until the
  1045. * device completes isr deassert
  1046. */
  1047. udelay(cd->cpdata->level_irq_udelay);
  1048. cyttsp4_irq_exit:
  1049. mutex_unlock(&cd->system_lock);
  1050. return IRQ_HANDLED;
  1051. }
  1052. static void cyttsp4_start_wd_timer(struct cyttsp4 *cd)
  1053. {
  1054. if (!CY_WATCHDOG_TIMEOUT)
  1055. return;
  1056. mod_timer(&cd->watchdog_timer, jiffies +
  1057. msecs_to_jiffies(CY_WATCHDOG_TIMEOUT));
  1058. }
  1059. static void cyttsp4_stop_wd_timer(struct cyttsp4 *cd)
  1060. {
  1061. if (!CY_WATCHDOG_TIMEOUT)
  1062. return;
  1063. /*
  1064. * Ensure we wait until the watchdog timer
  1065. * running on a different CPU finishes
  1066. */
  1067. del_timer_sync(&cd->watchdog_timer);
  1068. cancel_work_sync(&cd->watchdog_work);
  1069. del_timer_sync(&cd->watchdog_timer);
  1070. }
  1071. static void cyttsp4_watchdog_timer(unsigned long handle)
  1072. {
  1073. struct cyttsp4 *cd = (struct cyttsp4 *)handle;
  1074. dev_vdbg(cd->dev, "%s: Watchdog timer triggered\n", __func__);
  1075. if (!work_pending(&cd->watchdog_work))
  1076. schedule_work(&cd->watchdog_work);
  1077. return;
  1078. }
  1079. static int cyttsp4_request_exclusive(struct cyttsp4 *cd, void *ownptr,
  1080. int timeout_ms)
  1081. {
  1082. int t = msecs_to_jiffies(timeout_ms);
  1083. bool with_timeout = (timeout_ms != 0);
  1084. mutex_lock(&cd->system_lock);
  1085. if (!cd->exclusive_dev && cd->exclusive_waits == 0) {
  1086. cd->exclusive_dev = ownptr;
  1087. goto exit;
  1088. }
  1089. cd->exclusive_waits++;
  1090. wait:
  1091. mutex_unlock(&cd->system_lock);
  1092. if (with_timeout) {
  1093. t = wait_event_timeout(cd->wait_q, !cd->exclusive_dev, t);
  1094. if (IS_TMO(t)) {
  1095. dev_err(cd->dev, "%s: tmo waiting exclusive access\n",
  1096. __func__);
  1097. mutex_lock(&cd->system_lock);
  1098. cd->exclusive_waits--;
  1099. mutex_unlock(&cd->system_lock);
  1100. return -ETIME;
  1101. }
  1102. } else {
  1103. wait_event(cd->wait_q, !cd->exclusive_dev);
  1104. }
  1105. mutex_lock(&cd->system_lock);
  1106. if (cd->exclusive_dev)
  1107. goto wait;
  1108. cd->exclusive_dev = ownptr;
  1109. cd->exclusive_waits--;
  1110. exit:
  1111. mutex_unlock(&cd->system_lock);
  1112. return 0;
  1113. }
  1114. /*
  1115. * returns error if was not owned
  1116. */
  1117. static int cyttsp4_release_exclusive(struct cyttsp4 *cd, void *ownptr)
  1118. {
  1119. mutex_lock(&cd->system_lock);
  1120. if (cd->exclusive_dev != ownptr) {
  1121. mutex_unlock(&cd->system_lock);
  1122. return -EINVAL;
  1123. }
  1124. dev_vdbg(cd->dev, "%s: exclusive_dev %p freed\n",
  1125. __func__, cd->exclusive_dev);
  1126. cd->exclusive_dev = NULL;
  1127. wake_up(&cd->wait_q);
  1128. mutex_unlock(&cd->system_lock);
  1129. return 0;
  1130. }
  1131. static int cyttsp4_wait_bl_heartbeat(struct cyttsp4 *cd)
  1132. {
  1133. long t;
  1134. int rc = 0;
  1135. /* wait heartbeat */
  1136. dev_vdbg(cd->dev, "%s: wait heartbeat...\n", __func__);
  1137. t = wait_event_timeout(cd->wait_q, cd->mode == CY_MODE_BOOTLOADER,
  1138. msecs_to_jiffies(CY_CORE_RESET_AND_WAIT_TIMEOUT));
  1139. if (IS_TMO(t)) {
  1140. dev_err(cd->dev, "%s: tmo waiting bl heartbeat cd->mode=%d\n",
  1141. __func__, cd->mode);
  1142. rc = -ETIME;
  1143. }
  1144. return rc;
  1145. }
  1146. static int cyttsp4_wait_sysinfo_mode(struct cyttsp4 *cd)
  1147. {
  1148. long t;
  1149. dev_vdbg(cd->dev, "%s: wait sysinfo...\n", __func__);
  1150. t = wait_event_timeout(cd->wait_q, cd->mode == CY_MODE_SYSINFO,
  1151. msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT));
  1152. if (IS_TMO(t)) {
  1153. dev_err(cd->dev, "%s: tmo waiting exit bl cd->mode=%d\n",
  1154. __func__, cd->mode);
  1155. mutex_lock(&cd->system_lock);
  1156. cd->int_status &= ~CY_INT_MODE_CHANGE;
  1157. mutex_unlock(&cd->system_lock);
  1158. return -ETIME;
  1159. }
  1160. return 0;
  1161. }
  1162. static int cyttsp4_reset_and_wait(struct cyttsp4 *cd)
  1163. {
  1164. int rc;
  1165. /* reset hardware */
  1166. mutex_lock(&cd->system_lock);
  1167. dev_dbg(cd->dev, "%s: reset hw...\n", __func__);
  1168. rc = cyttsp4_hw_reset(cd);
  1169. cd->mode = CY_MODE_UNKNOWN;
  1170. mutex_unlock(&cd->system_lock);
  1171. if (rc < 0) {
  1172. dev_err(cd->dev, "%s:Fail hw reset r=%d\n", __func__, rc);
  1173. return rc;
  1174. }
  1175. return cyttsp4_wait_bl_heartbeat(cd);
  1176. }
  1177. /*
  1178. * returns err if refused or timeout; block until mode change complete
  1179. * bit is set (mode change interrupt)
  1180. */
  1181. static int cyttsp4_set_mode(struct cyttsp4 *cd, int new_mode)
  1182. {
  1183. u8 new_dev_mode;
  1184. u8 mode;
  1185. long t;
  1186. int rc;
  1187. switch (new_mode) {
  1188. case CY_MODE_OPERATIONAL:
  1189. new_dev_mode = CY_HST_OPERATE;
  1190. break;
  1191. case CY_MODE_SYSINFO:
  1192. new_dev_mode = CY_HST_SYSINFO;
  1193. break;
  1194. case CY_MODE_CAT:
  1195. new_dev_mode = CY_HST_CAT;
  1196. break;
  1197. default:
  1198. dev_err(cd->dev, "%s: invalid mode: %02X(%d)\n",
  1199. __func__, new_mode, new_mode);
  1200. return -EINVAL;
  1201. }
  1202. /* change mode */
  1203. dev_dbg(cd->dev, "%s: %s=%p new_dev_mode=%02X new_mode=%d\n",
  1204. __func__, "have exclusive", cd->exclusive_dev,
  1205. new_dev_mode, new_mode);
  1206. mutex_lock(&cd->system_lock);
  1207. rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), &mode);
  1208. if (rc < 0) {
  1209. mutex_unlock(&cd->system_lock);
  1210. dev_err(cd->dev, "%s: Fail read mode r=%d\n",
  1211. __func__, rc);
  1212. goto exit;
  1213. }
  1214. /* Clear device mode bits and set to new mode */
  1215. mode &= ~CY_HST_MODE;
  1216. mode |= new_dev_mode | CY_HST_MODE_CHANGE;
  1217. cd->int_status |= CY_INT_MODE_CHANGE;
  1218. rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(mode), &mode);
  1219. mutex_unlock(&cd->system_lock);
  1220. if (rc < 0) {
  1221. dev_err(cd->dev, "%s: Fail write mode change r=%d\n",
  1222. __func__, rc);
  1223. goto exit;
  1224. }
  1225. /* wait for mode change done interrupt */
  1226. t = wait_event_timeout(cd->wait_q,
  1227. (cd->int_status & CY_INT_MODE_CHANGE) == 0,
  1228. msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT));
  1229. dev_dbg(cd->dev, "%s: back from wait t=%ld cd->mode=%d\n",
  1230. __func__, t, cd->mode);
  1231. if (IS_TMO(t)) {
  1232. dev_err(cd->dev, "%s: %s\n", __func__,
  1233. "tmo waiting mode change");
  1234. mutex_lock(&cd->system_lock);
  1235. cd->int_status &= ~CY_INT_MODE_CHANGE;
  1236. mutex_unlock(&cd->system_lock);
  1237. rc = -EINVAL;
  1238. }
  1239. exit:
  1240. return rc;
  1241. }
  1242. static void cyttsp4_watchdog_work(struct work_struct *work)
  1243. {
  1244. struct cyttsp4 *cd =
  1245. container_of(work, struct cyttsp4, watchdog_work);
  1246. u8 *mode;
  1247. int retval;
  1248. mutex_lock(&cd->system_lock);
  1249. retval = cyttsp4_load_status_regs(cd);
  1250. if (retval < 0) {
  1251. dev_err(cd->dev,
  1252. "%s: failed to access device in watchdog timer r=%d\n",
  1253. __func__, retval);
  1254. cyttsp4_queue_startup_(cd);
  1255. goto cyttsp4_timer_watchdog_exit_error;
  1256. }
  1257. mode = &cd->sysinfo.xy_mode[CY_REG_BASE];
  1258. if (IS_BOOTLOADER(mode[0], mode[1])) {
  1259. dev_err(cd->dev,
  1260. "%s: device found in bootloader mode when operational mode\n",
  1261. __func__);
  1262. cyttsp4_queue_startup_(cd);
  1263. goto cyttsp4_timer_watchdog_exit_error;
  1264. }
  1265. cyttsp4_start_wd_timer(cd);
  1266. cyttsp4_timer_watchdog_exit_error:
  1267. mutex_unlock(&cd->system_lock);
  1268. return;
  1269. }
  1270. static int cyttsp4_core_sleep_(struct cyttsp4 *cd)
  1271. {
  1272. enum cyttsp4_sleep_state ss = SS_SLEEP_ON;
  1273. enum cyttsp4_int_state int_status = CY_INT_IGNORE;
  1274. int rc = 0;
  1275. u8 mode[2];
  1276. /* Already in sleep mode? */
  1277. mutex_lock(&cd->system_lock);
  1278. if (cd->sleep_state == SS_SLEEP_ON) {
  1279. mutex_unlock(&cd->system_lock);
  1280. return 0;
  1281. }
  1282. cd->sleep_state = SS_SLEEPING;
  1283. mutex_unlock(&cd->system_lock);
  1284. cyttsp4_stop_wd_timer(cd);
  1285. /* Wait until currently running IRQ handler exits and disable IRQ */
  1286. disable_irq(cd->irq);
  1287. dev_vdbg(cd->dev, "%s: write DEEP SLEEP...\n", __func__);
  1288. mutex_lock(&cd->system_lock);
  1289. rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), &mode);
  1290. if (rc) {
  1291. mutex_unlock(&cd->system_lock);
  1292. dev_err(cd->dev, "%s: Fail read adapter r=%d\n", __func__, rc);
  1293. goto error;
  1294. }
  1295. if (IS_BOOTLOADER(mode[0], mode[1])) {
  1296. mutex_unlock(&cd->system_lock);
  1297. dev_err(cd->dev, "%s: Device in BOOTLADER mode.\n", __func__);
  1298. rc = -EINVAL;
  1299. goto error;
  1300. }
  1301. mode[0] |= CY_HST_SLEEP;
  1302. rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(mode[0]), &mode[0]);
  1303. mutex_unlock(&cd->system_lock);
  1304. if (rc) {
  1305. dev_err(cd->dev, "%s: Fail write adapter r=%d\n", __func__, rc);
  1306. goto error;
  1307. }
  1308. dev_vdbg(cd->dev, "%s: write DEEP SLEEP succeeded\n", __func__);
  1309. if (cd->cpdata->power) {
  1310. dev_dbg(cd->dev, "%s: Power down HW\n", __func__);
  1311. rc = cd->cpdata->power(cd->cpdata, 0, cd->dev, &cd->ignore_irq);
  1312. } else {
  1313. dev_dbg(cd->dev, "%s: No power function\n", __func__);
  1314. rc = 0;
  1315. }
  1316. if (rc < 0) {
  1317. dev_err(cd->dev, "%s: HW Power down fails r=%d\n",
  1318. __func__, rc);
  1319. goto error;
  1320. }
  1321. /* Give time to FW to sleep */
  1322. msleep(50);
  1323. goto exit;
  1324. error:
  1325. ss = SS_SLEEP_OFF;
  1326. int_status = CY_INT_NONE;
  1327. cyttsp4_start_wd_timer(cd);
  1328. exit:
  1329. mutex_lock(&cd->system_lock);
  1330. cd->sleep_state = ss;
  1331. cd->int_status |= int_status;
  1332. mutex_unlock(&cd->system_lock);
  1333. enable_irq(cd->irq);
  1334. return rc;
  1335. }
  1336. static int cyttsp4_startup_(struct cyttsp4 *cd)
  1337. {
  1338. int retry = CY_CORE_STARTUP_RETRY_COUNT;
  1339. int rc;
  1340. cyttsp4_stop_wd_timer(cd);
  1341. reset:
  1342. if (retry != CY_CORE_STARTUP_RETRY_COUNT)
  1343. dev_dbg(cd->dev, "%s: Retry %d\n", __func__,
  1344. CY_CORE_STARTUP_RETRY_COUNT - retry);
  1345. /* reset hardware and wait for heartbeat */
  1346. rc = cyttsp4_reset_and_wait(cd);
  1347. if (rc < 0) {
  1348. dev_err(cd->dev, "%s: Error on h/w reset r=%d\n", __func__, rc);
  1349. if (retry--)
  1350. goto reset;
  1351. goto exit;
  1352. }
  1353. /* exit bl into sysinfo mode */
  1354. dev_vdbg(cd->dev, "%s: write exit ldr...\n", __func__);
  1355. mutex_lock(&cd->system_lock);
  1356. cd->int_status &= ~CY_INT_IGNORE;
  1357. cd->int_status |= CY_INT_MODE_CHANGE;
  1358. rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(ldr_exit),
  1359. (u8 *)ldr_exit);
  1360. mutex_unlock(&cd->system_lock);
  1361. if (rc < 0) {
  1362. dev_err(cd->dev, "%s: Fail write r=%d\n", __func__, rc);
  1363. if (retry--)
  1364. goto reset;
  1365. goto exit;
  1366. }
  1367. rc = cyttsp4_wait_sysinfo_mode(cd);
  1368. if (rc < 0) {
  1369. u8 buf[sizeof(ldr_err_app)];
  1370. int rc1;
  1371. /* Check for invalid/corrupted touch application */
  1372. rc1 = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(ldr_err_app),
  1373. buf);
  1374. if (rc1) {
  1375. dev_err(cd->dev, "%s: Fail read r=%d\n", __func__, rc1);
  1376. } else if (!memcmp(buf, ldr_err_app, sizeof(ldr_err_app))) {
  1377. dev_err(cd->dev, "%s: Error launching touch application\n",
  1378. __func__);
  1379. mutex_lock(&cd->system_lock);
  1380. cd->invalid_touch_app = true;
  1381. mutex_unlock(&cd->system_lock);
  1382. goto exit_no_wd;
  1383. }
  1384. if (retry--)
  1385. goto reset;
  1386. goto exit;
  1387. }
  1388. mutex_lock(&cd->system_lock);
  1389. cd->invalid_touch_app = false;
  1390. mutex_unlock(&cd->system_lock);
  1391. /* read sysinfo data */
  1392. dev_vdbg(cd->dev, "%s: get sysinfo regs..\n", __func__);
  1393. rc = cyttsp4_get_sysinfo_regs(cd);
  1394. if (rc < 0) {
  1395. dev_err(cd->dev, "%s: failed to get sysinfo regs rc=%d\n",
  1396. __func__, rc);
  1397. if (retry--)
  1398. goto reset;
  1399. goto exit;
  1400. }
  1401. rc = cyttsp4_set_mode(cd, CY_MODE_OPERATIONAL);
  1402. if (rc < 0) {
  1403. dev_err(cd->dev, "%s: failed to set mode to operational rc=%d\n",
  1404. __func__, rc);
  1405. if (retry--)
  1406. goto reset;
  1407. goto exit;
  1408. }
  1409. cyttsp4_lift_all(&cd->md);
  1410. /* restore to sleep if was suspended */
  1411. mutex_lock(&cd->system_lock);
  1412. if (cd->sleep_state == SS_SLEEP_ON) {
  1413. cd->sleep_state = SS_SLEEP_OFF;
  1414. mutex_unlock(&cd->system_lock);
  1415. cyttsp4_core_sleep_(cd);
  1416. goto exit_no_wd;
  1417. }
  1418. mutex_unlock(&cd->system_lock);
  1419. exit:
  1420. cyttsp4_start_wd_timer(cd);
  1421. exit_no_wd:
  1422. return rc;
  1423. }
  1424. static int cyttsp4_startup(struct cyttsp4 *cd)
  1425. {
  1426. int rc;
  1427. mutex_lock(&cd->system_lock);
  1428. cd->startup_state = STARTUP_RUNNING;
  1429. mutex_unlock(&cd->system_lock);
  1430. rc = cyttsp4_request_exclusive(cd, cd->dev,
  1431. CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT);
  1432. if (rc < 0) {
  1433. dev_err(cd->dev, "%s: fail get exclusive ex=%p own=%p\n",
  1434. __func__, cd->exclusive_dev, cd->dev);
  1435. goto exit;
  1436. }
  1437. rc = cyttsp4_startup_(cd);
  1438. if (cyttsp4_release_exclusive(cd, cd->dev) < 0)
  1439. /* Don't return fail code, mode is already changed. */
  1440. dev_err(cd->dev, "%s: fail to release exclusive\n", __func__);
  1441. else
  1442. dev_vdbg(cd->dev, "%s: pass release exclusive\n", __func__);
  1443. exit:
  1444. mutex_lock(&cd->system_lock);
  1445. cd->startup_state = STARTUP_NONE;
  1446. mutex_unlock(&cd->system_lock);
  1447. /* Wake the waiters for end of startup */
  1448. wake_up(&cd->wait_q);
  1449. return rc;
  1450. }
  1451. static void cyttsp4_startup_work_function(struct work_struct *work)
  1452. {
  1453. struct cyttsp4 *cd = container_of(work, struct cyttsp4, startup_work);
  1454. int rc;
  1455. rc = cyttsp4_startup(cd);
  1456. if (rc < 0)
  1457. dev_err(cd->dev, "%s: Fail queued startup r=%d\n",
  1458. __func__, rc);
  1459. }
  1460. static void cyttsp4_free_si_ptrs(struct cyttsp4 *cd)
  1461. {
  1462. struct cyttsp4_sysinfo *si = &cd->sysinfo;
  1463. if (!si)
  1464. return;
  1465. kfree(si->si_ptrs.cydata);
  1466. kfree(si->si_ptrs.test);
  1467. kfree(si->si_ptrs.pcfg);
  1468. kfree(si->si_ptrs.opcfg);
  1469. kfree(si->si_ptrs.ddata);
  1470. kfree(si->si_ptrs.mdata);
  1471. kfree(si->btn);
  1472. kfree(si->xy_mode);
  1473. kfree(si->xy_data);
  1474. kfree(si->btn_rec_data);
  1475. }
  1476. #if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_RUNTIME)
  1477. static int cyttsp4_core_sleep(struct cyttsp4 *cd)
  1478. {
  1479. int rc;
  1480. rc = cyttsp4_request_exclusive(cd, cd->dev,
  1481. CY_CORE_SLEEP_REQUEST_EXCLUSIVE_TIMEOUT);
  1482. if (rc < 0) {
  1483. dev_err(cd->dev, "%s: fail get exclusive ex=%p own=%p\n",
  1484. __func__, cd->exclusive_dev, cd->dev);
  1485. return 0;
  1486. }
  1487. rc = cyttsp4_core_sleep_(cd);
  1488. if (cyttsp4_release_exclusive(cd, cd->dev) < 0)
  1489. dev_err(cd->dev, "%s: fail to release exclusive\n", __func__);
  1490. else
  1491. dev_vdbg(cd->dev, "%s: pass release exclusive\n", __func__);
  1492. return rc;
  1493. }
  1494. static int cyttsp4_core_wake_(struct cyttsp4 *cd)
  1495. {
  1496. struct device *dev = cd->dev;
  1497. int rc;
  1498. u8 mode;
  1499. int t;
  1500. /* Already woken? */
  1501. mutex_lock(&cd->system_lock);
  1502. if (cd->sleep_state == SS_SLEEP_OFF) {
  1503. mutex_unlock(&cd->system_lock);
  1504. return 0;
  1505. }
  1506. cd->int_status &= ~CY_INT_IGNORE;
  1507. cd->int_status |= CY_INT_AWAKE;
  1508. cd->sleep_state = SS_WAKING;
  1509. if (cd->cpdata->power) {
  1510. dev_dbg(dev, "%s: Power up HW\n", __func__);
  1511. rc = cd->cpdata->power(cd->cpdata, 1, dev, &cd->ignore_irq);
  1512. } else {
  1513. dev_dbg(dev, "%s: No power function\n", __func__);
  1514. rc = -ENOSYS;
  1515. }
  1516. if (rc < 0) {
  1517. dev_err(dev, "%s: HW Power up fails r=%d\n",
  1518. __func__, rc);
  1519. /* Initiate a read transaction to wake up */
  1520. cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), &mode);
  1521. } else
  1522. dev_vdbg(cd->dev, "%s: HW power up succeeds\n",
  1523. __func__);
  1524. mutex_unlock(&cd->system_lock);
  1525. t = wait_event_timeout(cd->wait_q,
  1526. (cd->int_status & CY_INT_AWAKE) == 0,
  1527. msecs_to_jiffies(CY_CORE_WAKEUP_TIMEOUT));
  1528. if (IS_TMO(t)) {
  1529. dev_err(dev, "%s: TMO waiting for wakeup\n", __func__);
  1530. mutex_lock(&cd->system_lock);
  1531. cd->int_status &= ~CY_INT_AWAKE;
  1532. /* Try starting up */
  1533. cyttsp4_queue_startup_(cd);
  1534. mutex_unlock(&cd->system_lock);
  1535. }
  1536. mutex_lock(&cd->system_lock);
  1537. cd->sleep_state = SS_SLEEP_OFF;
  1538. mutex_unlock(&cd->system_lock);
  1539. cyttsp4_start_wd_timer(cd);
  1540. return 0;
  1541. }
  1542. static int cyttsp4_core_wake(struct cyttsp4 *cd)
  1543. {
  1544. int rc;
  1545. rc = cyttsp4_request_exclusive(cd, cd->dev,
  1546. CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT);
  1547. if (rc < 0) {
  1548. dev_err(cd->dev, "%s: fail get exclusive ex=%p own=%p\n",
  1549. __func__, cd->exclusive_dev, cd->dev);
  1550. return 0;
  1551. }
  1552. rc = cyttsp4_core_wake_(cd);
  1553. if (cyttsp4_release_exclusive(cd, cd->dev) < 0)
  1554. dev_err(cd->dev, "%s: fail to release exclusive\n", __func__);
  1555. else
  1556. dev_vdbg(cd->dev, "%s: pass release exclusive\n", __func__);
  1557. return rc;
  1558. }
  1559. static int cyttsp4_core_suspend(struct device *dev)
  1560. {
  1561. struct cyttsp4 *cd = dev_get_drvdata(dev);
  1562. struct cyttsp4_mt_data *md = &cd->md;
  1563. int rc;
  1564. md->is_suspended = true;
  1565. rc = cyttsp4_core_sleep(cd);
  1566. if (rc < 0) {
  1567. dev_err(dev, "%s: Error on sleep\n", __func__);
  1568. return -EAGAIN;
  1569. }
  1570. return 0;
  1571. }
  1572. static int cyttsp4_core_resume(struct device *dev)
  1573. {
  1574. struct cyttsp4 *cd = dev_get_drvdata(dev);
  1575. struct cyttsp4_mt_data *md = &cd->md;
  1576. int rc;
  1577. md->is_suspended = false;
  1578. rc = cyttsp4_core_wake(cd);
  1579. if (rc < 0) {
  1580. dev_err(dev, "%s: Error on wake\n", __func__);
  1581. return -EAGAIN;
  1582. }
  1583. return 0;
  1584. }
  1585. #endif
  1586. const struct dev_pm_ops cyttsp4_pm_ops = {
  1587. SET_SYSTEM_SLEEP_PM_OPS(cyttsp4_core_suspend, cyttsp4_core_resume)
  1588. SET_RUNTIME_PM_OPS(cyttsp4_core_suspend, cyttsp4_core_resume, NULL)
  1589. };
  1590. EXPORT_SYMBOL_GPL(cyttsp4_pm_ops);
  1591. static int cyttsp4_mt_open(struct input_dev *input)
  1592. {
  1593. pm_runtime_get(input->dev.parent);
  1594. return 0;
  1595. }
  1596. static void cyttsp4_mt_close(struct input_dev *input)
  1597. {
  1598. struct cyttsp4_mt_data *md = input_get_drvdata(input);
  1599. mutex_lock(&md->report_lock);
  1600. if (!md->is_suspended)
  1601. pm_runtime_put(input->dev.parent);
  1602. mutex_unlock(&md->report_lock);
  1603. }
  1604. static int cyttsp4_setup_input_device(struct cyttsp4 *cd)
  1605. {
  1606. struct device *dev = cd->dev;
  1607. struct cyttsp4_mt_data *md = &cd->md;
  1608. int signal = CY_IGNORE_VALUE;
  1609. int max_x, max_y, max_p, min, max;
  1610. int max_x_tmp, max_y_tmp;
  1611. int i;
  1612. int rc;
  1613. dev_vdbg(dev, "%s: Initialize event signals\n", __func__);
  1614. __set_bit(EV_ABS, md->input->evbit);
  1615. __set_bit(EV_REL, md->input->evbit);
  1616. __set_bit(EV_KEY, md->input->evbit);
  1617. max_x_tmp = md->si->si_ofs.max_x;
  1618. max_y_tmp = md->si->si_ofs.max_y;
  1619. /* get maximum values from the sysinfo data */
  1620. if (md->pdata->flags & CY_FLAG_FLIP) {
  1621. max_x = max_y_tmp - 1;
  1622. max_y = max_x_tmp - 1;
  1623. } else {
  1624. max_x = max_x_tmp - 1;
  1625. max_y = max_y_tmp - 1;
  1626. }
  1627. max_p = md->si->si_ofs.max_p;
  1628. /* set event signal capabilities */
  1629. for (i = 0; i < (md->pdata->frmwrk->size / CY_NUM_ABS_SET); i++) {
  1630. signal = md->pdata->frmwrk->abs
  1631. [(i * CY_NUM_ABS_SET) + CY_SIGNAL_OST];
  1632. if (signal != CY_IGNORE_VALUE) {
  1633. __set_bit(signal, md->input->absbit);
  1634. min = md->pdata->frmwrk->abs
  1635. [(i * CY_NUM_ABS_SET) + CY_MIN_OST];
  1636. max = md->pdata->frmwrk->abs
  1637. [(i * CY_NUM_ABS_SET) + CY_MAX_OST];
  1638. if (i == CY_ABS_ID_OST) {
  1639. /* shift track ids down to start at 0 */
  1640. max = max - min;
  1641. min = min - min;
  1642. } else if (i == CY_ABS_X_OST)
  1643. max = max_x;
  1644. else if (i == CY_ABS_Y_OST)
  1645. max = max_y;
  1646. else if (i == CY_ABS_P_OST)
  1647. max = max_p;
  1648. input_set_abs_params(md->input, signal, min, max,
  1649. md->pdata->frmwrk->abs
  1650. [(i * CY_NUM_ABS_SET) + CY_FUZZ_OST],
  1651. md->pdata->frmwrk->abs
  1652. [(i * CY_NUM_ABS_SET) + CY_FLAT_OST]);
  1653. dev_dbg(dev, "%s: register signal=%02X min=%d max=%d\n",
  1654. __func__, signal, min, max);
  1655. if ((i == CY_ABS_ID_OST) &&
  1656. (md->si->si_ofs.tch_rec_size <
  1657. CY_TMA4XX_TCH_REC_SIZE))
  1658. break;
  1659. }
  1660. }
  1661. input_mt_init_slots(md->input, md->si->si_ofs.tch_abs[CY_TCH_T].max,
  1662. INPUT_MT_DIRECT);
  1663. rc = input_register_device(md->input);
  1664. if (rc < 0)
  1665. dev_err(dev, "%s: Error, failed register input device r=%d\n",
  1666. __func__, rc);
  1667. return rc;
  1668. }
  1669. static int cyttsp4_mt_probe(struct cyttsp4 *cd)
  1670. {
  1671. struct device *dev = cd->dev;
  1672. struct cyttsp4_mt_data *md = &cd->md;
  1673. struct cyttsp4_mt_platform_data *pdata = cd->pdata->mt_pdata;
  1674. int rc = 0;
  1675. mutex_init(&md->report_lock);
  1676. md->pdata = pdata;
  1677. /* Create the input device and register it. */
  1678. dev_vdbg(dev, "%s: Create the input device and register it\n",
  1679. __func__);
  1680. md->input = input_allocate_device();
  1681. if (md->input == NULL) {
  1682. dev_err(dev, "%s: Error, failed to allocate input device\n",
  1683. __func__);
  1684. rc = -ENOSYS;
  1685. goto error_alloc_failed;
  1686. }
  1687. md->input->name = pdata->inp_dev_name;
  1688. scnprintf(md->phys, sizeof(md->phys)-1, "%s", dev_name(dev));
  1689. md->input->phys = md->phys;
  1690. md->input->id.bustype = cd->bus_ops->bustype;
  1691. md->input->dev.parent = dev;
  1692. md->input->open = cyttsp4_mt_open;
  1693. md->input->close = cyttsp4_mt_close;
  1694. input_set_drvdata(md->input, md);
  1695. /* get sysinfo */
  1696. md->si = &cd->sysinfo;
  1697. if (!md->si) {
  1698. dev_err(dev, "%s: Fail get sysinfo pointer from core p=%p\n",
  1699. __func__, md->si);
  1700. goto error_get_sysinfo;
  1701. }
  1702. rc = cyttsp4_setup_input_device(cd);
  1703. if (rc)
  1704. goto error_init_input;
  1705. return 0;
  1706. error_init_input:
  1707. input_free_device(md->input);
  1708. error_get_sysinfo:
  1709. input_set_drvdata(md->input, NULL);
  1710. error_alloc_failed:
  1711. dev_err(dev, "%s failed.\n", __func__);
  1712. return rc;
  1713. }
  1714. struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops,
  1715. struct device *dev, u16 irq, size_t xfer_buf_size)
  1716. {
  1717. struct cyttsp4 *cd;
  1718. struct cyttsp4_platform_data *pdata = dev_get_platdata(dev);
  1719. unsigned long irq_flags;
  1720. int rc = 0;
  1721. if (!pdata || !pdata->core_pdata || !pdata->mt_pdata) {
  1722. dev_err(dev, "%s: Missing platform data\n", __func__);
  1723. rc = -ENODEV;
  1724. goto error_no_pdata;
  1725. }
  1726. cd = kzalloc(sizeof(*cd), GFP_KERNEL);
  1727. if (!cd) {
  1728. dev_err(dev, "%s: Error, kzalloc\n", __func__);
  1729. rc = -ENOMEM;
  1730. goto error_alloc_data;
  1731. }
  1732. cd->xfer_buf = kzalloc(xfer_buf_size, GFP_KERNEL);
  1733. if (!cd->xfer_buf) {
  1734. dev_err(dev, "%s: Error, kzalloc\n", __func__);
  1735. rc = -ENOMEM;
  1736. goto error_free_cd;
  1737. }
  1738. /* Initialize device info */
  1739. cd->dev = dev;
  1740. cd->pdata = pdata;
  1741. cd->cpdata = pdata->core_pdata;
  1742. cd->bus_ops = ops;
  1743. /* Initialize mutexes and spinlocks */
  1744. mutex_init(&cd->system_lock);
  1745. mutex_init(&cd->adap_lock);
  1746. /* Initialize wait queue */
  1747. init_waitqueue_head(&cd->wait_q);
  1748. /* Initialize works */
  1749. INIT_WORK(&cd->startup_work, cyttsp4_startup_work_function);
  1750. INIT_WORK(&cd->watchdog_work, cyttsp4_watchdog_work);
  1751. /* Initialize IRQ */
  1752. cd->irq = gpio_to_irq(cd->cpdata->irq_gpio);
  1753. if (cd->irq < 0) {
  1754. rc = -EINVAL;
  1755. goto error_free_xfer;
  1756. }
  1757. dev_set_drvdata(dev, cd);
  1758. /* Call platform init function */
  1759. if (cd->cpdata->init) {
  1760. dev_dbg(cd->dev, "%s: Init HW\n", __func__);
  1761. rc = cd->cpdata->init(cd->cpdata, 1, cd->dev);
  1762. } else {
  1763. dev_dbg(cd->dev, "%s: No HW INIT function\n", __func__);
  1764. rc = 0;
  1765. }
  1766. if (rc < 0)
  1767. dev_err(cd->dev, "%s: HW Init fail r=%d\n", __func__, rc);
  1768. dev_dbg(dev, "%s: initialize threaded irq=%d\n", __func__, cd->irq);
  1769. if (cd->cpdata->level_irq_udelay > 0)
  1770. /* use level triggered interrupts */
  1771. irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT;
  1772. else
  1773. /* use edge triggered interrupts */
  1774. irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  1775. rc = request_threaded_irq(cd->irq, NULL, cyttsp4_irq, irq_flags,
  1776. dev_name(dev), cd);
  1777. if (rc < 0) {
  1778. dev_err(dev, "%s: Error, could not request irq\n", __func__);
  1779. goto error_request_irq;
  1780. }
  1781. /* Setup watchdog timer */
  1782. setup_timer(&cd->watchdog_timer, cyttsp4_watchdog_timer,
  1783. (unsigned long)cd);
  1784. /*
  1785. * call startup directly to ensure that the device
  1786. * is tested before leaving the probe
  1787. */
  1788. rc = cyttsp4_startup(cd);
  1789. /* Do not fail probe if startup fails but the device is detected */
  1790. if (rc < 0 && cd->mode == CY_MODE_UNKNOWN) {
  1791. dev_err(cd->dev, "%s: Fail initial startup r=%d\n",
  1792. __func__, rc);
  1793. goto error_startup;
  1794. }
  1795. rc = cyttsp4_mt_probe(cd);
  1796. if (rc < 0) {
  1797. dev_err(dev, "%s: Error, fail mt probe\n", __func__);
  1798. goto error_startup;
  1799. }
  1800. pm_runtime_enable(dev);
  1801. return cd;
  1802. error_startup:
  1803. cancel_work_sync(&cd->startup_work);
  1804. cyttsp4_stop_wd_timer(cd);
  1805. pm_runtime_disable(dev);
  1806. cyttsp4_free_si_ptrs(cd);
  1807. free_irq(cd->irq, cd);
  1808. error_request_irq:
  1809. if (cd->cpdata->init)
  1810. cd->cpdata->init(cd->cpdata, 0, dev);
  1811. dev_set_drvdata(dev, NULL);
  1812. error_free_xfer:
  1813. kfree(cd->xfer_buf);
  1814. error_free_cd:
  1815. kfree(cd);
  1816. error_alloc_data:
  1817. error_no_pdata:
  1818. dev_err(dev, "%s failed.\n", __func__);
  1819. return ERR_PTR(rc);
  1820. }
  1821. EXPORT_SYMBOL_GPL(cyttsp4_probe);
  1822. static void cyttsp4_mt_release(struct cyttsp4_mt_data *md)
  1823. {
  1824. input_unregister_device(md->input);
  1825. input_set_drvdata(md->input, NULL);
  1826. }
  1827. int cyttsp4_remove(struct cyttsp4 *cd)
  1828. {
  1829. struct device *dev = cd->dev;
  1830. cyttsp4_mt_release(&cd->md);
  1831. /*
  1832. * Suspend the device before freeing the startup_work and stopping
  1833. * the watchdog since sleep function restarts watchdog on failure
  1834. */
  1835. pm_runtime_suspend(dev);
  1836. pm_runtime_disable(dev);
  1837. cancel_work_sync(&cd->startup_work);
  1838. cyttsp4_stop_wd_timer(cd);
  1839. free_irq(cd->irq, cd);
  1840. if (cd->cpdata->init)
  1841. cd->cpdata->init(cd->cpdata, 0, dev);
  1842. dev_set_drvdata(dev, NULL);
  1843. cyttsp4_free_si_ptrs(cd);
  1844. kfree(cd);
  1845. return 0;
  1846. }
  1847. EXPORT_SYMBOL_GPL(cyttsp4_remove);
  1848. MODULE_LICENSE("GPL");
  1849. MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen core driver");
  1850. MODULE_AUTHOR("Cypress");