Lines Matching +full:lock +full:- +full:state

1 // SPDX-License-Identifier: GPL-2.0-or-later
48 static u32 stb0899_get_srate(struct stb0899_state *state)
50 struct stb0899_internal *internal = &state->internal;
53 stb0899_read_regs(state, STB0899_SFRH, sfr, 3);
55 return stb0899_calc_srate(internal->master_clk, sfr);
66 static u32 stb0899_set_srate(struct stb0899_state *state, u32 master_clk, u32 srate) in stb0899_set_srate() argument
71 dprintk(state->verbose, FE_DEBUG, 1, "-->"); in stb0899_set_srate()
96 stb0899_write_regs(state, STB0899_SFRH, sfr, 3); in stb0899_set_srate()
103 * Compute the amount of time needed by the derotator to lock
120 long stb0899_carr_width(struct stb0899_state *state) in stb0899_carr_width() argument
122 struct stb0899_internal *internal = &state->internal; in stb0899_carr_width()
124 return (internal->srate + (internal->srate * internal->rolloff) / 100); in stb0899_carr_width()
131 static void stb0899_first_subrange(struct stb0899_state *state) in stb0899_first_subrange() argument
133 struct stb0899_internal *internal = &state->internal; in stb0899_first_subrange()
134 struct stb0899_params *params = &state->params; in stb0899_first_subrange()
135 struct stb0899_config *config = state->config; in stb0899_first_subrange()
140 if (config->tuner_get_bandwidth) { in stb0899_first_subrange()
141 stb0899_i2c_gate_ctrl(&state->frontend, 1); in stb0899_first_subrange()
142 config->tuner_get_bandwidth(&state->frontend, &bandwidth); in stb0899_first_subrange()
143 stb0899_i2c_gate_ctrl(&state->frontend, 0); in stb0899_first_subrange()
144 range = bandwidth - stb0899_carr_width(state) / 2; in stb0899_first_subrange()
148 internal->sub_range = min(internal->srch_range, range); in stb0899_first_subrange()
150 internal->sub_range = 0; in stb0899_first_subrange()
152 internal->freq = params->freq; in stb0899_first_subrange()
153 internal->tuner_offst = 0L; in stb0899_first_subrange()
154 internal->sub_dir = 1; in stb0899_first_subrange()
159 * check for timing lock
160 * internal.Ttiming: time to wait for loop lock
162 static enum stb0899_status stb0899_check_tmg(struct stb0899_state *state) in stb0899_check_tmg() argument
164 struct stb0899_internal *internal = &state->internal; in stb0899_check_tmg()
165 int lock; in stb0899_check_tmg() local
169 msleep(internal->t_derot); in stb0899_check_tmg()
171 stb0899_write_reg(state, STB0899_RTF, 0xf2); in stb0899_check_tmg()
172 reg = stb0899_read_reg(state, STB0899_TLIR); in stb0899_check_tmg()
173 lock = STB0899_GETFIELD(TLIR_TMG_LOCK_IND, reg); in stb0899_check_tmg()
174 timing = stb0899_read_reg(state, STB0899_RTF); in stb0899_check_tmg()
176 if (lock >= 42) { in stb0899_check_tmg()
177 if ((lock > 48) && (abs(timing) >= 110)) { in stb0899_check_tmg()
178 internal->status = ANALOGCARRIER; in stb0899_check_tmg()
179 dprintk(state->verbose, FE_DEBUG, 1, "-->ANALOG Carrier !"); in stb0899_check_tmg()
181 internal->status = TIMINGOK; in stb0899_check_tmg()
182 dprintk(state->verbose, FE_DEBUG, 1, "------->TIMING OK !"); in stb0899_check_tmg()
185 internal->status = NOTIMING; in stb0899_check_tmg()
186 dprintk(state->verbose, FE_DEBUG, 1, "-->NO TIMING !"); in stb0899_check_tmg()
188 return internal->status; in stb0899_check_tmg()
193 * perform a fs/2 zig-zag to find timing
195 static enum stb0899_status stb0899_search_tmg(struct stb0899_state *state) in stb0899_search_tmg() argument
197 struct stb0899_internal *internal = &state->internal; in stb0899_search_tmg()
198 struct stb0899_params *params = &state->params; in stb0899_search_tmg()
204 internal->status = NOTIMING; in stb0899_search_tmg()
207 derot_limit = (internal->sub_range / 2L) / internal->mclk; in stb0899_search_tmg()
208 derot_step = (params->srate / 2L) / internal->mclk; in stb0899_search_tmg()
210 while ((stb0899_check_tmg(state) != TIMINGOK) && next_loop) { in stb0899_search_tmg()
212 derot_freq += index * internal->direction * derot_step; /* next derot zig zag position */ in stb0899_search_tmg()
215 next_loop--; in stb0899_search_tmg()
218 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(internal->inversion * derot_freq)); in stb0899_search_tmg()
219 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(internal->inversion * derot_freq)); in stb0899_search_tmg()
220 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */ in stb0899_search_tmg()
222 internal->direction = -internal->direction; /* Change zigzag direction */ in stb0899_search_tmg()
225 if (internal->status == TIMINGOK) { in stb0899_search_tmg()
226 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */ in stb0899_search_tmg()
227 internal->derot_freq = internal->inversion * MAKEWORD16(cfr[0], cfr[1]); in stb0899_search_tmg()
228 dprintk(state->verbose, FE_DEBUG, 1, "------->TIMING OK ! Derot Freq = %d", internal->derot_freq); in stb0899_search_tmg()
231 return internal->status; in stb0899_search_tmg()
238 static enum stb0899_status stb0899_check_carrier(struct stb0899_state *state) in stb0899_check_carrier() argument
240 struct stb0899_internal *internal = &state->internal; in stb0899_check_carrier()
243 msleep(internal->t_derot); /* wait for derotator ok */ in stb0899_check_carrier()
245 reg = stb0899_read_reg(state, STB0899_CFD); in stb0899_check_carrier()
247 stb0899_write_reg(state, STB0899_CFD, reg); in stb0899_check_carrier()
249 reg = stb0899_read_reg(state, STB0899_DSTATUS); in stb0899_check_carrier()
250 dprintk(state->verbose, FE_DEBUG, 1, "--------------------> STB0899_DSTATUS=[0x%02x]", reg); in stb0899_check_carrier()
252 internal->status = CARRIEROK; in stb0899_check_carrier()
253 dprintk(state->verbose, FE_DEBUG, 1, "-------------> CARRIEROK !"); in stb0899_check_carrier()
255 internal->status = NOCARRIER; in stb0899_check_carrier()
256 dprintk(state->verbose, FE_DEBUG, 1, "-------------> NOCARRIER !"); in stb0899_check_carrier()
259 return internal->status; in stb0899_check_carrier()
266 static enum stb0899_status stb0899_search_carrier(struct stb0899_state *state) in stb0899_search_carrier() argument
268 struct stb0899_internal *internal = &state->internal; in stb0899_search_carrier()
275 internal->status = NOCARRIER; in stb0899_search_carrier()
276 derot_limit = (internal->sub_range / 2L) / internal->mclk; in stb0899_search_carrier()
277 derot_freq = internal->derot_freq; in stb0899_search_carrier()
279 reg = stb0899_read_reg(state, STB0899_CFD); in stb0899_search_carrier()
281 stb0899_write_reg(state, STB0899_CFD, reg); in stb0899_search_carrier()
284 dprintk(state->verbose, FE_DEBUG, 1, "Derot Freq=%d, mclk=%d", derot_freq, internal->mclk); in stb0899_search_carrier()
285 if (stb0899_check_carrier(state) == NOCARRIER) { in stb0899_search_carrier()
288 …derot_freq += index * internal->direction * internal->derot_step; /* next zig zag derotator positi… in stb0899_search_carrier()
291 next_loop--; in stb0899_search_carrier()
294 reg = stb0899_read_reg(state, STB0899_CFD); in stb0899_search_carrier()
296 stb0899_write_reg(state, STB0899_CFD, reg); in stb0899_search_carrier()
298 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(internal->inversion * derot_freq)); in stb0899_search_carrier()
299 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(internal->inversion * derot_freq)); in stb0899_search_carrier()
300 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */ in stb0899_search_carrier()
304 internal->direction = -internal->direction; /* Change zigzag direction */ in stb0899_search_carrier()
305 } while ((internal->status != CARRIEROK) && next_loop); in stb0899_search_carrier()
307 if (internal->status == CARRIEROK) { in stb0899_search_carrier()
308 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */ in stb0899_search_carrier()
309 internal->derot_freq = internal->inversion * MAKEWORD16(cfr[0], cfr[1]); in stb0899_search_carrier()
310 dprintk(state->verbose, FE_DEBUG, 1, "----> CARRIER OK !, Derot Freq=%d", internal->derot_freq); in stb0899_search_carrier()
312 internal->derot_freq = last_derot_freq; in stb0899_search_carrier()
315 return internal->status; in stb0899_search_carrier()
322 static enum stb0899_status stb0899_check_data(struct stb0899_state *state) in stb0899_check_data() argument
324 struct stb0899_internal *internal = &state->internal; in stb0899_check_data()
325 struct stb0899_params *params = &state->params; in stb0899_check_data()
327 int lock = 0, index = 0, dataTime = 500, loop; in stb0899_check_data() local
330 internal->status = NODATA; in stb0899_check_data()
333 reg = stb0899_read_reg(state, STB0899_TSTRES); in stb0899_check_data()
335 stb0899_write_reg(state, STB0899_TSTRES, reg); in stb0899_check_data()
337 reg = stb0899_read_reg(state, STB0899_TSTRES); in stb0899_check_data()
339 stb0899_write_reg(state, STB0899_TSTRES, reg); in stb0899_check_data()
341 if (params->srate <= 2000000) in stb0899_check_data()
343 else if (params->srate <= 5000000) in stb0899_check_data()
345 else if (params->srate <= 15000000) in stb0899_check_data()
351 stb0899_read_reg(state, STB0899_VSTATUS); in stb0899_check_data()
353 stb0899_write_reg(state, STB0899_DSTATUS2, 0x00); /* force search loop */ in stb0899_check_data()
356 reg = stb0899_read_reg(state, STB0899_VSTATUS); in stb0899_check_data()
357 lock = STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg); in stb0899_check_data()
360 if (lock || loop || (index > dataTime)) in stb0899_check_data()
365 if (lock) { /* DATA LOCK indicator */ in stb0899_check_data()
366 internal->status = DATAOK; in stb0899_check_data()
367 dprintk(state->verbose, FE_DEBUG, 1, "-----------------> DATA OK !"); in stb0899_check_data()
370 return internal->status; in stb0899_check_data()
377 static enum stb0899_status stb0899_search_data(struct stb0899_state *state) in stb0899_search_data() argument
384 struct stb0899_internal *internal = &state->internal; in stb0899_search_data()
385 struct stb0899_params *params = &state->params; in stb0899_search_data()
387 derot_step = (params->srate / 4L) / internal->mclk; in stb0899_search_data()
388 derot_limit = (internal->sub_range / 2L) / internal->mclk; in stb0899_search_data()
389 derot_freq = internal->derot_freq; in stb0899_search_data()
392 if ((internal->status != CARRIEROK) || (stb0899_check_data(state) != DATAOK)) { in stb0899_search_data()
394 derot_freq += index * internal->direction * derot_step; /* next zig zag derotator position */ in stb0899_search_data()
396 next_loop--; in stb0899_search_data()
399 dprintk(state->verbose, FE_DEBUG, 1, "Derot freq=%d, mclk=%d", derot_freq, internal->mclk); in stb0899_search_data()
400 reg = stb0899_read_reg(state, STB0899_CFD); in stb0899_search_data()
402 stb0899_write_reg(state, STB0899_CFD, reg); in stb0899_search_data()
404 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(internal->inversion * derot_freq)); in stb0899_search_data()
405 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(internal->inversion * derot_freq)); in stb0899_search_data()
406 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */ in stb0899_search_data()
408 stb0899_check_carrier(state); in stb0899_search_data()
412 internal->direction = -internal->direction; /* change zig zag direction */ in stb0899_search_data()
413 } while ((internal->status != DATAOK) && next_loop); in stb0899_search_data()
415 if (internal->status == DATAOK) { in stb0899_search_data()
416 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */ in stb0899_search_data()
418 /* store autodetected IQ swapping as default for DVB-S2 tuning */ in stb0899_search_data()
419 reg = stb0899_read_reg(state, STB0899_IQSWAP); in stb0899_search_data()
421 internal->inversion = IQ_SWAP_ON; in stb0899_search_data()
423 internal->inversion = IQ_SWAP_OFF; in stb0899_search_data()
425 internal->derot_freq = internal->inversion * MAKEWORD16(cfr[0], cfr[1]); in stb0899_search_data()
426 dprintk(state->verbose, FE_DEBUG, 1, "------> DATAOK ! Derot Freq=%d", internal->derot_freq); in stb0899_search_data()
429 return internal->status; in stb0899_search_data()
436 static enum stb0899_status stb0899_check_range(struct stb0899_state *state) in stb0899_check_range() argument
438 struct stb0899_internal *internal = &state->internal; in stb0899_check_range()
439 struct stb0899_params *params = &state->params; in stb0899_check_range()
443 range_offst = internal->srch_range / 2000; in stb0899_check_range()
444 tp_freq = internal->freq - (internal->derot_freq * internal->mclk) / 1000; in stb0899_check_range()
446 if ((tp_freq >= params->freq - range_offst) && (tp_freq <= params->freq + range_offst)) { in stb0899_check_range()
447 internal->status = RANGEOK; in stb0899_check_range()
448 dprintk(state->verbose, FE_DEBUG, 1, "----> RANGEOK !"); in stb0899_check_range()
450 internal->status = OUTOFRANGE; in stb0899_check_range()
451 dprintk(state->verbose, FE_DEBUG, 1, "----> OUT OF RANGE !"); in stb0899_check_range()
454 return internal->status; in stb0899_check_range()
461 static void next_sub_range(struct stb0899_state *state) in next_sub_range() argument
463 struct stb0899_internal *internal = &state->internal; in next_sub_range()
464 struct stb0899_params *params = &state->params; in next_sub_range()
468 if (internal->sub_dir > 0) { in next_sub_range()
469 old_sub_range = internal->sub_range; in next_sub_range()
470 internal->sub_range = min((internal->srch_range / 2) - in next_sub_range()
471 (internal->tuner_offst + internal->sub_range / 2), in next_sub_range()
472 internal->sub_range); in next_sub_range()
474 if (internal->sub_range < 0) in next_sub_range()
475 internal->sub_range = 0; in next_sub_range()
477 internal->tuner_offst += (old_sub_range + internal->sub_range) / 2; in next_sub_range()
480 internal->freq = params->freq + (internal->sub_dir * internal->tuner_offst) / 1000; in next_sub_range()
481 internal->sub_dir = -internal->sub_dir; in next_sub_range()
489 enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state) in stb0899_dvbs_algo() argument
491 struct stb0899_params *params = &state->params; in stb0899_dvbs_algo()
492 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs_algo()
493 struct stb0899_config *config = state->config; in stb0899_dvbs_algo()
511 internal->direction = 1; in stb0899_dvbs_algo()
513 stb0899_set_srate(state, internal->master_clk, params->srate); in stb0899_dvbs_algo()
515 if (params->srate <= 5000000) { in stb0899_dvbs_algo()
516 stb0899_write_reg(state, STB0899_ACLC, 0x89); in stb0899_dvbs_algo()
517 bclc = stb0899_read_reg(state, STB0899_BCLC); in stb0899_dvbs_algo()
519 stb0899_write_reg(state, STB0899_BCLC, bclc); in stb0899_dvbs_algo()
521 } else if (params->srate <= 15000000) { in stb0899_dvbs_algo()
522 stb0899_write_reg(state, STB0899_ACLC, 0xc9); in stb0899_dvbs_algo()
523 bclc = stb0899_read_reg(state, STB0899_BCLC); in stb0899_dvbs_algo()
525 stb0899_write_reg(state, STB0899_BCLC, bclc); in stb0899_dvbs_algo()
527 } else if(params->srate <= 25000000) { in stb0899_dvbs_algo()
528 stb0899_write_reg(state, STB0899_ACLC, 0x89); in stb0899_dvbs_algo()
529 bclc = stb0899_read_reg(state, STB0899_BCLC); in stb0899_dvbs_algo()
531 stb0899_write_reg(state, STB0899_BCLC, bclc); in stb0899_dvbs_algo()
534 stb0899_write_reg(state, STB0899_ACLC, 0xc8); in stb0899_dvbs_algo()
535 bclc = stb0899_read_reg(state, STB0899_BCLC); in stb0899_dvbs_algo()
537 stb0899_write_reg(state, STB0899_BCLC, bclc); in stb0899_dvbs_algo()
541 dprintk(state->verbose, FE_DEBUG, 1, "Set the timing loop to acquisition"); in stb0899_dvbs_algo()
543 stb0899_write_reg(state, STB0899_RTC, 0x46); in stb0899_dvbs_algo()
544 stb0899_write_reg(state, STB0899_CFD, 0xee); in stb0899_dvbs_algo()
552 dprintk(state->verbose, FE_DEBUG, 1, "Derot Percent=%d Srate=%d mclk=%d", in stb0899_dvbs_algo()
553 internal->derot_percent, params->srate, internal->mclk); in stb0899_dvbs_algo()
556 …internal->derot_step = internal->derot_percent * (params->srate / 1000L) / internal->mclk; /* Dero… in stb0899_dvbs_algo()
557 internal->t_derot = stb0899_calc_derot_time(params->srate); in stb0899_dvbs_algo()
558 internal->t_data = 500; in stb0899_dvbs_algo()
560 dprintk(state->verbose, FE_DEBUG, 1, "RESET stream merger"); in stb0899_dvbs_algo()
562 reg = stb0899_read_reg(state, STB0899_TSTRES); in stb0899_dvbs_algo()
564 stb0899_write_reg(state, STB0899_TSTRES, reg); in stb0899_dvbs_algo()
570 reg = stb0899_read_reg(state, STB0899_DEMAPVIT); in stb0899_dvbs_algo()
572 stb0899_write_reg(state, STB0899_DEMAPVIT, reg); in stb0899_dvbs_algo()
574 stb0899_write_reg(state, STB0899_EQON, 0x01); /* Equalizer OFF while acquiring */ in stb0899_dvbs_algo()
575 stb0899_write_reg(state, STB0899_VITSYNC, 0x19); in stb0899_dvbs_algo()
577 stb0899_first_subrange(state); in stb0899_dvbs_algo()
581 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* RESET derotator frequency */ in stb0899_dvbs_algo()
583 stb0899_write_reg(state, STB0899_RTF, 0); in stb0899_dvbs_algo()
584 reg = stb0899_read_reg(state, STB0899_CFD); in stb0899_dvbs_algo()
586 stb0899_write_reg(state, STB0899_CFD, reg); in stb0899_dvbs_algo()
588 internal->derot_freq = 0; in stb0899_dvbs_algo()
589 internal->status = NOAGC1; in stb0899_dvbs_algo()
592 stb0899_i2c_gate_ctrl(&state->frontend, 1); in stb0899_dvbs_algo()
595 dprintk(state->verbose, FE_DEBUG, 1, "Tuner set frequency"); in stb0899_dvbs_algo()
596 if (state->config->tuner_set_frequency) in stb0899_dvbs_algo()
597 state->config->tuner_set_frequency(&state->frontend, internal->freq); in stb0899_dvbs_algo()
599 if (state->config->tuner_get_frequency) in stb0899_dvbs_algo()
600 state->config->tuner_get_frequency(&state->frontend, &internal->freq); in stb0899_dvbs_algo()
602 msleep(internal->t_agc1 + internal->t_agc2 + internal->t_derot); /* AGC1, AGC2 and timing loop */ in stb0899_dvbs_algo()
603 dprintk(state->verbose, FE_DEBUG, 1, "current derot freq=%d", internal->derot_freq); in stb0899_dvbs_algo()
604 internal->status = AGC1OK; in stb0899_dvbs_algo()
607 if (config->tuner_get_bandwidth) in stb0899_dvbs_algo()
608 config->tuner_get_bandwidth(&state->frontend, &bandwidth); in stb0899_dvbs_algo()
611 stb0899_i2c_gate_ctrl(&state->frontend, 0); in stb0899_dvbs_algo()
613 if (params->srate <= bandwidth / 2) in stb0899_dvbs_algo()
614 stb0899_search_tmg(state); /* For low rates (SCPC) */ in stb0899_dvbs_algo()
616 stb0899_check_tmg(state); /* For high rates (MCPC) */ in stb0899_dvbs_algo()
618 if (internal->status == TIMINGOK) { in stb0899_dvbs_algo()
619 dprintk(state->verbose, FE_DEBUG, 1, in stb0899_dvbs_algo()
621 internal->derot_freq, internal->mclk); in stb0899_dvbs_algo()
623 if (stb0899_search_carrier(state) == CARRIEROK) { /* Search for carrier */ in stb0899_dvbs_algo()
624 dprintk(state->verbose, FE_DEBUG, 1, in stb0899_dvbs_algo()
626 internal->derot_freq, internal->mclk); in stb0899_dvbs_algo()
628 if (stb0899_search_data(state) == DATAOK) { /* Check for data */ in stb0899_dvbs_algo()
629 dprintk(state->verbose, FE_DEBUG, 1, in stb0899_dvbs_algo()
631 internal->derot_freq, internal->mclk); in stb0899_dvbs_algo()
633 if (stb0899_check_range(state) == RANGEOK) { in stb0899_dvbs_algo()
634 dprintk(state->verbose, FE_DEBUG, 1, in stb0899_dvbs_algo()
636 internal->derot_freq, internal->mclk); in stb0899_dvbs_algo()
638 internal->freq = params->freq - ((internal->derot_freq * internal->mclk) / 1000); in stb0899_dvbs_algo()
639 reg = stb0899_read_reg(state, STB0899_PLPARM); in stb0899_dvbs_algo()
640 internal->fecrate = STB0899_GETFIELD(VITCURPUN, reg); in stb0899_dvbs_algo()
641 dprintk(state->verbose, FE_DEBUG, 1, in stb0899_dvbs_algo()
643 params->freq, internal->freq); in stb0899_dvbs_algo()
645 dprintk(state->verbose, FE_DEBUG, 1, in stb0899_dvbs_algo()
647 internal->fecrate); in stb0899_dvbs_algo()
652 if (internal->status != RANGEOK) in stb0899_dvbs_algo()
653 next_sub_range(state); in stb0899_dvbs_algo()
655 } while (internal->sub_range && internal->status != RANGEOK); in stb0899_dvbs_algo()
658 stb0899_write_reg(state, STB0899_RTC, 0x33); in stb0899_dvbs_algo()
659 stb0899_write_reg(state, STB0899_CFD, 0xf7); in stb0899_dvbs_algo()
661 if (internal->status == RANGEOK) { in stb0899_dvbs_algo()
662 dprintk(state->verbose, FE_DEBUG, 1, "Locked & Range OK !"); in stb0899_dvbs_algo()
663 stb0899_write_reg(state, STB0899_EQON, 0x41); /* Equalizer OFF while acquiring */ in stb0899_dvbs_algo()
664 stb0899_write_reg(state, STB0899_VITSYNC, 0x39); /* SN to b'11 for acquisition */ in stb0899_dvbs_algo()
670 reg = stb0899_read_reg(state, STB0899_BCLC); in stb0899_dvbs_algo()
671 switch (internal->fecrate) { in stb0899_dvbs_algo()
673 stb0899_write_reg(state, STB0899_DEMAPVIT, 0x1a); in stb0899_dvbs_algo()
675 stb0899_write_reg(state, STB0899_BCLC, reg); in stb0899_dvbs_algo()
678 stb0899_write_reg(state, STB0899_DEMAPVIT, 44); in stb0899_dvbs_algo()
680 stb0899_write_reg(state, STB0899_BCLC, reg); in stb0899_dvbs_algo()
683 stb0899_write_reg(state, STB0899_DEMAPVIT, 60); in stb0899_dvbs_algo()
685 stb0899_write_reg(state, STB0899_BCLC, reg); in stb0899_dvbs_algo()
688 stb0899_write_reg(state, STB0899_DEMAPVIT, 75); in stb0899_dvbs_algo()
690 stb0899_write_reg(state, STB0899_BCLC, reg); in stb0899_dvbs_algo()
693 stb0899_write_reg(state, STB0899_DEMAPVIT, 88); in stb0899_dvbs_algo()
694 stb0899_write_reg(state, STB0899_ACLC, 0x88); in stb0899_dvbs_algo()
695 stb0899_write_reg(state, STB0899_BCLC, 0x9a); in stb0899_dvbs_algo()
698 stb0899_write_reg(state, STB0899_DEMAPVIT, 94); in stb0899_dvbs_algo()
700 stb0899_write_reg(state, STB0899_BCLC, reg); in stb0899_dvbs_algo()
703 dprintk(state->verbose, FE_DEBUG, 1, "Unsupported Puncture Rate"); in stb0899_dvbs_algo()
707 reg = stb0899_read_reg(state, STB0899_TSTRES); in stb0899_dvbs_algo()
709 stb0899_write_reg(state, STB0899_TSTRES, reg); in stb0899_dvbs_algo()
712 reg = stb0899_read_reg(state, STB0899_CFD); in stb0899_dvbs_algo()
714 stb0899_write_reg(state, STB0899_CFD, reg); in stb0899_dvbs_algo()
716 stb0899_read_regs(state, STB0899_EQUAI1, eq_const, 10); in stb0899_dvbs_algo()
719 return internal->status; in stb0899_dvbs_algo()
724 * Configure UWP state machine
726 static void stb0899_dvbs2_config_uwp(struct stb0899_state *state) in stb0899_dvbs2_config_uwp() argument
728 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_config_uwp()
729 struct stb0899_config *config = state->config; in stb0899_dvbs2_config_uwp()
736 STB0899_SETFIELD_VAL(UWP_ESN0_AVE, uwp1, config->esno_ave); in stb0899_dvbs2_config_uwp()
737 STB0899_SETFIELD_VAL(UWP_ESN0_QUANT, uwp1, config->esno_quant); in stb0899_dvbs2_config_uwp()
738 STB0899_SETFIELD_VAL(UWP_TH_SOF, uwp1, config->uwp_threshold_sof); in stb0899_dvbs2_config_uwp()
740 STB0899_SETFIELD_VAL(FE_COARSE_TRK, uwp2, internal->av_frame_coarse); in stb0899_dvbs2_config_uwp()
741 STB0899_SETFIELD_VAL(FE_FINE_TRK, uwp2, internal->av_frame_fine); in stb0899_dvbs2_config_uwp()
742 STB0899_SETFIELD_VAL(UWP_MISS_TH, uwp2, config->miss_threshold); in stb0899_dvbs2_config_uwp()
744 STB0899_SETFIELD_VAL(UWP_TH_ACQ, uwp3, config->uwp_threshold_acq); in stb0899_dvbs2_config_uwp()
745 STB0899_SETFIELD_VAL(UWP_TH_TRACK, uwp3, config->uwp_threshold_track); in stb0899_dvbs2_config_uwp()
747 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_UWP_CNTRL1, STB0899_OFF0_UWP_CNTRL1, uwp1… in stb0899_dvbs2_config_uwp()
748 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_UWP_CNTRL2, STB0899_OFF0_UWP_CNTRL2, uwp2… in stb0899_dvbs2_config_uwp()
749 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_UWP_CNTRL3, STB0899_OFF0_UWP_CNTRL3, uwp3… in stb0899_dvbs2_config_uwp()
752 STB0899_SETFIELD_VAL(SOF_SEARCH_TIMEOUT, reg, config->sof_search_timeout); in stb0899_dvbs2_config_uwp()
753 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_SOF_SRCH_TO, STB0899_OFF0_SOF_SRCH_TO, re… in stb0899_dvbs2_config_uwp()
760 static void stb0899_dvbs2_config_csm_auto(struct stb0899_state *state) in stb0899_dvbs2_config_csm_auto() argument
766 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL1, STB0899_OFF0_CSM_CNTRL1, reg); in stb0899_dvbs2_config_csm_auto()
780 return i - 1; in Log2Int()
787 static u32 stb0899_dvbs2_calc_srate(struct stb0899_state *state) in stb0899_dvbs2_calc_srate() argument
789 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_calc_srate()
790 struct stb0899_config *config = state->config; in stb0899_dvbs2_calc_srate()
795 dec_ratio = (internal->master_clk * 2) / (5 * internal->srate); in stb0899_dvbs2_calc_srate()
799 master_clk = internal->master_clk / 1000; in stb0899_dvbs2_calc_srate()
800 srate = internal->srate / 1000; in stb0899_dvbs2_calc_srate()
803 intval = (decim * (1 << (config->btr_nco_bits - 1))) / master_clk; in stb0899_dvbs2_calc_srate()
804 remain = (decim * (1 << (config->btr_nco_bits - 1))) % master_clk; in stb0899_dvbs2_calc_srate()
806 intval = (1 << (config->btr_nco_bits - 1)) / (master_clk / 100) * decim / 100; in stb0899_dvbs2_calc_srate()
807 remain = (decim * (1 << (config->btr_nco_bits - 1))) % master_clk; in stb0899_dvbs2_calc_srate()
818 static u32 stb0899_dvbs2_calc_dev(struct stb0899_state *state) in stb0899_dvbs2_calc_dev() argument
820 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_calc_dev()
823 dec_ratio = (internal->master_clk * 2) / (5 * internal->srate); in stb0899_dvbs2_calc_dev()
826 master_clk = internal->master_clk / 1000; /* for integer Calculation*/ in stb0899_dvbs2_calc_dev()
827 srate = internal->srate / 1000; /* for integer Calculation*/ in stb0899_dvbs2_calc_dev()
837 static void stb0899_dvbs2_set_srate(struct stb0899_state *state) in stb0899_dvbs2_set_srate() argument
839 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_set_srate()
846 dec_ratio = (internal->master_clk * 2) / (5 * internal->srate); in stb0899_dvbs2_set_srate()
852 win_sel = dec_rate - 4; in stb0899_dvbs2_set_srate()
856 f_sym = internal->master_clk / ((decim * internal->srate) / 1000); in stb0899_dvbs2_set_srate()
864 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DECIM_CNTRL, STB0899_OFF0_DECIM_CNTRL, de… in stb0899_dvbs2_set_srate()
873 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_ANTI_ALIAS_SEL, STB0899_OFF0_ANTI_ALIAS_S… in stb0899_dvbs2_set_srate()
874 btr_nom_freq = stb0899_dvbs2_calc_srate(state); in stb0899_dvbs2_set_srate()
875 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_NOM_FREQ, STB0899_OFF0_BTR_NOM_FREQ, … in stb0899_dvbs2_set_srate()
877 correction = stb0899_dvbs2_calc_dev(state); in stb0899_dvbs2_set_srate()
880 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_CNTRL, STB0899_OFF0_BTR_CNTRL, reg); in stb0899_dvbs2_set_srate()
883 freq_adj = internal->srate / (internal->master_clk / 4096); in stb0899_dvbs2_set_srate()
884 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_FREQ_ADJ_SCALE, STB0899_OFF0_FREQ_ADJ_SCA… in stb0899_dvbs2_set_srate()
891 static void stb0899_dvbs2_set_btr_loopbw(struct stb0899_state *state) in stb0899_dvbs2_set_btr_loopbw() argument
893 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_set_btr_loopbw()
894 struct stb0899_config *config = state->config; in stb0899_dvbs2_set_btr_loopbw()
902 dec_ratio = (internal->master_clk * 2) / (5 * internal->srate); in stb0899_dvbs2_set_btr_loopbw()
908 K = (1 << config->btr_nco_bits) / (internal->master_clk / 1000); in stb0899_dvbs2_set_btr_loopbw()
909 K *= (internal->srate / 1000000) * decim; /*k=k 10^-8*/ in stb0899_dvbs2_set_btr_loopbw()
914 wn = (2 * (loopbw_percent * 1000) * 40 * zeta) /wn; /*wn =wn 10^-8*/ in stb0899_dvbs2_set_btr_loopbw()
916 k_indirect = (wn * wn) / K; /*kindirect = kindirect 10^-6*/ in stb0899_dvbs2_set_btr_loopbw()
917 k_direct = (2 * wn * zeta) / K; /*kDirect = kDirect 10^-2*/ in stb0899_dvbs2_set_btr_loopbw()
920 k_direct_shift = Log2Int(k_direct) - Log2Int(10000) - 2; in stb0899_dvbs2_set_btr_loopbw()
921 k_btr1_rshft = (-1 * k_direct_shift) + config->btr_gain_shift_offset; in stb0899_dvbs2_set_btr_loopbw()
925 k_indirect_shift = Log2Int(k_indirect + 15) - 20 /*- 2*/; in stb0899_dvbs2_set_btr_loopbw()
926 k_btr0_rshft = (-1 * k_indirect_shift) + config->btr_gain_shift_offset; in stb0899_dvbs2_set_btr_loopbw()
927 k_btr0 = k_indirect * (1 << (-k_indirect_shift)); in stb0899_dvbs2_set_btr_loopbw()
932 k_btr2_rshft = k_btr0_rshft - 15; in stb0899_dvbs2_set_btr_loopbw()
941 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_LOOP_GAIN, STB0899_OFF0_BTR_LOOP_GAIN… in stb0899_dvbs2_set_btr_loopbw()
943 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_LOOP_GAIN, STB0899_OFF0_BTR_LOOP_GAIN… in stb0899_dvbs2_set_btr_loopbw()
950 static void stb0899_dvbs2_set_carr_freq(struct stb0899_state *state, s32 carr_freq, u32 master_clk) in stb0899_dvbs2_set_carr_freq() argument
952 struct stb0899_config *config = state->config; in stb0899_dvbs2_set_carr_freq()
956 crl_nom_freq = (1 << config->crl_nco_bits) / master_clk; in stb0899_dvbs2_set_carr_freq()
960 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_NOM_FREQ, STB0899_OFF0_CRL_NOM_FREQ, … in stb0899_dvbs2_set_carr_freq()
967 static void stb0899_dvbs2_init_calc(struct stb0899_state *state) in stb0899_dvbs2_init_calc() argument
969 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_init_calc()
974 stb0899_dvbs2_config_uwp(state); in stb0899_dvbs2_init_calc()
975 stb0899_dvbs2_config_csm_auto(state); in stb0899_dvbs2_init_calc()
978 stb0899_dvbs2_set_srate(state); in stb0899_dvbs2_init_calc()
979 stb0899_dvbs2_set_btr_loopbw(state); in stb0899_dvbs2_init_calc()
981 if (internal->srate / 1000000 >= 15) in stb0899_dvbs2_init_calc()
983 else if (internal->srate / 1000000 >= 10) in stb0899_dvbs2_init_calc()
985 else if (internal->srate / 1000000 >= 5) in stb0899_dvbs2_init_calc()
990 range = internal->srch_range / 1000000; in stb0899_dvbs2_init_calc()
991 steps = (10 * range * (1 << 17)) / (step_size * (internal->srate / 1000000)); in stb0899_dvbs2_init_calc()
995 stb0899_dvbs2_set_carr_freq(state, internal->center_freq - in stb0899_dvbs2_init_calc()
996 (internal->step_size * (internal->srate / 20000000)), in stb0899_dvbs2_init_calc()
997 (internal->master_clk) / 1000000); in stb0899_dvbs2_init_calc()
999 stb0899_dvbs2_set_carr_freq(state, internal->center_freq, (internal->master_clk) / 1000000); in stb0899_dvbs2_init_calc()
1006 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_ACQ_CNTRL2, STB0899_OFF0_ACQ_CNTRL2, reg); in stb0899_dvbs2_init_calc()
1013 static void stb0899_dvbs2_btr_init(struct stb0899_state *state) in stb0899_dvbs2_btr_init() argument
1021 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_CNTRL, STB0899_OFF0_BTR_CNTRL, reg); in stb0899_dvbs2_btr_init()
1024 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_FREQ_INIT, STB0899_OFF0_BTR_FREQ_INIT… in stb0899_dvbs2_btr_init()
1025 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_FREQ_INIT, STB0899_OFF0_BTR_FREQ_INIT… in stb0899_dvbs2_btr_init()
1028 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_PHS_INIT, STB0899_OFF0_BTR_PHS_INIT, … in stb0899_dvbs2_btr_init()
1029 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_BTR_PHS_INIT, STB0899_OFF0_BTR_PHS_INIT, … in stb0899_dvbs2_btr_init()
1034 * trigger a DVB-S2 acquisition
1036 static void stb0899_dvbs2_reacquire(struct stb0899_state *state) in stb0899_dvbs2_reacquire() argument
1042 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_RESET_CNTRL, STB0899_OFF0_RESET_CNTRL, re… in stb0899_dvbs2_reacquire()
1045 stb0899_dvbs2_btr_init(state); in stb0899_dvbs2_reacquire()
1048 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_FREQ_INIT, STB0899_OFF0_CRL_FREQ_INIT… in stb0899_dvbs2_reacquire()
1049 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_FREQ_INIT, STB0899_OFF0_CRL_FREQ_INIT… in stb0899_dvbs2_reacquire()
1050 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_LOOP_GAIN, STB0899_OFF0_CRL_LOOP_GAIN… in stb0899_dvbs2_reacquire()
1051 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_PHS_INIT, STB0899_OFF0_CRL_PHS_INIT, … in stb0899_dvbs2_reacquire()
1052 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_PHS_INIT, STB0899_OFF0_CRL_PHS_INIT, … in stb0899_dvbs2_reacquire()
1057 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_RESET_CNTRL, STB0899_OFF0_RESET_CNTRL, re… in stb0899_dvbs2_reacquire()
1060 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_ACQUIRE_TRIG, STB0899_OFF0_ACQUIRE_TRIG, … in stb0899_dvbs2_reacquire()
1061 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_LOCK_LOST, STB0899_OFF0_LOCK_LOST, 0); in stb0899_dvbs2_reacquire()
1064 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_EQUALIZER_INIT, STB0899_OFF0_EQUALIZER_IN… in stb0899_dvbs2_reacquire()
1067 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_EQUALIZER_INIT, STB0899_OFF0_EQUALIZER_IN… in stb0899_dvbs2_reacquire()
1074 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_EQ_CNTRL, STB0899_OFF0_EQ_CNTRL, reg); in stb0899_dvbs2_reacquire()
1077 stb0899_write_reg(state, STB0899_PDELCTRL, 0x4a); in stb0899_dvbs2_reacquire()
1082 * get DVB-S2 Demod LOCK status
1084 static enum stb0899_status stb0899_dvbs2_get_dmd_status(struct stb0899_state *state, int timeout) in stb0899_dvbs2_get_dmd_status() argument
1086 int time = -10, lock = 0, uwp, csm; in stb0899_dvbs2_get_dmd_status() local
1091 dprintk(state->verbose, FE_DEBUG, 1, "DMD_STATUS=[0x%02x]", reg); in stb0899_dvbs2_get_dmd_status()
1093 dprintk(state->verbose, FE_DEBUG, 1, "------------->IF AGC LOCKED !"); in stb0899_dvbs2_get_dmd_status()
1095 dprintk(state->verbose, FE_DEBUG, 1, "----------->DMD STAT2=[0x%02x]", reg); in stb0899_dvbs2_get_dmd_status()
1099 lock = 1; in stb0899_dvbs2_get_dmd_status()
1104 } while ((!lock) && (time <= timeout)); in stb0899_dvbs2_get_dmd_status()
1106 if (lock) { in stb0899_dvbs2_get_dmd_status()
1107 dprintk(state->verbose, FE_DEBUG, 1, "----------------> DVB-S2 LOCK !"); in stb0899_dvbs2_get_dmd_status()
1118 static int stb0899_dvbs2_get_data_lock(struct stb0899_state *state, int timeout) in stb0899_dvbs2_get_data_lock() argument
1120 int time = 0, lock = 0; in stb0899_dvbs2_get_data_lock() local
1123 while ((!lock) && (time < timeout)) { in stb0899_dvbs2_get_data_lock()
1124 reg = stb0899_read_reg(state, STB0899_CFGPDELSTATUS1); in stb0899_dvbs2_get_data_lock()
1125 dprintk(state->verbose, FE_DEBUG, 1, "---------> CFGPDELSTATUS=[0x%02x]", reg); in stb0899_dvbs2_get_data_lock()
1126 lock = STB0899_GETFIELD(CFGPDELSTATUS_LOCK, reg); in stb0899_dvbs2_get_data_lock()
1130 return lock; in stb0899_dvbs2_get_data_lock()
1135 * get DVB-S2 FEC LOCK status
1137 static enum stb0899_status stb0899_dvbs2_get_fec_status(struct stb0899_state *state, int timeout) in stb0899_dvbs2_get_fec_status() argument
1142 Locked = stb0899_dvbs2_get_data_lock(state, 1); in stb0899_dvbs2_get_fec_status()
1149 dprintk(state->verbose, FE_DEBUG, 1, "---------->DVB-S2 FEC LOCK !"); in stb0899_dvbs2_get_fec_status()
1161 static void stb0899_dvbs2_init_csm(struct stb0899_state *state, int pilots, enum stb0899_modcod mod… in stb0899_dvbs2_init_csm() argument
1163 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_init_csm()
1169 if (((internal->master_clk / internal->srate) <= 4) && (modcod <= 11) && (pilots == 1)) { in stb0899_dvbs2_init_csm()
1238 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL1, STB0899_OFF0_CSM_CNTRL1, csm1… in stb0899_dvbs2_init_csm()
1257 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL1, STB0899_OFF0_CSM_CNTRL1, csm1… in stb0899_dvbs2_init_csm()
1258 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL2, STB0899_OFF0_CSM_CNTRL2, csm2… in stb0899_dvbs2_init_csm()
1259 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL3, STB0899_OFF0_CSM_CNTRL3, csm3… in stb0899_dvbs2_init_csm()
1260 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL4, STB0899_OFF0_CSM_CNTRL4, csm4… in stb0899_dvbs2_init_csm()
1266 * get DVB-S2 Symbol Rate
1268 static u32 stb0899_dvbs2_get_srate(struct stb0899_state *state) in stb0899_dvbs2_get_srate() argument
1270 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_get_srate()
1271 struct stb0899_config *config = state->config; in stb0899_dvbs2_get_srate()
1276 div1 = config->btr_nco_bits / 2; in stb0899_dvbs2_get_srate()
1277 div2 = config->btr_nco_bits - div1 - 1; in stb0899_dvbs2_get_srate()
1285 intval1 = internal->master_clk / (1 << div1); in stb0899_dvbs2_get_srate()
1288 rem1 = internal->master_clk % (1 << div1); in stb0899_dvbs2_get_srate()
1302 enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state) in stb0899_dvbs2_algo() argument
1304 struct stb0899_internal *internal = &state->internal; in stb0899_dvbs2_algo()
1311 if (internal->srate <= 2000000) { in stb0899_dvbs2_algo()
1312 searchTime = 5000; /* 5000 ms max time to lock UWP and CSM, SYMB <= 2Mbs */ in stb0899_dvbs2_algo()
1313 FecLockTime = 350; /* 350 ms max time to lock FEC, SYMB <= 2Mbs */ in stb0899_dvbs2_algo()
1314 } else if (internal->srate <= 5000000) { in stb0899_dvbs2_algo()
1315 searchTime = 2500; /* 2500 ms max time to lock UWP and CSM, 2Mbs < SYMB <= 5Mbs */ in stb0899_dvbs2_algo()
1316 FecLockTime = 170; /* 170 ms max time to lock FEC, 2Mbs< SYMB <= 5Mbs */ in stb0899_dvbs2_algo()
1317 } else if (internal->srate <= 10000000) { in stb0899_dvbs2_algo()
1318 searchTime = 1500; /* 1500 ms max time to lock UWP and CSM, 5Mbs <SYMB <= 10Mbs */ in stb0899_dvbs2_algo()
1319 FecLockTime = 80; /* 80 ms max time to lock FEC, 5Mbs< SYMB <= 10Mbs */ in stb0899_dvbs2_algo()
1320 } else if (internal->srate <= 15000000) { in stb0899_dvbs2_algo()
1321 searchTime = 500; /* 500 ms max time to lock UWP and CSM, 10Mbs <SYMB <= 15Mbs */ in stb0899_dvbs2_algo()
1322 FecLockTime = 50; /* 50 ms max time to lock FEC, 10Mbs< SYMB <= 15Mbs */ in stb0899_dvbs2_algo()
1323 } else if (internal->srate <= 20000000) { in stb0899_dvbs2_algo()
1324 searchTime = 300; /* 300 ms max time to lock UWP and CSM, 15Mbs < SYMB <= 20Mbs */ in stb0899_dvbs2_algo()
1325 FecLockTime = 30; /* 50 ms max time to lock FEC, 15Mbs< SYMB <= 20Mbs */ in stb0899_dvbs2_algo()
1326 } else if (internal->srate <= 25000000) { in stb0899_dvbs2_algo()
1327 searchTime = 250; /* 250 ms max time to lock UWP and CSM, 20 Mbs < SYMB <= 25Mbs */ in stb0899_dvbs2_algo()
1328 FecLockTime = 25; /* 25 ms max time to lock FEC, 20Mbs< SYMB <= 25Mbs */ in stb0899_dvbs2_algo()
1330 searchTime = 150; /* 150 ms max time to lock UWP and CSM, SYMB > 25Mbs */ in stb0899_dvbs2_algo()
1331 FecLockTime = 20; /* 20 ms max time to lock FEC, 20Mbs< SYMB <= 25Mbs */ in stb0899_dvbs2_algo()
1335 reg = stb0899_read_reg(state, STB0899_TSTRES); in stb0899_dvbs2_algo()
1337 stb0899_write_reg(state, STB0899_TSTRES, reg); in stb0899_dvbs2_algo()
1340 stb0899_i2c_gate_ctrl(&state->frontend, 1); in stb0899_dvbs2_algo()
1343 if (state->config->tuner_set_frequency) in stb0899_dvbs2_algo()
1344 state->config->tuner_set_frequency(&state->frontend, internal->freq); in stb0899_dvbs2_algo()
1345 if (state->config->tuner_get_frequency) in stb0899_dvbs2_algo()
1346 state->config->tuner_get_frequency(&state->frontend, &internal->freq); in stb0899_dvbs2_algo()
1349 stb0899_i2c_gate_ctrl(&state->frontend, 0); in stb0899_dvbs2_algo()
1355 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_IF_AGC_CNTRL, STB0899_OFF0_IF_AGC_CNTRL, … in stb0899_dvbs2_algo()
1359 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_IF_AGC_CNTRL2, STB0899_OFF0_IF_AGC_CNTRL2… in stb0899_dvbs2_algo()
1362 stb0899_dvbs2_init_calc(state); in stb0899_dvbs2_algo()
1365 switch (internal->inversion) { in stb0899_dvbs2_algo()
1373 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DMD_CNTRL2, STB0899_OFF0_DMD_CNTRL2, reg); in stb0899_dvbs2_algo()
1374 stb0899_dvbs2_reacquire(state); in stb0899_dvbs2_algo()
1376 /* Wait for demod lock (UWP and CSM) */ in stb0899_dvbs2_algo()
1377 internal->status = stb0899_dvbs2_get_dmd_status(state, searchTime); in stb0899_dvbs2_algo()
1379 if (internal->status == DVBS2_DEMOD_LOCK) { in stb0899_dvbs2_algo()
1380 dprintk(state->verbose, FE_DEBUG, 1, "------------> DVB-S2 DEMOD LOCK !"); in stb0899_dvbs2_algo()
1383 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime); in stb0899_dvbs2_algo()
1385 /*If false lock (UWP and CSM Locked but no FEC) try 3 time max*/ in stb0899_dvbs2_algo()
1386 while ((internal->status != DVBS2_FEC_LOCK) && (i < 3)) { in stb0899_dvbs2_algo()
1393 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_NOM_FREQ, STB0899_OFF0_CRL_NOM_FREQ, … in stb0899_dvbs2_algo()
1394 stb0899_dvbs2_reacquire(state); in stb0899_dvbs2_algo()
1395 internal->status = stb0899_dvbs2_get_fec_status(state, searchTime); in stb0899_dvbs2_algo()
1400 if (internal->status != DVBS2_FEC_LOCK) { in stb0899_dvbs2_algo()
1405 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DMD_CNTRL2, STB0899_OFF0_DMD_CNTRL2, reg); in stb0899_dvbs2_algo()
1407 stb0899_dvbs2_reacquire(state); in stb0899_dvbs2_algo()
1409 /* Wait for demod lock (UWP and CSM) */ in stb0899_dvbs2_algo()
1410 internal->status = stb0899_dvbs2_get_dmd_status(state, searchTime); in stb0899_dvbs2_algo()
1411 if (internal->status == DVBS2_DEMOD_LOCK) { in stb0899_dvbs2_algo()
1414 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime); in stb0899_dvbs2_algo()
1416 while ((internal->status != DVBS2_FEC_LOCK) && (i < 3)) { in stb0899_dvbs2_algo()
1423 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_NOM_FREQ, STB0899_OFF0_CRL_NOM_FREQ, … in stb0899_dvbs2_algo()
1425 stb0899_dvbs2_reacquire(state); in stb0899_dvbs2_algo()
1426 internal->status = stb0899_dvbs2_get_fec_status(state, searchTime); in stb0899_dvbs2_algo()
1431 if (pParams->DVBS2State == FE_DVBS2_FEC_LOCKED) in stb0899_dvbs2_algo()
1432 pParams->IQLocked = !iqSpectrum; in stb0899_dvbs2_algo()
1435 if (internal->status == DVBS2_FEC_LOCK) { in stb0899_dvbs2_algo()
1436 dprintk(state->verbose, FE_DEBUG, 1, "----------------> DVB-S2 FEC Lock !"); in stb0899_dvbs2_algo()
1441 if ((((10 * internal->master_clk) / (internal->srate / 10)) <= 410) && in stb0899_dvbs2_algo()
1445 stb0899_dvbs2_init_csm(state, pilots, modcod); in stb0899_dvbs2_algo()
1446 /* Wait for UWP,CSM and data LOCK 20ms max */ in stb0899_dvbs2_algo()
1447 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime); in stb0899_dvbs2_algo()
1450 while ((internal->status != DVBS2_FEC_LOCK) && (i < 3)) { in stb0899_dvbs2_algo()
1453 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL1, STB0899_OFF0_CSM_CNTRL1, csm1… in stb0899_dvbs2_algo()
1456 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CSM_CNTRL1, STB0899_OFF0_CSM_CNTRL1, csm1… in stb0899_dvbs2_algo()
1458 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime); in stb0899_dvbs2_algo()
1463 if ((((10 * internal->master_clk) / (internal->srate / 10)) <= 410) && in stb0899_dvbs2_algo()
1470 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_EQ_CNTRL, STB0899_OFF0_EQ_CNTRL, reg); in stb0899_dvbs2_algo()
1476 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_EQ_CNTRL, STB0899_OFF0_EQ_CNTRL, reg); in stb0899_dvbs2_algo()
1484 offsetfreq *= (internal->master_clk / 1000000); in stb0899_dvbs2_algo()
1489 internal->inversion = IQ_SWAP_ON; in stb0899_dvbs2_algo()
1491 internal->inversion = IQ_SWAP_OFF; in stb0899_dvbs2_algo()
1493 internal->freq = internal->freq + offsetfreq; in stb0899_dvbs2_algo()
1494 internal->srate = stb0899_dvbs2_get_srate(state); in stb0899_dvbs2_algo()
1497 internal->modcod = STB0899_GETFIELD(UWP_DECODE_MOD, reg) >> 2; in stb0899_dvbs2_algo()
1498 internal->pilots = STB0899_GETFIELD(UWP_DECODE_MOD, reg) & 0x01; in stb0899_dvbs2_algo()
1499 internal->frame_length = (STB0899_GETFIELD(UWP_DECODE_MOD, reg) >> 1) & 0x01; in stb0899_dvbs2_algo()
1506 if (INRANGE(STB0899_QPSK_12, internal->modcod, STB0899_QPSK_23)) in stb0899_dvbs2_algo()
1509 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_IF_AGC_CNTRL, STB0899_OFF0_IF_AGC_CNTRL, … in stb0899_dvbs2_algo()
1513 …stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_IF_AGC_CNTRL2, STB0899_OFF0_IF_AGC_CNTRL2… in stb0899_dvbs2_algo()
1517 reg = stb0899_read_reg(state, STB0899_TSTRES); in stb0899_dvbs2_algo()
1519 stb0899_write_reg(state, STB0899_TSTRES, reg); in stb0899_dvbs2_algo()
1521 return internal->status; in stb0899_dvbs2_algo()