forked from SanniZ/fpc1020-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpc1020_common.c
1784 lines (1406 loc) · 44 KB
/
fpc1020_common.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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* FPC1020 Touch sensor driver
*
* Copyright (c) 2013,2014 Fingerprint Cards AB <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License Version 2
* as published by the Free Software Foundation.
*/
#define DEBUG
#include <linux/gpio.h>
#include <linux/interrupt.h>
#ifndef CONFIG_OF
#include <linux/spi/fpc1020_common.h>
#include <linux/spi/fpc1020_regs.h>
#include <linux/spi/fpc1020_capture.h>
#include <linux/spi/fpc1020_regulator.h>
#else
#include "fpc1020_common.h"
#include "fpc1020_regs.h"
#include "fpc1020_capture.h"
#include "fpc1020_regulator.h"
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const bool target_little_endian = true;
#else
#warning BE target not tested!
const bool target_little_endian = false;
#endif
/* -------------------------------------------------------------------- */
/* fpc1020 data types */
/* -------------------------------------------------------------------- */
struct chip_struct {
fpc1020_chip_t type;
u16 hwid;
u8 revision;
u8 pixel_rows;
u8 pixel_columns;
u8 adc_group_size;
};
/* -------------------------------------------------------------------- */
/* fpc1020 driver constants */
/* -------------------------------------------------------------------- */
#define FPC1150_ROWS 208u
#define FPC1150_COLUMNS 80u
#define FPC1021_ROWS 160u
#define FPC1021_COLUMNS 160u
#define FPC1020_ROWS 192u
#define FPC1020_COLUMNS 192u
#define FPC102X_ADC_GROUP_SIZE 8u
#define FPC1020_EXT_HWID_CHECK_ID1020A_ROWS 5u
static const char *chip_text[] = {
"N/A", /* FPC1020_CHIP_NONE */
"fpc1020a", /* FPC1020_CHIP_1020A */
"fpc1021a", /* FPC1020_CHIP_1021A */
"fpc1021b", /* FPC1020_CHIP_1021B */
"fpc1150a", /* FPC1020_CHIP_1150A */
"fpc1150b", /* FPC1020_CHIP_1150B */
"fpc1150f" /* FPC1020_CHIP_1150F */
};
static const struct chip_struct chip_data[] = {
{FPC1020_CHIP_1020A, 0x020a, 0, FPC1020_ROWS, FPC1020_COLUMNS, FPC102X_ADC_GROUP_SIZE},
{FPC1020_CHIP_1021A, 0x021a, 2, FPC1021_ROWS, FPC1021_COLUMNS, FPC102X_ADC_GROUP_SIZE},
{FPC1020_CHIP_1021B, 0x021b, 1, FPC1021_ROWS, FPC1021_COLUMNS, FPC102X_ADC_GROUP_SIZE},
{FPC1020_CHIP_1150A, 0x150a, 1, FPC1150_ROWS, FPC1150_COLUMNS, FPC102X_ADC_GROUP_SIZE},
{FPC1020_CHIP_1150B, 0x150b, 1, FPC1150_ROWS, FPC1150_COLUMNS, FPC102X_ADC_GROUP_SIZE},
{FPC1020_CHIP_1150F, 0x150f, 1, FPC1150_ROWS, FPC1150_COLUMNS, FPC102X_ADC_GROUP_SIZE},
{FPC1020_CHIP_NONE, 0,0,0,0,0}
};
const fpc1020_setup_t fpc1020_setup_default_1020_a1a2 = {
.adc_gain = {0, 0, 1, 1},
.adc_shift = {1, 2, 1, 1},
.pxl_ctrl = {0x1b, 0x1f, 0x0b, 0x0b},
.capture_settings_mux = 0,
.capture_count = 1,
.capture_mode = FPC1020_MODE_WAIT_AND_CAPTURE,
.capture_row_start = 0,
.capture_row_count = FPC1020_ROWS,
.capture_col_start = 0,
.capture_col_groups = FPC1020_COLUMNS / FPC102X_ADC_GROUP_SIZE,
.capture_finger_up_threshold = 0,
.capture_finger_down_threshold = 6,
.finger_detect_threshold = 0x50,
.wakeup_detect_rows = {92, 92},
.wakeup_detect_cols = {64, 120},
};
const fpc1020_setup_t fpc1020_setup_default_1020_a3a4 = {
.adc_gain = {2, 2, 2, 2},
.adc_shift = {10, 10, 10, 10},
.pxl_ctrl = {0x1e, 0x0e, 0x0a, 0x0a},
.capture_settings_mux = 0,
.capture_count = 1,
.capture_mode = FPC1020_MODE_WAIT_AND_CAPTURE,
.capture_row_start = 0,
.capture_row_count = FPC1020_ROWS,
.capture_col_start = 0,
.capture_col_groups = FPC1020_COLUMNS / FPC102X_ADC_GROUP_SIZE,
.capture_finger_up_threshold = 0,
.capture_finger_down_threshold = 6,
.finger_detect_threshold = 0x50,
.wakeup_detect_rows = {92, 92},
.wakeup_detect_cols = {64, 120},
};
const fpc1020_setup_t fpc1020_setup_default_1021_a2b1 = {
.adc_gain = {2, 2, 2, 2},
.adc_shift = {10, 10, 10, 10},
.pxl_ctrl = {0x1e, 0x0e, 0x0a, 0x0a},
.capture_settings_mux = 0,
.capture_count = 1,
.capture_mode = FPC1020_MODE_WAIT_AND_CAPTURE,
.capture_row_start = 0,
.capture_row_count = FPC1021_ROWS,
.capture_col_start = 0,
.capture_col_groups = FPC1021_COLUMNS / FPC102X_ADC_GROUP_SIZE,
.capture_finger_up_threshold = 0,
.capture_finger_down_threshold = 6,
.finger_detect_threshold = 0x50,
.wakeup_detect_rows = {76, 76},
.wakeup_detect_cols = {56, 88},
};
const fpc1020_setup_t fpc1020_setup_default_1150_a1b1f1 = {
.adc_gain = {2, 2, 2, 2},
.adc_shift = {10, 10, 10, 10},
.pxl_ctrl = {0x1e, 0x0e, 0x0a, 0x0a},
.capture_settings_mux = 0,
.capture_count = 1,
.capture_mode = FPC1020_MODE_WAIT_AND_CAPTURE,
.capture_row_start = 0,
.capture_row_count = FPC1150_ROWS,
.capture_col_start = 0,
.capture_col_groups = FPC1150_COLUMNS / FPC102X_ADC_GROUP_SIZE,
.capture_finger_up_threshold = 0,
.capture_finger_down_threshold = 7,
.finger_detect_threshold = 0x50,
.wakeup_detect_rows = {72, 128},
.wakeup_detect_cols = {32, 32},
};
const fpc1020_diag_t fpc1020_diag_default = {
.selftest = 0,
.spi_register = 0,
.spi_regsize = 0,
.spi_data = 0,
};
/* -------------------------------------------------------------------- */
/* function prototypes */
/* -------------------------------------------------------------------- */
static int fpc1020_check_hw_id_extended(fpc1020_data_t *fpc1020);
static int fpc1020_hwid_1020a(fpc1020_data_t *fpc1020);
static int fpc1020_write_id_1020a_setup(fpc1020_data_t *fpc1020);
static int fpc1020_write_sensor_1020a_setup(fpc1020_data_t *fpc1020);
static int fpc1020_write_sensor_1020a_a1a2_setup(fpc1020_data_t *fpc1020);
static int fpc1020_write_sensor_1020a_a3a4_setup(fpc1020_data_t *fpc1020);
static int fpc1020_write_sensor_1021_setup(fpc1020_data_t *fpc1020);
static int fpc1020_write_sensor_1150_setup(fpc1020_data_t *fpc1020);
static int fpc1020_check_irq_after_reset(fpc1020_data_t *fpc1020);
static int fpc1020_flush_adc(fpc1020_data_t *fpc1020);
/* -------------------------------------------------------------------- */
/* function definitions */
/* -------------------------------------------------------------------- */
size_t fpc1020_calc_huge_buffer_minsize(fpc1020_data_t *fpc1020)
{
const size_t buff_min = FPC1020_EXT_HWID_CHECK_ID1020A_ROWS *
FPC1020_COLUMNS;
size_t buff_req;
buff_req = (fpc1020->chip.type == FPC1020_CHIP_NONE) ? buff_min :
(fpc1020->chip.pixel_columns *
fpc1020->chip.pixel_rows *
FPC1020_BUFFER_MAX_IMAGES);
return (buff_req > buff_min) ? buff_req : buff_min;
}
/* -------------------------------------------------------------------- */
int fpc1020_manage_huge_buffer(fpc1020_data_t *fpc1020, size_t new_size)
{
int error = 0;
int buffer_order_new, buffer_order_curr;
buffer_order_curr = get_order(fpc1020->huge_buffer_size);
buffer_order_new = get_order(new_size);
if (new_size == 0) {
if (fpc1020->huge_buffer) {
free_pages((unsigned long)fpc1020->huge_buffer,
buffer_order_curr);
fpc1020->huge_buffer = NULL;
}
fpc1020->huge_buffer_size = 0;
error = 0;
} else {
if (fpc1020->huge_buffer &&
(buffer_order_curr != buffer_order_new)) {
free_pages((unsigned long)fpc1020->huge_buffer,
buffer_order_curr);
fpc1020->huge_buffer = NULL;
}
if (fpc1020->huge_buffer == NULL)
{
fpc1020->huge_buffer =
(u8 *)__get_free_pages(GFP_KERNEL,
buffer_order_new);
fpc1020->huge_buffer_size = (fpc1020->huge_buffer) ?
(size_t)PAGE_SIZE << buffer_order_new : 0;
error = (fpc1020->huge_buffer_size == 0) ? -ENOMEM : 0;
}
}
if (error) {
dev_err(&fpc1020->spi->dev, "%s, failed %d\n",
__func__, error);
} else {
dev_info(&fpc1020->spi->dev, "%s, size=%d bytes\n",
__func__, (int)fpc1020->huge_buffer_size);
}
return error;
}
/* -------------------------------------------------------------------- */
int fpc1020_setup_defaults(fpc1020_data_t *fpc1020)
{
int error = 0;
const fpc1020_setup_t *ptr;
memcpy((void *)&fpc1020->diag,
(void *)&fpc1020_diag_default,
sizeof(fpc1020_diag_t));
switch (fpc1020->chip.type) {
case FPC1020_CHIP_1020A:
ptr = (fpc1020->chip.revision == 1) ? &fpc1020_setup_default_1020_a1a2 :
(fpc1020->chip.revision == 2) ? &fpc1020_setup_default_1020_a1a2 :
(fpc1020->chip.revision == 3) ? &fpc1020_setup_default_1020_a3a4 :
(fpc1020->chip.revision == 4) ? &fpc1020_setup_default_1020_a3a4 :
NULL;
break;
case FPC1020_CHIP_1021A:
ptr = (fpc1020->chip.revision == 2) ? &fpc1020_setup_default_1021_a2b1 :
NULL;
break;
case FPC1020_CHIP_1021B:
ptr = (fpc1020->chip.revision == 1) ? &fpc1020_setup_default_1021_a2b1 :
NULL;
break;
case FPC1020_CHIP_1150A:
case FPC1020_CHIP_1150B:
case FPC1020_CHIP_1150F:
ptr = (fpc1020->chip.revision == 1) ? &fpc1020_setup_default_1150_a1b1f1 :
NULL;
break;
default:
ptr = NULL;
break;
}
error = (ptr == NULL) ? -EINVAL : 0;
if (error)
goto out_err;
memcpy((void *)&fpc1020->setup, ptr, sizeof(fpc1020_setup_t));
dev_dbg(&fpc1020->spi->dev, "%s OK\n", __func__);
return 0;
out_err:
memset((void *)&fpc1020->setup, 0, sizeof(fpc1020_setup_t));
dev_err(&fpc1020->spi->dev, "%s FAILED %d\n", __func__, error);
return error;
}
/* -------------------------------------------------------------------- */
int fpc1020_gpio_reset(fpc1020_data_t *fpc1020)
{
int error = 0;
int counter = FPC1020_RESET_RETRIES;
while (counter) {
counter--;
gpio_set_value(fpc1020->reset_gpio, 1);
udelay(FPC1020_RESET_HIGH1_US);
gpio_set_value(fpc1020->reset_gpio, 0);
udelay(FPC1020_RESET_LOW_US);
gpio_set_value(fpc1020->reset_gpio, 1);
udelay(FPC1020_RESET_HIGH2_US);
error = gpio_get_value(fpc1020->irq_gpio) ? 0 : -EIO;
if (!error) {
printk(KERN_INFO "%s OK !\n", __func__);
counter = 0;
} else {
printk(KERN_INFO "%s timed out,retrying ...\n",
__func__);
udelay(1250);
}
}
return error;
}
/* -------------------------------------------------------------------- */
int fpc1020_spi_reset(fpc1020_data_t *fpc1020)
{
int error = 0;
int counter = FPC1020_RESET_RETRIES;
dev_dbg(&fpc1020->spi->dev, "%s\n", __func__);
while (counter) {
counter--;
error = fpc1020_cmd(fpc1020,
FPC1020_CMD_SOFT_RESET,
false);
if (error >= 0) {
error = fpc1020_wait_for_irq(fpc1020,
FPC1020_DEFAULT_IRQ_TIMEOUT_MS);
}
if (error >= 0) {
error = gpio_get_value(fpc1020->irq_gpio) ? 0 : -EIO;
if (!error) {
dev_dbg(&fpc1020->spi->dev,
"%s OK !\n", __func__);
counter = 0;
} else {
dev_dbg(&fpc1020->spi->dev,
"%s timed out,retrying ...\n",
__func__);
}
}
}
return error;
}
/* -------------------------------------------------------------------- */
int fpc1020_reset(fpc1020_data_t *fpc1020)
{
int error = 0;
dev_dbg(&fpc1020->spi->dev, "%s\n", __func__);
error = (fpc1020->soft_reset_enabled) ?
fpc1020_spi_reset(fpc1020) :
fpc1020_gpio_reset(fpc1020);
disable_irq(fpc1020->irq);
fpc1020->interrupt_done = false;
enable_irq(fpc1020->irq);
error = fpc1020_check_irq_after_reset(fpc1020);
if (error < 0)
goto out;
error = (gpio_get_value(fpc1020->irq_gpio) != 0) ? -EIO : 0;
if (error)
dev_err(&fpc1020->spi->dev, "IRQ pin, not low after clear.\n");
error = fpc1020_read_irq(fpc1020, true);
if (error != 0) {
dev_err(&fpc1020->spi->dev,
"IRQ register, expected 0x%x, got 0x%x.\n",
0,
(u8)error);
error = -EIO;
}
if (!error && (fpc1020->chip.type == FPC1020_CHIP_1020A))
error = fpc1020_flush_adc(fpc1020);
fpc1020->capture.available_bytes = 0;
fpc1020->capture.read_offset = 0;
fpc1020->capture.read_pending_eof = false;
out:
return error;
}
/* -------------------------------------------------------------------- */
int fpc1020_check_hw_id(fpc1020_data_t *fpc1020)
{
int error = 0;
u16 hardware_id;
fpc1020_reg_access_t reg;
int counter = 0;
bool match = false;
FPC1020_MK_REG_READ(reg, FPC102X_REG_HWID, &hardware_id);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
return error;
while (!match && chip_data[counter].type != FPC1020_CHIP_NONE) {
if (chip_data[counter].hwid == hardware_id)
match = true;
else
counter++;
}
if (match) {
fpc1020->chip.type = chip_data[counter].type;
fpc1020->chip.revision = chip_data[counter].revision;
fpc1020->chip.pixel_rows = chip_data[counter].pixel_rows;
fpc1020->chip.pixel_columns = chip_data[counter].pixel_columns;
fpc1020->chip.adc_group_size = chip_data[counter].adc_group_size;
if (fpc1020->chip.revision == 0) {
error = fpc1020_check_hw_id_extended(fpc1020);
if (error > 0) {
fpc1020->chip.revision = error;
error = 0;
}
}
dev_info(&fpc1020->spi->dev,
"Hardware id: 0x%x (%s, rev.%d) \n",
hardware_id,
chip_text[fpc1020->chip.type],
fpc1020->chip.revision);
} else {
dev_err(&fpc1020->spi->dev,
"Hardware id mismatch: got 0x%x\n", hardware_id);
fpc1020->chip.type = FPC1020_CHIP_NONE;
fpc1020->chip.revision = 0;
return -EIO;
}
return error;
}
/* -------------------------------------------------------------------- */
const char *fpc1020_hw_id_text(fpc1020_data_t *fpc1020)
{
return chip_text[fpc1020->chip.type];
}
/* -------------------------------------------------------------------- */
static int fpc1020_check_hw_id_extended(fpc1020_data_t *fpc1020)
{
int error = 0;
if (fpc1020->chip.revision != 0) {
return fpc1020->chip.revision;
}
error = (fpc1020->chip.type == FPC1020_CHIP_1020A) ?
fpc1020_hwid_1020a(fpc1020) : -EINVAL;
if (error < 0) {
dev_err(&fpc1020->spi->dev,
"%s, Unable to check chip revision %d\n",
__func__,error);
}
return (error < 0) ? error : fpc1020->chip.revision;
}
/* -------------------------------------------------------------------- */
static int fpc1020_hwid_1020a(fpc1020_data_t *fpc1020)
{
int error = 0;
int xpos, ypos, m1, m2, count;
const int num_rows = FPC1020_EXT_HWID_CHECK_ID1020A_ROWS;
const int num_pixels = 32;
const size_t image_size = num_rows * fpc1020->chip.pixel_columns;
dev_dbg(&fpc1020->spi->dev, "%s\n", __func__);
if (fpc1020->chip.type != FPC1020_CHIP_1020A)
return -EINVAL;
error = fpc1020_write_id_1020a_setup(fpc1020);
if (error)
goto out_err;
error = fpc1020_capture_set_crop(fpc1020,
0,
fpc1020->chip.pixel_columns / fpc1020->chip.adc_group_size,
0,
num_rows);
if (error)
goto out_err;
error = fpc1020_capture_buffer(fpc1020,
fpc1020->huge_buffer,
0,
image_size);
if (error)
goto out_err;
m1 = m2 = count = 0;
for (ypos = 1; ypos < num_rows; ypos++) {
for (xpos = 0; xpos < num_pixels; xpos++) {
m1 += fpc1020->huge_buffer
[(ypos * fpc1020->chip.pixel_columns) + xpos];
m2 += fpc1020->huge_buffer
[(ypos * fpc1020->chip.pixel_columns) +
(fpc1020->chip.pixel_columns - 1 - xpos)];
count++;
}
}
m1 /= count;
m2 /= count;
if (fpc1020_check_in_range_u64(m1, 181, 219) &&
fpc1020_check_in_range_u64(m2, 101, 179))
{
fpc1020->chip.revision = 1;
}
else if (fpc1020_check_in_range_u64(m1, 181, 219) &&
fpc1020_check_in_range_u64(m2, 181, 219))
{
fpc1020->chip.revision = 2;
}
else if (fpc1020_check_in_range_u64(m1, 101, 179) &&
fpc1020_check_in_range_u64(m2, 151, 179))
{
fpc1020->chip.revision = 3;
}
else if (fpc1020_check_in_range_u64(m1, 0, 99) &&
fpc1020_check_in_range_u64(m2, 0, 99))
{
fpc1020->chip.revision = 4;
}
else
{
fpc1020->chip.revision = 0;
}
dev_dbg(&fpc1020->spi->dev, "%s m1,m2 = %d,%d %s rev=%d \n", __func__,
m1, m2,
(fpc1020->chip.revision == 0) ? "UNKNOWN!" : "detected",
fpc1020->chip.revision);
out_err:
return error;
}
/* -------------------------------------------------------------------- */
static int fpc1020_write_id_1020a_setup(fpc1020_data_t *fpc1020)
{
int error = 0;
u8 temp_u8;
u16 temp_u16;
fpc1020_reg_access_t reg;
temp_u16 = 15 << 8;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ADC_SHIFT_GAIN, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = 0xffff;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_TST_COL_PATTERN_EN, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = 0x04;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_CONF, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
out:
return error;
}
/* -------------------------------------------------------------------- */
int fpc1020_write_sensor_setup(fpc1020_data_t *fpc1020)
{
switch (fpc1020->chip.type)
{
case FPC1020_CHIP_1020A:
return fpc1020_write_sensor_1020a_setup(fpc1020);
case FPC1020_CHIP_1021A:
case FPC1020_CHIP_1021B:
return fpc1020_write_sensor_1021_setup(fpc1020);
case FPC1020_CHIP_1150A:
case FPC1020_CHIP_1150B:
case FPC1020_CHIP_1150F:
return fpc1020_write_sensor_1150_setup(fpc1020);
default:
break;
}
return -EINVAL;
}
/* -------------------------------------------------------------------- */
static int fpc1020_write_sensor_1020a_setup(fpc1020_data_t *fpc1020)
{
switch (fpc1020->chip.revision)
{
case 1:
case 2:
return fpc1020_write_sensor_1020a_a1a2_setup(fpc1020);
case 3:
case 4:
return fpc1020_write_sensor_1020a_a3a4_setup(fpc1020);
default:
break;
}
return -EINVAL;
}
/* -------------------------------------------------------------------- */
static int fpc1020_write_sensor_1020a_a1a2_setup(fpc1020_data_t *fpc1020)
{
int error = 0;
u8 temp_u8;
u16 temp_u16;
u32 temp_u32;
u64 temp_u64;
fpc1020_reg_access_t reg;
const int mux = FPC1020_MAX_ADC_SETTINGS - 1;
const int rev = fpc1020->chip.revision;
dev_dbg(&fpc1020->spi->dev, "%s %d\n", __func__, mux);
if ((rev != 1) && (rev != 2))
return -EINVAL;
temp_u64 = (rev == 1) ? 0x363636363f3f3f3f : 0x141414141e1e1e1e;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_SAMPLE_PX_DLY, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = (rev == 1) ? 0x33 : 0x0f;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_PXL_RST_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = (rev == 1) ? 0x37 : 0x15;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u64 = 0x5540003f24;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ADC_SETUP, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u32 = 0x00080000;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ANA_TEST_MUX, &temp_u32);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u64 = 0x5540003f34;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ADC_SETUP, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = (fpc1020->vddtx_mv > 0) ? 0x02 : /* external supply */
(fpc1020->txout_boost) ? 0x22 : 0x12; /* internal supply */
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_CONF, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.adc_shift[mux];
temp_u16 <<= 8;
temp_u16 |= fpc1020->setup.adc_gain[mux];
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ADC_SHIFT_GAIN, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.pxl_ctrl[mux];
temp_u16 |= FPC1020_PXL_BIAS_CTRL;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_PXL_CTRL, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = 0x03 | 0x08;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_IMAGE_SETUP, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = fpc1020->setup.finger_detect_threshold;
FPC1020_MK_REG_WRITE(reg, FPC1020_REG_FNGR_DET_THRES, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = 0x00ff;
FPC1020_MK_REG_WRITE(reg, FPC1020_REG_FNGR_DET_CNTR, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
out:
return error;
}
/* -------------------------------------------------------------------- */
static int fpc1020_write_sensor_1020a_a3a4_setup(fpc1020_data_t *fpc1020)
{
int error = 0;
u8 temp_u8;
u16 temp_u16;
u64 temp_u64;
fpc1020_reg_access_t reg;
const int mux = FPC1020_MAX_ADC_SETTINGS - 1;
const int rev = fpc1020->chip.revision;
dev_dbg(&fpc1020->spi->dev, "%s %d\n", __func__, mux);
if (rev == 4)
{
temp_u8 = 0x09;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u64 = 0x0808080814141414;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_SAMPLE_PX_DLY, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
}
else if (rev == 3)
{
temp_u64 = 0x1717171723232323;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_SAMPLE_PX_DLY, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = 0x0f;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_PXL_RST_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = 0x18;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
}
else
{
error = -EINVAL;
goto out;
}
temp_u8 = (fpc1020->vddtx_mv > 0) ? 0x02 : /* external supply */
(fpc1020->txout_boost) ? 0x22 : 0x12; /* internal supply */
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_CONF, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.adc_shift[mux];
temp_u16 <<= 8;
temp_u16 |= fpc1020->setup.adc_gain[mux];
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ADC_SHIFT_GAIN, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.pxl_ctrl[mux];
temp_u16 |= FPC1020_PXL_BIAS_CTRL;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_PXL_CTRL, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = 0x03 | 0x08;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_IMAGE_SETUP, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = fpc1020->setup.finger_detect_threshold;
FPC1020_MK_REG_WRITE(reg, FPC1020_REG_FNGR_DET_THRES, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = 0x00ff;
FPC1020_MK_REG_WRITE(reg, FPC1020_REG_FNGR_DET_CNTR, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
out:
return error;
}
/* -------------------------------------------------------------------- */
static int fpc1020_write_sensor_1021_setup(fpc1020_data_t *fpc1020)
{
int error = 0;
u8 temp_u8;
u16 temp_u16;
u64 temp_u64;
fpc1020_reg_access_t reg;
const int mux = FPC1020_MAX_ADC_SETTINGS - 1;
const int rev = fpc1020->chip.revision;
dev_dbg(&fpc1020->spi->dev, "%s %d\n", __func__, mux);
if (rev == 0)
return -EINVAL;
temp_u8 = 0x09;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u64 = 0x0808080814141414;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_SAMPLE_PX_DLY, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = (fpc1020->vddtx_mv > 0) ? 0x02 : /* external supply */
(fpc1020->txout_boost) ? 0x22 : 0x12; /* internal supply */
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_CONF, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.adc_shift[mux];
temp_u16 <<= 8;
temp_u16 |= fpc1020->setup.adc_gain[mux];
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_ADC_SHIFT_GAIN, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.pxl_ctrl[mux];
temp_u16 |= FPC1020_PXL_BIAS_CTRL;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_PXL_CTRL, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = 0x03 | 0x08;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_IMAGE_SETUP, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = fpc1020->setup.finger_detect_threshold;
FPC1020_MK_REG_WRITE(reg, FPC1020_REG_FNGR_DET_THRES, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = 0x00ff;
FPC1020_MK_REG_WRITE(reg, FPC1020_REG_FNGR_DET_CNTR, &temp_u16);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
out:
return error;
}
/* -------------------------------------------------------------------- */
static int fpc1020_write_sensor_1150_setup(fpc1020_data_t *fpc1020)
{
int error = 0;
u8 temp_u8;
u16 temp_u16;
u32 temp_u32;
u64 temp_u64;
fpc1020_reg_access_t reg;
const int mux = FPC1020_MAX_ADC_SETTINGS - 1;
const int rev = fpc1020->chip.revision;
dev_dbg(&fpc1020->spi->dev, "%s %d\n", __func__, mux);
if (rev == 0)
return -EINVAL;
temp_u8 = 0x09;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_DLY, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u64 = 0x0808080814141414;
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_SAMPLE_PX_DLY, &temp_u64);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u8 = (fpc1020->vddtx_mv > 0) ? 0x02 : /* external supply */
(fpc1020->txout_boost) ? 0x22 : 0x12; /* internal supply */
FPC1020_MK_REG_WRITE(reg, FPC102X_REG_FINGER_DRIVE_CONF, &temp_u8);
error = fpc1020_reg_access(fpc1020, ®);
if (error)
goto out;
temp_u16 = fpc1020->setup.adc_shift[mux];