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