-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtuner_r820t.c
2916 lines (2438 loc) · 95.3 KB
/
tuner_r820t.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
/*
* R820T tuner driver, taken from Realteks RTL2832U Linux Kernel Driver
*
* This driver is a mess, and should be cleaned up/rewritten.
*
*/
#include <stdint.h>
#include <stdio.h>
#include "rtlsdr_i2c.h"
#include "tuner_r820t.h"
int r820t_SetRfFreqHz(void *pTuner, unsigned long RfFreqHz)
{
R828_Set_Info R828Info;
// if(pExtra->IsStandardModeSet==NO)
// goto error_status_set_tuner_rf_frequency;
// R828Info.R828_Standard = (R828_Standard_Type)pExtra->StandardMode;
R828Info.R828_Standard = (R828_Standard_Type) DVB_T_6M;
R828Info.RF_Hz = (UINT32) (RfFreqHz);
R828Info.RF_KHz = (UINT32) (RfFreqHz / 1000);
if (R828_SetFrequency(pTuner, R828Info, NORMAL_MODE) != RT_Success)
return FUNCTION_ERROR;
return FUNCTION_SUCCESS;
}
int r820t_SetStandardMode(void *pTuner, int StandardMode)
{
if (R828_SetStandard(pTuner, (R828_Standard_Type) StandardMode) != RT_Success)
return FUNCTION_ERROR;
return FUNCTION_SUCCESS;
}
int r820t_SetStandby(void *pTuner, int LoopThroughType)
{
if (R828_Standby(pTuner, (R828_LoopThrough_Type) LoopThroughType) != RT_Success)
return FUNCTION_ERROR;
return FUNCTION_SUCCESS;
}
// The following context is implemented for R820T source code.
/* just reverses the bits of a byte */
int r820t_Convert(int InvertNum)
{
int ReturnNum;
int AddNum;
int BitNum;
int CountNum;
ReturnNum = 0;
AddNum = 0x80;
BitNum = 0x01;
for (CountNum = 0; CountNum < 8; CountNum++) {
if (BitNum & InvertNum)
ReturnNum += AddNum;
AddNum /= 2;
BitNum *= 2;
}
return ReturnNum;
}
R828_ErrCode I2C_Write_Len(void *pTuner, R828_I2C_LEN_TYPE * I2C_Info)
{
unsigned int i, j;
unsigned char RegStartAddr;
unsigned char *pWritingBytes;
unsigned long ByteNum;
unsigned char WritingBuffer[128];
unsigned long WritingByteNum, WritingByteNumMax, WritingByteNumRem;
unsigned char RegWritingAddr;
// Get regiser start address, writing bytes, and byte number.
RegStartAddr = I2C_Info->RegAddr;
pWritingBytes = I2C_Info->Data;
ByteNum = (unsigned long) I2C_Info->Len;
// Calculate maximum writing byte number.
// WritingByteNumMax = pBaseInterface->I2cWritingByteNumMax - LEN_1_BYTE;
WritingByteNumMax = 2 - 1; //9 orig
// Set tuner register bytes with writing bytes.
// Note: Set tuner register bytes considering maximum writing byte number.
for (i = 0; i < ByteNum; i += WritingByteNumMax) {
// Set register writing address.
RegWritingAddr = RegStartAddr + i;
// Calculate remainder writing byte number.
WritingByteNumRem = ByteNum - i;
// Determine writing byte number.
WritingByteNum = (WritingByteNumRem > WritingByteNumMax) ? WritingByteNumMax : WritingByteNumRem;
// Set writing buffer.
// Note: The I2C format of tuner register byte setting is as follows:
// start_bit + (DeviceAddr | writing_bit) + RegWritingAddr + writing_bytes (WritingByteNum bytes) +
// stop_bit
WritingBuffer[0] = RegWritingAddr;
for (j = 0; j < WritingByteNum; j++)
WritingBuffer[j + 1] = pWritingBytes[i + j];
// Set tuner register bytes with writing buffer.
// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, DeviceAddr, WritingBuffer, WritingByteNum + LEN_1_BYTE) !=
// FUNCTION_SUCCESS)
// goto error_status_set_tuner_registers;
if (rtlsdr_i2c_write_fn(pTuner, R820T_I2C_ADDR, WritingBuffer, WritingByteNum + 1) < 0)
return RT_Fail;
}
return RT_Success;
}
R828_ErrCode I2C_Read_Len(void *pTuner, R828_I2C_LEN_TYPE * I2C_Info)
{
unsigned int i;
uint8_t RegStartAddr;
uint8_t ReadingBytes[128];
unsigned long ByteNum;
// Get regiser start address, writing bytes, and byte number.
RegStartAddr = 0x00;
ByteNum = (unsigned long) I2C_Info->Len;
// Set tuner register reading address.
// Note: The I2C format of tuner register reading address setting is as follows:
// start_bit + (DeviceAddr | writing_bit) + RegReadingAddr + stop_bit
// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, DeviceAddr, &RegStartAddr, LEN_1_BYTE) != FUNCTION_SUCCESS)
// goto error_status_set_tuner_register_reading_address;
if (rtlsdr_i2c_write_fn(pTuner, R820T_I2C_ADDR, &RegStartAddr, 1) < 0)
return RT_Fail;
// Get tuner register bytes.
// Note: The I2C format of tuner register byte getting is as follows:
// start_bit + (DeviceAddr | reading_bit) + reading_bytes (ReadingByteNum bytes) + stop_bit
// if(pI2cBridge->ForwardI2cReadingCmd(pI2cBridge, DeviceAddr, ReadingBytes, ByteNum) != FUNCTION_SUCCESS)
// goto error_status_get_tuner_registers;
if (rtlsdr_i2c_read_fn(pTuner, R820T_I2C_ADDR, ReadingBytes, ByteNum) < 0)
return RT_Fail;
for (i = 0; i < ByteNum; i++) {
I2C_Info->Data[i] = (UINT8) r820t_Convert(ReadingBytes[i]);
}
return RT_Success;
//error_status_get_tuner_registers:
//error_status_set_tuner_register_reading_address:
return RT_Fail;
}
R828_ErrCode I2C_Write(void *pTuner, R828_I2C_TYPE * I2C_Info)
{
uint8_t WritingBuffer[2];
// Set writing bytes.
// Note: The I2C format of tuner register byte setting is as follows:
// start_bit + (DeviceAddr | writing_bit) + addr + data + stop_bit
WritingBuffer[0] = I2C_Info->RegAddr;
WritingBuffer[1] = I2C_Info->Data;
// Set tuner register bytes with writing buffer.
// if(pI2cBridge->ForwardI2cWritingCmd(pI2cBridge, DeviceAddr, WritingBuffer, LEN_2_BYTE) != FUNCTION_SUCCESS)
// goto error_status_set_tuner_registers;
// printf("called %s: %02x -> %02x\n", __FUNCTION__, WritingBuffer[0], WritingBuffer[1]);
if (rtlsdr_i2c_write_fn(pTuner, R820T_I2C_ADDR, WritingBuffer, 2) < 0)
return RT_Fail;
return RT_Success;
}
void R828_Delay_MS()
{
/* simply don't wait for now */
return;
}
//-----------------------------------------------------
//
// Filename: R820T.c
//
// This file is R820T tuner driver
// Copyright 2011 by Rafaelmicro., Inc.
//
//-----------------------------------------------------
//#include "stdafx.h"
//#include "R828.h"
//#include "..\I2C_Sys.h"
#if(TUNER_CLK_OUT==TRUE) //enable tuner clk output for share Xtal application
UINT8 R828_iniArry[27] = { 0x83, 0x32, 0x75, 0xC0, 0x40, 0xD6, 0x6C, 0xF5, 0x63,
/* 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D */
0x75, 0x68, 0x6C, 0x83, 0x80, 0x00, 0x0F, 0x00, 0xC0, //xtal_check
/* 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x16 */
0x30, 0x48, 0xCC, 0x60, 0x00, 0x54, 0xAE, 0x4A, 0xC0
};
/* 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E 0x1F */
#else
UINT8 R828_iniArry[27] = { 0x83, 0x32, 0x75, 0xC0, 0x40, 0xD6, 0x6C, 0xF5, 0x63,
/* 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D */
0x75, 0x78, 0x6C, 0x83, 0x80, 0x00, 0x0F, 0x00, 0xC0, //xtal_check
/* 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x16 */
0x30, 0x48, 0xCC, 0x60, 0x00, 0x54, 0xAE, 0x4A, 0xC0
};
/* 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E 0x1F */
#endif
UINT8 R828_ADDRESS = 0x34;
UINT8 Rafael_Chip = R820T;
//----------------------------------------------------------//
// Internal Structs //
//----------------------------------------------------------//
typedef struct _R828_SectType {
UINT8 Phase_Y;
UINT8 Gain_X;
UINT16 Value;
} R828_SectType;
typedef enum _BW_Type {
BW_6M = 0,
BW_7M,
BW_8M,
BW_1_7M,
BW_10M,
BW_200K
} BW_Type;
typedef struct _Sys_Info_Type {
UINT16 IF_KHz;
BW_Type BW;
UINT32 FILT_CAL_LO;
UINT8 FILT_GAIN;
UINT8 IMG_R;
UINT8 FILT_Q;
UINT8 HP_COR;
UINT8 EXT_ENABLE;
UINT8 LOOP_THROUGH;
UINT8 LT_ATT;
UINT8 FLT_EXT_WIDEST;
UINT8 POLYFIL_CUR;
} Sys_Info_Type;
typedef struct _Freq_Info_Type {
UINT8 OPEN_D;
UINT8 RF_MUX_PLOY;
UINT8 TF_C;
UINT8 XTAL_CAP20P;
UINT8 XTAL_CAP10P;
UINT8 XTAL_CAP0P;
UINT8 IMR_MEM;
} Freq_Info_Type;
typedef struct _SysFreq_Info_Type {
UINT8 LNA_TOP;
UINT8 LNA_VTH_L;
UINT8 MIXER_TOP;
UINT8 MIXER_VTH_L;
UINT8 AIR_CABLE1_IN;
UINT8 CABLE2_IN;
UINT8 PRE_DECT;
UINT8 LNA_DISCHARGE;
UINT8 CP_CUR;
UINT8 DIV_BUF_CUR;
UINT8 FILTER_CUR;
} SysFreq_Info_Type;
//----------------------------------------------------------//
// Internal Parameters //
//----------------------------------------------------------//
enum XTAL_CAP_VALUE {
XTAL_LOW_CAP_30P = 0,
XTAL_LOW_CAP_20P,
XTAL_LOW_CAP_10P,
XTAL_LOW_CAP_0P,
XTAL_HIGH_CAP_0P
};
UINT8 R828_Arry[27];
R828_SectType IMR_Data[5] = {
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
}; //Please keep this array data for standby mode.
R828_I2C_TYPE R828_I2C;
R828_I2C_LEN_TYPE R828_I2C_Len;
UINT32 R828_IF_khz;
UINT32 R828_CAL_LO_khz;
UINT8 R828_IMR_point_num;
UINT8 R828_IMR_done_flag = FALSE;
UINT8 R828_Fil_Cal_flag[STD_SIZE];
static UINT8 R828_Fil_Cal_code[STD_SIZE];
static UINT8 Xtal_cap_sel = XTAL_LOW_CAP_0P;
static UINT8 Xtal_cap_sel_tmp = XTAL_LOW_CAP_0P;
//----------------------------------------------------------//
// Internal static struct //
//----------------------------------------------------------//
static SysFreq_Info_Type SysFreq_Info1;
static Sys_Info_Type Sys_Info1;
//static Freq_Info_Type R828_Freq_Info;
static Freq_Info_Type Freq_Info1;
//----------------------------------------------------------//
// Internal Functions //
//----------------------------------------------------------//
R828_ErrCode R828_Xtal_Check(void *pTuner);
R828_ErrCode R828_InitReg(void *pTuner);
R828_ErrCode R828_IMR_Prepare(void *pTuner);
R828_ErrCode R828_IMR(void *pTuner, UINT8 IMR_MEM, int IM_Flag);
R828_ErrCode R828_PLL(void *pTuner, UINT32 LO_Freq, R828_Standard_Type R828_Standard);
R828_ErrCode R828_MUX(void *pTuner, UINT32 RF_KHz);
R828_ErrCode R828_IQ(void *pTuner, R828_SectType * IQ_Pont);
R828_ErrCode R828_IQ_Tree(void *pTuner, UINT8 FixPot, UINT8 FlucPot, UINT8 PotReg,
R828_SectType * CompareTree);
R828_ErrCode R828_CompreCor(R828_SectType * CorArry);
R828_ErrCode R828_CompreStep(void *pTuner, R828_SectType * StepArry, UINT8 Pace);
R828_ErrCode R828_Muti_Read(void *pTuner, UINT8 IMR_Reg, UINT16 * IMR_Result_Data);
R828_ErrCode R828_Section(void *pTuner, R828_SectType * SectionArry);
R828_ErrCode R828_F_IMR(void *pTuner, R828_SectType * IQ_Pont);
R828_ErrCode R828_IMR_Cross(void *pTuner, R828_SectType * IQ_Pont, UINT8 * X_Direct);
Sys_Info_Type R828_Sys_Sel(R828_Standard_Type R828_Standard);
Freq_Info_Type R828_Freq_Sel(UINT32 RF_freq);
SysFreq_Info_Type R828_SysFreq_Sel(R828_Standard_Type R828_Standard, UINT32 RF_freq);
R828_ErrCode R828_Filt_Cal(void *pTuner, UINT32 Cal_Freq);
//R828_ErrCode R828_SetFrequency(void *pTuner, R828_Set_Info R828_INFO, R828_SetFreq_Type R828_SetFreqMode);
Sys_Info_Type R828_Sys_Sel(R828_Standard_Type R828_Standard)
{
Sys_Info_Type R828_Sys_Info;
switch (R828_Standard) {
case DVB_T_6M:
case DVB_T2_6M:
R828_Sys_Info.IF_KHz = 3570;
R828_Sys_Info.BW = BW_6M;
R828_Sys_Info.FILT_CAL_LO = 56000; //52000->56000
R828_Sys_Info.FILT_GAIN = 0x10; //+3dB, 6MHz on
R828_Sys_Info.IMG_R = 0x00; //image negative
R828_Sys_Info.FILT_Q = 0x10; //R10[4]:low Q(1'b1)
R828_Sys_Info.HP_COR = 0x6B; // 1.7M disable, +2cap, 1.0MHz
R828_Sys_Info.EXT_ENABLE = 0x60; //R30[6]=1 ext enable; R30[5]:1 ext at LNA max-1
R828_Sys_Info.LOOP_THROUGH = 0x00; //R5[7], LT ON
R828_Sys_Info.LT_ATT = 0x00; //R31[7], LT ATT enable
R828_Sys_Info.FLT_EXT_WIDEST = 0x00; //R15[7]: FLT_EXT_WIDE OFF
R828_Sys_Info.POLYFIL_CUR = 0x60; //R25[6:5]:Min
break;
case DVB_T_7M:
case DVB_T2_7M:
R828_Sys_Info.IF_KHz = 4070;
R828_Sys_Info.BW = BW_7M;
R828_Sys_Info.FILT_CAL_LO = 60000;
R828_Sys_Info.FILT_GAIN = 0x10; //+3dB, 6MHz on
R828_Sys_Info.IMG_R = 0x00; //image negative
R828_Sys_Info.FILT_Q = 0x10; //R10[4]:low Q(1'b1)
R828_Sys_Info.HP_COR = 0x2B; // 1.7M disable, +1cap, 1.0MHz
R828_Sys_Info.EXT_ENABLE = 0x60; //R30[6]=1 ext enable; R30[5]:1 ext at LNA max-1
R828_Sys_Info.LOOP_THROUGH = 0x00; //R5[7], LT ON
R828_Sys_Info.LT_ATT = 0x00; //R31[7], LT ATT enable
R828_Sys_Info.FLT_EXT_WIDEST = 0x00; //R15[7]: FLT_EXT_WIDE OFF
R828_Sys_Info.POLYFIL_CUR = 0x60; //R25[6:5]:Min
break;
case DVB_T_7M_2:
case DVB_T2_7M_2:
R828_Sys_Info.IF_KHz = 4570;
R828_Sys_Info.BW = BW_7M;
R828_Sys_Info.FILT_CAL_LO = 63000;
R828_Sys_Info.FILT_GAIN = 0x10; //+3dB, 6MHz on
R828_Sys_Info.IMG_R = 0x00; //image negative
R828_Sys_Info.FILT_Q = 0x10; //R10[4]:low Q(1'b1)
R828_Sys_Info.HP_COR = 0x2A; // 1.7M disable, +1cap, 1.25MHz
R828_Sys_Info.EXT_ENABLE = 0x60; //R30[6]=1 ext enable; R30[5]:1 ext at LNA max-1
R828_Sys_Info.LOOP_THROUGH = 0x00; //R5[7], LT ON
R828_Sys_Info.LT_ATT = 0x00; //R31[7], LT ATT enable
R828_Sys_Info.FLT_EXT_WIDEST = 0x00; //R15[7]: FLT_EXT_WIDE OFF
R828_Sys_Info.POLYFIL_CUR = 0x60; //R25[6:5]:Min
break;
case DVB_T_8M:
case DVB_T2_8M:
R828_Sys_Info.IF_KHz = 4570;
R828_Sys_Info.BW = BW_8M;
R828_Sys_Info.FILT_CAL_LO = 68500;
R828_Sys_Info.FILT_GAIN = 0x10; //+3dB, 6MHz on
R828_Sys_Info.IMG_R = 0x00; //image negative
R828_Sys_Info.FILT_Q = 0x10; //R10[4]:low Q(1'b1)
R828_Sys_Info.HP_COR = 0x0B; // 1.7M disable, +0cap, 1.0MHz
R828_Sys_Info.EXT_ENABLE = 0x60; //R30[6]=1 ext enable; R30[5]:1 ext at LNA max-1
R828_Sys_Info.LOOP_THROUGH = 0x00; //R5[7], LT ON
R828_Sys_Info.LT_ATT = 0x00; //R31[7], LT ATT enable
R828_Sys_Info.FLT_EXT_WIDEST = 0x00; //R15[7]: FLT_EXT_WIDE OFF
R828_Sys_Info.POLYFIL_CUR = 0x60; //R25[6:5]:Min
break;
case ISDB_T:
R828_Sys_Info.IF_KHz = 4063;
R828_Sys_Info.BW = BW_6M;
R828_Sys_Info.FILT_CAL_LO = 59000;
R828_Sys_Info.FILT_GAIN = 0x10; //+3dB, 6MHz on
R828_Sys_Info.IMG_R = 0x00; //image negative
R828_Sys_Info.FILT_Q = 0x10; //R10[4]:low Q(1'b1)
R828_Sys_Info.HP_COR = 0x6A; // 1.7M disable, +2cap, 1.25MHz
R828_Sys_Info.EXT_ENABLE = 0x40; //R30[6], ext enable; R30[5]:0 ext at LNA max
R828_Sys_Info.LOOP_THROUGH = 0x00; //R5[7], LT ON
R828_Sys_Info.LT_ATT = 0x00; //R31[7], LT ATT enable
R828_Sys_Info.FLT_EXT_WIDEST = 0x00; //R15[7]: FLT_EXT_WIDE OFF
R828_Sys_Info.POLYFIL_CUR = 0x60; //R25[6:5]:Min
break;
default: //DVB_T_8M
R828_Sys_Info.IF_KHz = 4570;
R828_Sys_Info.BW = BW_8M;
R828_Sys_Info.FILT_CAL_LO = 68500;
R828_Sys_Info.FILT_GAIN = 0x10; //+3dB, 6MHz on
R828_Sys_Info.IMG_R = 0x00; //image negative
R828_Sys_Info.FILT_Q = 0x10; //R10[4]:low Q(1'b1)
R828_Sys_Info.HP_COR = 0x0D; // 1.7M disable, +0cap, 0.7MHz
R828_Sys_Info.EXT_ENABLE = 0x60; //R30[6]=1 ext enable; R30[5]:1 ext at LNA max-1
R828_Sys_Info.LOOP_THROUGH = 0x00; //R5[7], LT ON
R828_Sys_Info.LT_ATT = 0x00; //R31[7], LT ATT enable
R828_Sys_Info.FLT_EXT_WIDEST = 0x00; //R15[7]: FLT_EXT_WIDE OFF
R828_Sys_Info.POLYFIL_CUR = 0x60; //R25[6:5]:Min
break;
}
return R828_Sys_Info;
}
Freq_Info_Type R828_Freq_Sel(UINT32 LO_freq)
{
Freq_Info_Type R828_Freq_Info;
// printf("LO_freq in Freq_Info = %u \n", LO_freq);
if (LO_freq < 50000) {
R828_Freq_Info.OPEN_D = 0x08; // low
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0xDF; //R27[7:0] band2,band0
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
}
else if (LO_freq >= 50000 && LO_freq < 55000) {
R828_Freq_Info.OPEN_D = 0x08; // low
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0xBE; //R27[7:0] band4,band1
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 55000 && LO_freq < 60000) {
R828_Freq_Info.OPEN_D = 0x08; // low
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x8B; //R27[7:0] band7,band4
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 60000 && LO_freq < 65000) {
R828_Freq_Info.OPEN_D = 0x08; // low
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x7B; //R27[7:0] band8,band4
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 65000 && LO_freq < 70000) {
R828_Freq_Info.OPEN_D = 0x08; // low
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x69; //R27[7:0] band9,band6
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 70000 && LO_freq < 75000) {
R828_Freq_Info.OPEN_D = 0x08; // low
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x58; //R27[7:0] band10,band7
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 75000 && LO_freq < 80000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x44; //R27[7:0] band11,band11
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 80000 && LO_freq < 90000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x44; //R27[7:0] band11,band11
R828_Freq_Info.XTAL_CAP20P = 0x02; //R16[1:0] 20pF (10)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 90000 && LO_freq < 100000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x34; //R27[7:0] band12,band11
R828_Freq_Info.XTAL_CAP20P = 0x01; //R16[1:0] 10pF (01)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 100000 && LO_freq < 110000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x34; //R27[7:0] band12,band11
R828_Freq_Info.XTAL_CAP20P = 0x01; //R16[1:0] 10pF (01)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 0;
} else if (LO_freq >= 110000 && LO_freq < 120000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x24; //R27[7:0] band13,band11
R828_Freq_Info.XTAL_CAP20P = 0x01; //R16[1:0] 10pF (01)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 1;
} else if (LO_freq >= 120000 && LO_freq < 140000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x24; //R27[7:0] band13,band11
R828_Freq_Info.XTAL_CAP20P = 0x01; //R16[1:0] 10pF (01)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 1;
} else if (LO_freq >= 140000 && LO_freq < 180000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x14; //R27[7:0] band14,band11
R828_Freq_Info.XTAL_CAP20P = 0x01; //R16[1:0] 10pF (01)
R828_Freq_Info.XTAL_CAP10P = 0x01;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 1;
} else if (LO_freq >= 180000 && LO_freq < 220000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x13; //R27[7:0] band14,band12
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 1;
} else if (LO_freq >= 220000 && LO_freq < 250000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x13; //R27[7:0] band14,band12
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 2;
} else if (LO_freq >= 250000 && LO_freq < 280000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x11; //R27[7:0] highest,highest
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 2;
} else if (LO_freq >= 280000 && LO_freq < 310000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x02; //R26[7:6]=0 (LPF) R26[1:0]=2 (low)
R828_Freq_Info.TF_C = 0x00; //R27[7:0] highest,highest
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 2;
} else if (LO_freq >= 310000 && LO_freq < 450000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x41; //R26[7:6]=1 (bypass) R26[1:0]=1 (middle)
R828_Freq_Info.TF_C = 0x00; //R27[7:0] highest,highest
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 2;
} else if (LO_freq >= 450000 && LO_freq < 588000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x41; //R26[7:6]=1 (bypass) R26[1:0]=1 (middle)
R828_Freq_Info.TF_C = 0x00; //R27[7:0] highest,highest
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 3;
} else if (LO_freq >= 588000 && LO_freq < 650000) {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x40; //R26[7:6]=1 (bypass) R26[1:0]=0 (highest)
R828_Freq_Info.TF_C = 0x00; //R27[7:0] highest,highest
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 3;
} else {
R828_Freq_Info.OPEN_D = 0x00; // high
R828_Freq_Info.RF_MUX_PLOY = 0x40; //R26[7:6]=1 (bypass) R26[1:0]=0 (highest)
R828_Freq_Info.TF_C = 0x00; //R27[7:0] highest,highest
R828_Freq_Info.XTAL_CAP20P = 0x00; //R16[1:0] 0pF (00)
R828_Freq_Info.XTAL_CAP10P = 0x00;
R828_Freq_Info.XTAL_CAP0P = 0x00;
R828_Freq_Info.IMR_MEM = 4;
}
return R828_Freq_Info;
}
SysFreq_Info_Type R828_SysFreq_Sel(R828_Standard_Type R828_Standard, UINT32 RF_freq)
{
SysFreq_Info_Type R828_SysFreq_Info;
switch (R828_Standard) {
case DVB_T_6M:
case DVB_T_7M:
case DVB_T_7M_2:
case DVB_T_8M:
if ((RF_freq == 506000) || (RF_freq == 666000) || (RF_freq == 818000)) {
R828_SysFreq_Info.MIXER_TOP = 0x14; // MIXER TOP:14 , TOP-1, low-discharge
R828_SysFreq_Info.LNA_TOP = 0xE5; // Detect BW 3, LNA TOP:4, PreDet Top:2
R828_SysFreq_Info.CP_CUR = 0x28; //101, 0.2
R828_SysFreq_Info.DIV_BUF_CUR = 0x20; // 10, 200u
} else {
R828_SysFreq_Info.MIXER_TOP = 0x24; // MIXER TOP:13 , TOP-1, low-discharge
R828_SysFreq_Info.LNA_TOP = 0xE5; // Detect BW 3, LNA TOP:4, PreDet Top:2
R828_SysFreq_Info.CP_CUR = 0x38; // 111, auto
R828_SysFreq_Info.DIV_BUF_CUR = 0x30; // 11, 150u
}
R828_SysFreq_Info.LNA_VTH_L = 0x53; // LNA VTH 0.84 , VTL 0.64
R828_SysFreq_Info.MIXER_VTH_L = 0x75; // MIXER VTH 1.04, VTL 0.84
R828_SysFreq_Info.AIR_CABLE1_IN = 0x00;
R828_SysFreq_Info.CABLE2_IN = 0x00;
R828_SysFreq_Info.PRE_DECT = 0x40;
R828_SysFreq_Info.LNA_DISCHARGE = 14;
R828_SysFreq_Info.FILTER_CUR = 0x40; // 10, low
break;
case DVB_T2_6M:
case DVB_T2_7M:
case DVB_T2_7M_2:
case DVB_T2_8M:
R828_SysFreq_Info.MIXER_TOP = 0x24; // MIXER TOP:13 , TOP-1, low-discharge
R828_SysFreq_Info.LNA_TOP = 0xE5; // Detect BW 3, LNA TOP:4, PreDet Top:2
R828_SysFreq_Info.LNA_VTH_L = 0x53; // LNA VTH 0.84 , VTL 0.64
R828_SysFreq_Info.MIXER_VTH_L = 0x75; // MIXER VTH 1.04, VTL 0.84
R828_SysFreq_Info.AIR_CABLE1_IN = 0x00;
R828_SysFreq_Info.CABLE2_IN = 0x00;
R828_SysFreq_Info.PRE_DECT = 0x40;
R828_SysFreq_Info.LNA_DISCHARGE = 14;
R828_SysFreq_Info.CP_CUR = 0x38; // 111, auto
R828_SysFreq_Info.DIV_BUF_CUR = 0x30; // 11, 150u
R828_SysFreq_Info.FILTER_CUR = 0x40; // 10, low
break;
case ISDB_T:
R828_SysFreq_Info.MIXER_TOP = 0x24; // MIXER TOP:13 , TOP-1, low-discharge
R828_SysFreq_Info.LNA_TOP = 0xE5; // Detect BW 3, LNA TOP:4, PreDet Top:2
R828_SysFreq_Info.LNA_VTH_L = 0x75; // LNA VTH 1.04 , VTL 0.84
R828_SysFreq_Info.MIXER_VTH_L = 0x75; // MIXER VTH 1.04, VTL 0.84
R828_SysFreq_Info.AIR_CABLE1_IN = 0x00;
R828_SysFreq_Info.CABLE2_IN = 0x00;
R828_SysFreq_Info.PRE_DECT = 0x40;
R828_SysFreq_Info.LNA_DISCHARGE = 14;
R828_SysFreq_Info.CP_CUR = 0x38; // 111, auto
R828_SysFreq_Info.DIV_BUF_CUR = 0x30; // 11, 150u
R828_SysFreq_Info.FILTER_CUR = 0x40; // 10, low
break;
default: //DVB-T 8M
R828_SysFreq_Info.MIXER_TOP = 0x24; // MIXER TOP:13 , TOP-1, low-discharge
R828_SysFreq_Info.LNA_TOP = 0xE5; // Detect BW 3, LNA TOP:4, PreDet Top:2
R828_SysFreq_Info.LNA_VTH_L = 0x53; // LNA VTH 0.84 , VTL 0.64
R828_SysFreq_Info.MIXER_VTH_L = 0x75; // MIXER VTH 1.04, VTL 0.84
R828_SysFreq_Info.AIR_CABLE1_IN = 0x00;
R828_SysFreq_Info.CABLE2_IN = 0x00;
R828_SysFreq_Info.PRE_DECT = 0x40;
R828_SysFreq_Info.LNA_DISCHARGE = 14;
R828_SysFreq_Info.CP_CUR = 0x38; // 111, auto
R828_SysFreq_Info.DIV_BUF_CUR = 0x30; // 11, 150u
R828_SysFreq_Info.FILTER_CUR = 0x40; // 10, low
break;
} //end switch
//DTV use Diplexer
#if(USE_DIPLEXER==TRUE)
if ((Rafael_Chip == R820C) || (Rafael_Chip == R820T) || (Rafael_Chip == R828S)) {
// Air-in (>=DIP_FREQ) & cable-1(<DIP_FREQ)
if (RF_freq >= DIP_FREQ) {
R828_SysFreq_Info.AIR_CABLE1_IN = 0x00; //air in, cable-1 off
R828_SysFreq_Info.CABLE2_IN = 0x00; //cable-2 off
} else {
R828_SysFreq_Info.AIR_CABLE1_IN = 0x60; //cable-1 in, air off
R828_SysFreq_Info.CABLE2_IN = 0x00; //cable-2 off
}
}
#endif
return R828_SysFreq_Info;
}
R828_ErrCode R828_Xtal_Check(void *pTuner)
{
UINT8 ArrayNum;
ArrayNum = 27;
for (ArrayNum = 0; ArrayNum < 27; ArrayNum++) {
R828_Arry[ArrayNum] = R828_iniArry[ArrayNum];
}
//cap 30pF & Drive Low
R828_I2C.RegAddr = 0x10;
R828_Arry[11] = (R828_Arry[11] & 0xF4) | 0x0B;
R828_I2C.Data = R828_Arry[11];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
//set pll autotune = 128kHz
R828_I2C.RegAddr = 0x1A;
R828_Arry[21] = R828_Arry[21] & 0xF3;
R828_I2C.Data = R828_Arry[21];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
//set manual initial reg = 111111;
R828_I2C.RegAddr = 0x13;
R828_Arry[14] = (R828_Arry[14] & 0x80) | 0x7F;
R828_I2C.Data = R828_Arry[14];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
//set auto
R828_I2C.RegAddr = 0x13;
R828_Arry[14] = (R828_Arry[14] & 0xBF);
R828_I2C.Data = R828_Arry[14];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
R828_Delay_MS(pTuner, 5);
R828_I2C_Len.RegAddr = 0x00;
R828_I2C_Len.Len = 3;
if (I2C_Read_Len(pTuner, &R828_I2C_Len) != RT_Success)
return RT_Fail;
// if 30pF unlock, set to cap 20pF
#if (USE_16M_XTAL==TRUE)
//VCO=2360MHz for 16M Xtal. VCO band 26
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) > 29)
|| ((R828_I2C_Len.Data[2] & 0x3F) < 23))
#else
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) == 0x3F))
#endif
{
//cap 20pF
R828_I2C.RegAddr = 0x10;
R828_Arry[11] = (R828_Arry[11] & 0xFC) | 0x02;
R828_I2C.Data = R828_Arry[11];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
R828_Delay_MS(pTuner, 5);
R828_I2C_Len.RegAddr = 0x00;
R828_I2C_Len.Len = 3;
if (I2C_Read_Len(pTuner, &R828_I2C_Len) != RT_Success)
return RT_Fail;
// if 20pF unlock, set to cap 10pF
#if (USE_16M_XTAL==TRUE)
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) > 29)
|| ((R828_I2C_Len.Data[2] & 0x3F) < 23))
#else
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) == 0x3F))
#endif
{
//cap 10pF
R828_I2C.RegAddr = 0x10;
R828_Arry[11] = (R828_Arry[11] & 0xFC) | 0x01;
R828_I2C.Data = R828_Arry[11];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
R828_Delay_MS(pTuner, 5);
R828_I2C_Len.RegAddr = 0x00;
R828_I2C_Len.Len = 3;
if (I2C_Read_Len(pTuner, &R828_I2C_Len) != RT_Success)
return RT_Fail;
// if 10pF unlock, set to cap 0pF
#if (USE_16M_XTAL==TRUE)
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) > 29)
|| ((R828_I2C_Len.Data[2] & 0x3F) < 23))
#else
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) == 0x3F))
#endif
{
//cap 0pF
R828_I2C.RegAddr = 0x10;
R828_Arry[11] = (R828_Arry[11] & 0xFC) | 0x00;
R828_I2C.Data = R828_Arry[11];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
R828_Delay_MS(pTuner, 5);
R828_I2C_Len.RegAddr = 0x00;
R828_I2C_Len.Len = 3;
if (I2C_Read_Len(pTuner, &R828_I2C_Len) != RT_Success)
return RT_Fail;
// if unlock, set to high drive
#if (USE_16M_XTAL==TRUE)
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) > 29)
|| ((R828_I2C_Len.Data[2] & 0x3F) < 23))
#else
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) == 0x3F))
#endif
{
//X'tal drive high
R828_I2C.RegAddr = 0x10;
R828_Arry[11] = (R828_Arry[11] & 0xF7);
R828_I2C.Data = R828_Arry[11];
if (I2C_Write(pTuner, &R828_I2C) != RT_Success)
return RT_Fail;
//R828_Delay_MS(15);
R828_Delay_MS(pTuner, 20);
R828_I2C_Len.RegAddr = 0x00;
R828_I2C_Len.Len = 3;
if (I2C_Read_Len(pTuner, &R828_I2C_Len) != RT_Success)
return RT_Fail;
#if (USE_16M_XTAL==TRUE)
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) > 29)
|| ((R828_I2C_Len.Data[2] & 0x3F) < 23))
#else
if (((R828_I2C_Len.Data[2] & 0x40) == 0x00) || ((R828_I2C_Len.Data[2] & 0x3F) == 0x3F))
#endif
{
return RT_Fail;
} else //0p+high drive lock
{
Xtal_cap_sel_tmp = XTAL_HIGH_CAP_0P;
}
} else //0p lock
{
Xtal_cap_sel_tmp = XTAL_LOW_CAP_0P;
}
} else //10p lock
{
Xtal_cap_sel_tmp = XTAL_LOW_CAP_10P;
}
} else //20p lock
{
Xtal_cap_sel_tmp = XTAL_LOW_CAP_20P;
}
} else // 30p lock
{
Xtal_cap_sel_tmp = XTAL_LOW_CAP_30P;
}
return RT_Success;
}
R828_ErrCode R828_Init(void *pTuner)
{
// R820T_EXTRA_MODULE *pExtra;
UINT8 i;
// Get tuner extra module.
// pExtra = &(pTuner->Extra.R820t);
//write initial reg
//if(R828_InitReg(pTuner) != RT_Success)
// return RT_Fail;
if (R828_IMR_done_flag == FALSE) {
//write initial reg
// if(R828_InitReg(pTuner) != RT_Success)
// return RT_Fail;
//Do Xtal check
if ((Rafael_Chip == R820T) || (Rafael_Chip == R828S) || (Rafael_Chip == R820C)) {
Xtal_cap_sel = XTAL_HIGH_CAP_0P;
} else {
if (R828_Xtal_Check(pTuner) != RT_Success) //1st
return RT_Fail;
Xtal_cap_sel = Xtal_cap_sel_tmp;
if (R828_Xtal_Check(pTuner) != RT_Success) //2nd
return RT_Fail;
if (Xtal_cap_sel_tmp > Xtal_cap_sel) {
Xtal_cap_sel = Xtal_cap_sel_tmp;
}
if (R828_Xtal_Check(pTuner) != RT_Success) //3rd
return RT_Fail;
if (Xtal_cap_sel_tmp > Xtal_cap_sel) {
Xtal_cap_sel = Xtal_cap_sel_tmp;
}
}
//reset filter cal.
for (i = 0; i < STD_SIZE; i++) {
R828_Fil_Cal_flag[i] = FALSE;
R828_Fil_Cal_code[i] = 0;
}
#if 0
//start imr cal.
if (R828_InitReg(pTuner) != RT_Success) //write initial reg before doing cal
return RT_Fail;
if (R828_IMR_Prepare(pTuner) != RT_Success)
return RT_Fail;
if (R828_IMR(pTuner, 3, TRUE) != RT_Success) //Full K node 3
return RT_Fail;
if (R828_IMR(pTuner, 1, FALSE) != RT_Success)
return RT_Fail;
if (R828_IMR(pTuner, 0, FALSE) != RT_Success)
return RT_Fail;
if (R828_IMR(pTuner, 2, FALSE) != RT_Success)
return RT_Fail;
if (R828_IMR(pTuner, 4, FALSE) != RT_Success)
return RT_Fail;
R828_IMR_done_flag = TRUE;
#endif
}
//write initial reg
if (R828_InitReg(pTuner) != RT_Success)
return RT_Fail;
return RT_Success;
}
R828_ErrCode R828_InitReg(void *pTuner)
{
UINT8 InitArryCount;
UINT8 InitArryNum;
InitArryCount = 0;
InitArryNum = 27;