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