tpd_debug.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. #include <linux/vmalloc.h>
  2. #include <linux/uaccess.h>
  3. #include <linux/major.h>
  4. #include <linux/miscdevice.h>
  5. #include <linux/i2c.h>
  6. #include <linux/delay.h>
  7. #include "tpd.h"
  8. #include "met_ftrace_touch.h"
  9. #ifdef TPD_DEBUG_CODE
  10. int tpd_fail_count = 0;
  11. int tpd_trial_count = 0;
  12. void tpd_debug_no_response(struct i2c_client *i2c_client)
  13. {
  14. char sleep[2] = { 0x07, 0x01 };
  15. char wakeup[2] = { 0x07, 0x02 };
  16. char threshold[2] = { 0x09, 0x04 };
  17. char gesture[2] = { 0x08, 0x11 };
  18. char sleeptime[2] = { 0x0d, 0x01 };
  19. char idletime[2] = { 0x0c, 0xff };
  20. static int trial_index;
  21. static int delay_index;
  22. int trial[] = { 1, 9, 2, 8, 3, 7, 4, 6, 5 };
  23. int delay[] = { 1, 100, 2, 50, 3, 25, 4, 12, 5, 6, 6, 1, 1, 500, 500 };
  24. int trial_max = 9;
  25. int delay_max = 15;
  26. int i, j;
  27. int wakeup_count = 200;
  28. for (i = 0; i < trial[trial_index]; i++) {
  29. i2c_master_send(i2c_client, sleep, 2);
  30. msleep(delay[delay_index]);
  31. for (j = 0; j < wakeup_count; j++) {
  32. i2c_master_send(i2c_client, wakeup, 2);
  33. if (i2c_master_send(i2c_client, wakeup, 2) == 2)
  34. break;
  35. msleep(20);
  36. }
  37. if (i2c_master_send(i2c_client, gesture, 2) != 2)
  38. i = wakeup_count;
  39. if (i2c_master_send(i2c_client, threshold, 2) != 2)
  40. i = wakeup_count;
  41. if (i2c_master_send(i2c_client, idletime, 2) != 2)
  42. i = wakeup_count;
  43. if (i2c_master_send(i2c_client, sleeptime, 2) != 2)
  44. i = wakeup_count;
  45. if (i == wakeup_count)
  46. tpd_fail_count++;
  47. tpd_trial_count++;
  48. pr_err("trial: %d / fail: %d\n", tpd_trial_count, tpd_fail_count);
  49. delay_index = ((delay_index + 1) % delay_max);
  50. }
  51. trial_index = ((trial_index + 1) % trial_max);
  52. }
  53. int tpd_debug_nr = 0;
  54. module_param(tpd_debug_nr, int, 0644);
  55. module_param(tpd_fail_count, int, 0644);
  56. module_param(tpd_trial_count, int, 0644);
  57. int tpd_debug_time = 0;
  58. long tpd_last_2_int_time[2] = { 0 };
  59. long tpd_last_down_time = 0;
  60. int tpd_start_profiling = 0;
  61. int tpd_down_status = 0;
  62. module_param(tpd_debug_time, int, 0644);
  63. void tpd_debug_set_time(void)
  64. {
  65. struct timeval t;
  66. if (!tpd_debug_time && !tpd_em_log)
  67. return;
  68. do_gettimeofday(&t);
  69. tpd_last_2_int_time[0] = tpd_last_2_int_time[1];
  70. tpd_last_2_int_time[1] = (t.tv_sec & 0xFFF) * 1000000 + t.tv_usec;
  71. /* */
  72. /* Start profiling while receive touch DOWN event */
  73. /* Stop profiling while the first frame is upadted */
  74. /* */
  75. if (!tpd_down_status) {
  76. tpd_start_profiling = 1;
  77. tpd_last_down_time = tpd_last_2_int_time[1];
  78. }
  79. }
  80. #ifdef TPD_DEBUG_TRACK
  81. int tpd_debug_track = 0;
  82. int tpd_debug_track_color = 0;
  83. int tpd_debug_touch_up = 0;
  84. module_param(tpd_debug_track, int, 0644);
  85. void tpd_draw(int x, int y)
  86. {
  87. UINT16 *buf = (UINT16 *) dal_fb_addr;
  88. buf = buf + (x + y * TPD_RES_X);
  89. tpd_debug_track_color += (tpd_debug_track_color >= 31 ? 0 : 1);
  90. *buf = (0xffe0 + tpd_debug_track_color);
  91. }
  92. void tpd_down_debug_track(int x, int y)
  93. {
  94. if (tpd_debug_touch_up == 1) {
  95. DAL_Clean();
  96. tpd_debug_touch_up = 0;
  97. }
  98. LCD_LayerEnable(5, TRUE);
  99. tpd_draw(x - 1, y - 1);
  100. tpd_draw(x, y - 1);
  101. tpd_draw(x + 1, y - 1);
  102. tpd_draw(x - 1, y);
  103. tpd_draw(x + 1, y);
  104. tpd_draw(x - 1, y + 1);
  105. tpd_draw(x, y + 1);
  106. tpd_draw(x + 1, y + 1);
  107. }
  108. void tpd_up_debug_track(int x, int y)
  109. {
  110. if (x == 0 && y == 0) {
  111. tpd_debug_track_color = 0;
  112. DAL_Clean();
  113. }
  114. tpd_debug_touch_up = 1;
  115. }
  116. #endif /* TPD_DEBUG_TRACK */
  117. #define BUFFER_SIZE 128
  118. int tpd_em_log = 0;
  119. module_param(tpd_em_log, int, 0664);
  120. void tpd_enable_em_log(int enable)
  121. {
  122. if (enable)
  123. tpd_em_log = 1;
  124. else
  125. tpd_em_log = 0;
  126. }
  127. EXPORT_SYMBOL(tpd_enable_em_log);
  128. int tpd_em_log_to_fs = 0;
  129. module_param(tpd_em_log_to_fs, int, 0664);
  130. int tpd_em_log_first = 1;
  131. struct tpd_em_log_struct {
  132. struct list_head list;
  133. char data[BUFFER_SIZE];
  134. };
  135. static LIST_HEAD(tpd_em_log_list);
  136. #if 0
  137. static void *tpd_em_log_seq_start(struct seq_file *seq, loff_t *pos)
  138. {
  139. struct tpd_em_log_struct *p;
  140. loff_t off = 0;
  141. list_for_each_entry(p, &tpd_em_log_list, list) {
  142. if (*pos == off++)
  143. return p;
  144. }
  145. return NULL;
  146. }
  147. static void *tpd_em_log_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  148. {
  149. struct list_head *n = ((struct tpd_em_log_struct *)v)->list.next;
  150. ++*pos;
  151. return (n != &tpd_em_log_list) ? list_entry(n, struct tpd_em_log_struct, list) : NULL;
  152. }
  153. static void tpd_em_log_seq_stop(struct seq_file *s, void *v)
  154. {
  155. struct tpd_em_log_struct *p, *p_tmp;
  156. list_for_each_entry_safe(p, p_tmp, &tpd_em_log_list, list) {
  157. list_del(&p->list);
  158. kfree(p);
  159. }
  160. }
  161. static int tpd_em_log_seq_show(struct seq_file *seq, void *v)
  162. {
  163. const struct tpd_em_log_struct *p = v;
  164. seq_printf(seq, p->data);
  165. return 0;
  166. }
  167. static const struct seq_operations tpd_em_log_seq_ops = {
  168. .start = tpd_em_log_seq_start,
  169. .next = tpd_em_log_seq_next,
  170. .stop = tpd_em_log_seq_stop,
  171. .show = tpd_em_log_seq_show
  172. };
  173. static int tpd_em_log_open(struct inode *inode, struct file *file)
  174. {
  175. return seq_open(file, &tpd_em_log_seq_ops);
  176. };
  177. static const struct file_operations tpd_em_log_file_ops = {
  178. .owner = THIS_MODULE,
  179. .open = tpd_em_log_open,
  180. .read = seq_read,
  181. .llseek = seq_lseek,
  182. .release = seq_release
  183. };
  184. #endif
  185. int tpd_log_line_buffer = 128; /* per line 128 bytes */
  186. int tpd_log_line_cnt = 1024 * 10;
  187. module_param(tpd_log_line_buffer, int, 0664);
  188. module_param(tpd_log_line_cnt, int, 0664);
  189. struct tpd_debug_log_buf {
  190. unsigned int head;
  191. unsigned int tail;
  192. spinlock_t buffer_lock;
  193. unsigned int cnt;
  194. unsigned char *buffer;
  195. };
  196. struct tpd_debug_log_buf tpd_buf;
  197. static int tpd_debug_log_open(struct inode *inode, struct file *file)
  198. {
  199. memset(&tpd_buf, 0, sizeof(struct tpd_debug_log_buf));
  200. tpd_buf.buffer = vmalloc(tpd_log_line_cnt * tpd_log_line_buffer);
  201. if (tpd_buf.buffer == NULL) {
  202. pr_err("tpd_log: nomem for tpd_buf->buffer\n");
  203. return -ENOMEM;
  204. }
  205. tpd_buf.head = tpd_buf.tail = 0;
  206. spin_lock_init(&tpd_buf.buffer_lock);
  207. file->private_data = &tpd_buf;
  208. pr_debug("[tpd_em_log]: open log file\n");
  209. return 0;
  210. }
  211. static int tpd_debug_log_release(struct inode *inode, struct file *file)
  212. {
  213. /* struct tpd_debug_log_buf *tpd_buf = (tpd_debug_log_buf *)file->private_data; */
  214. pr_debug("[tpd_em_log]: close log file\n");
  215. vfree(tpd_buf.buffer);
  216. /* free(tpd_buf); */
  217. return 0;
  218. }
  219. static ssize_t tpd_debug_log_write(struct file *file, const char __user *buffer,
  220. size_t count, loff_t *ppos)
  221. {
  222. return 0;
  223. }
  224. static ssize_t tpd_debug_log_read(struct file *file, char __user *buffer,
  225. size_t count, loff_t *ppos)
  226. {
  227. struct tpd_debug_log_buf *tpd_buf = (struct tpd_debug_log_buf *)file->private_data;
  228. unsigned int retval = 0, unit = tpd_log_line_buffer;
  229. unsigned char *tmp_buf = NULL;
  230. if (tpd_buf->head == tpd_buf->tail && (file->f_flags & O_NONBLOCK))
  231. return -EAGAIN;
  232. while ((count - retval) >= unit) {
  233. spin_lock_irq(&tpd_buf->buffer_lock);
  234. if (tpd_buf->head != tpd_buf->tail) {
  235. tmp_buf = &tpd_buf->buffer[tpd_buf->tail++ * unit];
  236. tpd_buf->tail &= tpd_log_line_cnt - 1;
  237. } else {
  238. /* printk("*******************tpd_debug_log is empty ****************\n"); */
  239. spin_unlock_irq(&tpd_buf->buffer_lock);
  240. break;
  241. }
  242. spin_unlock_irq(&tpd_buf->buffer_lock);
  243. /* printk("%s, tmp_buf:0x%x\n", tmp_buf, tmp_buf); */
  244. if (copy_to_user(buffer + retval, tmp_buf, unit))
  245. return -EFAULT;
  246. retval += unit;
  247. }
  248. return retval;
  249. }
  250. static unsigned char *tpd_log_find_buffer(void)
  251. {
  252. unsigned char *buffer = NULL;
  253. unsigned unit = tpd_log_line_buffer;
  254. if (tpd_buf.buffer == NULL) {
  255. pr_err("[tpd_em_log] :tpd_buf.buffer is NULL\n");
  256. return NULL;
  257. }
  258. spin_lock(&tpd_buf.buffer_lock);
  259. buffer = &tpd_buf.buffer[tpd_buf.head++ * unit];
  260. tpd_buf.head &= tpd_log_line_cnt - 1;
  261. spin_unlock(&tpd_buf.buffer_lock);
  262. if (tpd_buf.head == tpd_buf.tail) {
  263. snprintf(buffer, unit, "[tpd_em_log] overlay !!!!!\n");
  264. return NULL;
  265. }
  266. memset(buffer, 0, unit);
  267. return buffer;
  268. }
  269. static const struct file_operations tpd_debug_log_fops = {
  270. .owner = THIS_MODULE,
  271. .read = tpd_debug_log_read,
  272. .write = tpd_debug_log_write,
  273. .open = tpd_debug_log_open,
  274. .release = tpd_debug_log_release,
  275. };
  276. static struct miscdevice tpd_debug_log_dev = {
  277. .minor = MISC_DYNAMIC_MINOR,
  278. .name = "tpd_em_log",
  279. .fops = &tpd_debug_log_fops,
  280. };
  281. #ifndef CREATE_TRACE_POINTS
  282. #define CREATE_TRACE_POINTS
  283. #endif
  284. noinline void MET_touch(int raw_x, int raw_y, int cal_x, int cal_y, int p, int down)
  285. {
  286. struct timeval t;
  287. do_gettimeofday(&t);
  288. if ((tpd_down_status == 0 && down == 1) || (tpd_down_status == 1 && down == 0)) {
  289. trace_MET_touch("EV_EKY", t.tv_sec, t.tv_usec, "BIT_TOUCH", down);
  290. tpd_down_status = !tpd_down_status;
  291. }
  292. if (tpd_down_status) {
  293. trace_MET_touch("EV_ABS", t.tv_sec, t.tv_usec, "X", raw_x);
  294. trace_MET_touch("EV_ABS", t.tv_sec, t.tv_usec, "Y", raw_y);
  295. }
  296. }
  297. void tpd_em_log_output(int raw_x, int raw_y, int cal_x, int cal_y, int p, int down)
  298. {
  299. if (down == TPD_TYPE_INT_DOWN) {
  300. pr_debug("[tpd_em_log] int trigger down\n");
  301. } else if (down == TPD_TYPE_INT_UP) {
  302. pr_debug("[tpd_em_log] int trigger up\n");
  303. } else if (down == TPD_TYPE_TIMER) {
  304. pr_debug("[tpd_em_log] timer trigger\n");
  305. } else if (down == TPD_TYPE_RAW_DATA) {
  306. if (tpd_em_log == TPD_TYPE_RAW_DATA) {
  307. pr_debug("[tpd_em_log] rx=%d,ry=%d,rz1=%d,rz2=%d,p=%d,r\n",
  308. raw_x, raw_y, cal_x, cal_y, p);
  309. }
  310. } else if (down == TPD_TYPE_REJECT1) {
  311. pr_debug("[tpd_em_log] the first or last point is rejected\n");
  312. } else if (down == TPD_TYPE_REJECT2) {
  313. pr_debug
  314. ("[tpd_em_log] pressure(%d) > NICE_PRESSURE(%d), debounce debt0:%d ms, debt1:%d ms, spl_num:%d\n",
  315. raw_x, raw_y, cal_x, cal_y, p);
  316. } else if (down == TPD_TYPE_FIST_LATENCY) {
  317. pr_debug("[tpd_em_log] The first touch latency is %d ms\n", raw_x / 1000);
  318. } else if (down && tpd_down_status == 0) {
  319. pr_debug("[tpd_em_log] rx=%d,ry=%d,cx=%d,cy=%d,p=%d,d(+%ld ms)\n",
  320. raw_x, raw_y, cal_x, cal_y, p,
  321. (tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000);
  322. } else if (down && tpd_down_status != 0) {
  323. pr_debug("[tpd_em_log] rx=%d,ry=%d,cx=%d,cy=%d,p=%d,m(+%ld ms)\n",
  324. raw_x, raw_y, cal_x, cal_y, p,
  325. (tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000);
  326. } else {
  327. pr_debug("[tpd_em_log] rx=%d,ry=%d,cx=%d,cy=%d,p=%d,u(+%ld ms)\n",
  328. raw_x, raw_y, cal_x, cal_y, p,
  329. (tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000);
  330. }
  331. }
  332. void tpd_em_log_store(int raw_x, int raw_y, int cal_x, int cal_y, int p, int down)
  333. {
  334. /* static struct proc_dir_entry *entry = NULL; */
  335. /* struct tpd_em_log_struct *tpd_em_log_struct_new; */
  336. struct timeval t;
  337. #if 0
  338. if (tpd_em_log_first) {
  339. entry = create_proc_entry("tpd_em_log", 0, NULL);
  340. if (entry)
  341. entry->proc_fops = &tpd_em_log_file_ops;
  342. tpd_em_log_first = 0;
  343. return;
  344. }
  345. tpd_em_log_struct_new = kmalloc(sizeof(struct tpd_em_log_struct), GFP_ATOMIC);
  346. memset(tpd_em_log_struct_new, 0, sizeof(struct tpd_em_log_struct));
  347. #else
  348. unsigned char *buffer = NULL;
  349. /* unsigned int unit = tpd_log_line_buffer; */
  350. /* printk("[tpd_em_log]: start register log file"); */
  351. #endif
  352. buffer = tpd_log_find_buffer();
  353. if (buffer == NULL) {
  354. pr_err("not buffer\n");
  355. return;
  356. }
  357. do_gettimeofday(&t);
  358. if (down == TPD_TYPE_INT_DOWN) {
  359. snprintf(buffer, tpd_log_line_buffer, "[%5lu.%06lu][tpd_em_log] int trigger down\n",
  360. (t.tv_sec & 0xFFF), t.tv_usec);
  361. } else if (down == TPD_TYPE_INT_UP) {
  362. snprintf(buffer, tpd_log_line_buffer, "[%5lu.%06lu][tpd_em_log] int trigger up\n",
  363. (t.tv_sec & 0xFFF), t.tv_usec);
  364. } else if (down == TPD_TYPE_TIMER) {
  365. snprintf(buffer, tpd_log_line_buffer, "[%5lu.%06lu][tpd_em_log] timer trigger\n",
  366. (t.tv_sec & 0xFFF), t.tv_usec);
  367. } else if (down == TPD_TYPE_RAW_DATA) {
  368. if (tpd_em_log == TPD_TYPE_RAW_DATA) {
  369. snprintf(buffer, tpd_log_line_buffer,
  370. "[%5lu.%06lu][tpd_em_log] rx=%d,ry=%d,rz1=%d,rz2=%d,p=%d,r\n",
  371. (t.tv_sec & 0xFFF), t.tv_usec, raw_x, raw_y, cal_x, cal_y, p);
  372. }
  373. } else if (down == TPD_TYPE_REJECT1) {
  374. snprintf(buffer, tpd_log_line_buffer,
  375. "[%5lu.%06lu][tpd_em_log] the first or last point is rejected\n",
  376. (t.tv_sec & 0xFFF), t.tv_usec);
  377. } else if (down == TPD_TYPE_REJECT2) {
  378. snprintf(buffer, tpd_log_line_buffer,
  379. "[%5lu.%06lu][tpd_em_log] pressure(%d) > NICE_PRESSURE(%d), debounce debt0:%d, debt1:%d, spl_num:%d\n",
  380. (t.tv_sec & 0xFFF), t.tv_usec, raw_x, raw_y, cal_x, cal_y, p);
  381. } else if (down == TPD_TYPE_FIST_LATENCY) {
  382. snprintf(buffer, tpd_log_line_buffer,
  383. "[%5lu.%06lu][tpd_em_log] The first touch latency is %d ms\n",
  384. (t.tv_sec & 0xFFF), t.tv_usec, raw_x / 1000);
  385. } else if (down && tpd_down_status == 0) {
  386. snprintf(buffer, tpd_log_line_buffer,
  387. "[%5lu.%06lu][tpd_em_log] rx=%d,ry=%d,cx=%d,cy=%d,p=%d,d(+%ld ms)\n",
  388. (t.tv_sec & 0xFFF), t.tv_usec, raw_x, raw_y, cal_x, cal_y, p,
  389. (tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000);
  390. } else if (down && tpd_down_status != 0) {
  391. snprintf(buffer, tpd_log_line_buffer,
  392. "[%5lu.%06lu][tpd_em_log] rx=%d,ry=%d,cx=%d,cy=%d,p=%d,d(+%ld ms)\n",
  393. (t.tv_sec & 0xFFF), t.tv_usec, raw_x, raw_y, cal_x, cal_y, p,
  394. (tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000);
  395. } else {
  396. snprintf(buffer, tpd_log_line_buffer,
  397. "[%5lu.%06lu][tpd_em_log] rx=%d,ry=%d,cx=%d,cy=%d,p=%d,u(+%ld ms)\n",
  398. (t.tv_sec & 0xFFF), t.tv_usec, raw_x, raw_y, cal_x, cal_y, p,
  399. (tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000);
  400. }
  401. /* list_add_tail(&tpd_em_log_struct_new->list, &tpd_em_log_list); */
  402. }
  403. void tpd_em_log_release(void)
  404. {
  405. struct tpd_em_log_struct *p, *p_tmp;
  406. if (!tpd_em_log_first) {
  407. remove_proc_entry("tpd_em_log", NULL);
  408. list_for_each_entry_safe(p, p_tmp, &tpd_em_log_list, list) {
  409. list_del(&p->list);
  410. kfree(p);
  411. }
  412. tpd_em_log_first = 1;
  413. tpd_em_log_to_fs = 0;
  414. }
  415. }
  416. static int __init tpd_log_init(void)
  417. {
  418. if (misc_register(&tpd_debug_log_dev) < 0) {
  419. pr_err("[tpd_em_log] :register device failed\n");
  420. return -1;
  421. }
  422. pr_warn("[tpd_em_log] :register device successfully\n");
  423. return 0;
  424. }
  425. int tpd_debuglog = 0;
  426. module_param(tpd_debuglog, int, 0664);
  427. module_init(tpd_log_init);
  428. #endif /* TPD_DEBUG_CODE */