import PULS_20180308
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / input / touchscreen / mediatek / GT9XX_hotknot / goodix_tool.c
1 /* drivers/input/touchscreen/goodix_tool.c
2 *
3 * 2010 - 2012 Goodix Technology.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be a reference
11 * to you, when you are integrating the GOODiX's CTP IC into your system,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * Version:1.2
17 * V1.0:2012/05/01,create file.
18 * V1.2:2012/10/17,reset_guitar etc.
19 * V1.4: 2013/06/08, new proc name
20 */
21
22 #include "tpd.h"
23 #include <linux/interrupt.h>
24 #include <cust_eint.h>
25 #include <linux/i2c.h>
26 #include <linux/sched.h>
27 #include <linux/kthread.h>
28 #include <linux/rtpm_prio.h>
29 #include <linux/wait.h>
30 #include <linux/time.h>
31 #include <linux/delay.h>
32 #include "cust_gpio_usage.h"
33 #include <linux/device.h>
34 #include <linux/miscdevice.h>
35 #include <asm/uaccess.h>
36 #include <linux/proc_fs.h> /*proc*/
37
38 #include "tpd_custom_gt9xx.h"
39 #pragma pack(1)
40 typedef struct
41 {
42 u8 wr; //write read flag£¬0:R 1:W 2:PID 3:
43 u8 flag; //0:no need flag/int 1: need flag 2:need int
44 u8 flag_addr[2]; //flag address
45 u8 flag_val; //flag val
46 u8 flag_relation; //flag_val:flag 0:not equal 1:equal 2:> 3:<
47 u16 circle; //polling cycle
48 u8 times; //plling times
49 u8 retry; //I2C retry times
50 u16 delay; //delay befor read or after write
51 u16 data_len; //data length
52 u8 addr_len; //address length
53 u8 addr[2]; //address
54 u8 res[3]; //reserved
55 u8 *data; //data pointer
56 } st_cmd_head;
57 #pragma pack()
58 st_cmd_head cmd_head;
59
60 #define UPDATE_FUNCTIONS
61 #define DATA_LENGTH_UINT 512
62 #define CMD_HEAD_LENGTH (sizeof(st_cmd_head) - sizeof(u8*))
63 static char procname[20] = {0};
64 extern struct i2c_client *i2c_client_point;
65 extern unsigned int touch_irq;
66 static struct i2c_client *gt_client = NULL;
67
68 #ifdef UPDATE_FUNCTIONS
69 extern s32 gup_enter_update_mode(struct i2c_client *client);
70 extern void gup_leave_update_mode(void);
71 extern s32 gup_update_proc(void *dir);
72 #endif
73 extern s32 gup_load_hotknot_system(void);
74 extern s32 gup_load_fx_system(void);
75 extern s32 gup_recovery_main_system(void);
76 extern s32 gup_load_main_system(char *filepath);
77
78 //static struct proc_dir_entry *goodix_proc_entry;
79
80 static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data);
81 static s32 goodix_tool_read(char *page, char **start, off_t off, int count, int *eof, void *data);
82 static s32(*tool_i2c_read)(u8 *, u16);
83 static s32(*tool_i2c_write)(u8 *, u16);
84
85 #if GTP_ESD_PROTECT
86 extern void gtp_esd_switch(struct i2c_client *client, s32 on);
87 #endif
88
89 #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE)
90 extern u8 is_reseting;
91 #endif
92
93
94 s32 DATA_LENGTH = 0;
95 s8 IC_TYPE[16] = "GT9XX";
96
97 #if HOTKNOT_BLOCK_RW
98 DECLARE_WAIT_QUEUE_HEAD(bp_waiter);
99 u8 got_hotknot_state = 0;
100 u8 got_hotknot_extra_state = 0;
101 u8 wait_hotknot_state = 0;
102 u8 force_wake_flag = 0;
103 #endif
104
105 #define HOTKNOTNAME "hotknot"
106
107 static ssize_t hotknot_read(struct file *file, char __user *buffer,
108 size_t count, loff_t *ppos)
109 {
110 return goodix_tool_read(buffer, NULL,0, count, NULL, ppos);
111 }
112
113 static ssize_t hotknot_write(struct file *file, const char __user *buffer,
114 size_t count, loff_t *ppos)
115 {
116 return goodix_tool_write(file, buffer, count, ppos);
117 }
118
119 static struct file_operations hotknot_fops =
120 {
121 // .owner = THIS_MODULE,
122 .read = hotknot_read,
123 .write = hotknot_write,
124 };
125
126 static struct miscdevice hotknot_misc_device =
127 {
128 .minor = MISC_DYNAMIC_MINOR,
129 .name = HOTKNOTNAME,
130 .fops = &hotknot_fops,
131 };
132 static ssize_t goodix_tool_upper_read(struct file *file, char __user *buffer,
133 size_t count, loff_t *ppos)
134 {
135 return goodix_tool_read(buffer, NULL,0, count, NULL, ppos);
136 }
137
138 static ssize_t goodix_tool_upper_write(struct file *file, const char __user *buffer,
139 size_t count, loff_t *ppos)
140 {
141 return goodix_tool_write(file, buffer, count, ppos);
142 }
143
144 static const struct file_operations gt_tool_fops = {
145 .write = goodix_tool_upper_write,
146 .read = goodix_tool_upper_read,
147 };
148
149 static void tool_set_proc_name(char * procname)
150 {
151 #if 1
152 char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May",
153 "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
154 char date[20] = {0};
155 char month[4] = {0};
156 int i = 0, n_month = 1, n_day = 0, n_year = 0;
157
158 sprintf(date, "%s", __DATE__);
159
160 //GTP_DEBUG("compile date: %s", date);
161
162 sscanf(date, "%s %d %d", month, &n_day, &n_year);
163
164 for (i = 0; i < 12; ++i)
165 {
166 if (!memcmp(months[i], month, 3))
167 {
168 n_month = i+1;
169 break;
170 }
171 }
172
173 sprintf(procname, "gmnode%04d%02d%02d", n_year, n_month, n_day);
174 #else
175 sprintf(procname, HOTKNOTNAME);
176 #endif
177 //GTP_DEBUG("procname = %s", procname);
178 }
179 static s32 tool_i2c_read_no_extra(u8 *buf, u16 len)
180 {
181 s32 ret = -1;
182
183 ret = gtp_i2c_read(gt_client, buf, len + GTP_ADDR_LENGTH);
184 return ret;
185 }
186
187 static s32 tool_i2c_write_no_extra(u8 *buf, u16 len)
188 {
189 s32 ret = -1;
190
191 ret = gtp_i2c_write(gt_client, buf, len);
192 return ret;
193 }
194
195 static s32 tool_i2c_read_with_extra(u8 *buf, u16 len)
196 {
197 s32 ret = -1;
198 u8 pre[2] = {0x0f, 0xff};
199 u8 end[2] = {0x80, 0x00};
200
201 tool_i2c_write_no_extra(pre, 2);
202 ret = tool_i2c_read_no_extra(buf, len);
203 tool_i2c_write_no_extra(end, 2);
204
205 return ret;
206 }
207
208 static s32 tool_i2c_write_with_extra(u8 *buf, u16 len)
209 {
210 s32 ret = -1;
211 u8 pre[2] = {0x0f, 0xff};
212 u8 end[2] = {0x80, 0x00};
213
214 tool_i2c_write_no_extra(pre, 2);
215 ret = tool_i2c_write_no_extra(buf, len);
216 tool_i2c_write_no_extra(end, 2);
217
218 return ret;
219 }
220
221 static void register_i2c_func(void)
222 {
223 // if (!strncmp(IC_TYPE, "GT818", 5) || !strncmp(IC_TYPE, "GT816", 5)
224 // || !strncmp(IC_TYPE, "GT811", 5) || !strncmp(IC_TYPE, "GT818F", 6)
225 // || !strncmp(IC_TYPE, "GT827", 5) || !strncmp(IC_TYPE,"GT828", 5)
226 // || !strncmp(IC_TYPE, "GT813", 5))
227 if (strncmp(IC_TYPE, "GT8110", 6) && strncmp(IC_TYPE, "GT8105", 6)
228 && strncmp(IC_TYPE, "GT801", 5) && strncmp(IC_TYPE, "GT800", 5)
229 && strncmp(IC_TYPE, "GT801PLUS", 9) && strncmp(IC_TYPE, "GT811", 5)
230 && strncmp(IC_TYPE, "GTxxx", 5) && strncmp(IC_TYPE, "GT9XX", 5))
231 {
232 tool_i2c_read = tool_i2c_read_with_extra;
233 tool_i2c_write = tool_i2c_write_with_extra;
234 GTP_DEBUG("I2C function: with pre and end cmd!");
235 }
236 else
237 {
238 tool_i2c_read = tool_i2c_read_no_extra;
239 tool_i2c_write = tool_i2c_write_no_extra;
240 GTP_INFO("I2C function: without pre and end cmd!");
241 }
242 }
243
244 static void unregister_i2c_func(void)
245 {
246 tool_i2c_read = NULL;
247 tool_i2c_write = NULL;
248 GTP_INFO("I2C function: unregister i2c transfer function!");
249 }
250
251 s32 init_wr_node(struct i2c_client *client)
252 {
253 s32 i;
254
255 gt_client = i2c_client_point;
256
257 memset(&cmd_head, 0, sizeof(cmd_head));
258 cmd_head.data = NULL;
259
260 i = 5;
261
262 while ((!cmd_head.data) && i)
263 {
264 cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);
265
266 if (NULL != cmd_head.data)
267 {
268 break;
269 }
270
271 i--;
272 }
273
274 if (i)
275 {
276 DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
277 GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
278 }
279 else
280 {
281 GTP_ERROR("Apply for memory failed.");
282 return FAIL;
283 }
284
285 cmd_head.addr_len = 2;
286 cmd_head.retry = 5;
287
288 register_i2c_func();
289
290 tool_set_proc_name(procname);
291 #if 0
292 goodix_proc_entry = create_proc_entry(procname, 0660, NULL);
293 if (goodix_proc_entry == NULL)
294 {
295 GTP_ERROR("Couldn't create proc entry!");
296 return FAIL;
297 }
298 else
299 {
300 GTP_INFO("Create proc entry success!");
301 goodix_proc_entry->write_proc = goodix_tool_write;
302 goodix_proc_entry->read_proc = goodix_tool_read;
303 }
304 #else
305 if(proc_create(procname, 0660, NULL, &gt_tool_fops)== NULL)
306 {
307 GTP_ERROR("create_proc_entry %s failed", procname);
308 return -1;
309 }
310 #endif
311
312 #if 1 // setting by hotknot feature
313 if (misc_register(&hotknot_misc_device))
314 {
315 printk("mtk_tpd: hotknot_device register failed\n");
316 return FAIL;
317 }
318 #endif
319
320 return SUCCESS;
321 }
322
323 void uninit_wr_node(void)
324 {
325 kfree(cmd_head.data);
326 cmd_head.data = NULL;
327 unregister_i2c_func();
328 remove_proc_entry(procname, NULL);
329 }
330
331 static u8 relation(u8 src, u8 dst, u8 rlt)
332 {
333 u8 ret = 0;
334
335 switch (rlt)
336 {
337 case 0:
338 ret = (src != dst) ? true : false;
339 break;
340
341 case 1:
342 ret = (src == dst) ? true : false;
343 GTP_DEBUG("equal:src:0x%02x dst:0x%02x ret:%d.", src, dst, (s32)ret);
344 break;
345
346 case 2:
347 ret = (src > dst) ? true : false;
348 break;
349
350 case 3:
351 ret = (src < dst) ? true : false;
352 break;
353
354 case 4:
355 ret = (src & dst) ? true : false;
356 break;
357
358 case 5:
359 ret = (!(src | dst)) ? true : false;
360 break;
361
362 default:
363 ret = false;
364 break;
365 }
366
367 return ret;
368 }
369
370 /*******************************************************
371 Function:
372 Comfirm function.
373 Input:
374 None.
375 Output:
376 Return write length.
377 ********************************************************/
378 static u8 comfirm(void)
379 {
380 s32 i = 0;
381 u8 buf[32];
382
383 // memcpy(&buf[GTP_ADDR_LENGTH - cmd_head.addr_len], &cmd_head.flag_addr, cmd_head.addr_len);
384 // memcpy(buf, &cmd_head.flag_addr, cmd_head.addr_len);//Modified by Scott, 2012-02-17
385 memcpy(buf, cmd_head.flag_addr, cmd_head.addr_len);
386
387 for (i = 0; i < cmd_head.times; i++)
388 {
389 if (tool_i2c_read(buf, 1) <= 0)
390 {
391 GTP_ERROR("Read flag data failed!");
392 return FAIL;
393 }
394
395 if (true == relation(buf[GTP_ADDR_LENGTH], cmd_head.flag_val, cmd_head.flag_relation))
396 {
397 GTP_DEBUG("value at flag addr:0x%02x.", buf[GTP_ADDR_LENGTH]);
398 GTP_DEBUG("flag value:0x%02x.", cmd_head.flag_val);
399 break;
400 }
401
402 msleep(cmd_head.circle);
403 }
404
405 if (i >= cmd_head.times)
406 {
407 GTP_ERROR("Didn't get the flag to continue!");
408 return FAIL;
409 }
410
411 return SUCCESS;
412 }
413
414 /*******************************************************
415 Function:
416 Goodix tool write function.
417 Input:
418 standard proc write function param.
419 Output:
420 Return write length.
421 ********************************************************/
422 static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data)
423 {
424 u64 ret = 0;
425 GTP_DEBUG_FUNC();
426 GTP_DEBUG_ARRAY((u8 *)buff, len);
427
428 if(tpd_halt == 1||is_reseting == 1)
429 {
430 //GTP_ERROR("[Write]tpd_halt =1 fail!");
431 return FAIL;
432 }
433
434 ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);
435
436 if (ret)
437 {
438 GTP_ERROR("copy_from_user failed.");
439 }
440
441 GTP_DEBUG("wr :0x%02x.", cmd_head.wr);
442 /*
443 GTP_DEBUG("flag:0x%02x.", cmd_head.flag);
444 GTP_DEBUG("flag addr:0x%02x%02x.", cmd_head.flag_addr[0], cmd_head.flag_addr[1]);
445 GTP_DEBUG("flag val:0x%02x.", cmd_head.flag_val);
446 GTP_DEBUG("flag rel:0x%02x.", cmd_head.flag_relation);
447 GTP_DEBUG("circle :%d.", (s32)cmd_head.circle);
448 GTP_DEBUG("times :%d.", (s32)cmd_head.times);
449 GTP_DEBUG("retry :%d.", (s32)cmd_head.retry);
450 GTP_DEBUG("delay :%d.", (s32)cmd_head.delay);
451 GTP_DEBUG("data len:%d.", (s32)cmd_head.data_len);
452 GTP_DEBUG("addr len:%d.", (s32)cmd_head.addr_len);
453 GTP_DEBUG("addr:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]);
454 GTP_DEBUG("len:%d.", (s32)len);
455 GTP_DEBUG("buf[20]:0x%02x.", buff[CMD_HEAD_LENGTH]);
456 */
457
458 if (1 == cmd_head.wr)
459 {
460 // copy_from_user(&cmd_head.data[cmd_head.addr_len], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
461 ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
462
463 if (ret)
464 {
465 GTP_ERROR("copy_from_user failed.");
466 }
467
468 memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.addr, cmd_head.addr_len);
469
470 GTP_DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len);
471 GTP_DEBUG_ARRAY((u8 *)&buff[CMD_HEAD_LENGTH], cmd_head.data_len);
472
473 if (1 == cmd_head.flag)
474 {
475 if (FAIL == comfirm())
476 {
477 GTP_ERROR("[WRITE]Comfirm fail!");
478 return FAIL;
479 }
480 }
481 else if (2 == cmd_head.flag)
482 {
483 //Need interrupt!
484 }
485
486 if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
487 cmd_head.data_len + cmd_head.addr_len) <= 0)
488 {
489 GTP_ERROR("[WRITE]Write data failed!");
490 return FAIL;
491 }
492
493 GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.data_len + cmd_head.addr_len);
494
495 if (cmd_head.delay)
496 {
497 msleep(cmd_head.delay);
498 }
499
500 return cmd_head.data_len + CMD_HEAD_LENGTH;
501 }
502 else if (3 == cmd_head.wr) //Write ic type
503 {
504 memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
505 register_i2c_func();
506
507 return cmd_head.data_len + CMD_HEAD_LENGTH;
508 }
509 else if (5 == cmd_head.wr)
510 {
511 //memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
512
513 return cmd_head.data_len + CMD_HEAD_LENGTH;
514 }
515 else if (7 == cmd_head.wr)//disable irq!
516 {
517 #ifdef CONFIG_OF_TOUCH
518 disable_irq(touch_irq);
519 #else
520 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
521 #endif
522
523 #if GTP_ESD_PROTECT
524 gtp_esd_switch(i2c_client_point, SWITCH_OFF);
525 #endif
526 return CMD_HEAD_LENGTH;
527 }
528 else if (9 == cmd_head.wr) //enable irq!
529 {
530 #ifdef CONFIG_OF_TOUCH
531 enable_irq(touch_irq);
532 #else
533 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
534 #endif
535
536 #if GTP_ESD_PROTECT
537 gtp_esd_switch(i2c_client_point, SWITCH_ON);
538 #endif
539 return CMD_HEAD_LENGTH;
540 }
541 else if (17 == cmd_head.wr)
542 {
543 ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
544
545 if (ret)
546 {
547 GTP_DEBUG("copy_from_user failed.");
548 }
549
550 if (cmd_head.data[GTP_ADDR_LENGTH])
551 {
552 GTP_DEBUG("gtp enter rawdiff.");
553 gtp_rawdiff_mode = true;
554 }
555 else
556 {
557 gtp_rawdiff_mode = false;
558 GTP_DEBUG("gtp leave rawdiff.");
559 }
560
561 return CMD_HEAD_LENGTH;
562 }
563
564 #ifdef UPDATE_FUNCTIONS
565 else if (11 == cmd_head.wr) //Enter update mode!
566 {
567 if (FAIL == gup_enter_update_mode(gt_client))
568 {
569 return FAIL;
570 }
571 }
572 else if (13 == cmd_head.wr)//Leave update mode!
573 {
574 gup_leave_update_mode();
575 }
576 else if (15 == cmd_head.wr) //Update firmware!
577 {
578 show_len = 0;
579 total_len = 0;
580 if ((cmd_head.data == NULL)
581 || (cmd_head.data_len >= DATA_LENGTH)
582 || (cmd_head.data_len >= (len - CMD_HEAD_LENGTH))) {
583 GTP_ERROR("copy_from_user data out of range.");
584 return -EINVAL;
585 }
586
587 memset(cmd_head.data, 0, cmd_head.data_len + 1);
588 ret = copy_from_user(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
589 if (ret)
590 {
591 GTP_ERROR("copy_from_user failed.");
592 }
593 GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
594 if (FAIL == gup_update_proc((void *)cmd_head.data))
595 {
596 return FAIL;
597 }
598 }
599
600 #endif
601 else if (19 == cmd_head.wr) //load subsystem
602 {
603 ret = copy_from_user(&cmd_head.data[0], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
604 if(0 == cmd_head.data[0])
605 {
606 if (FAIL == gup_load_hotknot_system())
607 {
608 return FAIL;
609 }
610 }
611 else if(1 == cmd_head.data[0])
612 {
613 if (FAIL == gup_load_fx_system())
614 {
615 return FAIL;
616 }
617 }
618 else if(2 == cmd_head.data[0])
619 {
620 if (FAIL == gup_recovery_main_system())
621 {
622 return FAIL;
623 }
624 }
625 else if(3 == cmd_head.data[0])
626 {
627 if (FAIL == gup_load_main_system(NULL))
628 {
629 return FAIL;
630 }
631 }
632 }
633 #if HOTKNOT_BLOCK_RW
634 else if (21 == cmd_head.wr)
635 {
636 u16 wait_hotknot_timeout = 0;
637 u8 rqst_hotknot_state;
638
639 ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH],
640 &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
641
642 if (ret)
643 {
644 GTP_ERROR("copy_from_user failed.");
645 }
646
647 rqst_hotknot_state = cmd_head.data[GTP_ADDR_LENGTH];
648 wait_hotknot_state |= rqst_hotknot_state;
649 wait_hotknot_timeout = (cmd_head.data[GTP_ADDR_LENGTH + 1]<<8) +
650 cmd_head.data[GTP_ADDR_LENGTH + 2];
651 GTP_DEBUG("Goodix tool received wait polling state:0x%x,timeout:%d, all wait state:0x%x",
652 rqst_hotknot_state, wait_hotknot_timeout, wait_hotknot_state);
653 got_hotknot_state &= (~rqst_hotknot_state);
654 //got_hotknot_extra_state = 0;
655 switch(rqst_hotknot_state)
656 {
657 set_current_state(TASK_INTERRUPTIBLE);
658 case HN_DEVICE_PAIRED:
659 hotknot_paired_flag = 0;
660 wait_event_interruptible(bp_waiter, force_wake_flag ||
661 rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state));
662 wait_hotknot_state &= (~rqst_hotknot_state);
663 if(rqst_hotknot_state != (got_hotknot_state&rqst_hotknot_state))
664 {
665 GTP_ERROR("Wait 0x%x block polling waiter failed.", rqst_hotknot_state);
666 force_wake_flag = 0;
667 return FAIL;
668 }
669 break;
670 case HN_MASTER_SEND:
671 case HN_SLAVE_RECEIVED:
672 wait_event_interruptible_timeout(bp_waiter, force_wake_flag ||
673 rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state),
674 wait_hotknot_timeout);
675 wait_hotknot_state &= (~rqst_hotknot_state);
676 if(rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state))
677 {
678 return got_hotknot_extra_state;
679 }
680 else
681 {
682 GTP_ERROR("Wait 0x%x block polling waiter timeout.", rqst_hotknot_state);
683 force_wake_flag = 0;
684 return FAIL;
685 }
686 break;
687 case HN_MASTER_DEPARTED:
688 case HN_SLAVE_DEPARTED:
689 wait_event_interruptible_timeout(bp_waiter, force_wake_flag ||
690 rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state),
691 wait_hotknot_timeout);
692 wait_hotknot_state &= (~rqst_hotknot_state);
693 if(rqst_hotknot_state != (got_hotknot_state&rqst_hotknot_state))
694 {
695 GTP_ERROR("Wait 0x%x block polling waitor timeout.", rqst_hotknot_state);
696 force_wake_flag = 0;
697 return FAIL;
698 }
699 break;
700 default:
701 GTP_ERROR("Invalid rqst_hotknot_state in goodix_tool.");
702 break;
703 }
704 force_wake_flag = 0;
705 }
706 else if(23 == cmd_head.wr)
707 {
708 GTP_DEBUG("Manual wakeup all block polling waiter!");
709 got_hotknot_state = 0;
710 wait_hotknot_state = 0;
711 force_wake_flag = 1;
712 hotknot_paired_flag = 0;
713 wake_up_interruptible(&bp_waiter);
714 }
715 #endif
716 return CMD_HEAD_LENGTH;
717 }
718
719 /*******************************************************
720 Function:
721 Goodix tool read function.
722 Input:
723 standard proc read function param.
724 Output:
725 Return read length.
726 ********************************************************/
727 static s32 goodix_tool_read(char *page, char **start, off_t off, int count, int *eof, void *data)
728 {
729 u64 ret = 0;
730 GTP_DEBUG_FUNC();
731
732 if(tpd_halt == 1||is_reseting == 1)
733 {
734 //GTP_ERROR("[READ]tpd_halt =1 fail!");
735 return FAIL;
736 }
737 if (cmd_head.wr % 2)
738 {
739 GTP_ERROR("[READ] invaild operator fail!");
740 return FAIL;
741 }
742 else if (!cmd_head.wr)
743 {
744 u16 len = 0;
745 s16 data_len = 0;
746 u16 loc = 0;
747
748 if (1 == cmd_head.flag)
749 {
750 if (FAIL == comfirm())
751 {
752 GTP_ERROR("[READ]Comfirm fail!");
753 return FAIL;
754 }
755 }
756 else if (2 == cmd_head.flag)
757 {
758 //Need interrupt!
759 }
760
761 memcpy(cmd_head.data, cmd_head.addr, cmd_head.addr_len);
762
763 GTP_DEBUG("[CMD HEAD DATA] ADDR:0x%02x%02x.", cmd_head.data[0], cmd_head.data[1]);
764 GTP_DEBUG("[CMD HEAD ADDR] ADDR:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]);
765
766 if (cmd_head.delay)
767 {
768 msleep(cmd_head.delay);
769 }
770
771 data_len = cmd_head.data_len;
772
773 while (data_len > 0)
774 {
775 if (data_len > DATA_LENGTH)
776 {
777 len = DATA_LENGTH;
778 }
779 else
780 {
781 len = data_len;
782 }
783
784 data_len -= DATA_LENGTH;
785
786 if (tool_i2c_read(cmd_head.data, len) <= 0)
787 {
788 GTP_ERROR("[READ]Read data failed!");
789 return FAIL;
790 }
791
792 ret = copy_to_user(&page[loc], &cmd_head.data[GTP_ADDR_LENGTH], len);
793 if (ret)
794 {
795 GTP_ERROR("copy_from_user failed.");
796 return FAIL;
797 }
798 loc += len;
799
800 GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH], len);
801 GTP_DEBUG_ARRAY(page, len);
802 }
803 }
804 else if (2 == cmd_head.wr)
805 {
806 // memcpy(page, "gt8", cmd_head.data_len);
807 // memcpy(page, "GT818", 5);
808 // page[5] = 0;
809
810 GTP_DEBUG("Return ic type:%s len:%d.", page, (s32)cmd_head.data_len);
811 return cmd_head.data_len;
812 //return sizeof(IC_TYPE_NAME);
813 }
814 else if (4 == cmd_head.wr)
815 {
816 page[0] = show_len >> 8;
817 page[1] = show_len & 0xff;
818 page[2] = total_len >> 8;
819 page[3] = total_len & 0xff;
820
821 return cmd_head.data_len;
822 }
823 else if (6 == cmd_head.wr)
824 {
825 //Read error code!
826 }
827 else if (8 == cmd_head.wr) //Read driver version
828 {
829 // memcpy(page, GTP_DRIVER_VERSION, strlen(GTP_DRIVER_VERSION));
830 s32 tmp_len;
831 tmp_len = strlen(GTP_DRIVER_VERSION);
832 ret = copy_to_user(page, GTP_DRIVER_VERSION, tmp_len);
833 if (ret)
834 {
835 GTP_ERROR("copy_from_user failed.");
836 return FAIL;
837 }
838 page[tmp_len] = 0;
839 }
840
841 return cmd_head.data_len;
842 }
843
844