1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Driver for ST STV0900 satellite demodulator IC.
7 * Copyright (C) ST Microelectronics.
8 * Copyright (C) 2009 NetUP Inc.
9 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
13 #include "stv0900_reg.h"
14 #include "stv0900_priv.h"
16 s32
shiftx(s32 x
, int demod
, s32 shift
)
24 int stv0900_check_signal_presence(struct stv0900_internal
*intp
,
25 enum fe_stv0900_demod_num demod
)
31 int no_signal
= FALSE
;
33 carr_offset
= (stv0900_read_reg(intp
, CFR2
) << 8)
34 | stv0900_read_reg(intp
, CFR1
);
35 carr_offset
= ge2comp(carr_offset
, 16);
36 agc2_integr
= (stv0900_read_reg(intp
, AGC2I1
) << 8)
37 | stv0900_read_reg(intp
, AGC2I0
);
38 max_carrier
= intp
->srch_range
[demod
] / 1000;
40 max_carrier
+= (max_carrier
/ 10);
41 max_carrier
= 65536 * (max_carrier
/ 2);
42 max_carrier
/= intp
->mclk
/ 1000;
43 if (max_carrier
> 0x4000)
46 if ((agc2_integr
> 0x2000)
47 || (carr_offset
> (2 * max_carrier
))
48 || (carr_offset
< (-2 * max_carrier
)))
54 static void stv0900_get_sw_loop_params(struct stv0900_internal
*intp
,
55 s32
*frequency_inc
, s32
*sw_timeout
,
57 enum fe_stv0900_demod_num demod
)
59 s32 timeout
, freq_inc
, max_steps
, srate
, max_carrier
;
61 enum fe_stv0900_search_standard standard
;
63 srate
= intp
->symbol_rate
[demod
];
64 max_carrier
= intp
->srch_range
[demod
] / 1000;
65 max_carrier
+= max_carrier
/ 10;
66 standard
= intp
->srch_standard
[demod
];
68 max_carrier
= 65536 * (max_carrier
/ 2);
69 max_carrier
/= intp
->mclk
/ 1000;
71 if (max_carrier
> 0x4000)
75 freq_inc
/= intp
->mclk
>> 10;
76 freq_inc
= freq_inc
<< 6;
79 case STV0900_SEARCH_DVBS1
:
80 case STV0900_SEARCH_DSS
:
84 case STV0900_SEARCH_DVBS2
:
88 case STV0900_AUTO_SEARCH
:
97 if ((freq_inc
> max_carrier
) || (freq_inc
< 0))
98 freq_inc
= max_carrier
/ 2;
103 timeout
/= srate
/ 1000;
105 if ((timeout
> 100) || (timeout
< 0))
108 max_steps
= (max_carrier
/ freq_inc
) + 1;
110 if ((max_steps
> 100) || (max_steps
< 0)) {
112 freq_inc
= max_carrier
/ max_steps
;
115 *frequency_inc
= freq_inc
;
116 *sw_timeout
= timeout
;
121 static int stv0900_search_carr_sw_loop(struct stv0900_internal
*intp
,
122 s32 FreqIncr
, s32 Timeout
, int zigzag
,
123 s32 MaxStep
, enum fe_stv0900_demod_num demod
)
131 max_carrier
= intp
->srch_range
[demod
] / 1000;
132 max_carrier
+= (max_carrier
/ 10);
134 max_carrier
= 65536 * (max_carrier
/ 2);
135 max_carrier
/= intp
->mclk
/ 1000;
137 if (max_carrier
> 0x4000)
138 max_carrier
= 0x4000;
143 freqOffset
= -max_carrier
+ FreqIncr
;
148 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
149 stv0900_write_reg(intp
, CFRINIT1
, (freqOffset
/ 256) & 0xff);
150 stv0900_write_reg(intp
, CFRINIT0
, freqOffset
& 0xff);
151 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
152 stv0900_write_bits(intp
, ALGOSWRST
, 1);
154 if (intp
->chip_id
== 0x12) {
155 stv0900_write_bits(intp
, RST_HWARE
, 1);
156 stv0900_write_bits(intp
, RST_HWARE
, 0);
159 if (zigzag
== TRUE
) {
161 freqOffset
= -freqOffset
- 2 * FreqIncr
;
163 freqOffset
= -freqOffset
;
165 freqOffset
+= + 2 * FreqIncr
;
168 lock
= stv0900_get_demod_lock(intp
, demod
, Timeout
);
169 no_signal
= stv0900_check_signal_presence(intp
, demod
);
171 } while ((lock
== FALSE
)
172 && (no_signal
== FALSE
)
173 && ((freqOffset
- FreqIncr
) < max_carrier
)
174 && ((freqOffset
+ FreqIncr
) > -max_carrier
)
175 && (stepCpt
< MaxStep
));
177 stv0900_write_bits(intp
, ALGOSWRST
, 0);
182 static int stv0900_sw_algo(struct stv0900_internal
*intp
,
183 enum fe_stv0900_demod_num demod
)
194 stv0900_get_sw_loop_params(intp
, &fqc_inc
, &sft_stp_tout
,
196 switch (intp
->srch_standard
[demod
]) {
197 case STV0900_SEARCH_DVBS1
:
198 case STV0900_SEARCH_DSS
:
199 if (intp
->chip_id
>= 0x20)
200 stv0900_write_reg(intp
, CARFREQ
, 0x3b);
202 stv0900_write_reg(intp
, CARFREQ
, 0xef);
204 stv0900_write_reg(intp
, DMDCFGMD
, 0x49);
207 case STV0900_SEARCH_DVBS2
:
208 if (intp
->chip_id
>= 0x20)
209 stv0900_write_reg(intp
, CORRELABS
, 0x79);
211 stv0900_write_reg(intp
, CORRELABS
, 0x68);
213 stv0900_write_reg(intp
, DMDCFGMD
, 0x89);
217 case STV0900_AUTO_SEARCH
:
219 if (intp
->chip_id
>= 0x20) {
220 stv0900_write_reg(intp
, CARFREQ
, 0x3b);
221 stv0900_write_reg(intp
, CORRELABS
, 0x79);
223 stv0900_write_reg(intp
, CARFREQ
, 0xef);
224 stv0900_write_reg(intp
, CORRELABS
, 0x68);
227 stv0900_write_reg(intp
, DMDCFGMD
, 0xc9);
234 lock
= stv0900_search_carr_sw_loop(intp
,
240 no_signal
= stv0900_check_signal_presence(intp
, demod
);
243 || (no_signal
== TRUE
)
244 || (trial_cntr
== 2)) {
246 if (intp
->chip_id
>= 0x20) {
247 stv0900_write_reg(intp
, CARFREQ
, 0x49);
248 stv0900_write_reg(intp
, CORRELABS
, 0x9e);
250 stv0900_write_reg(intp
, CARFREQ
, 0xed);
251 stv0900_write_reg(intp
, CORRELABS
, 0x88);
254 if ((stv0900_get_bits(intp
, HEADER_MODE
) ==
255 STV0900_DVBS2_FOUND
) &&
257 msleep(sft_stp_tout
);
258 s2fw
= stv0900_get_bits(intp
, FLYWHEEL_CPT
);
261 msleep(sft_stp_tout
);
262 s2fw
= stv0900_get_bits(intp
,
269 if (trial_cntr
< 2) {
270 if (intp
->chip_id
>= 0x20)
271 stv0900_write_reg(intp
,
275 stv0900_write_reg(intp
,
279 stv0900_write_reg(intp
,
287 } while ((lock
== FALSE
)
289 && (no_signal
== FALSE
));
294 static u32
stv0900_get_symbol_rate(struct stv0900_internal
*intp
,
296 enum fe_stv0900_demod_num demod
)
298 s32 rem1
, rem2
, intval1
, intval2
, srate
;
300 srate
= (stv0900_get_bits(intp
, SYMB_FREQ3
) << 24) +
301 (stv0900_get_bits(intp
, SYMB_FREQ2
) << 16) +
302 (stv0900_get_bits(intp
, SYMB_FREQ1
) << 8) +
303 (stv0900_get_bits(intp
, SYMB_FREQ0
));
304 dprintk("lock: srate=%d r0=0x%x r1=0x%x r2=0x%x r3=0x%x \n",
305 srate
, stv0900_get_bits(intp
, SYMB_FREQ0
),
306 stv0900_get_bits(intp
, SYMB_FREQ1
),
307 stv0900_get_bits(intp
, SYMB_FREQ2
),
308 stv0900_get_bits(intp
, SYMB_FREQ3
));
310 intval1
= (mclk
) >> 16;
311 intval2
= (srate
) >> 16;
313 rem1
= (mclk
) % 0x10000;
314 rem2
= (srate
) % 0x10000;
315 srate
= (intval1
* intval2
) +
316 ((intval1
* rem2
) >> 16) +
317 ((intval2
* rem1
) >> 16);
322 static void stv0900_set_symbol_rate(struct stv0900_internal
*intp
,
324 enum fe_stv0900_demod_num demod
)
328 dprintk("%s: Mclk %d, SR %d, Dmd %d\n", __func__
, mclk
,
331 if (srate
> 60000000) {
333 symb
/= (mclk
>> 12);
334 } else if (srate
> 6000000) {
336 symb
/= (mclk
>> 10);
342 stv0900_write_reg(intp
, SFRINIT1
, (symb
>> 8) & 0x7f);
343 stv0900_write_reg(intp
, SFRINIT1
+ 1, (symb
& 0xff));
346 static void stv0900_set_max_symbol_rate(struct stv0900_internal
*intp
,
348 enum fe_stv0900_demod_num demod
)
352 srate
= 105 * (srate
/ 100);
354 if (srate
> 60000000) {
356 symb
/= (mclk
>> 12);
357 } else if (srate
> 6000000) {
359 symb
/= (mclk
>> 10);
366 stv0900_write_reg(intp
, SFRUP1
, (symb
>> 8) & 0x7f);
367 stv0900_write_reg(intp
, SFRUP1
+ 1, (symb
& 0xff));
369 stv0900_write_reg(intp
, SFRUP1
, 0x7f);
370 stv0900_write_reg(intp
, SFRUP1
+ 1, 0xff);
374 static void stv0900_set_min_symbol_rate(struct stv0900_internal
*intp
,
376 enum fe_stv0900_demod_num demod
)
380 srate
= 95 * (srate
/ 100);
381 if (srate
> 60000000) {
383 symb
/= (mclk
>> 12);
385 } else if (srate
> 6000000) {
387 symb
/= (mclk
>> 10);
394 stv0900_write_reg(intp
, SFRLOW1
, (symb
>> 8) & 0xff);
395 stv0900_write_reg(intp
, SFRLOW1
+ 1, (symb
& 0xff));
398 static s32
stv0900_get_timing_offst(struct stv0900_internal
*intp
,
400 enum fe_stv0900_demod_num demod
)
405 timingoffset
= (stv0900_read_reg(intp
, TMGREG2
) << 16) +
406 (stv0900_read_reg(intp
, TMGREG2
+ 1) << 8) +
407 (stv0900_read_reg(intp
, TMGREG2
+ 2));
409 timingoffset
= ge2comp(timingoffset
, 24);
412 if (timingoffset
== 0)
415 timingoffset
= ((s32
)srate
* 10) / ((s32
)0x1000000 / timingoffset
);
421 static void stv0900_set_dvbs2_rolloff(struct stv0900_internal
*intp
,
422 enum fe_stv0900_demod_num demod
)
426 if (intp
->chip_id
== 0x10) {
427 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 1);
428 rolloff
= stv0900_read_reg(intp
, MATSTR1
) & 0x03;
429 stv0900_write_bits(intp
, ROLLOFF_CONTROL
, rolloff
);
430 } else if (intp
->chip_id
<= 0x20)
431 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 0);
433 stv0900_write_bits(intp
, MANUALS2_ROLLOFF
, 0);
436 static u32
stv0900_carrier_width(u32 srate
, enum fe_stv0900_rolloff ro
)
453 return srate
+ (srate
* rolloff
) / 100;
456 static int stv0900_check_timing_lock(struct stv0900_internal
*intp
,
457 enum fe_stv0900_demod_num demod
)
459 int timingLock
= FALSE
;
466 car_freq
= stv0900_read_reg(intp
, CARFREQ
);
467 tmg_th_high
= stv0900_read_reg(intp
, TMGTHRISE
);
468 tmg_th_low
= stv0900_read_reg(intp
, TMGTHFALL
);
469 stv0900_write_reg(intp
, TMGTHRISE
, 0x20);
470 stv0900_write_reg(intp
, TMGTHFALL
, 0x0);
471 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
472 stv0900_write_reg(intp
, RTC
, 0x80);
473 stv0900_write_reg(intp
, RTCS2
, 0x40);
474 stv0900_write_reg(intp
, CARFREQ
, 0x0);
475 stv0900_write_reg(intp
, CFRINIT1
, 0x0);
476 stv0900_write_reg(intp
, CFRINIT0
, 0x0);
477 stv0900_write_reg(intp
, AGC2REF
, 0x65);
478 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
481 for (i
= 0; i
< 10; i
++) {
482 if (stv0900_get_bits(intp
, TMGLOCK_QUALITY
) >= 2)
491 stv0900_write_reg(intp
, AGC2REF
, 0x38);
492 stv0900_write_reg(intp
, RTC
, 0x88);
493 stv0900_write_reg(intp
, RTCS2
, 0x68);
494 stv0900_write_reg(intp
, CARFREQ
, car_freq
);
495 stv0900_write_reg(intp
, TMGTHRISE
, tmg_th_high
);
496 stv0900_write_reg(intp
, TMGTHFALL
, tmg_th_low
);
501 static int stv0900_get_demod_cold_lock(struct dvb_frontend
*fe
,
504 struct stv0900_state
*state
= fe
->demodulator_priv
;
505 struct stv0900_internal
*intp
= state
->internal
;
506 enum fe_stv0900_demod_num demod
= state
->demod
;
520 srate
= intp
->symbol_rate
[d
];
521 search_range
= intp
->srch_range
[d
];
523 if (srate
>= 10000000)
524 locktimeout
= demod_timeout
/ 3;
526 locktimeout
= demod_timeout
/ 2;
528 lock
= stv0900_get_demod_lock(intp
, d
, locktimeout
);
533 if (srate
>= 10000000) {
534 if (stv0900_check_timing_lock(intp
, d
) == TRUE
) {
535 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
536 stv0900_write_reg(intp
, DMDISTATE
, 0x15);
537 lock
= stv0900_get_demod_lock(intp
, d
, demod_timeout
);
544 if (intp
->chip_id
<= 0x20) {
545 if (srate
<= 1000000)
547 else if (srate
<= 4000000)
549 else if (srate
<= 7000000)
551 else if (srate
<= 10000000)
556 if (srate
>= 2000000) {
557 timeout
= (demod_timeout
/ 3);
561 timeout
= (demod_timeout
/ 2);
564 currier_step
= srate
/ 4000;
565 timeout
= (demod_timeout
* 3) / 4;
568 nb_steps
= ((search_range
/ 1000) / currier_step
);
570 if ((nb_steps
% 2) != 0)
575 else if (nb_steps
> 12)
581 if (intp
->chip_id
<= 0x20) {
582 tuner_freq
= intp
->freq
[d
];
583 intp
->bw
[d
] = stv0900_carrier_width(intp
->symbol_rate
[d
],
584 intp
->rolloff
) + intp
->symbol_rate
[d
];
588 while ((current_step
<= nb_steps
) && (lock
== FALSE
)) {
590 tuner_freq
+= (current_step
* currier_step
);
592 tuner_freq
-= (current_step
* currier_step
);
594 if (intp
->chip_id
<= 0x20) {
595 if (intp
->tuner_type
[d
] == 3)
596 stv0900_set_tuner_auto(intp
, tuner_freq
,
599 stv0900_set_tuner(fe
, tuner_freq
, intp
->bw
[d
]);
601 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
602 stv0900_write_reg(intp
, CFRINIT1
, 0);
603 stv0900_write_reg(intp
, CFRINIT0
, 0);
604 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
605 stv0900_write_reg(intp
, DMDISTATE
, 0x15);
607 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
608 freq
= (tuner_freq
* 65536) / (intp
->mclk
/ 1000);
609 stv0900_write_bits(intp
, CFR_INIT1
, MSB(freq
));
610 stv0900_write_bits(intp
, CFR_INIT0
, LSB(freq
));
611 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
612 stv0900_write_reg(intp
, DMDISTATE
, 0x05);
615 lock
= stv0900_get_demod_lock(intp
, d
, timeout
);
623 static void stv0900_get_lock_timeout(s32
*demod_timeout
, s32
*fec_timeout
,
625 enum fe_stv0900_search_algo algo
)
628 case STV0900_BLIND_SEARCH
:
629 if (srate
<= 1500000) {
630 (*demod_timeout
) = 1500;
631 (*fec_timeout
) = 400;
632 } else if (srate
<= 5000000) {
633 (*demod_timeout
) = 1000;
634 (*fec_timeout
) = 300;
636 (*demod_timeout
) = 700;
637 (*fec_timeout
) = 100;
641 case STV0900_COLD_START
:
642 case STV0900_WARM_START
:
644 if (srate
<= 1000000) {
645 (*demod_timeout
) = 3000;
646 (*fec_timeout
) = 1700;
647 } else if (srate
<= 2000000) {
648 (*demod_timeout
) = 2500;
649 (*fec_timeout
) = 1100;
650 } else if (srate
<= 5000000) {
651 (*demod_timeout
) = 1000;
652 (*fec_timeout
) = 550;
653 } else if (srate
<= 10000000) {
654 (*demod_timeout
) = 700;
655 (*fec_timeout
) = 250;
656 } else if (srate
<= 20000000) {
657 (*demod_timeout
) = 400;
658 (*fec_timeout
) = 130;
660 (*demod_timeout
) = 300;
661 (*fec_timeout
) = 100;
668 if (algo
== STV0900_WARM_START
)
669 (*demod_timeout
) /= 2;
672 static void stv0900_set_viterbi_tracq(struct stv0900_internal
*intp
,
673 enum fe_stv0900_demod_num demod
)
678 dprintk("%s\n", __func__
);
680 stv0900_write_reg(intp
, vth_reg
++, 0xd0);
681 stv0900_write_reg(intp
, vth_reg
++, 0x7d);
682 stv0900_write_reg(intp
, vth_reg
++, 0x53);
683 stv0900_write_reg(intp
, vth_reg
++, 0x2f);
684 stv0900_write_reg(intp
, vth_reg
++, 0x24);
685 stv0900_write_reg(intp
, vth_reg
++, 0x1f);
688 static void stv0900_set_viterbi_standard(struct stv0900_internal
*intp
,
689 enum fe_stv0900_search_standard standard
,
690 enum fe_stv0900_fec fec
,
691 enum fe_stv0900_demod_num demod
)
693 dprintk("%s: ViterbiStandard = ", __func__
);
696 case STV0900_AUTO_SEARCH
:
698 stv0900_write_reg(intp
, FECM
, 0x10);
699 stv0900_write_reg(intp
, PRVIT
, 0x3f);
701 case STV0900_SEARCH_DVBS1
:
703 stv0900_write_reg(intp
, FECM
, 0x00);
705 case STV0900_FEC_UNKNOWN
:
707 stv0900_write_reg(intp
, PRVIT
, 0x2f);
709 case STV0900_FEC_1_2
:
710 stv0900_write_reg(intp
, PRVIT
, 0x01);
712 case STV0900_FEC_2_3
:
713 stv0900_write_reg(intp
, PRVIT
, 0x02);
715 case STV0900_FEC_3_4
:
716 stv0900_write_reg(intp
, PRVIT
, 0x04);
718 case STV0900_FEC_5_6
:
719 stv0900_write_reg(intp
, PRVIT
, 0x08);
721 case STV0900_FEC_7_8
:
722 stv0900_write_reg(intp
, PRVIT
, 0x20);
727 case STV0900_SEARCH_DSS
:
729 stv0900_write_reg(intp
, FECM
, 0x80);
731 case STV0900_FEC_UNKNOWN
:
733 stv0900_write_reg(intp
, PRVIT
, 0x13);
735 case STV0900_FEC_1_2
:
736 stv0900_write_reg(intp
, PRVIT
, 0x01);
738 case STV0900_FEC_2_3
:
739 stv0900_write_reg(intp
, PRVIT
, 0x02);
741 case STV0900_FEC_6_7
:
742 stv0900_write_reg(intp
, PRVIT
, 0x10);
751 static enum fe_stv0900_fec
stv0900_get_vit_fec(struct stv0900_internal
*intp
,
752 enum fe_stv0900_demod_num demod
)
754 enum fe_stv0900_fec prate
;
755 s32 rate_fld
= stv0900_get_bits(intp
, VIT_CURPUN
);
759 prate
= STV0900_FEC_1_2
;
762 prate
= STV0900_FEC_2_3
;
765 prate
= STV0900_FEC_3_4
;
768 prate
= STV0900_FEC_5_6
;
771 prate
= STV0900_FEC_6_7
;
774 prate
= STV0900_FEC_7_8
;
777 prate
= STV0900_FEC_UNKNOWN
;
784 static void stv0900_set_dvbs1_track_car_loop(struct stv0900_internal
*intp
,
785 enum fe_stv0900_demod_num demod
,
788 if (intp
->chip_id
>= 0x30) {
789 if (srate
>= 15000000) {
790 stv0900_write_reg(intp
, ACLC
, 0x2b);
791 stv0900_write_reg(intp
, BCLC
, 0x1a);
792 } else if ((srate
>= 7000000) && (15000000 > srate
)) {
793 stv0900_write_reg(intp
, ACLC
, 0x0c);
794 stv0900_write_reg(intp
, BCLC
, 0x1b);
795 } else if (srate
< 7000000) {
796 stv0900_write_reg(intp
, ACLC
, 0x2c);
797 stv0900_write_reg(intp
, BCLC
, 0x1c);
800 } else { /*cut 2.0 and 1.x*/
801 stv0900_write_reg(intp
, ACLC
, 0x1a);
802 stv0900_write_reg(intp
, BCLC
, 0x09);
807 static void stv0900_track_optimization(struct dvb_frontend
*fe
)
809 struct stv0900_state
*state
= fe
->demodulator_priv
;
810 struct stv0900_internal
*intp
= state
->internal
;
811 enum fe_stv0900_demod_num demod
= state
->demod
;
824 enum fe_stv0900_modcode foundModcod
;
826 dprintk("%s\n", __func__
);
828 srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
829 srate
+= stv0900_get_timing_offst(intp
, srate
, demod
);
831 switch (intp
->result
[demod
].standard
) {
832 case STV0900_DVBS1_STANDARD
:
833 case STV0900_DSS_STANDARD
:
834 dprintk("%s: found DVB-S or DSS\n", __func__
);
835 if (intp
->srch_standard
[demod
] == STV0900_AUTO_SEARCH
) {
836 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
837 stv0900_write_bits(intp
, DVBS2_ENABLE
, 0);
840 stv0900_write_bits(intp
, ROLLOFF_CONTROL
, intp
->rolloff
);
841 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 1);
843 if (intp
->chip_id
< 0x30) {
844 stv0900_write_reg(intp
, ERRCTRL1
, 0x75);
848 if (stv0900_get_vit_fec(intp
, demod
) == STV0900_FEC_1_2
) {
849 stv0900_write_reg(intp
, GAUSSR0
, 0x98);
850 stv0900_write_reg(intp
, CCIR0
, 0x18);
852 stv0900_write_reg(intp
, GAUSSR0
, 0x18);
853 stv0900_write_reg(intp
, CCIR0
, 0x18);
856 stv0900_write_reg(intp
, ERRCTRL1
, 0x75);
858 case STV0900_DVBS2_STANDARD
:
859 dprintk("%s: found DVB-S2\n", __func__
);
860 stv0900_write_bits(intp
, DVBS1_ENABLE
, 0);
861 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
862 stv0900_write_reg(intp
, ACLC
, 0);
863 stv0900_write_reg(intp
, BCLC
, 0);
864 if (intp
->result
[demod
].frame_len
== STV0900_LONG_FRAME
) {
865 foundModcod
= stv0900_get_bits(intp
, DEMOD_MODCOD
);
866 pilots
= stv0900_get_bits(intp
, DEMOD_TYPE
) & 0x01;
867 aclc
= stv0900_get_optim_carr_loop(srate
,
871 if (foundModcod
<= STV0900_QPSK_910
)
872 stv0900_write_reg(intp
, ACLC2S2Q
, aclc
);
873 else if (foundModcod
<= STV0900_8PSK_910
) {
874 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
875 stv0900_write_reg(intp
, ACLC2S28
, aclc
);
878 if ((intp
->demod_mode
== STV0900_SINGLE
) &&
879 (foundModcod
> STV0900_8PSK_910
)) {
880 if (foundModcod
<= STV0900_16APSK_910
) {
881 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
882 stv0900_write_reg(intp
, ACLC2S216A
,
884 } else if (foundModcod
<= STV0900_32APSK_910
) {
885 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
886 stv0900_write_reg(intp
, ACLC2S232A
,
892 modulation
= intp
->result
[demod
].modulation
;
893 aclc
= stv0900_get_optim_short_carr_loop(srate
,
894 modulation
, intp
->chip_id
);
895 if (modulation
== STV0900_QPSK
)
896 stv0900_write_reg(intp
, ACLC2S2Q
, aclc
);
897 else if (modulation
== STV0900_8PSK
) {
898 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
899 stv0900_write_reg(intp
, ACLC2S28
, aclc
);
900 } else if (modulation
== STV0900_16APSK
) {
901 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
902 stv0900_write_reg(intp
, ACLC2S216A
, aclc
);
903 } else if (modulation
== STV0900_32APSK
) {
904 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
905 stv0900_write_reg(intp
, ACLC2S232A
, aclc
);
910 if (intp
->chip_id
<= 0x11) {
911 if (intp
->demod_mode
!= STV0900_SINGLE
)
912 stv0900_activate_s2_modcod(intp
, demod
);
916 stv0900_write_reg(intp
, ERRCTRL1
, 0x67);
918 case STV0900_UNKNOWN_STANDARD
:
920 dprintk("%s: found unknown standard\n", __func__
);
921 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
922 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
926 freq1
= stv0900_read_reg(intp
, CFR2
);
927 freq0
= stv0900_read_reg(intp
, CFR1
);
928 if (intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
) {
929 stv0900_write_reg(intp
, SFRSTEP
, 0x00);
930 stv0900_write_bits(intp
, SCAN_ENABLE
, 0);
931 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
932 stv0900_write_reg(intp
, TMGCFG2
, 0xc1);
933 stv0900_set_symbol_rate(intp
, intp
->mclk
, srate
, demod
);
935 if (intp
->result
[demod
].standard
!= STV0900_DVBS2_STANDARD
)
936 stv0900_set_dvbs1_track_car_loop(intp
, demod
, srate
);
940 if (intp
->chip_id
>= 0x20) {
941 if ((intp
->srch_standard
[demod
] == STV0900_SEARCH_DVBS1
) ||
942 (intp
->srch_standard
[demod
] ==
943 STV0900_SEARCH_DSS
) ||
944 (intp
->srch_standard
[demod
] ==
945 STV0900_AUTO_SEARCH
)) {
946 stv0900_write_reg(intp
, VAVSRVIT
, 0x0a);
947 stv0900_write_reg(intp
, VITSCALE
, 0x0);
951 if (intp
->chip_id
< 0x20)
952 stv0900_write_reg(intp
, CARHDR
, 0x08);
954 if (intp
->chip_id
== 0x10)
955 stv0900_write_reg(intp
, CORRELEXP
, 0x0a);
957 stv0900_write_reg(intp
, AGC2REF
, 0x38);
959 if ((intp
->chip_id
>= 0x20) ||
960 (blind_tun_sw
== 1) ||
961 (intp
->symbol_rate
[demod
] < 10000000)) {
962 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
963 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
964 intp
->bw
[demod
] = stv0900_carrier_width(srate
,
965 intp
->rolloff
) + 10000000;
967 if ((intp
->chip_id
>= 0x20) || (blind_tun_sw
== 1)) {
968 if (intp
->srch_algo
[demod
] != STV0900_WARM_START
) {
969 if (intp
->tuner_type
[demod
] == 3)
970 stv0900_set_tuner_auto(intp
,
975 stv0900_set_bandwidth(fe
,
980 if ((intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
) ||
981 (intp
->symbol_rate
[demod
] < 10000000))
986 stv0900_get_lock_timeout(&timed
, &timef
, srate
,
989 if (stv0900_get_demod_lock(intp
, demod
, timed
/ 2) == FALSE
) {
990 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
991 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
992 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
993 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
995 while ((stv0900_get_demod_lock(intp
,
997 timed
/ 2) == FALSE
) &&
999 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
1000 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1001 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1002 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1009 if (intp
->chip_id
>= 0x20)
1010 stv0900_write_reg(intp
, CARFREQ
, 0x49);
1012 if ((intp
->result
[demod
].standard
== STV0900_DVBS1_STANDARD
) ||
1013 (intp
->result
[demod
].standard
== STV0900_DSS_STANDARD
))
1014 stv0900_set_viterbi_tracq(intp
, demod
);
1018 static int stv0900_get_fec_lock(struct stv0900_internal
*intp
,
1019 enum fe_stv0900_demod_num demod
, s32 time_out
)
1021 s32 timer
= 0, lock
= 0;
1023 enum fe_stv0900_search_state dmd_state
;
1025 dprintk("%s\n", __func__
);
1027 dmd_state
= stv0900_get_bits(intp
, HEADER_MODE
);
1029 while ((timer
< time_out
) && (lock
== 0)) {
1030 switch (dmd_state
) {
1031 case STV0900_SEARCH
:
1032 case STV0900_PLH_DETECTED
:
1036 case STV0900_DVBS2_FOUND
:
1037 lock
= stv0900_get_bits(intp
, PKTDELIN_LOCK
);
1039 case STV0900_DVBS_FOUND
:
1040 lock
= stv0900_get_bits(intp
, LOCKEDVIT
);
1051 dprintk("%s: DEMOD FEC LOCK OK\n", __func__
);
1053 dprintk("%s: DEMOD FEC LOCK FAIL\n", __func__
);
1058 static int stv0900_wait_for_lock(struct stv0900_internal
*intp
,
1059 enum fe_stv0900_demod_num demod
,
1060 s32 dmd_timeout
, s32 fec_timeout
)
1063 s32 timer
= 0, lock
= 0;
1065 dprintk("%s\n", __func__
);
1067 lock
= stv0900_get_demod_lock(intp
, demod
, dmd_timeout
);
1070 lock
= stv0900_get_fec_lock(intp
, demod
, fec_timeout
);
1075 dprintk("%s: Timer = %d, time_out = %d\n",
1076 __func__
, timer
, fec_timeout
);
1078 while ((timer
< fec_timeout
) && (lock
== 0)) {
1079 lock
= stv0900_get_bits(intp
, TSFIFO_LINEOK
);
1086 dprintk("%s: DEMOD LOCK OK\n", __func__
);
1088 dprintk("%s: DEMOD LOCK FAIL\n", __func__
);
1096 enum fe_stv0900_tracking_standard
stv0900_get_standard(struct dvb_frontend
*fe
,
1097 enum fe_stv0900_demod_num demod
)
1099 struct stv0900_state
*state
= fe
->demodulator_priv
;
1100 struct stv0900_internal
*intp
= state
->internal
;
1101 enum fe_stv0900_tracking_standard fnd_standard
;
1103 int hdr_mode
= stv0900_get_bits(intp
, HEADER_MODE
);
1107 fnd_standard
= STV0900_DVBS2_STANDARD
;
1110 if (stv0900_get_bits(intp
, DSS_DVB
) == 1)
1111 fnd_standard
= STV0900_DSS_STANDARD
;
1113 fnd_standard
= STV0900_DVBS1_STANDARD
;
1117 fnd_standard
= STV0900_UNKNOWN_STANDARD
;
1120 dprintk("%s: standard %d\n", __func__
, fnd_standard
);
1122 return fnd_standard
;
1125 static s32
stv0900_get_carr_freq(struct stv0900_internal
*intp
, u32 mclk
,
1126 enum fe_stv0900_demod_num demod
)
1134 derot
= (stv0900_get_bits(intp
, CAR_FREQ2
) << 16) +
1135 (stv0900_get_bits(intp
, CAR_FREQ1
) << 8) +
1136 (stv0900_get_bits(intp
, CAR_FREQ0
));
1138 derot
= ge2comp(derot
, 24);
1139 intval1
= mclk
>> 12;
1140 intval2
= derot
>> 12;
1141 rem1
= mclk
% 0x1000;
1142 rem2
= derot
% 0x1000;
1143 derot
= (intval1
* intval2
) +
1144 ((intval1
* rem2
) >> 12) +
1145 ((intval2
* rem1
) >> 12);
1150 static u32
stv0900_get_tuner_freq(struct dvb_frontend
*fe
)
1152 struct dvb_frontend_ops
*frontend_ops
= NULL
;
1153 struct dvb_tuner_ops
*tuner_ops
= NULL
;
1156 frontend_ops
= &fe
->ops
;
1157 tuner_ops
= &frontend_ops
->tuner_ops
;
1159 if (tuner_ops
->get_frequency
) {
1160 if ((tuner_ops
->get_frequency(fe
, &freq
)) < 0)
1161 dprintk("%s: Invalid parameter\n", __func__
);
1163 dprintk("%s: Frequency=%d\n", __func__
, freq
);
1171 fe_stv0900_signal_type
stv0900_get_signal_params(struct dvb_frontend
*fe
)
1173 struct stv0900_state
*state
= fe
->demodulator_priv
;
1174 struct stv0900_internal
*intp
= state
->internal
;
1175 enum fe_stv0900_demod_num demod
= state
->demod
;
1176 enum fe_stv0900_signal_type range
= STV0900_OUTOFRANGE
;
1177 struct stv0900_signal_info
*result
= &intp
->result
[demod
];
1186 if (intp
->srch_algo
[d
] == STV0900_BLIND_SEARCH
) {
1187 timing
= stv0900_read_reg(intp
, TMGREG2
);
1189 stv0900_write_reg(intp
, SFRSTEP
, 0x5c);
1191 while ((i
<= 50) && (timing
!= 0) && (timing
!= 0xff)) {
1192 timing
= stv0900_read_reg(intp
, TMGREG2
);
1198 result
->standard
= stv0900_get_standard(fe
, d
);
1199 if (intp
->tuner_type
[demod
] == 3)
1200 result
->frequency
= stv0900_get_freq_auto(intp
, d
);
1202 result
->frequency
= stv0900_get_tuner_freq(fe
);
1204 offsetFreq
= stv0900_get_carr_freq(intp
, intp
->mclk
, d
) / 1000;
1205 result
->frequency
+= offsetFreq
;
1206 result
->symbol_rate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, d
);
1207 srate_offset
= stv0900_get_timing_offst(intp
, result
->symbol_rate
, d
);
1208 result
->symbol_rate
+= srate_offset
;
1209 result
->fec
= stv0900_get_vit_fec(intp
, d
);
1210 result
->modcode
= stv0900_get_bits(intp
, DEMOD_MODCOD
);
1211 result
->pilot
= stv0900_get_bits(intp
, DEMOD_TYPE
) & 0x01;
1212 result
->frame_len
= ((u32
)stv0900_get_bits(intp
, DEMOD_TYPE
)) >> 1;
1213 result
->rolloff
= stv0900_get_bits(intp
, ROLLOFF_STATUS
);
1215 dprintk("%s: modcode=0x%x \n", __func__
, result
->modcode
);
1217 switch (result
->standard
) {
1218 case STV0900_DVBS2_STANDARD
:
1219 result
->spectrum
= stv0900_get_bits(intp
, SPECINV_DEMOD
);
1220 if (result
->modcode
<= STV0900_QPSK_910
)
1221 result
->modulation
= STV0900_QPSK
;
1222 else if (result
->modcode
<= STV0900_8PSK_910
)
1223 result
->modulation
= STV0900_8PSK
;
1224 else if (result
->modcode
<= STV0900_16APSK_910
)
1225 result
->modulation
= STV0900_16APSK
;
1226 else if (result
->modcode
<= STV0900_32APSK_910
)
1227 result
->modulation
= STV0900_32APSK
;
1229 result
->modulation
= STV0900_UNKNOWN
;
1231 case STV0900_DVBS1_STANDARD
:
1232 case STV0900_DSS_STANDARD
:
1233 result
->spectrum
= stv0900_get_bits(intp
, IQINV
);
1234 result
->modulation
= STV0900_QPSK
;
1240 if ((intp
->srch_algo
[d
] == STV0900_BLIND_SEARCH
) ||
1241 (intp
->symbol_rate
[d
] < 10000000)) {
1242 offsetFreq
= result
->frequency
- intp
->freq
[d
];
1243 if (intp
->tuner_type
[demod
] == 3)
1244 intp
->freq
[d
] = stv0900_get_freq_auto(intp
, d
);
1246 intp
->freq
[d
] = stv0900_get_tuner_freq(fe
);
1248 if (abs(offsetFreq
) <= ((intp
->srch_range
[d
] / 2000) + 500))
1249 range
= STV0900_RANGEOK
;
1250 else if (abs(offsetFreq
) <=
1251 (stv0900_carrier_width(result
->symbol_rate
,
1252 result
->rolloff
) / 2000))
1253 range
= STV0900_RANGEOK
;
1255 } else if (abs(offsetFreq
) <= ((intp
->srch_range
[d
] / 2000) + 500))
1256 range
= STV0900_RANGEOK
;
1258 dprintk("%s: range %d\n", __func__
, range
);
1264 fe_stv0900_signal_type
stv0900_dvbs1_acq_workaround(struct dvb_frontend
*fe
)
1266 struct stv0900_state
*state
= fe
->demodulator_priv
;
1267 struct stv0900_internal
*intp
= state
->internal
;
1268 enum fe_stv0900_demod_num demod
= state
->demod
;
1269 enum fe_stv0900_signal_type signal_type
= STV0900_NODATA
;
1277 intp
->result
[demod
].locked
= FALSE
;
1279 if (stv0900_get_bits(intp
, HEADER_MODE
) == STV0900_DVBS_FOUND
) {
1280 srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1281 srate
+= stv0900_get_timing_offst(intp
, srate
, demod
);
1282 if (intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
)
1283 stv0900_set_symbol_rate(intp
, intp
->mclk
, srate
, demod
);
1285 stv0900_get_lock_timeout(&demod_timeout
, &fec_timeout
,
1286 srate
, STV0900_WARM_START
);
1287 freq1
= stv0900_read_reg(intp
, CFR2
);
1288 freq0
= stv0900_read_reg(intp
, CFR1
);
1289 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
1290 stv0900_write_bits(intp
, SPECINV_CONTROL
,
1291 STV0900_IQ_FORCE_SWAPPED
);
1292 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
1293 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1294 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1295 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1296 if (stv0900_wait_for_lock(intp
, demod
,
1297 demod_timeout
, fec_timeout
) == TRUE
) {
1298 intp
->result
[demod
].locked
= TRUE
;
1299 signal_type
= stv0900_get_signal_params(fe
);
1300 stv0900_track_optimization(fe
);
1302 stv0900_write_bits(intp
, SPECINV_CONTROL
,
1303 STV0900_IQ_FORCE_NORMAL
);
1304 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
1305 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1306 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1307 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1308 if (stv0900_wait_for_lock(intp
, demod
,
1309 demod_timeout
, fec_timeout
) == TRUE
) {
1310 intp
->result
[demod
].locked
= TRUE
;
1311 signal_type
= stv0900_get_signal_params(fe
);
1312 stv0900_track_optimization(fe
);
1318 intp
->result
[demod
].locked
= FALSE
;
1323 static u16
stv0900_blind_check_agc2_min_level(struct stv0900_internal
*intp
,
1324 enum fe_stv0900_demod_num demod
)
1326 u32 minagc2level
= 0xffff,
1328 init_freq
, freq_step
;
1330 s32 i
, j
, nb_steps
, direction
;
1332 dprintk("%s\n", __func__
);
1334 stv0900_write_reg(intp
, AGC2REF
, 0x38);
1335 stv0900_write_bits(intp
, SCAN_ENABLE
, 0);
1336 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
1338 stv0900_write_bits(intp
, AUTO_GUP
, 1);
1339 stv0900_write_bits(intp
, AUTO_GLOW
, 1);
1341 stv0900_write_reg(intp
, DMDT0M
, 0x0);
1343 stv0900_set_symbol_rate(intp
, intp
->mclk
, 1000000, demod
);
1344 nb_steps
= -1 + (intp
->srch_range
[demod
] / 1000000);
1346 nb_steps
= (2 * nb_steps
) + 1;
1353 freq_step
= (1000000 << 8) / (intp
->mclk
>> 8);
1357 for (i
= 0; i
< nb_steps
; i
++) {
1359 init_freq
= init_freq
+ (freq_step
* i
);
1361 init_freq
= init_freq
- (freq_step
* i
);
1364 stv0900_write_reg(intp
, DMDISTATE
, 0x5C);
1365 stv0900_write_reg(intp
, CFRINIT1
, (init_freq
>> 8) & 0xff);
1366 stv0900_write_reg(intp
, CFRINIT0
, init_freq
& 0xff);
1367 stv0900_write_reg(intp
, DMDISTATE
, 0x58);
1371 for (j
= 0; j
< 10; j
++)
1372 agc2level
+= (stv0900_read_reg(intp
, AGC2I1
) << 8)
1373 | stv0900_read_reg(intp
, AGC2I0
);
1377 if (agc2level
< minagc2level
)
1378 minagc2level
= agc2level
;
1382 return (u16
)minagc2level
;
1385 static u32
stv0900_search_srate_coarse(struct dvb_frontend
*fe
)
1387 struct stv0900_state
*state
= fe
->demodulator_priv
;
1388 struct stv0900_internal
*intp
= state
->internal
;
1389 enum fe_stv0900_demod_num demod
= state
->demod
;
1390 int timing_lck
= FALSE
;
1391 s32 i
, timingcpt
= 0,
1399 currier_step
= 1200;
1401 if (intp
->chip_id
>= 0x30)
1406 stv0900_write_bits(intp
, DEMOD_MODE
, 0x1f);
1407 stv0900_write_reg(intp
, TMGCFG
, 0x12);
1408 stv0900_write_reg(intp
, TMGTHRISE
, 0xf0);
1409 stv0900_write_reg(intp
, TMGTHFALL
, 0xe0);
1410 stv0900_write_bits(intp
, SCAN_ENABLE
, 1);
1411 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 1);
1412 stv0900_write_reg(intp
, SFRUP1
, 0x83);
1413 stv0900_write_reg(intp
, SFRUP0
, 0xc0);
1414 stv0900_write_reg(intp
, SFRLOW1
, 0x82);
1415 stv0900_write_reg(intp
, SFRLOW0
, 0xa0);
1416 stv0900_write_reg(intp
, DMDT0M
, 0x0);
1417 stv0900_write_reg(intp
, AGC2REF
, 0x50);
1419 if (intp
->chip_id
>= 0x30) {
1420 stv0900_write_reg(intp
, CARFREQ
, 0x99);
1421 stv0900_write_reg(intp
, SFRSTEP
, 0x98);
1422 } else if (intp
->chip_id
>= 0x20) {
1423 stv0900_write_reg(intp
, CARFREQ
, 0x6a);
1424 stv0900_write_reg(intp
, SFRSTEP
, 0x95);
1426 stv0900_write_reg(intp
, CARFREQ
, 0xed);
1427 stv0900_write_reg(intp
, SFRSTEP
, 0x73);
1430 if (intp
->symbol_rate
[demod
] <= 2000000)
1431 currier_step
= 1000;
1432 else if (intp
->symbol_rate
[demod
] <= 5000000)
1433 currier_step
= 2000;
1434 else if (intp
->symbol_rate
[demod
] <= 12000000)
1435 currier_step
= 3000;
1437 currier_step
= 5000;
1439 nb_steps
= -1 + ((intp
->srch_range
[demod
] / 1000) / currier_step
);
1441 nb_steps
= (2 * nb_steps
) + 1;
1445 else if (nb_steps
> 10) {
1447 currier_step
= (intp
->srch_range
[demod
] / 1000) / 10;
1453 tuner_freq
= intp
->freq
[demod
];
1455 while ((timing_lck
== FALSE
) && (current_step
< nb_steps
)) {
1456 stv0900_write_reg(intp
, DMDISTATE
, 0x5f);
1457 stv0900_write_bits(intp
, DEMOD_MODE
, 0);
1461 for (i
= 0; i
< 10; i
++) {
1462 if (stv0900_get_bits(intp
, TMGLOCK_QUALITY
) >= 2)
1465 agc2_integr
+= (stv0900_read_reg(intp
, AGC2I1
) << 8) |
1466 stv0900_read_reg(intp
, AGC2I0
);
1470 coarse_srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1474 dprintk("lock: I2C_DEMOD_MODE_FIELD =0. Search started. tuner freq=%d agc2=0x%x srate_coarse=%d tmg_cpt=%d\n",
1475 tuner_freq
, agc2_integr
, coarse_srate
, timingcpt
);
1477 if ((timingcpt
>= 5) &&
1478 (agc2_integr
< agc2_th
) &&
1479 (coarse_srate
< 55000000) &&
1480 (coarse_srate
> 850000))
1482 else if (current_step
< nb_steps
) {
1484 tuner_freq
+= (current_step
* currier_step
);
1486 tuner_freq
-= (current_step
* currier_step
);
1488 if (intp
->tuner_type
[demod
] == 3)
1489 stv0900_set_tuner_auto(intp
, tuner_freq
,
1490 intp
->bw
[demod
], demod
);
1492 stv0900_set_tuner(fe
, tuner_freq
,
1497 if (timing_lck
== FALSE
)
1500 coarse_srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1502 return coarse_srate
;
1505 static u32
stv0900_search_srate_fine(struct dvb_frontend
*fe
)
1507 struct stv0900_state
*state
= fe
->demodulator_priv
;
1508 struct stv0900_internal
*intp
= state
->internal
;
1509 enum fe_stv0900_demod_num demod
= state
->demod
;
1517 coarse_srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1519 if (coarse_srate
> 3000000) {
1520 symbmax
= 13 * (coarse_srate
/ 10);
1521 symbmax
= (symbmax
/ 1000) * 65536;
1522 symbmax
/= (intp
->mclk
/ 1000);
1524 symbmin
= 10 * (coarse_srate
/ 13);
1525 symbmin
= (symbmin
/ 1000)*65536;
1526 symbmin
/= (intp
->mclk
/ 1000);
1528 symb
= (coarse_srate
/ 1000) * 65536;
1529 symb
/= (intp
->mclk
/ 1000);
1531 symbmax
= 13 * (coarse_srate
/ 10);
1532 symbmax
= (symbmax
/ 100) * 65536;
1533 symbmax
/= (intp
->mclk
/ 100);
1535 symbmin
= 10 * (coarse_srate
/ 14);
1536 symbmin
= (symbmin
/ 100) * 65536;
1537 symbmin
/= (intp
->mclk
/ 100);
1539 symb
= (coarse_srate
/ 100) * 65536;
1540 symb
/= (intp
->mclk
/ 100);
1543 symbcomp
= 13 * (coarse_srate
/ 10);
1544 coarse_freq
= (stv0900_read_reg(intp
, CFR2
) << 8)
1545 | stv0900_read_reg(intp
, CFR1
);
1547 if (symbcomp
< intp
->symbol_rate
[demod
])
1550 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
1551 stv0900_write_reg(intp
, TMGCFG2
, 0xc1);
1552 stv0900_write_reg(intp
, TMGTHRISE
, 0x20);
1553 stv0900_write_reg(intp
, TMGTHFALL
, 0x00);
1554 stv0900_write_reg(intp
, TMGCFG
, 0xd2);
1555 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
1556 stv0900_write_reg(intp
, AGC2REF
, 0x38);
1558 if (intp
->chip_id
>= 0x30)
1559 stv0900_write_reg(intp
, CARFREQ
, 0x79);
1560 else if (intp
->chip_id
>= 0x20)
1561 stv0900_write_reg(intp
, CARFREQ
, 0x49);
1563 stv0900_write_reg(intp
, CARFREQ
, 0xed);
1565 stv0900_write_reg(intp
, SFRUP1
, (symbmax
>> 8) & 0x7f);
1566 stv0900_write_reg(intp
, SFRUP0
, (symbmax
& 0xff));
1568 stv0900_write_reg(intp
, SFRLOW1
, (symbmin
>> 8) & 0x7f);
1569 stv0900_write_reg(intp
, SFRLOW0
, (symbmin
& 0xff));
1571 stv0900_write_reg(intp
, SFRINIT1
, (symb
>> 8) & 0xff);
1572 stv0900_write_reg(intp
, SFRINIT0
, (symb
& 0xff));
1574 stv0900_write_reg(intp
, DMDT0M
, 0x20);
1575 stv0900_write_reg(intp
, CFRINIT1
, (coarse_freq
>> 8) & 0xff);
1576 stv0900_write_reg(intp
, CFRINIT0
, coarse_freq
& 0xff);
1577 stv0900_write_reg(intp
, DMDISTATE
, 0x15);
1580 return coarse_srate
;
1583 static int stv0900_blind_search_algo(struct dvb_frontend
*fe
)
1585 struct stv0900_state
*state
= fe
->demodulator_priv
;
1586 struct stv0900_internal
*intp
= state
->internal
;
1587 enum fe_stv0900_demod_num demod
= state
->demod
;
1594 coarse_fail
= FALSE
;
1595 s32 demod_timeout
= 500,
1603 dprintk("%s\n", __func__
);
1605 if (intp
->chip_id
< 0x20) {
1606 k_ref_tmg_max
= 233;
1607 k_ref_tmg_min
= 143;
1609 k_ref_tmg_max
= 110;
1613 if (intp
->chip_id
<= 0x20)
1614 agc2_th
= STV0900_BLIND_SEARCH_AGC2_TH
;
1616 agc2_th
= STV0900_BLIND_SEARCH_AGC2_TH_CUT30
;
1618 agc2_int
= stv0900_blind_check_agc2_min_level(intp
, demod
);
1620 dprintk("%s agc2_int=%d agc2_th=%d \n", __func__
, agc2_int
, agc2_th
);
1621 if (agc2_int
> agc2_th
)
1624 if (intp
->chip_id
== 0x10)
1625 stv0900_write_reg(intp
, CORRELEXP
, 0xaa);
1627 if (intp
->chip_id
< 0x20)
1628 stv0900_write_reg(intp
, CARHDR
, 0x55);
1630 stv0900_write_reg(intp
, CARHDR
, 0x20);
1632 if (intp
->chip_id
<= 0x20)
1633 stv0900_write_reg(intp
, CARCFG
, 0xc4);
1635 stv0900_write_reg(intp
, CARCFG
, 0x6);
1637 stv0900_write_reg(intp
, RTCS2
, 0x44);
1639 if (intp
->chip_id
>= 0x20) {
1640 stv0900_write_reg(intp
, EQUALCFG
, 0x41);
1641 stv0900_write_reg(intp
, FFECFG
, 0x41);
1642 stv0900_write_reg(intp
, VITSCALE
, 0x82);
1643 stv0900_write_reg(intp
, VAVSRVIT
, 0x0);
1646 k_ref_tmg
= k_ref_tmg_max
;
1649 stv0900_write_reg(intp
, KREFTMG
, k_ref_tmg
);
1650 if (stv0900_search_srate_coarse(fe
) != 0) {
1651 coarse_srate
= stv0900_search_srate_fine(fe
);
1653 if (coarse_srate
!= 0) {
1654 stv0900_get_lock_timeout(&demod_timeout
,
1657 STV0900_BLIND_SEARCH
);
1658 lock
= stv0900_get_demod_lock(intp
,
1667 for (i
= 0; i
< 10; i
++) {
1668 agc2_int
= (stv0900_read_reg(intp
, AGC2I1
) << 8)
1669 | stv0900_read_reg(intp
, AGC2I0
);
1671 if (agc2_int
>= 0xff00)
1674 dstatus2
= stv0900_read_reg(intp
, DSTATUS2
);
1676 if (((dstatus2
& 0x1) == 0x1) &&
1677 ((dstatus2
>> 7) == 1))
1681 if ((fail_cpt
> 7) || (agc2_overflow
> 7))
1687 } while ((k_ref_tmg
>= k_ref_tmg_min
) &&
1689 (coarse_fail
== FALSE
));
1694 static void stv0900_set_viterbi_acq(struct stv0900_internal
*intp
,
1695 enum fe_stv0900_demod_num demod
)
1697 s32 vth_reg
= VTH12
;
1699 dprintk("%s\n", __func__
);
1701 stv0900_write_reg(intp
, vth_reg
++, 0x96);
1702 stv0900_write_reg(intp
, vth_reg
++, 0x64);
1703 stv0900_write_reg(intp
, vth_reg
++, 0x36);
1704 stv0900_write_reg(intp
, vth_reg
++, 0x23);
1705 stv0900_write_reg(intp
, vth_reg
++, 0x1e);
1706 stv0900_write_reg(intp
, vth_reg
++, 0x19);
1709 static void stv0900_set_search_standard(struct stv0900_internal
*intp
,
1710 enum fe_stv0900_demod_num demod
)
1713 dprintk("%s\n", __func__
);
1715 switch (intp
->srch_standard
[demod
]) {
1716 case STV0900_SEARCH_DVBS1
:
1717 dprintk("Search Standard = DVBS1\n");
1719 case STV0900_SEARCH_DSS
:
1720 dprintk("Search Standard = DSS\n");
1722 case STV0900_SEARCH_DVBS2
:
1723 dprintk("Search Standard = DVBS2\n");
1725 case STV0900_AUTO_SEARCH
:
1727 dprintk("Search Standard = AUTO\n");
1731 switch (intp
->srch_standard
[demod
]) {
1732 case STV0900_SEARCH_DVBS1
:
1733 case STV0900_SEARCH_DSS
:
1734 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
1735 stv0900_write_bits(intp
, DVBS2_ENABLE
, 0);
1736 stv0900_write_bits(intp
, STOP_CLKVIT
, 0);
1737 stv0900_set_dvbs1_track_car_loop(intp
,
1739 intp
->symbol_rate
[demod
]);
1740 stv0900_write_reg(intp
, CAR2CFG
, 0x22);
1742 stv0900_set_viterbi_acq(intp
, demod
);
1743 stv0900_set_viterbi_standard(intp
,
1744 intp
->srch_standard
[demod
],
1745 intp
->fec
[demod
], demod
);
1748 case STV0900_SEARCH_DVBS2
:
1749 stv0900_write_bits(intp
, DVBS1_ENABLE
, 0);
1750 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
1751 stv0900_write_bits(intp
, STOP_CLKVIT
, 1);
1752 stv0900_write_reg(intp
, ACLC
, 0x1a);
1753 stv0900_write_reg(intp
, BCLC
, 0x09);
1754 if (intp
->chip_id
<= 0x20) /*cut 1.x and 2.0*/
1755 stv0900_write_reg(intp
, CAR2CFG
, 0x26);
1757 stv0900_write_reg(intp
, CAR2CFG
, 0x66);
1759 if (intp
->demod_mode
!= STV0900_SINGLE
) {
1760 if (intp
->chip_id
<= 0x11)
1761 stv0900_stop_all_s2_modcod(intp
, demod
);
1763 stv0900_activate_s2_modcod(intp
, demod
);
1766 stv0900_activate_s2_modcod_single(intp
, demod
);
1768 stv0900_set_viterbi_tracq(intp
, demod
);
1771 case STV0900_AUTO_SEARCH
:
1773 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
1774 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
1775 stv0900_write_bits(intp
, STOP_CLKVIT
, 0);
1776 stv0900_write_reg(intp
, ACLC
, 0x1a);
1777 stv0900_write_reg(intp
, BCLC
, 0x09);
1778 stv0900_set_dvbs1_track_car_loop(intp
,
1780 intp
->symbol_rate
[demod
]);
1781 if (intp
->chip_id
<= 0x20) /*cut 1.x and 2.0*/
1782 stv0900_write_reg(intp
, CAR2CFG
, 0x26);
1784 stv0900_write_reg(intp
, CAR2CFG
, 0x66);
1786 if (intp
->demod_mode
!= STV0900_SINGLE
) {
1787 if (intp
->chip_id
<= 0x11)
1788 stv0900_stop_all_s2_modcod(intp
, demod
);
1790 stv0900_activate_s2_modcod(intp
, demod
);
1793 stv0900_activate_s2_modcod_single(intp
, demod
);
1795 stv0900_set_viterbi_tracq(intp
, demod
);
1796 stv0900_set_viterbi_standard(intp
,
1797 intp
->srch_standard
[demod
],
1798 intp
->fec
[demod
], demod
);
1804 enum fe_stv0900_signal_type
stv0900_algo(struct dvb_frontend
*fe
)
1806 struct stv0900_state
*state
= fe
->demodulator_priv
;
1807 struct stv0900_internal
*intp
= state
->internal
;
1808 enum fe_stv0900_demod_num demod
= state
->demod
;
1810 s32 demod_timeout
= 500, fec_timeout
= 50;
1811 s32 aq_power
, agc1_power
, i
;
1813 int lock
= FALSE
, low_sr
= FALSE
;
1815 enum fe_stv0900_signal_type signal_type
= STV0900_NOCARRIER
;
1816 enum fe_stv0900_search_algo algo
;
1817 int no_signal
= FALSE
;
1819 dprintk("%s\n", __func__
);
1821 algo
= intp
->srch_algo
[demod
];
1822 stv0900_write_bits(intp
, RST_HWARE
, 1);
1823 stv0900_write_reg(intp
, DMDISTATE
, 0x5c);
1824 if (intp
->chip_id
>= 0x20) {
1825 if (intp
->symbol_rate
[demod
] > 5000000)
1826 stv0900_write_reg(intp
, CORRELABS
, 0x9e);
1828 stv0900_write_reg(intp
, CORRELABS
, 0x82);
1830 stv0900_write_reg(intp
, CORRELABS
, 0x88);
1832 stv0900_get_lock_timeout(&demod_timeout
, &fec_timeout
,
1833 intp
->symbol_rate
[demod
],
1834 intp
->srch_algo
[demod
]);
1836 if (intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
) {
1837 intp
->bw
[demod
] = 2 * 36000000;
1839 stv0900_write_reg(intp
, TMGCFG2
, 0xc0);
1840 stv0900_write_reg(intp
, CORRELMANT
, 0x70);
1842 stv0900_set_symbol_rate(intp
, intp
->mclk
, 1000000, demod
);
1844 stv0900_write_reg(intp
, DMDT0M
, 0x20);
1845 stv0900_write_reg(intp
, TMGCFG
, 0xd2);
1847 if (intp
->symbol_rate
[demod
] < 2000000)
1848 stv0900_write_reg(intp
, CORRELMANT
, 0x63);
1850 stv0900_write_reg(intp
, CORRELMANT
, 0x70);
1852 stv0900_write_reg(intp
, AGC2REF
, 0x38);
1855 stv0900_carrier_width(intp
->symbol_rate
[demod
],
1857 if (intp
->chip_id
>= 0x20) {
1858 stv0900_write_reg(intp
, KREFTMG
, 0x5a);
1860 if (intp
->srch_algo
[demod
] == STV0900_COLD_START
) {
1861 intp
->bw
[demod
] += 10000000;
1862 intp
->bw
[demod
] *= 15;
1863 intp
->bw
[demod
] /= 10;
1864 } else if (intp
->srch_algo
[demod
] == STV0900_WARM_START
)
1865 intp
->bw
[demod
] += 10000000;
1868 stv0900_write_reg(intp
, KREFTMG
, 0xc1);
1869 intp
->bw
[demod
] += 10000000;
1870 intp
->bw
[demod
] *= 15;
1871 intp
->bw
[demod
] /= 10;
1874 stv0900_write_reg(intp
, TMGCFG2
, 0xc1);
1876 stv0900_set_symbol_rate(intp
, intp
->mclk
,
1877 intp
->symbol_rate
[demod
], demod
);
1878 stv0900_set_max_symbol_rate(intp
, intp
->mclk
,
1879 intp
->symbol_rate
[demod
], demod
);
1880 stv0900_set_min_symbol_rate(intp
, intp
->mclk
,
1881 intp
->symbol_rate
[demod
], demod
);
1882 if (intp
->symbol_rate
[demod
] >= 10000000)
1889 if (intp
->tuner_type
[demod
] == 3)
1890 stv0900_set_tuner_auto(intp
, intp
->freq
[demod
],
1891 intp
->bw
[demod
], demod
);
1893 stv0900_set_tuner(fe
, intp
->freq
[demod
], intp
->bw
[demod
]);
1895 agc1_power
= MAKEWORD(stv0900_get_bits(intp
, AGCIQ_VALUE1
),
1896 stv0900_get_bits(intp
, AGCIQ_VALUE0
));
1900 if (agc1_power
== 0) {
1901 for (i
= 0; i
< 5; i
++)
1902 aq_power
+= (stv0900_get_bits(intp
, POWER_I
) +
1903 stv0900_get_bits(intp
, POWER_Q
)) / 2;
1908 if ((agc1_power
== 0) && (aq_power
< IQPOWER_THRESHOLD
)) {
1909 intp
->result
[demod
].locked
= FALSE
;
1910 signal_type
= STV0900_NOAGC1
;
1911 dprintk("%s: NO AGC1, POWERI, POWERQ\n", __func__
);
1913 stv0900_write_bits(intp
, SPECINV_CONTROL
,
1914 intp
->srch_iq_inv
[demod
]);
1915 if (intp
->chip_id
<= 0x20) /*cut 2.0*/
1916 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 1);
1918 stv0900_write_bits(intp
, MANUALS2_ROLLOFF
, 1);
1920 stv0900_set_search_standard(intp
, demod
);
1922 if (intp
->srch_algo
[demod
] != STV0900_BLIND_SEARCH
)
1923 stv0900_start_search(intp
, demod
);
1926 if (signal_type
== STV0900_NOAGC1
)
1929 if (intp
->chip_id
== 0x12) {
1930 stv0900_write_bits(intp
, RST_HWARE
, 0);
1932 stv0900_write_bits(intp
, RST_HWARE
, 1);
1933 stv0900_write_bits(intp
, RST_HWARE
, 0);
1936 if (algo
== STV0900_BLIND_SEARCH
)
1937 lock
= stv0900_blind_search_algo(fe
);
1938 else if (algo
== STV0900_COLD_START
)
1939 lock
= stv0900_get_demod_cold_lock(fe
, demod_timeout
);
1940 else if (algo
== STV0900_WARM_START
)
1941 lock
= stv0900_get_demod_lock(intp
, demod
, demod_timeout
);
1943 if ((lock
== FALSE
) && (algo
== STV0900_COLD_START
)) {
1944 if (low_sr
== FALSE
) {
1945 if (stv0900_check_timing_lock(intp
, demod
) == TRUE
)
1946 lock
= stv0900_sw_algo(intp
, demod
);
1951 signal_type
= stv0900_get_signal_params(fe
);
1953 if ((lock
== TRUE
) && (signal_type
== STV0900_RANGEOK
)) {
1954 stv0900_track_optimization(fe
);
1955 if (intp
->chip_id
<= 0x11) {
1956 if ((stv0900_get_standard(fe
, 0) ==
1957 STV0900_DVBS1_STANDARD
) &&
1958 (stv0900_get_standard(fe
, 1) ==
1959 STV0900_DVBS1_STANDARD
)) {
1961 stv0900_write_bits(intp
, RST_HWARE
, 0);
1963 stv0900_write_bits(intp
, RST_HWARE
, 0);
1965 stv0900_write_bits(intp
, RST_HWARE
, 1);
1966 stv0900_write_bits(intp
, RST_HWARE
, 0);
1969 } else if (intp
->chip_id
>= 0x20) {
1970 stv0900_write_bits(intp
, RST_HWARE
, 0);
1972 stv0900_write_bits(intp
, RST_HWARE
, 1);
1973 stv0900_write_bits(intp
, RST_HWARE
, 0);
1976 if (stv0900_wait_for_lock(intp
, demod
,
1977 fec_timeout
, fec_timeout
) == TRUE
) {
1979 intp
->result
[demod
].locked
= TRUE
;
1980 if (intp
->result
[demod
].standard
==
1981 STV0900_DVBS2_STANDARD
) {
1982 stv0900_set_dvbs2_rolloff(intp
, demod
);
1983 stv0900_write_bits(intp
, RESET_UPKO_COUNT
, 1);
1984 stv0900_write_bits(intp
, RESET_UPKO_COUNT
, 0);
1985 stv0900_write_reg(intp
, ERRCTRL1
, 0x67);
1987 stv0900_write_reg(intp
, ERRCTRL1
, 0x75);
1990 stv0900_write_reg(intp
, FBERCPT4
, 0);
1991 stv0900_write_reg(intp
, ERRCTRL2
, 0xc1);
1994 signal_type
= STV0900_NODATA
;
1995 no_signal
= stv0900_check_signal_presence(intp
, demod
);
1997 intp
->result
[demod
].locked
= FALSE
;
2001 if ((signal_type
!= STV0900_NODATA
) || (no_signal
!= FALSE
))
2004 if (intp
->chip_id
> 0x11) {
2005 intp
->result
[demod
].locked
= FALSE
;
2009 if ((stv0900_get_bits(intp
, HEADER_MODE
) == STV0900_DVBS_FOUND
) &&
2010 (intp
->srch_iq_inv
[demod
] <= STV0900_IQ_AUTO_NORMAL_FIRST
))
2011 signal_type
= stv0900_dvbs1_acq_workaround(fe
);