40 static u32 stb0899_calc_srate(
u32 master_clk,
u8 *sfr)
47 tmp = (((
u32)sfr[0]) << 16) | (((
u32)sfr[1]) << 8) | sfr[2];
66 return stb0899_calc_srate(
internal->master_clk, sfr);
100 tmp = stb0899_do_div((((
u64)srate) << 21) + master_clk, 2 * master_clk);
118 static long stb0899_calc_derot_time(
long srate)
121 return (100000 / (srate / 1000));
142 static void stb0899_first_subrange(
struct stb0899_state *state)
159 internal->sub_range =
min(
internal->srch_range, range);
161 internal->sub_range = 0;
163 internal->freq = params->
freq;
164 internal->tuner_offst = 0
L;
165 internal->sub_dir = 1;
188 if ((lock > 48) && (
abs(timing) >= 110)) {
199 return internal->status;
211 short int derot_step, derot_freq = 0, derot_limit, next_loop = 3;
218 derot_limit = (
internal->sub_range / 2
L) /
internal->mclk;
219 derot_step = (params->
srate / 2L) /
internal->mclk;
221 while ((stb0899_check_tmg(state) !=
TIMINGOK) && next_loop) {
223 derot_freq += index *
internal->direction * derot_step;
225 if (
abs(derot_freq) > derot_limit)
233 internal->direction = -
internal->direction;
238 internal->derot_freq = state->
config->inversion *
MAKEWORD16(cfr[0], cfr[1]);
242 return internal->status;
270 return internal->status;
281 short int derot_freq = 0, last_derot_freq = 0, derot_limit, next_loop = 3;
287 derot_limit = (
internal->sub_range / 2
L) /
internal->mclk;
296 if (stb0899_check_carrier(state) ==
NOCARRIER) {
299 derot_freq += index *
internal->direction *
internal->derot_step;
301 if(
abs(derot_freq) > derot_limit)
315 internal->direction = -
internal->direction;
320 internal->derot_freq = state->
config->inversion *
MAKEWORD16(cfr[0], cfr[1]);
323 internal->derot_freq = last_derot_freq;
326 return internal->status;
338 int lock = 0, index = 0, dataTime = 500, loop;
341 internal->status =
NODATA;
352 if (params->
srate <= 2000000)
354 else if (params->
srate <= 5000000)
356 else if (params->
srate <= 15000000)
371 if (lock || loop || (index > dataTime))
377 internal->status =
DATAOK;
381 return internal->status;
390 short int derot_freq, derot_step, derot_limit, next_loop = 3;
399 derot_limit = (
internal->sub_range / 2L) /
internal->mclk;
400 derot_freq =
internal->derot_freq;
405 derot_freq += index *
internal->direction * derot_step;
406 if (
abs(derot_freq) > derot_limit)
419 stb0899_check_carrier(state);
423 internal->direction = -
internal->direction;
428 internal->derot_freq = state->
config->inversion *
MAKEWORD16(cfr[0], cfr[1]);
432 return internal->status;
444 int range_offst, tp_freq;
446 range_offst =
internal->srch_range / 2000;
447 tp_freq =
internal->freq + (
internal->derot_freq *
internal->mclk) / 1000;
449 if ((tp_freq >= params->
freq - range_offst) && (tp_freq <= params->
freq + range_offst)) {
457 return internal->status;
472 old_sub_range =
internal->sub_range;
473 internal->sub_range =
min((
internal->srch_range / 2) -
478 internal->sub_range = 0;
480 internal->tuner_offst += (old_sub_range +
internal->sub_range) / 2;
483 internal->freq = params->
freq + (
internal->sub_dir *
internal->tuner_offst) / 1000;
484 internal->sub_dir = -
internal->sub_dir;
505 s32 betaTab[5][4] = {
514 internal->direction = 1;
516 stb0899_set_srate(state,
internal->master_clk, params->
srate);
518 if (params->
srate <= 5000000) {
524 }
else if (params->
srate <= 15000000) {
530 }
else if(params->
srate <= 25000000) {
559 internal->derot_step =
internal->derot_percent * (params->
srate / 1000
L) /
internal->mclk;
561 internal->t_data = 500;
580 stb0899_first_subrange(state);
591 internal->derot_freq = 0;
592 internal->status =
NOAGC1;
599 if (state->
config->tuner_set_frequency)
602 if (state->
config->tuner_get_frequency)
607 internal->status =
AGC1OK;
616 if (params->
srate <= bandwidth / 2)
617 stb0899_search_tmg(state);
619 stb0899_check_tmg(state);
623 "TIMING OK ! Derot freq=%d, mclk=%d",
626 if (stb0899_search_carrier(state) ==
CARRIEROK) {
628 "CARRIER OK ! Derot freq=%d, mclk=%d",
631 if (stb0899_search_data(state) ==
DATAOK) {
633 "DATA OK ! Derot freq=%d, mclk=%d",
636 if (stb0899_check_range(state) ==
RANGEOK) {
638 "RANGE OK ! derot freq=%d, mclk=%d",
641 internal->freq = params->
freq + ((
internal->derot_freq *
internal->mclk) / 1000);
645 "freq=%d, internal resultant freq=%d",
649 "internal puncture rate=%d",
656 next_sub_range(state);
722 return internal->status;
729 static void stb0899_dvbs2_config_uwp(
struct stb0899_state *state)
733 u32 uwp1, uwp2, uwp3,
reg;
763 static void stb0899_dvbs2_config_csm_auto(
struct stb0899_state *state)
772 static long Log2Int(
int number)
777 while ((1 << i) <=
abs(number))
795 u32 dec_ratio, dec_rate, decim, remain, intval, btr_nom_freq;
796 u32 master_clk, srate;
798 dec_ratio = (
internal->master_clk * 2) / (5 *
internal->srate);
799 dec_ratio = (dec_ratio == 0) ? 1 : dec_ratio;
800 dec_rate = Log2Int(dec_ratio);
801 decim = 1 << dec_rate;
802 master_clk =
internal->master_clk / 1000;
803 srate =
internal->srate / 1000;
806 intval = (decim * (1 << (config->
btr_nco_bits - 1))) / master_clk;
807 remain = (decim * (1 << (config->
btr_nco_bits - 1))) % master_clk;
809 intval = (1 << (config->
btr_nco_bits - 1)) / (master_clk / 100) * decim / 100;
810 remain = (decim * (1 << (config->
btr_nco_bits - 1))) % master_clk;
812 btr_nom_freq = (intval * srate) + ((remain * srate) / master_clk);
826 dec_ratio = (
internal->master_clk * 2) / (5 *
internal->srate);
827 dec_ratio = (dec_ratio == 0) ? 1 : dec_ratio;
829 master_clk =
internal->master_clk / 1000;
830 srate =
internal->srate / 1000;
831 correction = (512 *
master_clk) / (2 * dec_ratio * srate);
840 static void stb0899_dvbs2_set_srate(
struct stb0899_state *state)
844 u32 dec_ratio, dec_rate, win_sel, decim, f_sym, btr_nom_freq;
845 u32 correction, freq_adj, band_lim, decim_cntrl,
reg;
849 dec_ratio = (
internal->master_clk * 2) / (5 *
internal->srate);
850 dec_ratio = (dec_ratio == 0) ? 1 : dec_ratio;
851 dec_rate = Log2Int(dec_ratio);
855 win_sel = dec_rate - 4;
857 decim = (1 << dec_rate);
859 f_sym =
internal->master_clk / ((decim *
internal->srate) / 1000);
866 decim_cntrl = ((win_sel << 3) & 0x18) + ((band_lim << 5) & 0x20) + (dec_rate & 0x7);
871 else if (f_sym <= 4250)
877 btr_nom_freq = stb0899_dvbs2_calc_srate(state);
880 correction = stb0899_dvbs2_calc_dev(state);
886 freq_adj =
internal->srate / (
internal->master_clk / 4096);
894 static void stb0899_dvbs2_set_btr_loopbw(
struct stb0899_state *state)
899 u32 sym_peak = 23, zeta = 707, loopbw_percent = 60;
900 s32 dec_ratio, dec_rate, k_btr1_rshft, k_btr1, k_btr0_rshft;
901 s32 k_btr0, k_btr2_rshft, k_direct_shift, k_indirect_shift;
902 u32 decim,
K, wn, k_direct, k_indirect;
905 dec_ratio = (
internal->master_clk * 2) / (5 *
internal->srate);
906 dec_ratio = (dec_ratio == 0) ? 1 : dec_ratio;
907 dec_rate = Log2Int(dec_ratio);
908 decim = (1 << dec_rate);
912 K *= (
internal->srate / 1000000) * decim;
916 wn = (4 * zeta * zeta) + 1000000;
917 wn = (2 * (loopbw_percent * 1000) * 40 * zeta) /wn;
919 k_indirect = (wn * wn) / K;
920 k_indirect = k_indirect;
921 k_direct = (2 * wn * zeta) / K;
924 k_direct_shift = Log2Int(k_direct) - Log2Int(10000) - 2;
926 k_btr1 = k_direct / (1 << k_direct_shift);
929 k_indirect_shift = Log2Int(k_indirect + 15) - 20 ;
931 k_btr0 = k_indirect * (1 << (-k_indirect_shift));
935 if (k_btr0_rshft > 15) {
936 k_btr2_rshft = k_btr0_rshft - 15;
954 static void stb0899_dvbs2_set_carr_freq(
struct stb0899_state *state,
s32 carr_freq,
u32 master_clk)
960 crl_nom_freq = (1 << config->
crl_nco_bits) / master_clk;
961 crl_nom_freq *= carr_freq;
971 static void stb0899_dvbs2_init_calc(
struct stb0899_state *state)
978 stb0899_dvbs2_config_uwp(state);
979 stb0899_dvbs2_config_csm_auto(state);
982 stb0899_dvbs2_set_srate(state);
983 stb0899_dvbs2_set_btr_loopbw(state);
985 if (
internal->srate / 1000000 >= 15)
986 step_size = (1 << 17) / 5;
987 else if (
internal->srate / 1000000 >= 10)
988 step_size = (1 << 17) / 7;
989 else if (
internal->srate / 1000000 >= 5)
990 step_size = (1 << 17) / 10;
992 step_size = (1 << 17) / 4;
994 range =
internal->srch_range / 1000000;
995 steps = (10 * range * (1 << 17)) / (step_size * (
internal->srate / 1000000));
996 steps = (steps + 6) / 10;
997 steps = (steps == 0) ? 1 : steps;
999 stb0899_dvbs2_set_carr_freq(state,
internal->center_freq -
1003 stb0899_dvbs2_set_carr_freq(state,
internal->center_freq, (
internal->master_clk) / 1000000);
1017 static void stb0899_dvbs2_btr_init(
struct stb0899_state *state)
1040 static void stb0899_dvbs2_reacquire(
struct stb0899_state *state)
1049 stb0899_dvbs2_btr_init(state);
1090 int time = -10, lock = 0, uwp, csm;
1108 }
while ((!lock) && (time <= timeout));
1122 static int stb0899_dvbs2_get_data_lock(
struct stb0899_state *state,
int timeout)
1124 int time = 0, lock = 0;
1127 while ((!lock) && (time < timeout)) {
1143 int time = 0, Locked;
1146 Locked = stb0899_dvbs2_get_data_lock(state, 1);
1150 }
while ((!Locked) && (time < timeout));
1169 s32 dvt_tbl = 1, two_pass = 0,
agc_gain = 6, agc_shift = 0, loop_shift = 0, phs_diff_thr = 0x80;
1170 s32 gamma_acq, gamma_rho_acq, gamma_trk, gamma_rho_trk, lock_count_thr;
1171 u32 csm1, csm2, csm3, csm4;
1173 if (((
internal->master_clk /
internal->srate) <= 4) && (modcod <= 11) && (pilots == 1)) {
1177 gamma_rho_acq = 2700;
1179 gamma_rho_trk = 180;
1184 gamma_rho_acq = 7182;
1186 gamma_rho_trk = 308;
1191 gamma_rho_acq = 9408;
1193 gamma_rho_trk = 476;
1198 gamma_rho_acq = 16642;
1200 gamma_rho_trk = 646;
1205 gamma_rho_acq = 17119;
1207 gamma_rho_trk = 880;
1212 gamma_rho_acq = 19250;
1214 gamma_rho_trk = 989;
1219 gamma_rho_acq = 24240;
1221 gamma_rho_trk = 1176;
1226 gamma_rho_acq = 29634;
1228 gamma_rho_trk = 1176;
1233 gamma_rho_acq = 29634;
1235 gamma_rho_trk = 1176;
1277 u32 bTrNomFreq, srate, decimRate, intval1, intval2,
reg;
1278 int div1,
div2, rem1, rem2;
1287 decimRate = (1 << decimRate);
1289 intval1 =
internal->master_clk / (1 << div1);
1290 intval2 = bTrNomFreq / (1 <<
div2);
1292 rem1 =
internal->master_clk % (1 << div1);
1293 rem2 = bTrNomFreq % (1 <<
div2);
1295 srate = (intval1 * intval2) + ((intval1 * rem2) / (1 <<
div2)) + ((intval2 * rem1) / (1 << div1));
1311 s32 offsetfreq, searchTime, FecLockTime,
pilots, iqSpectrum;
1318 }
else if (
internal->srate <= 5000000) {
1321 }
else if (
internal->srate <= 10000000) {
1324 }
else if (
internal->srate <= 15000000) {
1327 }
else if (
internal->srate <= 20000000) {
1330 }
else if (
internal->srate <= 25000000) {
1347 if (state->
config->tuner_set_frequency)
1349 if (state->
config->tuner_get_frequency)
1366 stb0899_dvbs2_init_calc(state);
1381 stb0899_dvbs2_reacquire(state);
1384 internal->status = stb0899_dvbs2_get_dmd_status(state, searchTime);
1390 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime);
1401 stb0899_dvbs2_reacquire(state);
1402 internal->status = stb0899_dvbs2_get_fec_status(state, searchTime);
1415 stb0899_dvbs2_reacquire(state);
1418 internal->status = stb0899_dvbs2_get_dmd_status(state, searchTime);
1422 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime);
1433 stb0899_dvbs2_reacquire(state);
1434 internal->status = stb0899_dvbs2_get_fec_status(state, searchTime);
1454 stb0899_dvbs2_init_csm(state, pilots, modcod);
1456 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime);
1467 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime);
1490 offsetfreq = offsetfreq / ((1 << 30) / 1000);
1491 offsetfreq *= (
internal->master_clk / 1000000);
1496 internal->freq =
internal->freq - offsetfreq;
1497 internal->srate = stb0899_dvbs2_get_srate(state);
1502 internal->frame_length = (
STB0899_GETFIELD(UWP_DECODE_MOD, reg) >> 1) & 0x01;
1524 return internal->status;