fts_driver_test.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * FTS Capacitive touch screen controller (FingerTipS)
  4. *
  5. * Copyright (C) 2016-2019, STMicroelectronics Limited.
  6. * Authors: AMG(Analog Mems Group) <[email protected]>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/init.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/slab.h>
  26. #include <linux/input.h>
  27. #include <linux/input/mt.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/hrtimer.h>
  30. #include <linux/delay.h>
  31. #include <linux/firmware.h>
  32. #include <linux/i2c.h>
  33. #include <linux/i2c-dev.h>
  34. #include <linux/completion.h>
  35. /*#include <linux/wakelock.h>*/
  36. #include <linux/pm_wakeup.h>
  37. #include <linux/gpio.h>
  38. #include <linux/of_gpio.h>
  39. #include <linux/regulator/consumer.h>
  40. #include "fts.h"
  41. #include "fts_lib/ftsCompensation.h"
  42. #include "fts_lib/ftsIO.h"
  43. #include "fts_lib/ftsError.h"
  44. #include "fts_lib/ftsFrame.h"
  45. #include "fts_lib/ftsFlash.h"
  46. #include "fts_lib/ftsTest.h"
  47. #include "fts_lib/ftsTime.h"
  48. #include "fts_lib/ftsTool.h"
  49. #ifdef DRIVER_TEST
  50. #define MAX_PARAMS 50
  51. /*DEFINE COMMANDS TO TEST*/
  52. #define CMD_READ 0x00
  53. #define CMD_WRITE 0x01
  54. #define CMD_READU16 0x02
  55. #define CMD_READB2 0x03
  56. #define CMD_READB2U16 0x04
  57. #define CMD_POLLFOREVENT 0x05
  58. #define CMD_SYSTEMRESET 0x06
  59. #define CMD_CLEANUP 0x07
  60. #define CMD_GETFORCELEN 0x08
  61. #define CMD_GETSENSELEN 0x09
  62. #define CMD_GETMSFRAME 0x0A
  63. /*#define CMD_GETMSKEYFRAME 0x0B*/
  64. #define CMD_GETSSFRAME 0x0C
  65. #define CMD_REQCOMPDATA 0x0D
  66. #define CMD_READCOMPDATAHEAD 0x0E
  67. #define CMD_READMSCOMPDATA 0x0F
  68. #define CMD_READSSCOMPDATA 0x10
  69. #define CMD_READGNCOMPDATA 0x11
  70. #define CMD_GETFWVER 0x12
  71. #define CMD_FLASHSTATUS 0x13
  72. #define CMD_FLASHUNLOCK 0x14
  73. #define CMD_READFWFILE 0x15
  74. #define CMD_FLASHPROCEDURE 0x16
  75. #define CMD_ITOTEST 0x17
  76. #define CMD_INITTEST 0x18
  77. #define CMD_MSRAWTEST 0x19
  78. #define CMD_MSINITDATATEST 0x1A
  79. #define CMD_SSRAWTEST 0x1B
  80. #define CMD_SSINITDATATEST 0x1C
  81. #define CMD_MAINTEST 0x1D
  82. #define CMD_POWERCYCLE 0x1E
  83. #define CMD_FWWRITE 0x1F
  84. #define CMD_READCHIPINFO 0x20
  85. #define CMD_REQFRAME 0x21
  86. static char tag[8] = "[ FTS ]\0";
  87. static u32 functionToTest[MAX_PARAMS];
  88. static int numberParam;
  89. static ssize_t stm_driver_test_store(struct device *dev,
  90. struct device_attribute *attr, const char *buf, size_t count)
  91. {
  92. int n;
  93. char *p = (char *)buf;
  94. int ret;
  95. memset(functionToTest, 0, MAX_PARAMS * sizeof(u32));
  96. for (n = 0; n < (count + 1) / 3 && n < MAX_PARAMS; n++) {
  97. ret = sscanf(p, "%02X ", &functionToTest[n]);
  98. if (ret != 1)
  99. return -EINVAL;
  100. p += 3;
  101. logError(1, "%s functionToTest[%d] = %02X\n", tag, n,
  102. functionToTest[n]);
  103. }
  104. numberParam = n;
  105. logError(1, "%s Number of Parameters = %d\n", tag, numberParam);
  106. return count;
  107. }
  108. static ssize_t stm_driver_test_show(struct device *dev,
  109. struct device_attribute *attr, char *buf)
  110. {
  111. char buff[CMD_STR_LEN] = {0};
  112. int res = -1, j, count;
  113. int size = 6 * 2;
  114. int temp = 0;
  115. int i;
  116. int byteToRead = 0;
  117. u8 *readData = NULL;
  118. u8 *all_strbuff = NULL;
  119. u8 *cmd = NULL;
  120. struct MutualSenseFrame frameMS = {0};
  121. struct SelfSenseFrame frameSS = {0};
  122. struct DataHeader dataHead = {0};
  123. struct MutualSenseData compData = {0};
  124. struct SelfSenseData comData = {0};
  125. struct GeneralData gnData = {0};
  126. u16 address = 0;
  127. u16 fw_version = 0;
  128. u16 config_id = 0;
  129. struct Firmware fw;
  130. /*struct used for defining which test*/
  131. /*perform during the MP test*/
  132. struct TestToDo todoDefault;
  133. struct i2c_client *client = to_i2c_client(dev);
  134. struct fts_ts_info *info = i2c_get_clientdata(client);
  135. fw.data = NULL;
  136. todoDefault.MutualRaw = 1;
  137. todoDefault.MutualRawGap = 1;
  138. todoDefault.MutualCx1 = 0;
  139. todoDefault.MutualCx2 = 1;
  140. todoDefault.MutualCx2Adj = 1;
  141. todoDefault.MutualCxTotal = 0;
  142. todoDefault.MutualCxTotalAdj = 0;
  143. todoDefault.MutualKeyRaw = 0;
  144. todoDefault.MutualKeyCx1 = 0;
  145. todoDefault.MutualKeyCx2 = 0;
  146. todoDefault.MutualKeyCxTotal = 0;
  147. todoDefault.SelfForceRaw = 1;
  148. todoDefault.SelfForceRawGap = 0;
  149. todoDefault.SelfForceIx1 = 0;
  150. todoDefault.SelfForceIx2 = 0;
  151. todoDefault.SelfForceIx2Adj = 0;
  152. todoDefault.SelfForceIxTotal = 1;
  153. todoDefault.SelfForceIxTotalAdj = 0;
  154. todoDefault.SelfForceCx1 = 0;
  155. todoDefault.SelfForceCx2 = 0;
  156. todoDefault.SelfForceCx2Adj = 0;
  157. todoDefault.SelfForceCxTotal = 0;
  158. todoDefault.SelfForceCxTotalAdj = 0;
  159. todoDefault.SelfSenseRaw = 1;
  160. todoDefault.SelfSenseRawGap = 0;
  161. todoDefault.SelfSenseIx1 = 0;
  162. todoDefault.SelfSenseIx2 = 0;
  163. todoDefault.SelfSenseIx2Adj = 0;
  164. todoDefault.SelfSenseIxTotal = 1;
  165. todoDefault.SelfSenseIxTotalAdj = 0;
  166. todoDefault.SelfSenseCx1 = 0;
  167. todoDefault.SelfSenseCx2 = 0;
  168. todoDefault.SelfSenseCx2Adj = 0;
  169. todoDefault.SelfSenseCxTotal = 0;
  170. todoDefault.SelfSenseCxTotalAdj = 0;
  171. if (numberParam < 1) {
  172. logError(1, "%s NO COMMAND SPECIFIED!!! ", tag);
  173. logError(1, "do: 'echo [cmd_code] [args] > stm_fts_cmd' ");
  174. logError(1, "before looking for result!\n");
  175. res = ERROR_OP_NOT_ALLOW;
  176. goto END;
  177. }
  178. res = fts_disableInterrupt();
  179. if (res < 0) {
  180. logError(0, "%s %s: ERROR %08X\n", tag, __func__, res);
  181. res = (res | ERROR_DISABLE_INTER);
  182. goto END;
  183. }
  184. switch (functionToTest[0]) {
  185. case CMD_READ:
  186. if (numberParam != 4) {
  187. logError(1, "%s Wrong number of parameters!\n", tag);
  188. res = ERROR_OP_NOT_ALLOW;
  189. break;
  190. }
  191. /**
  192. * need to pass:cmdLength
  193. * cmd[0]cmd[1]…cmd[cmdLength-1]
  194. * byteToRead
  195. */
  196. temp = (int)functionToTest[1];
  197. if (numberParam == 4 + (temp - 1) && temp != 0) {
  198. cmd = (u8 *)kmalloc_array(temp, sizeof(u8), GFP_KERNEL);
  199. if (!cmd) {
  200. res = ERROR_OP_NOT_ALLOW;
  201. break;
  202. }
  203. for (i = 0; i < temp; i++)
  204. cmd[i] = functionToTest[i + 2];
  205. byteToRead = functionToTest[i + 2];
  206. readData = (u8 *)kmalloc_array(byteToRead, sizeof(u8),
  207. GFP_KERNEL);
  208. if (!readData) {
  209. kfree(cmd);
  210. res = ERROR_OP_NOT_ALLOW;
  211. break;
  212. }
  213. res = fts_readCmd(cmd, temp, readData, byteToRead);
  214. size += (byteToRead * sizeof(u8)) * 2;
  215. kfree(cmd);
  216. } else {
  217. logError(1, "%s Wrong parameters!\n", tag);
  218. res = ERROR_OP_NOT_ALLOW;
  219. }
  220. break;
  221. case CMD_WRITE:
  222. if (numberParam != 3) {
  223. logError(1, "%s Wrong number of parameters!\n", tag);
  224. res = ERROR_OP_NOT_ALLOW;
  225. break;
  226. }
  227. /**
  228. * need to pass:cmdLength
  229. * cmd[0] cmd[1]…cmd[cmdLength-1]
  230. */
  231. temp = (int)functionToTest[1];
  232. if (numberParam == 3 + (temp - 1) && temp != 0) {
  233. cmd = (u8 *)kmalloc_array(temp, sizeof(u8), GFP_KERNEL);
  234. if (!cmd) {
  235. res = ERROR_OP_NOT_ALLOW;
  236. break;
  237. }
  238. for (i = 0; i < temp; i++)
  239. cmd[i] = functionToTest[i + 2];
  240. res = fts_writeCmd(cmd, temp);
  241. kfree(cmd);
  242. } else {
  243. logError(1, "%s Wrong parameters!\n", tag);
  244. res = ERROR_OP_NOT_ALLOW;
  245. }
  246. break;
  247. case CMD_FWWRITE:
  248. if (numberParam != 3) {
  249. logError(1, "%s Wrong number parameters!\n", tag);
  250. res = ERROR_OP_NOT_ALLOW;
  251. break;
  252. }
  253. /**
  254. * need to pass:cmdLength
  255. * cmd[0] cmd[1]…cmd[cmdLength-1]
  256. */
  257. temp = (int)functionToTest[1];
  258. if (numberParam == 3 + (temp - 1) && temp != 0) {
  259. cmd = (u8 *)kmalloc_array(temp, sizeof(u8), GFP_KERNEL);
  260. if (!cmd) {
  261. res = ERROR_OP_NOT_ALLOW;
  262. break;
  263. }
  264. for (i = 0; i < temp; i++)
  265. cmd[i] = functionToTest[i + 2];
  266. res = fts_writeFwCmd(cmd, temp);
  267. kfree(cmd);
  268. } else {
  269. logError(1, "%s Wrong parameters!\n", tag);
  270. res = ERROR_OP_NOT_ALLOW;
  271. }
  272. break;
  273. case CMD_READU16:
  274. if (numberParam != 6) {
  275. logError(1, "%s Wrong number parameters!\n", tag);
  276. res = ERROR_OP_NOT_ALLOW;
  277. break;
  278. }
  279. /**
  280. * need to pass: cmd addr[0] addr[1]
  281. * byteToRead hasDummyByte
  282. */
  283. byteToRead = functionToTest[4];
  284. readData = kmalloc_array(byteToRead,
  285. sizeof(u8), GFP_KERNEL);
  286. if (!readData) {
  287. res = ERROR_OP_NOT_ALLOW;
  288. break;
  289. }
  290. res = readCmdU16((u8)functionToTest[1],
  291. (u16)((((u8) functionToTest[2]
  292. & 0x00FF) << 8) + ((u8) functionToTest[3]
  293. & 0x00FF)),
  294. readData,
  295. byteToRead,
  296. functionToTest[5]);
  297. size += (byteToRead * sizeof(u8)) * 2;
  298. break;
  299. case CMD_READB2:
  300. if (numberParam != 4) {
  301. logError(1, "%s Wrong number of parameters!\n", tag);
  302. res = ERROR_OP_NOT_ALLOW;
  303. break;
  304. }
  305. /*need to pass: addr[0] addr[1] byteToRead*/
  306. byteToRead = functionToTest[3];
  307. readData = kmalloc_array(byteToRead,
  308. sizeof(u8), GFP_KERNEL);
  309. if (!readData) {
  310. res = ERROR_OP_NOT_ALLOW;
  311. break;
  312. }
  313. res = readB2((u16)(
  314. (((u8)functionToTest[1] & 0x00FF) << 8)
  315. + ((u8) functionToTest[2] & 0x00FF)),
  316. readData,
  317. byteToRead);
  318. size += (byteToRead * sizeof(u8)) * 2;
  319. break;
  320. case CMD_READB2U16:
  321. if (numberParam != 4) {
  322. logError(1, "%s Wrong number of parameters!\n", tag);
  323. res = ERROR_OP_NOT_ALLOW;
  324. break;
  325. }
  326. /*need to pass: addr[0] addr[1] byteToRead*/
  327. byteToRead = functionToTest[3];
  328. readData = (u8 *)kmalloc_array(byteToRead,
  329. sizeof(u8), GFP_KERNEL);
  330. if (!readData) {
  331. res = ERROR_OP_NOT_ALLOW;
  332. break;
  333. }
  334. res = readB2U16((u16)((((u8)functionToTest[1]
  335. & 0x00FF) << 8) + ((u8)functionToTest[2]
  336. & 0x00FF)), readData, byteToRead);
  337. size += (byteToRead * sizeof(u8)) * 2;
  338. break;
  339. case CMD_POLLFOREVENT:
  340. if (numberParam < 5) {
  341. logError(1, "%s Wrong number of parameters!\n", tag);
  342. res = ERROR_OP_NOT_ALLOW;
  343. break;
  344. }
  345. /**
  346. * need to pass: eventLength event[0] event[1]
  347. * … event[eventLength-1] timeTowait
  348. */
  349. temp = (int)functionToTest[1];
  350. if (numberParam == 5 + (temp - 1) && temp != 0) {
  351. readData = (u8 *)kmalloc_array(FIFO_EVENT_SIZE,
  352. sizeof(u8), GFP_KERNEL);
  353. if (!readData) {
  354. res = ERROR_OP_NOT_ALLOW;
  355. break;
  356. }
  357. res = pollForEvent((int *)&functionToTest[2],
  358. temp,
  359. readData,
  360. ((functionToTest[temp + 2] & 0x00FF) << 8)
  361. + (functionToTest[temp + 3] & 0x00FF));
  362. //pollForEvent return the number of error found
  363. if (res >= OK)
  364. res = OK;
  365. size += (FIFO_EVENT_SIZE * sizeof(u8)) * 2;
  366. byteToRead = FIFO_EVENT_SIZE;
  367. } else {
  368. logError(1, "%s Wrong parameters!\n", tag);
  369. res = ERROR_OP_NOT_ALLOW;
  370. }
  371. break;
  372. case CMD_SYSTEMRESET:
  373. res = fts_system_reset();
  374. break;
  375. case CMD_READCHIPINFO:
  376. if (numberParam != 2) {
  377. logError(1, "%s Wrong number of parameters!\n", tag);
  378. res = ERROR_OP_NOT_ALLOW;
  379. break;
  380. }
  381. /*need to pass: doRequest */
  382. res = readChipInfo(functionToTest[1]);
  383. break;
  384. /* TOUCH ENABLE/DISABLE */
  385. case CMD_CLEANUP:
  386. if (numberParam != 2) {
  387. logError(1, "%s Wrong number of parameters!\n", tag);
  388. res = ERROR_OP_NOT_ALLOW;
  389. break;
  390. }
  391. /* need to pass: enableTouch*/
  392. res = cleanUp(functionToTest[1]);
  393. break;
  394. case CMD_GETFORCELEN:
  395. /*read number Tx channels */
  396. temp = getForceLen();
  397. if (temp < OK)
  398. res = temp;
  399. else {
  400. size += (1 * sizeof(u8)) * 2;
  401. res = OK;
  402. }
  403. break;
  404. case CMD_GETSENSELEN:
  405. /* read number Rx channels */
  406. temp = getSenseLen();
  407. if (temp < OK)
  408. res = temp;
  409. else {
  410. size += (1 * sizeof(u8)) * 2;
  411. res = OK;
  412. }
  413. break;
  414. case CMD_REQFRAME:
  415. /* request a frame */
  416. if (numberParam != 3) {
  417. logError(1, "%s Wrong number of parameters!\n", tag);
  418. res = ERROR_OP_NOT_ALLOW;
  419. break;
  420. }
  421. logError(0, "%s Requesting Frame\n", tag);
  422. res = requestFrame((u16)((((u8)functionToTest[1] & 0x00FF) << 8)
  423. + ((u8)functionToTest[2] & 0x00FF)));
  424. if (res < OK) {
  425. logError(0, "%s Err requesting frame ERROR:%02X\n",
  426. tag, res);
  427. } else {
  428. logError(0, "%s Requesting Frame Finished!\n", tag);
  429. }
  430. break;
  431. case CMD_GETMSFRAME:
  432. if (numberParam != 3) {
  433. logError(1, "%s Wrong number of param!\n", tag);
  434. res = ERROR_OP_NOT_ALLOW;
  435. break;
  436. }
  437. logError(0, "%s Get 1 MS Frame\n", tag);
  438. flushFIFO();
  439. /**
  440. * delete the events related to some
  441. * touch (allow to call this function
  442. * while touching the sreen without
  443. * having a flooding of the FIFO)
  444. */
  445. res = getMSFrame2((u16)((((u8)functionToTest[1] & 0x00FF) << 8)
  446. + ((u8)functionToTest[2] & 0x00FF)), &frameMS);
  447. if (res < 0) {
  448. logError(0, "%s Err while taking MS frame:%02X\n",
  449. tag, res);
  450. } else {
  451. logError(0, "%s:frame size is %d words\n", tag, res);
  452. size = (res * sizeof(short) + 8) * 2;
  453. /*set res to OK because if getMSFrame is*/
  454. /*successful res = number of words read*/
  455. res = OK;
  456. print_frame_short("MS frame =",
  457. array1dTo2d_short(frameMS.node_data,
  458. frameMS.node_data_size,
  459. frameMS.header.sense_node),
  460. frameMS.header.force_node,
  461. frameMS.header.sense_node);
  462. }
  463. break;
  464. /*read self raw*/
  465. case CMD_GETSSFRAME:
  466. if (numberParam != 3) {
  467. logError(1, "%s Wrong number of parameters!\n", tag);
  468. res = ERROR_OP_NOT_ALLOW;
  469. break;
  470. }
  471. logError(0, "%s Get 1 SS Frame\n", tag);
  472. flushFIFO();
  473. /**
  474. * delete the events related to some
  475. * touch (allow to call this function
  476. * while touching the sreen without
  477. * having a flooding of the FIFO)
  478. */
  479. res = getSSFrame2((u16)((((u8)functionToTest[1] & 0x00FF) << 8)
  480. + ((u8)functionToTest[2] & 0x00FF)), &frameSS);
  481. if (res < OK) {
  482. logError(0,
  483. "%s Error while taking the SS frame... ERROR %02X\n",
  484. tag, res);
  485. } else {
  486. logError(0, "%s The frame size is %d words\n",
  487. tag, res);
  488. size = (res * sizeof(short) + 8) * 2 + 1;
  489. /*set res to OK because if getMSFrame is*/
  490. /*successful res = number of words read*/
  491. res = OK;
  492. print_frame_short("SS force frame =",
  493. array1dTo2d_short(frameSS.force_data,
  494. frameSS.header.force_node, 1),
  495. frameSS.header.force_node,
  496. 1);
  497. print_frame_short("SS sense frame =",
  498. array1dTo2d_short(frameSS.sense_data,
  499. frameSS.header.sense_node,
  500. frameSS.header.sense_node),
  501. 1,
  502. frameSS.header.sense_node);
  503. }
  504. break;
  505. case CMD_REQCOMPDATA:
  506. /*request comp data*/
  507. if (numberParam != 3) {
  508. logError(1, "%s Wrong number of parameters!\n", tag);
  509. res = ERROR_OP_NOT_ALLOW;
  510. break;
  511. }
  512. logError(0, "%s Requesting Compensation Data\n", tag);
  513. res = requestCompensationData((u16)
  514. ((((u8)functionToTest[1] & 0x00FF) << 8)
  515. + ((u8)functionToTest[2] & 0x00FF)));
  516. if (res < OK) {
  517. logError(0,
  518. "%s Error requesting compensation data ERROR %02X\n",
  519. tag, res);
  520. } else {
  521. logError(0,
  522. "%s Requesting Compensation Data Finished!\n",
  523. tag);
  524. }
  525. break;
  526. case CMD_READCOMPDATAHEAD:
  527. /*read comp data header*/
  528. if (numberParam != 3) {
  529. logError(1, "%s Wrong number of parameters!\n", tag);
  530. res = ERROR_OP_NOT_ALLOW;
  531. break;
  532. }
  533. logError(0, "%s Requesting Compensation Data\n", tag);
  534. res = requestCompensationData(
  535. (u16) ((((u8)functionToTest[1] & 0x00FF) << 8)
  536. + ((u8)functionToTest[2] & 0x00FF)));
  537. if (res < OK) {
  538. logError(0, "%s Error requesting:%02X\n", tag, res);
  539. } else {
  540. logError(0,
  541. "%s Requesting Compensation Data Finished!\n", tag);
  542. res = readCompensationDataHeader(
  543. (u16)((((u8)functionToTest[1] & 0x00FF) << 8)
  544. +((u8)functionToTest[2] & 0x00FF)),
  545. &dataHead,
  546. &address);
  547. if (res < OK) {
  548. logError(0, "%s Read Header ERROR:%02X\n",
  549. tag, res);
  550. } else {
  551. logError(0, "%s Read Header OK!\n", tag);
  552. size += (2 * sizeof(u8)) * 2;
  553. }
  554. }
  555. break;
  556. case CMD_READMSCOMPDATA:
  557. if (numberParam != 3) {
  558. logError(1, "%s Wrong number of parameters!\n", tag);
  559. res = ERROR_OP_NOT_ALLOW;
  560. break;
  561. }
  562. /*read mutual comp data */
  563. logError(0, "%s Get MS Compensation Data\n", tag);
  564. res = readMutualSenseCompensationData(
  565. (u16)((((u8)functionToTest[1] & 0x00FF) << 8)
  566. + ((u8)functionToTest[2] & 0x00FF)),
  567. &compData);
  568. if (res < OK) {
  569. logError(0, "%s Error reading MS compe data:%02X\n",
  570. tag, res);
  571. } else {
  572. logError(0, "%s MS Compensa Reading Finished!\n",
  573. tag);
  574. size = ((compData.node_data_size + 9) * sizeof(u8)) * 2;
  575. print_frame_u8("MS Data (Cx2) = ",
  576. array1dTo2d_u8(compData.node_data,
  577. compData.node_data_size,
  578. compData.header.sense_node),
  579. compData.header.force_node,
  580. compData.header.sense_node);
  581. }
  582. break;
  583. case CMD_READSSCOMPDATA:
  584. if (numberParam != 3) {
  585. logError(1, "%sWrong number of parameters!\n", tag);
  586. res = ERROR_OP_NOT_ALLOW;
  587. break;
  588. }
  589. /*read self comp data*/
  590. logError(0, "%s Get SS Compensation Data...\n", tag);
  591. res = readSelfSenseCompensationData((u16)
  592. ((((u8)functionToTest[1] & 0x00FF) << 8)
  593. + ((u8)functionToTest[2] & 0x00FF)),
  594. &comData);
  595. if (res < OK) {
  596. logError(0, "%s Error reading SS Compensa data %02X\n",
  597. tag, res);
  598. } else {
  599. logError(0, "%s SS Compensa Reading Finished!\n", tag);
  600. size = comData.header.force_node
  601. + comData.header.sense_node;
  602. size = (size * 2 + 12) * sizeof(u8) * 2;
  603. print_frame_u8("SS Data Ix2_fm = ",
  604. array1dTo2d_u8(comData.ix2_fm,
  605. comData.header.force_node,
  606. comData.header.force_node),
  607. 1,
  608. comData.header.force_node);
  609. print_frame_u8("SS Data Cx2_fm = ",
  610. array1dTo2d_u8(comData.cx2_fm,
  611. comData.header.force_node,
  612. comData.header.force_node),
  613. 1,
  614. comData.header.force_node);
  615. print_frame_u8("SS Data Ix2_sn = ",
  616. array1dTo2d_u8(comData.ix2_sn,
  617. comData.header.sense_node,
  618. comData.header.sense_node),
  619. 1,
  620. comData.header.sense_node);
  621. print_frame_u8("SS Data Cx2_sn = ",
  622. array1dTo2d_u8(comData.cx2_sn,
  623. comData.header.sense_node,
  624. comData.header.sense_node),
  625. 1,
  626. comData.header.sense_node);
  627. }
  628. break;
  629. case CMD_READGNCOMPDATA:
  630. if (numberParam != 3) {
  631. logError(1, "%s Wrong number of parameters!\n", tag);
  632. res = ERROR_OP_NOT_ALLOW;
  633. break;
  634. }
  635. /*read self comp data */
  636. logError(0, "%s Get General Compensation Data...\n", tag);
  637. res = readGeneralCompensationData((u16)
  638. ((((u8)functionToTest[1]
  639. & 0x00FF) << 8) + ((u8)functionToTest[2]
  640. & 0x00FF)), &gnData);
  641. if (res < OK) {
  642. logError(0,
  643. "%s Reading General compensa data ERROR %02X\n",
  644. tag, res);
  645. } else {
  646. logError(0, "%s:General compensa Reading Finished!\n",
  647. tag);
  648. size = (14) * sizeof(u8) * 2;
  649. }
  650. break;
  651. case CMD_GETFWVER:
  652. res = getFirmwareVersion(&fw_version, &config_id);
  653. if (res < OK) {
  654. logError(1, "%s Reading firmware version ERROR %02X\n",
  655. tag, res);
  656. } else {
  657. logError(0, "%s getFirmware Version Finished!\n", tag);
  658. size += (4) * sizeof(u8) * 2;
  659. }
  660. break;
  661. #ifdef FTM3_CHIP
  662. case CMD_FLASHSTATUS:
  663. res = flash_status();
  664. /*return 0 = flash ready, 1 = flash busy, <0 error*/
  665. if (res < OK) {
  666. logError(1, "%s Reading flash status ERROR %02X\n",
  667. tag, res);
  668. } else {
  669. logError(0, "%s Flash Status: %d\n", tag, res);
  670. size += (1 * sizeof(u8)) * 2;
  671. /*need to store the value for further display */
  672. temp = res;
  673. /*set res =ok for returning code*/
  674. res = OK;
  675. }
  676. break;
  677. #endif
  678. case CMD_FLASHUNLOCK:
  679. res = flash_unlock();
  680. if (res < OK) {
  681. logError(1, "%s:Impossible Unlock Flash ERROR %02X\n",
  682. tag, res);
  683. } else {
  684. logError(0, "%s Flash Unlock OK!\n", tag);
  685. }
  686. break;
  687. case CMD_READFWFILE:
  688. if (numberParam != 2) {
  689. logError(1, "%s Wrong number of parameters!\n", tag);
  690. res = ERROR_OP_NOT_ALLOW;
  691. break;
  692. }
  693. /*read fw file */
  694. logError(0, "%s Reading FW File...\n", tag);
  695. res = readFwFile(PATH_FILE_FW, &fw, functionToTest[1]);
  696. if (res < OK) {
  697. logError(0, "%s Error reading FW File:%02X\n",
  698. tag, res);
  699. } else {
  700. logError(0, "%s Read FW File Finished!\n", tag);
  701. }
  702. kfree(fw.data);
  703. break;
  704. case CMD_FLASHPROCEDURE:
  705. if (numberParam != 3) {
  706. logError(1, "%s Wrong number of parameters!\n", tag);
  707. res = ERROR_OP_NOT_ALLOW;
  708. break;
  709. }
  710. /*flashing procedure*/
  711. logError(0, "%s Starting Flashing Procedure\n", tag);
  712. res = flashProcedure(PATH_FILE_FW,
  713. functionToTest[1], functionToTest[2]);
  714. if (res < OK) {
  715. logError(0, "%s During flash procedure ERROR %02X",
  716. tag, res);
  717. } else {
  718. logError(0, "%s Flash Procedure Finished!\n", tag);
  719. }
  720. break;
  721. /*ITO TEST*/
  722. case CMD_ITOTEST:
  723. res = production_test_ito();
  724. break;
  725. /*Initialization*/
  726. case CMD_INITTEST:
  727. if (numberParam != 2) {
  728. logError(1, "%s Wrong number of parameters!\n", tag);
  729. res = ERROR_OP_NOT_ALLOW;
  730. break;
  731. }
  732. /*need to specify if if save value on Flash*/
  733. if (functionToTest[1] == 0x01)
  734. res = production_test_initialization();
  735. else
  736. res = production_test_split_initialization(false);
  737. break;
  738. case CMD_MSRAWTEST:
  739. if (numberParam != 2) {
  740. logError(1, "%s Wrong number of parameters!\n", tag);
  741. res = ERROR_OP_NOT_ALLOW;
  742. break;
  743. }
  744. /* MS Raw DATA TEST*/
  745. /* need to specify if stopOnFail */
  746. res = production_test_ms_raw(LIMITS_FILE, functionToTest[1],
  747. &todoDefault);
  748. break;
  749. case CMD_MSINITDATATEST:
  750. /*MS CX DATA TEST*/
  751. if (numberParam != 2) {
  752. logError(1, "%s Wrong number of parameters!\n", tag);
  753. res = ERROR_OP_NOT_ALLOW;
  754. break;
  755. }
  756. /*need to specify if stopOnFail*/
  757. res = production_test_ms_cx(LIMITS_FILE, functionToTest[1],
  758. &todoDefault);
  759. break;
  760. case CMD_SSRAWTEST:
  761. /*SS RAW DATA TEST*/
  762. if (numberParam != 2) {
  763. logError(1, "%s Wrong number of parameters!\n", tag);
  764. res = ERROR_OP_NOT_ALLOW;
  765. break;
  766. }
  767. /*need to specify if stopOnFail*/
  768. res = production_test_ss_raw(LIMITS_FILE, functionToTest[1],
  769. &todoDefault);
  770. break;
  771. case CMD_SSINITDATATEST:
  772. /*SS IX CX DATA TEST*/
  773. if (numberParam != 2) {
  774. logError(1, "%s Wrong number of parameters!\n", tag);
  775. res = ERROR_OP_NOT_ALLOW;
  776. break;
  777. }
  778. /*need to specify if stopOnFail*/
  779. res = production_test_ss_ix_cx(LIMITS_FILE, functionToTest[1],
  780. &todoDefault);
  781. break;
  782. case CMD_MAINTEST:
  783. /*PRODUCTION TEST*/
  784. if (numberParam != 3) {
  785. logError(1, "%s Wrong number of parameters!\n", tag);
  786. res = ERROR_OP_NOT_ALLOW;
  787. break;
  788. }
  789. /*need to specify if stopOnFail and saveInit*/
  790. res = production_test_main(LIMITS_FILE, functionToTest[1],
  791. functionToTest[2], &todoDefault, INIT_FIELD);
  792. break;
  793. case CMD_POWERCYCLE:
  794. res = fts_chip_powercycle(info);
  795. break;
  796. default:
  797. logError(1, "%s COMMAND ID NOT VALID!!\n", tag);
  798. logError(1, "%s Inset a value between 00 and 1E.\n", tag);
  799. res = ERROR_OP_NOT_ALLOW;
  800. break;
  801. }
  802. END:
  803. /**
  804. * here start the reporting phase,
  805. * assembling the data to send in the file node
  806. */
  807. all_strbuff = kmalloc(size, GFP_KERNEL);
  808. memset(all_strbuff, 0, size);
  809. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  810. strlcat(all_strbuff, buff, size);
  811. snprintf(buff, sizeof(buff), "%08X", res);
  812. strlcat(all_strbuff, buff, size);
  813. if (res >= OK) {
  814. /*all the other cases are already*/
  815. /*fine printing only the res.*/
  816. switch (functionToTest[0]) {
  817. case CMD_READ:
  818. case CMD_READU16:
  819. case CMD_READB2:
  820. case CMD_READB2U16:
  821. case CMD_POLLFOREVENT:
  822. for (j = 0; j < byteToRead; j++) {
  823. snprintf(buff, sizeof(buff), "%02X",
  824. readData[j]);
  825. strlcat(all_strbuff, buff, size);
  826. }
  827. break;
  828. case CMD_GETFORCELEN:
  829. case CMD_GETSENSELEN:
  830. case CMD_FLASHSTATUS:
  831. snprintf(buff, sizeof(buff), "%02X", (u8)temp);
  832. strlcat(all_strbuff, buff, size);
  833. break;
  834. case CMD_GETMSFRAME:
  835. snprintf(buff, sizeof(buff), "%02X",
  836. (u8) frameMS.header.force_node);
  837. strlcat(all_strbuff, buff, size);
  838. snprintf(buff, sizeof(buff), "%02X",
  839. (u8)frameMS.header.sense_node);
  840. strlcat(all_strbuff, buff, size);
  841. for (j = 0; j < frameMS.node_data_size; j++) {
  842. snprintf(buff, sizeof(buff), "%04X",
  843. frameMS.node_data[j]);
  844. strlcat(all_strbuff, buff, size);
  845. }
  846. kfree(frameMS.node_data);
  847. break;
  848. case CMD_GETSSFRAME:
  849. snprintf(buff, sizeof(buff), "%02X",
  850. (u8) frameSS.header.force_node);
  851. strlcat(all_strbuff, buff, size);
  852. snprintf(buff, sizeof(buff), "%02X",
  853. (u8)frameSS.header.sense_node);
  854. strlcat(all_strbuff, buff, size);
  855. /* Copying self raw data Force */
  856. for (j = 0; j < frameSS.header.force_node; j++) {
  857. snprintf(buff, sizeof(buff), "%04X",
  858. frameSS.force_data[j]);
  859. strlcat(all_strbuff, buff, size);
  860. }
  861. /* Copying self raw data Sense */
  862. for (j = 0; j < frameSS.header.sense_node; j++) {
  863. snprintf(buff, sizeof(buff), "%04X",
  864. frameSS.sense_data[j]);
  865. strlcat(all_strbuff, buff, size);
  866. }
  867. kfree(frameSS.force_data);
  868. kfree(frameSS.sense_data);
  869. break;
  870. case CMD_READMSCOMPDATA:
  871. snprintf(buff, sizeof(buff), "%02X",
  872. (u8)compData.header.force_node);
  873. strlcat(all_strbuff, buff, size);
  874. snprintf(buff, sizeof(buff), "%02X",
  875. (u8)compData.header.sense_node);
  876. strlcat(all_strbuff, buff, size);
  877. /* Cpying CX1 value */
  878. snprintf(buff, sizeof(buff), "%02X",
  879. compData.cx1);
  880. strlcat(all_strbuff, buff, size);
  881. /* Copying CX2 values */
  882. for (j = 0; j < compData.node_data_size; j++) {
  883. snprintf(buff, sizeof(buff), "%02X",
  884. *(compData.node_data + j));
  885. strlcat(all_strbuff, buff, size);
  886. }
  887. kfree(compData.node_data);
  888. break;
  889. case CMD_READSSCOMPDATA:
  890. snprintf(buff, sizeof(buff), "%02X",
  891. comData.header.force_node);
  892. strlcat(all_strbuff, buff, size);
  893. snprintf(buff, sizeof(buff), "%02X",
  894. comData.header.sense_node);
  895. strlcat(all_strbuff, buff, size);
  896. snprintf(buff, sizeof(buff), "%02X", comData.f_ix1);
  897. strlcat(all_strbuff, buff, size);
  898. snprintf(buff, sizeof(buff), "%02X", comData.s_ix1);
  899. strlcat(all_strbuff, buff, size);
  900. snprintf(buff, sizeof(buff), "%02X", comData.f_cx1);
  901. strlcat(all_strbuff, buff, size);
  902. snprintf(buff, sizeof(buff), "%02X", comData.s_cx1);
  903. strlcat(all_strbuff, buff, size);
  904. /* Copying IX2 Force */
  905. for (j = 0; j < comData.header.force_node; j++) {
  906. snprintf(buff, sizeof(buff), "%02X",
  907. comData.ix2_fm[j]);
  908. strlcat(all_strbuff, buff, size);
  909. }
  910. /* Copying IX2 Sense*/
  911. for (j = 0; j < comData.header.sense_node; j++) {
  912. snprintf(buff, sizeof(buff), "%02X",
  913. comData.ix2_sn[j]);
  914. strlcat(all_strbuff, buff, size);
  915. }
  916. /* Copying CX2 Force */
  917. for (j = 0; j < comData.header.force_node; j++) {
  918. snprintf(buff, sizeof(buff), "%02X",
  919. comData.cx2_fm[j]);
  920. strlcat(all_strbuff, buff, size);
  921. }
  922. /* Copying CX2 Sense */
  923. for (j = 0; j < comData.header.sense_node; j++) {
  924. snprintf(buff, sizeof(buff), "%02X",
  925. comData.cx2_sn[j]);
  926. strlcat(all_strbuff, buff, size);
  927. }
  928. kfree(comData.ix2_fm);
  929. kfree(comData.ix2_sn);
  930. kfree(comData.cx2_fm);
  931. kfree(comData.cx2_sn);
  932. break;
  933. case CMD_READGNCOMPDATA:
  934. snprintf(buff, sizeof(buff), "%02X",
  935. gnData.header.force_node);
  936. strlcat(all_strbuff, buff, size);
  937. snprintf(buff, sizeof(buff), "%02X",
  938. gnData.header.sense_node);
  939. strlcat(all_strbuff, buff, size);
  940. snprintf(buff, sizeof(buff), "%02X",
  941. gnData.ftsd_lp_timer_cal0);
  942. strlcat(all_strbuff, buff, size);
  943. snprintf(buff, sizeof(buff), "%02X",
  944. gnData.ftsd_lp_timer_cal1);
  945. strlcat(all_strbuff, buff, size);
  946. snprintf(buff, sizeof(buff), "%02X",
  947. gnData.ftsd_lp_timer_cal2);
  948. strlcat(all_strbuff, buff, size);
  949. snprintf(buff, sizeof(buff), "%02X",
  950. gnData.ftsd_lp_timer_cal3);
  951. strlcat(all_strbuff, buff, size);
  952. snprintf(buff, sizeof(buff), "%02X",
  953. gnData.ftsa_lp_timer_cal0);
  954. strlcat(all_strbuff, buff, size);
  955. snprintf(buff, sizeof(buff), "%02X",
  956. gnData.ftsa_lp_timer_cal1);
  957. strlcat(all_strbuff, buff, size);
  958. break;
  959. case CMD_GETFWVER:
  960. snprintf(buff, sizeof(buff), "%04X", fw_version);
  961. strlcat(all_strbuff, buff, size);
  962. snprintf(buff, sizeof(buff), "%04X", config_id);
  963. strlcat(all_strbuff, buff, size);
  964. break;
  965. case CMD_READCOMPDATAHEAD:
  966. snprintf(buff, sizeof(buff), "%02X",
  967. dataHead.force_node);
  968. strlcat(all_strbuff, buff, size);
  969. snprintf(buff, sizeof(buff), "%02X",
  970. dataHead.sense_node);
  971. strlcat(all_strbuff, buff, size);
  972. break;
  973. default:
  974. break;
  975. }
  976. }
  977. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  978. strlcat(all_strbuff, buff, size);
  979. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  980. numberParam = 0;
  981. /**
  982. * need to reset the number of parameters
  983. * in order to wait the next command,
  984. * comment if you want to repeat
  985. * the last command sent just doing a cat
  986. */
  987. kfree(readData);
  988. kfree(all_strbuff);
  989. return count;
  990. }
  991. static DEVICE_ATTR_RW(stm_driver_test);
  992. static struct attribute *test_cmd_attributes[] = {
  993. &dev_attr_stm_driver_test.attr,
  994. NULL,
  995. };
  996. struct attribute_group test_cmd_attr_group = {
  997. .attrs = test_cmd_attributes,
  998. };
  999. #endif