45 int no_signal =
FALSE;
49 carr_offset =
ge2comp(carr_offset, 16);
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)))
69 s32 *frequency_inc,
s32 *sw_timeout,
73 s32 timeout, freq_inc, max_steps, srate, max_carrier;
79 max_carrier += max_carrier / 10;
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;
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;
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;
173 if (zigzag ==
TRUE) {
175 freqOffset = -freqOffset - 2 * FreqIncr;
177 freqOffset = -freqOffset;
179 freqOffset += + 2 * FreqIncr;
185 }
while ((lock ==
FALSE)
186 && (no_signal ==
FALSE)
187 && ((freqOffset - FreqIncr) < max_carrier)
188 && ((freqOffset + FreqIncr) > -max_carrier)
189 && (stepCpt < MaxStep));
208 stv0900_get_sw_loop_params(intp, &fqc_inc, &sft_stp_tout,
248 lock = stv0900_search_carr_sw_loop(intp,
257 || (no_signal ==
TRUE)
258 || (trial_cntr == 2)) {
283 if (trial_cntr < 2) {
301 }
while ((lock ==
FALSE)
303 && (no_signal ==
FALSE));
312 s32 rem1, rem2, intval1, intval2, srate;
318 dprintk(
"lock: srate=%d r0=0x%x r1=0x%x r2=0x%x r3=0x%x \n",
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);
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);
366 srate = 105 * (srate / 100);
368 if (srate > 60000000) {
370 symb /= (mclk >> 12);
371 }
else if (srate > 6000000) {
373 symb /= (mclk >> 10);
394 srate = 95 * (srate / 100);
395 if (srate > 60000000) {
397 symb /= (mclk >> 12);
399 }
else if (srate > 6000000) {
401 symb /= (mclk >> 10);
423 timingoffset =
ge2comp(timingoffset, 24);
426 if (timingoffset == 0)
429 timingoffset = ((
s32)srate * 10) / ((
s32)0x1000000 / timingoffset);
444 }
else if (intp->
chip_id <= 0x20)
467 return srate + (srate * rolloff) / 100;
473 int timingLock =
FALSE;
495 for (i = 0; i < 10; i++) {
515 static int stv0900_get_demod_cold_lock(
struct dvb_frontend *fe,
537 if (srate >= 10000000)
538 locktimeout = demod_timeout / 3;
540 locktimeout = demod_timeout / 2;
547 if (srate >= 10000000) {
548 if (stv0900_check_timing_lock(intp, d) ==
TRUE) {
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)
596 tuner_freq = intp->
freq[
d];
602 while ((current_step <= nb_steps) && (lock ==
FALSE)) {
604 tuner_freq += (current_step * currier_step);
606 tuner_freq -= (current_step * currier_step);
622 freq = (tuner_freq * 65536) / (intp->
mclk / 1000);
637 static void stv0900_get_lock_timeout(
s32 *demod_timeout,
s32 *fec_timeout,
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;
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;
683 (*demod_timeout) /= 2;
707 dprintk(
"%s: ViterbiStandard = ", __func__);
803 if (srate >= 15000000) {
806 }
else if ((srate >= 7000000) && (15000000 > srate)) {
809 }
else if (srate < 7000000) {
821 static void stv0900_track_optimization(
struct dvb_frontend *fe)
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) {
848 dprintk(
"%s: found DVB-S or DSS\n", __func__);
873 dprintk(
"%s: found DVB-S2\n", __func__);
934 dprintk(
"%s: found unknown standard\n", __func__);
947 stv0900_set_symbol_rate(intp, intp->
mclk, srate, demod);
950 stv0900_set_dvbs1_track_car_loop(intp, demod, srate);
974 (blind_tun_sw == 1) ||
978 intp->
bw[demod] = stv0900_carrier_width(srate,
981 if ((intp->
chip_id >= 0x20) || (blind_tun_sw == 1)) {
1000 stv0900_get_lock_timeout(&timed, &timef, srate,
1011 timed / 2) ==
FALSE) &&
1028 stv0900_set_viterbi_tracq(intp, demod);
1043 while ((timer < time_out) && (lock == 0)) {
1044 switch (dmd_state) {
1065 dprintk(
"%s: DEMOD FEC LOCK OK\n", __func__);
1067 dprintk(
"%s: DEMOD FEC LOCK FAIL\n", __func__);
1074 s32 dmd_timeout,
s32 fec_timeout)
1077 s32 timer = 0, lock = 0;
1084 lock = 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)) {
1100 dprintk(
"%s: DEMOD LOCK OK\n", __func__);
1102 dprintk(
"%s: DEMOD LOCK FAIL\n", __func__);
1134 dprintk(
"%s: standard %d\n", __func__, fnd_standard);
1136 return fnd_standard;
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);
1171 frontend_ops = &fe->
ops;
1178 dprintk(
"%s: Invalid parameter\n", __func__);
1180 dprintk(
"%s: Frequency=%d\n", __func__, freq);
1208 while ((i <= 50) && (timing != 0) && (timing != 0xff)) {
1219 result->
frequency = stv0900_get_tuner_freq(fe);
1221 offsetFreq = stv0900_get_carr_freq(intp, intp->
mclk, d) / 1000;
1224 srate_offset = stv0900_get_timing_offst(intp, result->
symbol_rate, d);
1226 result->
fec = stv0900_get_vit_fec(intp, d);
1263 intp->
freq[
d] = stv0900_get_tuner_freq(fe);
1265 if (
ABS(offsetFreq) <= ((intp->
srch_range[d] / 2000) + 500))
1267 else if (
ABS(offsetFreq) <=
1272 }
else if (
ABS(offsetFreq) <= ((intp->
srch_range[d] / 2000) + 500))
1275 dprintk(
"%s: range %d\n", __func__, range);
1297 srate = stv0900_get_symbol_rate(intp, intp->
mclk, demod);
1298 srate += stv0900_get_timing_offst(intp, srate, demod);
1300 stv0900_set_symbol_rate(intp, intp->
mclk, srate, demod);
1302 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout,
1313 if (stv0900_wait_for_lock(intp, demod,
1314 demod_timeout, fec_timeout) ==
TRUE) {
1316 signal_type = stv0900_get_signal_params(fe);
1317 stv0900_track_optimization(fe);
1325 if (stv0900_wait_for_lock(intp, demod,
1326 demod_timeout, fec_timeout) ==
TRUE) {
1328 signal_type = stv0900_get_signal_params(fe);
1329 stv0900_track_optimization(fe);
1343 u32 minagc2level = 0xffff,
1345 init_freq, freq_step;
1360 stv0900_set_symbol_rate(intp, intp->
mclk, 1000000, demod);
1361 nb_steps = -1 + (intp->
srch_range[demod] / 1000000);
1363 nb_steps = (2 * nb_steps) + 1;
1370 freq_step = (1000000 << 8) / (intp->
mclk >> 8);
1374 for (i = 0; i < nb_steps; i++) {
1376 init_freq = init_freq + (freq_step *
i);
1378 init_freq = init_freq - (freq_step *
i);
1388 for (j = 0; j < 10; j++)
1394 if (agc2level < minagc2level)
1395 minagc2level = agc2level;
1399 return (
u16)minagc2level;
1407 int timing_lck =
FALSE;
1408 s32 i, timingcpt = 0,
1416 currier_step = 1200;
1439 }
else if (intp->
chip_id >= 0x20) {
1448 currier_step = 1000;
1450 currier_step = 2000;
1452 currier_step = 3000;
1454 currier_step = 5000;
1456 nb_steps = -1 + ((intp->
srch_range[demod] / 1000) / currier_step);
1458 nb_steps = (2 * nb_steps) + 1;
1462 else if (nb_steps > 10) {
1464 currier_step = (intp->
srch_range[demod] / 1000) / 10;
1470 tuner_freq = intp->
freq[demod];
1472 while ((timing_lck ==
FALSE) && (current_step < nb_steps)) {
1478 for (i = 0; i < 10; i++) {
1487 coarse_srate = stv0900_get_symbol_rate(intp, intp->
mclk, demod);
1491 dprintk(
"lock: I2C_DEMOD_MODE_FIELD =0. Search started."
1492 " tuner freq=%d agc2=0x%x srate_coarse=%d tmg_cpt=%d\n",
1493 tuner_freq, agc2_integr, coarse_srate, timingcpt);
1495 if ((timingcpt >= 5) &&
1496 (agc2_integr < agc2_th) &&
1497 (coarse_srate < 55000000) &&
1498 (coarse_srate > 850000))
1500 else if (current_step < nb_steps) {
1502 tuner_freq += (current_step * currier_step);
1504 tuner_freq -= (current_step * currier_step);
1508 intp->
bw[demod], demod);
1515 if (timing_lck ==
FALSE)
1518 coarse_srate = stv0900_get_symbol_rate(intp, intp->
mclk, demod);
1520 return coarse_srate;
1535 coarse_srate = stv0900_get_symbol_rate(intp, intp->
mclk, demod);
1537 if (coarse_srate > 3000000) {
1538 symbmax = 13 * (coarse_srate / 10);
1539 symbmax = (symbmax / 1000) * 65536;
1540 symbmax /= (intp->
mclk / 1000);
1542 symbmin = 10 * (coarse_srate / 13);
1543 symbmin = (symbmin / 1000)*65536;
1544 symbmin /= (intp->
mclk / 1000);
1546 symb = (coarse_srate / 1000) * 65536;
1547 symb /= (intp->
mclk / 1000);
1549 symbmax = 13 * (coarse_srate / 10);
1550 symbmax = (symbmax / 100) * 65536;
1551 symbmax /= (intp->
mclk / 100);
1553 symbmin = 10 * (coarse_srate / 14);
1554 symbmin = (symbmin / 100) * 65536;
1555 symbmin /= (intp->
mclk / 100);
1557 symb = (coarse_srate / 100) * 65536;
1558 symb /= (intp->
mclk / 100);
1561 symbcomp = 13 * (coarse_srate / 10);
1578 else if (intp->
chip_id >= 0x20)
1598 return coarse_srate;
1601 static int stv0900_blind_search_algo(
struct dvb_frontend *fe)
1612 coarse_fail =
FALSE;
1613 s32 demod_timeout = 500,
1624 k_ref_tmg_max = 233;
1625 k_ref_tmg_min = 143;
1627 k_ref_tmg_max = 110;
1636 agc2_int = stv0900_blind_check_agc2_min_level(intp, demod);
1638 dprintk(
"%s agc2_int=%d agc2_th=%d \n", __func__, agc2_int, agc2_th);
1639 if (agc2_int > agc2_th)
1664 k_ref_tmg = k_ref_tmg_max;
1668 if (stv0900_search_srate_coarse(fe) != 0) {
1669 coarse_srate = stv0900_search_srate_fine(fe);
1671 if (coarse_srate != 0) {
1672 stv0900_get_lock_timeout(&demod_timeout,
1685 for (i = 0; i < 10; i++) {
1689 if (agc2_int >= 0xff00)
1694 if (((dstatus2 & 0x1) == 0x1) &&
1695 ((dstatus2 >> 7) == 1))
1699 if ((fail_cpt > 7) || (agc2_overflow > 7))
1705 }
while ((k_ref_tmg >= k_ref_tmg_min) &&
1707 (coarse_fail ==
FALSE));
1735 dprintk(
"Search Standard = DVBS1\n");
1738 dprintk(
"Search Standard = DSS\n");
1741 dprintk(
"Search Standard = DVBS2\n");
1744 dprintk(
"Search Standard = AUTO\n");
1754 stv0900_set_dvbs1_track_car_loop(intp,
1759 stv0900_set_viterbi_acq(intp, demod);
1760 stv0900_set_viterbi_standard(intp,
1762 intp->
fec[demod], demod);
1785 stv0900_set_viterbi_tracq(intp, demod);
1795 stv0900_set_dvbs1_track_car_loop(intp,
1812 stv0900_set_viterbi_tracq(intp, demod);
1813 stv0900_set_viterbi_standard(intp,
1815 intp->
fec[demod], demod);
1827 s32 demod_timeout = 500, fec_timeout = 50;
1828 s32 aq_power, agc1_power,
i;
1834 int no_signal =
FALSE;
1849 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout,
1854 intp->
bw[demod] = 2 * 36000000;
1859 stv0900_set_symbol_rate(intp, intp->
mclk, 1000000, demod);
1878 intp->
bw[demod] += 10000000;
1879 intp->
bw[demod] *= 15;
1880 intp->
bw[demod] /= 10;
1882 intp->
bw[demod] += 10000000;
1886 intp->
bw[demod] += 10000000;
1887 intp->
bw[demod] *= 15;
1888 intp->
bw[demod] /= 10;
1893 stv0900_set_symbol_rate(intp, intp->
mclk,
1895 stv0900_set_max_symbol_rate(intp, intp->
mclk,
1897 stv0900_set_min_symbol_rate(intp, intp->
mclk,
1908 intp->
bw[demod], demod);
1917 if (agc1_power == 0) {
1918 for (i = 0; i < 5; i++)
1928 dprintk(
"%s: NO AGC1, POWERI, POWERQ\n", __func__);
1937 stv0900_set_search_standard(intp, demod);
1954 lock = stv0900_blind_search_algo(fe);
1956 lock = stv0900_get_demod_cold_lock(fe, demod_timeout);
1961 if (low_sr ==
FALSE) {
1962 if (stv0900_check_timing_lock(intp, demod) ==
TRUE)
1963 lock = stv0900_sw_algo(intp, demod);
1968 signal_type = stv0900_get_signal_params(fe);
1971 stv0900_track_optimization(fe);
1986 }
else if (intp->
chip_id >= 0x20) {
1993 if (stv0900_wait_for_lock(intp, demod,
1994 fec_timeout, fec_timeout) ==
TRUE) {
1997 if (intp->
result[demod].standard ==
1999 stv0900_set_dvbs2_rolloff(intp, demod);
2028 signal_type = stv0900_dvbs1_acq_workaround(fe);