Lines Matching refs:state

132 static int write_reg(struct stv *state, u16 reg, u8 val)  in write_reg()  argument
134 struct i2c_adapter *adap = state->base->i2c; in write_reg()
136 struct i2c_msg msg = {.addr = state->base->adr, .flags = 0, in write_reg()
141 state->base->adr, reg, val); in write_reg()
164 static int read_reg(struct stv *state, u16 reg, u8 *val) in read_reg() argument
166 return i2c_read_regs16(state->base->i2c, state->base->adr, in read_reg()
170 static int read_regs(struct stv *state, u16 reg, u8 *val, int len) in read_regs() argument
172 return i2c_read_regs16(state->base->i2c, state->base->adr, in read_regs()
176 static int write_shared_reg(struct stv *state, u16 reg, u8 mask, u8 val) in write_shared_reg() argument
181 mutex_lock(&state->base->reg_lock); in write_shared_reg()
182 status = read_reg(state, reg, &tmp); in write_shared_reg()
184 status = write_reg(state, reg, (tmp & ~mask) | (val & mask)); in write_shared_reg()
185 mutex_unlock(&state->base->reg_lock); in write_shared_reg()
189 static int write_field(struct stv *state, u32 field, u8 val) in write_field() argument
194 status = read_reg(state, field >> 16, &old); in write_field()
202 return write_reg(state, field >> 16, new); in write_field()
206 write_field(state, state->nr ? FSTV0910_P2_##_reg : \
210 write_reg(state, state->nr ? RSTV0910_P2_##_reg : \
214 read_reg(state, state->nr ? RSTV0910_P2_##_reg : \
433 static u8 get_optim_cloop(struct stv *state, in get_optim_cloop() argument
443 if (state->symbol_rate <= 3000000) in get_optim_cloop()
445 else if (state->symbol_rate <= 7000000) in get_optim_cloop()
447 else if (state->symbol_rate <= 15000000) in get_optim_cloop()
449 else if (state->symbol_rate <= 25000000) in get_optim_cloop()
460 static int get_cur_symbol_rate(struct stv *state, u32 *p_symbol_rate) in get_cur_symbol_rate() argument
474 if (!state->started) in get_cur_symbol_rate()
477 read_reg(state, RSTV0910_P2_SFR3 + state->regoff, &symb_freq3); in get_cur_symbol_rate()
478 read_reg(state, RSTV0910_P2_SFR2 + state->regoff, &symb_freq2); in get_cur_symbol_rate()
479 read_reg(state, RSTV0910_P2_SFR1 + state->regoff, &symb_freq1); in get_cur_symbol_rate()
480 read_reg(state, RSTV0910_P2_SFR0 + state->regoff, &symb_freq0); in get_cur_symbol_rate()
481 read_reg(state, RSTV0910_P2_TMGREG2 + state->regoff, &tim_offs2); in get_cur_symbol_rate()
482 read_reg(state, RSTV0910_P2_TMGREG1 + state->regoff, &tim_offs1); in get_cur_symbol_rate()
483 read_reg(state, RSTV0910_P2_TMGREG0 + state->regoff, &tim_offs0); in get_cur_symbol_rate()
493 symbol_rate = (u32)(((u64)symbol_rate * state->base->mclk) >> 32); in get_cur_symbol_rate()
501 static int get_signal_parameters(struct stv *state) in get_signal_parameters() argument
505 if (!state->started) in get_signal_parameters()
508 if (state->receive_mode == RCVMODE_DVBS2) { in get_signal_parameters()
509 read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp); in get_signal_parameters()
510 state->mod_cod = (enum fe_stv0910_mod_cod)((tmp & 0x7c) >> 2); in get_signal_parameters()
511 state->pilots = (tmp & 0x01) != 0; in get_signal_parameters()
512 state->fectype = (enum dvbs2_fectype)((tmp & 0x02) >> 1); in get_signal_parameters()
514 } else if (state->receive_mode == RCVMODE_DVBS) { in get_signal_parameters()
515 read_reg(state, RSTV0910_P2_VITCURPUN + state->regoff, &tmp); in get_signal_parameters()
516 state->puncture_rate = FEC_NONE; in get_signal_parameters()
519 state->puncture_rate = FEC_1_2; in get_signal_parameters()
522 state->puncture_rate = FEC_2_3; in get_signal_parameters()
525 state->puncture_rate = FEC_3_4; in get_signal_parameters()
528 state->puncture_rate = FEC_5_6; in get_signal_parameters()
531 state->puncture_rate = FEC_7_8; in get_signal_parameters()
534 state->is_vcm = 0; in get_signal_parameters()
535 state->is_standard_broadcast = 1; in get_signal_parameters()
536 state->feroll_off = FE_SAT_35; in get_signal_parameters()
541 static int tracking_optimization(struct stv *state) in tracking_optimization() argument
545 read_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, &tmp); in tracking_optimization()
548 switch (state->receive_mode) { in tracking_optimization()
559 write_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, tmp); in tracking_optimization()
561 if (state->receive_mode == RCVMODE_DVBS2) { in tracking_optimization()
563 write_shared_reg(state, in tracking_optimization()
564 RSTV0910_TSTTSRS, state->nr ? 0x02 : 0x01, in tracking_optimization()
567 if (state->fectype == DVBS2_64K) { in tracking_optimization()
568 u8 aclc = get_optim_cloop(state, state->mod_cod, in tracking_optimization()
569 state->pilots); in tracking_optimization()
571 if (state->mod_cod <= FE_QPSK_910) { in tracking_optimization()
572 write_reg(state, RSTV0910_P2_ACLC2S2Q + in tracking_optimization()
573 state->regoff, aclc); in tracking_optimization()
574 } else if (state->mod_cod <= FE_8PSK_910) { in tracking_optimization()
575 write_reg(state, RSTV0910_P2_ACLC2S2Q + in tracking_optimization()
576 state->regoff, 0x2a); in tracking_optimization()
577 write_reg(state, RSTV0910_P2_ACLC2S28 + in tracking_optimization()
578 state->regoff, aclc); in tracking_optimization()
579 } else if (state->mod_cod <= FE_16APSK_910) { in tracking_optimization()
580 write_reg(state, RSTV0910_P2_ACLC2S2Q + in tracking_optimization()
581 state->regoff, 0x2a); in tracking_optimization()
582 write_reg(state, RSTV0910_P2_ACLC2S216A + in tracking_optimization()
583 state->regoff, aclc); in tracking_optimization()
584 } else if (state->mod_cod <= FE_32APSK_910) { in tracking_optimization()
585 write_reg(state, RSTV0910_P2_ACLC2S2Q + in tracking_optimization()
586 state->regoff, 0x2a); in tracking_optimization()
587 write_reg(state, RSTV0910_P2_ACLC2S232A + in tracking_optimization()
588 state->regoff, aclc); in tracking_optimization()
631 static int get_signal_to_noise(struct stv *state, s32 *signal_to_noise) in get_signal_to_noise() argument
641 if (!state->started) in get_signal_to_noise()
644 if (state->receive_mode == RCVMODE_DVBS2) { in get_signal_to_noise()
645 read_reg(state, RSTV0910_P2_NNOSPLHT1 + state->regoff, in get_signal_to_noise()
647 read_reg(state, RSTV0910_P2_NNOSPLHT0 + state->regoff, in get_signal_to_noise()
652 read_reg(state, RSTV0910_P2_NNOSDATAT1 + state->regoff, in get_signal_to_noise()
654 read_reg(state, RSTV0910_P2_NNOSDATAT0 + state->regoff, in get_signal_to_noise()
664 static int get_bit_error_rate_s(struct stv *state, u32 *bernumerator, in get_bit_error_rate_s() argument
669 int status = read_regs(state, in get_bit_error_rate_s()
670 RSTV0910_P2_ERRCNT12 + state->regoff, in get_bit_error_rate_s()
677 state->last_berdenominator = 1ULL << ((state->berscale * 2) + in get_bit_error_rate_s()
679 state->last_bernumerator = ((u32)(regs[0] & 0x7F) << 16) | in get_bit_error_rate_s()
681 if (state->last_bernumerator < 256 && state->berscale < 6) { in get_bit_error_rate_s()
682 state->berscale += 1; in get_bit_error_rate_s()
683 status = write_reg(state, RSTV0910_P2_ERRCTRL1 + in get_bit_error_rate_s()
684 state->regoff, in get_bit_error_rate_s()
685 0x20 | state->berscale); in get_bit_error_rate_s()
686 } else if (state->last_bernumerator > 1024 && in get_bit_error_rate_s()
687 state->berscale > 2) { in get_bit_error_rate_s()
688 state->berscale -= 1; in get_bit_error_rate_s()
689 status = write_reg(state, RSTV0910_P2_ERRCTRL1 + in get_bit_error_rate_s()
690 state->regoff, 0x20 | in get_bit_error_rate_s()
691 state->berscale); in get_bit_error_rate_s()
694 *bernumerator = state->last_bernumerator; in get_bit_error_rate_s()
695 *berdenominator = state->last_berdenominator; in get_bit_error_rate_s()
739 static int get_bit_error_rate_s2(struct stv *state, u32 *bernumerator, in get_bit_error_rate_s2() argument
744 int status = read_regs(state, RSTV0910_P2_ERRCNT12 + state->regoff, in get_bit_error_rate_s2()
751 state->last_berdenominator = in get_bit_error_rate_s2()
752 dvbs2_nbch((enum dvbs2_mod_cod)state->mod_cod, in get_bit_error_rate_s2()
753 state->fectype) << in get_bit_error_rate_s2()
754 (state->berscale * 2); in get_bit_error_rate_s2()
755 state->last_bernumerator = (((u32)regs[0] & 0x7F) << 16) | in get_bit_error_rate_s2()
757 if (state->last_bernumerator < 256 && state->berscale < 6) { in get_bit_error_rate_s2()
758 state->berscale += 1; in get_bit_error_rate_s2()
759 write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, in get_bit_error_rate_s2()
760 0x20 | state->berscale); in get_bit_error_rate_s2()
761 } else if (state->last_bernumerator > 1024 && in get_bit_error_rate_s2()
762 state->berscale > 2) { in get_bit_error_rate_s2()
763 state->berscale -= 1; in get_bit_error_rate_s2()
764 write_reg(state, RSTV0910_P2_ERRCTRL1 + state->regoff, in get_bit_error_rate_s2()
765 0x20 | state->berscale); in get_bit_error_rate_s2()
768 *bernumerator = state->last_bernumerator; in get_bit_error_rate_s2()
769 *berdenominator = state->last_berdenominator; in get_bit_error_rate_s2()
773 static int get_bit_error_rate(struct stv *state, u32 *bernumerator, in get_bit_error_rate() argument
779 switch (state->receive_mode) { in get_bit_error_rate()
781 return get_bit_error_rate_s(state, in get_bit_error_rate()
784 return get_bit_error_rate_s2(state, in get_bit_error_rate()
792 static int set_mclock(struct stv *state, u32 master_clock) in set_mclock() argument
796 u32 quartz = state->base->extclk / 1000000; in set_mclock()
845 write_reg(state, RSTV0910_NCOARSE, (cp << 3) | idf); in set_mclock()
846 write_reg(state, RSTV0910_NCOARSE2, odf); in set_mclock()
847 write_reg(state, RSTV0910_NCOARSE1, ndiv); in set_mclock()
850 state->base->mclk = fvco / (2 * odf) * 1000000; in set_mclock()
855 static int stop(struct stv *state) in stop() argument
857 if (state->started) { in stop()
860 write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, in stop()
861 state->tscfgh | 0x01); in stop()
862 read_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, &tmp); in stop()
864 write_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, tmp); in stop()
866 write_reg(state, RSTV0910_P2_AGC2O + state->regoff, 0x5B); in stop()
868 write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x5c); in stop()
869 state->started = 0; in stop()
871 state->receive_mode = RCVMODE_NONE; in stop()
875 static void set_pls(struct stv *state, u32 pls_code) in set_pls() argument
877 if (pls_code == state->cur_scrambling_code) in set_pls()
881 write_reg(state, RSTV0910_P2_PLROOT0 + state->regoff, in set_pls()
883 write_reg(state, RSTV0910_P2_PLROOT1 + state->regoff, in set_pls()
885 write_reg(state, RSTV0910_P2_PLROOT2 + state->regoff, in set_pls()
887 state->cur_scrambling_code = pls_code; in set_pls()
890 static void set_isi(struct stv *state, u32 isi) in set_isi() argument
899 write_reg(state, RSTV0910_P2_ISIENTRY + state->regoff, in set_isi()
901 write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0xff); in set_isi()
907 static void set_stream_modes(struct stv *state, in set_stream_modes() argument
910 set_isi(state, p->stream_id); in set_stream_modes()
911 set_pls(state, p->scrambling_sequence_index); in set_stream_modes()
914 static int init_search_param(struct stv *state, in init_search_param() argument
928 set_stream_modes(state, p); in init_search_param()
932 static int enable_puncture_rate(struct stv *state, enum fe_code_rate rate) in enable_puncture_rate() argument
958 return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, val); in enable_puncture_rate()
961 static int set_vth_default(struct stv *state) in set_vth_default() argument
963 state->vth[0] = 0xd7; in set_vth_default()
964 state->vth[1] = 0x85; in set_vth_default()
965 state->vth[2] = 0x58; in set_vth_default()
966 state->vth[3] = 0x3a; in set_vth_default()
967 state->vth[4] = 0x34; in set_vth_default()
968 state->vth[5] = 0x28; in set_vth_default()
969 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 0, state->vth[0]); in set_vth_default()
970 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 1, state->vth[1]); in set_vth_default()
971 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 2, state->vth[2]); in set_vth_default()
972 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 3, state->vth[3]); in set_vth_default()
973 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 4, state->vth[4]); in set_vth_default()
974 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 5, state->vth[5]); in set_vth_default()
978 static int set_vth(struct stv *state) in set_vth() argument
990 int status = read_regs(state, in set_vth()
991 RSTV0910_P2_NNOSDATAT1 + state->regoff, in set_vth()
998 if (state->vth[i] > vth) in set_vth()
999 state->vth[i] = vth; in set_vth()
1001 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 0, state->vth[0]); in set_vth()
1002 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 1, state->vth[1]); in set_vth()
1003 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 2, state->vth[2]); in set_vth()
1004 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 3, state->vth[3]); in set_vth()
1005 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 4, state->vth[4]); in set_vth()
1006 write_reg(state, RSTV0910_P2_VTH12 + state->regoff + 5, state->vth[5]); in set_vth()
1010 static int start(struct stv *state, struct dtv_frontend_properties *p) in start() argument
1019 state->receive_mode = RCVMODE_NONE; in start()
1020 state->demod_lock_time = 0; in start()
1023 if (state->started) in start()
1024 write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x5C); in start()
1026 init_search_param(state, p); in start()
1029 state->demod_timeout = 3000; in start()
1030 state->fec_timeout = 2000; in start()
1032 state->demod_timeout = 2500; in start()
1033 state->fec_timeout = 1300; in start()
1035 state->demod_timeout = 1000; in start()
1036 state->fec_timeout = 650; in start()
1038 state->demod_timeout = 700; in start()
1039 state->fec_timeout = 350; in start()
1041 state->demod_timeout = 400; in start()
1042 state->fec_timeout = 200; in start()
1044 state->demod_timeout = 300; in start()
1045 state->fec_timeout = 200; in start()
1049 symb = muldiv32(p->symbol_rate, 65536, state->base->mclk); in start()
1050 write_reg(state, RSTV0910_P2_SFRINIT1 + state->regoff, in start()
1052 write_reg(state, RSTV0910_P2_SFRINIT0 + state->regoff, (symb & 0xFF)); in start()
1054 state->demod_bits |= 0x80; in start()
1055 write_reg(state, RSTV0910_P2_DEMOD + state->regoff, state->demod_bits); in start()
1058 read_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, &reg_dmdcfgmd); in start()
1059 write_reg(state, RSTV0910_P2_DMDCFGMD + state->regoff, in start()
1062 write_shared_reg(state, in start()
1063 RSTV0910_TSTTSRS, state->nr ? 0x02 : 0x01, 0x00); in start()
1066 write_reg(state, RSTV0910_P2_FECM + state->regoff, 0x00); in start()
1067 write_reg(state, RSTV0910_P2_PRVIT + state->regoff, 0x2F); in start()
1069 enable_puncture_rate(state, FEC_NONE); in start()
1072 write_reg(state, RSTV0910_P2_ACLC2S2Q + state->regoff, 0x0B); in start()
1073 write_reg(state, RSTV0910_P2_ACLC2S28 + state->regoff, 0x0A); in start()
1074 write_reg(state, RSTV0910_P2_BCLC2S2Q + state->regoff, 0x84); in start()
1075 write_reg(state, RSTV0910_P2_BCLC2S28 + state->regoff, 0x84); in start()
1076 write_reg(state, RSTV0910_P2_CARHDR + state->regoff, 0x1C); in start()
1077 write_reg(state, RSTV0910_P2_CARFREQ + state->regoff, 0x79); in start()
1079 write_reg(state, RSTV0910_P2_ACLC2S216A + state->regoff, 0x29); in start()
1080 write_reg(state, RSTV0910_P2_ACLC2S232A + state->regoff, 0x09); in start()
1081 write_reg(state, RSTV0910_P2_BCLC2S216A + state->regoff, 0x84); in start()
1082 write_reg(state, RSTV0910_P2_BCLC2S232A + state->regoff, 0x84); in start()
1088 write_reg(state, RSTV0910_TSTRES0, state->nr ? 0x04 : 0x08); in start()
1089 write_reg(state, RSTV0910_TSTRES0, 0); in start()
1091 set_vth_default(state); in start()
1093 write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x1F); in start()
1095 write_reg(state, RSTV0910_P2_CARCFG + state->regoff, 0x46); in start()
1098 freq = (state->search_range / 2000) + 80; in start()
1100 freq = (state->search_range / 2000) + 1600; in start()
1101 freq = (freq << 16) / (state->base->mclk / 1000); in start()
1103 write_reg(state, RSTV0910_P2_CFRUP1 + state->regoff, in start()
1105 write_reg(state, RSTV0910_P2_CFRUP0 + state->regoff, (freq & 0xff)); in start()
1108 write_reg(state, RSTV0910_P2_CFRLOW1 + state->regoff, in start()
1110 write_reg(state, RSTV0910_P2_CFRLOW0 + state->regoff, (freq & 0xff)); in start()
1113 write_reg(state, RSTV0910_P2_CFRINIT1 + state->regoff, 0); in start()
1114 write_reg(state, RSTV0910_P2_CFRINIT0 + state->regoff, 0); in start()
1116 write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x1F); in start()
1118 write_reg(state, RSTV0910_P2_DMDISTATE + state->regoff, 0x15); in start()
1120 state->demod_lock_time += TUNING_DELAY; in start()
1121 state->started = 1; in start()
1126 static int init_diseqc(struct stv *state) in init_diseqc() argument
1128 u16 offs = state->nr ? 0x40 : 0; /* Address offset */ in init_diseqc()
1129 u8 freq = ((state->base->mclk + 11000 * 32) / (22000 * 32)); in init_diseqc()
1132 write_reg(state, RSTV0910_P1_DISRXCFG + offs, 0x00); in init_diseqc()
1133 write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0xBA); /* Reset = 1 */ in init_diseqc()
1134 write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0x3A); /* Reset = 0 */ in init_diseqc()
1135 write_reg(state, RSTV0910_P1_DISTXF22 + offs, freq); in init_diseqc()
1139 static int probe(struct stv *state) in probe() argument
1143 state->receive_mode = RCVMODE_NONE; in probe()
1144 state->started = 0; in probe()
1146 if (read_reg(state, RSTV0910_MID, &id) < 0) in probe()
1153 write_reg(state, RSTV0910_P1_I2CRPT, 0x24); in probe()
1155 write_reg(state, RSTV0910_P2_I2CRPT, 0x24); in probe()
1157 write_reg(state, RSTV0910_I2CCFG, 0x88); /* state->i2ccfg */ in probe()
1159 write_reg(state, RSTV0910_OUTCFG, 0x00); /* OUTCFG */ in probe()
1160 write_reg(state, RSTV0910_PADCFG, 0x05); /* RFAGC Pads Dev = 05 */ in probe()
1161 write_reg(state, RSTV0910_SYNTCTRL, 0x02); /* SYNTCTRL */ in probe()
1162 write_reg(state, RSTV0910_TSGENERAL, state->tsgeneral); /* TSGENERAL */ in probe()
1163 write_reg(state, RSTV0910_CFGEXT, 0x02); /* CFGEXT */ in probe()
1165 if (state->single) in probe()
1166 write_reg(state, RSTV0910_GENCFG, 0x14); /* GENCFG */ in probe()
1168 write_reg(state, RSTV0910_GENCFG, 0x15); /* GENCFG */ in probe()
1170 write_reg(state, RSTV0910_P1_TNRCFG2, 0x02); /* IQSWAP = 0 */ in probe()
1171 write_reg(state, RSTV0910_P2_TNRCFG2, 0x82); /* IQSWAP = 1 */ in probe()
1173 write_reg(state, RSTV0910_P1_CAR3CFG, 0x02); in probe()
1174 write_reg(state, RSTV0910_P2_CAR3CFG, 0x02); in probe()
1175 write_reg(state, RSTV0910_P1_DMDCFG4, 0x04); in probe()
1176 write_reg(state, RSTV0910_P2_DMDCFG4, 0x04); in probe()
1178 write_reg(state, RSTV0910_TSTRES0, 0x80); /* LDPC Reset */ in probe()
1179 write_reg(state, RSTV0910_TSTRES0, 0x00); in probe()
1181 write_reg(state, RSTV0910_P1_TSPIDFLT1, 0x00); in probe()
1182 write_reg(state, RSTV0910_P2_TSPIDFLT1, 0x00); in probe()
1184 write_reg(state, RSTV0910_P1_TMGCFG2, 0x80); in probe()
1185 write_reg(state, RSTV0910_P2_TMGCFG2, 0x80); in probe()
1187 set_mclock(state, 135000000); in probe()
1190 write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh | 0x01); in probe()
1191 write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh); in probe()
1192 write_reg(state, RSTV0910_P1_TSCFGM, 0xC0); /* Manual speed */ in probe()
1193 write_reg(state, RSTV0910_P1_TSCFGL, 0x20); in probe()
1195 write_reg(state, RSTV0910_P1_TSSPEED, state->tsspeed); in probe()
1197 write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh | 0x01); in probe()
1198 write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh); in probe()
1199 write_reg(state, RSTV0910_P2_TSCFGM, 0xC0); /* Manual speed */ in probe()
1200 write_reg(state, RSTV0910_P2_TSCFGL, 0x20); in probe()
1202 write_reg(state, RSTV0910_P2_TSSPEED, state->tsspeed); in probe()
1205 write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh | 0x01); in probe()
1206 write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh | 0x01); in probe()
1207 write_reg(state, RSTV0910_P1_TSCFGH, state->tscfgh); in probe()
1208 write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh); in probe()
1210 write_reg(state, RSTV0910_P1_I2CRPT, state->i2crpt); in probe()
1211 write_reg(state, RSTV0910_P2_I2CRPT, state->i2crpt); in probe()
1213 write_reg(state, RSTV0910_P1_TSINSDELM, 0x17); in probe()
1214 write_reg(state, RSTV0910_P1_TSINSDELL, 0xff); in probe()
1216 write_reg(state, RSTV0910_P2_TSINSDELM, 0x17); in probe()
1217 write_reg(state, RSTV0910_P2_TSINSDELL, 0xff); in probe()
1219 init_diseqc(state); in probe()
1225 struct stv *state = fe->demodulator_priv; in gate_ctrl() local
1226 u8 i2crpt = state->i2crpt & ~0x86; in gate_ctrl()
1239 mutex_lock(&state->base->i2c_lock); in gate_ctrl()
1245 if (write_reg(state, state->nr ? RSTV0910_P2_I2CRPT : in gate_ctrl()
1248 if (!WARN_ON(!mutex_is_locked(&state->base->i2c_lock))) in gate_ctrl()
1249 mutex_unlock(&state->base->i2c_lock); in gate_ctrl()
1250 dev_err(&state->base->i2c->dev, in gate_ctrl()
1256 state->i2crpt = i2crpt; in gate_ctrl()
1259 if (!WARN_ON(!mutex_is_locked(&state->base->i2c_lock))) in gate_ctrl()
1260 mutex_unlock(&state->base->i2c_lock); in gate_ctrl()
1266 struct stv *state = fe->demodulator_priv; in release() local
1268 state->base->count--; in release()
1269 if (state->base->count == 0) { in release()
1270 list_del(&state->base->stvlist); in release()
1271 kfree(state->base); in release()
1273 kfree(state); in release()
1279 struct stv *state = fe->demodulator_priv; in set_parameters() local
1282 stop(state); in set_parameters()
1285 state->symbol_rate = p->symbol_rate; in set_parameters()
1286 stat = start(state, p); in set_parameters()
1290 static int manage_matype_info(struct stv *state) in manage_matype_info() argument
1292 if (!state->started) in manage_matype_info()
1294 if (state->receive_mode == RCVMODE_DVBS2) { in manage_matype_info()
1297 read_regs(state, RSTV0910_P2_MATSTR1 + state->regoff, in manage_matype_info()
1299 state->feroll_off = in manage_matype_info()
1301 state->is_vcm = (bbheader[0] & 0x10) == 0; in manage_matype_info()
1302 state->is_standard_broadcast = (bbheader[0] & 0xFC) == 0xF0; in manage_matype_info()
1303 } else if (state->receive_mode == RCVMODE_DVBS) { in manage_matype_info()
1304 state->is_vcm = 0; in manage_matype_info()
1305 state->is_standard_broadcast = 1; in manage_matype_info()
1306 state->feroll_off = FE_SAT_35; in manage_matype_info()
1313 struct stv *state = fe->demodulator_priv; in read_snr() local
1317 if (!get_signal_to_noise(state, &snrval)) { in read_snr()
1329 struct stv *state = fe->demodulator_priv; in read_ber() local
1333 get_bit_error_rate(state, &n, &d); in read_ber()
1345 struct stv *state = fe->demodulator_priv; in read_signal_strength() local
1346 struct dtv_frontend_properties *p = &state->fe.dtv_property_cache; in read_signal_strength()
1352 read_regs(state, RSTV0910_P2_AGCIQIN1 + state->regoff, reg, 2); in read_signal_strength()
1357 read_regs(state, RSTV0910_P2_POWERI + state->regoff, reg, 2); in read_signal_strength()
1372 struct stv *state = fe->demodulator_priv; in read_status() local
1381 read_reg(state, RSTV0910_P2_DMDSTATE + state->regoff, &dmd_state); in read_status()
1384 read_reg(state, RSTV0910_P2_DSTATUS + state->regoff, &dstatus); in read_status()
1390 set_vth(state); in read_status()
1406 if (state->receive_mode == RCVMODE_NONE) { in read_status()
1407 state->receive_mode = cur_receive_mode; in read_status()
1408 state->demod_lock_time = jiffies; in read_status()
1409 state->first_time_lock = 1; in read_status()
1411 get_signal_parameters(state); in read_status()
1412 tracking_optimization(state); in read_status()
1414 write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, in read_status()
1415 state->tscfgh); in read_status()
1417 write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, in read_status()
1418 state->tscfgh | 0x01); in read_status()
1419 write_reg(state, RSTV0910_P2_TSCFGH + state->regoff, in read_status()
1420 state->tscfgh); in read_status()
1423 if (state->receive_mode == RCVMODE_DVBS2) { in read_status()
1426 read_reg(state, in read_status()
1427 RSTV0910_P2_PDELSTATUS1 + state->regoff, in read_status()
1433 read_reg(state, in read_status()
1434 RSTV0910_P2_VSTATUSVIT + state->regoff, in read_status()
1443 if (state->first_time_lock) { in read_status()
1446 state->first_time_lock = 0; in read_status()
1448 manage_matype_info(state); in read_status()
1450 if (state->receive_mode == RCVMODE_DVBS2) { in read_status()
1455 state->demod_bits &= ~0x84; in read_status()
1456 write_reg(state, in read_status()
1457 RSTV0910_P2_DEMOD + state->regoff, in read_status()
1458 state->demod_bits); in read_status()
1459 read_reg(state, in read_status()
1460 RSTV0910_P2_PDELCTRL2 + state->regoff, in read_status()
1464 write_reg(state, in read_status()
1465 RSTV0910_P2_PDELCTRL2 + state->regoff, in read_status()
1469 write_reg(state, in read_status()
1470 RSTV0910_P2_PDELCTRL2 + state->regoff, in read_status()
1473 state->berscale = 2; in read_status()
1474 state->last_bernumerator = 0; in read_status()
1475 state->last_berdenominator = 1; in read_status()
1477 write_reg(state, in read_status()
1478 RSTV0910_P2_ERRCTRL1 + state->regoff, in read_status()
1479 BER_SRC_S2 | state->berscale); in read_status()
1481 state->berscale = 2; in read_status()
1482 state->last_bernumerator = 0; in read_status()
1483 state->last_berdenominator = 1; in read_status()
1485 write_reg(state, in read_status()
1486 RSTV0910_P2_ERRCTRL1 + state->regoff, in read_status()
1487 BER_SRC_S | state->berscale); in read_status()
1490 write_reg(state, in read_status()
1491 RSTV0910_P2_FBERCPT4 + state->regoff, 0x00); in read_status()
1496 write_reg(state, in read_status()
1497 RSTV0910_P2_ERRCTRL2 + state->regoff, 0xc1); in read_status()
1499 set_vth_default(state); in read_status()
1500 if (state->receive_mode == RCVMODE_DVBS) in read_status()
1501 enable_puncture_rate(state, in read_status()
1502 state->puncture_rate); in read_status()
1506 if (state->is_vcm) { in read_status()
1510 read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, in read_status()
1514 if (mod_cod > state->mod_cod) in read_status()
1515 state->mod_cod = mod_cod; in read_status()
1544 struct stv *state = fe->demodulator_priv; in get_frontend() local
1548 if (state->receive_mode == RCVMODE_DVBS2) { in get_frontend()
1570 read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp); in get_frontend()
1575 } else if (state->receive_mode == RCVMODE_DVBS) { in get_frontend()
1576 read_reg(state, RSTV0910_P2_VITCURPUN + state->regoff, &tmp); in get_frontend()
1600 if (state->receive_mode != RCVMODE_NONE) { in get_frontend()
1601 get_cur_symbol_rate(state, &symbolrate); in get_frontend()
1611 struct stv *state = fe->demodulator_priv; in tune() local
1618 state->tune_time = jiffies; in tune()
1639 struct stv *state = fe->demodulator_priv; in set_tone() local
1640 u16 offs = state->nr ? 0x40 : 0; in set_tone()
1644 return write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0x38); in set_tone()
1646 return write_reg(state, RSTV0910_P1_DISTXCFG + offs, 0x3a); in set_tone()
1653 static int wait_dis(struct stv *state, u8 flag, u8 val) in wait_dis() argument
1657 u16 offs = state->nr ? 0x40 : 0; in wait_dis()
1660 read_reg(state, RSTV0910_P1_DISTXSTATUS + offs, &stat); in wait_dis()
1671 struct stv *state = fe->demodulator_priv; in send_master_cmd() local
1677 wait_dis(state, 0x40, 0x00); in send_master_cmd()
1681 wait_dis(state, 0x20, 0x20); in send_master_cmd()
1687 struct stv *state = fe->demodulator_priv; in send_burst() local
1699 wait_dis(state, 0x40, 0x00); in send_burst()
1702 wait_dis(state, 0x20, 0x20); in send_burst()
1709 struct stv *state = fe->demodulator_priv; in sleep() local
1711 stop(state); in sleep()
1753 static void stv0910_init_stats(struct stv *state) in stv0910_init_stats() argument
1755 struct dtv_frontend_properties *p = &state->fe.dtv_property_cache; in stv0910_init_stats()
1771 struct stv *state; in stv0910_attach() local
1774 state = kzalloc(sizeof(*state), GFP_KERNEL); in stv0910_attach()
1775 if (!state) in stv0910_attach()
1778 state->tscfgh = 0x20 | (cfg->parallel ? 0 : 0x40); in stv0910_attach()
1779 state->tsgeneral = (cfg->parallel == 2) ? 0x02 : 0x00; in stv0910_attach()
1780 state->i2crpt = 0x0A | ((cfg->rptlvl & 0x07) << 4); in stv0910_attach()
1782 state->tsspeed = (cfg->tsspeed ? cfg->tsspeed : 0x28); in stv0910_attach()
1783 state->nr = nr; in stv0910_attach()
1784 state->regoff = state->nr ? 0 : 0x200; in stv0910_attach()
1785 state->search_range = 16000000; in stv0910_attach()
1786 state->demod_bits = 0x10; /* Inversion : Auto with reset to 0 */ in stv0910_attach()
1787 state->receive_mode = RCVMODE_NONE; in stv0910_attach()
1788 state->cur_scrambling_code = (~0U); in stv0910_attach()
1789 state->single = cfg->single ? 1 : 0; in stv0910_attach()
1794 state->base = base; in stv0910_attach()
1806 state->base = base; in stv0910_attach()
1807 if (probe(state) < 0) { in stv0910_attach()
1815 state->fe.ops = stv0910_ops; in stv0910_attach()
1816 state->fe.demodulator_priv = state; in stv0910_attach()
1817 state->nr = nr; in stv0910_attach()
1820 state->fe.ops.info.name, cfg->adr, dev_name(&i2c->dev)); in stv0910_attach()
1822 stv0910_init_stats(state); in stv0910_attach()
1824 return &state->fe; in stv0910_attach()
1827 kfree(state); in stv0910_attach()