diff --git a/frontends/stv0910.c b/frontends/stv0910.c index c846074..531ee18 100644 --- a/frontends/stv0910.c +++ b/frontends/stv0910.c @@ -853,45 +853,67 @@ static int stop(struct stv *state) return 0; } -static int init_search_param(struct stv *state) +static void set_pls(struct stv *state, u32 val) { - u8 tmp; + if (val == state->cur_scrambling_code) + return; + write_reg(state, RSTV0910_P2_PLROOT0 + state->regoff, + val & 0xff); + write_reg(state, RSTV0910_P2_PLROOT1 + state->regoff, + (val >> 8) & 0xff); + write_reg(state, RSTV0910_P2_PLROOT2 + state->regoff, + (val >> 16) & 0x0f); + state->cur_scrambling_code = val; +} - read_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, &tmp); - tmp |= 0x20; // Filter_en (no effect if SIS=non-MIS - write_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, tmp); +static void set_isi(struct stv *state, u32 isi) +{ + if (isi == NO_STREAM_ID_FILTER) + return; + if (isi == 0x80000000) { + set_field(FORCE_CONTINUOUS, 1); + set_field(TSOUT_NOSYNC, 1); + } else { + set_field(FILTER_EN, 1); + write_reg(state, RSTV0910_P2_ISIENTRY + state->regoff, + isi & 0xff); + write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0xff); + } + set_field(ALGOSWRST, 1); + set_field(ALGOSWRST, 0); +} - read_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, &tmp); - tmp &= ~0x02; // frame mode = 0 - write_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, tmp); +static void set_stream_modes(struct stv *state, struct dtv_frontend_properties *p) +{ + u32 scrambling_code = 1; - write_reg(state, RSTV0910_P2_UPLCCST0 + state->regoff, 0xe0); - write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0x00); + set_isi(state, p->stream_id); - read_reg(state, RSTV0910_P2_TSSTATEM + state->regoff, &tmp); - tmp &= ~0x01; // nosync = 0, in case next signal is standard TS - write_reg(state, RSTV0910_P2_TSSTATEM + state->regoff, tmp); - - read_reg(state, RSTV0910_P2_TSCFGL + state->regoff, &tmp); - tmp &= ~0x04; // embindvb = 0 - write_reg(state, RSTV0910_P2_TSCFGL + state->regoff, tmp); - - read_reg(state, RSTV0910_P2_TSINSDELH + state->regoff, &tmp); - tmp &= ~0x80; // syncbyte = 0 - write_reg(state, RSTV0910_P2_TSINSDELH + state->regoff, tmp); - - read_reg(state, RSTV0910_P2_TSINSDELM + state->regoff, &tmp); - tmp &= ~0x08; // token = 0 - write_reg(state, RSTV0910_P2_TSINSDELM + state->regoff, tmp); - - read_reg(state, RSTV0910_P2_TSDLYSET2 + state->regoff, &tmp); - tmp &= ~0x30; // hysteresis threshold = 0 - write_reg(state, RSTV0910_P2_TSDLYSET2 + state->regoff, tmp); - - read_reg(state, RSTV0910_P2_PDELCTRL0 + state->regoff, &tmp); - tmp = (tmp & ~0x30) | 0x10; // isi obs mode = 1, observe min ISI - write_reg(state, RSTV0910_P2_PDELCTRL0 + state->regoff, tmp); + /* Backwards compatibility to API in CrazyCat tree. + * PRBS X root cannot be 0, so this should always work. + */ + if ((p->stream_id != NO_STREAM_ID_FILTER) && + (p->stream_id & 0xfffff00)) + scrambling_code = 0xfffff & (p->stream_id >> 8); + /* p->pls is always gold code ! */ + if (p->pls != NO_SCRAMBLING_CODE) + scrambling_code = p->pls | 0x40000; + set_pls(state, scrambling_code); +} +static int init_search_param(struct stv *state, struct dtv_frontend_properties *p) +{ + set_field(FORCE_CONTINUOUS, 0); + set_field(FRAME_MODE, 0); + set_field(FILTER_EN, 0); + set_field(TSOUT_NOSYNC, 0); + set_field(TSFIFO_EMBINDVB, 0); + set_field(TSDEL_SYNCBYTE, 0); + set_reg(UPLCCST0, 0xe0); + set_field(TSINS_TOKEN, 0); + set_field(HYSTERESIS_THRESHOLD, 0); + set_field(ISIOBS_MODE, 1); + set_stream_modes(state, p); return 0; } @@ -974,7 +996,6 @@ static int start(struct stv *state, struct dtv_frontend_properties *p) s32 freq; u8 reg_dmdcfgmd; u16 symb; - u32 scrambling_code = 1; if (p->symbol_rate < 100000 || p->symbol_rate > 70000000) return -EINVAL; @@ -986,32 +1007,7 @@ static int start(struct stv *state, struct dtv_frontend_properties *p) if (state->started) write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x5C); - init_search_param(state); - - if (p->stream_id != NO_STREAM_ID_FILTER) { - /* Backwards compatibility to "crazy" API. - * PRBS X root cannot be 0, so this should always work. - */ - if (p->stream_id & 0xffffff00) - scrambling_code = p->stream_id >> 8; - write_reg(state, RSTV0910_P2_ISIENTRY + state->regoff, - p->stream_id & 0xff); - write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0xff); - } - - /* props->pls is always gold code ! */ - if (p->pls != NO_SCRAMBLING_CODE) - scrambling_code = p->pls | 0x40000; - - if (scrambling_code != state->cur_scrambling_code) { - write_reg(state, RSTV0910_P2_PLROOT0 + state->regoff, - scrambling_code & 0xff); - write_reg(state, RSTV0910_P2_PLROOT1 + state->regoff, - (scrambling_code >> 8) & 0xff); - write_reg(state, RSTV0910_P2_PLROOT2 + state->regoff, - (scrambling_code >> 16) & 0x0f); - state->cur_scrambling_code = scrambling_code; - } + init_search_param(state, p); if (p->symbol_rate <= 1000000) { /*SR <=1Msps*/ state->demod_timeout = 3000;