4 * Driver for ST STV0900 satellite demodulator IC.
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "stv0900_reg.h"
28 #include "stv0900_priv.h"
30 s32
shiftx(s32 x
, int demod
, s32 shift
)
38 int stv0900_check_signal_presence(struct stv0900_internal
*intp
,
39 enum fe_stv0900_demod_num demod
)
45 int no_signal
= FALSE
;
47 carr_offset
= (stv0900_read_reg(intp
, CFR2
) << 8)
48 | stv0900_read_reg(intp
, CFR1
);
49 carr_offset
= ge2comp(carr_offset
, 16);
50 agc2_integr
= (stv0900_read_reg(intp
, AGC2I1
) << 8)
51 | stv0900_read_reg(intp
, AGC2I0
);
52 max_carrier
= intp
->srch_range
[demod
] / 1000;
54 max_carrier
+= (max_carrier
/ 10);
55 max_carrier
= 65536 * (max_carrier
/ 2);
56 max_carrier
/= intp
->mclk
/ 1000;
57 if (max_carrier
> 0x4000)
60 if ((agc2_integr
> 0x2000)
61 || (carr_offset
> (2 * max_carrier
))
62 || (carr_offset
< (-2 * max_carrier
)))
68 static void stv0900_get_sw_loop_params(struct stv0900_internal
*intp
,
69 s32
*frequency_inc
, s32
*sw_timeout
,
71 enum fe_stv0900_demod_num demod
)
73 s32 timeout
, freq_inc
, max_steps
, srate
, max_carrier
;
75 enum fe_stv0900_search_standard standard
;
77 srate
= intp
->symbol_rate
[demod
];
78 max_carrier
= intp
->srch_range
[demod
] / 1000;
79 max_carrier
+= max_carrier
/ 10;
80 standard
= intp
->srch_standard
[demod
];
82 max_carrier
= 65536 * (max_carrier
/ 2);
83 max_carrier
/= intp
->mclk
/ 1000;
85 if (max_carrier
> 0x4000)
89 freq_inc
/= intp
->mclk
>> 10;
90 freq_inc
= freq_inc
<< 6;
93 case STV0900_SEARCH_DVBS1
:
94 case STV0900_SEARCH_DSS
:
98 case STV0900_SEARCH_DVBS2
:
102 case STV0900_AUTO_SEARCH
:
111 if ((freq_inc
> max_carrier
) || (freq_inc
< 0))
112 freq_inc
= max_carrier
/ 2;
117 timeout
/= srate
/ 1000;
119 if ((timeout
> 100) || (timeout
< 0))
122 max_steps
= (max_carrier
/ freq_inc
) + 1;
124 if ((max_steps
> 100) || (max_steps
< 0)) {
126 freq_inc
= max_carrier
/ max_steps
;
129 *frequency_inc
= freq_inc
;
130 *sw_timeout
= timeout
;
135 static int stv0900_search_carr_sw_loop(struct stv0900_internal
*intp
,
136 s32 FreqIncr
, s32 Timeout
, int zigzag
,
137 s32 MaxStep
, enum fe_stv0900_demod_num demod
)
145 max_carrier
= intp
->srch_range
[demod
] / 1000;
146 max_carrier
+= (max_carrier
/ 10);
148 max_carrier
= 65536 * (max_carrier
/ 2);
149 max_carrier
/= intp
->mclk
/ 1000;
151 if (max_carrier
> 0x4000)
152 max_carrier
= 0x4000;
157 freqOffset
= -max_carrier
+ FreqIncr
;
162 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
163 stv0900_write_reg(intp
, CFRINIT1
, (freqOffset
/ 256) & 0xff);
164 stv0900_write_reg(intp
, CFRINIT0
, freqOffset
& 0xff);
165 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
166 stv0900_write_bits(intp
, ALGOSWRST
, 1);
168 if (intp
->chip_id
== 0x12) {
169 stv0900_write_bits(intp
, RST_HWARE
, 1);
170 stv0900_write_bits(intp
, RST_HWARE
, 0);
173 if (zigzag
== TRUE
) {
175 freqOffset
= -freqOffset
- 2 * FreqIncr
;
177 freqOffset
= -freqOffset
;
179 freqOffset
+= + 2 * FreqIncr
;
182 lock
= stv0900_get_demod_lock(intp
, demod
, Timeout
);
183 no_signal
= stv0900_check_signal_presence(intp
, demod
);
185 } while ((lock
== FALSE
)
186 && (no_signal
== FALSE
)
187 && ((freqOffset
- FreqIncr
) < max_carrier
)
188 && ((freqOffset
+ FreqIncr
) > -max_carrier
)
189 && (stepCpt
< MaxStep
));
191 stv0900_write_bits(intp
, ALGOSWRST
, 0);
196 static int stv0900_sw_algo(struct stv0900_internal
*intp
,
197 enum fe_stv0900_demod_num demod
)
208 stv0900_get_sw_loop_params(intp
, &fqc_inc
, &sft_stp_tout
,
210 switch (intp
->srch_standard
[demod
]) {
211 case STV0900_SEARCH_DVBS1
:
212 case STV0900_SEARCH_DSS
:
213 if (intp
->chip_id
>= 0x20)
214 stv0900_write_reg(intp
, CARFREQ
, 0x3b);
216 stv0900_write_reg(intp
, CARFREQ
, 0xef);
218 stv0900_write_reg(intp
, DMDCFGMD
, 0x49);
221 case STV0900_SEARCH_DVBS2
:
222 if (intp
->chip_id
>= 0x20)
223 stv0900_write_reg(intp
, CORRELABS
, 0x79);
225 stv0900_write_reg(intp
, CORRELABS
, 0x68);
227 stv0900_write_reg(intp
, DMDCFGMD
, 0x89);
231 case STV0900_AUTO_SEARCH
:
233 if (intp
->chip_id
>= 0x20) {
234 stv0900_write_reg(intp
, CARFREQ
, 0x3b);
235 stv0900_write_reg(intp
, CORRELABS
, 0x79);
237 stv0900_write_reg(intp
, CARFREQ
, 0xef);
238 stv0900_write_reg(intp
, CORRELABS
, 0x68);
241 stv0900_write_reg(intp
, DMDCFGMD
, 0xc9);
248 lock
= stv0900_search_carr_sw_loop(intp
,
254 no_signal
= stv0900_check_signal_presence(intp
, demod
);
257 || (no_signal
== TRUE
)
258 || (trial_cntr
== 2)) {
260 if (intp
->chip_id
>= 0x20) {
261 stv0900_write_reg(intp
, CARFREQ
, 0x49);
262 stv0900_write_reg(intp
, CORRELABS
, 0x9e);
264 stv0900_write_reg(intp
, CARFREQ
, 0xed);
265 stv0900_write_reg(intp
, CORRELABS
, 0x88);
268 if ((stv0900_get_bits(intp
, HEADER_MODE
) ==
269 STV0900_DVBS2_FOUND
) &&
271 msleep(sft_stp_tout
);
272 s2fw
= stv0900_get_bits(intp
, FLYWHEEL_CPT
);
275 msleep(sft_stp_tout
);
276 s2fw
= stv0900_get_bits(intp
,
283 if (trial_cntr
< 2) {
284 if (intp
->chip_id
>= 0x20)
285 stv0900_write_reg(intp
,
289 stv0900_write_reg(intp
,
293 stv0900_write_reg(intp
,
301 } while ((lock
== FALSE
)
303 && (no_signal
== FALSE
));
308 static u32
stv0900_get_symbol_rate(struct stv0900_internal
*intp
,
310 enum fe_stv0900_demod_num demod
)
312 s32 rem1
, rem2
, intval1
, intval2
, srate
;
314 srate
= (stv0900_get_bits(intp
, SYMB_FREQ3
) << 24) +
315 (stv0900_get_bits(intp
, SYMB_FREQ2
) << 16) +
316 (stv0900_get_bits(intp
, SYMB_FREQ1
) << 8) +
317 (stv0900_get_bits(intp
, SYMB_FREQ0
));
318 dprintk("lock: srate=%d r0=0x%x r1=0x%x r2=0x%x r3=0x%x \n",
319 srate
, stv0900_get_bits(intp
, SYMB_FREQ0
),
320 stv0900_get_bits(intp
, SYMB_FREQ1
),
321 stv0900_get_bits(intp
, SYMB_FREQ2
),
322 stv0900_get_bits(intp
, SYMB_FREQ3
));
324 intval1
= (mclk
) >> 16;
325 intval2
= (srate
) >> 16;
327 rem1
= (mclk
) % 0x10000;
328 rem2
= (srate
) % 0x10000;
329 srate
= (intval1
* intval2
) +
330 ((intval1
* rem2
) >> 16) +
331 ((intval2
* rem1
) >> 16);
336 static void stv0900_set_symbol_rate(struct stv0900_internal
*intp
,
338 enum fe_stv0900_demod_num demod
)
342 dprintk("%s: Mclk %d, SR %d, Dmd %d\n", __func__
, mclk
,
345 if (srate
> 60000000) {
347 symb
/= (mclk
>> 12);
348 } else if (srate
> 6000000) {
350 symb
/= (mclk
>> 10);
356 stv0900_write_reg(intp
, SFRINIT1
, (symb
>> 8) & 0x7f);
357 stv0900_write_reg(intp
, SFRINIT1
+ 1, (symb
& 0xff));
360 static void stv0900_set_max_symbol_rate(struct stv0900_internal
*intp
,
362 enum fe_stv0900_demod_num demod
)
366 srate
= 105 * (srate
/ 100);
368 if (srate
> 60000000) {
370 symb
/= (mclk
>> 12);
371 } else if (srate
> 6000000) {
373 symb
/= (mclk
>> 10);
380 stv0900_write_reg(intp
, SFRUP1
, (symb
>> 8) & 0x7f);
381 stv0900_write_reg(intp
, SFRUP1
+ 1, (symb
& 0xff));
383 stv0900_write_reg(intp
, SFRUP1
, 0x7f);
384 stv0900_write_reg(intp
, SFRUP1
+ 1, 0xff);
388 static void stv0900_set_min_symbol_rate(struct stv0900_internal
*intp
,
390 enum fe_stv0900_demod_num demod
)
394 srate
= 95 * (srate
/ 100);
395 if (srate
> 60000000) {
397 symb
/= (mclk
>> 12);
399 } else if (srate
> 6000000) {
401 symb
/= (mclk
>> 10);
408 stv0900_write_reg(intp
, SFRLOW1
, (symb
>> 8) & 0xff);
409 stv0900_write_reg(intp
, SFRLOW1
+ 1, (symb
& 0xff));
412 static s32
stv0900_get_timing_offst(struct stv0900_internal
*intp
,
414 enum fe_stv0900_demod_num demod
)
419 timingoffset
= (stv0900_read_reg(intp
, TMGREG2
) << 16) +
420 (stv0900_read_reg(intp
, TMGREG2
+ 1) << 8) +
421 (stv0900_read_reg(intp
, TMGREG2
+ 2));
423 timingoffset
= ge2comp(timingoffset
, 24);
426 if (timingoffset
== 0)
429 timingoffset
= ((s32
)srate
* 10) / ((s32
)0x1000000 / timingoffset
);
435 static void stv0900_set_dvbs2_rolloff(struct stv0900_internal
*intp
,
436 enum fe_stv0900_demod_num demod
)
440 if (intp
->chip_id
== 0x10) {
441 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 1);
442 rolloff
= stv0900_read_reg(intp
, MATSTR1
) & 0x03;
443 stv0900_write_bits(intp
, ROLLOFF_CONTROL
, rolloff
);
444 } else if (intp
->chip_id
<= 0x20)
445 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 0);
447 stv0900_write_bits(intp
, MANUALS2_ROLLOFF
, 0);
450 static u32
stv0900_carrier_width(u32 srate
, enum fe_stv0900_rolloff ro
)
467 return srate
+ (srate
* rolloff
) / 100;
470 static int stv0900_check_timing_lock(struct stv0900_internal
*intp
,
471 enum fe_stv0900_demod_num demod
)
473 int timingLock
= FALSE
;
480 car_freq
= stv0900_read_reg(intp
, CARFREQ
);
481 tmg_th_high
= stv0900_read_reg(intp
, TMGTHRISE
);
482 tmg_th_low
= stv0900_read_reg(intp
, TMGTHFALL
);
483 stv0900_write_reg(intp
, TMGTHRISE
, 0x20);
484 stv0900_write_reg(intp
, TMGTHFALL
, 0x0);
485 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
486 stv0900_write_reg(intp
, RTC
, 0x80);
487 stv0900_write_reg(intp
, RTCS2
, 0x40);
488 stv0900_write_reg(intp
, CARFREQ
, 0x0);
489 stv0900_write_reg(intp
, CFRINIT1
, 0x0);
490 stv0900_write_reg(intp
, CFRINIT0
, 0x0);
491 stv0900_write_reg(intp
, AGC2REF
, 0x65);
492 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
495 for (i
= 0; i
< 10; i
++) {
496 if (stv0900_get_bits(intp
, TMGLOCK_QUALITY
) >= 2)
505 stv0900_write_reg(intp
, AGC2REF
, 0x38);
506 stv0900_write_reg(intp
, RTC
, 0x88);
507 stv0900_write_reg(intp
, RTCS2
, 0x68);
508 stv0900_write_reg(intp
, CARFREQ
, car_freq
);
509 stv0900_write_reg(intp
, TMGTHRISE
, tmg_th_high
);
510 stv0900_write_reg(intp
, TMGTHFALL
, tmg_th_low
);
515 static int stv0900_get_demod_cold_lock(struct dvb_frontend
*fe
,
518 struct stv0900_state
*state
= fe
->demodulator_priv
;
519 struct stv0900_internal
*intp
= state
->internal
;
520 enum fe_stv0900_demod_num demod
= state
->demod
;
534 srate
= intp
->symbol_rate
[d
];
535 search_range
= intp
->srch_range
[d
];
537 if (srate
>= 10000000)
538 locktimeout
= demod_timeout
/ 3;
540 locktimeout
= demod_timeout
/ 2;
542 lock
= stv0900_get_demod_lock(intp
, d
, locktimeout
);
547 if (srate
>= 10000000) {
548 if (stv0900_check_timing_lock(intp
, d
) == TRUE
) {
549 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
550 stv0900_write_reg(intp
, DMDISTATE
, 0x15);
551 lock
= stv0900_get_demod_lock(intp
, d
, demod_timeout
);
558 if (intp
->chip_id
<= 0x20) {
559 if (srate
<= 1000000)
561 else if (srate
<= 4000000)
563 else if (srate
<= 7000000)
565 else if (srate
<= 10000000)
570 if (srate
>= 2000000) {
571 timeout
= (demod_timeout
/ 3);
575 timeout
= (demod_timeout
/ 2);
578 currier_step
= srate
/ 4000;
579 timeout
= (demod_timeout
* 3) / 4;
582 nb_steps
= ((search_range
/ 1000) / currier_step
);
584 if ((nb_steps
% 2) != 0)
589 else if (nb_steps
> 12)
595 if (intp
->chip_id
<= 0x20) {
596 tuner_freq
= intp
->freq
[d
];
597 intp
->bw
[d
] = stv0900_carrier_width(intp
->symbol_rate
[d
],
598 intp
->rolloff
) + intp
->symbol_rate
[d
];
602 while ((current_step
<= nb_steps
) && (lock
== FALSE
)) {
604 tuner_freq
+= (current_step
* currier_step
);
606 tuner_freq
-= (current_step
* currier_step
);
608 if (intp
->chip_id
<= 0x20) {
609 if (intp
->tuner_type
[d
] == 3)
610 stv0900_set_tuner_auto(intp
, tuner_freq
,
613 stv0900_set_tuner(fe
, tuner_freq
, intp
->bw
[d
]);
615 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
616 stv0900_write_reg(intp
, CFRINIT1
, 0);
617 stv0900_write_reg(intp
, CFRINIT0
, 0);
618 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
619 stv0900_write_reg(intp
, DMDISTATE
, 0x15);
621 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
622 freq
= (tuner_freq
* 65536) / (intp
->mclk
/ 1000);
623 stv0900_write_bits(intp
, CFR_INIT1
, MSB(freq
));
624 stv0900_write_bits(intp
, CFR_INIT0
, LSB(freq
));
625 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
626 stv0900_write_reg(intp
, DMDISTATE
, 0x05);
629 lock
= stv0900_get_demod_lock(intp
, d
, timeout
);
637 static void stv0900_get_lock_timeout(s32
*demod_timeout
, s32
*fec_timeout
,
639 enum fe_stv0900_search_algo algo
)
642 case STV0900_BLIND_SEARCH
:
643 if (srate
<= 1500000) {
644 (*demod_timeout
) = 1500;
645 (*fec_timeout
) = 400;
646 } else if (srate
<= 5000000) {
647 (*demod_timeout
) = 1000;
648 (*fec_timeout
) = 300;
650 (*demod_timeout
) = 700;
651 (*fec_timeout
) = 100;
655 case STV0900_COLD_START
:
656 case STV0900_WARM_START
:
658 if (srate
<= 1000000) {
659 (*demod_timeout
) = 3000;
660 (*fec_timeout
) = 1700;
661 } else if (srate
<= 2000000) {
662 (*demod_timeout
) = 2500;
663 (*fec_timeout
) = 1100;
664 } else if (srate
<= 5000000) {
665 (*demod_timeout
) = 1000;
666 (*fec_timeout
) = 550;
667 } else if (srate
<= 10000000) {
668 (*demod_timeout
) = 700;
669 (*fec_timeout
) = 250;
670 } else if (srate
<= 20000000) {
671 (*demod_timeout
) = 400;
672 (*fec_timeout
) = 130;
674 (*demod_timeout
) = 300;
675 (*fec_timeout
) = 100;
682 if (algo
== STV0900_WARM_START
)
683 (*demod_timeout
) /= 2;
686 static void stv0900_set_viterbi_tracq(struct stv0900_internal
*intp
,
687 enum fe_stv0900_demod_num demod
)
692 dprintk("%s\n", __func__
);
694 stv0900_write_reg(intp
, vth_reg
++, 0xd0);
695 stv0900_write_reg(intp
, vth_reg
++, 0x7d);
696 stv0900_write_reg(intp
, vth_reg
++, 0x53);
697 stv0900_write_reg(intp
, vth_reg
++, 0x2f);
698 stv0900_write_reg(intp
, vth_reg
++, 0x24);
699 stv0900_write_reg(intp
, vth_reg
++, 0x1f);
702 static void stv0900_set_viterbi_standard(struct stv0900_internal
*intp
,
703 enum fe_stv0900_search_standard standard
,
704 enum fe_stv0900_fec fec
,
705 enum fe_stv0900_demod_num demod
)
707 dprintk("%s: ViterbiStandard = ", __func__
);
710 case STV0900_AUTO_SEARCH
:
712 stv0900_write_reg(intp
, FECM
, 0x10);
713 stv0900_write_reg(intp
, PRVIT
, 0x3f);
715 case STV0900_SEARCH_DVBS1
:
717 stv0900_write_reg(intp
, FECM
, 0x00);
719 case STV0900_FEC_UNKNOWN
:
721 stv0900_write_reg(intp
, PRVIT
, 0x2f);
723 case STV0900_FEC_1_2
:
724 stv0900_write_reg(intp
, PRVIT
, 0x01);
726 case STV0900_FEC_2_3
:
727 stv0900_write_reg(intp
, PRVIT
, 0x02);
729 case STV0900_FEC_3_4
:
730 stv0900_write_reg(intp
, PRVIT
, 0x04);
732 case STV0900_FEC_5_6
:
733 stv0900_write_reg(intp
, PRVIT
, 0x08);
735 case STV0900_FEC_7_8
:
736 stv0900_write_reg(intp
, PRVIT
, 0x20);
741 case STV0900_SEARCH_DSS
:
743 stv0900_write_reg(intp
, FECM
, 0x80);
745 case STV0900_FEC_UNKNOWN
:
747 stv0900_write_reg(intp
, PRVIT
, 0x13);
749 case STV0900_FEC_1_2
:
750 stv0900_write_reg(intp
, PRVIT
, 0x01);
752 case STV0900_FEC_2_3
:
753 stv0900_write_reg(intp
, PRVIT
, 0x02);
755 case STV0900_FEC_6_7
:
756 stv0900_write_reg(intp
, PRVIT
, 0x10);
765 static enum fe_stv0900_fec
stv0900_get_vit_fec(struct stv0900_internal
*intp
,
766 enum fe_stv0900_demod_num demod
)
768 enum fe_stv0900_fec prate
;
769 s32 rate_fld
= stv0900_get_bits(intp
, VIT_CURPUN
);
773 prate
= STV0900_FEC_1_2
;
776 prate
= STV0900_FEC_2_3
;
779 prate
= STV0900_FEC_3_4
;
782 prate
= STV0900_FEC_5_6
;
785 prate
= STV0900_FEC_6_7
;
788 prate
= STV0900_FEC_7_8
;
791 prate
= STV0900_FEC_UNKNOWN
;
798 static void stv0900_set_dvbs1_track_car_loop(struct stv0900_internal
*intp
,
799 enum fe_stv0900_demod_num demod
,
802 if (intp
->chip_id
>= 0x30) {
803 if (srate
>= 15000000) {
804 stv0900_write_reg(intp
, ACLC
, 0x2b);
805 stv0900_write_reg(intp
, BCLC
, 0x1a);
806 } else if ((srate
>= 7000000) && (15000000 > srate
)) {
807 stv0900_write_reg(intp
, ACLC
, 0x0c);
808 stv0900_write_reg(intp
, BCLC
, 0x1b);
809 } else if (srate
< 7000000) {
810 stv0900_write_reg(intp
, ACLC
, 0x2c);
811 stv0900_write_reg(intp
, BCLC
, 0x1c);
814 } else { /*cut 2.0 and 1.x*/
815 stv0900_write_reg(intp
, ACLC
, 0x1a);
816 stv0900_write_reg(intp
, BCLC
, 0x09);
821 static void stv0900_track_optimization(struct dvb_frontend
*fe
)
823 struct stv0900_state
*state
= fe
->demodulator_priv
;
824 struct stv0900_internal
*intp
= state
->internal
;
825 enum fe_stv0900_demod_num demod
= state
->demod
;
838 enum fe_stv0900_modcode foundModcod
;
840 dprintk("%s\n", __func__
);
842 srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
843 srate
+= stv0900_get_timing_offst(intp
, srate
, demod
);
845 switch (intp
->result
[demod
].standard
) {
846 case STV0900_DVBS1_STANDARD
:
847 case STV0900_DSS_STANDARD
:
848 dprintk("%s: found DVB-S or DSS\n", __func__
);
849 if (intp
->srch_standard
[demod
] == STV0900_AUTO_SEARCH
) {
850 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
851 stv0900_write_bits(intp
, DVBS2_ENABLE
, 0);
854 stv0900_write_bits(intp
, ROLLOFF_CONTROL
, intp
->rolloff
);
855 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 1);
857 if (intp
->chip_id
< 0x30) {
858 stv0900_write_reg(intp
, ERRCTRL1
, 0x75);
862 if (stv0900_get_vit_fec(intp
, demod
) == STV0900_FEC_1_2
) {
863 stv0900_write_reg(intp
, GAUSSR0
, 0x98);
864 stv0900_write_reg(intp
, CCIR0
, 0x18);
866 stv0900_write_reg(intp
, GAUSSR0
, 0x18);
867 stv0900_write_reg(intp
, CCIR0
, 0x18);
870 stv0900_write_reg(intp
, ERRCTRL1
, 0x75);
872 case STV0900_DVBS2_STANDARD
:
873 dprintk("%s: found DVB-S2\n", __func__
);
874 stv0900_write_bits(intp
, DVBS1_ENABLE
, 0);
875 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
876 stv0900_write_reg(intp
, ACLC
, 0);
877 stv0900_write_reg(intp
, BCLC
, 0);
878 if (intp
->result
[demod
].frame_len
== STV0900_LONG_FRAME
) {
879 foundModcod
= stv0900_get_bits(intp
, DEMOD_MODCOD
);
880 pilots
= stv0900_get_bits(intp
, DEMOD_TYPE
) & 0x01;
881 aclc
= stv0900_get_optim_carr_loop(srate
,
885 if (foundModcod
<= STV0900_QPSK_910
)
886 stv0900_write_reg(intp
, ACLC2S2Q
, aclc
);
887 else if (foundModcod
<= STV0900_8PSK_910
) {
888 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
889 stv0900_write_reg(intp
, ACLC2S28
, aclc
);
892 if ((intp
->demod_mode
== STV0900_SINGLE
) &&
893 (foundModcod
> STV0900_8PSK_910
)) {
894 if (foundModcod
<= STV0900_16APSK_910
) {
895 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
896 stv0900_write_reg(intp
, ACLC2S216A
,
898 } else if (foundModcod
<= STV0900_32APSK_910
) {
899 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
900 stv0900_write_reg(intp
, ACLC2S232A
,
906 modulation
= intp
->result
[demod
].modulation
;
907 aclc
= stv0900_get_optim_short_carr_loop(srate
,
908 modulation
, intp
->chip_id
);
909 if (modulation
== STV0900_QPSK
)
910 stv0900_write_reg(intp
, ACLC2S2Q
, aclc
);
911 else if (modulation
== STV0900_8PSK
) {
912 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
913 stv0900_write_reg(intp
, ACLC2S28
, aclc
);
914 } else if (modulation
== STV0900_16APSK
) {
915 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
916 stv0900_write_reg(intp
, ACLC2S216A
, aclc
);
917 } else if (modulation
== STV0900_32APSK
) {
918 stv0900_write_reg(intp
, ACLC2S2Q
, 0x2a);
919 stv0900_write_reg(intp
, ACLC2S232A
, aclc
);
924 if (intp
->chip_id
<= 0x11) {
925 if (intp
->demod_mode
!= STV0900_SINGLE
)
926 stv0900_activate_s2_modcod(intp
, demod
);
930 stv0900_write_reg(intp
, ERRCTRL1
, 0x67);
932 case STV0900_UNKNOWN_STANDARD
:
934 dprintk("%s: found unknown standard\n", __func__
);
935 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
936 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
940 freq1
= stv0900_read_reg(intp
, CFR2
);
941 freq0
= stv0900_read_reg(intp
, CFR1
);
942 if (intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
) {
943 stv0900_write_reg(intp
, SFRSTEP
, 0x00);
944 stv0900_write_bits(intp
, SCAN_ENABLE
, 0);
945 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
946 stv0900_write_reg(intp
, TMGCFG2
, 0xc1);
947 stv0900_set_symbol_rate(intp
, intp
->mclk
, srate
, demod
);
949 if (intp
->result
[demod
].standard
!= STV0900_DVBS2_STANDARD
)
950 stv0900_set_dvbs1_track_car_loop(intp
, demod
, srate
);
954 if (intp
->chip_id
>= 0x20) {
955 if ((intp
->srch_standard
[demod
] == STV0900_SEARCH_DVBS1
) ||
956 (intp
->srch_standard
[demod
] ==
957 STV0900_SEARCH_DSS
) ||
958 (intp
->srch_standard
[demod
] ==
959 STV0900_AUTO_SEARCH
)) {
960 stv0900_write_reg(intp
, VAVSRVIT
, 0x0a);
961 stv0900_write_reg(intp
, VITSCALE
, 0x0);
965 if (intp
->chip_id
< 0x20)
966 stv0900_write_reg(intp
, CARHDR
, 0x08);
968 if (intp
->chip_id
== 0x10)
969 stv0900_write_reg(intp
, CORRELEXP
, 0x0a);
971 stv0900_write_reg(intp
, AGC2REF
, 0x38);
973 if ((intp
->chip_id
>= 0x20) ||
974 (blind_tun_sw
== 1) ||
975 (intp
->symbol_rate
[demod
] < 10000000)) {
976 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
977 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
978 intp
->bw
[demod
] = stv0900_carrier_width(srate
,
979 intp
->rolloff
) + 10000000;
981 if ((intp
->chip_id
>= 0x20) || (blind_tun_sw
== 1)) {
982 if (intp
->srch_algo
[demod
] != STV0900_WARM_START
) {
983 if (intp
->tuner_type
[demod
] == 3)
984 stv0900_set_tuner_auto(intp
,
989 stv0900_set_bandwidth(fe
,
994 if ((intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
) ||
995 (intp
->symbol_rate
[demod
] < 10000000))
1000 stv0900_get_lock_timeout(&timed
, &timef
, srate
,
1001 STV0900_WARM_START
);
1003 if (stv0900_get_demod_lock(intp
, demod
, timed
/ 2) == FALSE
) {
1004 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
1005 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1006 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1007 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1009 while ((stv0900_get_demod_lock(intp
,
1011 timed
/ 2) == FALSE
) &&
1013 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
1014 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1015 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1016 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1023 if (intp
->chip_id
>= 0x20)
1024 stv0900_write_reg(intp
, CARFREQ
, 0x49);
1026 if ((intp
->result
[demod
].standard
== STV0900_DVBS1_STANDARD
) ||
1027 (intp
->result
[demod
].standard
== STV0900_DSS_STANDARD
))
1028 stv0900_set_viterbi_tracq(intp
, demod
);
1032 static int stv0900_get_fec_lock(struct stv0900_internal
*intp
,
1033 enum fe_stv0900_demod_num demod
, s32 time_out
)
1035 s32 timer
= 0, lock
= 0;
1037 enum fe_stv0900_search_state dmd_state
;
1039 dprintk("%s\n", __func__
);
1041 dmd_state
= stv0900_get_bits(intp
, HEADER_MODE
);
1043 while ((timer
< time_out
) && (lock
== 0)) {
1044 switch (dmd_state
) {
1045 case STV0900_SEARCH
:
1046 case STV0900_PLH_DETECTED
:
1050 case STV0900_DVBS2_FOUND
:
1051 lock
= stv0900_get_bits(intp
, PKTDELIN_LOCK
);
1053 case STV0900_DVBS_FOUND
:
1054 lock
= stv0900_get_bits(intp
, LOCKEDVIT
);
1065 dprintk("%s: DEMOD FEC LOCK OK\n", __func__
);
1067 dprintk("%s: DEMOD FEC LOCK FAIL\n", __func__
);
1072 static int stv0900_wait_for_lock(struct stv0900_internal
*intp
,
1073 enum fe_stv0900_demod_num demod
,
1074 s32 dmd_timeout
, s32 fec_timeout
)
1077 s32 timer
= 0, lock
= 0;
1079 dprintk("%s\n", __func__
);
1081 lock
= stv0900_get_demod_lock(intp
, demod
, dmd_timeout
);
1084 lock
= stv0900_get_fec_lock(intp
, demod
, fec_timeout
);
1089 dprintk("%s: Timer = %d, time_out = %d\n",
1090 __func__
, timer
, fec_timeout
);
1092 while ((timer
< fec_timeout
) && (lock
== 0)) {
1093 lock
= stv0900_get_bits(intp
, TSFIFO_LINEOK
);
1100 dprintk("%s: DEMOD LOCK OK\n", __func__
);
1102 dprintk("%s: DEMOD LOCK FAIL\n", __func__
);
1110 enum fe_stv0900_tracking_standard
stv0900_get_standard(struct dvb_frontend
*fe
,
1111 enum fe_stv0900_demod_num demod
)
1113 struct stv0900_state
*state
= fe
->demodulator_priv
;
1114 struct stv0900_internal
*intp
= state
->internal
;
1115 enum fe_stv0900_tracking_standard fnd_standard
;
1117 int hdr_mode
= stv0900_get_bits(intp
, HEADER_MODE
);
1121 fnd_standard
= STV0900_DVBS2_STANDARD
;
1124 if (stv0900_get_bits(intp
, DSS_DVB
) == 1)
1125 fnd_standard
= STV0900_DSS_STANDARD
;
1127 fnd_standard
= STV0900_DVBS1_STANDARD
;
1131 fnd_standard
= STV0900_UNKNOWN_STANDARD
;
1134 dprintk("%s: standard %d\n", __func__
, fnd_standard
);
1136 return fnd_standard
;
1139 static s32
stv0900_get_carr_freq(struct stv0900_internal
*intp
, u32 mclk
,
1140 enum fe_stv0900_demod_num demod
)
1148 derot
= (stv0900_get_bits(intp
, CAR_FREQ2
) << 16) +
1149 (stv0900_get_bits(intp
, CAR_FREQ1
) << 8) +
1150 (stv0900_get_bits(intp
, CAR_FREQ0
));
1152 derot
= ge2comp(derot
, 24);
1153 intval1
= mclk
>> 12;
1154 intval2
= derot
>> 12;
1155 rem1
= mclk
% 0x1000;
1156 rem2
= derot
% 0x1000;
1157 derot
= (intval1
* intval2
) +
1158 ((intval1
* rem2
) >> 12) +
1159 ((intval2
* rem1
) >> 12);
1164 static u32
stv0900_get_tuner_freq(struct dvb_frontend
*fe
)
1166 struct dvb_frontend_ops
*frontend_ops
= NULL
;
1167 struct dvb_tuner_ops
*tuner_ops
= NULL
;
1170 frontend_ops
= &fe
->ops
;
1171 tuner_ops
= &frontend_ops
->tuner_ops
;
1173 if (tuner_ops
->get_frequency
) {
1174 if ((tuner_ops
->get_frequency(fe
, &freq
)) < 0)
1175 dprintk("%s: Invalid parameter\n", __func__
);
1177 dprintk("%s: Frequency=%d\n", __func__
, freq
);
1185 fe_stv0900_signal_type
stv0900_get_signal_params(struct dvb_frontend
*fe
)
1187 struct stv0900_state
*state
= fe
->demodulator_priv
;
1188 struct stv0900_internal
*intp
= state
->internal
;
1189 enum fe_stv0900_demod_num demod
= state
->demod
;
1190 enum fe_stv0900_signal_type range
= STV0900_OUTOFRANGE
;
1191 struct stv0900_signal_info
*result
= &intp
->result
[demod
];
1200 if (intp
->srch_algo
[d
] == STV0900_BLIND_SEARCH
) {
1201 timing
= stv0900_read_reg(intp
, TMGREG2
);
1203 stv0900_write_reg(intp
, SFRSTEP
, 0x5c);
1205 while ((i
<= 50) && (timing
!= 0) && (timing
!= 0xff)) {
1206 timing
= stv0900_read_reg(intp
, TMGREG2
);
1212 result
->standard
= stv0900_get_standard(fe
, d
);
1213 if (intp
->tuner_type
[demod
] == 3)
1214 result
->frequency
= stv0900_get_freq_auto(intp
, d
);
1216 result
->frequency
= stv0900_get_tuner_freq(fe
);
1218 offsetFreq
= stv0900_get_carr_freq(intp
, intp
->mclk
, d
) / 1000;
1219 result
->frequency
+= offsetFreq
;
1220 result
->symbol_rate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, d
);
1221 srate_offset
= stv0900_get_timing_offst(intp
, result
->symbol_rate
, d
);
1222 result
->symbol_rate
+= srate_offset
;
1223 result
->fec
= stv0900_get_vit_fec(intp
, d
);
1224 result
->modcode
= stv0900_get_bits(intp
, DEMOD_MODCOD
);
1225 result
->pilot
= stv0900_get_bits(intp
, DEMOD_TYPE
) & 0x01;
1226 result
->frame_len
= ((u32
)stv0900_get_bits(intp
, DEMOD_TYPE
)) >> 1;
1227 result
->rolloff
= stv0900_get_bits(intp
, ROLLOFF_STATUS
);
1229 dprintk("%s: modcode=0x%x \n", __func__
, result
->modcode
);
1231 switch (result
->standard
) {
1232 case STV0900_DVBS2_STANDARD
:
1233 result
->spectrum
= stv0900_get_bits(intp
, SPECINV_DEMOD
);
1234 if (result
->modcode
<= STV0900_QPSK_910
)
1235 result
->modulation
= STV0900_QPSK
;
1236 else if (result
->modcode
<= STV0900_8PSK_910
)
1237 result
->modulation
= STV0900_8PSK
;
1238 else if (result
->modcode
<= STV0900_16APSK_910
)
1239 result
->modulation
= STV0900_16APSK
;
1240 else if (result
->modcode
<= STV0900_32APSK_910
)
1241 result
->modulation
= STV0900_32APSK
;
1243 result
->modulation
= STV0900_UNKNOWN
;
1245 case STV0900_DVBS1_STANDARD
:
1246 case STV0900_DSS_STANDARD
:
1247 result
->spectrum
= stv0900_get_bits(intp
, IQINV
);
1248 result
->modulation
= STV0900_QPSK
;
1254 if ((intp
->srch_algo
[d
] == STV0900_BLIND_SEARCH
) ||
1255 (intp
->symbol_rate
[d
] < 10000000)) {
1256 offsetFreq
= result
->frequency
- intp
->freq
[d
];
1257 if (intp
->tuner_type
[demod
] == 3)
1258 intp
->freq
[d
] = stv0900_get_freq_auto(intp
, d
);
1260 intp
->freq
[d
] = stv0900_get_tuner_freq(fe
);
1262 if (ABS(offsetFreq
) <= ((intp
->srch_range
[d
] / 2000) + 500))
1263 range
= STV0900_RANGEOK
;
1264 else if (ABS(offsetFreq
) <=
1265 (stv0900_carrier_width(result
->symbol_rate
,
1266 result
->rolloff
) / 2000))
1267 range
= STV0900_RANGEOK
;
1269 } else if (ABS(offsetFreq
) <= ((intp
->srch_range
[d
] / 2000) + 500))
1270 range
= STV0900_RANGEOK
;
1272 dprintk("%s: range %d\n", __func__
, range
);
1278 fe_stv0900_signal_type
stv0900_dvbs1_acq_workaround(struct dvb_frontend
*fe
)
1280 struct stv0900_state
*state
= fe
->demodulator_priv
;
1281 struct stv0900_internal
*intp
= state
->internal
;
1282 enum fe_stv0900_demod_num demod
= state
->demod
;
1283 enum fe_stv0900_signal_type signal_type
= STV0900_NODATA
;
1291 intp
->result
[demod
].locked
= FALSE
;
1293 if (stv0900_get_bits(intp
, HEADER_MODE
) == STV0900_DVBS_FOUND
) {
1294 srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1295 srate
+= stv0900_get_timing_offst(intp
, srate
, demod
);
1296 if (intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
)
1297 stv0900_set_symbol_rate(intp
, intp
->mclk
, srate
, demod
);
1299 stv0900_get_lock_timeout(&demod_timeout
, &fec_timeout
,
1300 srate
, STV0900_WARM_START
);
1301 freq1
= stv0900_read_reg(intp
, CFR2
);
1302 freq0
= stv0900_read_reg(intp
, CFR1
);
1303 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
1304 stv0900_write_bits(intp
, SPECINV_CONTROL
,
1305 STV0900_IQ_FORCE_SWAPPED
);
1306 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
1307 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1308 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1309 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1310 if (stv0900_wait_for_lock(intp
, demod
,
1311 demod_timeout
, fec_timeout
) == TRUE
) {
1312 intp
->result
[demod
].locked
= TRUE
;
1313 signal_type
= stv0900_get_signal_params(fe
);
1314 stv0900_track_optimization(fe
);
1316 stv0900_write_bits(intp
, SPECINV_CONTROL
,
1317 STV0900_IQ_FORCE_NORMAL
);
1318 stv0900_write_reg(intp
, DMDISTATE
, 0x1c);
1319 stv0900_write_reg(intp
, CFRINIT1
, freq1
);
1320 stv0900_write_reg(intp
, CFRINIT0
, freq0
);
1321 stv0900_write_reg(intp
, DMDISTATE
, 0x18);
1322 if (stv0900_wait_for_lock(intp
, demod
,
1323 demod_timeout
, fec_timeout
) == TRUE
) {
1324 intp
->result
[demod
].locked
= TRUE
;
1325 signal_type
= stv0900_get_signal_params(fe
);
1326 stv0900_track_optimization(fe
);
1332 intp
->result
[demod
].locked
= FALSE
;
1337 static u16
stv0900_blind_check_agc2_min_level(struct stv0900_internal
*intp
,
1338 enum fe_stv0900_demod_num demod
)
1340 u32 minagc2level
= 0xffff,
1342 init_freq
, freq_step
;
1344 s32 i
, j
, nb_steps
, direction
;
1346 dprintk("%s\n", __func__
);
1348 stv0900_write_reg(intp
, AGC2REF
, 0x38);
1349 stv0900_write_bits(intp
, SCAN_ENABLE
, 0);
1350 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
1352 stv0900_write_bits(intp
, AUTO_GUP
, 1);
1353 stv0900_write_bits(intp
, AUTO_GLOW
, 1);
1355 stv0900_write_reg(intp
, DMDT0M
, 0x0);
1357 stv0900_set_symbol_rate(intp
, intp
->mclk
, 1000000, demod
);
1358 nb_steps
= -1 + (intp
->srch_range
[demod
] / 1000000);
1360 nb_steps
= (2 * nb_steps
) + 1;
1367 freq_step
= (1000000 << 8) / (intp
->mclk
>> 8);
1371 for (i
= 0; i
< nb_steps
; i
++) {
1373 init_freq
= init_freq
+ (freq_step
* i
);
1375 init_freq
= init_freq
- (freq_step
* i
);
1378 stv0900_write_reg(intp
, DMDISTATE
, 0x5C);
1379 stv0900_write_reg(intp
, CFRINIT1
, (init_freq
>> 8) & 0xff);
1380 stv0900_write_reg(intp
, CFRINIT0
, init_freq
& 0xff);
1381 stv0900_write_reg(intp
, DMDISTATE
, 0x58);
1385 for (j
= 0; j
< 10; j
++)
1386 agc2level
+= (stv0900_read_reg(intp
, AGC2I1
) << 8)
1387 | stv0900_read_reg(intp
, AGC2I0
);
1391 if (agc2level
< minagc2level
)
1392 minagc2level
= agc2level
;
1396 return (u16
)minagc2level
;
1399 static u32
stv0900_search_srate_coarse(struct dvb_frontend
*fe
)
1401 struct stv0900_state
*state
= fe
->demodulator_priv
;
1402 struct stv0900_internal
*intp
= state
->internal
;
1403 enum fe_stv0900_demod_num demod
= state
->demod
;
1404 int timing_lck
= FALSE
;
1405 s32 i
, timingcpt
= 0,
1413 currier_step
= 1200;
1415 if (intp
->chip_id
>= 0x30)
1420 stv0900_write_bits(intp
, DEMOD_MODE
, 0x1f);
1421 stv0900_write_reg(intp
, TMGCFG
, 0x12);
1422 stv0900_write_reg(intp
, TMGTHRISE
, 0xf0);
1423 stv0900_write_reg(intp
, TMGTHFALL
, 0xe0);
1424 stv0900_write_bits(intp
, SCAN_ENABLE
, 1);
1425 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 1);
1426 stv0900_write_reg(intp
, SFRUP1
, 0x83);
1427 stv0900_write_reg(intp
, SFRUP0
, 0xc0);
1428 stv0900_write_reg(intp
, SFRLOW1
, 0x82);
1429 stv0900_write_reg(intp
, SFRLOW0
, 0xa0);
1430 stv0900_write_reg(intp
, DMDT0M
, 0x0);
1431 stv0900_write_reg(intp
, AGC2REF
, 0x50);
1433 if (intp
->chip_id
>= 0x30) {
1434 stv0900_write_reg(intp
, CARFREQ
, 0x99);
1435 stv0900_write_reg(intp
, SFRSTEP
, 0x98);
1436 } else if (intp
->chip_id
>= 0x20) {
1437 stv0900_write_reg(intp
, CARFREQ
, 0x6a);
1438 stv0900_write_reg(intp
, SFRSTEP
, 0x95);
1440 stv0900_write_reg(intp
, CARFREQ
, 0xed);
1441 stv0900_write_reg(intp
, SFRSTEP
, 0x73);
1444 if (intp
->symbol_rate
[demod
] <= 2000000)
1445 currier_step
= 1000;
1446 else if (intp
->symbol_rate
[demod
] <= 5000000)
1447 currier_step
= 2000;
1448 else if (intp
->symbol_rate
[demod
] <= 12000000)
1449 currier_step
= 3000;
1451 currier_step
= 5000;
1453 nb_steps
= -1 + ((intp
->srch_range
[demod
] / 1000) / currier_step
);
1455 nb_steps
= (2 * nb_steps
) + 1;
1459 else if (nb_steps
> 10) {
1461 currier_step
= (intp
->srch_range
[demod
] / 1000) / 10;
1467 tuner_freq
= intp
->freq
[demod
];
1469 while ((timing_lck
== FALSE
) && (current_step
< nb_steps
)) {
1470 stv0900_write_reg(intp
, DMDISTATE
, 0x5f);
1471 stv0900_write_bits(intp
, DEMOD_MODE
, 0);
1475 for (i
= 0; i
< 10; i
++) {
1476 if (stv0900_get_bits(intp
, TMGLOCK_QUALITY
) >= 2)
1479 agc2_integr
+= (stv0900_read_reg(intp
, AGC2I1
) << 8) |
1480 stv0900_read_reg(intp
, AGC2I0
);
1484 coarse_srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1488 dprintk("lock: I2C_DEMOD_MODE_FIELD =0. Search started. tuner freq=%d agc2=0x%x srate_coarse=%d tmg_cpt=%d\n",
1489 tuner_freq
, agc2_integr
, coarse_srate
, timingcpt
);
1491 if ((timingcpt
>= 5) &&
1492 (agc2_integr
< agc2_th
) &&
1493 (coarse_srate
< 55000000) &&
1494 (coarse_srate
> 850000))
1496 else if (current_step
< nb_steps
) {
1498 tuner_freq
+= (current_step
* currier_step
);
1500 tuner_freq
-= (current_step
* currier_step
);
1502 if (intp
->tuner_type
[demod
] == 3)
1503 stv0900_set_tuner_auto(intp
, tuner_freq
,
1504 intp
->bw
[demod
], demod
);
1506 stv0900_set_tuner(fe
, tuner_freq
,
1511 if (timing_lck
== FALSE
)
1514 coarse_srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1516 return coarse_srate
;
1519 static u32
stv0900_search_srate_fine(struct dvb_frontend
*fe
)
1521 struct stv0900_state
*state
= fe
->demodulator_priv
;
1522 struct stv0900_internal
*intp
= state
->internal
;
1523 enum fe_stv0900_demod_num demod
= state
->demod
;
1531 coarse_srate
= stv0900_get_symbol_rate(intp
, intp
->mclk
, demod
);
1533 if (coarse_srate
> 3000000) {
1534 symbmax
= 13 * (coarse_srate
/ 10);
1535 symbmax
= (symbmax
/ 1000) * 65536;
1536 symbmax
/= (intp
->mclk
/ 1000);
1538 symbmin
= 10 * (coarse_srate
/ 13);
1539 symbmin
= (symbmin
/ 1000)*65536;
1540 symbmin
/= (intp
->mclk
/ 1000);
1542 symb
= (coarse_srate
/ 1000) * 65536;
1543 symb
/= (intp
->mclk
/ 1000);
1545 symbmax
= 13 * (coarse_srate
/ 10);
1546 symbmax
= (symbmax
/ 100) * 65536;
1547 symbmax
/= (intp
->mclk
/ 100);
1549 symbmin
= 10 * (coarse_srate
/ 14);
1550 symbmin
= (symbmin
/ 100) * 65536;
1551 symbmin
/= (intp
->mclk
/ 100);
1553 symb
= (coarse_srate
/ 100) * 65536;
1554 symb
/= (intp
->mclk
/ 100);
1557 symbcomp
= 13 * (coarse_srate
/ 10);
1558 coarse_freq
= (stv0900_read_reg(intp
, CFR2
) << 8)
1559 | stv0900_read_reg(intp
, CFR1
);
1561 if (symbcomp
< intp
->symbol_rate
[demod
])
1564 stv0900_write_reg(intp
, DMDISTATE
, 0x1f);
1565 stv0900_write_reg(intp
, TMGCFG2
, 0xc1);
1566 stv0900_write_reg(intp
, TMGTHRISE
, 0x20);
1567 stv0900_write_reg(intp
, TMGTHFALL
, 0x00);
1568 stv0900_write_reg(intp
, TMGCFG
, 0xd2);
1569 stv0900_write_bits(intp
, CFR_AUTOSCAN
, 0);
1570 stv0900_write_reg(intp
, AGC2REF
, 0x38);
1572 if (intp
->chip_id
>= 0x30)
1573 stv0900_write_reg(intp
, CARFREQ
, 0x79);
1574 else if (intp
->chip_id
>= 0x20)
1575 stv0900_write_reg(intp
, CARFREQ
, 0x49);
1577 stv0900_write_reg(intp
, CARFREQ
, 0xed);
1579 stv0900_write_reg(intp
, SFRUP1
, (symbmax
>> 8) & 0x7f);
1580 stv0900_write_reg(intp
, SFRUP0
, (symbmax
& 0xff));
1582 stv0900_write_reg(intp
, SFRLOW1
, (symbmin
>> 8) & 0x7f);
1583 stv0900_write_reg(intp
, SFRLOW0
, (symbmin
& 0xff));
1585 stv0900_write_reg(intp
, SFRINIT1
, (symb
>> 8) & 0xff);
1586 stv0900_write_reg(intp
, SFRINIT0
, (symb
& 0xff));
1588 stv0900_write_reg(intp
, DMDT0M
, 0x20);
1589 stv0900_write_reg(intp
, CFRINIT1
, (coarse_freq
>> 8) & 0xff);
1590 stv0900_write_reg(intp
, CFRINIT0
, coarse_freq
& 0xff);
1591 stv0900_write_reg(intp
, DMDISTATE
, 0x15);
1594 return coarse_srate
;
1597 static int stv0900_blind_search_algo(struct dvb_frontend
*fe
)
1599 struct stv0900_state
*state
= fe
->demodulator_priv
;
1600 struct stv0900_internal
*intp
= state
->internal
;
1601 enum fe_stv0900_demod_num demod
= state
->demod
;
1608 coarse_fail
= FALSE
;
1609 s32 demod_timeout
= 500,
1617 dprintk("%s\n", __func__
);
1619 if (intp
->chip_id
< 0x20) {
1620 k_ref_tmg_max
= 233;
1621 k_ref_tmg_min
= 143;
1623 k_ref_tmg_max
= 110;
1627 if (intp
->chip_id
<= 0x20)
1628 agc2_th
= STV0900_BLIND_SEARCH_AGC2_TH
;
1630 agc2_th
= STV0900_BLIND_SEARCH_AGC2_TH_CUT30
;
1632 agc2_int
= stv0900_blind_check_agc2_min_level(intp
, demod
);
1634 dprintk("%s agc2_int=%d agc2_th=%d \n", __func__
, agc2_int
, agc2_th
);
1635 if (agc2_int
> agc2_th
)
1638 if (intp
->chip_id
== 0x10)
1639 stv0900_write_reg(intp
, CORRELEXP
, 0xaa);
1641 if (intp
->chip_id
< 0x20)
1642 stv0900_write_reg(intp
, CARHDR
, 0x55);
1644 stv0900_write_reg(intp
, CARHDR
, 0x20);
1646 if (intp
->chip_id
<= 0x20)
1647 stv0900_write_reg(intp
, CARCFG
, 0xc4);
1649 stv0900_write_reg(intp
, CARCFG
, 0x6);
1651 stv0900_write_reg(intp
, RTCS2
, 0x44);
1653 if (intp
->chip_id
>= 0x20) {
1654 stv0900_write_reg(intp
, EQUALCFG
, 0x41);
1655 stv0900_write_reg(intp
, FFECFG
, 0x41);
1656 stv0900_write_reg(intp
, VITSCALE
, 0x82);
1657 stv0900_write_reg(intp
, VAVSRVIT
, 0x0);
1660 k_ref_tmg
= k_ref_tmg_max
;
1663 stv0900_write_reg(intp
, KREFTMG
, k_ref_tmg
);
1664 if (stv0900_search_srate_coarse(fe
) != 0) {
1665 coarse_srate
= stv0900_search_srate_fine(fe
);
1667 if (coarse_srate
!= 0) {
1668 stv0900_get_lock_timeout(&demod_timeout
,
1671 STV0900_BLIND_SEARCH
);
1672 lock
= stv0900_get_demod_lock(intp
,
1681 for (i
= 0; i
< 10; i
++) {
1682 agc2_int
= (stv0900_read_reg(intp
, AGC2I1
) << 8)
1683 | stv0900_read_reg(intp
, AGC2I0
);
1685 if (agc2_int
>= 0xff00)
1688 dstatus2
= stv0900_read_reg(intp
, DSTATUS2
);
1690 if (((dstatus2
& 0x1) == 0x1) &&
1691 ((dstatus2
>> 7) == 1))
1695 if ((fail_cpt
> 7) || (agc2_overflow
> 7))
1701 } while ((k_ref_tmg
>= k_ref_tmg_min
) &&
1703 (coarse_fail
== FALSE
));
1708 static void stv0900_set_viterbi_acq(struct stv0900_internal
*intp
,
1709 enum fe_stv0900_demod_num demod
)
1711 s32 vth_reg
= VTH12
;
1713 dprintk("%s\n", __func__
);
1715 stv0900_write_reg(intp
, vth_reg
++, 0x96);
1716 stv0900_write_reg(intp
, vth_reg
++, 0x64);
1717 stv0900_write_reg(intp
, vth_reg
++, 0x36);
1718 stv0900_write_reg(intp
, vth_reg
++, 0x23);
1719 stv0900_write_reg(intp
, vth_reg
++, 0x1e);
1720 stv0900_write_reg(intp
, vth_reg
++, 0x19);
1723 static void stv0900_set_search_standard(struct stv0900_internal
*intp
,
1724 enum fe_stv0900_demod_num demod
)
1727 dprintk("%s\n", __func__
);
1729 switch (intp
->srch_standard
[demod
]) {
1730 case STV0900_SEARCH_DVBS1
:
1731 dprintk("Search Standard = DVBS1\n");
1733 case STV0900_SEARCH_DSS
:
1734 dprintk("Search Standard = DSS\n");
1736 case STV0900_SEARCH_DVBS2
:
1737 dprintk("Search Standard = DVBS2\n");
1739 case STV0900_AUTO_SEARCH
:
1741 dprintk("Search Standard = AUTO\n");
1745 switch (intp
->srch_standard
[demod
]) {
1746 case STV0900_SEARCH_DVBS1
:
1747 case STV0900_SEARCH_DSS
:
1748 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
1749 stv0900_write_bits(intp
, DVBS2_ENABLE
, 0);
1750 stv0900_write_bits(intp
, STOP_CLKVIT
, 0);
1751 stv0900_set_dvbs1_track_car_loop(intp
,
1753 intp
->symbol_rate
[demod
]);
1754 stv0900_write_reg(intp
, CAR2CFG
, 0x22);
1756 stv0900_set_viterbi_acq(intp
, demod
);
1757 stv0900_set_viterbi_standard(intp
,
1758 intp
->srch_standard
[demod
],
1759 intp
->fec
[demod
], demod
);
1762 case STV0900_SEARCH_DVBS2
:
1763 stv0900_write_bits(intp
, DVBS1_ENABLE
, 0);
1764 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
1765 stv0900_write_bits(intp
, STOP_CLKVIT
, 1);
1766 stv0900_write_reg(intp
, ACLC
, 0x1a);
1767 stv0900_write_reg(intp
, BCLC
, 0x09);
1768 if (intp
->chip_id
<= 0x20) /*cut 1.x and 2.0*/
1769 stv0900_write_reg(intp
, CAR2CFG
, 0x26);
1771 stv0900_write_reg(intp
, CAR2CFG
, 0x66);
1773 if (intp
->demod_mode
!= STV0900_SINGLE
) {
1774 if (intp
->chip_id
<= 0x11)
1775 stv0900_stop_all_s2_modcod(intp
, demod
);
1777 stv0900_activate_s2_modcod(intp
, demod
);
1780 stv0900_activate_s2_modcod_single(intp
, demod
);
1782 stv0900_set_viterbi_tracq(intp
, demod
);
1785 case STV0900_AUTO_SEARCH
:
1787 stv0900_write_bits(intp
, DVBS1_ENABLE
, 1);
1788 stv0900_write_bits(intp
, DVBS2_ENABLE
, 1);
1789 stv0900_write_bits(intp
, STOP_CLKVIT
, 0);
1790 stv0900_write_reg(intp
, ACLC
, 0x1a);
1791 stv0900_write_reg(intp
, BCLC
, 0x09);
1792 stv0900_set_dvbs1_track_car_loop(intp
,
1794 intp
->symbol_rate
[demod
]);
1795 if (intp
->chip_id
<= 0x20) /*cut 1.x and 2.0*/
1796 stv0900_write_reg(intp
, CAR2CFG
, 0x26);
1798 stv0900_write_reg(intp
, CAR2CFG
, 0x66);
1800 if (intp
->demod_mode
!= STV0900_SINGLE
) {
1801 if (intp
->chip_id
<= 0x11)
1802 stv0900_stop_all_s2_modcod(intp
, demod
);
1804 stv0900_activate_s2_modcod(intp
, demod
);
1807 stv0900_activate_s2_modcod_single(intp
, demod
);
1809 stv0900_set_viterbi_tracq(intp
, demod
);
1810 stv0900_set_viterbi_standard(intp
,
1811 intp
->srch_standard
[demod
],
1812 intp
->fec
[demod
], demod
);
1818 enum fe_stv0900_signal_type
stv0900_algo(struct dvb_frontend
*fe
)
1820 struct stv0900_state
*state
= fe
->demodulator_priv
;
1821 struct stv0900_internal
*intp
= state
->internal
;
1822 enum fe_stv0900_demod_num demod
= state
->demod
;
1824 s32 demod_timeout
= 500, fec_timeout
= 50;
1825 s32 aq_power
, agc1_power
, i
;
1827 int lock
= FALSE
, low_sr
= FALSE
;
1829 enum fe_stv0900_signal_type signal_type
= STV0900_NOCARRIER
;
1830 enum fe_stv0900_search_algo algo
;
1831 int no_signal
= FALSE
;
1833 dprintk("%s\n", __func__
);
1835 algo
= intp
->srch_algo
[demod
];
1836 stv0900_write_bits(intp
, RST_HWARE
, 1);
1837 stv0900_write_reg(intp
, DMDISTATE
, 0x5c);
1838 if (intp
->chip_id
>= 0x20) {
1839 if (intp
->symbol_rate
[demod
] > 5000000)
1840 stv0900_write_reg(intp
, CORRELABS
, 0x9e);
1842 stv0900_write_reg(intp
, CORRELABS
, 0x82);
1844 stv0900_write_reg(intp
, CORRELABS
, 0x88);
1846 stv0900_get_lock_timeout(&demod_timeout
, &fec_timeout
,
1847 intp
->symbol_rate
[demod
],
1848 intp
->srch_algo
[demod
]);
1850 if (intp
->srch_algo
[demod
] == STV0900_BLIND_SEARCH
) {
1851 intp
->bw
[demod
] = 2 * 36000000;
1853 stv0900_write_reg(intp
, TMGCFG2
, 0xc0);
1854 stv0900_write_reg(intp
, CORRELMANT
, 0x70);
1856 stv0900_set_symbol_rate(intp
, intp
->mclk
, 1000000, demod
);
1858 stv0900_write_reg(intp
, DMDT0M
, 0x20);
1859 stv0900_write_reg(intp
, TMGCFG
, 0xd2);
1861 if (intp
->symbol_rate
[demod
] < 2000000)
1862 stv0900_write_reg(intp
, CORRELMANT
, 0x63);
1864 stv0900_write_reg(intp
, CORRELMANT
, 0x70);
1866 stv0900_write_reg(intp
, AGC2REF
, 0x38);
1869 stv0900_carrier_width(intp
->symbol_rate
[demod
],
1871 if (intp
->chip_id
>= 0x20) {
1872 stv0900_write_reg(intp
, KREFTMG
, 0x5a);
1874 if (intp
->srch_algo
[demod
] == STV0900_COLD_START
) {
1875 intp
->bw
[demod
] += 10000000;
1876 intp
->bw
[demod
] *= 15;
1877 intp
->bw
[demod
] /= 10;
1878 } else if (intp
->srch_algo
[demod
] == STV0900_WARM_START
)
1879 intp
->bw
[demod
] += 10000000;
1882 stv0900_write_reg(intp
, KREFTMG
, 0xc1);
1883 intp
->bw
[demod
] += 10000000;
1884 intp
->bw
[demod
] *= 15;
1885 intp
->bw
[demod
] /= 10;
1888 stv0900_write_reg(intp
, TMGCFG2
, 0xc1);
1890 stv0900_set_symbol_rate(intp
, intp
->mclk
,
1891 intp
->symbol_rate
[demod
], demod
);
1892 stv0900_set_max_symbol_rate(intp
, intp
->mclk
,
1893 intp
->symbol_rate
[demod
], demod
);
1894 stv0900_set_min_symbol_rate(intp
, intp
->mclk
,
1895 intp
->symbol_rate
[demod
], demod
);
1896 if (intp
->symbol_rate
[demod
] >= 10000000)
1903 if (intp
->tuner_type
[demod
] == 3)
1904 stv0900_set_tuner_auto(intp
, intp
->freq
[demod
],
1905 intp
->bw
[demod
], demod
);
1907 stv0900_set_tuner(fe
, intp
->freq
[demod
], intp
->bw
[demod
]);
1909 agc1_power
= MAKEWORD(stv0900_get_bits(intp
, AGCIQ_VALUE1
),
1910 stv0900_get_bits(intp
, AGCIQ_VALUE0
));
1914 if (agc1_power
== 0) {
1915 for (i
= 0; i
< 5; i
++)
1916 aq_power
+= (stv0900_get_bits(intp
, POWER_I
) +
1917 stv0900_get_bits(intp
, POWER_Q
)) / 2;
1922 if ((agc1_power
== 0) && (aq_power
< IQPOWER_THRESHOLD
)) {
1923 intp
->result
[demod
].locked
= FALSE
;
1924 signal_type
= STV0900_NOAGC1
;
1925 dprintk("%s: NO AGC1, POWERI, POWERQ\n", __func__
);
1927 stv0900_write_bits(intp
, SPECINV_CONTROL
,
1928 intp
->srch_iq_inv
[demod
]);
1929 if (intp
->chip_id
<= 0x20) /*cut 2.0*/
1930 stv0900_write_bits(intp
, MANUALSX_ROLLOFF
, 1);
1932 stv0900_write_bits(intp
, MANUALS2_ROLLOFF
, 1);
1934 stv0900_set_search_standard(intp
, demod
);
1936 if (intp
->srch_algo
[demod
] != STV0900_BLIND_SEARCH
)
1937 stv0900_start_search(intp
, demod
);
1940 if (signal_type
== STV0900_NOAGC1
)
1943 if (intp
->chip_id
== 0x12) {
1944 stv0900_write_bits(intp
, RST_HWARE
, 0);
1946 stv0900_write_bits(intp
, RST_HWARE
, 1);
1947 stv0900_write_bits(intp
, RST_HWARE
, 0);
1950 if (algo
== STV0900_BLIND_SEARCH
)
1951 lock
= stv0900_blind_search_algo(fe
);
1952 else if (algo
== STV0900_COLD_START
)
1953 lock
= stv0900_get_demod_cold_lock(fe
, demod_timeout
);
1954 else if (algo
== STV0900_WARM_START
)
1955 lock
= stv0900_get_demod_lock(intp
, demod
, demod_timeout
);
1957 if ((lock
== FALSE
) && (algo
== STV0900_COLD_START
)) {
1958 if (low_sr
== FALSE
) {
1959 if (stv0900_check_timing_lock(intp
, demod
) == TRUE
)
1960 lock
= stv0900_sw_algo(intp
, demod
);
1965 signal_type
= stv0900_get_signal_params(fe
);
1967 if ((lock
== TRUE
) && (signal_type
== STV0900_RANGEOK
)) {
1968 stv0900_track_optimization(fe
);
1969 if (intp
->chip_id
<= 0x11) {
1970 if ((stv0900_get_standard(fe
, 0) ==
1971 STV0900_DVBS1_STANDARD
) &&
1972 (stv0900_get_standard(fe
, 1) ==
1973 STV0900_DVBS1_STANDARD
)) {
1975 stv0900_write_bits(intp
, RST_HWARE
, 0);
1977 stv0900_write_bits(intp
, RST_HWARE
, 0);
1979 stv0900_write_bits(intp
, RST_HWARE
, 1);
1980 stv0900_write_bits(intp
, RST_HWARE
, 0);
1983 } else if (intp
->chip_id
>= 0x20) {
1984 stv0900_write_bits(intp
, RST_HWARE
, 0);
1986 stv0900_write_bits(intp
, RST_HWARE
, 1);
1987 stv0900_write_bits(intp
, RST_HWARE
, 0);
1990 if (stv0900_wait_for_lock(intp
, demod
,
1991 fec_timeout
, fec_timeout
) == TRUE
) {
1993 intp
->result
[demod
].locked
= TRUE
;
1994 if (intp
->result
[demod
].standard
==
1995 STV0900_DVBS2_STANDARD
) {
1996 stv0900_set_dvbs2_rolloff(intp
, demod
);
1997 stv0900_write_bits(intp
, RESET_UPKO_COUNT
, 1);
1998 stv0900_write_bits(intp
, RESET_UPKO_COUNT
, 0);
1999 stv0900_write_reg(intp
, ERRCTRL1
, 0x67);
2001 stv0900_write_reg(intp
, ERRCTRL1
, 0x75);
2004 stv0900_write_reg(intp
, FBERCPT4
, 0);
2005 stv0900_write_reg(intp
, ERRCTRL2
, 0xc1);
2008 signal_type
= STV0900_NODATA
;
2009 no_signal
= stv0900_check_signal_presence(intp
, demod
);
2011 intp
->result
[demod
].locked
= FALSE
;
2015 if ((signal_type
!= STV0900_NODATA
) || (no_signal
!= FALSE
))
2018 if (intp
->chip_id
> 0x11) {
2019 intp
->result
[demod
].locked
= FALSE
;
2023 if ((stv0900_get_bits(intp
, HEADER_MODE
) == STV0900_DVBS_FOUND
) &&
2024 (intp
->srch_iq_inv
[demod
] <= STV0900_IQ_AUTO_NORMAL_FIRST
))
2025 signal_type
= stv0900_dvbs1_acq_workaround(fe
);