ftsError.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. /**
  22. *
  23. **************************************************************************
  24. ** STMicroelectronics **
  25. **************************************************************************
  26. ** [email protected] **
  27. **************************************************************************
  28. * *
  29. * FTS error/info kernel log reporting *
  30. * *
  31. **************************************************************************
  32. **************************************************************************
  33. */
  34. #include <linux/device.h>
  35. #include <linux/init.h>
  36. #include <linux/kernel.h>
  37. #include <linux/module.h>
  38. #include <linux/slab.h>
  39. #include <linux/input.h>
  40. #include <linux/input/mt.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/hrtimer.h>
  43. #include <linux/delay.h>
  44. #include <linux/firmware.h>
  45. #include <linux/i2c.h>
  46. #include <linux/i2c-dev.h>
  47. #include <linux/completion.h>
  48. //#include <linux/wakelock.h>
  49. #include <linux/pm_wakeup.h>
  50. #include <linux/gpio.h>
  51. #include <linux/of_gpio.h>
  52. #include <linux/regulator/consumer.h>
  53. #include "../fts.h"
  54. #include "ftsCrossCompile.h"
  55. #include "ftsError.h"
  56. #include "ftsIO.h"
  57. #include "ftsTool.h"
  58. #include "ftsCompensation.h"
  59. static char tag[8] = "[ FTS ]\0";
  60. void logError(int force, const char *msg, ...)
  61. {
  62. if (force == 1
  63. #ifdef DEBUG
  64. || 1
  65. #endif
  66. ) {
  67. va_list args;
  68. va_start(args, msg);
  69. vprintk(msg, args);
  70. va_end(args);
  71. }
  72. }
  73. int isI2cError(int error)
  74. {
  75. if (((error & 0x000000FF) >= (ERROR_I2C_R & 0x000000FF))
  76. && ((error & 0x000000FF) <= (ERROR_I2C_O & 0x000000FF)))
  77. return 1;
  78. else
  79. return 0;
  80. }
  81. int dumpErrorInfo(void)
  82. {
  83. int ret, i;
  84. u8 data[ERROR_INFO_SIZE] = {0};
  85. u32 sign = 0;
  86. logError(0, "%s %s: Starting dump of error info...\n", tag, __func__);
  87. if (ftsInfo.u16_errOffset == INVALID_ERROR_OFFS) {
  88. logError(1, "%s %s: Invalid error offset ERROR %02X\n",
  89. tag, __func__, ERROR_OP_NOT_ALLOW);
  90. return ERROR_OP_NOT_ALLOW;
  91. }
  92. ret = readCmdU16(FTS_CMD_FRAMEBUFFER_R, ftsInfo.u16_errOffset,
  93. data, ERROR_INFO_SIZE, DUMMY_FRAMEBUFFER);
  94. if (ret < OK) {
  95. logError(1, "%s %s: reading data ERROR %02X\n",
  96. tag, __func__, ret);
  97. return ret;
  98. }
  99. logError(0, "%s %s: Error Info =\n", tag, __func__);
  100. u8ToU32(data, &sign);
  101. if (sign != ERROR_SIGNATURE)
  102. logError(1, "%s %s:Wrong Signature! Data may be invalid!\n",
  103. tag, __func__);
  104. else
  105. logError(1, "%s %s: Error Signature OK! Data are valid!\n",
  106. tag, __func__);
  107. for (i = 0; i < ERROR_INFO_SIZE; i++) {
  108. if (i % 4 == 0)
  109. logError(1, KERN_ERR "\n%s %s: %d) ",
  110. tag, __func__, i / 4);
  111. logError(1, "%02X ", data[i]);
  112. }
  113. logError(1, "\n");
  114. logError(0, "%s %s: dump of error info FINISHED!\n", tag, __func__);
  115. return OK;
  116. }
  117. int errorHandler(u8 *event, int size)
  118. {
  119. int res = OK;
  120. struct fts_ts_info *info = NULL;
  121. if (getClient() != NULL)
  122. info = i2c_get_clientdata(getClient());
  123. if (info == NULL || event == NULL || size <= 1 || event[0] !=
  124. EVENTID_ERROR_EVENT) {
  125. logError(1, "%s %s: event Null or not correct size! ",
  126. tag, __func__, ERROR_OP_NOT_ALLOW);
  127. logError(1, "ERROR %08X\n", ERROR_OP_NOT_ALLOW);
  128. return ERROR_OP_NOT_ALLOW;
  129. }
  130. logError(0, "%s %s: Starting handling...\n", tag, __func__);
  131. //TODO: write an error log for undefinied command subtype 0xBA
  132. switch (event[1]) {
  133. case EVENT_TYPE_ESD_ERROR: //esd
  134. res = fts_chip_powercycle(info);
  135. if (res < OK) {
  136. logError(1, "%s %s: ", tag, res);
  137. logError(1, "Error performing powercycle ERROR %08X\n");
  138. }
  139. res = fts_system_reset();
  140. if (res < OK)
  141. logError(1, "%s %s:Cannot reset device ERROR%08X\n",
  142. tag, __func__, res);
  143. res = (ERROR_HANDLER_STOP_PROC | res);
  144. break;
  145. case EVENT_TYPE_WATCHDOG_ERROR: //watchdog
  146. dumpErrorInfo();
  147. res = fts_system_reset();
  148. if (res < OK)
  149. logError(1, "%s %s:Cannot reset device:ERROR%08X\n",
  150. tag, __func__, res);
  151. res = (ERROR_HANDLER_STOP_PROC | res);
  152. break;
  153. case EVENT_TYPE_CHECKSUM_ERROR: //CRC ERRORS
  154. switch (event[2]) {
  155. case CRC_CONFIG_SIGNATURE:
  156. logError(1, "%s %s: Config Signature ERROR!\n",
  157. tag, __func__);
  158. break;
  159. case CRC_CONFIG:
  160. logError(1, "%s %s:Config CRC ERROR!\n", tag, __func__);
  161. break;
  162. case CRC_CX_MEMORY:
  163. logError(1, "%s %s: CX CRC ERROR!\n", tag, __func__);
  164. break;
  165. }
  166. break;
  167. case EVENT_TYPE_LOCKDOWN_ERROR:
  168. //res = (ERROR_HANDLER_STOP_PROC|res);
  169. //stop lockdown code routines in order to retry
  170. switch (event[2]) {
  171. case 0x01:
  172. logError(1, "%s %s:Lockdown code alredy ",
  173. tag, __func__);
  174. logError(1, "written into the IC!\n");
  175. break;
  176. case 0x02:
  177. logError(1, "%s %s:Lockdown CRC ", tag, __func__);
  178. logError(1, "check fail during a WRITE!\n");
  179. break;
  180. case 0x03:
  181. logError(1,
  182. "%s %s:Lockdown WRITE command format wrong!\n",
  183. tag, __func__);
  184. break;
  185. case 0x04:
  186. pr_err("Lockdown Memory Corrupted!\n");
  187. logError(1, "%s %s:Please contact ST for support!\n",
  188. tag, __func__);
  189. break;
  190. case 0x11:
  191. logError(1,
  192. "%s %s:NO Lockdown code to READ into the IC!\n",
  193. tag, __func__);
  194. break;
  195. case 0x12:
  196. logError(1,
  197. "%s %s:Lockdown code data corrupted\n",
  198. tag, __func__);
  199. break;
  200. case 0x13:
  201. logError(1,
  202. "%s %s:Lockdown READ command format wrong!\n",
  203. tag, __func__);
  204. break;
  205. case 0x21:
  206. pr_err("Exceeded maximum number of\n");
  207. logError(1,
  208. "%s %s:Lockdown code REWRITE into IC!\n",
  209. tag, __func__);
  210. break;
  211. case 0x22:
  212. logError(1, "%s %s:Lockdown CRC check", tag, __func__);
  213. logError(1, " fail during a REWRITE!\n");
  214. break;
  215. case 0x23:
  216. logError(1, "%s %s:", tag, __func__);
  217. logError(1, "Lockdown REWRITE command format wrong!\n");
  218. break;
  219. case 0x24:
  220. pr_err("Lockdown Memory Corrupted!\n");
  221. logError(1, "%s %s:Please contact ST for support!\n",
  222. tag, __func__);
  223. break;
  224. default:
  225. logError(1, "%s %s:No valid error type for LOCKDOWN!\n",
  226. tag, __func__);
  227. }
  228. break;
  229. default:
  230. logError(0, "%s %s: No Action taken!\n", tag, __func__);
  231. break;
  232. }
  233. logError(0, "%s %s: handling Finished! res = %08X\n",
  234. tag, __func__, res);
  235. return res;
  236. }