-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_proc.c
686 lines (637 loc) · 17.9 KB
/
debug_proc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
#include "include/CN1100_common.h"
#include "include/CN1100_linux.h"
#include "include/CN1100_Function.h"
static bool cn1100_need_write = false;
static bool cn1100_need_read = false;
static int read_value = 0;
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void chm_ts_reset_func(struct work_struct *work)
{
cn1100_reset();
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
int get_chip_addr(void)
{
int retry = 0;
int ret = 0;
chip_addr = 0x5d;
while(retry < 1)
{
ret = SPI_read_singleData(0x400);
if(ret < 0)
{
retry++;
msleep(10);
}
else
{
break;
}
}
if(retry >= 1)
{
chip_addr = 0x20;
retry = 0;
while(retry < 1)
{
ret = SPI_read_singleData(0x400);
if(ret < 0)
{
retry++;
msleep(10);
}
else
{
retry = 0;
break;
}
}
if(retry >= 1)
{
spidev->i2c_ok = false;
return -1;
}
}
spidev->i2c_ok = true;
CN1100_print("get chip addr:0x%x\n",chip_addr);
return 0;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
s32 atoi(char *psz_buf)
{
char *pch = psz_buf;
s32 base = 0;
while (isspace(*pch))
pch++;
if (('-' == *pch) || ('+' == *pch))
{
base = 10;
pch++;
}
else if ('h' == (*pch && tolower(pch[strlen(pch) - 1])))
{
base = 16;
}
return simple_strtoul(pch, NULL, base);
}
#ifdef DEBUG_PROC_USED //Use PROC interface to debug chip
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
int chm_ts_write_config(cn1100_t config)
{
unsigned int *pp = &(bdt.PCBA.ProtectTime);
switch(config.type)
{
case 0:
{
pp[config.index] = config.value;
if(config.index >= 6 && config.index <= 11){
//TC1126_Init_VarRegSetting(); // unused
;
}else if(config.index == 12){
CN1100_print("write config:%d,%d\n",config.index,config.value);
if(1 == config.value)
{
SPI_write_singleData(TPL1_REG, 0xffff); /* cfg_reg30, 12'h000 */
}
else if(0 == config.value)
{
SPI_write_singleData(TPL1_REG, 0x0000); /* cfg_reg30, 12'h000 */
}
}
break;
}
case 1:
{
SPI_write_singleData(config.index,config.value);
break;
}
}
return 0;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
int chm_ts_read_config(cn1100_t config)
{
unsigned int *pp = &(bdt.PCBA.ProtectTime);
switch(config.type)
{
case 0:
{
read_value = pp[config.index];
break;
}
case 1:
{
read_value = SPI_read_singleData(config.index);
break;
}
}
spidev->mode |= SHELL_READ_MODE;
return 0;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
static char config_type = 0;
ssize_t chm_proc_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
{
int len = 0,i = 0,j = 0;
uint32_t X = 0,Y = 0;
uint32_t tmp[FINGER_NUM_MAX*2] = {0};
#ifdef CAL_TIME_CONSUMED
uint32_t time_used[10] = {0};
#endif
data_t cn1100;
switch((spidev->mode &(0xffff)))
{
#ifdef CAL_TIME_CONSUMED
case TIME_READ_MODE:
{
time_used[0] = spidev->irq_interval;
time_used[1] = spidev->total_time;
time_used[2] = spidev->i2c_time;
len = sizeof(time_used);
if(copy_to_user(buf,time_used,len)){
CN1100_print("copy failed\n");
};
break;
}
#endif
case CFG_READ_MODE:
{
len = sizeof(read_value);
if(copy_to_user(buf,&read_value,len)){
CN1100_print("copy failed\n");
};
break;
}
case SHELL_READ_MODE:
{
if(0 == config_type)
{
len = sprintf(buf,"%d\n",read_value);
}else if(1 == config_type)
{
len = sprintf(buf,"0x%x\n",read_value);
}
break;
}
case DIFF_READ_MODE:
{
len = sizeof(bdt.DeltaDat16A);
wait_event_interruptible(spidev->waitq,(spidev->mode & CN1100_DATA_PREPARED));
#ifdef KEY_PRESS_DETECT
for(j=SRECV_NUM; j<RECV_NUM; j++)
for(i=0;i<XMTR_NUM;i++)
{
bdt.DeltaDat16A[i][j] = bdt.DeltaDat_kp[i];
}
#endif
if(copy_to_user(buf,&bdt.DeltaDat16A[0][0],len)){
CN1100_print("copy failed\n");
};
spidev->mode &= ~(CN1100_DATA_PREPARED);
break;
}
case RAW_READ_MODE:
{
len = sizeof(bdt.DeltaDat16A);
wait_event_interruptible(spidev->waitq,(spidev->mode & CN1100_DATA_PREPARED));
switch(bd->BufferID)
{
case 0:
{
if(copy_to_user(buf,&bdt.FrameDatLoadA[0][0],len)){
CN1100_print("copy failed\n");
};
break;
}
case 1:
{
if(copy_to_user(buf,&bdt.FrameDatLoadB[0][0],len)){
CN1100_print("copy failed\n");
};
break;
}
}
spidev->mode &= ~(CN1100_DATA_PREPARED);
break;
}
case BASE_READ_MODE:
{
len = sizeof(bdt.BFD.BaseDat);
wait_event_interruptible(spidev->waitq,(spidev->mode & CN1100_DATA_PREPARED));
if(copy_to_user(buf,&bdt.BFD.BaseDat[0][0],len)){
CN1100_print("copy failed\n");
}
spidev->mode &= ~(CN1100_DATA_PREPARED);
break;
}
case DEBUG_READ_MODE:
{
len = sizeof(bdt.SigDeltaDat);
wait_event_interruptible(spidev->waitq,(spidev->mode & CN1100_DATA_PREPARED));
if(copy_to_user(buf,&bdt.SigDeltaDat[0][0],len)){
CN1100_print("copy failed\n");
}
spidev->mode &= ~(CN1100_DATA_PREPARED);
break;
}
case ALL_READ_MODE:
{
len = sizeof(data_t);
wait_event_interruptible(spidev->waitq,(spidev->mode & CN1100_DATA_PREPARED));
memcpy(&cn1100.diff[0][0],&bdt.DeltaDat16A[0][0],sizeof(bd->bdt->DeltaDat16A));
memcpy(&cn1100.base[0][0],&bdt.BFD.BaseDat[0][0],sizeof(bd->bdt->BFD.BaseDat));
if(0 == bd->BufferID)
{
memcpy(&cn1100.raw[0][0],&bdt.FrameDatLoadA[0][0],sizeof(bd->bdt->FrameDatLoadA));
}else if(1 == bd->BufferID)
{
memcpy(&cn1100.raw[0][0],&bdt.FrameDatLoadB[0][0],sizeof(bd->bdt->FrameDatLoadB));
}
j = 0;
for (i = 0;i < FINGER_NUM_MAX;i++ )
{
Y = bdt.DPD[i].Finger_Y_Reported; /* Y -> RECV (480) */
X = bdt.DPD[i].Finger_X_Reported; /* X -> XTMR (800) */
#if 0
Y = (uint32_t)(( ((uint32_t)Y) * RECV_SCALE )>>16);
X = (uint32_t)(( ((uint32_t)X) * XMTR_SCALE )>>16);
if(X > 0 || Y > 0){
X = SCREEN_HIGH-X;
Y = SCREEN_WIDTH-Y;
}
#endif
cn1100.base[XMTR_NUM-1][j++] = X;
cn1100.base[XMTR_NUM-1][j++] = Y;
}
if(copy_to_user(buf,&cn1100,len)){
CN1100_print("copy failed\n");
}
spidev->mode &= ~(CN1100_DATA_PREPARED);
break;
}
case COOR_READ_MODE:
{
len = sizeof(tmp);
wait_event_interruptible(spidev->waitq,(spidev->mode & CN1100_DATA_PREPARED));
for (i = 0;i < FINGER_NUM_MAX;i++ )
{
Y = bdt.DPD[i].Finger_Y_Reported; /* Y -> RECV (480) */
X = bdt.DPD[i].Finger_X_Reported; /* X -> XTMR (800) */
Y = (uint32_t)(( ((uint32_t)Y) * RECV_SCALE )>>16);
X = (uint32_t)(( ((uint32_t)X) * XMTR_SCALE )>>16);
if(X > 0 || Y > 0)
{
X = SCREEN_HIGH-X;
Y = SCREEN_WIDTH-Y;
}
tmp[j++] = X;
tmp[j++] = Y;
}
if(copy_to_user(buf,tmp,len)){
CN1100_print("copy failed\n");
}
spidev->mode &= ~(CN1100_DATA_PREPARED);
break;
}
case MANUAL_READ_MODE:
{
break;
}
case INFO_READ_MODE:
{
len = sizeof(tmp);
#ifdef TC1126
tmp[0] = 1;
#else
#endif
tmp[1] = XMTR_NUM;tmp[2] = RECV_NUM;
tmp[3] = 1024;
if(copy_to_user(buf,tmp,len)){
CN1100_print("copy failed\n");
}
break;
}
default:
len = 0;
break;
}
return len;
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
int chm_proc_write(struct file *file, const char __user *buffer, size_t size, loff_t *ppos)
{
int buff[16];
char *p = NULL;
char *rp = NULL;
cn1100_t config;
unsigned int *pp = &(bdt.PCBA.ProtectTime);
bool err_cmd = true;
memset(buff,0,sizeof(buff));
if(copy_from_user(buff,buffer,size) != 0)
{
CN1100_print("failed to copy content from user space\n");
}
if(buff[0] >= PROC_CMD_MIN && buff[0] <= PROC_CMD_MAX)
{
spidev->mode &= (~0xffff);
config_type = buff[1];
switch(buff[0])
{
case PROC_WRITE_CFG:
{
config.type = config_type;
config.index = buff[2];
config.value = buff[3];
chm_ts_write_config(config);
/* *(pp+buff[2]) = buff[3]; */
bdt.BFD.InitCount = 0;
break;
}
case PROC_READ_CFG:
{
if(0 == config_type)
{
read_value = *(pp+buff[2]);
}else if(1 == config_type)
{
read_value = SPI_read_singleData(buff[2]);
}
spidev->mode |= CFG_READ_MODE;
break;
}
case PROC_READ_COORDINATE:
{
spidev->mode |= COOR_READ_MODE;
break;
}
case PROC_READ_ALL:
{
spidev->mode |= ALL_READ_MODE;
break;
}
case PROC_READ_DIFF:
{
spidev->mode |= DIFF_READ_MODE;
break;
}
case PROC_READ_RAW:
{
spidev->mode |= RAW_READ_MODE;
break;
}
case PROC_READ_BASE:
{
spidev->mode |= BASE_READ_MODE;
break;
}
case PROC_READ_MANUAL:
{
spidev->mode |= MANUAL_READ_MODE;
break;
}
case PROC_READ_DEBUG:
{
spidev->mode |= DEBUG_READ_MODE;
break;
}
case PROC_READ_INFO:
{
CN1100_print("read driver infomation\n");
spidev->mode |= INFO_READ_MODE;
break;
}
case PROC_READ_TIME:
{
spidev->mode |= TIME_READ_MODE;
break;
}
}
err_cmd = false;
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
if(!strncmp("cn1100_write",(char*)buff,12))
{
if(cn1100_need_read)
{
cn1100_need_read = false;
}
CN1100_print("start to write cn1100\n");
cn1100_need_write = true;
err_cmd = false;
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
if(!strncmp("write_complete",(char*)buff,14))
{
CN1100_print("write cn1100 complete\n");
cn1100_need_write = false;
err_cmd = false;
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
if(!strncmp("cn1100_read",(char*)buff,11))
{
if(cn1100_need_write)
{
cn1100_need_write = false;
}
CN1100_print("start to read cn1100\n");
cn1100_need_read = true;
err_cmd = false;
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
if(!strncmp("read_complete",(char*)buff,13))
{
CN1100_print("read cn1100 complete\n");
cn1100_need_read = false;
err_cmd = false;
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
if((cn1100_need_read) || (cn1100_need_write))
{
p = (char *)buff;
rp = strsep(&p,",");
if(!rp)
{
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
config.type = atoi(rp);
config_type = config.type;
rp = strsep(&p,",");
if(!rp)
{
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
config.index = atoi(rp);
if(1 == config.type)
{
if(1 == pp[13])
{
CN1100_print("in frequency scan mode,cannot config registers\n");
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
}
if(cn1100_need_write)
{
rp = strsep(&p,",");
if(!rp)
{
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
config.value = atoi(rp);
chm_ts_write_config(config);
bdt.BFD.InitCount = 0;
}else if(cn1100_need_read)
{
config.value = 0;
chm_ts_read_config(config);
}
err_cmd = false;
}
if(err_cmd)
{
CN1100_print("erro command\n");
}
return size;
}
#endif
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void cn1100_init(void)
{
TC1126_Init_GlobalVariables();
TC1126_Init_HardwareRegs();
spidev->ticks = 0;
spidev->irq_count = 5;
#ifdef CAL_TIME_CONSUMED
spidev->irq_interval = 0;
#endif
}
/*******************************************************************************
* Function Name :
* Description :
* Input :
* Output :
* Return :
*******************************************************************************/
void cn1100_reset(void)
{
#if 1
hrtimer_cancel(&spidev->systic);
if(spidev->mode & CN1100_USE_IRQ)
{
disable_irq_nosync(spidev->irq);
}
cancel_work_sync(&spidev->main);
if(CN1100_RESET_PIN != -1)
{
gpio_set_value(CN1100_RESET_PIN,0);
msleep(50);
gpio_set_value(CN1100_RESET_PIN,1);
msleep(10);
}
enable_irq(spidev->irq);
get_chip_addr();
if(spidev->i2c_ok)
{
cn1100_init();
}
hrtimer_start(&spidev->systic, ktime_set(0, SCAN_SYSTIC_INTERVAL), HRTIMER_MODE_REL);
#endif
}
void cn1100_set_irq(bool enable){
if(enable){
#ifdef CONFIG_ARCH_SUN8IW1P1
sw_gpio_eint_set_enable(spidev->irq,1);
#else
enable_irq(spidev->irq);
#endif
}else{
#ifdef CONFIG_ARCH_SUN8IW1P1
sw_gpio_eint_set_enable(spidev->irq,0);
#else
disable_irq_nosync(spidev->irq);
#endif
}
}