1 #include <linux/vmalloc.h>
2 #include <asm/uaccess.h>
3 #include <linux/major.h>
4 #include <linux/miscdevice.h>
6 #include <linux/delay.h>
10 int tpd_fail_count
= 0;
11 int tpd_trial_count
= 0;
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};
28 int wakeup_count
= 200;
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;
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
++;
44 printk("trial: %d / fail: %d\n", tpd_trial_count
, tpd_fail_count
);
45 delay_index
= ((delay_index
+1)%delay_max
);
47 trial_index
= ((trial_index
+1)%trial_max
);
51 module_param(tpd_debug_nr
, int, 00644);
52 module_param(tpd_fail_count
, int, 00644);
53 module_param(tpd_trial_count
, int, 00644);
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;
60 int tpd_down_status
= 0;
61 module_param(tpd_debug_time
, int, 00644);
63 void tpd_debug_set_time() {
66 if (!tpd_debug_time
&& !tpd_em_log
) return;
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
;
73 // Start profiling while receive touch DOWN event
74 // Stop profiling while the first frame is upadted
76 if (!tpd_down_status
) {
77 tpd_start_profiling
= 1;
78 tpd_last_down_time
= tpd_last_2_int_time
[1];
82 #ifdef TPD_DEBUG_TRACK
84 int DAL_Printf(const char *fmt
, ...);
85 int LCD_LayerEnable(int id
, BOOL enable
);
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);
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
);
99 void tpd_down_debug_track(int x
, int y
) {
100 if(tpd_debug_touch_up
== 1) {
102 tpd_debug_touch_up
= 0;
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);
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;
115 #endif // TPD_DEBUG_TRACK
118 #define BUFFER_SIZE 128
121 module_param(tpd_em_log
, int, 00664);
123 void tpd_enable_em_log(int enable
)
131 EXPORT_SYMBOL(tpd_enable_em_log
);
134 int tpd_em_log_to_fs
= 0;
135 module_param(tpd_em_log_to_fs
, int, 00664);
137 int tpd_em_log_first
= 1;
139 struct tpd_em_log_struct
141 struct list_head list
;
142 char data
[BUFFER_SIZE
];
144 static LIST_HEAD(tpd_em_log_list
);
147 static void *tpd_em_log_seq_start(struct seq_file
*seq
, loff_t
*pos
)
149 struct tpd_em_log_struct
*p
;
152 list_for_each_entry(p
, &tpd_em_log_list
, list
) {
153 if (*pos
== off
++) return p
;
158 static void *tpd_em_log_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
160 struct list_head
*n
= ((struct tpd_em_log_struct
*) v
)->list
.next
;
164 return (n
!= &tpd_em_log_list
) ? list_entry(n
, struct tpd_em_log_struct
, list
) : NULL
;
167 static void tpd_em_log_seq_stop(struct seq_file
*s
, void *v
)
169 struct tpd_em_log_struct
*p
, *p_tmp
;
170 list_for_each_entry_safe(p
, p_tmp
, &tpd_em_log_list
, list
) {
176 static int tpd_em_log_seq_show(struct seq_file
*seq
, void *v
)
178 const struct tpd_em_log_struct
*p
= v
;
179 seq_printf(seq
, p
->data
);
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
193 static int tpd_em_log_open(struct inode
*inode
, struct file
*file
) {
194 return seq_open(file
, &tpd_em_log_seq_ops
);
197 static struct file_operations tpd_em_log_file_ops
= {
198 .owner
= THIS_MODULE
,
199 .open
= tpd_em_log_open
,
202 .release
= seq_release
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);
211 struct tpd_debug_log_buf
215 spinlock_t buffer_lock
;
217 unsigned char *buffer
;
220 struct tpd_debug_log_buf tpd_buf
;
222 static int tpd_debug_log_open(struct inode
*inode
, struct file
*file
)
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
)
228 printk("tpd_log: nomem for tpd_buf->buffer\n");
231 tpd_buf
.head
= tpd_buf
.tail
= 0;
232 spin_lock_init(&tpd_buf
.buffer_lock
);
234 file
->private_data
= &tpd_buf
;
235 printk("[tpd_em_log]: open log file\n");
239 static int tpd_debug_log_release(struct inode
*inode
, struct file
*file
)
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
);
248 static ssize_t
tpd_debug_log_write(struct file
*file
, const char __user
*buffer
,
249 size_t count
, loff_t
*ppos
)
254 static ssize_t
tpd_debug_log_read(struct file
*file
, char __user
*buffer
,
255 size_t count
, loff_t
*ppos
)
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
;
262 if (tpd_buf
->head
== tpd_buf
->tail
&&
263 (file
->f_flags
& O_NONBLOCK
))
267 while ((count
- retval
) >= unit
) {
268 spin_lock_irq(&tpd_buf
->buffer_lock
);
269 if(tpd_buf
->head
!= tpd_buf
->tail
)
271 tmp_buf
= &tpd_buf
->buffer
[tpd_buf
->tail
++*unit
];
272 tpd_buf
->tail
&= tpd_log_line_cnt
- 1;
276 //printk("*******************tpd_debug_log is empty **************************************\n");
277 spin_unlock_irq(&tpd_buf
->buffer_lock
);
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
))
294 static unsigned char* tpd_log_find_buffer(void)
296 unsigned char *buffer
= NULL
;
297 unsigned unit
= tpd_log_line_buffer
;
298 if(tpd_buf
.buffer
== NULL
)
300 printk( "[tpd_em_log] :tpd_buf.buffer is NULL \n");
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
)
309 snprintf(buffer
, unit
, "[tpd_em_log] overlay !!!!!\n");
312 memset(buffer
, 0, unit
);
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
,
324 static struct miscdevice tpd_debug_log_dev
= {
325 .minor
= MISC_DYNAMIC_MINOR
,
326 .name
= "tpd_em_log",
327 .fops
= &tpd_debug_log_fops
,
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
);
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);
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);
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;
365 if (tpd_em_log_first
) {
366 entry
= create_proc_entry("tpd_em_log", 0, NULL
);
368 entry
->proc_fops
= &tpd_em_log_file_ops
;
370 tpd_em_log_first
= 0;
373 tpd_em_log_struct_new
= kmalloc(sizeof(struct tpd_em_log_struct
), GFP_ATOMIC
);
375 memset(tpd_em_log_struct_new
, 0, sizeof(struct tpd_em_log_struct
));
377 unsigned char *buffer
= NULL
;
378 //unsigned int unit = tpd_log_line_buffer;
380 //printk("[tpd_em_log]: start register log file");
383 buffer
= tpd_log_find_buffer();
386 printk("not buffer \n");
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
);
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);
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);
420 //list_add_tail(&tpd_em_log_struct_new->list, &tpd_em_log_list);
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
);
428 list_for_each_entry_safe(p
, p_tmp
, &tpd_em_log_list
, list
) {
433 tpd_em_log_first
= 1;
434 tpd_em_log_to_fs
= 0;
438 static int __init
tpd_log_init(void)
440 if (misc_register(&tpd_debug_log_dev
) < 0)
442 printk( "[tpd_em_log] :register device failed \n");
445 printk( "[tpd_em_log] :register device successfully \n");
449 int tpd_debuglog
= 0;
450 module_param(tpd_debuglog
, int, 00664);
452 module_init(tpd_log_init
);
453 #endif // TPD_DEBUG_CODE