synaptics_tcm_testing.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  1. /*
  2. * Synaptics TCM touchscreen driver
  3. *
  4. * Copyright (C) 2017-2019 Synaptics Incorporated. All rights reserved.
  5. *
  6. * Copyright (C) 2017-2019 Scott Lin <[email protected]>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS
  19. * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
  21. * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS.
  22. * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION
  24. * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED
  25. * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  26. * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF
  27. * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES
  28. * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS'
  29. * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S.
  30. * DOLLARS.
  31. */
  32. #include <linux/gpio.h>
  33. #include "synaptics_tcm_core.h"
  34. #include "synaptics_tcm_testing.h"
  35. #define SYSFS_DIR_NAME "testing"
  36. #define REPORT_TIMEOUT_MS 500
  37. #define testing_sysfs_show(t_name) \
  38. static ssize_t testing_sysfs_##t_name##_show(struct device *dev, \
  39. struct device_attribute *attr, char *buf) \
  40. { \
  41. int retval; \
  42. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd; \
  43. \
  44. mutex_lock(&tcm_hcd->extif_mutex); \
  45. \
  46. retval = testing_##t_name(); \
  47. if (retval < 0) { \
  48. LOGE(tcm_hcd->pdev->dev.parent, \
  49. "Failed to do "#t_name" test\n"); \
  50. goto exit; \
  51. } \
  52. \
  53. retval = snprintf(buf, PAGE_SIZE, \
  54. "%s\n", \
  55. testing_hcd->result ? "Passed" : "Failed"); \
  56. \
  57. exit: \
  58. mutex_unlock(&tcm_hcd->extif_mutex); \
  59. \
  60. return retval; \
  61. }
  62. enum test_code {
  63. TEST_TRX_TRX_SHORTS = 0,
  64. TEST_TRX_SENSOR_OPENS = 1,
  65. TEST_TRX_GROUND_SHORTS = 2,
  66. TEST_DYNAMIC_RANGE = 7,
  67. TEST_OPEN_SHORT_DETECTOR = 8,
  68. TEST_NOISE = 10,
  69. TEST_PT11 = 11,
  70. TEST_PT12 = 12,
  71. TEST_PT13 = 13,
  72. TEST_DYNAMIC_RANGE_DOZE = 14,
  73. TEST_NOISE_DOZE = 15,
  74. };
  75. struct testing_hcd {
  76. bool result;
  77. unsigned char report_type;
  78. unsigned int report_index;
  79. unsigned int num_of_reports;
  80. struct kobject *sysfs_dir;
  81. struct syna_tcm_buffer out;
  82. struct syna_tcm_buffer resp;
  83. struct syna_tcm_buffer report;
  84. struct syna_tcm_buffer process;
  85. struct syna_tcm_buffer output;
  86. struct syna_tcm_hcd *tcm_hcd;
  87. int (*collect_reports)(enum report_type report_type,
  88. unsigned int num_of_reports);
  89. };
  90. DECLARE_COMPLETION(report_complete);
  91. DECLARE_COMPLETION(testing_remove_complete);
  92. static struct testing_hcd *testing_hcd;
  93. static int testing_dynamic_range(void);
  94. static int testing_dynamic_range_lpwg(void);
  95. static int testing_dynamic_range_doze(void);
  96. static int testing_noise(void);
  97. static int testing_noise_lpwg(void);
  98. static int testing_noise_doze(void);
  99. static int testing_open_short_detector(void);
  100. static int testing_pt11(void);
  101. static int testing_pt12(void);
  102. static int testing_pt13(void);
  103. static int testing_reset_open(void);
  104. static int testing_lockdown(void);
  105. static int testing_trx(enum test_code test_code);
  106. SHOW_PROTOTYPE(testing, dynamic_range);
  107. SHOW_PROTOTYPE(testing, dynamic_range_lpwg);
  108. SHOW_PROTOTYPE(testing, dynamic_range_doze);
  109. SHOW_PROTOTYPE(testing, noise);
  110. SHOW_PROTOTYPE(testing, noise_lpwg);
  111. SHOW_PROTOTYPE(testing, noise_doze);
  112. SHOW_PROTOTYPE(testing, open_short_detector);
  113. SHOW_PROTOTYPE(testing, pt11);
  114. SHOW_PROTOTYPE(testing, pt12);
  115. SHOW_PROTOTYPE(testing, pt13);
  116. SHOW_PROTOTYPE(testing, reset_open);
  117. SHOW_PROTOTYPE(testing, lockdown);
  118. SHOW_PROTOTYPE(testing, trx_trx_shorts);
  119. SHOW_PROTOTYPE(testing, trx_sensor_opens);
  120. SHOW_PROTOTYPE(testing, trx_ground_shorts);
  121. SHOW_PROTOTYPE(testing, size);
  122. static struct device_attribute *attrs[] = {
  123. ATTRIFY(dynamic_range),
  124. ATTRIFY(dynamic_range_lpwg),
  125. ATTRIFY(dynamic_range_doze),
  126. ATTRIFY(noise),
  127. ATTRIFY(noise_lpwg),
  128. ATTRIFY(noise_doze),
  129. ATTRIFY(open_short_detector),
  130. ATTRIFY(pt11),
  131. ATTRIFY(pt12),
  132. ATTRIFY(pt13),
  133. ATTRIFY(reset_open),
  134. ATTRIFY(lockdown),
  135. ATTRIFY(trx_trx_shorts),
  136. ATTRIFY(trx_sensor_opens),
  137. ATTRIFY(trx_ground_shorts),
  138. ATTRIFY(size),
  139. };
  140. static ssize_t testing_sysfs_data_show(struct file *data_file,
  141. struct kobject *kobj, struct bin_attribute *attributes,
  142. char *buf, loff_t pos, size_t count);
  143. static struct bin_attribute bin_attr = {
  144. .attr = {
  145. .name = "data",
  146. .mode = 0444,
  147. },
  148. .size = 0,
  149. .read = testing_sysfs_data_show,
  150. };
  151. testing_sysfs_show(dynamic_range)
  152. testing_sysfs_show(dynamic_range_lpwg)
  153. testing_sysfs_show(dynamic_range_doze)
  154. testing_sysfs_show(noise)
  155. testing_sysfs_show(noise_lpwg)
  156. testing_sysfs_show(noise_doze)
  157. testing_sysfs_show(open_short_detector)
  158. testing_sysfs_show(pt11)
  159. testing_sysfs_show(pt12)
  160. testing_sysfs_show(pt13)
  161. testing_sysfs_show(reset_open)
  162. testing_sysfs_show(lockdown)
  163. static ssize_t testing_sysfs_trx_trx_shorts_show(struct device *dev,
  164. struct device_attribute *attr, char *buf)
  165. {
  166. int retval;
  167. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  168. mutex_lock(&tcm_hcd->extif_mutex);
  169. retval = testing_trx(TEST_TRX_TRX_SHORTS);
  170. if (retval < 0) {
  171. LOGE(tcm_hcd->pdev->dev.parent,
  172. "Failed to do TRX-TRX shorts test\n");
  173. goto exit;
  174. }
  175. retval = snprintf(buf, PAGE_SIZE,
  176. "%s\n",
  177. testing_hcd->result ? "Passed" : "Failed");
  178. exit:
  179. mutex_unlock(&tcm_hcd->extif_mutex);
  180. return retval;
  181. }
  182. static ssize_t testing_sysfs_trx_sensor_opens_show(struct device *dev,
  183. struct device_attribute *attr, char *buf)
  184. {
  185. int retval;
  186. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  187. mutex_lock(&tcm_hcd->extif_mutex);
  188. retval = testing_trx(TEST_TRX_SENSOR_OPENS);
  189. if (retval < 0) {
  190. LOGE(tcm_hcd->pdev->dev.parent,
  191. "Failed to do TRX-sensor opens test\n");
  192. goto exit;
  193. }
  194. retval = snprintf(buf, PAGE_SIZE,
  195. "%s\n",
  196. testing_hcd->result ? "Passed" : "Failed");
  197. exit:
  198. mutex_unlock(&tcm_hcd->extif_mutex);
  199. return retval;
  200. }
  201. static ssize_t testing_sysfs_trx_ground_shorts_show(struct device *dev,
  202. struct device_attribute *attr, char *buf)
  203. {
  204. int retval;
  205. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  206. mutex_lock(&tcm_hcd->extif_mutex);
  207. retval = testing_trx(TEST_TRX_GROUND_SHORTS);
  208. if (retval < 0) {
  209. LOGE(tcm_hcd->pdev->dev.parent,
  210. "Failed to do TRX-ground shorts test\n");
  211. goto exit;
  212. }
  213. retval = snprintf(buf, PAGE_SIZE,
  214. "%s\n",
  215. testing_hcd->result ? "Passed" : "Failed");
  216. exit:
  217. mutex_unlock(&tcm_hcd->extif_mutex);
  218. return retval;
  219. }
  220. static ssize_t testing_sysfs_size_show(struct device *dev,
  221. struct device_attribute *attr, char *buf)
  222. {
  223. int retval;
  224. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  225. mutex_lock(&tcm_hcd->extif_mutex);
  226. LOCK_BUFFER(testing_hcd->output);
  227. retval = snprintf(buf, PAGE_SIZE,
  228. "%u\n",
  229. testing_hcd->output.data_length);
  230. UNLOCK_BUFFER(testing_hcd->output);
  231. mutex_unlock(&tcm_hcd->extif_mutex);
  232. return retval;
  233. }
  234. static ssize_t testing_sysfs_data_show(struct file *data_file,
  235. struct kobject *kobj, struct bin_attribute *attributes,
  236. char *buf, loff_t pos, size_t count)
  237. {
  238. int retval;
  239. unsigned int readlen;
  240. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  241. mutex_lock(&tcm_hcd->extif_mutex);
  242. LOCK_BUFFER(testing_hcd->output);
  243. readlen = MIN(count, testing_hcd->output.data_length - pos);
  244. retval = secure_memcpy(buf,
  245. count,
  246. &testing_hcd->output.buf[pos],
  247. testing_hcd->output.buf_size - pos,
  248. readlen);
  249. if (retval < 0) {
  250. LOGE(tcm_hcd->pdev->dev.parent,
  251. "Failed to copy report data\n");
  252. } else {
  253. retval = readlen;
  254. }
  255. UNLOCK_BUFFER(testing_hcd->output);
  256. mutex_unlock(&tcm_hcd->extif_mutex);
  257. return retval;
  258. }
  259. static int testing_run_prod_test_item(enum test_code test_code)
  260. {
  261. int retval;
  262. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  263. if (tcm_hcd->features.dual_firmware &&
  264. tcm_hcd->id_info.mode != MODE_PRODUCTION_TEST) {
  265. retval = tcm_hcd->switch_mode(tcm_hcd, FW_MODE_PRODUCTION_TEST);
  266. if (retval < 0) {
  267. LOGE(tcm_hcd->pdev->dev.parent,
  268. "Failed to run production test firmware\n");
  269. return retval;
  270. }
  271. } else if (tcm_hcd->id_info.mode != MODE_APPLICATION ||
  272. tcm_hcd->app_status != APP_STATUS_OK) {
  273. LOGE(tcm_hcd->pdev->dev.parent,
  274. "Application firmware not running\n");
  275. return -ENODEV;
  276. }
  277. LOCK_BUFFER(testing_hcd->out);
  278. retval = syna_tcm_alloc_mem(tcm_hcd,
  279. &testing_hcd->out,
  280. 1);
  281. if (retval < 0) {
  282. LOGE(tcm_hcd->pdev->dev.parent,
  283. "Failed to allocate memory for testing_hcd->out.buf\n");
  284. UNLOCK_BUFFER(testing_hcd->out);
  285. return retval;
  286. }
  287. testing_hcd->out.buf[0] = test_code;
  288. LOCK_BUFFER(testing_hcd->resp);
  289. retval = tcm_hcd->write_message(tcm_hcd,
  290. CMD_PRODUCTION_TEST,
  291. testing_hcd->out.buf,
  292. 1,
  293. &testing_hcd->resp.buf,
  294. &testing_hcd->resp.buf_size,
  295. &testing_hcd->resp.data_length,
  296. NULL,
  297. 0);
  298. if (retval < 0) {
  299. LOGE(tcm_hcd->pdev->dev.parent,
  300. "Failed to write command %s\n",
  301. STR(CMD_PRODUCTION_TEST));
  302. UNLOCK_BUFFER(testing_hcd->resp);
  303. UNLOCK_BUFFER(testing_hcd->out);
  304. return retval;
  305. }
  306. UNLOCK_BUFFER(testing_hcd->resp);
  307. UNLOCK_BUFFER(testing_hcd->out);
  308. return 0;
  309. }
  310. static int testing_collect_reports(enum report_type report_type,
  311. unsigned int num_of_reports)
  312. {
  313. int retval;
  314. bool completed;
  315. unsigned int timeout;
  316. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  317. testing_hcd->report_index = 0;
  318. testing_hcd->report_type = report_type;
  319. testing_hcd->num_of_reports = num_of_reports;
  320. reinit_completion(&report_complete);
  321. LOCK_BUFFER(testing_hcd->out);
  322. retval = syna_tcm_alloc_mem(tcm_hcd,
  323. &testing_hcd->out,
  324. 1);
  325. if (retval < 0) {
  326. LOGE(tcm_hcd->pdev->dev.parent,
  327. "Failed to allocate memory for testing_hcd->out.buf\n");
  328. UNLOCK_BUFFER(testing_hcd->out);
  329. goto exit;
  330. }
  331. testing_hcd->out.buf[0] = testing_hcd->report_type;
  332. LOCK_BUFFER(testing_hcd->resp);
  333. retval = tcm_hcd->write_message(tcm_hcd,
  334. CMD_ENABLE_REPORT,
  335. testing_hcd->out.buf,
  336. 1,
  337. &testing_hcd->resp.buf,
  338. &testing_hcd->resp.buf_size,
  339. &testing_hcd->resp.data_length,
  340. NULL,
  341. 0);
  342. if (retval < 0) {
  343. LOGE(tcm_hcd->pdev->dev.parent,
  344. "Failed to write command %s\n",
  345. STR(CMD_ENABLE_REPORT));
  346. UNLOCK_BUFFER(testing_hcd->resp);
  347. UNLOCK_BUFFER(testing_hcd->out);
  348. goto exit;
  349. }
  350. UNLOCK_BUFFER(testing_hcd->resp);
  351. UNLOCK_BUFFER(testing_hcd->out);
  352. completed = false;
  353. timeout = REPORT_TIMEOUT_MS * num_of_reports;
  354. retval = wait_for_completion_timeout(&report_complete,
  355. msecs_to_jiffies(timeout));
  356. if (retval == 0) {
  357. LOGE(tcm_hcd->pdev->dev.parent,
  358. "Timed out waiting for report collection\n");
  359. } else {
  360. completed = true;
  361. }
  362. LOCK_BUFFER(testing_hcd->out);
  363. testing_hcd->out.buf[0] = testing_hcd->report_type;
  364. LOCK_BUFFER(testing_hcd->resp);
  365. retval = tcm_hcd->write_message(tcm_hcd,
  366. CMD_DISABLE_REPORT,
  367. testing_hcd->out.buf,
  368. 1,
  369. &testing_hcd->resp.buf,
  370. &testing_hcd->resp.buf_size,
  371. &testing_hcd->resp.data_length,
  372. NULL,
  373. 0);
  374. if (retval < 0) {
  375. LOGE(tcm_hcd->pdev->dev.parent,
  376. "Failed to write command %s\n",
  377. STR(CMD_DISABLE_REPORT));
  378. UNLOCK_BUFFER(testing_hcd->resp);
  379. UNLOCK_BUFFER(testing_hcd->out);
  380. goto exit;
  381. }
  382. UNLOCK_BUFFER(testing_hcd->resp);
  383. UNLOCK_BUFFER(testing_hcd->out);
  384. if (completed)
  385. retval = 0;
  386. else
  387. retval = -EIO;
  388. exit:
  389. testing_hcd->report_type = 0;
  390. return retval;
  391. }
  392. static void testing_get_frame_size_words(unsigned int *size, bool image_only)
  393. {
  394. unsigned int rows;
  395. unsigned int cols;
  396. unsigned int hybrid;
  397. unsigned int buttons;
  398. struct syna_tcm_app_info *app_info;
  399. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  400. app_info = &tcm_hcd->app_info;
  401. rows = le2_to_uint(app_info->num_of_image_rows);
  402. cols = le2_to_uint(app_info->num_of_image_cols);
  403. hybrid = le2_to_uint(app_info->has_hybrid_data);
  404. buttons = le2_to_uint(app_info->num_of_buttons);
  405. *size = rows * cols;
  406. if (!image_only) {
  407. if (hybrid)
  408. *size += rows + cols;
  409. *size += buttons;
  410. }
  411. }
  412. static void testing_doze_frame_output(unsigned int rows, unsigned int cols)
  413. {
  414. int retval;
  415. unsigned int data_size;
  416. unsigned int header_size;
  417. unsigned int output_size;
  418. struct syna_tcm_app_info *app_info;
  419. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  420. app_info = &tcm_hcd->app_info;
  421. header_size = 2;
  422. data_size = rows * cols;
  423. if (le2_to_uint(app_info->num_of_buttons))
  424. data_size++;
  425. output_size = header_size + data_size * 2;
  426. LOCK_BUFFER(testing_hcd->output);
  427. retval = syna_tcm_alloc_mem(tcm_hcd,
  428. &testing_hcd->output,
  429. output_size);
  430. if (retval < 0) {
  431. LOGE(tcm_hcd->pdev->dev.parent,
  432. "Failed to allocate memory for testing_hcd->output.buf\n");
  433. UNLOCK_BUFFER(testing_hcd->output);
  434. return;
  435. }
  436. testing_hcd->output.buf[0] = rows;
  437. testing_hcd->output.buf[1] = cols;
  438. output_size = header_size;
  439. LOCK_BUFFER(testing_hcd->resp);
  440. retval = secure_memcpy(testing_hcd->output.buf + header_size,
  441. testing_hcd->output.buf_size - header_size,
  442. testing_hcd->resp.buf,
  443. testing_hcd->resp.buf_size,
  444. testing_hcd->resp.data_length);
  445. if (retval < 0) {
  446. LOGE(tcm_hcd->pdev->dev.parent,
  447. "Failed to copy test data\n");
  448. UNLOCK_BUFFER(testing_hcd->resp);
  449. UNLOCK_BUFFER(testing_hcd->output);
  450. return;
  451. }
  452. output_size += testing_hcd->resp.data_length;
  453. UNLOCK_BUFFER(testing_hcd->resp);
  454. testing_hcd->output.data_length = output_size;
  455. UNLOCK_BUFFER(testing_hcd->output);
  456. }
  457. static void testing_standard_frame_output(bool image_only)
  458. {
  459. int retval;
  460. unsigned int data_size;
  461. unsigned int header_size;
  462. unsigned int output_size;
  463. struct syna_tcm_app_info *app_info;
  464. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  465. app_info = &tcm_hcd->app_info;
  466. testing_get_frame_size_words(&data_size, image_only);
  467. header_size = sizeof(app_info->num_of_buttons) +
  468. sizeof(app_info->num_of_image_rows) +
  469. sizeof(app_info->num_of_image_cols) +
  470. sizeof(app_info->has_hybrid_data);
  471. output_size = header_size + data_size * 2;
  472. LOCK_BUFFER(testing_hcd->output);
  473. retval = syna_tcm_alloc_mem(tcm_hcd,
  474. &testing_hcd->output,
  475. output_size);
  476. if (retval < 0) {
  477. LOGE(tcm_hcd->pdev->dev.parent,
  478. "Failed to allocate memory for testing_hcd->output.buf\n");
  479. UNLOCK_BUFFER(testing_hcd->output);
  480. return;
  481. }
  482. retval = secure_memcpy(testing_hcd->output.buf,
  483. testing_hcd->output.buf_size,
  484. &app_info->num_of_buttons[0],
  485. header_size,
  486. header_size);
  487. if (retval < 0) {
  488. LOGE(tcm_hcd->pdev->dev.parent,
  489. "Failed to copy header data\n");
  490. UNLOCK_BUFFER(testing_hcd->output);
  491. return;
  492. }
  493. output_size = header_size;
  494. LOCK_BUFFER(testing_hcd->resp);
  495. retval = secure_memcpy(testing_hcd->output.buf + header_size,
  496. testing_hcd->output.buf_size - header_size,
  497. testing_hcd->resp.buf,
  498. testing_hcd->resp.buf_size,
  499. testing_hcd->resp.data_length);
  500. if (retval < 0) {
  501. LOGE(tcm_hcd->pdev->dev.parent,
  502. "Failed to copy test data\n");
  503. UNLOCK_BUFFER(testing_hcd->resp);
  504. UNLOCK_BUFFER(testing_hcd->output);
  505. return;
  506. }
  507. output_size += testing_hcd->resp.data_length;
  508. UNLOCK_BUFFER(testing_hcd->resp);
  509. testing_hcd->output.data_length = output_size;
  510. UNLOCK_BUFFER(testing_hcd->output);
  511. }
  512. static int testing_dynamic_range_doze(void)
  513. {
  514. int retval;
  515. unsigned char *buf;
  516. unsigned int idx;
  517. unsigned int row;
  518. unsigned int col;
  519. unsigned int data;
  520. unsigned int rows;
  521. unsigned int cols;
  522. unsigned int data_size;
  523. unsigned int limits_rows;
  524. unsigned int limits_cols;
  525. struct syna_tcm_app_info *app_info;
  526. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  527. app_info = &tcm_hcd->app_info;
  528. cols = le2_to_uint(app_info->num_of_image_cols);
  529. retval = testing_run_prod_test_item(TEST_DYNAMIC_RANGE_DOZE);
  530. if (retval < 0) {
  531. LOGE(tcm_hcd->pdev->dev.parent,
  532. "Failed to run test\n");
  533. goto exit;
  534. }
  535. LOCK_BUFFER(testing_hcd->resp);
  536. data_size = testing_hcd->resp.data_length / 2;
  537. if (le2_to_uint(app_info->num_of_buttons))
  538. data_size--;
  539. if (data_size % cols) {
  540. LOGE(tcm_hcd->pdev->dev.parent,
  541. "Invalid max number of rows per burst\n");
  542. UNLOCK_BUFFER(testing_hcd->resp);
  543. retval = -EINVAL;
  544. goto exit;
  545. }
  546. rows = data_size / cols;
  547. limits_rows = ARRAY_SIZE(drt_hi_limits);
  548. limits_cols = ARRAY_SIZE(drt_hi_limits[0]);
  549. if (rows > limits_rows || cols > limits_cols) {
  550. LOGE(tcm_hcd->pdev->dev.parent,
  551. "Mismatching limits data\n");
  552. UNLOCK_BUFFER(testing_hcd->resp);
  553. retval = -EINVAL;
  554. goto exit;
  555. }
  556. limits_rows = ARRAY_SIZE(drt_lo_limits);
  557. limits_cols = ARRAY_SIZE(drt_lo_limits[0]);
  558. if (rows > limits_rows || cols > limits_cols) {
  559. LOGE(tcm_hcd->pdev->dev.parent,
  560. "Mismatching limits data\n");
  561. UNLOCK_BUFFER(testing_hcd->resp);
  562. retval = -EINVAL;
  563. goto exit;
  564. }
  565. idx = 0;
  566. buf = testing_hcd->resp.buf;
  567. testing_hcd->result = true;
  568. for (row = 0; row < rows; row++) {
  569. for (col = 0; col < cols; col++) {
  570. data = le2_to_uint(&buf[idx * 2]);
  571. if (data > drt_hi_limits[row][col] ||
  572. data < drt_lo_limits[row][col]) {
  573. testing_hcd->result = false;
  574. break;
  575. }
  576. idx++;
  577. }
  578. }
  579. UNLOCK_BUFFER(testing_hcd->resp);
  580. testing_doze_frame_output(rows, cols);
  581. retval = 0;
  582. exit:
  583. if (tcm_hcd->features.dual_firmware) {
  584. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  585. LOGE(tcm_hcd->pdev->dev.parent,
  586. "Failed to do reset\n");
  587. }
  588. }
  589. return retval;
  590. }
  591. static int testing_dynamic_range_lpwg(void)
  592. {
  593. int retval;
  594. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  595. retval = tcm_hcd->set_dynamic_config(tcm_hcd,
  596. DC_IN_WAKEUP_GESTURE_MODE,
  597. 1);
  598. if (retval < 0) {
  599. LOGE(tcm_hcd->pdev->dev.parent,
  600. "Failed to enable wakeup gesture mode\n");
  601. return retval;
  602. }
  603. retval = testing_dynamic_range();
  604. if (retval < 0) {
  605. LOGE(tcm_hcd->pdev->dev.parent,
  606. "Failed to do dynamic range test\n");
  607. return retval;
  608. }
  609. retval = tcm_hcd->set_dynamic_config(tcm_hcd,
  610. DC_IN_WAKEUP_GESTURE_MODE,
  611. 0);
  612. if (retval < 0) {
  613. LOGE(tcm_hcd->pdev->dev.parent,
  614. "Failed to disable wakeup gesture mode\n");
  615. return retval;
  616. }
  617. return 0;
  618. }
  619. static int testing_dynamic_range(void)
  620. {
  621. int retval;
  622. unsigned char *buf;
  623. unsigned int idx;
  624. unsigned int row;
  625. unsigned int col;
  626. unsigned int data;
  627. unsigned int rows;
  628. unsigned int cols;
  629. unsigned int limits_rows;
  630. unsigned int limits_cols;
  631. unsigned int frame_size_words;
  632. struct syna_tcm_app_info *app_info;
  633. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  634. app_info = &tcm_hcd->app_info;
  635. rows = le2_to_uint(app_info->num_of_image_rows);
  636. cols = le2_to_uint(app_info->num_of_image_cols);
  637. testing_get_frame_size_words(&frame_size_words, false);
  638. retval = testing_run_prod_test_item(TEST_DYNAMIC_RANGE);
  639. if (retval < 0) {
  640. LOGE(tcm_hcd->pdev->dev.parent,
  641. "Failed to run test\n");
  642. goto exit;
  643. }
  644. LOCK_BUFFER(testing_hcd->resp);
  645. if (frame_size_words != testing_hcd->resp.data_length / 2) {
  646. LOGE(tcm_hcd->pdev->dev.parent,
  647. "Frame size mismatch\n");
  648. UNLOCK_BUFFER(testing_hcd->resp);
  649. retval = -EINVAL;
  650. goto exit;
  651. }
  652. limits_rows = ARRAY_SIZE(drt_hi_limits);
  653. limits_cols = ARRAY_SIZE(drt_hi_limits[0]);
  654. if (rows > limits_rows || cols > limits_cols) {
  655. LOGE(tcm_hcd->pdev->dev.parent,
  656. "Mismatching limits data\n");
  657. UNLOCK_BUFFER(testing_hcd->resp);
  658. retval = -EINVAL;
  659. goto exit;
  660. }
  661. limits_rows = ARRAY_SIZE(drt_lo_limits);
  662. limits_cols = ARRAY_SIZE(drt_lo_limits[0]);
  663. if (rows > limits_rows || cols > limits_cols) {
  664. LOGE(tcm_hcd->pdev->dev.parent,
  665. "Mismatching limits data\n");
  666. UNLOCK_BUFFER(testing_hcd->resp);
  667. retval = -EINVAL;
  668. goto exit;
  669. }
  670. idx = 0;
  671. buf = testing_hcd->resp.buf;
  672. testing_hcd->result = true;
  673. for (row = 0; row < rows; row++) {
  674. for (col = 0; col < cols; col++) {
  675. data = le2_to_uint(&buf[idx * 2]);
  676. if (data > drt_hi_limits[row][col] ||
  677. data < drt_lo_limits[row][col]) {
  678. testing_hcd->result = false;
  679. break;
  680. }
  681. idx++;
  682. }
  683. }
  684. UNLOCK_BUFFER(testing_hcd->resp);
  685. testing_standard_frame_output(false);
  686. retval = 0;
  687. exit:
  688. if (tcm_hcd->features.dual_firmware) {
  689. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  690. LOGE(tcm_hcd->pdev->dev.parent,
  691. "Failed to do reset\n");
  692. }
  693. }
  694. return retval;
  695. }
  696. static int testing_noise_doze(void)
  697. {
  698. int retval;
  699. short data;
  700. unsigned char *buf;
  701. unsigned int idx;
  702. unsigned int row;
  703. unsigned int col;
  704. unsigned int rows;
  705. unsigned int cols;
  706. unsigned int data_size;
  707. unsigned int limits_rows;
  708. unsigned int limits_cols;
  709. struct syna_tcm_app_info *app_info;
  710. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  711. app_info = &tcm_hcd->app_info;
  712. cols = le2_to_uint(app_info->num_of_image_cols);
  713. retval = testing_run_prod_test_item(TEST_NOISE_DOZE);
  714. if (retval < 0) {
  715. LOGE(tcm_hcd->pdev->dev.parent,
  716. "Failed to run test\n");
  717. goto exit;
  718. }
  719. LOCK_BUFFER(testing_hcd->resp);
  720. data_size = testing_hcd->resp.data_length / 2;
  721. if (le2_to_uint(app_info->num_of_buttons))
  722. data_size--;
  723. if (data_size % cols) {
  724. LOGE(tcm_hcd->pdev->dev.parent,
  725. "Invalid max number of rows per burst\n");
  726. UNLOCK_BUFFER(testing_hcd->resp);
  727. retval = -EINVAL;
  728. goto exit;
  729. }
  730. rows = data_size / cols;
  731. limits_rows = ARRAY_SIZE(noise_limits);
  732. limits_cols = ARRAY_SIZE(noise_limits[0]);
  733. if (rows > limits_rows || cols > limits_cols) {
  734. LOGE(tcm_hcd->pdev->dev.parent,
  735. "Mismatching limits data\n");
  736. UNLOCK_BUFFER(testing_hcd->resp);
  737. retval = -EINVAL;
  738. goto exit;
  739. }
  740. idx = 0;
  741. buf = testing_hcd->resp.buf;
  742. testing_hcd->result = true;
  743. for (row = 0; row < rows; row++) {
  744. for (col = 0; col < cols; col++) {
  745. data = (short)le2_to_uint(&buf[idx * 2]);
  746. if (data > noise_limits[row][col]) {
  747. testing_hcd->result = false;
  748. break;
  749. }
  750. idx++;
  751. }
  752. }
  753. UNLOCK_BUFFER(testing_hcd->resp);
  754. testing_doze_frame_output(rows, cols);
  755. retval = 0;
  756. exit:
  757. if (tcm_hcd->features.dual_firmware) {
  758. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  759. LOGE(tcm_hcd->pdev->dev.parent,
  760. "Failed to do reset\n");
  761. }
  762. }
  763. return retval;
  764. }
  765. static int testing_noise_lpwg(void)
  766. {
  767. int retval;
  768. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  769. retval = tcm_hcd->set_dynamic_config(tcm_hcd,
  770. DC_IN_WAKEUP_GESTURE_MODE,
  771. 1);
  772. if (retval < 0) {
  773. LOGE(tcm_hcd->pdev->dev.parent,
  774. "Failed to enable wakeup gesture mode\n");
  775. return retval;
  776. }
  777. retval = testing_noise();
  778. if (retval < 0) {
  779. LOGE(tcm_hcd->pdev->dev.parent,
  780. "Failed to do noise test\n");
  781. return retval;
  782. }
  783. retval = tcm_hcd->set_dynamic_config(tcm_hcd,
  784. DC_IN_WAKEUP_GESTURE_MODE,
  785. 0);
  786. if (retval < 0) {
  787. LOGE(tcm_hcd->pdev->dev.parent,
  788. "Failed to disable wakeup gesture mode\n");
  789. return retval;
  790. }
  791. return 0;
  792. }
  793. static int testing_noise(void)
  794. {
  795. int retval;
  796. short data;
  797. unsigned char *buf;
  798. unsigned int idx;
  799. unsigned int row;
  800. unsigned int col;
  801. unsigned int rows;
  802. unsigned int cols;
  803. unsigned int limits_rows;
  804. unsigned int limits_cols;
  805. unsigned int frame_size_words;
  806. struct syna_tcm_app_info *app_info;
  807. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  808. app_info = &tcm_hcd->app_info;
  809. rows = le2_to_uint(app_info->num_of_image_rows);
  810. cols = le2_to_uint(app_info->num_of_image_cols);
  811. testing_get_frame_size_words(&frame_size_words, false);
  812. retval = testing_run_prod_test_item(TEST_NOISE);
  813. if (retval < 0) {
  814. LOGE(tcm_hcd->pdev->dev.parent,
  815. "Failed to run test\n");
  816. goto exit;
  817. }
  818. LOCK_BUFFER(testing_hcd->resp);
  819. if (frame_size_words != testing_hcd->resp.data_length / 2) {
  820. LOGE(tcm_hcd->pdev->dev.parent,
  821. "Frame size mismatch\n");
  822. UNLOCK_BUFFER(testing_hcd->resp);
  823. retval = -EINVAL;
  824. goto exit;
  825. }
  826. limits_rows = ARRAY_SIZE(noise_limits);
  827. limits_cols = ARRAY_SIZE(noise_limits[0]);
  828. if (rows > limits_rows || cols > limits_cols) {
  829. LOGE(tcm_hcd->pdev->dev.parent,
  830. "Mismatching limits data\n");
  831. UNLOCK_BUFFER(testing_hcd->resp);
  832. retval = -EINVAL;
  833. goto exit;
  834. }
  835. idx = 0;
  836. buf = testing_hcd->resp.buf;
  837. testing_hcd->result = true;
  838. for (row = 0; row < rows; row++) {
  839. for (col = 0; col < cols; col++) {
  840. data = (short)le2_to_uint(&buf[idx * 2]);
  841. if (data > noise_limits[row][col]) {
  842. testing_hcd->result = false;
  843. break;
  844. }
  845. idx++;
  846. }
  847. }
  848. UNLOCK_BUFFER(testing_hcd->resp);
  849. testing_standard_frame_output(false);
  850. retval = 0;
  851. exit:
  852. if (tcm_hcd->features.dual_firmware) {
  853. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  854. LOGE(tcm_hcd->pdev->dev.parent,
  855. "Failed to do reset\n");
  856. }
  857. }
  858. return retval;
  859. }
  860. static void testing_open_short_detector_output(void)
  861. {
  862. int retval;
  863. unsigned int rows;
  864. unsigned int cols;
  865. unsigned int data_size;
  866. unsigned int header_size;
  867. unsigned int output_size;
  868. struct syna_tcm_app_info *app_info;
  869. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  870. app_info = &tcm_hcd->app_info;
  871. rows = le2_to_uint(app_info->num_of_image_rows);
  872. cols = le2_to_uint(app_info->num_of_image_cols);
  873. data_size = (rows * cols + 7) / 8;
  874. header_size = sizeof(app_info->num_of_buttons) +
  875. sizeof(app_info->num_of_image_rows) +
  876. sizeof(app_info->num_of_image_cols) +
  877. sizeof(app_info->has_hybrid_data);
  878. output_size = header_size + data_size * 2;
  879. LOCK_BUFFER(testing_hcd->output);
  880. retval = syna_tcm_alloc_mem(tcm_hcd,
  881. &testing_hcd->output,
  882. output_size);
  883. if (retval < 0) {
  884. LOGE(tcm_hcd->pdev->dev.parent,
  885. "Failed to allocate memory for output.buf\n");
  886. UNLOCK_BUFFER(testing_hcd->output);
  887. return;
  888. }
  889. retval = secure_memcpy(testing_hcd->output.buf,
  890. testing_hcd->output.buf_size,
  891. &app_info->num_of_buttons[0],
  892. header_size,
  893. header_size);
  894. if (retval < 0) {
  895. LOGE(tcm_hcd->pdev->dev.parent,
  896. "Failed to copy header data\n");
  897. UNLOCK_BUFFER(testing_hcd->output);
  898. return;
  899. }
  900. output_size = header_size;
  901. LOCK_BUFFER(testing_hcd->resp);
  902. retval = secure_memcpy(testing_hcd->output.buf + header_size,
  903. testing_hcd->output.buf_size - header_size,
  904. testing_hcd->resp.buf,
  905. testing_hcd->resp.buf_size,
  906. testing_hcd->resp.data_length);
  907. if (retval < 0) {
  908. LOGE(tcm_hcd->pdev->dev.parent,
  909. "Failed to copy test data\n");
  910. UNLOCK_BUFFER(testing_hcd->resp);
  911. UNLOCK_BUFFER(testing_hcd->output);
  912. return;
  913. }
  914. output_size += testing_hcd->resp.data_length;
  915. UNLOCK_BUFFER(testing_hcd->resp);
  916. testing_hcd->output.data_length = output_size;
  917. UNLOCK_BUFFER(testing_hcd->output);
  918. }
  919. static int testing_open_short_detector(void)
  920. {
  921. int retval;
  922. unsigned int bit;
  923. unsigned int byte;
  924. unsigned int row;
  925. unsigned int col;
  926. unsigned int rows;
  927. unsigned int cols;
  928. unsigned int data_size;
  929. unsigned char *data;
  930. struct syna_tcm_app_info *app_info;
  931. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  932. app_info = &tcm_hcd->app_info;
  933. rows = le2_to_uint(app_info->num_of_image_rows);
  934. cols = le2_to_uint(app_info->num_of_image_cols);
  935. data_size = (rows * cols + 7) / 8;
  936. retval = testing_run_prod_test_item(TEST_OPEN_SHORT_DETECTOR);
  937. if (retval < 0) {
  938. LOGE(tcm_hcd->pdev->dev.parent,
  939. "Failed to run test\n");
  940. goto exit;
  941. }
  942. LOCK_BUFFER(testing_hcd->resp);
  943. if (data_size * 2 != testing_hcd->resp.data_length) {
  944. LOGE(tcm_hcd->pdev->dev.parent,
  945. "Data size mismatch\n");
  946. UNLOCK_BUFFER(testing_hcd->resp);
  947. retval = -EINVAL;
  948. goto exit;
  949. }
  950. testing_hcd->result = true;
  951. bit = 0;
  952. byte = 0;
  953. data = &testing_hcd->resp.buf[0];
  954. for (row = 0; row < rows; row++) {
  955. for (col = 0; col < cols; col++) {
  956. if (data[byte] & (1 << bit)) {
  957. testing_hcd->result = false;
  958. break;
  959. }
  960. if (bit++ > 7) {
  961. bit = 0;
  962. byte++;
  963. }
  964. }
  965. }
  966. if (testing_hcd->result == true) {
  967. bit = 0;
  968. byte = 0;
  969. data = &testing_hcd->resp.buf[data_size];
  970. for (row = 0; row < rows; row++) {
  971. for (col = 0; col < cols; col++) {
  972. if (data[byte] & (1 << bit)) {
  973. testing_hcd->result = false;
  974. break;
  975. }
  976. if (bit++ > 7) {
  977. bit = 0;
  978. byte++;
  979. }
  980. }
  981. }
  982. }
  983. UNLOCK_BUFFER(testing_hcd->resp);
  984. testing_open_short_detector_output();
  985. retval = 0;
  986. exit:
  987. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  988. LOGE(tcm_hcd->pdev->dev.parent,
  989. "Failed to do reset\n");
  990. }
  991. return retval;
  992. }
  993. static int testing_pt11(void)
  994. {
  995. int retval;
  996. short data;
  997. unsigned char *buf;
  998. unsigned int idx;
  999. unsigned int row;
  1000. unsigned int col;
  1001. unsigned int rows;
  1002. unsigned int cols;
  1003. unsigned int limits_rows;
  1004. unsigned int limits_cols;
  1005. unsigned int image_size_words;
  1006. struct syna_tcm_app_info *app_info;
  1007. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1008. app_info = &tcm_hcd->app_info;
  1009. rows = le2_to_uint(app_info->num_of_image_rows);
  1010. cols = le2_to_uint(app_info->num_of_image_cols);
  1011. testing_get_frame_size_words(&image_size_words, true);
  1012. retval = testing_run_prod_test_item(TEST_PT11);
  1013. if (retval < 0) {
  1014. LOGE(tcm_hcd->pdev->dev.parent,
  1015. "Failed to run test\n");
  1016. goto exit;
  1017. }
  1018. LOCK_BUFFER(testing_hcd->resp);
  1019. if (image_size_words != testing_hcd->resp.data_length / 2) {
  1020. LOGE(tcm_hcd->pdev->dev.parent,
  1021. "Image size mismatch\n");
  1022. UNLOCK_BUFFER(testing_hcd->resp);
  1023. retval = -EINVAL;
  1024. goto exit;
  1025. }
  1026. limits_rows = ARRAY_SIZE(pt11_hi_limits);
  1027. limits_cols = ARRAY_SIZE(pt11_hi_limits[0]);
  1028. if (rows > limits_rows || cols > limits_cols) {
  1029. LOGE(tcm_hcd->pdev->dev.parent,
  1030. "Mismatching limits data\n");
  1031. UNLOCK_BUFFER(testing_hcd->resp);
  1032. retval = -EINVAL;
  1033. goto exit;
  1034. }
  1035. limits_rows = ARRAY_SIZE(pt11_lo_limits);
  1036. limits_cols = ARRAY_SIZE(pt11_lo_limits[0]);
  1037. if (rows > limits_rows || cols > limits_cols) {
  1038. LOGE(tcm_hcd->pdev->dev.parent,
  1039. "Mismatching limits data\n");
  1040. UNLOCK_BUFFER(testing_hcd->resp);
  1041. retval = -EINVAL;
  1042. goto exit;
  1043. }
  1044. idx = 0;
  1045. buf = testing_hcd->resp.buf;
  1046. testing_hcd->result = true;
  1047. for (row = 0; row < rows; row++) {
  1048. for (col = 0; col < cols; col++) {
  1049. data = (short)le2_to_uint(&buf[idx * 2]);
  1050. if (data > pt11_hi_limits[row][col] ||
  1051. data < pt11_lo_limits[row][col]) {
  1052. testing_hcd->result = false;
  1053. break;
  1054. }
  1055. idx++;
  1056. }
  1057. }
  1058. UNLOCK_BUFFER(testing_hcd->resp);
  1059. testing_standard_frame_output(true);
  1060. retval = 0;
  1061. exit:
  1062. if (tcm_hcd->features.dual_firmware) {
  1063. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  1064. LOGE(tcm_hcd->pdev->dev.parent,
  1065. "Failed to do reset\n");
  1066. }
  1067. }
  1068. return retval;
  1069. }
  1070. static int testing_pt12(void)
  1071. {
  1072. int retval;
  1073. short data;
  1074. unsigned char *buf;
  1075. unsigned int idx;
  1076. unsigned int row;
  1077. unsigned int col;
  1078. unsigned int rows;
  1079. unsigned int cols;
  1080. unsigned int limits_rows;
  1081. unsigned int limits_cols;
  1082. unsigned int image_size_words;
  1083. struct syna_tcm_app_info *app_info;
  1084. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1085. app_info = &tcm_hcd->app_info;
  1086. rows = le2_to_uint(app_info->num_of_image_rows);
  1087. cols = le2_to_uint(app_info->num_of_image_cols);
  1088. testing_get_frame_size_words(&image_size_words, true);
  1089. retval = testing_run_prod_test_item(TEST_PT12);
  1090. if (retval < 0) {
  1091. LOGE(tcm_hcd->pdev->dev.parent,
  1092. "Failed to run test\n");
  1093. goto exit;
  1094. }
  1095. LOCK_BUFFER(testing_hcd->resp);
  1096. if (image_size_words != testing_hcd->resp.data_length / 2) {
  1097. LOGE(tcm_hcd->pdev->dev.parent,
  1098. "Image size mismatch\n");
  1099. UNLOCK_BUFFER(testing_hcd->resp);
  1100. retval = -EINVAL;
  1101. goto exit;
  1102. }
  1103. limits_rows = ARRAY_SIZE(pt12_limits);
  1104. limits_cols = ARRAY_SIZE(pt12_limits[0]);
  1105. if (rows > limits_rows || cols > limits_cols) {
  1106. LOGE(tcm_hcd->pdev->dev.parent,
  1107. "Mismatching limits data\n");
  1108. UNLOCK_BUFFER(testing_hcd->resp);
  1109. retval = -EINVAL;
  1110. goto exit;
  1111. }
  1112. idx = 0;
  1113. buf = testing_hcd->resp.buf;
  1114. testing_hcd->result = true;
  1115. for (row = 0; row < rows; row++) {
  1116. for (col = 0; col < cols; col++) {
  1117. data = (short)le2_to_uint(&buf[idx * 2]);
  1118. if (data < pt12_limits[row][col]) {
  1119. testing_hcd->result = false;
  1120. break;
  1121. }
  1122. idx++;
  1123. }
  1124. }
  1125. UNLOCK_BUFFER(testing_hcd->resp);
  1126. testing_standard_frame_output(true);
  1127. retval = 0;
  1128. exit:
  1129. if (tcm_hcd->features.dual_firmware) {
  1130. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  1131. LOGE(tcm_hcd->pdev->dev.parent,
  1132. "Failed to do reset\n");
  1133. }
  1134. }
  1135. return retval;
  1136. }
  1137. static int testing_pt13(void)
  1138. {
  1139. int retval;
  1140. short data;
  1141. unsigned char *buf;
  1142. unsigned int idx;
  1143. unsigned int row;
  1144. unsigned int col;
  1145. unsigned int rows;
  1146. unsigned int cols;
  1147. unsigned int limits_rows;
  1148. unsigned int limits_cols;
  1149. unsigned int image_size_words;
  1150. struct syna_tcm_app_info *app_info;
  1151. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1152. app_info = &tcm_hcd->app_info;
  1153. rows = le2_to_uint(app_info->num_of_image_rows);
  1154. cols = le2_to_uint(app_info->num_of_image_cols);
  1155. testing_get_frame_size_words(&image_size_words, true);
  1156. retval = testing_run_prod_test_item(TEST_PT13);
  1157. if (retval < 0) {
  1158. LOGE(tcm_hcd->pdev->dev.parent,
  1159. "Failed to run test\n");
  1160. goto exit;
  1161. }
  1162. LOCK_BUFFER(testing_hcd->resp);
  1163. if (image_size_words != testing_hcd->resp.data_length / 2) {
  1164. LOGE(tcm_hcd->pdev->dev.parent,
  1165. "Image size mismatch\n");
  1166. UNLOCK_BUFFER(testing_hcd->resp);
  1167. retval = -EINVAL;
  1168. goto exit;
  1169. }
  1170. limits_rows = ARRAY_SIZE(pt13_limits);
  1171. limits_cols = ARRAY_SIZE(pt13_limits[0]);
  1172. if (rows > limits_rows || cols > limits_cols) {
  1173. LOGE(tcm_hcd->pdev->dev.parent,
  1174. "Mismatching limits data\n");
  1175. UNLOCK_BUFFER(testing_hcd->resp);
  1176. retval = -EINVAL;
  1177. goto exit;
  1178. }
  1179. idx = 0;
  1180. buf = testing_hcd->resp.buf;
  1181. testing_hcd->result = true;
  1182. for (row = 0; row < rows; row++) {
  1183. for (col = 0; col < cols; col++) {
  1184. data = (short)le2_to_uint(&buf[idx * 2]);
  1185. if (data < pt13_limits[row][col]) {
  1186. testing_hcd->result = false;
  1187. break;
  1188. }
  1189. idx++;
  1190. }
  1191. }
  1192. UNLOCK_BUFFER(testing_hcd->resp);
  1193. testing_standard_frame_output(true);
  1194. retval = 0;
  1195. exit:
  1196. if (tcm_hcd->features.dual_firmware) {
  1197. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  1198. LOGE(tcm_hcd->pdev->dev.parent,
  1199. "Failed to do reset\n");
  1200. }
  1201. }
  1202. return retval;
  1203. }
  1204. static int testing_reset_open(void)
  1205. {
  1206. int retval;
  1207. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1208. const struct syna_tcm_board_data *bdata = tcm_hcd->hw_if->bdata;
  1209. if (bdata->reset_gpio < 0) {
  1210. LOGE(tcm_hcd->pdev->dev.parent,
  1211. "Hardware reset unavailable\n");
  1212. return -EINVAL;
  1213. }
  1214. mutex_lock(&tcm_hcd->reset_mutex);
  1215. tcm_hcd->update_watchdog(tcm_hcd, false);
  1216. gpio_set_value(bdata->reset_gpio, bdata->reset_on_state);
  1217. msleep(bdata->reset_active_ms);
  1218. gpio_set_value(bdata->reset_gpio, !bdata->reset_on_state);
  1219. msleep(bdata->reset_delay_ms);
  1220. tcm_hcd->update_watchdog(tcm_hcd, true);
  1221. mutex_unlock(&tcm_hcd->reset_mutex);
  1222. if (tcm_hcd->id_info.mode == MODE_APPLICATION) {
  1223. retval = tcm_hcd->switch_mode(tcm_hcd, FW_MODE_BOOTLOADER);
  1224. if (retval < 0) {
  1225. LOGE(tcm_hcd->pdev->dev.parent,
  1226. "Failed to enter bootloader mode\n");
  1227. return retval;
  1228. }
  1229. } else {
  1230. retval = tcm_hcd->identify(tcm_hcd, false);
  1231. if (retval < 0) {
  1232. LOGE(tcm_hcd->pdev->dev.parent,
  1233. "Failed to do identification\n");
  1234. goto run_app_firmware;
  1235. }
  1236. }
  1237. if (tcm_hcd->boot_info.last_reset_reason == reset_open_limit)
  1238. testing_hcd->result = true;
  1239. else
  1240. testing_hcd->result = false;
  1241. retval = 0;
  1242. run_app_firmware:
  1243. if (tcm_hcd->switch_mode(tcm_hcd, FW_MODE_APPLICATION) < 0) {
  1244. LOGE(tcm_hcd->pdev->dev.parent,
  1245. "Failed to run application firmware\n");
  1246. }
  1247. return retval;
  1248. }
  1249. static void testing_lockdown_output(void)
  1250. {
  1251. int retval;
  1252. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1253. LOCK_BUFFER(testing_hcd->output);
  1254. LOCK_BUFFER(testing_hcd->resp);
  1255. retval = syna_tcm_alloc_mem(tcm_hcd,
  1256. &testing_hcd->output,
  1257. testing_hcd->resp.data_length);
  1258. if (retval < 0) {
  1259. LOGE(tcm_hcd->pdev->dev.parent,
  1260. "Failed to allocate memory for output.buf\n");
  1261. UNLOCK_BUFFER(testing_hcd->resp);
  1262. UNLOCK_BUFFER(testing_hcd->output);
  1263. return;
  1264. }
  1265. retval = secure_memcpy(testing_hcd->output.buf,
  1266. testing_hcd->output.buf_size,
  1267. testing_hcd->resp.buf,
  1268. testing_hcd->resp.buf_size,
  1269. testing_hcd->resp.data_length);
  1270. if (retval < 0) {
  1271. LOGE(tcm_hcd->pdev->dev.parent,
  1272. "Failed to copy test data\n");
  1273. UNLOCK_BUFFER(testing_hcd->resp);
  1274. UNLOCK_BUFFER(testing_hcd->output);
  1275. return;
  1276. }
  1277. testing_hcd->output.data_length = testing_hcd->resp.data_length;
  1278. UNLOCK_BUFFER(testing_hcd->resp);
  1279. UNLOCK_BUFFER(testing_hcd->output);
  1280. }
  1281. static int testing_lockdown(void)
  1282. {
  1283. int retval;
  1284. unsigned int idx;
  1285. unsigned int lockdown_size;
  1286. unsigned int limits_size;
  1287. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1288. if (tcm_hcd->read_flash_data == NULL) {
  1289. LOGE(tcm_hcd->pdev->dev.parent,
  1290. "Unable to read from flash\n");
  1291. return -EINVAL;
  1292. }
  1293. LOCK_BUFFER(testing_hcd->resp);
  1294. retval = tcm_hcd->read_flash_data(CUSTOM_OTP, true, &testing_hcd->resp);
  1295. if (retval < 0) {
  1296. LOGE(tcm_hcd->pdev->dev.parent,
  1297. "Failed to read lockdown data\n");
  1298. UNLOCK_BUFFER(testing_hcd->resp);
  1299. return retval;
  1300. }
  1301. lockdown_size = testing_hcd->resp.data_length;
  1302. limits_size = sizeof(lockdown_limits) / sizeof(*lockdown_limits);
  1303. if (lockdown_size != limits_size) {
  1304. LOGE(tcm_hcd->pdev->dev.parent,
  1305. "Mismatching limits data\n");
  1306. UNLOCK_BUFFER(testing_hcd->resp);
  1307. return -EINVAL;
  1308. }
  1309. testing_hcd->result = true;
  1310. for (idx = 0; idx < lockdown_size; idx++) {
  1311. if (testing_hcd->resp.buf[idx] != lockdown_limits[idx]) {
  1312. testing_hcd->result = false;
  1313. break;
  1314. }
  1315. }
  1316. UNLOCK_BUFFER(testing_hcd->resp);
  1317. testing_lockdown_output();
  1318. return 0;
  1319. }
  1320. static void testing_trx_output(void)
  1321. {
  1322. int retval;
  1323. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1324. LOCK_BUFFER(testing_hcd->output);
  1325. LOCK_BUFFER(testing_hcd->resp);
  1326. retval = syna_tcm_alloc_mem(tcm_hcd,
  1327. &testing_hcd->output,
  1328. testing_hcd->resp.data_length);
  1329. if (retval < 0) {
  1330. LOGE(tcm_hcd->pdev->dev.parent,
  1331. "Failed to allocate memory for output.buf\n");
  1332. UNLOCK_BUFFER(testing_hcd->resp);
  1333. UNLOCK_BUFFER(testing_hcd->output);
  1334. return;
  1335. }
  1336. retval = secure_memcpy(testing_hcd->output.buf,
  1337. testing_hcd->output.buf_size,
  1338. testing_hcd->resp.buf,
  1339. testing_hcd->resp.buf_size,
  1340. testing_hcd->resp.data_length);
  1341. if (retval < 0) {
  1342. LOGE(tcm_hcd->pdev->dev.parent,
  1343. "Failed to copy test data\n");
  1344. UNLOCK_BUFFER(testing_hcd->resp);
  1345. UNLOCK_BUFFER(testing_hcd->output);
  1346. return;
  1347. }
  1348. testing_hcd->output.data_length = testing_hcd->resp.data_length;
  1349. UNLOCK_BUFFER(testing_hcd->resp);
  1350. UNLOCK_BUFFER(testing_hcd->output);
  1351. }
  1352. static int testing_trx(enum test_code test_code)
  1353. {
  1354. int retval;
  1355. unsigned char pass_vector;
  1356. unsigned int idx;
  1357. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1358. switch (test_code) {
  1359. case TEST_TRX_TRX_SHORTS:
  1360. case TEST_TRX_GROUND_SHORTS:
  1361. pass_vector = 0xff;
  1362. break;
  1363. case TEST_TRX_SENSOR_OPENS:
  1364. pass_vector = 0x00;
  1365. break;
  1366. default:
  1367. return -EINVAL;
  1368. }
  1369. retval = testing_run_prod_test_item(test_code);
  1370. if (retval < 0) {
  1371. LOGE(tcm_hcd->pdev->dev.parent,
  1372. "Failed to run test\n");
  1373. goto exit;
  1374. }
  1375. LOCK_BUFFER(testing_hcd->resp);
  1376. testing_hcd->result = true;
  1377. for (idx = 0; idx < testing_hcd->resp.data_length; idx++) {
  1378. if (testing_hcd->resp.buf[idx] != pass_vector) {
  1379. testing_hcd->result = false;
  1380. break;
  1381. }
  1382. }
  1383. UNLOCK_BUFFER(testing_hcd->resp);
  1384. testing_trx_output();
  1385. retval = 0;
  1386. exit:
  1387. if (tcm_hcd->features.dual_firmware) {
  1388. if (tcm_hcd->reset(tcm_hcd, false, true) < 0) {
  1389. LOGE(tcm_hcd->pdev->dev.parent,
  1390. "Failed to do reset\n");
  1391. }
  1392. }
  1393. return retval;
  1394. }
  1395. static void testing_report(void)
  1396. {
  1397. int retval;
  1398. unsigned int offset;
  1399. unsigned int report_size;
  1400. struct syna_tcm_hcd *tcm_hcd = testing_hcd->tcm_hcd;
  1401. report_size = tcm_hcd->report.buffer.data_length;
  1402. LOCK_BUFFER(testing_hcd->report);
  1403. if (testing_hcd->report_index == 0) {
  1404. retval = syna_tcm_alloc_mem(tcm_hcd,
  1405. &testing_hcd->report,
  1406. report_size * testing_hcd->num_of_reports);
  1407. if (retval < 0) {
  1408. LOGE(tcm_hcd->pdev->dev.parent,
  1409. "Failed to allocate memory for report.buf\n");
  1410. UNLOCK_BUFFER(testing_hcd->report);
  1411. return;
  1412. }
  1413. }
  1414. if (testing_hcd->report_index < testing_hcd->num_of_reports) {
  1415. offset = report_size * testing_hcd->report_index;
  1416. retval = secure_memcpy(testing_hcd->report.buf + offset,
  1417. testing_hcd->report.buf_size - offset,
  1418. tcm_hcd->report.buffer.buf,
  1419. tcm_hcd->report.buffer.buf_size,
  1420. tcm_hcd->report.buffer.data_length);
  1421. if (retval < 0) {
  1422. LOGE(tcm_hcd->pdev->dev.parent,
  1423. "Failed to copy report data\n");
  1424. UNLOCK_BUFFER(testing_hcd->report);
  1425. return;
  1426. }
  1427. testing_hcd->report_index++;
  1428. testing_hcd->report.data_length += report_size;
  1429. }
  1430. UNLOCK_BUFFER(testing_hcd->report);
  1431. if (testing_hcd->report_index == testing_hcd->num_of_reports)
  1432. complete(&report_complete);
  1433. }
  1434. static int testing_init(struct syna_tcm_hcd *tcm_hcd)
  1435. {
  1436. int retval;
  1437. int idx;
  1438. testing_hcd = kzalloc(sizeof(*testing_hcd), GFP_KERNEL);
  1439. if (!testing_hcd) {
  1440. LOGE(tcm_hcd->pdev->dev.parent,
  1441. "Failed to allocate memory for testing_hcd\n");
  1442. return -ENOMEM;
  1443. }
  1444. testing_hcd->tcm_hcd = tcm_hcd;
  1445. testing_hcd->collect_reports = testing_collect_reports;
  1446. INIT_BUFFER(testing_hcd->out, false);
  1447. INIT_BUFFER(testing_hcd->resp, false);
  1448. INIT_BUFFER(testing_hcd->report, false);
  1449. INIT_BUFFER(testing_hcd->process, false);
  1450. INIT_BUFFER(testing_hcd->output, false);
  1451. testing_hcd->sysfs_dir = kobject_create_and_add(SYSFS_DIR_NAME,
  1452. tcm_hcd->sysfs_dir);
  1453. if (!testing_hcd->sysfs_dir) {
  1454. LOGE(tcm_hcd->pdev->dev.parent,
  1455. "Failed to create sysfs directory\n");
  1456. retval = -EINVAL;
  1457. goto err_sysfs_create_dir;
  1458. }
  1459. for (idx = 0; idx < ARRAY_SIZE(attrs); idx++) {
  1460. retval = sysfs_create_file(testing_hcd->sysfs_dir,
  1461. &(*attrs[idx]).attr);
  1462. if (retval < 0) {
  1463. LOGE(tcm_hcd->pdev->dev.parent,
  1464. "Failed to create sysfs file\n");
  1465. goto err_sysfs_create_file;
  1466. }
  1467. }
  1468. retval = sysfs_create_bin_file(testing_hcd->sysfs_dir, &bin_attr);
  1469. if (retval < 0) {
  1470. LOGE(tcm_hcd->pdev->dev.parent,
  1471. "Failed to create sysfs bin file\n");
  1472. goto err_sysfs_create_bin_file;
  1473. }
  1474. return 0;
  1475. err_sysfs_create_bin_file:
  1476. err_sysfs_create_file:
  1477. for (idx--; idx >= 0; idx--)
  1478. sysfs_remove_file(testing_hcd->sysfs_dir, &(*attrs[idx]).attr);
  1479. kobject_put(testing_hcd->sysfs_dir);
  1480. err_sysfs_create_dir:
  1481. RELEASE_BUFFER(testing_hcd->output);
  1482. RELEASE_BUFFER(testing_hcd->process);
  1483. RELEASE_BUFFER(testing_hcd->report);
  1484. RELEASE_BUFFER(testing_hcd->resp);
  1485. RELEASE_BUFFER(testing_hcd->out);
  1486. kfree(testing_hcd);
  1487. testing_hcd = NULL;
  1488. return retval;
  1489. }
  1490. static int testing_remove(struct syna_tcm_hcd *tcm_hcd)
  1491. {
  1492. int idx;
  1493. if (!testing_hcd)
  1494. goto exit;
  1495. sysfs_remove_bin_file(testing_hcd->sysfs_dir, &bin_attr);
  1496. for (idx = 0; idx < ARRAY_SIZE(attrs); idx++)
  1497. sysfs_remove_file(testing_hcd->sysfs_dir, &(*attrs[idx]).attr);
  1498. kobject_put(testing_hcd->sysfs_dir);
  1499. RELEASE_BUFFER(testing_hcd->output);
  1500. RELEASE_BUFFER(testing_hcd->process);
  1501. RELEASE_BUFFER(testing_hcd->report);
  1502. RELEASE_BUFFER(testing_hcd->resp);
  1503. RELEASE_BUFFER(testing_hcd->out);
  1504. kfree(testing_hcd);
  1505. testing_hcd = NULL;
  1506. exit:
  1507. complete(&testing_remove_complete);
  1508. return 0;
  1509. }
  1510. static int testing_reset(struct syna_tcm_hcd *tcm_hcd)
  1511. {
  1512. int retval;
  1513. if (!testing_hcd) {
  1514. retval = testing_init(tcm_hcd);
  1515. return retval;
  1516. }
  1517. return 0;
  1518. }
  1519. static int testing_syncbox(struct syna_tcm_hcd *tcm_hcd)
  1520. {
  1521. if (!testing_hcd)
  1522. return 0;
  1523. if (tcm_hcd->report.id == testing_hcd->report_type)
  1524. testing_report();
  1525. return 0;
  1526. }
  1527. static struct syna_tcm_module_cb testing_module = {
  1528. .type = TCM_TESTING,
  1529. .init = testing_init,
  1530. .remove = testing_remove,
  1531. .syncbox = testing_syncbox,
  1532. .asyncbox = NULL,
  1533. .reset = testing_reset,
  1534. .suspend = NULL,
  1535. .resume = NULL,
  1536. .early_suspend = NULL,
  1537. };
  1538. static int __init testing_module_init(void)
  1539. {
  1540. return syna_tcm_add_module(&testing_module, true);
  1541. }
  1542. static void __exit testing_module_exit(void)
  1543. {
  1544. syna_tcm_add_module(&testing_module, false);
  1545. wait_for_completion(&testing_remove_complete);
  1546. }
  1547. module_init(testing_module_init);
  1548. module_exit(testing_module_exit);
  1549. MODULE_AUTHOR("Synaptics, Inc.");
  1550. MODULE_DESCRIPTION("Synaptics TCM Testing Module");
  1551. MODULE_LICENSE("GPL v2");